annotate src/event-msw.c @ 357:4711e16a8e49 r21-1-8

Import from CVS: tag r21-1-8
author cvs
date Mon, 13 Aug 2007 10:57:04 +0200
parents 182f72e8cd0d
children 972bbb6d6ca2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1 /* The mswindows event_stream interface.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
4 Copyright (C) 1996 Ben Wing.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
5 Copyright (C) 1997 Jonathan Harris.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
6
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
7 This file is part of XEmacs.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
8
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
12 later version.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
13
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
17 for more details.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
18
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
23
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
24 /* Synched up with: Not in FSF. */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
25
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
26 /* Authorship:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
27
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
28 Ultimately based on FSF.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
29 Rewritten by Ben Wing.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
30 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
31 Subprocess and modal loop support by Kirill M. Katsnelson.
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
32 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
33
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
34 #include <config.h>
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
35 #include "lisp.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
36
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
37 #include "console-msw.h"
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
38
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
39 #ifdef HAVE_SCROLLBARS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
40 # include "scrollbar-msw.h"
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
41 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
42
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
43 #ifdef HAVE_MENUBARS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
44 # include "menubar-msw.h"
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
45 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
46
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
47 #ifdef HAVE_DRAGNDROP
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
48 # include "dragdrop.h"
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
49 #endif
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
50
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
51 #include "device.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
52 #include "events.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
53 #include "frame.h"
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
54 #include "lstream.h"
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
55 #include "process.h"
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
56 #include "redisplay.h"
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
57 #include "sysproc.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
58 #include "syswait.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
59 #include "systime.h"
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
60 #include "sysdep.h"
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
61
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
62 #include "events-mod.h"
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
63 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
64 #include "sysfile.h"
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
65 #elif defined(__CYGWIN32__)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
66 typedef unsigned int SOCKET;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
67 #endif
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
68 #include <io.h>
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
69 #include <errno.h>
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
70
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
71 #ifdef HAVE_MENUBARS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
72 #define ADJR_MENUFLAG TRUE
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
73 #else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
74 #define ADJR_MENUFLAG FALSE
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
75 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
76
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
77 /* Fake key modifier which is attached to a quit char event.
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
78 Removed upon dequeueing an event */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
79 #define FAKE_MOD_QUIT 0x80
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
80
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
81 /* Timer ID used for button2 emulation */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
82 #define BUTTON_2_TIMER_ID 1
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
83
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
84 extern Lisp_Object
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
85 mswindows_get_toolbar_button_text (struct frame* f, int command_id);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
86 extern Lisp_Object
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
87 mswindows_handle_toolbar_wm_command (struct frame* f, HWND ctrl, WORD id);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
88
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
89 static Lisp_Object mswindows_find_frame (HWND hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
90 static Lisp_Object mswindows_find_console (HWND hwnd);
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
91 static Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
92 int extendedp);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
93 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
94 static void mswindows_set_chord_timer (HWND hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
95 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
96 static int mswindows_current_layout_has_AltGr (void);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
97
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
98 static struct event_stream *mswindows_event_stream;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
99
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
100 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
101 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
102 extern SELECT_TYPE process_only_mask, tty_only_mask;
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
103 SELECT_TYPE zero_mask;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
104 extern int signal_event_pipe_initialized;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
105 int windows_fd;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
106 #endif
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
107
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
108 /*
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
109 * Two separate queues, for efficiency, one (_u_) for user events, and
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
110 * another (_s_) for non-user ones. We always return events out of the
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
111 * first one until it is empty and only then proceed with the second
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
112 * one.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
113 */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
114 static Lisp_Object mswindows_u_dispatch_event_queue, mswindows_u_dispatch_event_queue_tail;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
115 static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
116
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
117 /* The number of things we can wait on */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
118 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
119
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
120 /* List of mswindows waitable handles. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
121 static HANDLE mswindows_waitable_handles[MAX_WAITABLE];
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
122
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
123 /* Number of wait handles */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
124 static int mswindows_waitable_count=0;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
125
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
126 /* Count of quit chars currently in the queue */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
127 /* Incremented in WM_[SYS]KEYDOWN handler in the mswindows_wnd_proc()
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
128 Decremented in mswindows_dequeue_dispatch_event() */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
129 int mswindows_quit_chars_count = 0;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
130
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
131 /* These are Lisp integers; see DEFVARS in this file for description. */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
132 int mswindows_dynamic_frame_resize;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
133 int mswindows_num_mouse_buttons;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
134 int mswindows_mouse_button_max_skew_x;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
135 int mswindows_mouse_button_max_skew_y;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
136 int mswindows_mouse_button_tolerance;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
137
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
138 /* This is the event signaled by the event pump.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
139 See mswindows_pump_outstanding_events for comments */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
140 static Lisp_Object mswindows_error_caught_in_modal_loop;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
141 static int mswindows_in_modal_loop;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
142
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
143 /* Count of wound timers */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
144 static int mswindows_pending_timers_count;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
145
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
146 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
147 /* Pipe instream - reads process output */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
148 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
149
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
150 #define PIPE_READ_DELAY 20
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
151
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
152 #define HANDLE_TO_USID(h) ((USID)(h))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
153
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
154 #define NTPIPE_SLURP_STREAM_DATA(stream) \
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
155 LSTREAM_TYPE_DATA (stream, ntpipe_slurp)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
156
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
157 /* This structure is allocated by the main thread, and is deallocated
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
158 in the thread upon exit. There are situations when a thread
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
159 remains blocked for a long time, much longer than the lstream
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
160 exists. For exmaple, "start notepad" command is issued from the
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
161 shell, then the shell is closed by C-c C-d. Although the shell
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
162 process exits, its output pipe will not get closed until the
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
163 notepad process exits also, because it inherits the pipe form the
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
164 shell. In this case, we abandon the thread, and let it live until
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
165 all such processes exit. While struct ntpipe_slurp_stream is
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
166 deallocated in this case, ntpipe_slurp_stream_shared_data are not. */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
167
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
168 struct ntpipe_slurp_stream_shared_data
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
169 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
170 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
171 /* This is a manual-reset object. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
172 HANDLE hev_caller; /* Caller blocks on this, and we signal it */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
173 /* This is a manual-reset object. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
174 HANDLE hev_unsleep; /* Pipe read delay is canceled if this is set */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
175 /* This is a manual-reset object. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
176 HANDLE hpipe; /* Pipe read end handle. */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
177 LONG die_p; /* Thread must exit ASAP if non-zero */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
178 BOOL eof_p : 1; /* Set when thread saw EOF */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
179 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
180 BOOL inuse_p : 1; /* this structure is in use */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
181 LONG lock_count; /* Client count of this struct, 0=safe to free */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
182 BYTE onebyte; /* One byte buffer read by thread */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
183 };
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
184
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
185 #define MAX_SLURP_STREAMS 32
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
186 struct ntpipe_slurp_stream_shared_data
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
187 shared_data_block[MAX_SLURP_STREAMS]={{0}};
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
188
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
189 struct ntpipe_slurp_stream
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
190 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
191 LPARAM user_data; /* Any user data stored in the stream object */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
192 struct ntpipe_slurp_stream_shared_data* thread_data;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
193 };
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
194
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
195 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-input", lstream_ntpipe_slurp,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
196 sizeof (struct ntpipe_slurp_stream));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
197
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
198 /* This function is thread-safe, and is called from either thread
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
199 context. It serializes freeing shared dtata structure */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
200 static void
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
201 slurper_free_shared_data_maybe (struct ntpipe_slurp_stream_shared_data* s)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
202 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
203 if (InterlockedDecrement (&s->lock_count) == 0)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
204 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
205 /* Destroy events */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
206 CloseHandle (s->hev_thread);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
207 CloseHandle (s->hev_caller);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
208 CloseHandle (s->hev_unsleep);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
209 s->inuse_p = 0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
210 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
211 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
212
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
213 static struct ntpipe_slurp_stream_shared_data*
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
214 slurper_allocate_shared_data()
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
215 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
216 int i=0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
217 for (i=0; i<MAX_SLURP_STREAMS; i++)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
218 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
219 if (!shared_data_block[i].inuse_p)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
220 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
221 shared_data_block[i].inuse_p=1;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
222 return &shared_data_block[i];
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
223 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
224 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
225 return (struct ntpipe_slurp_stream_shared_data*)0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
226 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
227
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
228 static DWORD WINAPI
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
229 slurp_thread (LPVOID vparam)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
230 {
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
231 struct ntpipe_slurp_stream_shared_data *s =
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
232 (struct ntpipe_slurp_stream_shared_data*)vparam;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
233
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
234 for (;;)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
235 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
236 /* Read one byte from the pipe */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
237 DWORD actually_read;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
238 if (!ReadFile (s->hpipe, &s->onebyte, 1, &actually_read, NULL))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
239 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
240 DWORD err = GetLastError ();
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
241 if (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
242 s->eof_p = TRUE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
243 else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
244 s->error_p = TRUE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
245 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
246 else if (actually_read == 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
247 s->eof_p = TRUE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
248
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
249 /* We must terminate on an error or eof */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
250 if (s->eof_p || s->error_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
251 InterlockedIncrement (&s->die_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
252
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
253 /* Before we notify caller, we unsignal our event. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
254 ResetEvent (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
255
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
256 /* Now we got something to notify caller, either a byte or an
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
257 error/eof indication. Before we do, allow internal pipe
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
258 buffer to accumulate little bit more data.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
259 Reader function pulses this event before waiting for
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
260 a character, to avoid pipe delay, and to get the byte
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
261 immediately. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
262 if (!s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
263 WaitForSingleObject (s->hev_unsleep, PIPE_READ_DELAY);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
264
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
265 /* Either make event loop generate a process event, or
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
266 inblock reader */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
267 SetEvent (s->hev_caller);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
268
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
269 /* Cleanup and exit if we're shot off */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
270 if (s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
271 break;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
272
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
273 /* Block until the client finishes with retireving the rest of
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
274 pipe data */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
275 WaitForSingleObject (s->hev_thread, INFINITE);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
276 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
277
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
278 slurper_free_shared_data_maybe (s);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
279
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
280 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
281 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
282
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
283 static Lisp_Object
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
284 make_ntpipe_input_stream (HANDLE hpipe, LPARAM param)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
285 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
286 Lisp_Object obj;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
287 Lstream *lstr = Lstream_new (lstream_ntpipe_slurp, "r");
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
288 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA (lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
289 DWORD thread_id_unused;
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
290 HANDLE hthread;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
291
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
292 /* We deal only with pipes, for we're using PeekNamedPipe api */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
293 assert (GetFileType (hpipe) == FILE_TYPE_PIPE);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
294
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
295 s->thread_data = slurper_allocate_shared_data();
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
296
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
297 /* Create reader thread. This could fail, so do not create events
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
298 until thread is created */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
299 hthread = CreateThread (NULL, 0, slurp_thread, (LPVOID)s->thread_data,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
300 CREATE_SUSPENDED, &thread_id_unused);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
301 if (hthread == NULL)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
302 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
303 Lstream_delete (lstr);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
304 s->thread_data->inuse_p=0;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
305 return Qnil;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
306 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
307
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
308 /* Shared data are initially owned by both main and slurper
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
309 threads. */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
310 s->thread_data->lock_count = 2;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
311 s->thread_data->die_p = 0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
312 s->thread_data->eof_p = FALSE;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
313 s->thread_data->error_p = FALSE;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
314 s->thread_data->hpipe = hpipe;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
315 s->user_data = param;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
316
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
317 /* hev_thread is a manual-reset event, initially signaled */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
318 s->thread_data->hev_thread = CreateEvent (NULL, TRUE, TRUE, NULL);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
319 /* hev_caller is a manual-reset event, initially nonsignaled */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
320 s->thread_data->hev_caller = CreateEvent (NULL, TRUE, FALSE, NULL);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
321 /* hev_unsleep is a manual-reset event, initially nonsignaled */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
322 s->thread_data->hev_unsleep = CreateEvent (NULL, TRUE, FALSE, NULL);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
323
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
324 /* Now let it go */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
325 ResumeThread (hthread);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
326 CloseHandle (hthread);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
327
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
328 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
329 XSETLSTREAM (obj, lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
330 return obj;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
331 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
332
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
333 static LPARAM
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
334 get_ntpipe_input_stream_param (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
335 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
336 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
337 return s->user_data;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
338 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
339
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
340 static HANDLE
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
341 get_ntpipe_input_stream_waitable (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
342 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
343 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA(stream);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
344 return s->thread_data->hev_caller;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
345 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
346
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
347 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
348 ntpipe_slurp_reader (Lstream *stream, unsigned char *data, size_t size)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
349 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
350 /* This function must be called from the main thread only */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
351 struct ntpipe_slurp_stream_shared_data* s =
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
352 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
353
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
354 if (!s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
355 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
356 DWORD wait_result;
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
357 /* Disallow pipe read delay for the thread: we need a character
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
358 ASAP */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
359 SetEvent (s->hev_unsleep);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
360
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
361 /* Check if we have a character ready. Give it a short delay,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
362 for the thread to awake from pipe delay, just ion case*/
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
363 wait_result = WaitForSingleObject (s->hev_caller, 2);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
364
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
365 /* Revert to the normal sleep behavior. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
366 ResetEvent (s->hev_unsleep);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
367
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
368 /* If there's no byte buffered yet, give up */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
369 if (wait_result == WAIT_TIMEOUT)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
370 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
371 errno = EAGAIN;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
372 return -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
373 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
374 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
375
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
376 /* Reset caller unlock event now, as we've handled the pending
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
377 process output event */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
378 ResetEvent (s->hev_caller);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
379
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
380 /* It is now safe to do anything with contents of S, except for
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
381 changing s->die_p, which still should be interlocked */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
382
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
383 if (s->eof_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
384 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
385 if (s->error_p || s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
386 return -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
387
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
388 /* Ok, there were no error neither eof - we've got a byte from the
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
389 pipe */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
390 *(data++) = s->onebyte;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
391 --size;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
392
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
393 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
394 DWORD bytes_read = 0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
395 if (size > 0)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
396 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
397 DWORD bytes_available;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
398
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
399 /* If the api call fails, return at least one byte already
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
400 read. ReadFile in thread will return error */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
401 if (PeekNamedPipe (s->hpipe, NULL, 0, NULL, &bytes_available, NULL))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
402 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
403
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
404 /* Fetch available bytes. The same consideration applies,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
405 so do not check for errors. ReadFile in the thread will
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
406 fail if the next call fails. */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
407 if (bytes_available)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
408 ReadFile (s->hpipe, data, min (bytes_available, size),
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
409 &bytes_read, NULL);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
410 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
411
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
412 /* Now we can unblock thread, so it attempts to read more */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
413 SetEvent (s->hev_thread);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
414 return bytes_read + 1;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
415 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
416 }
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
417 return 0;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
418 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
419
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
420 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
421 ntpipe_slurp_closer (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
422 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
423 /* This function must be called from the main thread only */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
424 struct ntpipe_slurp_stream_shared_data* s =
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
425 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
426
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
427 /* Force thread to stop */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
428 InterlockedIncrement (&s->die_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
429
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
430 /* Set events which could possibly block slurper. Let it finish soon
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
431 or later. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
432 SetEvent (s->hev_unsleep);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
433 SetEvent (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
434
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
435 /* Unlock and maybe free shared data */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
436 slurper_free_shared_data_maybe (s);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
437
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
438 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
439 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
440
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
441 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
442 init_slurp_stream (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
443 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
444 LSTREAM_HAS_METHOD (ntpipe_slurp, reader);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
445 LSTREAM_HAS_METHOD (ntpipe_slurp, closer);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
446 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
447
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
448 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
449 /* Pipe outstream - writes process input */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
450 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
451
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
452 #define NTPIPE_SHOVE_STREAM_DATA(stream) \
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
453 LSTREAM_TYPE_DATA (stream, ntpipe_shove)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
454
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
455 #define MAX_SHOVE_BUFFER_SIZE 128
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
456
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
457 struct ntpipe_shove_stream
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
458 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
459 LPARAM user_data; /* Any user data stored in the stream object */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
460 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
461 /* This is an auto-reset object. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
462 HANDLE hpipe; /* Pipe write end handle. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
463 HANDLE hthread; /* Reader thread handle. */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
464 char buffer[MAX_SHOVE_BUFFER_SIZE]; /* Buffer being written */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
465 DWORD size; /* Number of bytes to write */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
466 LONG die_p; /* Thread must exit ASAP if non-zero */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
467 LONG idle_p; /* Non-zero if thread is waiting for job */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
468 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
469 BOOL blocking_p : 1;/* Last write attempt would cause blocking */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
470 };
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
471
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
472 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-output", lstream_ntpipe_shove,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
473 sizeof (struct ntpipe_shove_stream));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
474
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
475 static DWORD WINAPI
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
476 shove_thread (LPVOID vparam)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
477 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
478 struct ntpipe_shove_stream *s = (struct ntpipe_shove_stream*) vparam;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
479
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
480 for (;;)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
481 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
482 DWORD bytes_written;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
483
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
484 /* Block on event and wait for a job */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
485 InterlockedIncrement (&s->idle_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
486 WaitForSingleObject (s->hev_thread, INFINITE);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
487
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
488 if (s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
489 break;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
490
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
491 /* Write passed buffer */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
492 if (!WriteFile (s->hpipe, s->buffer, s->size, &bytes_written, NULL)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
493 || bytes_written != s->size)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
494 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
495 s->error_p = TRUE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
496 InterlockedIncrement (&s->die_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
497 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
498
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
499 if (s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
500 break;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
501 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
502
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
503 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
504 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
505
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
506 static Lisp_Object
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
507 make_ntpipe_output_stream (HANDLE hpipe, LPARAM param)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
508 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
509 Lisp_Object obj;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
510 Lstream *lstr = Lstream_new (lstream_ntpipe_shove, "w");
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
511 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA (lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
512 DWORD thread_id_unused;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
513
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
514 s->die_p = 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
515 s->error_p = FALSE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
516 s->hpipe = hpipe;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
517 s->user_data = param;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
518
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
519 /* Create reader thread. This could fail, so do not
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
520 create the event until thread is created */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
521 s->hthread = CreateThread (NULL, 0, shove_thread, (LPVOID)s,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
522 CREATE_SUSPENDED, &thread_id_unused);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
523 if (s->hthread == NULL)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
524 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
525 Lstream_delete (lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
526 return Qnil;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
527 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
528
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
529 /* hev_thread is an auto-reset event, initially nonsignaled */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
530 s->hev_thread = CreateEvent (NULL, FALSE, FALSE, NULL);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
531
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
532 /* Now let it go */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
533 ResumeThread (s->hthread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
534
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
535 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
536 XSETLSTREAM (obj, lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
537 return obj;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
538 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
539
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
540 static LPARAM
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
541 get_ntpipe_output_stream_param (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
542 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
543 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
544 return s->user_data;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
545 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
546
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
547 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
548 ntpipe_shove_writer (Lstream *stream, const unsigned char *data, size_t size)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
549 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
550 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
551
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
552 if (s->error_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
553 return -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
554
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
555 s->blocking_p = !s->idle_p;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
556 if (s->blocking_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
557 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
558
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
559 if (size>MAX_SHOVE_BUFFER_SIZE)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
560 return 0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
561
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
562 memcpy (s->buffer, data, size);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
563 s->size = size;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
564
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
565 /* Start output */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
566 InterlockedDecrement (&s->idle_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
567 SetEvent (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
568 return size;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
569 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
570
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
571 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
572 ntpipe_shove_was_blocked_p (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
573 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
574 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
575 return s->blocking_p;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
576 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
577
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
578 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
579 ntpipe_shove_closer (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
580 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
581 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
582
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
583 /* Force thread stop */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
584 InterlockedIncrement (&s->die_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
585
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
586 /* Close pipe handle, possibly breaking it */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
587 CloseHandle (s->hpipe);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
588
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
589 /* Thread will end upon unblocking */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
590 SetEvent (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
591
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
592 /* Wait while thread terminates */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
593 WaitForSingleObject (s->hthread, INFINITE);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
594 CloseHandle (s->hthread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
595
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
596 /* Destroy the event */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
597 CloseHandle (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
598
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
599 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
600 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
601
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
602 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
603 init_shove_stream (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
604 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
605 LSTREAM_HAS_METHOD (ntpipe_shove, writer);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
606 LSTREAM_HAS_METHOD (ntpipe_shove, was_blocked_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
607 LSTREAM_HAS_METHOD (ntpipe_shove, closer);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
608 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
609
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
610 /************************************************************************/
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
611 /* Winsock I/O stream */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
612 /************************************************************************/
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
613 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
614
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
615 #define WINSOCK_READ_BUFFER_SIZE 1024
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
616
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
617 struct winsock_stream
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
618 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
619 LPARAM user_data; /* Any user data stored in the stream object */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
620 SOCKET s; /* Socket handle (which is a Win32 handle) */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
621 OVERLAPPED ov; /* Overlapped I/O structure */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
622 void* buffer; /* Buffer. Allocated for input stream only */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
623 unsigned int bufsize; /* Number of bytes last read */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
624 unsigned int bufpos; /* Psition in buffer for next fetch */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
625 unsigned int error_p :1; /* I/O Error seen */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
626 unsigned int eof_p :1; /* EOF Error seen */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
627 unsigned int pending_p :1; /* There is a pending I/O operation */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
628 unsigned int blocking_p :1; /* Last write attempt would block */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
629 };
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
630
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
631 #define WINSOCK_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, winsock)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
632
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
633 DEFINE_LSTREAM_IMPLEMENTATION ("winsock", lstream_winsock,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
634 sizeof (struct winsock_stream));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
635
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
636 static void
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
637 winsock_initiate_read (struct winsock_stream *str)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
638 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
639 ResetEvent (str->ov.hEvent);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
640 str->bufpos = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
641
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
642 if (!ReadFile ((HANDLE)str->s, str->buffer, WINSOCK_READ_BUFFER_SIZE,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
643 &str->bufsize, &str->ov))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
644 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
645 if (GetLastError () == ERROR_IO_PENDING)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
646 str->pending_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
647 else if (GetLastError () == ERROR_HANDLE_EOF)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
648 str->eof_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
649 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
650 str->error_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
651 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
652 else if (str->bufsize == 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
653 str->eof_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
654 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
655
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
656 static int
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
657 winsock_reader (Lstream *stream, unsigned char *data, size_t size)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
658 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
659 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
660
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
661 /* If the current operation is not yet complete, there's nothing to
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
662 give back */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
663 if (str->pending_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
664 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
665 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
666 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
667 errno = EAGAIN;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
668 return -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
669 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
670 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
671 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
672 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &str->bufsize, TRUE))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
673 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
674 if (GetLastError() == ERROR_HANDLE_EOF)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
675 str->bufsize = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
676 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
677 str->error_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
678 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
679 if (str->bufsize == 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
680 str->eof_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
681 str->pending_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
682 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
683 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
684
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
685 if (str->eof_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
686 return 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
687 if (str->error_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
688 return -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
689
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
690 /* Return as much of buffer as we have */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
691 size = min (size, (size_t) (str->bufsize - str->bufpos));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
692 memcpy (data, (void*)((BYTE*)str->buffer + str->bufpos), size);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
693 str->bufpos += size;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
694
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
695 /* Read more if buffer is exhausted */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
696 if (str->bufsize == str->bufpos)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
697 winsock_initiate_read (str);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
698
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
699 return size;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
700 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
701
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
702 static int
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
703 winsock_writer (Lstream *stream, CONST unsigned char *data, size_t size)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
704 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
705 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
706
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
707 if (str->pending_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
708 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
709 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
710 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
711 str->blocking_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
712 return -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
713 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
714 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
715 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
716 DWORD dw_unused;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
717 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &dw_unused, TRUE))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
718 str->error_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
719 str->pending_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
720 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
721 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
722
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
723 str->blocking_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
724
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
725 if (str->error_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
726 return -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
727
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
728 if (size == 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
729 return 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
730
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
731 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
732 ResetEvent (str->ov.hEvent);
314
341dac730539 Import from CVS: tag r21-0b55
cvs
parents: 308
diff changeset
733
341dac730539 Import from CVS: tag r21-0b55
cvs
parents: 308
diff changeset
734 /* Docs indicate that 4th parameter to WriteFile can be NULL since this is
341dac730539 Import from CVS: tag r21-0b55
cvs
parents: 308
diff changeset
735 * an overlapped operation. This fails on Win95 with winsock 1.x so we
341dac730539 Import from CVS: tag r21-0b55
cvs
parents: 308
diff changeset
736 * supply a spare address which is ignored by Win95 anyway. Sheesh. */
341dac730539 Import from CVS: tag r21-0b55
cvs
parents: 308
diff changeset
737 if (WriteFile ((HANDLE)str->s, data, size, (LPDWORD)&str->buffer, &str->ov)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
738 || GetLastError() == ERROR_IO_PENDING)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
739 str->pending_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
740 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
741 str->error_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
742 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
743
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
744 return str->error_p ? -1 : size;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
745 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
746
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
747 static int
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
748 winsock_closer (Lstream *lstr)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
749 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
750 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
751
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
752 if (lstr->flags & LSTREAM_FL_READ)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
753 shutdown (str->s, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
754 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
755 shutdown (str->s, 1);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
756
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
757 CloseHandle ((HANDLE)str->s);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
758 if (str->pending_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
759 WaitForSingleObject (str->ov.hEvent, INFINITE);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
760
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
761 if (lstr->flags & LSTREAM_FL_READ)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
762 xfree (str->buffer);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
763
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
764 CloseHandle (str->ov.hEvent);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
765 return 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
766 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
767
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
768 static int
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
769 winsock_was_blocked_p (Lstream *stream)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
770 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
771 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
772 return str->blocking_p;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
773 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
774
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
775 static Lisp_Object
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
776 make_winsock_stream_1 (SOCKET s, LPARAM param, CONST char *mode)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
777 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
778 Lisp_Object obj;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
779 Lstream *lstr = Lstream_new (lstream_winsock, mode);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
780 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
781
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
782 str->s = s;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
783 str->blocking_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
784 str->error_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
785 str->eof_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
786 str->pending_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
787 str->user_data = param;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
788
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
789 xzero (str->ov);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
790 str->ov.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
791
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
792 if (lstr->flags & LSTREAM_FL_READ)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
793 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
794 str->buffer = xmalloc (WINSOCK_READ_BUFFER_SIZE);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
795 winsock_initiate_read (str);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
796 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
797
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
798 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
799 XSETLSTREAM (obj, lstr);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
800 return obj;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
801 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
802
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
803 static Lisp_Object
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
804 make_winsock_input_stream (SOCKET s, LPARAM param)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
805 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
806 return make_winsock_stream_1 (s, param, "r");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
807 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
808
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
809 static Lisp_Object
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
810 make_winsock_output_stream (SOCKET s, LPARAM param)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
811 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
812 return make_winsock_stream_1 (s, param, "w");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
813 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
814
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
815 static HANDLE
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
816 get_winsock_stream_waitable (Lstream *lstr)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
817 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
818 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
819 return str->ov.hEvent;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
820 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
821
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
822 static LPARAM
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
823 get_winsock_stream_param (Lstream *lstr)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
824 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
825 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
826 return str->user_data;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
827 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
828
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
829 static void
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
830 init_winsock_stream (void)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
831 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
832 LSTREAM_HAS_METHOD (winsock, reader);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
833 LSTREAM_HAS_METHOD (winsock, writer);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
834 LSTREAM_HAS_METHOD (winsock, closer);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
835 LSTREAM_HAS_METHOD (winsock, was_blocked_p);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
836 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
837 #endif /* defined (HAVE_SOCKETS) */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
838
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
839 /************************************************************************/
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
840 /* Dispatch queue management */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
841 /************************************************************************/
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
842
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
843 static int
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
844 mswindows_user_event_p (struct Lisp_Event* sevt)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
845 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
846 return (sevt->event_type == key_press_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
847 || sevt->event_type == button_press_event
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
848 || sevt->event_type == button_release_event
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
849 || sevt->event_type == misc_user_event);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
850 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
851
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
852 /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
853 * Add an emacs event to the proper dispatch queue
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
854 */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
855 static void
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
856 mswindows_enqueue_dispatch_event (Lisp_Object event)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
857 {
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
858 int user_p = mswindows_user_event_p (XEVENT(event));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
859 enqueue_event (event,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
860 user_p ? &mswindows_u_dispatch_event_queue :
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
861 &mswindows_s_dispatch_event_queue,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
862 user_p ? &mswindows_u_dispatch_event_queue_tail :
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
863 &mswindows_s_dispatch_event_queue_tail);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
864
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
865 /* Avoid blocking on WaitMessage */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
866 PostMessage (NULL, XM_BUMPQUEUE, 0, 0);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
867 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
868
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
869 /*
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
870 * Add a misc-user event to the dispatch queue.
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
871 *
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
872 * Stuff it into our own dispatch queue, so we have something
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
873 * to return from next_event callback.
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
874 */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
875 void
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
876 mswindows_enqueue_misc_user_event (Lisp_Object channel, Lisp_Object function,
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
877 Lisp_Object object)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
878 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
879 Lisp_Object event = Fmake_event (Qnil, Qnil);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
880 struct Lisp_Event* e = XEVENT (event);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
881
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
882 e->event_type = misc_user_event;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
883 e->channel = channel;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
884 e->event.misc.function = function;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
885 e->event.misc.object = object;
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
886
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
887 mswindows_enqueue_dispatch_event (event);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
888 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
889
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
890 void
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
891 mswindows_enqueue_magic_event (HWND hwnd, UINT message)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
892 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
893 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
894 struct Lisp_Event* event = XEVENT (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
895
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
896 event->channel = hwnd ? mswindows_find_frame (hwnd) : Qnil;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
897 event->timestamp = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
898 event->event_type = magic_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
899 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
900
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
901 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
902 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
903
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
904 static void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
905 mswindows_enqueue_process_event (struct Lisp_Process* p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
906 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
907 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
908 struct Lisp_Event* event = XEVENT (emacs_event);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
909 Lisp_Object process;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
910 XSETPROCESS (process, p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
911
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
912 event->event_type = process_event;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
913 event->timestamp = GetTickCount ();
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
914 event->event.process.process = process;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
915
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
916 mswindows_enqueue_dispatch_event (emacs_event);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
917 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
918
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
919 static void
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
920 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT message, POINTS where, DWORD when)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
921 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
922
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
923 /* We always use last message time, because mouse button
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
924 events may get delayed, and XEmacs double click
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
925 recognition will fail */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
926
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
927 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
928 struct Lisp_Event* event = XEVENT(emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
929
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
930 event->channel = mswindows_find_frame(hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
931 event->timestamp = when;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
932 event->event.button.button =
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
933 (message==WM_LBUTTONDOWN || message==WM_LBUTTONUP) ? 1 :
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
934 ((message==WM_RBUTTONDOWN || message==WM_RBUTTONUP) ? 3 : 2);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
935 event->event.button.x = where.x;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
936 event->event.button.y = where.y;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
937 event->event.button.modifiers = mswindows_modifier_state (NULL, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
938
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
939 if (message==WM_LBUTTONDOWN || message==WM_MBUTTONDOWN ||
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
940 message==WM_RBUTTONDOWN)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
941 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
942 event->event_type = button_press_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
943 SetCapture (hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
944 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
945 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
946 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
947 event->event_type = button_release_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
948 ReleaseCapture ();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
949 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
950
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
951 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
952 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
953
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
954 static void
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
955 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
956 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
957 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
958 struct Lisp_Event* event = XEVENT(emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
959
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
960 event->channel = mswindows_find_console(hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
961 event->timestamp = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
962 event->event_type = key_press_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
963 event->event.key.keysym = keysym;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
964 event->event.key.modifiers = mods;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
965 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
966 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
967
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
968 /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
969 * Remove and return the first emacs event on the dispatch queue.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
970 * Give a preference to user events over non-user ones.
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
971 */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
972 static Lisp_Object
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
973 mswindows_dequeue_dispatch_event ()
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
974 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
975 Lisp_Object event;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
976 struct Lisp_Event* sevt;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
977
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
978 assert (!NILP(mswindows_u_dispatch_event_queue) ||
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
979 !NILP(mswindows_s_dispatch_event_queue));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
980
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
981 event = dequeue_event (
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
982 NILP(mswindows_u_dispatch_event_queue) ?
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
983 &mswindows_s_dispatch_event_queue :
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
984 &mswindows_u_dispatch_event_queue,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
985 NILP(mswindows_u_dispatch_event_queue) ?
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
986 &mswindows_s_dispatch_event_queue_tail :
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
987 &mswindows_u_dispatch_event_queue_tail);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
988
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
989 sevt = XEVENT(event);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
990 if (sevt->event_type == key_press_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
991 && (sevt->event.key.modifiers & FAKE_MOD_QUIT))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
992 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
993 sevt->event.key.modifiers &= ~FAKE_MOD_QUIT;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
994 --mswindows_quit_chars_count;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
995 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
996
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
997 return event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
998 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
999
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1000 /*
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1001 * Remove and return the first emacs event on the dispatch queue that matches
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1002 * the supplied event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1003 * Timeout event matches if interval_id equals to that of the given event.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1004 * Keypress event matches if logical AND between modifiers bitmask of the
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1005 * event in the queue and that of the given event is non-zero
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1006 * For all other event types, this function asserts.
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1007 */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1008
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1009 Lisp_Object
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1010 mswindows_cancel_dispatch_event (struct Lisp_Event* match)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1011 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1012 Lisp_Object event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1013 Lisp_Object previous_event=Qnil;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1014 int user_p = mswindows_user_event_p (match);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1015 Lisp_Object* head = user_p ? &mswindows_u_dispatch_event_queue :
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1016 &mswindows_s_dispatch_event_queue;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1017 Lisp_Object* tail = user_p ? &mswindows_u_dispatch_event_queue_tail :
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1018 &mswindows_s_dispatch_event_queue_tail;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1019
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1020 assert (match->event_type == timeout_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1021 || match->event_type == key_press_event);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1022
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1023 EVENT_CHAIN_LOOP (event, *head)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1024 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1025 int found = 1;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1026 if (XEVENT_TYPE (event) != match->event_type)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1027 found = 0;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1028 if (found && match->event_type == timeout_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1029 && (XEVENT(event)->event.timeout.interval_id !=
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1030 match->event.timeout.interval_id))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1031 found = 0;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1032 if (found && match->event_type == key_press_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1033 && ((XEVENT(event)->event.key.modifiers &
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1034 match->event.key.modifiers) == 0))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1035 found = 0;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1036
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1037 if (found)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1038 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1039 if (NILP (previous_event))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1040 dequeue_event (head, tail);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1041 else
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1042 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1043 XSET_EVENT_NEXT (previous_event, XEVENT_NEXT (event));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1044 if (EQ (*tail, event))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1045 *tail = previous_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1046 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1047
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1048 return event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1049 }
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1050 previous_event = event;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1051 }
239
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 233
diff changeset
1052 return Qnil;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1053 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1054
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1055 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1056 /* Waitable handles manipulation */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1057 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1058 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1059 find_waitable_handle (HANDLE h)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1060 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1061 int i;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1062 for (i = 0; i < mswindows_waitable_count; ++i)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1063 if (mswindows_waitable_handles[i] == h)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1064 return i;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1065
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1066 return -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1067 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1068
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1069 static BOOL
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1070 add_waitable_handle (HANDLE h)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1071 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1072 assert (find_waitable_handle (h) < 0);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1073 if (mswindows_waitable_count == MAX_WAITABLE)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1074 return FALSE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1075
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1076 mswindows_waitable_handles [mswindows_waitable_count++] = h;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1077 return TRUE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1078 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1079
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1080 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1081 remove_waitable_handle (HANDLE h)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1082 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1083 int ix = find_waitable_handle (h);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1084 if (ix < 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1085 return;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1086
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1087 mswindows_waitable_handles [ix] =
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1088 mswindows_waitable_handles [--mswindows_waitable_count];
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1089 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1090
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1091
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1092 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1093 /* Event pump */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1094 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1095
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1096 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1097 mswindows_modal_loop_error_handler (Lisp_Object cons_sig_data,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1098 Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1099 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1100 mswindows_error_caught_in_modal_loop = cons_sig_data;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1101 return Qunbound;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1102 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1103
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1104 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1105 mswindows_protect_modal_loop (Lisp_Object (*bfun) (Lisp_Object barg),
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1106 Lisp_Object barg)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1107 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1108 Lisp_Object tmp;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1109
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1110 ++mswindows_in_modal_loop;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1111 tmp = condition_case_1 (Qt,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1112 bfun, barg,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1113 mswindows_modal_loop_error_handler, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1114 --mswindows_in_modal_loop;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1115
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1116 return tmp;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1117 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1118
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1119 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1120 mswindows_unmodalize_signal_maybe (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1121 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1122 if (!NILP (mswindows_error_caught_in_modal_loop))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1123 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1124 /* Got an error while messages were pumped while
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1125 in window procedure - have to resignal */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1126 Lisp_Object sym = XCAR (mswindows_error_caught_in_modal_loop);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1127 Lisp_Object data = XCDR (mswindows_error_caught_in_modal_loop);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1128 mswindows_error_caught_in_modal_loop = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1129 Fsignal (sym, data);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1130 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1131 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1132
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1133 /*
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1134 * This is an unsafe part of event pump, guarded by
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1135 * condition_case. See mswindows_pump_outstanding_events
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1136 */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1137 static Lisp_Object
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1138 mswindows_unsafe_pump_events (Lisp_Object u_n_u_s_e_d)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1139 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1140 /* This function can call lisp */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1141 Lisp_Object event = Fmake_event (Qnil, Qnil);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1142 struct gcpro gcpro1;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1143 int do_redisplay = 0;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1144 GCPRO1 (event);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1145
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1146 while (detect_input_pending ())
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1147 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1148 Fnext_event (event, Qnil);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1149 Fdispatch_event (event);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1150 do_redisplay = 1;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1151 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1152
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1153 if (do_redisplay)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1154 redisplay ();
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1155
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1156 Fdeallocate_event (event);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1157 UNGCPRO;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1158
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1159 /* Qt becomes return value of mswindows_pump_outstanding_events
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1160 once we get here */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1161 return Qt;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1162 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1163
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1164 /*
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1165 * This function pumps emacs events, while available, by using
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1166 * next_message/dispatch_message loop. Errors are trapped around
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1167 * the loop so the function always returns.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1168 *
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1169 * Windows message queue is not looked into during the call,
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1170 * neither are waitable handles checked. The function pumps
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1171 * thus only dispatch events already queued, as well as those
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1172 * resulted in dispatching thereof. This is done by setting
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1173 * module local variable mswidows_in_modal_loop to nonzero.
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1174 *
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1175 * Return value is Qt if no errors was trapped, or Qunbound if
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1176 * there was an error.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1177 *
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1178 * In case of error, a cons representing the error, in the
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1179 * form (SIGNAL . DATA), is stored in the module local variable
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1180 * mswindows_error_caught_in_modal_loop. This error is signaled
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1181 * again when DispatchMessage returns. Thus, Windows internal
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1182 * modal loops are protected against throws, which are proven
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1183 * to corrupt internal Windows structures.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1184 *
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1185 * In case of success, mswindows_error_caught_in_modal_loop is
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1186 * assigned Qnil.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1187 *
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1188 * If the value of mswindows_error_caught_in_modal_loop is not
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1189 * nil already upon entry, the function just returns non-nil.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1190 * This situation means that a new event has been queued while
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1191 * cancleng mode. The event will be dequeued on the next regular
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1192 * call of next-event; the pump is off since error is caught.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1193 * The caller must *unconditionally* cancel modal loop if the
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1194 * value returned by this function is nil. Otherwise, everything
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1195 * will become frozen until the modal loop exits under normal
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1196 * condition (scrollbar drag is released, menu closed etc.)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1197 */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1198 Lisp_Object
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1199 mswindows_pump_outstanding_events (void)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1200 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1201 /* This function can call lisp */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1202
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1203 Lisp_Object result = Qt;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1204 struct gcpro gcpro1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1205 GCPRO1 (result);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1206
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1207 if (NILP(mswindows_error_caught_in_modal_loop))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1208 result = mswindows_protect_modal_loop (mswindows_unsafe_pump_events, Qnil);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1209 UNGCPRO;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1210 return result;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1211 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1212
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1213 static void
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1214 mswindows_drain_windows_queue ()
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1215 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1216 MSG msg;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1217 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1218 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1219 DispatchMessage (&msg);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1220 mswindows_unmodalize_signal_maybe ();
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1221 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1222 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1223
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1224 /*
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1225 * This is a special flavour of the mswindows_need_event function,
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1226 * used while in event pump. Actually, there is only kind of events
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1227 * allowed while in event pump: a timer. An attempt to fetch any
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1228 * other event leads to a dealock, as there's no source of user input
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1229 * ('cause event pump mirrors windows modal loop, which is a sole
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1230 * owner of thread message queue).
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1231 *
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1232 * To detect this, we use a counter of active timers, and allow
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1233 * fetching WM_TIMER messages. Instead of trying to fetch a WM_TIMER
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1234 * which will never come when there are no pending timers, which leads
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1235 * to deadlock, we simply signal an error.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1236 */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1237 static void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1238 mswindows_need_event_in_modal_loop (int badly_p)
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1239 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1240 MSG msg;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1241
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1242 /* Check if already have one */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1243 if (!NILP (mswindows_u_dispatch_event_queue)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1244 || !NILP (mswindows_s_dispatch_event_queue))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1245 return;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1246
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1247 /* No event is ok */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1248 if (!badly_p)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1249 return;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1250
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1251 /* We do not check the _u_ queue, because timers go to _s_ */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1252 while (NILP (mswindows_s_dispatch_event_queue))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1253 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1254 /* We'll deadlock if go waiting */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1255 if (mswindows_pending_timers_count == 0)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1256 error ("Deadlock due to an attempt to call next-event in a wrong context");
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1257
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1258 /* Fetch and dispatch any pending timers */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1259 GetMessage (&msg, NULL, WM_TIMER, WM_TIMER);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1260 DispatchMessage (&msg);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1261 }
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1262 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1263
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1264 /*
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1265 * This drains the event queue and fills up two internal queues until
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1266 * an event of a type specified by USER_P is retrieved.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1267 *
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1268 *
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1269 * Used by emacs_mswindows_event_pending_p and emacs_mswindows_next_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1270 */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1271 static void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1272 mswindows_need_event (int badly_p)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1273 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1274 int active;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1275
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1276 if (mswindows_in_modal_loop)
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1277 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1278 mswindows_need_event_in_modal_loop (badly_p);
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1279 return;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1280 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1281
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1282 /* Have to drain Windows message queue first, otherwise, we may miss
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1283 quit char when called from quit_p */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1284 mswindows_drain_windows_queue ();
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1285
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1286 while (NILP (mswindows_u_dispatch_event_queue)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1287 && NILP (mswindows_s_dispatch_event_queue))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1288 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1289 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1290 int i;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1291 SELECT_TYPE temp_mask = input_wait_mask;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1292 EMACS_TIME sometime;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1293 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1294
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1295 if (badly_p)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1296 pointer_to_this = 0;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1297 else
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1298 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1299 EMACS_SET_SECS_USECS (sometime, 0, 0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1300 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1301 pointer_to_this = &select_time_to_block;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1302 }
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1303
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1304 /* select() is slow and buggy so if we don't have any processes
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1305 just wait as normal */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1306 if (memcmp (&process_only_mask, &zero_mask, sizeof(SELECT_TYPE))==0)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1307 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1308 /* Now try getting a message or process event */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1309 active = MsgWaitForMultipleObjects (0, mswindows_waitable_handles,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1310 FALSE, badly_p ? INFINITE : 0,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1311 QS_ALLINPUT);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1312
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1313 if (active == WAIT_TIMEOUT)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1314 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1315 /* No luck trying - just return what we've already got */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1316 return;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1317 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1318 else if (active == WAIT_OBJECT_0)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1319 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1320 /* Got your message, thanks */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1321 mswindows_drain_windows_queue ();
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1322 continue;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1323 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1324 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1325
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1326 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1327
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1328 if (active == 0)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1329 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1330 return; /* timeout */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1331 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1332 else if (active > 0)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1333 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1334 if (FD_ISSET (windows_fd, &temp_mask))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1335 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1336 mswindows_drain_windows_queue ();
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1337 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1338
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1339 /* Look for a process event */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1340 for (i = 0; i < MAXDESC-1; i++)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1341 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1342 if (FD_ISSET (i, &temp_mask))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1343 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1344 if (FD_ISSET (i, &process_only_mask))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1345 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1346 struct Lisp_Process *p =
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1347 get_process_from_usid (FD_TO_USID(i));
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1348
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1349 mswindows_enqueue_process_event (p);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1350 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1351 else if (FD_ISSET (i, &tty_only_mask))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1352 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1353 /* do we care about tty events? Do we
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1354 ever get tty events? */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1355 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1356 else
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1357 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1358 /* We might get here when a fake event came
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1359 through a signal. Return a dummy event, so
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1360 that a cycle of the command loop will
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1361 occur. */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1362 drain_signal_event_pipe ();
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1363 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1364 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1365 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1366 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1367 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1368 else if (active==-1)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1369 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1370 if (errno != EINTR)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1371 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1372 /* something bad happended */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1373 assert(0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1374 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1375 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1376 else
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1377 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1378 assert(0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1379 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1380 #else
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1381 /* Now try getting a message or process event */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1382 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1383 mswindows_waitable_handles,
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1384 FALSE, badly_p ? INFINITE : 0,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1385 QS_ALLINPUT);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1386
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1387 /* This will assert if handle being waited for becomes abandoned.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1388 Not the case currently tho */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1389 assert ((!badly_p && active == WAIT_TIMEOUT) ||
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1390 (active >= WAIT_OBJECT_0 &&
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1391 active <= WAIT_OBJECT_0 + mswindows_waitable_count));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1392
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1393 if (active == WAIT_TIMEOUT)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1394 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1395 /* No luck trying - just return what we've already got */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1396 return;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1397 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1398 else if (active == WAIT_OBJECT_0 + mswindows_waitable_count)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1399 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1400 /* Got your message, thanks */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1401 mswindows_drain_windows_queue ();
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1402 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1403 else
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1404 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1405 int ix = active - WAIT_OBJECT_0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1406 /* First, try to find which process' ouptut has signaled */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1407 struct Lisp_Process *p =
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1408 get_process_from_usid (HANDLE_TO_USID (mswindows_waitable_handles[ix]));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1409 if (p != NULL)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1410 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1411 /* Found a signaled process input handle */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1412 mswindows_enqueue_process_event (p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1413 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1414 else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1415 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1416 /* None. This means that the process handle itself has signaled.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1417 Remove the handle from the wait vector, and make status_ntoify
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1418 note the exited process */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1419 mswindows_waitable_handles [ix] =
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1420 mswindows_waitable_handles [--mswindows_waitable_count];
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1421 kick_status_notify ();
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
1422 /* Have to return something: there may be no accompanying
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
1423 process event */
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1424 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1425 }
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1426 }
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1427 #endif
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1428 } /* while */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1429 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1430
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1431 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1432 /* Event generators */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1433 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1434
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1435 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1436 * Callback procedure for synchronous timer messages
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1437 */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1438 static void CALLBACK
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1439 mswindows_wm_timer_callback (HWND hwnd, UINT umsg, UINT id_timer, DWORD dwtime)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1440 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1441 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1442 struct Lisp_Event *event = XEVENT (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1443
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1444 if (KillTimer (NULL, id_timer))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1445 --mswindows_pending_timers_count;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1446
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1447 event->channel = Qnil;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1448 event->timestamp = dwtime;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1449 event->event_type = timeout_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1450 event->event.timeout.interval_id = id_timer;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1451
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1452 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1453 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1454
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1455 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1456 * Callback procedure for dde messages
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1457 *
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1458 * We execute a dde Open("file") by simulating a file drop, so dde support
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1459 * depends on dnd support.
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1460 */
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1461 #ifdef HAVE_DRAGNDROP
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1462 HDDEDATA CALLBACK
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1463 mswindows_dde_callback (UINT uType, UINT uFmt, HCONV hconv,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1464 HSZ hszTopic, HSZ hszItem, HDDEDATA hdata,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1465 DWORD dwData1, DWORD dwData2)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1466 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1467 switch (uType)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1468 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1469 case XTYP_CONNECT:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1470 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1471 return (HDDEDATA)TRUE;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1472 return (HDDEDATA)FALSE;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1473
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1474 case XTYP_WILDCONNECT:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1475 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1476 /* We only support one {service,topic} pair */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1477 HSZPAIR pairs[2] = {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1478 { mswindows_dde_service, mswindows_dde_topic_system }, { 0, 0 } };
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1479
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1480 if (!(hszItem || DdeCmpStringHandles (hszItem, mswindows_dde_service)) &&
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1481 !(hszTopic || DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1482 return (DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE)pairs,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1483 sizeof (pairs), 0L, 0, uFmt, 0));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1484 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1485 return (HDDEDATA)NULL;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1486
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1487 case XTYP_EXECUTE:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1488 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1489 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1490 DWORD len = DdeGetData (hdata, NULL, 0, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1491 char *cmd = alloca (len+1);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1492 char *end;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1493 char *filename;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1494 struct gcpro gcpro1, gcpro2;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1495 Lisp_Object l_dndlist = Qnil;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1496 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1497 Lisp_Object frmcons, devcons, concons;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1498 struct Lisp_Event *event = XEVENT (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1499
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1500 DdeGetData (hdata, cmd, len, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1501 cmd[len] = '\0';
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1502 DdeFreeDataHandle (hdata);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1503
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1504 /* Check syntax & that it's an [Open("foo")] command, which we
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1505 * treat like a file drop */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1506 /* #### Ought to be generalised and accept some other commands */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1507 if (*cmd == '[')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1508 cmd++;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1509 if (strnicmp (cmd, MSWINDOWS_DDE_ITEM_OPEN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1510 strlen (MSWINDOWS_DDE_ITEM_OPEN)))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1511 return DDE_FNOTPROCESSED;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1512 cmd += strlen (MSWINDOWS_DDE_ITEM_OPEN);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1513 while (*cmd==' ')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1514 cmd++;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1515 if (*cmd!='(' || *(cmd+1)!='\"')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1516 return DDE_FNOTPROCESSED;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1517 end = (cmd+=2);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1518 while (*end && *end!='\"')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1519 end++;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1520 if (!*end)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1521 return DDE_FNOTPROCESSED;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1522 *end = '\0';
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1523 if (*(++end)!=')')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1524 return DDE_FNOTPROCESSED;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1525 if (*(++end)==']')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1526 end++;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1527 if (*end)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1528 return DDE_FNOTPROCESSED;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1529
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
1530 #ifdef __CYGWIN32__
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1531 filename = alloca (cygwin32_win32_to_posix_path_list_buf_size (cmd) + 5);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1532 strcpy (filename, "file:");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1533 cygwin32_win32_to_posix_path_list (cmd, filename+5);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1534 #else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1535 dostounix_filename (cmd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1536 filename = alloca (strlen (cmd)+6);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1537 strcpy (filename, "file:");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1538 strcat (filename, cmd);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
1539 #endif
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1540 GCPRO2 (emacs_event, l_dndlist);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1541 l_dndlist = make_string (filename, strlen (filename));
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1542
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1543 /* Find a mswindows frame */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1544 event->channel = Qnil;
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1545 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1546 {
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1547 Lisp_Object frame = XCAR (frmcons);
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1548 if (FRAME_TYPE_P (XFRAME (frame), mswindows))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1549 event->channel = frame;
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1550 };
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1551 assert (!NILP (event->channel));
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1552
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1553 event->timestamp = GetTickCount();
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1554 event->event_type = misc_user_event;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1555 event->event.misc.button = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1556 event->event.misc.modifiers = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1557 event->event.misc.x = -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1558 event->event.misc.y = -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1559 event->event.misc.function = Qdragdrop_drop_dispatch;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1560 event->event.misc.object = Fcons (Qdragdrop_URL,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1561 Fcons (l_dndlist, Qnil));
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1562 mswindows_enqueue_dispatch_event (emacs_event);
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1563 UNGCPRO;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1564 return (HDDEDATA) DDE_FACK;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1565 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1566 DdeFreeDataHandle (hdata);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1567 return (HDDEDATA) DDE_FNOTPROCESSED;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1568
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1569 default:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1570 return (HDDEDATA) NULL;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1571 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1572 }
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1573 #endif
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1574
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1575 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1576 * The windows procedure for the window class XEMACS_CLASS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1577 */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1578 LRESULT WINAPI
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1579 mswindows_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1580 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1581 /* Note: Remember to initialise emacs_event and event before use.
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1582 This code calls code that can GC. You must GCPRO before calling such code. */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1583 Lisp_Object emacs_event = Qnil;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1584 Lisp_Object fobj = Qnil;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1585
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1586 struct Lisp_Event *event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1587 struct frame *frame;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1588 struct mswindows_frame* msframe;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1589
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1590 switch (message)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1591 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1592 case WM_ERASEBKGND:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1593 /* Erase background only during non-dynamic sizing */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1594 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1595 if (msframe->sizing && !mswindows_dynamic_frame_resize)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1596 goto defproc;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1597 return 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1598
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1599 case WM_CLOSE:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1600 fobj = mswindows_find_frame (hwnd);
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1601 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1602 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1603
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1604 case WM_KEYUP:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1605 case WM_SYSKEYUP:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1606 /* See Win95 comment under WM_KEYDOWN */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1607 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1608 BYTE keymap[256];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1609
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1610 if (wParam == VK_CONTROL)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1611 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1612 GetKeyboardState (keymap);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1613 keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] &= ~0x80;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1614 SetKeyboardState (keymap);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1615 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1616 else if (wParam == VK_MENU)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1617 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1618 GetKeyboardState (keymap);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1619 keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] &= ~0x80;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1620 SetKeyboardState (keymap);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1621 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1622 };
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1623 goto defproc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1624
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1625 case WM_KEYDOWN:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1626 case WM_SYSKEYDOWN:
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1627 /* In some locales the right-hand Alt key is labelled AltGr. This key
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1628 * should produce alternative charcaters when combined with another key.
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1629 * eg on a German keyboard pressing AltGr+q should produce '@'.
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1630 * AltGr generates exactly the same keystrokes as LCtrl+RAlt. But if
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1631 * TranslateMessage() is called with *any* combination of Ctrl+Alt down,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1632 * it translates as if AltGr were down.
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1633 * We get round this by removing all modifiers from the keymap before
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1634 * calling TranslateMessage() unless AltGr is *really* down. */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1635 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1636 BYTE keymap[256];
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1637 int has_AltGr = mswindows_current_layout_has_AltGr ();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1638 int mods;
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
1639 int extendedp = lParam & 0x1000000;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1640 Lisp_Object keysym;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1641
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1642 GetKeyboardState (keymap);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1643 mods = mswindows_modifier_state (keymap, has_AltGr);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1644
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
1645 /* Handle non-printables */
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
1646 if (!NILP (keysym = mswindows_key_to_emacs_keysym (wParam, mods,
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
1647 extendedp)))
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1648 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
1649 else /* Normal keys & modifiers */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1650 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1651 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1652 BYTE keymap_orig[256];
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1653 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) };
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1654
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1655 /* GetKeyboardState() does not work as documented on Win95. We have
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1656 * to loosely track Left and Right modifiers on behalf of the OS,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1657 * without screwing up Windows NT which tracks them properly. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1658 if (wParam == VK_CONTROL)
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
1659 keymap [extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1660 else if (wParam == VK_MENU)
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
1661 keymap [extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1662
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1663 memcpy (keymap_orig, keymap, 256);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1664
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1665 /* Remove shift modifier from an ascii character */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1666 mods &= ~MOD_SHIFT;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1667
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1668 /* Clear control and alt modifiers unless AltGr is pressed */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1669 keymap [VK_RCONTROL] = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1670 keymap [VK_LMENU] = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1671 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1672 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1673 keymap [VK_LCONTROL] = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1674 keymap [VK_CONTROL] = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1675 keymap [VK_RMENU] = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1676 keymap [VK_MENU] = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1677 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1678 SetKeyboardState (keymap);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1679
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
1680 /* Maybe generate some WM_[SYS]CHARs in the queue */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1681 TranslateMessage (&msg);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1682
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1683 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
1684 || PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE))
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1685 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1686 int mods1 = mods;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
1687 WPARAM ch = msg.wParam;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1688
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1689 /* If a quit char with no modifiers other than control and
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1690 shift, then mark it with a fake modifier, which is removed
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1691 upon dequeueing the event */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1692 /* #### This might also not withstand localization, if
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1693 quit character is not a latin-1 symbol */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1694 if (((quit_ch < ' ' && (mods & MOD_CONTROL) && quit_ch + 'a' - 1 == ch)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1695 || (quit_ch >= ' ' && !(mods & MOD_CONTROL) && quit_ch == ch))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1696 && ((mods & ~(MOD_CONTROL | MOD_SHIFT)) == 0))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1697 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1698 mods1 |= FAKE_MOD_QUIT;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1699 ++mswindows_quit_chars_count;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1700 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1701
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1702 mswindows_enqueue_keypress_event (hwnd, make_char(ch), mods1);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1703 } /* while */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1704 SetKeyboardState (keymap_orig);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1705 } /* else */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1706 }
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1707 /* F10 causes menu activation by default. We do not want this */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1708 if (wParam != VK_F10)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1709 goto defproc;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1710 break;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1711
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1712 case WM_MBUTTONDOWN:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1713 case WM_MBUTTONUP:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1714 /* Real middle mouse button has nothing to do with emulated one:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1715 if one wants to exercise fingers playing chords on the mouse,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1716 he is allowed to do that! */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1717 mswindows_enqueue_mouse_button_event (hwnd, message,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1718 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1719 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1720
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1721 case WM_LBUTTONUP:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1722 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1723 msframe->last_click_time = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1724
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1725 KillTimer (hwnd, BUTTON_2_TIMER_ID);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1726 msframe->button2_need_lbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1727 if (msframe->ignore_next_lbutton_up)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1728 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1729 msframe->ignore_next_lbutton_up = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1730 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1731 else if (msframe->button2_is_down)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1732 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1733 msframe->button2_is_down = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1734 msframe->ignore_next_rbutton_up = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1735 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1736 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1737 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1738 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1739 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1740 if (msframe->button2_need_rbutton)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1741 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1742 msframe->button2_need_rbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1743 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1744 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1745 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1746 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1747 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1748 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1749 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1750
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1751 case WM_RBUTTONUP:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1752 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1753 msframe->last_click_time = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1754
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1755 KillTimer (hwnd, BUTTON_2_TIMER_ID);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1756 msframe->button2_need_rbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1757 if (msframe->ignore_next_rbutton_up)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1758 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1759 msframe->ignore_next_rbutton_up = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1760 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1761 else if (msframe->button2_is_down)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1762 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1763 msframe->button2_is_down = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1764 msframe->ignore_next_lbutton_up = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1765 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1766 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1767 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1768 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1769 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1770 if (msframe->button2_need_lbutton)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1771 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1772 msframe->button2_need_lbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1773 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1774 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1775 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1776 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1777 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1778 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1779 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1780
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1781 case WM_LBUTTONDOWN:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1782 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1783
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1784 if (msframe->button2_need_lbutton)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1785 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1786 KillTimer (hwnd, BUTTON_2_TIMER_ID);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1787 msframe->button2_need_lbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1788 msframe->button2_need_rbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1789 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1790 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1791 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1792 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1793 msframe->button2_is_down = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1794 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1795 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1796 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1797 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1798 msframe->last_click_point, msframe->last_click_time);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1799 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1800 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1801 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1802 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1803 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1804 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1805 mswindows_set_chord_timer (hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1806 msframe->button2_need_rbutton = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1807 msframe->last_click_point = MAKEPOINTS (lParam);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1808 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1809 msframe->last_click_time = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1810 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1811
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1812 case WM_RBUTTONDOWN:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1813 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1814
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1815 if (msframe->button2_need_rbutton)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1816 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1817 KillTimer (hwnd, BUTTON_2_TIMER_ID);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1818 msframe->button2_need_lbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1819 msframe->button2_need_rbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1820 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1821 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1822 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1823 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1824 msframe->button2_is_down = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1825 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1826 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1827 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1828 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1829 msframe->last_click_point, msframe->last_click_time);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1830 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1831 MAKEPOINTS (lParam), GetMessageTime());
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1832 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1833 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1834 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1835 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1836 mswindows_set_chord_timer (hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1837 msframe->button2_need_lbutton = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1838 msframe->last_click_point = MAKEPOINTS (lParam);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1839 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1840 msframe->last_click_time = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1841 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1842
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1843 case WM_TIMER:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1844 if (wParam == BUTTON_2_TIMER_ID)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1845 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1846 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1847 KillTimer (hwnd, BUTTON_2_TIMER_ID);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1848
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1849 if (msframe->button2_need_lbutton)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1850 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1851 msframe->button2_need_lbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1852 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1853 msframe->last_click_point, msframe->last_click_time);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1854 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1855 else if (msframe->button2_need_rbutton)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1856 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1857 msframe->button2_need_rbutton = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1858 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1859 msframe->last_click_point, msframe->last_click_time);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1860 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1861 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1862 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1863 assert ("Spurious timer fired" == 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1864 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1865
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1866 case WM_MOUSEMOVE:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1867 /* Optimization: don't report mouse movement while size is changind */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1868 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1869 if (!msframe->sizing)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1870 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1871 /* When waiting for the second mouse button to finish
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1872 button2 emulation, and have moved too far, just pretend
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1873 as if timer has expired. This impoves drag-select feedback */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1874 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1875 && !mswindows_button2_near_enough (msframe->last_click_point,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1876 MAKEPOINTS (lParam)))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1877 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1878 KillTimer (hwnd, BUTTON_2_TIMER_ID);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1879 SendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1880 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1881
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1882 emacs_event = Fmake_event (Qnil, Qnil);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1883 event = XEVENT(emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1884
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1885 event->channel = mswindows_find_frame(hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1886 event->timestamp = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1887 event->event_type = pointer_motion_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1888 event->event.motion.x = MAKEPOINTS(lParam).x;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1889 event->event.motion.y = MAKEPOINTS(lParam).y;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1890 event->event.motion.modifiers = mswindows_modifier_state (NULL, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1891
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1892 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1893 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1894 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1895
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
1896 case WM_CANCELMODE:
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
1897 ReleaseCapture ();
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
1898 /* Queue a `cancel-mode-internal' misc user event, so mouse
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
1899 selection would be canceled if any */
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
1900 mswindows_enqueue_misc_user_event (mswindows_find_frame (hwnd),
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
1901 Qcancel_mode_internal, Qnil);
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
1902 break;
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
1903
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1904 #ifdef HAVE_TOOLBARS
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1905 case WM_NOTIFY:
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1906 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1907 LPTOOLTIPTEXT tttext = (LPTOOLTIPTEXT)lParam;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1908 Lisp_Object btext;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1909 if (tttext->hdr.code == TTN_NEEDTEXT)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1910 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1911 /* find out which toolbar */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1912 frame = XFRAME (mswindows_find_frame (hwnd));
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1913 btext = mswindows_get_toolbar_button_text ( frame,
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1914 tttext->hdr.idFrom );
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1915
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1916 tttext->lpszText = NULL;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1917 tttext->hinst = NULL;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1918
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1919 if (!NILP(btext))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1920 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1921 /* I think this is safe since the text will only go away
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1922 when the toolbar does...*/
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
1923 tttext->lpszText=XSTRING_DATA (btext);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1924 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1925 #if 0
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1926 tttext->uFlags |= TTF_DI_SETITEM;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1927 #endif
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1928 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1929 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1930 break;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1931 #endif
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1932
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1933 case WM_PAINT:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1934 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1935 PAINTSTRUCT paintStruct;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1936
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1937 frame = XFRAME (mswindows_find_frame (hwnd));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1938
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1939 BeginPaint (hwnd, &paintStruct);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1940 mswindows_redraw_exposed_area (frame,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1941 paintStruct.rcPaint.left, paintStruct.rcPaint.top,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1942 paintStruct.rcPaint.right, paintStruct.rcPaint.bottom);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1943 EndPaint (hwnd, &paintStruct);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1944 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1945 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1946
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1947 case WM_SIZE:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1948 /* We only care about this message if our size has really changed */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1949 if (wParam==SIZE_RESTORED || wParam==SIZE_MAXIMIZED || wParam==SIZE_MINIMIZED)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1950 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1951 RECT rect;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1952 int columns, rows;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1953
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1954 fobj = mswindows_find_frame (hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1955 frame = XFRAME (fobj);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1956 msframe = FRAME_MSWINDOWS_DATA (frame);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1957
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1958 /* We cannot handle frame map and unmap hooks right in
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1959 this routine, because these may throw. We queue
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1960 magic events to run these hooks instead - kkm */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1961
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1962 if (wParam==SIZE_MINIMIZED)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1963 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1964 /* Iconified */
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 290
diff changeset
1965 FRAME_VISIBLE_P (frame) = 0;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1966 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1967 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1968 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1969 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1970 GetClientRect(hwnd, &rect);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1971 FRAME_PIXWIDTH(frame) = rect.right;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1972 FRAME_PIXHEIGHT(frame) = rect.bottom;
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1973
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1974 pixel_to_real_char_size (frame, rect.right, rect.bottom,
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1975 &FRAME_MSWINDOWS_CHARWIDTH (frame),
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1976 &FRAME_MSWINDOWS_CHARHEIGHT (frame));
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1977
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1978 pixel_to_char_size (frame, rect.right, rect.bottom, &columns, &rows);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1979 change_frame_size (frame, rows, columns, 1);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1980
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1981 /* If we are inside frame creation, we have to apply geometric
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1982 properties now. */
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 290
diff changeset
1983 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1984 {
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1985 /* Yes, we have to size again */
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 290
diff changeset
1986 mswindows_size_frame_internal ( frame,
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 290
diff changeset
1987 FRAME_MSWINDOWS_TARGET_RECT
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 290
diff changeset
1988 (frame));
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
1989 /* Reset so we do not get here again. The SetWindowPos call in
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
1990 * mswindows_size_frame_internal can cause recursion here. */
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
1991 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
1992 {
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
1993 xfree (FRAME_MSWINDOWS_TARGET_RECT (frame));
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
1994 FRAME_MSWINDOWS_TARGET_RECT (frame) = 0;
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
1995 }
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1996 }
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1997 else
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1998 {
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
1999 if (!msframe->sizing && !FRAME_VISIBLE_P (frame))
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2000 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2001 FRAME_VISIBLE_P (frame) = 1;
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2002
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2003 if (!msframe->sizing || mswindows_dynamic_frame_resize)
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2004 redisplay ();
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2005 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2006 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2007 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2008 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2009
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2010 /* Misc magic events which only require that the frame be identified */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2011 case WM_SETFOCUS:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2012 case WM_KILLFOCUS:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2013 mswindows_enqueue_magic_event (hwnd, message);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2014 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2015
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2016 case WM_WINDOWPOSCHANGING:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2017 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2018 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2019 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2020 GetWindowPlacement(hwnd, &wpl);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2021
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2022 /* Only interested if size is changing and we're not being iconified */
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2023 if (wpl.showCmd != SW_SHOWMINIMIZED
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2024 && wpl.showCmd != SW_SHOWMAXIMIZED
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2025 && !(wp->flags & SWP_NOSIZE))
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2026 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2027 RECT ncsize = { 0, 0, 0, 0 };
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2028 int pixwidth, pixheight;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2029 AdjustWindowRectEx (&ncsize, GetWindowLong (hwnd, GWL_STYLE),
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2030 GetMenu(hwnd) != NULL,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2031 GetWindowLong (hwnd, GWL_EXSTYLE));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2032
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2033 round_size_to_real_char (XFRAME (mswindows_find_frame (hwnd)),
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2034 wp->cx - (ncsize.right - ncsize.left),
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2035 wp->cy - (ncsize.bottom - ncsize.top),
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2036 &pixwidth, &pixheight);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2037
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2038 /* Convert client sizes to window sizes */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2039 pixwidth += (ncsize.right - ncsize.left);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2040 pixheight += (ncsize.bottom - ncsize.top);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2041
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2042 if (wpl.showCmd != SW_SHOWMAXIMIZED)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2043 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2044 /* Adjust so that the bottom or right doesn't move if it's
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2045 * the top or left that's being changed */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2046 RECT rect;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2047 GetWindowRect (hwnd, &rect);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2048
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2049 if (rect.left != wp->x)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2050 wp->x += wp->cx - pixwidth;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2051 if (rect.top != wp->y)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2052 wp->y += wp->cy - pixheight;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2053 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2054
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2055 wp->cx = pixwidth;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2056 wp->cy = pixheight;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2057 }
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2058 /* DefWindowProc sends useful WM_GETMINMAXINFO message, and adjusts
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2059 window position if the user tries to track window too small */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2060 }
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2061 goto defproc;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2062
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2063 case WM_ENTERSIZEMOVE:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2064 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2065 msframe->sizing = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2066 return 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2067
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2068 case WM_EXITSIZEMOVE:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2069 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2070 msframe->sizing = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2071 /* Queue noop event */
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2072 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2073 return 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2074
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2075 #ifdef HAVE_SCROLLBARS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2076 case WM_VSCROLL:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2077 case WM_HSCROLL:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2078 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2079 /* Direction of scroll is determined by scrollbar instance. */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2080 int code = (int) LOWORD(wParam);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2081 int pos = (short int) HIWORD(wParam);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2082 HWND hwndScrollBar = (HWND) lParam;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2083 struct gcpro gcpro1, gcpro2;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2084
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2085 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2086 GCPRO2 (emacs_event, fobj);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2087 if (UNBOUNDP(mswindows_pump_outstanding_events())) /* Can GC */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2088 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2089 /* Error during event pumping - cancel scroll */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2090 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2091 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2092 UNGCPRO;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2093 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2094 }
355
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2095
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2096 case WM_MOUSEWHEEL:
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2097 {
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2098 int keys = LOWORD (wParam); /* Modifier key flags */
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2099 int delta = (short) HIWORD (wParam); /* Wheel rotation amount */
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2100 struct gcpro gcpro1, gcpro2;
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2101
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2102 if (mswindows_handle_mousewheel_event (mswindows_find_frame (hwnd), keys, delta))
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2103 {
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2104 GCPRO2 (emacs_event, fobj);
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2105 mswindows_pump_outstanding_events (); /* Can GC */
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2106 UNGCPRO;
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2107 }
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2108 else
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2109 goto defproc;
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2110 break;
182f72e8cd0d Import from CVS: tag r21-1-7
cvs
parents: 327
diff changeset
2111 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2112 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2113
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2114 #ifdef HAVE_MENUBARS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2115 case WM_INITMENU:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2116 if (UNBOUNDP (mswindows_handle_wm_initmenu (
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2117 (HMENU) wParam,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2118 XFRAME (mswindows_find_frame (hwnd)))))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2119 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2120 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2121
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2122 case WM_INITMENUPOPUP:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2123 if (!HIWORD(lParam))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2124 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2125 if (UNBOUNDP (mswindows_handle_wm_initmenupopup (
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2126 (HMENU) wParam,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2127 XFRAME (mswindows_find_frame (hwnd)))))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2128 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2129 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2130 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2131
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2132 #endif /* HAVE_MENUBARS */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2133
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2134 case WM_COMMAND:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2135 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2136 WORD id = LOWORD (wParam);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2137 HWND cid = (HWND)lParam;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2138 frame = XFRAME (mswindows_find_frame (hwnd));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2139
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2140 #ifdef HAVE_TOOLBARS
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2141 if (!NILP (mswindows_handle_toolbar_wm_command (frame, cid, id)))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2142 break;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2143 #endif
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2144
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2145 #ifdef HAVE_MENUBARS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2146 if (!NILP (mswindows_handle_wm_command (frame, id)))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2147 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2148 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2149
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2150 /* Bite me - a spurious command. This cannot happen. */
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2151 error ("XEMACS BUG: Cannot decode command message");
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2152 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2153 break;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2154
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
2155 #ifdef HAVE_DRAGNDROP
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2156 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2157 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2158 UINT filecount, i, len;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2159 POINT point;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2160 char* filename;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2161 #ifdef __CYGWIN32__
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2162 char* fname;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2163 #endif
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2164 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2165 struct gcpro gcpro1, gcpro2, gcpro3;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2166
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2167 emacs_event = Fmake_event (Qnil, Qnil);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2168 event = XEVENT(emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2169
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2170 GCPRO3 (emacs_event, l_dndlist, l_item);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2171
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2172 if (!DragQueryPoint ((HANDLE) wParam, &point))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2173 point.x = point.y = -1; /* outside client area */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2174
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2175 event->event_type = misc_user_event;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2176 event->channel = mswindows_find_frame(hwnd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2177 event->timestamp = GetMessageTime();
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2178 event->event.misc.button = 1; /* #### Should try harder */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2179 event->event.misc.modifiers = mswindows_modifier_state (NULL, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2180 event->event.misc.x = point.x;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2181 event->event.misc.y = point.y;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2182 event->event.misc.function = Qdragdrop_drop_dispatch;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2183
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2184 filecount = DragQueryFile ((HANDLE) wParam, 0xffffffff, NULL, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2185 for (i=0; i<filecount; i++)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2186 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2187 len = DragQueryFile ((HANDLE) wParam, i, NULL, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2188 /* The URLs that we make here aren't correct according to section
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2189 * 3.10 of rfc1738 because they're missing the //<host>/ part and
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2190 * because they may contain reserved characters. But that's OK. */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2191 #ifdef __CYGWIN32__
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2192 fname = (char *)xmalloc (len+1);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2193 DragQueryFile ((HANDLE) wParam, i, fname, len+1);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2194 filename = xmalloc (cygwin32_win32_to_posix_path_list_buf_size (fname) + 5);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2195 strcpy (filename, "file:");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2196 cygwin32_win32_to_posix_path_list (fname, filename+5);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2197 xfree (fname);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2198 #else
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2199 filename = (char *)xmalloc (len+6);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2200 strcpy (filename, "file:");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2201 DragQueryFile ((HANDLE) wParam, i, filename+5, len+1);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2202 dostounix_filename (filename+5);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2203 #endif
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2204 l_item = make_string (filename, strlen (filename));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2205 l_dndlist = Fcons (l_item, l_dndlist);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2206 xfree (filename);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2207 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2208 DragFinish ((HANDLE) wParam);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2209
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2210 event->event.misc.object = Fcons (Qdragdrop_URL, l_dndlist);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2211 mswindows_enqueue_dispatch_event (emacs_event);
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2212 UNGCPRO;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2213 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2214 break;
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
2215 #endif
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2216
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2217 defproc:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2218 default:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2219 return DefWindowProc (hwnd, message, wParam, lParam);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2220 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2221 return (0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2222 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2223
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2224
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2225 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2226 /* keyboard, mouse & other helpers for the windows procedure */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2227 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2228 static void
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2229 mswindows_set_chord_timer (HWND hwnd)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2230 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2231 int interval;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2232
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2233 /* We get one third half system double click threshold */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2234 if (mswindows_mouse_button_tolerance <= 0)
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2235 interval = GetDoubleClickTime () / 3;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2236 else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2237 interval = mswindows_mouse_button_tolerance;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2238
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2239 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2240 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2241
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2242 static int
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2243 mswindows_button2_near_enough (POINTS p1, POINTS p2)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2244 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2245 int dx, dy;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2246 if (mswindows_mouse_button_max_skew_x <= 0)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2247 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2248 else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2249 dx = mswindows_mouse_button_max_skew_x;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2250
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2251 if (mswindows_mouse_button_max_skew_y <= 0)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2252 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2253 else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2254 dy = mswindows_mouse_button_max_skew_y;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2255
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2256 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2257 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2258
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2259 static int
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2260 mswindows_current_layout_has_AltGr (void)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2261 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2262 /* This simple caching mechanism saves 10% of CPU
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2263 time when a key typed at autorepeat rate of 30 cps! */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2264 static HKL last_hkl = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2265 static int last_hkl_has_AltGr;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2266
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2267 HKL current_hkl = GetKeyboardLayout (0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2268 if (current_hkl != last_hkl)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2269 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2270 TCHAR c;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2271 last_hkl_has_AltGr = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2272 /* In this loop, we query whether a character requires
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2273 AltGr to be down to generate it. If at least such one
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2274 found, this means that the layout does regard AltGr */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2275 for (c = ' '; c <= 0xFFU && c != 0 && !last_hkl_has_AltGr; ++c)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2276 if (HIBYTE (VkKeyScan (c)) == 6)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2277 last_hkl_has_AltGr = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2278 last_hkl = current_hkl;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2279 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2280 return last_hkl_has_AltGr;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2281 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2282
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2283
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2284 /* Returns the state of the modifier keys in the format expected by the
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2285 * Lisp_Event key_data, button_data and motion_data modifiers member */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2286 int mswindows_modifier_state (BYTE* keymap, int has_AltGr)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2287 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2288 int mods = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2289
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2290 if (keymap == NULL)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2291 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2292 keymap = (BYTE*) alloca(256);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2293 GetKeyboardState (keymap);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2294 has_AltGr = mswindows_current_layout_has_AltGr ();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2295 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2296
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2297 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2298 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2299 mods |= (keymap [VK_LMENU] & 0x80) ? MOD_META : 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2300 mods |= (keymap [VK_RCONTROL] & 0x80) ? MOD_CONTROL : 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2301 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2302 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2303 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2304 mods |= (keymap [VK_MENU] & 0x80) ? MOD_META : 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2305 mods |= (keymap [VK_CONTROL] & 0x80) ? MOD_CONTROL : 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2306 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2307
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2308 mods |= (keymap [VK_SHIFT] & 0x80) ? MOD_SHIFT : 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2309
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2310 return mods;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2311 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2312
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2313 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2314 * Translate a mswindows virtual key to a keysym.
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2315 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2316 * or whose ASCII codes (like space) xemacs doesn't like.
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2317 * Virtual key values are defined in winresrc.h
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2318 */
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2319 Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2320 int extendedp)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2321 {
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2322 if (extendedp) /* Keys not present on a 82 key keyboard */
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2323 {
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2324 switch (mswindows_key)
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2325 {
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2326 case VK_RETURN: return KEYSYM ("kp-enter");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2327 case VK_PRIOR: return KEYSYM ("prior");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2328 case VK_NEXT: return KEYSYM ("next");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2329 case VK_END: return KEYSYM ("end");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2330 case VK_HOME: return KEYSYM ("home");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2331 case VK_LEFT: return KEYSYM ("left");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2332 case VK_UP: return KEYSYM ("up");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2333 case VK_RIGHT: return KEYSYM ("right");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2334 case VK_DOWN: return KEYSYM ("down");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2335 case VK_INSERT: return KEYSYM ("insert");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2336 case VK_DELETE: return QKdelete;
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2337 }
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2338 }
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2339 else
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2340 {
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2341 switch (mswindows_key)
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2342 {
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2343 case VK_BACK: return QKbackspace;
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2344 case VK_TAB: return QKtab;
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2345 case '\n': return QKlinefeed;
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2346 case VK_CLEAR: return KEYSYM ("clear");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2347 case VK_RETURN: return QKreturn;
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2348 case VK_ESCAPE: return QKescape;
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2349 case VK_SPACE: return QKspace;
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2350 case VK_PRIOR: return KEYSYM ("kp-prior");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2351 case VK_NEXT: return KEYSYM ("kp-next");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2352 case VK_END: return KEYSYM ("kp-end");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2353 case VK_HOME: return KEYSYM ("kp-home");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2354 case VK_LEFT: return KEYSYM ("kp-left");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2355 case VK_UP: return KEYSYM ("kp-up");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2356 case VK_RIGHT: return KEYSYM ("kp-right");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2357 case VK_DOWN: return KEYSYM ("kp-down");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2358 case VK_SELECT: return KEYSYM ("select");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2359 case VK_PRINT: return KEYSYM ("print");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2360 case VK_EXECUTE: return KEYSYM ("execute");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2361 case VK_SNAPSHOT: return KEYSYM ("print");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2362 case VK_INSERT: return KEYSYM ("kp-insert");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2363 case VK_DELETE: return KEYSYM ("kp-delete");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2364 case VK_HELP: return KEYSYM ("help");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2365 #if 0 /* FSF Emacs allows these to return configurable syms/mods */
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2366 case VK_LWIN return KEYSYM ("");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2367 case VK_RWIN return KEYSYM ("");
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2368 #endif
357
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2369 case VK_APPS: return KEYSYM ("menu");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2370 case VK_NUMPAD0: return KEYSYM ("kp-0");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2371 case VK_NUMPAD1: return KEYSYM ("kp-1");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2372 case VK_NUMPAD2: return KEYSYM ("kp-2");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2373 case VK_NUMPAD3: return KEYSYM ("kp-3");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2374 case VK_NUMPAD4: return KEYSYM ("kp-4");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2375 case VK_NUMPAD5: return KEYSYM ("kp-5");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2376 case VK_NUMPAD6: return KEYSYM ("kp-6");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2377 case VK_NUMPAD7: return KEYSYM ("kp-7");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2378 case VK_NUMPAD8: return KEYSYM ("kp-8");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2379 case VK_NUMPAD9: return KEYSYM ("kp-9");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2380 case VK_MULTIPLY: return KEYSYM ("kp-multiply");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2381 case VK_ADD: return KEYSYM ("kp-add");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2382 case VK_SEPARATOR: return KEYSYM ("kp-separator");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2383 case VK_SUBTRACT: return KEYSYM ("kp-subtract");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2384 case VK_DECIMAL: return KEYSYM ("kp-decimal");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2385 case VK_DIVIDE: return KEYSYM ("kp-divide");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2386 case VK_F1: return KEYSYM ("f1");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2387 case VK_F2: return KEYSYM ("f2");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2388 case VK_F3: return KEYSYM ("f3");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2389 case VK_F4: return KEYSYM ("f4");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2390 case VK_F5: return KEYSYM ("f5");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2391 case VK_F6: return KEYSYM ("f6");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2392 case VK_F7: return KEYSYM ("f7");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2393 case VK_F8: return KEYSYM ("f8");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2394 case VK_F9: return KEYSYM ("f9");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2395 case VK_F10: return KEYSYM ("f10");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2396 case VK_F11: return KEYSYM ("f11");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2397 case VK_F12: return KEYSYM ("f12");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2398 case VK_F13: return KEYSYM ("f13");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2399 case VK_F14: return KEYSYM ("f14");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2400 case VK_F15: return KEYSYM ("f15");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2401 case VK_F16: return KEYSYM ("f16");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2402 case VK_F17: return KEYSYM ("f17");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2403 case VK_F18: return KEYSYM ("f18");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2404 case VK_F19: return KEYSYM ("f19");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2405 case VK_F20: return KEYSYM ("f20");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2406 case VK_F21: return KEYSYM ("f21");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2407 case VK_F22: return KEYSYM ("f22");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2408 case VK_F23: return KEYSYM ("f23");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2409 case VK_F24: return KEYSYM ("f24");
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2410 }
4711e16a8e49 Import from CVS: tag r21-1-8
cvs
parents: 355
diff changeset
2411 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2412 return Qnil;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2413 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2414
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2415 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2416 * Find the console that matches the supplied mswindows window handle
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2417 */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2418 Lisp_Object
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2419 mswindows_find_console (HWND hwnd)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2420 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2421 /* We only support one console */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2422 return XCAR (Vconsole_list);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2423 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2424
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2425 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2426 * Find the frame that matches the supplied mswindows window handle
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2427 */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2428 static Lisp_Object
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2429 mswindows_find_frame (HWND hwnd)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2430 {
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2431 LONG l = GetWindowLong (hwnd, XWL_FRAMEOBJ);
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2432 Lisp_Object f;
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2433 if (l == 0)
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2434 {
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2435 /* We are in progress of frame creation. Return the frame
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2436 being created, as it still not remembered in the window
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2437 extra storage. */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2438 assert (!NILP (Vmswindows_frame_being_created));
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2439 return Vmswindows_frame_being_created;
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2440 }
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2441 VOID_TO_LISP (f, l);
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2442 return f;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2443 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2444
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2445
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2446 /************************************************************************/
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2447 /* methods */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2448 /************************************************************************/
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2449
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2450 static int
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2451 emacs_mswindows_add_timeout (EMACS_TIME thyme)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2452 {
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2453 int milliseconds;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2454 EMACS_TIME current_time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2455 EMACS_GET_TIME (current_time);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2456 EMACS_SUB_TIME (thyme, thyme, current_time);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2457 milliseconds = EMACS_SECS (thyme) * 1000 +
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2458 (EMACS_USECS (thyme) + 500) / 1000;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2459 if (milliseconds < 1)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2460 milliseconds = 1;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
2461 ++mswindows_pending_timers_count;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2462 return SetTimer (NULL, 0, milliseconds,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2463 (TIMERPROC) mswindows_wm_timer_callback);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2464 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2465
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2466 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2467 emacs_mswindows_remove_timeout (int id)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2468 {
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2469 struct Lisp_Event match_against;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2470 Lisp_Object emacs_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2471
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
2472 if (KillTimer (NULL, id))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
2473 --mswindows_pending_timers_count;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2474
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2475 /* If there is a dispatch event generated by this
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2476 timeout in the queue, we have to remove it too. */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2477 match_against.event_type = timeout_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2478 match_against.event.timeout.interval_id = id;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2479 emacs_event = mswindows_cancel_dispatch_event (&match_against);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2480 if (!NILP (emacs_event))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2481 Fdeallocate_event(emacs_event);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2482 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2483
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2484 /* If `user_p' is false, then return whether there are any win32, timeout,
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2485 * or subprocess events pending (that is, whether
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2486 * emacs_mswindows_next_event() would return immediately without blocking).
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2487 *
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2488 * if `user_p' is true, then return whether there are any *user generated*
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2489 * events available (that is, whether there are keyboard or mouse-click
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2490 * events ready to be read). This also implies that
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2491 * emacs_mswindows_next_event() would not block.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
2492 */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2493 static int
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2494 emacs_mswindows_event_pending_p (int user_p)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2495 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2496 mswindows_need_event (0);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2497 return (!NILP (mswindows_u_dispatch_event_queue)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2498 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2499 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2500
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2501 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2502 * Return the next event
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2503 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2504 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2505 emacs_mswindows_next_event (struct Lisp_Event *emacs_event)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2506 {
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2507 Lisp_Object event, event2;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2508
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2509 mswindows_need_event (1);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2510
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2511 event = mswindows_dequeue_dispatch_event (!NILP(mswindows_u_dispatch_event_queue));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2512 XSETEVENT (event2, emacs_event);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2513 Fcopy_event (event, event2);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2514 Fdeallocate_event (event);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2515 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2516
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2517 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2518 * Handle a magic event off the dispatch queue.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2519 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2520 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2521 emacs_mswindows_handle_magic_event (struct Lisp_Event *emacs_event)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2522 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2523 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2524 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2525 case XM_BUMPQUEUE:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2526 break;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2527
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2528 case WM_SETFOCUS:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2529 case WM_KILLFOCUS:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2530 {
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2531 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2532 struct frame *f = XFRAME (frame);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2533 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2534 Lisp_Object conser;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2535
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2536 /* struct gcpro gcpro1; */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2537
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2538 /* Clear sticky modifiers here (if we had any) */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2539
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2540 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2541 /* GCPRO1 (conser); XXX Not necessary? */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2542 emacs_handle_focus_change_preliminary (conser);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2543 /* Under X the stuff up to here is done in the X event handler.
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2544 I Don't know why */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2545 emacs_handle_focus_change_final (conser);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2546 /* UNGCPRO; */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2547
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2548 }
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2549 break;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2550
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2551 case XM_MAPFRAME:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2552 case XM_UNMAPFRAME:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2553 {
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2554 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2555 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2556 == XM_MAPFRAME ?
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2557 Qmap_frame_hook : Qunmap_frame_hook,
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2558 1, frame);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2559 }
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2560 break;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2561
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2562 /* #### What about Enter & Leave */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2563 #if 0
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2564 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2565 Qmouse_leave_frame_hook, 1, frame);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2566 #endif
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2567
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2568 default:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2569 assert(0);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
2570 }
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2571 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2572
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2573 static HANDLE
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2574 get_process_input_waitable (struct Lisp_Process *process)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2575 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2576 Lisp_Object instr, outstr, p;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2577 XSETPROCESS (p, process);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2578 get_process_streams (process, &instr, &outstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2579 assert (!NILP (instr));
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2580 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2581 return (network_connection_p (p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2582 ? get_winsock_stream_waitable (XLSTREAM (instr))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2583 : get_ntpipe_input_stream_waitable (XLSTREAM (instr)));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2584 #else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2585 return get_ntpipe_input_stream_waitable (XLSTREAM (instr));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2586 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2587 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2588
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2589 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2590 emacs_mswindows_select_process (struct Lisp_Process *process)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2591 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2592 HANDLE hev = get_process_input_waitable (process);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2593
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2594 if (!add_waitable_handle (hev))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2595 error ("Too many active processes");
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2596
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2597 #ifdef HAVE_WIN32_PROCESSES
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2598 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2599 Lisp_Object p;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2600 XSETPROCESS (p, process);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2601 if (!network_connection_p (p))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2602 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2603 HANDLE hprocess = get_nt_process_handle (process);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2604 if (!add_waitable_handle (hprocess))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2605 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2606 remove_waitable_handle (hev);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2607 error ("Too many active processes");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2608 }
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2609 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2610 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2611 #endif
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2612 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2613
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2614 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2615 emacs_mswindows_unselect_process (struct Lisp_Process *process)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2616 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2617 /* Process handle is removed in the event loop as soon
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2618 as it is signaled, so don't bother here about it */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2619 HANDLE hev = get_process_input_waitable (process);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2620 remove_waitable_handle (hev);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2621 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2622
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2623 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2624 emacs_mswindows_select_console (struct console *con)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2625 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2626 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2627
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2628 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2629 emacs_mswindows_unselect_console (struct console *con)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2630 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2631 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2632
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2633 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2634 emacs_mswindows_quit_p (void)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2635 {
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2636 MSG msg;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2637
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2638 /* Quit cannot happen in modal loop: all program
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2639 input is dedicated to Windows. */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2640 if (mswindows_in_modal_loop)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2641 return;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2642
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2643 /* Drain windows queue. This sets up number of quit characters in the queue
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2644 * (and also processes wm focus change, move, resize, etc messages).
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2645 * We don't want to process WM_PAINT messages because this function can be
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2646 * called from almost anywhere and the windows' states may be changing. */
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2647 while (PeekMessage (&msg, NULL, 0, WM_PAINT-1, PM_REMOVE) ||
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2648 PeekMessage (&msg, NULL, WM_PAINT+1, WM_USER-1, PM_REMOVE))
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 314
diff changeset
2649 DispatchMessage (&msg);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2650
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2651 if (mswindows_quit_chars_count > 0)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2652 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2653 /* Yes there's a hidden one... Throw it away */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2654 struct Lisp_Event match_against;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2655 Lisp_Object emacs_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2656
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2657 match_against.event_type = key_press_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2658 match_against.event.key.modifiers = FAKE_MOD_QUIT;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2659
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2660 emacs_event = mswindows_cancel_dispatch_event (&match_against);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2661 assert (!NILP (emacs_event));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2662
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2663 Vquit_flag = (XEVENT(emacs_event)->event.key.modifiers & MOD_SHIFT
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2664 ? Qcritical : Qt);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2665
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2666 Fdeallocate_event(emacs_event);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2667 --mswindows_quit_chars_count;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2668 }
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2669 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2670
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2671 USID
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2672 emacs_mswindows_create_stream_pair (void* inhandle, void* outhandle,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2673 Lisp_Object* instream,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2674 Lisp_Object* outstream,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2675 int flags)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2676 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2677 /* Handles for streams */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2678 HANDLE hin, hout;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2679 /* fds. These just stored along with the streams, and are closed in
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2680 delete stream pair method, because we need to handle fake unices
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2681 here. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2682 int fdi, fdo;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2683
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2684 /* Decode inhandle and outhandle. Their meaning depends on
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2685 the process implementation being used. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2686 #if defined (HAVE_WIN32_PROCESSES)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2687 /* We're passed in Windows handles. That's what we like most... */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2688 hin = (HANDLE) inhandle;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2689 hout = (HANDLE) outhandle;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2690 fdi = fdo = -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2691 #elif defined (HAVE_UNIX_PROCESSES)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2692 /* We are passed UNIX fds. This must be Cygwin.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2693 Fetch os handles */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2694 hin = inhandle >= 0 ? (HANDLE)get_osfhandle ((int)inhandle) : INVALID_HANDLE_VALUE;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2695 hout = outhandle >= 0 ? (HANDLE)get_osfhandle ((int)outhandle) : INVALID_HANDLE_VALUE;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2696 fdi=(int)inhandle;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2697 fdo=(int)outhandle;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2698 #else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2699 #error "So, WHICH kind of processes do you want?"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2700 #endif
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2701
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2702 *instream = (hin == INVALID_HANDLE_VALUE
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2703 ? Qnil
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2704 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2705 : flags & STREAM_NETWORK_CONNECTION
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2706 ? make_winsock_input_stream ((SOCKET)hin, fdi)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2707 #endif
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2708 : make_ntpipe_input_stream (hin, fdi));
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2709
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2710 #ifdef HAVE_WIN32_PROCESSES
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2711 *outstream = (hout == INVALID_HANDLE_VALUE
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2712 ? Qnil
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2713 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2714 : flags & STREAM_NETWORK_CONNECTION
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2715 ? make_winsock_output_stream ((SOCKET)hout, fdo)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2716 #endif
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2717 : make_ntpipe_output_stream (hout, fdo));
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2718 #elif defined (HAVE_UNIX_PROCESSES)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2719 *outstream = (fdo >= 0
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2720 ? make_filedesc_output_stream (fdo, 0, -1, LSTR_BLOCKED_OK)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2721 : Qnil);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2722
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2723 #if defined(HAVE_UNIX_PROCESSES) && defined(HAVE_PTYS)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2724 /* FLAGS is process->pty_flag for UNIX_PROCESSES */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2725 if ((flags & STREAM_PTY_FLUSHING) && fdo >= 0)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2726 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2727 Bufbyte eof_char = get_eof_char (fdo);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2728 int pty_max_bytes = get_pty_max_bytes (fdo);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2729 filedesc_stream_set_pty_flushing (XLSTREAM(*outstream), pty_max_bytes, eof_char);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2730 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2731 #endif
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2732 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2733
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2734 return (NILP (*instream)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2735 ? USID_ERROR
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2736 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2737 : flags & STREAM_NETWORK_CONNECTION
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2738 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (*instream)))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2739 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2740 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (*instream))));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2741 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2742
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2743 USID
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2744 emacs_mswindows_delete_stream_pair (Lisp_Object instream,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2745 Lisp_Object outstream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2746 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2747 /* Oh nothing special here for Win32 at all */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2748 #if defined (HAVE_UNIX_PROCESSES)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2749 int in = (NILP(instream)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2750 ? -1
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2751 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2752 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2753 ? get_winsock_stream_param (XLSTREAM (instream))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2754 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2755 : get_ntpipe_input_stream_param (XLSTREAM (instream)));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2756 int out = (NILP(outstream) ? -1
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2757 : filedesc_stream_fd (XLSTREAM (outstream)));
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2758
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2759 if (in >= 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2760 close (in);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2761 if (out != in && out >= 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2762 close (out);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2763 #endif
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2764
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2765 return (NILP (instream)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2766 ? USID_DONTHASH
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2767 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2768 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2769 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (instream)))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2770 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2771 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (instream))));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2772 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2773
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2774 #ifndef HAVE_X_WINDOWS
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2775 /* This is called from GC when a process object is about to be freed.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2776 If we've still got pointers to it in this file, we're gonna lose hard.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2777 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2778 void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2779 debug_process_finalization (struct Lisp_Process *p)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2780 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2781 #if 0 /* #### */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2782 Lisp_Object instr, outstr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2783
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2784 get_process_streams (p, &instr, &outstr);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2785 /* if it still has fds, then it hasn't been killed yet. */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2786 assert (NILP(instr));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2787 assert (NILP(outstr));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2788
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2789 /* #### More checks here */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2790 #endif
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2791 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
2792 #endif
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2793
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2794 /************************************************************************/
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2795 /* initialization */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2796 /************************************************************************/
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2797
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2798 void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2799 vars_of_event_mswindows (void)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2800 {
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2801 mswindows_u_dispatch_event_queue = Qnil;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2802 staticpro (&mswindows_u_dispatch_event_queue);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2803 mswindows_u_dispatch_event_queue_tail = Qnil;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2804
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2805 mswindows_s_dispatch_event_queue = Qnil;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2806 staticpro (&mswindows_s_dispatch_event_queue);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2807 mswindows_s_dispatch_event_queue_tail = Qnil;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2808
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
2809 mswindows_error_caught_in_modal_loop = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
2810 staticpro (&mswindows_error_caught_in_modal_loop);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
2811 mswindows_in_modal_loop = 0;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
2812 mswindows_pending_timers_count = 0;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
2813
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2814 mswindows_event_stream = xnew (struct event_stream);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2815
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2816 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2817 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2818 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2819 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2820 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2821 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2822 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2823 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2824 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2825 mswindows_event_stream->select_process_cb =
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2826 (void (*)(struct Lisp_Process*))event_stream_unixoid_select_process;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2827 mswindows_event_stream->unselect_process_cb =
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2828 (void (*)(struct Lisp_Process*))event_stream_unixoid_unselect_process;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2829 mswindows_event_stream->create_stream_pair_cb = event_stream_unixoid_create_stream_pair;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2830 mswindows_event_stream->delete_stream_pair_cb = event_stream_unixoid_delete_stream_pair;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2831 #else
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2832 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2833 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2834 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2835 mswindows_event_stream->delete_stream_pair_cb = emacs_mswindows_delete_stream_pair;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2836 #endif
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2837
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 223
diff changeset
2838 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2839 *Controls redrawing frame contents during mouse-drag or keyboard resize
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2840 operation. When non-nil, the frame is redrawn while being resized. When
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2841 nil, frame is not redrawn, and exposed areas are filled with default
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2842 MDI application background color. Note that this option only has effect
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2843 if "Show window contents while dragging" is on in system Display/Plus!
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2844 settings.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2845 Default is t on fast machines, nil on slow.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2846 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2847
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2848 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2849 DEFVAR_INT ("mswindows-mouse-button-tolerance", &mswindows_mouse_button_tolerance /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2850 *Analogue of double click interval for faking middle mouse events.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2851 The value is the minimum time in milliseconds that must elapse between
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2852 left/right button down events before they are considered distinct events.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2853 If both mouse buttons are depressed within this interval, a middle mouse
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2854 button down event is generated instead.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2855 If negative or zero, currently set system default is used instead.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2856 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2857
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2858 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 223
diff changeset
2859 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2860 Number of physical mouse buttons.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2861 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2862
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2863 DEFVAR_INT ("mswindows-mouse-button-max-skew-x", &mswindows_mouse_button_max_skew_x /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2864 *Maximum horizontal distance in pixels between points in which left and
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2865 right button clicks occured for them to be translated into single
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2866 middle button event. Clicks must occur in time not longer than defined
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2867 by the variable `mswindows-mouse-button-tolerance'.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2868 If negative or zero, currently set system default is used instead.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2869 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2870
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2871 DEFVAR_INT ("mswindows-mouse-button-max-skew-y", &mswindows_mouse_button_max_skew_y /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2872 *Maximum vertical distance in pixels between points in which left and
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2873 right button clicks occured for them to be translated into single
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2874 middle button event. Clicks must occur in time not longer than defined
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2875 by the variable `mswindows-mouse-button-tolerance'.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2876 If negative or zero, currently set system default is used instead.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2877 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2878
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2879 mswindows_mouse_button_max_skew_x = 0;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2880 mswindows_mouse_button_max_skew_y = 0;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2881 mswindows_mouse_button_tolerance = 0;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2882 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2883
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2884 void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2885 syms_of_event_mswindows (void)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2886 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2887 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2888
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2889 void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2890 lstream_type_create_mswindows_selectable (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2891 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2892 init_slurp_stream ();
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2893 init_shove_stream ();
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2894 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2895 init_winsock_stream ();
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
2896 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2897 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2898
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2899 void
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2900 init_event_mswindows_late (void)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2901 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2902 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2903 windows_fd = open("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2904 assert (windows_fd>=0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2905 FD_SET (windows_fd, &input_wait_mask);
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
2906 FD_ZERO(&zero_mask);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2907 #endif
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2908
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2909 event_stream = mswindows_event_stream;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2910
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2911 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2912 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2913 }