annotate src/event-msw.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 501cfd01ee6d
children 697ef44129c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1 /* The mswindows event_stream interface.
213
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.
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
4 Copyright (C) 1996, 2000 Ben Wing.
213
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.
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
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
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
44 # include "menubar.h"
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
45 # include "menubar-msw.h"
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
46 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
47
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
48 #ifdef HAVE_DRAGNDROP
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
49 # include "dragdrop.h"
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
50 #endif
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
51
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
52 #include "device.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
53 #include "events.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
54 #include "frame.h"
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
55 #include "buffer.h"
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
56 #include "faces.h"
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
57 #include "lstream.h"
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
58 #include "process.h"
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
59 #include "redisplay.h"
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
60 #include "select.h"
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
61 #include "window.h"
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
62 #include "sysproc.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
63 #include "syswait.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
64 #include "systime.h"
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
65 #include "sysdep.h"
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
66 #include "objects-msw.h"
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
67
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
68 #include "events-mod.h"
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
69 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
70 #include "sysfile.h"
392
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
71 #include "console-tty.h"
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
72 #elif defined(CYGWIN)
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
73 typedef unsigned int SOCKET;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
74 #endif
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
75 #include <io.h>
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
76 #include <errno.h>
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
77
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
78 #if !(defined(CYGWIN) || defined(MINGW))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
79 # include <shlobj.h> /* For IShellLink */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
80 #endif
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
81
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
82 #ifdef HAVE_MENUBARS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
83 #define ADJR_MENUFLAG TRUE
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
84 #else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
85 #define ADJR_MENUFLAG FALSE
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
86 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
87
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
88 /* Fake key modifier which is attached to a quit char event.
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
89 Removed upon dequeueing an event */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
90 #define FAKE_MOD_QUIT 0x80
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
91
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
92 /* Timer ID used for button2 emulation */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
93 #define BUTTON_2_TIMER_ID 1
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
94
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
95 static Lisp_Object mswindows_find_frame (HWND hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
96 static Lisp_Object mswindows_find_console (HWND hwnd);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
97 static Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
98 int extendedp);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
99 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
100 static void mswindows_set_chord_timer (HWND hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
101 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
102 static int mswindows_current_layout_has_AltGr (void);
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
103 static int mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
104 int downp, int keyp);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
105
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
106 static struct event_stream *mswindows_event_stream;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
107
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
108 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
109 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
110 extern SELECT_TYPE process_only_mask, tty_only_mask;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
111 SELECT_TYPE zero_mask;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
112 extern int signal_event_pipe_initialized;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
113 int windows_fd;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
114 #endif
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
115
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
116 /*
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
117 * Two separate queues, for efficiency, one (_u_) for user events, and
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
118 * 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
119 * 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
120 * one.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
121 */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
122 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
123 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
124
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
125 /* The number of things we can wait on */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
126 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
127
392
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
128 #ifndef HAVE_MSG_SELECT
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
129 /* List of mswindows waitable handles. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
130 static HANDLE mswindows_waitable_handles[MAX_WAITABLE];
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
131
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
132 /* Number of wait handles */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
133 static int mswindows_waitable_count=0;
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
134 #endif /* HAVE_MSG_SELECT */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
135
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
136 /* Brush for painting widgets */
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
137 static HBRUSH widget_brush = 0;
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
138 static LONG last_widget_brushed = 0;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
139
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
140 /* Count of quit chars currently in the queue */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
141 /* Incremented in WM_[SYS]KEYDOWN handler in the mswindows_wnd_proc()
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
142 Decremented in mswindows_dequeue_dispatch_event() */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
143 int mswindows_quit_chars_count = 0;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
144
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
145 /* These are Lisp integers; see DEFVARS in this file for description. */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
146 int mswindows_dynamic_frame_resize;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
147 int mswindows_alt_by_itself_activates_menu;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
148 int mswindows_num_mouse_buttons;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
149 int mswindows_mouse_button_max_skew_x;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
150 int mswindows_mouse_button_max_skew_y;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
151 int mswindows_mouse_button_tolerance;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
152
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
153 #ifdef DEBUG_XEMACS
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
154 int mswindows_debug_events;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
155 #endif
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
156
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
157 /* This is the event signaled by the event pump.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
158 See mswindows_pump_outstanding_events for comments */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
159 static Lisp_Object mswindows_error_caught_in_modal_loop;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
160 static int mswindows_in_modal_loop;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
161
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
162 /* Count of wound timers */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
163 static int mswindows_pending_timers_count;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
164
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
165 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
166 /* Pipe instream - reads process output */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
167 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
168
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
169 #define PIPE_READ_DELAY 20
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
170
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
171 #define HANDLE_TO_USID(h) ((USID)(h))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
172
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
173 #define NTPIPE_SLURP_STREAM_DATA(stream) \
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
174 LSTREAM_TYPE_DATA (stream, ntpipe_slurp)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
175
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
176 /* This structure is allocated by the main thread, and is deallocated
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
177 in the thread upon exit. There are situations when a thread
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
178 remains blocked for a long time, much longer than the lstream
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
179 exists. For example, "start notepad" command is issued from the
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
180 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
181 process exits, its output pipe will not get closed until the
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
182 notepad process exits also, because it inherits the pipe form the
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
183 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
184 all such processes exit. While struct ntpipe_slurp_stream is
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
185 deallocated in this case, ntpipe_slurp_stream_shared_data are not. */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
186
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
187 struct ntpipe_slurp_stream_shared_data
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
188 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
189 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
190 /* This is a manual-reset object. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
191 HANDLE hev_caller; /* Caller blocks on this, and we signal it */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
192 /* This is a manual-reset object. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
193 HANDLE hev_unsleep; /* Pipe read delay is canceled if this is set */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
194 /* This is a manual-reset object. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
195 HANDLE hpipe; /* Pipe read end handle. */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
196 LONG die_p; /* Thread must exit ASAP if non-zero */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
197 BOOL eof_p : 1; /* Set when thread saw EOF */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
198 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
199 BOOL inuse_p : 1; /* this structure is in use */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
200 LONG lock_count; /* Client count of this struct, 0=safe to free */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
201 BYTE onebyte; /* One byte buffer read by thread */
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
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
204 #define MAX_SLURP_STREAMS 32
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
205 struct ntpipe_slurp_stream_shared_data
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
206 shared_data_block[MAX_SLURP_STREAMS]={{0}};
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
207
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
208 struct ntpipe_slurp_stream
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
209 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
210 LPARAM user_data; /* Any user data stored in the stream object */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
211 struct ntpipe_slurp_stream_shared_data* thread_data;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
212 };
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
213
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
214 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-input", lstream_ntpipe_slurp,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
215 sizeof (struct ntpipe_slurp_stream));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
216
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
217 /* This function is thread-safe, and is called from either thread
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
218 context. It serializes freeing shared data structure */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
219 static void
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
220 slurper_free_shared_data_maybe (struct ntpipe_slurp_stream_shared_data* s)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
221 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
222 if (InterlockedDecrement (&s->lock_count) == 0)
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 /* Destroy events */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
225 CloseHandle (s->hev_thread);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
226 CloseHandle (s->hev_caller);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
227 CloseHandle (s->hev_unsleep);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
228 s->inuse_p = 0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
229 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
230 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
231
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
232 static struct ntpipe_slurp_stream_shared_data*
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
233 slurper_allocate_shared_data (void)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
234 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
235 int i=0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
236 for (i=0; i<MAX_SLURP_STREAMS; i++)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
237 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
238 if (!shared_data_block[i].inuse_p)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
239 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
240 shared_data_block[i].inuse_p=1;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
241 return &shared_data_block[i];
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
242 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
243 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
244 return (struct ntpipe_slurp_stream_shared_data*)0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
245 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
246
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
247 static DWORD WINAPI
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
248 slurp_thread (LPVOID vparam)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
249 {
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
250 struct ntpipe_slurp_stream_shared_data *s =
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
251 (struct ntpipe_slurp_stream_shared_data*)vparam;
274
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 for (;;)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
254 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
255 /* Read one byte from the pipe */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
256 DWORD actually_read;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
257 if (!ReadFile (s->hpipe, &s->onebyte, 1, &actually_read, NULL))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
258 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
259 DWORD err = GetLastError ();
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
260 if (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
261 s->eof_p = TRUE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
262 else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
263 s->error_p = TRUE;
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 else if (actually_read == 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
266 s->eof_p = TRUE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
267
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
268 /* We must terminate on an error or eof */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
269 if (s->eof_p || s->error_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
270 InterlockedIncrement (&s->die_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
271
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
272 /* Before we notify caller, we unsignal our event. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
273 ResetEvent (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
275 /* Now we got something to notify caller, either a byte or an
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
276 error/eof indication. Before we do, allow internal pipe
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
277 buffer to accumulate little bit more data.
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
278 Reader function pulses this event before waiting for
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
279 a character, to avoid pipe delay, and to get the byte
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
280 immediately. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
281 if (!s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
282 WaitForSingleObject (s->hev_unsleep, PIPE_READ_DELAY);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
283
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
284 /* Either make event loop generate a process event, or
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
285 inblock reader */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
286 SetEvent (s->hev_caller);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
287
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
288 /* Cleanup and exit if we're shot off */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
289 if (s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
290 break;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
291
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
292 /* Block until the client finishes with retrieving the rest of
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
293 pipe data */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
294 WaitForSingleObject (s->hev_thread, INFINITE);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
295 }
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 slurper_free_shared_data_maybe (s);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
298
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
299 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
300 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
301
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
302 static Lisp_Object
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
303 make_ntpipe_input_stream (HANDLE hpipe, LPARAM param)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
304 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
305 Lisp_Object obj;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
306 Lstream *lstr = Lstream_new (lstream_ntpipe_slurp, "r");
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
307 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA (lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
308 DWORD thread_id_unused;
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
309 HANDLE hthread;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
310
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
311 /* We deal only with pipes, for we're using PeekNamedPipe api */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
312 assert (GetFileType (hpipe) == FILE_TYPE_PIPE);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
313
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
314 s->thread_data = slurper_allocate_shared_data();
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
315
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
316 /* Create reader thread. This could fail, so do not create events
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
317 until thread is created */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
318 hthread = CreateThread (NULL, 0, slurp_thread, (LPVOID)s->thread_data,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
319 CREATE_SUSPENDED, &thread_id_unused);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
320 if (hthread == NULL)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
321 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
322 Lstream_delete (lstr);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
323 s->thread_data->inuse_p=0;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
324 return Qnil;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
325 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
326
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
327 /* Shared data are initially owned by both main and slurper
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
328 threads. */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
329 s->thread_data->lock_count = 2;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
330 s->thread_data->die_p = 0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
331 s->thread_data->eof_p = FALSE;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
332 s->thread_data->error_p = FALSE;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
333 s->thread_data->hpipe = hpipe;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
334 s->user_data = param;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
335
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
336 /* hev_thread is a manual-reset event, initially signaled */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
337 s->thread_data->hev_thread = CreateEvent (NULL, TRUE, TRUE, NULL);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
338 /* hev_caller is a manual-reset event, initially nonsignaled */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
339 s->thread_data->hev_caller = CreateEvent (NULL, TRUE, FALSE, NULL);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
340 /* hev_unsleep is a manual-reset event, initially nonsignaled */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
341 s->thread_data->hev_unsleep = CreateEvent (NULL, TRUE, FALSE, NULL);
274
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 /* Now let it go */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
344 ResumeThread (hthread);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
345 CloseHandle (hthread);
274
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 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
348 XSETLSTREAM (obj, lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
349 return obj;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
350 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
351
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
352 static LPARAM
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
353 get_ntpipe_input_stream_param (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
354 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
355 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
356 return s->user_data;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
357 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
358
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
359 static HANDLE
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
360 get_ntpipe_input_stream_waitable (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
361 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
362 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA(stream);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
363 return s->thread_data->hev_caller;
274
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
366 static ssize_t
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
367 ntpipe_slurp_reader (Lstream *stream, unsigned char *data, size_t size)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
368 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
369 /* This function must be called from the main thread only */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
370 struct ntpipe_slurp_stream_shared_data* s =
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
371 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
372
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
373 if (!s->die_p)
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 DWORD wait_result;
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
376 /* Disallow pipe read delay for the thread: we need a character
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
377 ASAP */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
378 SetEvent (s->hev_unsleep);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
379
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
380 /* Check if we have a character ready. Give it a short delay,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
381 for the thread to awake from pipe delay, just ion case*/
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
382 wait_result = WaitForSingleObject (s->hev_caller, 2);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
383
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
384 /* Revert to the normal sleep behavior. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
385 ResetEvent (s->hev_unsleep);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
386
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
387 /* If there's no byte buffered yet, give up */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
388 if (wait_result == WAIT_TIMEOUT)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
389 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
390 errno = EAGAIN;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
391 return -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
392 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
393 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
394
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
395 /* Reset caller unlock event now, as we've handled the pending
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
396 process output event */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
397 ResetEvent (s->hev_caller);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
398
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
399 /* 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
400 changing s->die_p, which still should be interlocked */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
401
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
402 if (s->eof_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
403 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
404 if (s->error_p || s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
405 return -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
406
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
407 /* 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
408 pipe */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
409 *(data++) = s->onebyte;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
410 --size;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
411
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
412 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
413 DWORD bytes_read = 0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
414 if (size > 0)
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 DWORD bytes_available;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
417
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
418 /* If the api call fails, return at least one byte already
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
419 read. ReadFile in thread will return error */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
420 if (PeekNamedPipe (s->hpipe, NULL, 0, NULL, &bytes_available, NULL))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
421 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
422
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
423 /* Fetch available bytes. The same consideration applies,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
424 so do not check for errors. ReadFile in the thread will
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
425 fail if the next call fails. */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
426 if (bytes_available)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
427 ReadFile (s->hpipe, data, min (bytes_available, size),
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
428 &bytes_read, NULL);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
429 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
430
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
431 /* Now we can unblock thread, so it attempts to read more */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
432 SetEvent (s->hev_thread);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
433 return bytes_read + 1;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
434 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
435 }
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
436 return 0;
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
439 static int
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
440 ntpipe_slurp_closer (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
441 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
442 /* This function must be called from the main thread only */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
443 struct ntpipe_slurp_stream_shared_data* s =
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
444 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
445
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
446 /* Force thread to stop */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
447 InterlockedIncrement (&s->die_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
448
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
449 /* Set events which could possibly block slurper. Let it finish soon
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
450 or later. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
451 SetEvent (s->hev_unsleep);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
452 SetEvent (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
453
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
454 /* Unlock and maybe free shared data */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
455 slurper_free_shared_data_maybe (s);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
456
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
457 return 0;
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
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
460 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
461 init_slurp_stream (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
462 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
463 LSTREAM_HAS_METHOD (ntpipe_slurp, reader);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
464 LSTREAM_HAS_METHOD (ntpipe_slurp, closer);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
465 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
466
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
467 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
468 /* Pipe outstream - writes process input */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
469 /************************************************************************/
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 #define NTPIPE_SHOVE_STREAM_DATA(stream) \
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
472 LSTREAM_TYPE_DATA (stream, ntpipe_shove)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
473
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
474 #define MAX_SHOVE_BUFFER_SIZE 512
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
475
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
476 struct ntpipe_shove_stream
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 LPARAM user_data; /* Any user data stored in the stream object */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
479 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
480 /* This is an auto-reset object. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
481 HANDLE hpipe; /* Pipe write end handle. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
482 HANDLE hthread; /* Reader thread handle. */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
483 char buffer[MAX_SHOVE_BUFFER_SIZE]; /* Buffer being written */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
484 DWORD size; /* Number of bytes to write */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
485 LONG die_p; /* Thread must exit ASAP if non-zero */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
486 LONG idle_p; /* Non-zero if thread is waiting for job */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
487 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
488 BOOL blocking_p : 1;/* Last write attempt would cause blocking */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
489 };
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 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-output", lstream_ntpipe_shove,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
492 sizeof (struct ntpipe_shove_stream));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
493
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
494 #ifndef HAVE_MSG_SELECT
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
495 static DWORD WINAPI
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
496 shove_thread (LPVOID vparam)
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 struct ntpipe_shove_stream *s = (struct ntpipe_shove_stream*) vparam;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
499
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
500 for (;;)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
501 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
502 DWORD bytes_written;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
503
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
504 /* Block on event and wait for a job */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
505 InterlockedIncrement (&s->idle_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
506 WaitForSingleObject (s->hev_thread, INFINITE);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
507
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
508 /* Write passed buffer if any */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
509 if (s->size > 0)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
510 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
511 if (!WriteFile (s->hpipe, s->buffer, s->size, &bytes_written, NULL)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
512 || bytes_written != s->size)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
513 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
514 s->error_p = TRUE;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
515 InterlockedIncrement (&s->die_p);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
516 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
517 /* Set size to zero so we won't write it again if the closer sets
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
518 die_p and kicks us */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
519 s->size = 0;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
520 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
521
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
522 if (s->die_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
523 break;
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
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
526 return 0;
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 static Lisp_Object
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
530 make_ntpipe_output_stream (HANDLE hpipe, LPARAM param)
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 Lisp_Object obj;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
533 Lstream *lstr = Lstream_new (lstream_ntpipe_shove, "w");
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
534 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA (lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
535 DWORD thread_id_unused;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
536
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
537 s->die_p = 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
538 s->error_p = FALSE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
539 s->hpipe = hpipe;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
540 s->user_data = param;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
541
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
542 /* Create reader thread. This could fail, so do not
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
543 create the event until thread is created */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
544 s->hthread = CreateThread (NULL, 0, shove_thread, (LPVOID)s,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
545 CREATE_SUSPENDED, &thread_id_unused);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
546 if (s->hthread == NULL)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
547 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
548 Lstream_delete (lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
549 return Qnil;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
550 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
551
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
552 /* Set the priority of the thread higher so we don't end up waiting
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
553 on it to send things. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
554 if (!SetThreadPriority (s->hthread, THREAD_PRIORITY_HIGHEST))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
555 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
556 CloseHandle (s->hthread);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
557 Lstream_delete (lstr);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
558 return Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
559 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
560
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
561 /* hev_thread is an auto-reset event, initially nonsignaled */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
562 s->hev_thread = CreateEvent (NULL, FALSE, FALSE, NULL);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
563
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
564 /* Now let it go */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
565 ResumeThread (s->hthread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
566
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
567 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
568 XSETLSTREAM (obj, lstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
569 return obj;
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
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
572 static LPARAM
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
573 get_ntpipe_output_stream_param (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
574 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
575 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
576 return s->user_data;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
577 }
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
578 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
579
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
580 static ssize_t
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
581 ntpipe_shove_writer (Lstream *stream, const unsigned char *data, size_t size)
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 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
584
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
585 if (s->error_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
586 return -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
587
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
588 s->blocking_p = !s->idle_p;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
589 if (s->blocking_p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
590 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
591
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
592 if (size>MAX_SHOVE_BUFFER_SIZE)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
593 return 0;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
594
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
595 memcpy (s->buffer, data, size);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
596 s->size = size;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
597
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
598 /* Start output */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
599 InterlockedDecrement (&s->idle_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
600 SetEvent (s->hev_thread);
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
601 /* Give it a chance to run -- this dramatically improves performance
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
602 of things like crypt. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
603 (void) SwitchToThread ();
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
604 return size;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
605 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
606
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
607 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
608 ntpipe_shove_was_blocked_p (Lstream *stream)
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 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
611 return s->blocking_p;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
612 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
613
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
614 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
615 ntpipe_shove_closer (Lstream *stream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
616 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
617 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
618
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
619 /* Force thread stop */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
620 InterlockedIncrement (&s->die_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
621
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
622 /* Thread will end upon unblocking. If it's already unblocked this will
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
623 do nothing, but the thread won't look at die_p until it's written any
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
624 pending output. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
625 SetEvent (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
626
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
627 /* Wait while thread terminates */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
628 WaitForSingleObject (s->hthread, INFINITE);
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
629
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
630 /* Close pipe handle, possibly breaking it */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
631 CloseHandle (s->hpipe);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
632
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
633 /* Close the thread handle */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
634 CloseHandle (s->hthread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
635
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
636 /* Destroy the event */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
637 CloseHandle (s->hev_thread);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
638
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
639 return 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
640 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
641
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
642 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
643 init_shove_stream (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
644 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
645 LSTREAM_HAS_METHOD (ntpipe_shove, writer);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
646 LSTREAM_HAS_METHOD (ntpipe_shove, was_blocked_p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
647 LSTREAM_HAS_METHOD (ntpipe_shove, closer);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
648 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
649
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
650 /************************************************************************/
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
651 /* Winsock I/O stream */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
652 /************************************************************************/
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
653 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
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 #define WINSOCK_READ_BUFFER_SIZE 1024
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
656
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
657 struct winsock_stream
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 LPARAM user_data; /* Any user data stored in the stream object */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
660 SOCKET s; /* Socket handle (which is a Win32 handle) */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
661 OVERLAPPED ov; /* Overlapped I/O structure */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
662 void* buffer; /* Buffer. Allocated for input stream only */
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
663 unsigned long bufsize; /* Number of bytes last read */
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
664 unsigned long bufpos; /* Position in buffer for next fetch */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
665 unsigned int error_p :1; /* I/O Error seen */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
666 unsigned int eof_p :1; /* EOF Error seen */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
667 unsigned int pending_p :1; /* There is a pending I/O operation */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
668 unsigned int blocking_p :1; /* Last write attempt would block */
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
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
671 #define WINSOCK_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, winsock)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
672
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
673 DEFINE_LSTREAM_IMPLEMENTATION ("winsock", lstream_winsock,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
674 sizeof (struct winsock_stream));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
675
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
676 static void
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
677 winsock_initiate_read (struct winsock_stream *str)
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 ResetEvent (str->ov.hEvent);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
680 str->bufpos = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
681
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
682 if (!ReadFile ((HANDLE)str->s, str->buffer, WINSOCK_READ_BUFFER_SIZE,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
683 &str->bufsize, &str->ov))
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 (GetLastError () == ERROR_IO_PENDING)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
686 str->pending_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
687 else if (GetLastError () == ERROR_HANDLE_EOF)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
688 str->eof_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
689 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
690 str->error_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
691 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
692 else if (str->bufsize == 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
693 str->eof_p = 1;
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
696 static ssize_t
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
697 winsock_reader (Lstream *stream, unsigned char *data, size_t size)
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 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
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 /* If the current operation is not yet complete, there's nothing to
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
702 give back */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
703 if (str->pending_p)
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 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
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 errno = EAGAIN;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
708 return -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
709 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
710 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
711 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
712 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &str->bufsize, TRUE))
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 if (GetLastError() == ERROR_HANDLE_EOF)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
715 str->bufsize = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
716 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
717 str->error_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
718 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
719 if (str->bufsize == 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
720 str->eof_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
721 str->pending_p = 0;
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 }
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->eof_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
726 return 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
727 if (str->error_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
728 return -1;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
729
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
730 /* Return as much of buffer as we have */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
731 size = min (size, (size_t) (str->bufsize - str->bufpos));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
732 memcpy (data, (void*)((BYTE*)str->buffer + str->bufpos), size);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
733 str->bufpos += size;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
734
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
735 /* Read more if buffer is exhausted */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
736 if (str->bufsize == str->bufpos)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
737 winsock_initiate_read (str);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
738
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
739 return size;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
740 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
741
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
742 static ssize_t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
743 winsock_writer (Lstream *stream, const unsigned char *data, size_t size)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
744 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
745 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
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 if (str->pending_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
748 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
749 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
750 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
751 str->blocking_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
752 return -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
753 }
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 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
756 DWORD dw_unused;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
757 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &dw_unused, TRUE))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
758 str->error_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
759 str->pending_p = 0;
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 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
762
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
763 str->blocking_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
764
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
765 if (str->error_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
766 return -1;
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 if (size == 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
769 return 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
770
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
771 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
772 ResetEvent (str->ov.hEvent);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
773
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
774 /* Docs indicate that 4th parameter to WriteFile can be NULL since this is
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
775 * an overlapped operation. This fails on Win95 with winsock 1.x so we
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
776 * supply a spare address which is ignored by Win95 anyway. Sheesh. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
777 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
778 || GetLastError() == ERROR_IO_PENDING)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
779 str->pending_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
780 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
781 str->error_p = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
782 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
783
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
784 return str->error_p ? -1 : size;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
785 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
786
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
787 static int
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
788 winsock_closer (Lstream *lstr)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
789 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
790 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
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 shutdown (str->s, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
794 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
795 shutdown (str->s, 1);
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 CloseHandle ((HANDLE)str->s);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
798 if (str->pending_p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
799 WaitForSingleObject (str->ov.hEvent, INFINITE);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
800
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
801 if (lstr->flags & LSTREAM_FL_READ)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
802 xfree (str->buffer);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
803
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
804 CloseHandle (str->ov.hEvent);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
805 return 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
806 }
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 static int
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
809 winsock_was_blocked_p (Lstream *stream)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
810 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
811 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
812 return str->blocking_p;
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 Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
816 make_winsock_stream_1 (SOCKET s, LPARAM param, const char *mode)
282
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 Lisp_Object obj;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
819 Lstream *lstr = Lstream_new (lstream_winsock, mode);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
820 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
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 str->s = s;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
823 str->blocking_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
824 str->error_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
825 str->eof_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
826 str->pending_p = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
827 str->user_data = param;
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 xzero (str->ov);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
830 str->ov.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
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 if (lstr->flags & LSTREAM_FL_READ)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
833 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
834 str->buffer = xmalloc (WINSOCK_READ_BUFFER_SIZE);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
835 winsock_initiate_read (str);
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
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
838 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
839 XSETLSTREAM (obj, lstr);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
840 return obj;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
841 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
842
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
843 static Lisp_Object
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
844 make_winsock_input_stream (SOCKET s, LPARAM param)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
845 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
846 return make_winsock_stream_1 (s, param, "r");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
847 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
848
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
849 static Lisp_Object
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
850 make_winsock_output_stream (SOCKET s, LPARAM param)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
851 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
852 return make_winsock_stream_1 (s, param, "w");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
853 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
854
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
855 static HANDLE
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
856 get_winsock_stream_waitable (Lstream *lstr)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
857 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
858 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
859 return str->ov.hEvent;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
860 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
861
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
862 static LPARAM
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
863 get_winsock_stream_param (Lstream *lstr)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
864 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
865 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
866 return str->user_data;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
867 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
868
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
869 static void
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
870 init_winsock_stream (void)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
871 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
872 LSTREAM_HAS_METHOD (winsock, reader);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
873 LSTREAM_HAS_METHOD (winsock, writer);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
874 LSTREAM_HAS_METHOD (winsock, closer);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
875 LSTREAM_HAS_METHOD (winsock, was_blocked_p);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
876 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
877 #endif /* defined (HAVE_SOCKETS) */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
878
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
879 /************************************************************************/
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
880 /* Dispatch queue management */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
881 /************************************************************************/
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
882
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
883 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
884 mswindows_user_event_p (Lisp_Event* sevt)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
885 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
886 return (sevt->event_type == key_press_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
887 || sevt->event_type == button_press_event
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
888 || sevt->event_type == button_release_event
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
889 || sevt->event_type == misc_user_event);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
890 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
891
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
892 /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
893 * Add an emacs event to the proper dispatch queue
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
894 */
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
895 void
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
896 mswindows_enqueue_dispatch_event (Lisp_Object event)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
897 {
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
898 int user_p = mswindows_user_event_p (XEVENT(event));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
899 enqueue_event (event,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
900 user_p ? &mswindows_u_dispatch_event_queue :
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
901 &mswindows_s_dispatch_event_queue,
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
902 user_p ? &mswindows_u_dispatch_event_queue_tail :
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
903 &mswindows_s_dispatch_event_queue_tail);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
904
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
905 /* Avoid blocking on WaitMessage */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
906 PostMessage (NULL, XM_BUMPQUEUE, 0, 0);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
907 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
908
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
909 /*
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
910 * Add a misc-user event to the dispatch queue.
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
911 *
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
912 * Stuff it into our own dispatch queue, so we have something
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
913 * to return from next_event callback.
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
914 */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
915 void
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
916 mswindows_enqueue_misc_user_event (Lisp_Object channel, Lisp_Object function,
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
917 Lisp_Object object)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
918 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
919 Lisp_Object event = Fmake_event (Qnil, Qnil);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
920 Lisp_Event* e = XEVENT (event);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
921
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
922 e->event_type = misc_user_event;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
923 e->channel = channel;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
924 e->timestamp = GetTickCount ();
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
925 e->event.misc.function = function;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
926 e->event.misc.object = object;
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
927
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
928 mswindows_enqueue_dispatch_event (event);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
929 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
930
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
931 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
932 mswindows_enqueue_magic_event (HWND hwnd, UINT msg)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
933 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
934 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
935 Lisp_Event* event = XEVENT (emacs_event);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
936
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
937 event->channel = hwnd ? mswindows_find_frame (hwnd) : Qnil;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
938 event->timestamp = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
939 event->event_type = magic_event;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
940 EVENT_MSWINDOWS_MAGIC_TYPE (event) = msg;
249
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 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
943 }
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 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
946 mswindows_enqueue_process_event (Lisp_Process* p)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
947 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
948 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
949 Lisp_Event* event = XEVENT (emacs_event);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
950 Lisp_Object process;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
951 XSETPROCESS (process, p);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
952
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
953 event->event_type = process_event;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
954 event->timestamp = GetTickCount ();
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
955 event->event.process.process = process;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
956
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
957 mswindows_enqueue_dispatch_event (emacs_event);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
958 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
959
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
960 static void
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
961 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT msg, POINTS where,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
962 DWORD when)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
963 {
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
964 int downp = (msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN ||
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
965 msg == WM_RBUTTONDOWN);
249
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 /* We always use last message time, because mouse button
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
968 events may get delayed, and XEmacs double click
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
969 recognition will fail */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
970
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
971 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
972 Lisp_Event* event = XEVENT (emacs_event);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
973
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
974 mswindows_handle_sticky_modifiers (0, 0, downp, 0);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
975 event->channel = mswindows_find_frame (hwnd);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
976 event->timestamp = when;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
977 event->event.button.button =
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
978 (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP) ? 1 :
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
979 ((msg==WM_RBUTTONDOWN || msg==WM_RBUTTONUP) ? 3 : 2);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
980 event->event.button.x = where.x;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
981 event->event.button.y = where.y;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
982 event->event.button.modifiers = mswindows_modifier_state (NULL, 0);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
983
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
984 if (downp)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
985 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
986 event->event_type = button_press_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
987 SetCapture (hwnd);
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
988 /* we need this to make sure the main window regains the focus
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
989 from control subwindows */
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
990 if (GetFocus() != hwnd)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
991 {
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
992 SetFocus (hwnd);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
993 mswindows_enqueue_magic_event (hwnd, WM_SETFOCUS);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
994 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
995 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
996 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
997 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
998 event->event_type = button_release_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
999 ReleaseCapture ();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1000 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1001
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1002 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1003 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1004
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1005 static void
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1006 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1007 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1008 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1009 Lisp_Event* event = XEVENT(emacs_event);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1010
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1011 event->channel = mswindows_find_console(hwnd);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1012 event->timestamp = GetMessageTime();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1013 event->event_type = key_press_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1014 event->event.key.keysym = keysym;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1015 event->event.key.modifiers = mods;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1016 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1017 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1018
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 * Remove and return the first emacs event on the dispatch queue.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1021 * Give a preference to user events over non-user ones.
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1022 */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1023 static Lisp_Object
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1024 mswindows_dequeue_dispatch_event (void)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1025 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1026 Lisp_Object event;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1027 Lisp_Event* sevt;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1028
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1029 assert (!NILP(mswindows_u_dispatch_event_queue) ||
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1030 !NILP(mswindows_s_dispatch_event_queue));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1031
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1032 event = dequeue_event (
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1033 NILP(mswindows_u_dispatch_event_queue) ?
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1034 &mswindows_s_dispatch_event_queue :
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1035 &mswindows_u_dispatch_event_queue,
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1036 NILP(mswindows_u_dispatch_event_queue) ?
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1037 &mswindows_s_dispatch_event_queue_tail :
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1038 &mswindows_u_dispatch_event_queue_tail);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1039
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1040 sevt = XEVENT(event);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1041 if (sevt->event_type == key_press_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1042 && (sevt->event.key.modifiers & FAKE_MOD_QUIT))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1043 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1044 sevt->event.key.modifiers &= ~FAKE_MOD_QUIT;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1045 --mswindows_quit_chars_count;
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
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1048 return event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1049 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1050
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1051 /*
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1052 * Remove and return the first emacs event on the dispatch queue that matches
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1053 * the supplied event.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1054 * Timeout event matches if interval_id is equal to that of the given event.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1055 * Keypress event matches if logical AND between modifiers bitmask of the
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1056 * event in the queue and that of the given event is non-zero.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1057 * For all other event types, this function aborts.
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1058 */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1059
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1060 Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1061 mswindows_cancel_dispatch_event (Lisp_Event *match)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1062 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1063 Lisp_Object event;
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1064 Lisp_Object previous_event = Qnil;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1065 int user_p = mswindows_user_event_p (match);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1066 Lisp_Object* head = user_p ? &mswindows_u_dispatch_event_queue :
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1067 &mswindows_s_dispatch_event_queue;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1068 Lisp_Object* tail = user_p ? &mswindows_u_dispatch_event_queue_tail :
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1069 &mswindows_s_dispatch_event_queue_tail;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1070
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1071 assert (match->event_type == timeout_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1072 || match->event_type == key_press_event);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1073
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1074 EVENT_CHAIN_LOOP (event, *head)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1075 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1076 Lisp_Event *e = XEVENT (event);
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1077 if ((e->event_type == match->event_type) &&
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1078 ((e->event_type == timeout_event) ?
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1079 (e->event.timeout.interval_id == match->event.timeout.interval_id) :
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1080 /* Must be key_press_event */
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1081 ((e->event.key.modifiers & match->event.key.modifiers) != 0)))
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1082 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1083 if (NILP (previous_event))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1084 dequeue_event (head, tail);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1085 else
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1086 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1087 XSET_EVENT_NEXT (previous_event, XEVENT_NEXT (event));
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1088 if (EQ (*tail, event))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1089 *tail = previous_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1090 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1091
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1092 return event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1093 }
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1094 previous_event = event;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1095 }
239
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 233
diff changeset
1096 return Qnil;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1097 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1098
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1099 #ifndef HAVE_MSG_SELECT
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1100 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1101 /* Waitable handles manipulation */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1102 /************************************************************************/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1103 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1104 find_waitable_handle (HANDLE h)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1105 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1106 int i;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1107 for (i = 0; i < mswindows_waitable_count; ++i)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1108 if (mswindows_waitable_handles[i] == h)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1109 return i;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1110
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1111 return -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1112 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1113
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1114 static BOOL
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1115 add_waitable_handle (HANDLE h)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1116 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1117 assert (find_waitable_handle (h) < 0);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1118 if (mswindows_waitable_count == MAX_WAITABLE)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1119 return FALSE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1120
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1121 mswindows_waitable_handles [mswindows_waitable_count++] = h;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1122 return TRUE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1123 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1124
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1125 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1126 remove_waitable_handle (HANDLE h)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1127 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1128 int ix = find_waitable_handle (h);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1129 if (ix < 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1130 return;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1131
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1132 mswindows_waitable_handles [ix] =
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1133 mswindows_waitable_handles [--mswindows_waitable_count];
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1134 }
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1135 #endif /* HAVE_MSG_SELECT */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1136
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1137
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1138 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1139 /* Event pump */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1140 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1141
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1142 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1143 mswindows_modal_loop_error_handler (Lisp_Object cons_sig_data,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1144 Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1145 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1146 mswindows_error_caught_in_modal_loop = cons_sig_data;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1147 return Qunbound;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1148 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1149
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1150 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1151 mswindows_protect_modal_loop (Lisp_Object (*bfun) (Lisp_Object barg),
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1152 Lisp_Object barg)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1153 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1154 Lisp_Object tmp;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1155
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1156 ++mswindows_in_modal_loop;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1157 tmp = condition_case_1 (Qt,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1158 bfun, barg,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1159 mswindows_modal_loop_error_handler, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1160 --mswindows_in_modal_loop;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1161
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1162 return tmp;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1163 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1164
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1165 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1166 mswindows_unmodalize_signal_maybe (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1167 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1168 if (!NILP (mswindows_error_caught_in_modal_loop))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1169 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1170 /* Got an error while messages were pumped while
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1171 in window procedure - have to resignal */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1172 Lisp_Object sym = XCAR (mswindows_error_caught_in_modal_loop);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1173 Lisp_Object data = XCDR (mswindows_error_caught_in_modal_loop);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1174 mswindows_error_caught_in_modal_loop = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1175 Fsignal (sym, data);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1176 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1177 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1178
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1179 /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1180 * This is an unsafe part of event pump, guarded by
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1181 * condition_case. See mswindows_pump_outstanding_events
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1182 */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1183 static Lisp_Object
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1184 mswindows_unsafe_pump_events (Lisp_Object u_n_u_s_e_d)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1185 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1186 /* This function can call lisp */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1187 Lisp_Object event = Fmake_event (Qnil, Qnil);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1188 struct gcpro gcpro1;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1189 int do_redisplay = 0;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1190 GCPRO1 (event);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1191
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1192 while (detect_input_pending ())
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1193 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1194 Fnext_event (event, Qnil);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1195 Fdispatch_event (event);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1196 do_redisplay = 1;
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
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1199 if (do_redisplay)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1200 redisplay ();
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1201
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1202 Fdeallocate_event (event);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1203 UNGCPRO;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1204
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1205 /* Qt becomes return value of mswindows_pump_outstanding_events
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1206 once we get here */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1207 return Qt;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1208 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1209
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1210 /*
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1211 * This function pumps emacs events, while available, by using
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1212 * next_message/dispatch_message loop. Errors are trapped around
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1213 * the loop so the function always returns.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1214 *
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1215 * Windows message queue is not looked into during the call,
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1216 * neither are waitable handles checked. The function pumps
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1217 * thus only dispatch events already queued, as well as those
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1218 * resulted in dispatching thereof. This is done by setting
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1219 * module local variable mswindows_in_modal_loop to nonzero.
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1220 *
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1221 * 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
1222 * there was an error.
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 * In case of error, a cons representing the error, in the
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1225 * form (SIGNAL . DATA), is stored in the module local variable
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1226 * mswindows_error_caught_in_modal_loop. This error is signaled
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1227 * again when DispatchMessage returns. Thus, Windows internal
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1228 * modal loops are protected against throws, which are proven
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1229 * to corrupt internal Windows structures.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1230 *
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1231 * In case of success, mswindows_error_caught_in_modal_loop is
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1232 * assigned Qnil.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1233 *
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1234 * 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
1235 * nil already upon entry, the function just returns non-nil.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1236 * This situation means that a new event has been queued while
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1237 * in cancel mode. The event will be dequeued on the next regular
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1238 * call of next-event; the pump is off since error is caught.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1239 * The caller must *unconditionally* cancel modal loop if the
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1240 * value returned by this function is nil. Otherwise, everything
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1241 * will become frozen until the modal loop exits under normal
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1242 * condition (scrollbar drag is released, menu closed etc.)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1243 */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1244 Lisp_Object
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1245 mswindows_pump_outstanding_events (void)
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 /* This function can call lisp */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1248
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1249 Lisp_Object result = Qt;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1250 struct gcpro gcpro1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1251 GCPRO1 (result);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1252
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1253 if (NILP(mswindows_error_caught_in_modal_loop))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1254 result = mswindows_protect_modal_loop (mswindows_unsafe_pump_events, Qnil);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1255 UNGCPRO;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1256 return result;
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1259 /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1260 * KEYBOARD_ONLY_P is set to non-zero when we are called from
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1261 * QUITP, and are interesting in keyboard messages only.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1262 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1263 static void
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1264 mswindows_drain_windows_queue (void)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1265 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1266 MSG msg;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1267
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1268 /* should call mswindows_need_event_in_modal_loop() if in modal loop */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1269 assert (!mswindows_in_modal_loop);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1270
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1271 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1272 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1273 /* We have to translate messages that are not sent to an XEmacs
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1274 frame. This is so that key presses work ok in things like
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1275 edit fields. However, we *musn't* translate message for XEmacs
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1276 frames as this is handled in the wnd proc.
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1277 We also have to avoid generating paint magic events for windows
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1278 that aren't XEmacs frames */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1279 /* GetClassName will truncate a longer class name. By adding one
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1280 extra character, we are forcing textual comparison to fail
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1281 if the name is longer than XEMACS_CLASS */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1282 char class_name_buf [sizeof (XEMACS_CLASS) + 2] = "";
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1283 GetClassName (msg.hwnd, class_name_buf, sizeof (class_name_buf) - 1);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1284 if (stricmp (class_name_buf, XEMACS_CLASS) != 0)
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1285 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1286 /* Not an XEmacs frame */
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1287 TranslateMessage (&msg);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
1288 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1289 else if (msg.message == WM_PAINT)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1290 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1291 struct mswindows_frame* msframe;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1292
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1293 /* hdc will be NULL unless this is a subwindow - in which case we
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1294 shouldn't have received a paint message for it here. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1295 assert (msg.wParam == 0);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1296
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
1297 /* Queue a magic event for handling when safe */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1298 msframe =
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1299 FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (msg.hwnd)));
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1300 if (!msframe->paint_pending)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1301 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1302 msframe->paint_pending = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1303 mswindows_enqueue_magic_event (msg.hwnd, WM_PAINT);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1304 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1305 /* Don't dispatch. WM_PAINT is always the last message in the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1306 queue so it's OK to just return. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1307 return;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1308 }
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1309 DispatchMessage (&msg);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1310 mswindows_unmodalize_signal_maybe ();
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1311 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1312 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1313
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1314 /*
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1315 * This is a special flavor of the mswindows_need_event function,
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1316 * used while in event pump. Actually, there is only kind of events
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1317 * allowed while in event pump: a timer. An attempt to fetch any
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1318 * other event leads to a deadlock, as there's no source of user input
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1319 * ('cause event pump mirrors windows modal loop, which is a sole
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1320 * owner of thread message queue).
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1321 *
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1322 * To detect this, we use a counter of active timers, and allow
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1323 * fetching WM_TIMER messages. Instead of trying to fetch a WM_TIMER
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1324 * which will never come when there are no pending timers, which leads
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1325 * to deadlock, we simply signal an error.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1326 */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1327 static void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1328 mswindows_need_event_in_modal_loop (int badly_p)
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1329 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1330 MSG msg;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1331
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1332 /* Check if already have one */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1333 if (!NILP (mswindows_u_dispatch_event_queue)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1334 || !NILP (mswindows_s_dispatch_event_queue))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1335 return;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1336
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1337 /* No event is ok */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1338 if (!badly_p)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1339 return;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1340
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1341 /* We do not check the _u_ queue, because timers go to _s_ */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1342 while (NILP (mswindows_s_dispatch_event_queue))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1343 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1344 /* We'll deadlock if go waiting */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1345 if (mswindows_pending_timers_count == 0)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1346 error ("Deadlock due to an attempt to call next-event in a wrong context");
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1347
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1348 /* Fetch and dispatch any pending timers */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1349 GetMessage (&msg, NULL, WM_TIMER, WM_TIMER);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1350 DispatchMessage (&msg);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1351 }
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1352 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1353
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1354 /*
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1355 * This drains the event queue and fills up two internal queues until
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1356 * an event of a type specified by USER_P is retrieved.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1357 *
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1358 *
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1359 * Used by emacs_mswindows_event_pending_p and emacs_mswindows_next_event
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1360 */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1361 static void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1362 mswindows_need_event (int badly_p)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1363 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1364 int active;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1365
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
1366 if (mswindows_in_modal_loop)
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1367 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1368 mswindows_need_event_in_modal_loop (badly_p);
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1369 return;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1370 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
1371
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1372 while (NILP (mswindows_u_dispatch_event_queue)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1373 && NILP (mswindows_s_dispatch_event_queue))
278
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 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1376 int i;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1377 SELECT_TYPE temp_mask = input_wait_mask;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1378 EMACS_TIME sometime;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1379 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1380
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1381 if (badly_p)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1382 pointer_to_this = 0;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1383 else
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1384 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1385 EMACS_SET_SECS_USECS (sometime, 0, 0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1386 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1387 pointer_to_this = &select_time_to_block;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1388 }
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
1389
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1390 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1391
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1392 if (active == 0)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1393 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1394 assert (!badly_p);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1395 return; /* timeout */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1396 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1397 else if (active > 0)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1398 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1399 if (FD_ISSET (windows_fd, &temp_mask))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1400 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1401 mswindows_drain_windows_queue ();
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1402 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1403 else
392
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
1404 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1405 #ifdef HAVE_TTY
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1406 /* Look for a TTY event */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1407 for (i = 0; i < MAXDESC-1; i++)
392
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
1408 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1409 /* To avoid race conditions (among other things, an infinite
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1410 loop when called from Fdiscard_input()), we must return
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1411 user events ahead of process events. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1412 if (FD_ISSET (i, &temp_mask) && FD_ISSET (i, &tty_only_mask))
392
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
1413 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1414 struct console *c = tty_find_console_from_fd (i);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1415 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1416 Lisp_Event* event = XEVENT (emacs_event);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1417
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1418 assert (c);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1419 if (read_event_from_tty_or_stream_desc (event, c, i))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1420 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1421 mswindows_enqueue_dispatch_event (emacs_event);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1422 return;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1423 }
392
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
1424 }
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
1425 }
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
1426 #endif
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1427 /* Look for a process event */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1428 for (i = 0; i < MAXDESC-1; i++)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1429 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1430 if (FD_ISSET (i, &temp_mask))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1431 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1432 if (FD_ISSET (i, &process_only_mask))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1433 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1434 Lisp_Process *p =
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1435 get_process_from_usid (FD_TO_USID(i));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1436
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1437 mswindows_enqueue_process_event (p);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1438 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1439 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1440 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1441 /* We might get here when a fake event came
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1442 through a signal. Return a dummy event, so
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1443 that a cycle of the command loop will
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1444 occur. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1445 drain_signal_event_pipe ();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1446 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1447 }
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1448 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1449 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1450 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1451 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1452 else if (active==-1)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1453 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1454 if (errno != EINTR)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1455 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1456 /* something bad happened */
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1457 assert(0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1458 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1459 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1460 else
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1461 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1462 assert(0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1463 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1464 #else
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1465 /* Now try getting a message or process event */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1466 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1467 mswindows_waitable_handles,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1468 FALSE, badly_p ? INFINITE : 0,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1469 QS_ALLINPUT);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1470
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1471 /* This will assert if handle being waited for becomes abandoned.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1472 Not the case currently tho */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1473 assert ((!badly_p && active == WAIT_TIMEOUT) ||
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1474 (active >= WAIT_OBJECT_0 &&
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1475 active <= WAIT_OBJECT_0 + mswindows_waitable_count));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1476
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1477 if (active == WAIT_TIMEOUT)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1478 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1479 /* No luck trying - just return what we've already got */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1480 return;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1481 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1482 else if (active == WAIT_OBJECT_0 + mswindows_waitable_count)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1483 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1484 /* Got your message, thanks */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1485 mswindows_drain_windows_queue ();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1486 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1487 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1488 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1489 int ix = active - WAIT_OBJECT_0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1490 /* First, try to find which process' output has signaled */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1491 Lisp_Process *p =
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1492 get_process_from_usid (HANDLE_TO_USID (mswindows_waitable_handles[ix]));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1493 if (p != NULL)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1494 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1495 /* Found a signaled process input handle */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1496 mswindows_enqueue_process_event (p);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1497 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1498 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1499 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1500 /* None. This means that the process handle itself has signaled.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1501 Remove the handle from the wait vector, and make status_notify
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1502 note the exited process */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1503 mswindows_waitable_handles [ix] =
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1504 mswindows_waitable_handles [--mswindows_waitable_count];
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1505 kick_status_notify ();
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1506 /* We need to return a process event here so that
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1507 (1) accept-process-output will return when called on this
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1508 process, and (2) status notifications will happen in
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1509 accept-process-output, sleep-for, and sit-for. */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1510 /* #### horrible kludge till my real process fixes go in.
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1511 */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1512 if (!NILP (Vprocess_list))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1513 {
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1514 Lisp_Object vaffanculo = XCAR (Vprocess_list);
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1515 mswindows_enqueue_process_event (XPROCESS (vaffanculo));
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1516 }
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1517 else /* trash me soon. */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1518 /* Have to return something: there may be no accompanying
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1519 process event */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1520 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1521 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1522 }
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
1523 #endif
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1524 } /* while */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1525 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
1526
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1527 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1528 /* Event generators */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1529 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1530
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1531 /*
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1532 * Callback procedure for synchronous timer messages
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1533 */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1534 static void CALLBACK
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1535 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
1536 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1537 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1538 Lisp_Event *event = XEVENT (emacs_event);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1539
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1540 if (KillTimer (NULL, id_timer))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1541 --mswindows_pending_timers_count;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1542
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1543 event->channel = Qnil;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1544 event->timestamp = dwtime;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1545 event->event_type = timeout_event;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1546 event->event.timeout.interval_id = id_timer;
382
064ab7fed2e0 Import from CVS: tag r21-2-6
cvs
parents: 380
diff changeset
1547 event->event.timeout.function = Qnil;
064ab7fed2e0 Import from CVS: tag r21-2-6
cvs
parents: 380
diff changeset
1548 event->event.timeout.object = Qnil;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1549
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1550 mswindows_enqueue_dispatch_event (emacs_event);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1551 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1552
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1553 /*
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1554 * Callback procedure for dde messages
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1555 *
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1556 * 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
1557 * depends on dnd support.
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1558 */
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1559 #ifdef HAVE_DRAGNDROP
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1560 HDDEDATA CALLBACK
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1561 mswindows_dde_callback (UINT uType, UINT uFmt, HCONV hconv,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1562 HSZ hszTopic, HSZ hszItem, HDDEDATA hdata,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1563 DWORD dwData1, DWORD dwData2)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1564 {
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1565 switch (uType)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1566 {
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1567 case XTYP_CONNECT:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1568 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1569 return (HDDEDATA)TRUE;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1570 return (HDDEDATA)FALSE;
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 case XTYP_WILDCONNECT:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1573 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1574 /* We only support one {service,topic} pair */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1575 HSZPAIR pairs[2] = {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1576 { mswindows_dde_service, mswindows_dde_topic_system }, { 0, 0 } };
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 if (!(hszItem || DdeCmpStringHandles (hszItem, mswindows_dde_service)) &&
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
1579 !(hszTopic || DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)))
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1580 return (DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE)pairs,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1581 sizeof (pairs), 0L, 0, uFmt, 0));
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1582 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1583 return (HDDEDATA)NULL;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1584
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1585 case XTYP_EXECUTE:
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1586 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1587 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1588 DWORD len = DdeGetData (hdata, NULL, 0, 0);
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
1589 LPBYTE cmd = (LPBYTE) alloca (len+1);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1590 char *end;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1591 char *filename;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1592 struct gcpro gcpro1, gcpro2;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1593 Lisp_Object l_dndlist = Qnil;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1594 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1595 Lisp_Object frmcons, devcons, concons;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1596 Lisp_Event *event = XEVENT (emacs_event);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1597
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1598 DdeGetData (hdata, cmd, len, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1599 cmd[len] = '\0';
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1600 DdeFreeDataHandle (hdata);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1601
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1602 /* Check syntax & that it's an [Open("foo")] command, which we
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1603 * treat like a file drop */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1604 /* #### Ought to be generalised and accept some other commands */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1605 if (*cmd == '[')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1606 cmd++;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1607 if (strnicmp (cmd, MSWINDOWS_DDE_ITEM_OPEN,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1608 strlen (MSWINDOWS_DDE_ITEM_OPEN)))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1609 return DDE_FNOTPROCESSED;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1610 cmd += strlen (MSWINDOWS_DDE_ITEM_OPEN);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1611 while (*cmd==' ')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1612 cmd++;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1613 if (*cmd!='(' || *(cmd+1)!='\"')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1614 return DDE_FNOTPROCESSED;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1615 end = (cmd+=2);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1616 while (*end && *end!='\"')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1617 end++;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1618 if (!*end)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1619 return DDE_FNOTPROCESSED;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1620 *end = '\0';
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1621 if (*(++end)!=')')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1622 return DDE_FNOTPROCESSED;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1623 if (*(++end)==']')
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1624 end++;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1625 if (*end)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1626 return DDE_FNOTPROCESSED;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1627
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1628 #ifdef CYGWIN
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1629 filename = alloca (cygwin32_win32_to_posix_path_list_buf_size (cmd) + 5);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1630 strcpy (filename, "file:");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1631 cygwin32_win32_to_posix_path_list (cmd, filename+5);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1632 #else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1633 dostounix_filename (cmd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1634 filename = alloca (strlen (cmd)+6);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1635 strcpy (filename, "file:");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1636 strcat (filename, cmd);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
1637 #endif
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1638 GCPRO2 (emacs_event, l_dndlist);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1639 l_dndlist = make_string (filename, strlen (filename));
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1640
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1641 /* Find a mswindows frame */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1642 event->channel = Qnil;
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1643 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1644 {
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1645 Lisp_Object frame = XCAR (frmcons);
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1646 if (FRAME_TYPE_P (XFRAME (frame), mswindows))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1647 event->channel = frame;
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1648 };
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1649 assert (!NILP (event->channel));
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1650
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1651 event->timestamp = GetTickCount();
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1652 event->event_type = misc_user_event;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1653 event->event.misc.button = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1654 event->event.misc.modifiers = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1655 event->event.misc.x = -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1656 event->event.misc.y = -1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1657 event->event.misc.function = Qdragdrop_drop_dispatch;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1658 event->event.misc.object = Fcons (Qdragdrop_URL,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1659 Fcons (l_dndlist, Qnil));
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1660 mswindows_enqueue_dispatch_event (emacs_event);
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1661 UNGCPRO;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1662 return (HDDEDATA) DDE_FACK;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1663 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1664 DdeFreeDataHandle (hdata);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1665 return (HDDEDATA) DDE_FNOTPROCESSED;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1666
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1667 default:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1668 return (HDDEDATA) NULL;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1669 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
1670 }
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
1671 #endif
249
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 /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1674 * Helper to do repainting - repaints can happen both from the windows
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1675 * procedure and from magic events
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1676 */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1677 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1678 mswindows_handle_paint (struct frame *frame)
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1679 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1680 HWND hwnd = FRAME_MSWINDOWS_HANDLE (frame);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1681
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1682 /* According to the docs we need to check GetUpdateRect() before
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1683 actually doing a WM_PAINT */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1684 if (GetUpdateRect (hwnd, NULL, FALSE))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1685 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1686 PAINTSTRUCT paintStruct;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1687 int x, y, width, height;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1688
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1689 BeginPaint (hwnd, &paintStruct);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1690 x = paintStruct.rcPaint.left;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1691 y = paintStruct.rcPaint.top;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1692 width = paintStruct.rcPaint.right - paintStruct.rcPaint.left;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1693 height = paintStruct.rcPaint.bottom - paintStruct.rcPaint.top;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1694 /* Normally we want to ignore expose events when child
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1695 windows are unmapped, however once we are in the guts of
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1696 WM_PAINT we need to make sure that we don't register
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1697 unmaps then because they will not actually occur. */
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1698 /* #### commenting out the next line seems to fix some problems
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1699 but not all. only andy currently understands this stuff and
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1700 he needs to review it more carefully. --ben */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1701 if (!check_for_ignored_expose (frame, x, y, width, height))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1702 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1703 hold_ignored_expose_registration = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1704 mswindows_redraw_exposed_area (frame, x, y, width, height);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1705 hold_ignored_expose_registration = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1706 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1707 EndPaint (hwnd, &paintStruct);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1708 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1709 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1710
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1711 /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1712 * Returns 1 if a key is a real modifier or special key, which
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1713 * is better handled by DefWindowProc
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1714 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1715 static int
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1716 key_needs_default_processing_p (UINT vkey)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1717 {
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1718 if (mswindows_alt_by_itself_activates_menu && vkey == VK_MENU
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1719 /* if we let ALT activate the menu like this, then sticky ALT-modified
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1720 keystrokes become impossible. */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1721 && !modifier_keys_are_sticky)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1722 return 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1723
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1724 return 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1725 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1726
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1727 /* key-handling code is always ugly. It just ends up working out
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1728 that way.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1729
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1730 #### Most of the sticky-modifier code below is copied from similar
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1731 code in event-Xt.c. They should somehow or other be merged.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1732
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1733 Here are some pointers:
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1734
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1735 -- DOWN_MASK indicates which modifiers should be treated as "down"
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1736 when the corresponding upstroke happens. It gets reset for
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1737 a particular modifier when that modifier goes up, and reset
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1738 for all modifiers when a non-modifier key is pressed. Example:
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1739
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1740 I press Control-A-Shift and then release Control-A-Shift.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1741 I want the Shift key to be sticky but not the Control key.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1742
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1743 -- If a modifier key is sticky, I can unstick it by pressing
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1744 the modifier key again. */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1745
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1746 static WPARAM last_downkey;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1747 static int need_to_add_mask, down_mask;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1748
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1749 #define XEMSW_LCONTROL (1<<0)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1750 #define XEMSW_RCONTROL (1<<1)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1751 #define XEMSW_LSHIFT (1<<2)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1752 #define XEMSW_RSHIFT (1<<3)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1753 #define XEMSW_LMENU (1<<4)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1754 #define XEMSW_RMENU (1<<5)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1755
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1756 static int
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1757 mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1758 int downp, int keyp)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1759 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1760 int mods = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1761
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1762 if (!modifier_keys_are_sticky) /* Optimize for non-sticky modifiers */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1763 return 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1764
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1765 if (! (keyp &&
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1766 (wParam == VK_CONTROL || wParam == VK_LCONTROL ||
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1767 wParam == VK_RCONTROL ||
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1768 wParam == VK_MENU || wParam == VK_LMENU ||
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1769 wParam == VK_RMENU ||
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1770 wParam == VK_SHIFT || wParam == VK_LSHIFT ||
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1771 wParam == VK_RSHIFT)))
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1772 { /* Not a modifier key */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1773 if (downp && keyp && !last_downkey)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1774 last_downkey = wParam;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1775 /* If I hold press-and-release the Control key and then press
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1776 and hold down the right arrow, I want it to auto-repeat
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1777 Control-Right. On the other hand, if I do the same but
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1778 manually press the Right arrow a bunch of times, I want
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1779 to see one Control-Right and then a bunch of Rights.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1780 This means that we need to distinguish between an
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1781 auto-repeated key and a key pressed and released a bunch
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1782 of times. */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1783 else if ((downp && !keyp) ||
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1784 (downp && keyp && last_downkey &&
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1785 (wParam != last_downkey ||
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1786 /* the "previous key state" bit indicates autorepeat */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1787 ! (lParam & (1 << 30)))))
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1788 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1789 need_to_add_mask = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1790 last_downkey = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1791 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1792 if (downp)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1793 down_mask = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1794
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1795 mods = need_to_add_mask;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1796 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1797 else /* Modifier key pressed */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1798 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1799 /* If a non-modifier key was pressed in the middle of a bunch
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1800 of modifiers, then it unsticks all the modifiers that were
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1801 previously pressed. We cannot unstick the modifiers until
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1802 now because we want to check for auto-repeat of the
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1803 non-modifier key. */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1804
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1805 if (last_downkey)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1806 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1807 last_downkey = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1808 need_to_add_mask = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1809 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1810
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1811 #define FROB(mask) \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1812 do { \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1813 if (downp && keyp) \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1814 { \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1815 /* If modifier key is already sticky, \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1816 then unstick it. Note that we do \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1817 not test down_mask to deal with the \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1818 unlikely but possible case that the \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1819 modifier key auto-repeats. */ \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1820 if (need_to_add_mask & mask) \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1821 { \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1822 need_to_add_mask &= ~mask; \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1823 down_mask &= ~mask; \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1824 } \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1825 else \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1826 down_mask |= mask; \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1827 } \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1828 else \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1829 { \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1830 if (down_mask & mask) \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1831 { \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1832 down_mask &= ~mask; \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1833 need_to_add_mask |= mask; \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1834 } \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1835 } \
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1836 } while (0)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1837
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1838 if ((wParam == VK_CONTROL && (lParam & 0x1000000))
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1839 || wParam == VK_RCONTROL)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1840 FROB (XEMSW_RCONTROL);
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1841 if ((wParam == VK_CONTROL && !(lParam & 0x1000000))
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1842 || wParam == VK_LCONTROL)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1843 FROB (XEMSW_LCONTROL);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1844
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1845 if ((wParam == VK_SHIFT && (lParam & 0x1000000))
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1846 || wParam == VK_RSHIFT)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1847 FROB (XEMSW_RSHIFT);
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1848 if ((wParam == VK_SHIFT && !(lParam & 0x1000000))
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1849 || wParam == VK_LSHIFT)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1850 FROB (XEMSW_LSHIFT);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1851
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1852 if ((wParam == VK_MENU && (lParam & 0x1000000))
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1853 || wParam == VK_RMENU)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1854 FROB (XEMSW_RMENU);
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1855 if ((wParam == VK_MENU && !(lParam & 0x1000000))
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1856 || wParam == VK_LMENU)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1857 FROB (XEMSW_LMENU);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1858 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1859 #undef FROB
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1860
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1861 if (mods && downp)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1862 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1863 BYTE keymap[256];
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1864
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1865 GetKeyboardState (keymap);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1866
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1867 if (mods & XEMSW_LCONTROL)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1868 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1869 keymap [VK_CONTROL] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1870 keymap [VK_LCONTROL] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1871 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1872 if (mods & XEMSW_RCONTROL)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1873 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1874 keymap [VK_CONTROL] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1875 keymap [VK_RCONTROL] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1876 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1877
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1878 if (mods & XEMSW_LSHIFT)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1879 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1880 keymap [VK_SHIFT] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1881 keymap [VK_LSHIFT] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1882 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1883 if (mods & XEMSW_RSHIFT)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1884 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1885 keymap [VK_SHIFT] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1886 keymap [VK_RSHIFT] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1887 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1888
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1889 if (mods & XEMSW_LMENU)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1890 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1891 keymap [VK_MENU] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1892 keymap [VK_LMENU] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1893 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1894 if (mods & XEMSW_RMENU)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1895 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1896 keymap [VK_MENU] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1897 keymap [VK_RMENU] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1898 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1899
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1900 SetKeyboardState (keymap);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1901 return 1;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1902 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1903
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1904 return 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1905 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1906
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1907 static void
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1908 clear_sticky_modifiers (void)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1909 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1910 need_to_add_mask = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1911 last_downkey = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1912 down_mask = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1913 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1914
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1915 #ifdef DEBUG_XEMACS
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1916
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1917 #if 0
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1918
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1919 static void
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1920 output_modifier_keyboard_state (void)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1921 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1922 BYTE keymap[256];
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1923
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1924 GetKeyboardState (keymap);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1925
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1926 stderr_out ("GetKeyboardState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1927 keymap[VK_MENU] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1928 keymap[VK_MENU] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1929 keymap[VK_LMENU] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1930 keymap[VK_LMENU] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1931 keymap[VK_RMENU] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1932 keymap[VK_RMENU] & 0x1 ? 1 : 0);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1933 stderr_out ("GetKeyboardState VK_CONTROL %d %d VK_LCONTROL %d %d VK_RCONTROL %d %d\n",
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1934 keymap[VK_CONTROL] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1935 keymap[VK_CONTROL] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1936 keymap[VK_LCONTROL] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1937 keymap[VK_LCONTROL] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1938 keymap[VK_RCONTROL] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1939 keymap[VK_RCONTROL] & 0x1 ? 1 : 0);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1940 stderr_out ("GetKeyboardState VK_SHIFT %d %d VK_LSHIFT %d %d VK_RSHIFT %d %d\n",
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1941 keymap[VK_SHIFT] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1942 keymap[VK_SHIFT] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1943 keymap[VK_LSHIFT] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1944 keymap[VK_LSHIFT] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1945 keymap[VK_RSHIFT] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1946 keymap[VK_RSHIFT] & 0x1 ? 1 : 0);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1947 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1948
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1949 #endif
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
1950
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1951 /* try to debug the stuck-alt-key problem.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1952
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1953 #### this happens only inconsistently, and may only happen when using
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1954 StickyKeys in the Win2000 accessibility section of the control panel,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1955 which is extremely broken for other reasons. */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1956
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1957 static void
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1958 output_alt_keyboard_state (void)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1959 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1960 BYTE keymap[256];
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1961 SHORT keystate[3];
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1962 // SHORT asyncstate[3];
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1963
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1964 GetKeyboardState (keymap);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1965 keystate[0] = GetKeyState (VK_MENU);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1966 keystate[1] = GetKeyState (VK_LMENU);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1967 keystate[2] = GetKeyState (VK_RMENU);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1968 /* Doing this interferes with key processing. */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1969 /* asyncstate[0] = GetAsyncKeyState (VK_MENU); */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1970 /* asyncstate[1] = GetAsyncKeyState (VK_LMENU); */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1971 /* asyncstate[2] = GetAsyncKeyState (VK_RMENU); */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1972
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1973 stderr_out ("GetKeyboardState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1974 keymap[VK_MENU] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1975 keymap[VK_MENU] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1976 keymap[VK_LMENU] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1977 keymap[VK_LMENU] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1978 keymap[VK_RMENU] & 0x80 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1979 keymap[VK_RMENU] & 0x1 ? 1 : 0);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1980 stderr_out ("GetKeyState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1981 keystate[0] & 0x8000 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1982 keystate[0] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1983 keystate[1] & 0x8000 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1984 keystate[1] & 0x1 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1985 keystate[2] & 0x8000 ? 1 : 0,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1986 keystate[2] & 0x1 ? 1 : 0);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1987 /* stderr_out ("GetAsyncKeyState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n", */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1988 /* asyncstate[0] & 0x8000 ? 1 : 0, */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1989 /* asyncstate[0] & 0x1 ? 1 : 0, */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1990 /* asyncstate[1] & 0x8000 ? 1 : 0, */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1991 /* asyncstate[1] & 0x1 ? 1 : 0, */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1992 /* asyncstate[2] & 0x8000 ? 1 : 0, */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1993 /* asyncstate[2] & 0x1 ? 1 : 0); */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1994 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1995
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1996 #endif /* DEBUG_XEMACS */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1997
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
1998
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
1999 /*
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2000 * The windows procedure for the window class XEMACS_CLASS
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2001 */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2002 LRESULT WINAPI
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2003 mswindows_wnd_proc (HWND hwnd, UINT message_, WPARAM wParam, LPARAM lParam)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2004 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2005 /* Note: Remember to initialize emacs_event and event before use.
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2006 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
2007 Lisp_Object emacs_event = Qnil;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2008 Lisp_Object fobj = Qnil;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2009
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
2010 Lisp_Event *event;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2011 struct frame *frame;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2012 struct mswindows_frame* msframe;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2013
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2014 assert (!GetWindowLong (hwnd, GWL_USERDATA));
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2015 switch (message_)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2016 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2017 case WM_DESTROYCLIPBOARD:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2018 /* We own the clipboard and someone else wants it. Delete our
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2019 cached copy of the clipboard contents so we'll ask for it from
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2020 Windows again when someone does a paste, and destroy any memory
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2021 objects we hold on the clipboard that are not in the list of types
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2022 that Windows will delete itself. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2023 mswindows_destroy_selection (QCLIPBOARD);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2024 handle_selection_clear (QCLIPBOARD);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2025 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2026
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2027 case WM_ERASEBKGND:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2028 /* Erase background only during non-dynamic sizing */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2029 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2030 if (msframe->sizing && !mswindows_dynamic_frame_resize)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2031 goto defproc;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2032 return 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2033
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2034 case WM_CLOSE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2035 fobj = mswindows_find_frame (hwnd);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2036 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
2037 break;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2038
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2039 case WM_KEYUP:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2040 case WM_SYSKEYUP:
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2041
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2042 /* See Win95 comment under WM_KEYDOWN */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2043 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2044 BYTE keymap[256];
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2045 int should_set_keymap = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2046
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2047 #ifdef DEBUG_XEMACS
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2048 if (mswindows_debug_events)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2049 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2050 stderr_out ("%s wparam=%d lparam=%d\n",
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2051 message_ == WM_KEYUP ? "WM_KEYUP" : "WM_SYSKEYUP",
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2052 wParam, (int)lParam);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2053 output_alt_keyboard_state ();
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2054 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2055 #endif /* DEBUG_XEMACS */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2056
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2057 mswindows_handle_sticky_modifiers (wParam, lParam, 0, 1);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2058 if (wParam == VK_CONTROL)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2059 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2060 GetKeyboardState (keymap);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2061 keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] &= ~0x80;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2062 should_set_keymap = 1;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2063 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2064 else if (wParam == VK_MENU)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2065 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2066 GetKeyboardState (keymap);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2067 keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] &= ~0x80;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2068 should_set_keymap = 1;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2069 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2070
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2071 if (should_set_keymap)
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2072 // && (message_ != WM_SYSKEYUP
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2073 // || NILP (Vmenu_accelerator_enabled)))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2074 SetKeyboardState (keymap);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2075
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2076 }
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2077
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2078 if (key_needs_default_processing_p (wParam))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2079 goto defproc;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2080 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2081 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2082
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2083 case WM_KEYDOWN:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2084 case WM_SYSKEYDOWN:
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2085
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2086 /* In some locales the right-hand Alt key is labelled AltGr. This key
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2087 * should produce alternative charcaters when combined with another key.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2088 * eg on a German keyboard pressing AltGr+q should produce '@'.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2089 * AltGr generates exactly the same keystrokes as LCtrl+RAlt. But if
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2090 * TranslateMessage() is called with *any* combination of Ctrl+Alt down,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2091 * it translates as if AltGr were down.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2092 * We get round this by removing all modifiers from the keymap before
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2093 * calling TranslateMessage() unless AltGr is *really* down. */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2094 {
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2095 BYTE keymap_trans[256];
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2096 BYTE keymap_orig[256];
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2097 BYTE keymap_sticky[256];
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2098 int has_AltGr = mswindows_current_layout_has_AltGr ();
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2099 int mods = 0;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2100 int extendedp = lParam & 0x1000000;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2101 Lisp_Object keysym;
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2102 int sticky_changed;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2103
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2104 #ifdef DEBUG_XEMACS
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2105 if (mswindows_debug_events)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2106 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2107 stderr_out ("%s wparam=%d lparam=%d\n",
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2108 message_ == WM_KEYDOWN ? "WM_KEYDOWN" : "WM_SYSKEYDOWN",
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2109 wParam, (int)lParam);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2110 output_alt_keyboard_state ();
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2111 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2112 #endif /* DEBUG_XEMACS */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2113
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2114 GetKeyboardState (keymap_orig);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2115 frame = XFRAME (mswindows_find_frame (hwnd));
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2116 if ((sticky_changed =
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2117 mswindows_handle_sticky_modifiers (wParam, lParam, 1, 1)))
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2118 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2119 GetKeyboardState (keymap_sticky);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2120 if (keymap_sticky[VK_MENU] & 0x80)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2121 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2122 message_ = WM_SYSKEYDOWN;
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2123 /* We have to set the "context bit" so that the
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2124 TranslateMessage() call below that generates the
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2125 SYSCHAR message does its thing; see the documentation
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2126 on WM_SYSKEYDOWN */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2127 lParam |= 1 << 29;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2128 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2129 }
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2130 else
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2131 memcpy (keymap_sticky, keymap_orig, 256);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2132
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2133 mods = mswindows_modifier_state (keymap_sticky, has_AltGr);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2134
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2135 /* Handle non-printables */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2136 if (!NILP (keysym = mswindows_key_to_emacs_keysym (wParam, mods,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2137 extendedp)))
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2138 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2139 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2140 if (sticky_changed)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2141 SetKeyboardState (keymap_orig);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2142 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2143 else /* Normal keys & modifiers */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2144 {
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2145 Emchar quit_ch =
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2146 CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2147 POINT pnt = { LOWORD (GetMessagePos()), HIWORD (GetMessagePos()) };
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2148 MSG msg, tranmsg;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2149 int potential_accelerator = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2150 int got_accelerator = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2151
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2152 msg.hwnd = hwnd;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2153 msg.message = message_;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2154 msg.wParam = wParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2155 msg.lParam = lParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2156 msg.time = GetMessageTime();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2157 msg.pt = pnt;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2158
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2159 /* GetKeyboardState() does not work as documented on Win95. We have
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2160 * to loosely track Left and Right modifiers on behalf of the OS,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2161 * without screwing up Windows NT which tracks them properly. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2162 if (wParam == VK_CONTROL)
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2163 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2164 keymap_orig[extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2165 keymap_sticky[extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2166 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2167 else if (wParam == VK_MENU)
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2168 {
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2169 keymap_orig[extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2170 keymap_sticky[extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2171 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2172
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2173 if (!NILP (Vmenu_accelerator_enabled) &&
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2174 !(mods & XEMACS_MOD_SHIFT) && message_ == WM_SYSKEYDOWN)
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2175 potential_accelerator = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2176
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2177 /* Remove shift modifier from an ascii character */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2178 mods &= ~XEMACS_MOD_SHIFT;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2179
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2180 memcpy (keymap_trans, keymap_sticky, 256);
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2181
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2182 /* Clear control and alt modifiers unless AltGr is pressed */
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2183 keymap_trans[VK_RCONTROL] = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2184 keymap_trans[VK_LMENU] = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2185 if (!has_AltGr || !(keymap_trans[VK_LCONTROL] & 0x80)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2186 || !(keymap_trans[VK_RMENU] & 0x80))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2187 {
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2188 keymap_trans[VK_LCONTROL] = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2189 keymap_trans[VK_CONTROL] = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2190 keymap_trans[VK_RMENU] = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2191 keymap_trans[VK_MENU] = 0;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2192 }
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2193 SetKeyboardState (keymap_trans);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2194
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2195 /* Maybe generate some WM_[SYS]CHARs in the queue */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2196 TranslateMessage (&msg);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2197
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2198 while (PeekMessage (&tranmsg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2199 || PeekMessage (&tranmsg, hwnd, WM_SYSCHAR, WM_SYSCHAR,
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2200 PM_REMOVE))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2201 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2202 int mods1 = mods;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2203 WPARAM ch = tranmsg.wParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2204
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2205 /* If a quit char with no modifiers other than control and
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2206 shift, then mark it with a fake modifier, which is removed
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2207 upon dequeueing the event */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2208 /* #### This might also not withstand localization, if
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2209 quit character is not a latin-1 symbol */
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2210 if (((quit_ch < ' ' && (mods & XEMACS_MOD_CONTROL)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2211 && quit_ch + 'a' - 1 == ch)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2212 || (quit_ch >= ' ' && !(mods & XEMACS_MOD_CONTROL)
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2213 && quit_ch == ch))
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2214 && ((mods & ~(XEMACS_MOD_CONTROL | XEMACS_MOD_SHIFT))
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2215 == 0))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2216 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2217 mods1 |= FAKE_MOD_QUIT;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2218 ++mswindows_quit_chars_count;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2219 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2220 else if (potential_accelerator && !got_accelerator &&
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2221 mswindows_char_is_accelerator (frame, ch))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2222 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2223 got_accelerator = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2224 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2225 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2226 mswindows_enqueue_keypress_event (hwnd, make_char (ch), mods1);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2227 } /* while */
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2228
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2229 /* This generates WM_SYSCHAR messages, which are interpreted
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2230 by DefWindowProc as the menu selections. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2231 if (got_accelerator)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2232 {
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2233 SetKeyboardState (keymap_sticky);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2234 TranslateMessage (&msg);
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2235 SetKeyboardState (keymap_orig);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2236 goto defproc;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2237 }
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2238
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2239 SetKeyboardState (keymap_orig);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2240 } /* else */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2241 }
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2242
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2243 if (key_needs_default_processing_p (wParam))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2244 goto defproc;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2245 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2246 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2247
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2248 case WM_MBUTTONDOWN:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2249 case WM_MBUTTONUP:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2250 /* Real middle mouse button has nothing to do with emulated one:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2251 if one wants to exercise fingers playing chords on the mouse,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2252 he is allowed to do that! */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2253 mswindows_enqueue_mouse_button_event (hwnd, message_,
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2254 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2255 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2256
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2257 case WM_LBUTTONUP:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2258 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2259 msframe->last_click_time = GetMessageTime();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2260
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2261 KillTimer (hwnd, BUTTON_2_TIMER_ID);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2262 msframe->button2_need_lbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2263 if (msframe->ignore_next_lbutton_up)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2264 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2265 msframe->ignore_next_lbutton_up = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2266 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2267 else if (msframe->button2_is_down)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2268 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2269 msframe->button2_is_down = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2270 msframe->ignore_next_rbutton_up = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2271 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2272 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2273 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2274 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2275 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2276 if (msframe->button2_need_rbutton)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2277 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2278 msframe->button2_need_rbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2279 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2280 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2281 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2282 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2283 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2284 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2285 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2286
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2287 case WM_RBUTTONUP:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2288 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2289 msframe->last_click_time = GetMessageTime();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2290
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2291 KillTimer (hwnd, BUTTON_2_TIMER_ID);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2292 msframe->button2_need_rbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2293 if (msframe->ignore_next_rbutton_up)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2294 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2295 msframe->ignore_next_rbutton_up = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2296 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2297 else if (msframe->button2_is_down)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2298 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2299 msframe->button2_is_down = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2300 msframe->ignore_next_lbutton_up = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2301 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2302 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2303 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2304 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2305 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2306 if (msframe->button2_need_lbutton)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2307 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2308 msframe->button2_need_lbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2309 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2310 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2311 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2312 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2313 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2314 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2315 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2316
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2317 case WM_LBUTTONDOWN:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2318 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2319
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2320 if (msframe->button2_need_lbutton)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2321 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2322 KillTimer (hwnd, BUTTON_2_TIMER_ID);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2323 msframe->button2_need_lbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2324 msframe->button2_need_rbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2325 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2326 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2327 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2328 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2329 msframe->button2_is_down = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2330 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2331 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2332 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2333 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2334 msframe->last_click_point, msframe->last_click_time);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2335 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2336 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2337 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2338 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2339 else
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
2340 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2341 mswindows_set_chord_timer (hwnd);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2342 msframe->button2_need_rbutton = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2343 msframe->last_click_point = MAKEPOINTS (lParam);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
2344 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2345 msframe->last_click_time = GetMessageTime();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2346 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2347
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2348 case WM_RBUTTONDOWN:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2349 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2350
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2351 if (msframe->button2_need_rbutton)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
2352 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2353 KillTimer (hwnd, BUTTON_2_TIMER_ID);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2354 msframe->button2_need_lbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2355 msframe->button2_need_rbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2356 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2357 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2358 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2359 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2360 msframe->button2_is_down = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2361 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2362 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2363 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2364 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2365 msframe->last_click_point, msframe->last_click_time);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2366 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2367 MAKEPOINTS (lParam), GetMessageTime());
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2368 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2369 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2370 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2371 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2372 mswindows_set_chord_timer (hwnd);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2373 msframe->button2_need_lbutton = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2374 msframe->last_click_point = MAKEPOINTS (lParam);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2375 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2376 msframe->last_click_time = GetMessageTime();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2377 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2378
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2379 case WM_TIMER:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2380 if (wParam == BUTTON_2_TIMER_ID)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2381 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2382 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2383 KillTimer (hwnd, BUTTON_2_TIMER_ID);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2384
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2385 if (msframe->button2_need_lbutton)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2386 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2387 msframe->button2_need_lbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2388 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2389 msframe->last_click_point, msframe->last_click_time);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2390 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2391 else if (msframe->button2_need_rbutton)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2392 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2393 msframe->button2_need_rbutton = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2394 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2395 msframe->last_click_point, msframe->last_click_time);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2396 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2397 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2398 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2399 assert ("Spurious timer fired" == 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2400 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2401
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2402 case WM_MOUSEMOVE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2403 /* Optimization: don't report mouse movement while size is changing */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2404 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2405 if (!msframe->sizing)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2406 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2407 /* When waiting for the second mouse button to finish
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2408 button2 emulation, and have moved too far, just pretend
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2409 as if timer has expired. This improves drag-select feedback */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2410 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2411 && !mswindows_button2_near_enough (msframe->last_click_point,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2412 MAKEPOINTS (lParam)))
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2413 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2414 KillTimer (hwnd, BUTTON_2_TIMER_ID);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2415 SendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2416 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2417
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2418 emacs_event = Fmake_event (Qnil, Qnil);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2419 event = XEVENT(emacs_event);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2420
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2421 event->channel = mswindows_find_frame(hwnd);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2422 event->timestamp = GetMessageTime();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2423 event->event_type = pointer_motion_event;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2424 event->event.motion.x = MAKEPOINTS(lParam).x;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2425 event->event.motion.y = MAKEPOINTS(lParam).y;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2426 event->event.motion.modifiers = mswindows_modifier_state (NULL, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2427
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2428 mswindows_enqueue_dispatch_event (emacs_event);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2429 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2430 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2431
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2432 case WM_CANCELMODE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2433 ReleaseCapture ();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2434 /* Queue a `cancel-mode-internal' misc user event, so mouse
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2435 selection would be canceled if any */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2436 mswindows_enqueue_misc_user_event (mswindows_find_frame (hwnd),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2437 Qcancel_mode_internal, Qnil);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2438 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2439
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2440 case WM_NOTIFY:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2441 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2442 LPNMHDR nmhdr = (LPNMHDR)lParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2443
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2444 if (nmhdr->code == TTN_NEEDTEXT)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2445 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2446 #ifdef HAVE_TOOLBARS
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2447 LPTOOLTIPTEXT tttext = (LPTOOLTIPTEXT)lParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2448 Lisp_Object btext;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2449
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2450 /* find out which toolbar */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2451 frame = XFRAME (mswindows_find_frame (hwnd));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2452 btext = mswindows_get_toolbar_button_text ( frame,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2453 nmhdr->idFrom );
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2454
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2455 tttext->lpszText = NULL;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2456 tttext->hinst = NULL;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2457
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2458 if (!NILP(btext))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2459 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2460 /* I think this is safe since the text will only go away
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2461 when the toolbar does...*/
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2462 TO_EXTERNAL_FORMAT (LISP_STRING, btext,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2463 C_STRING_ALLOCA, tttext->lpszText,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2464 Qnative);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2465 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2466 #endif
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2467 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2468 /* handle tree view callbacks */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2469 else if (nmhdr->code == TVN_SELCHANGED)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2470 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2471 NM_TREEVIEW* ptree = (NM_TREEVIEW*)lParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2472 frame = XFRAME (mswindows_find_frame (hwnd));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2473 mswindows_handle_gui_wm_command (frame, 0, ptree->itemNew.lParam);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2474 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2475 /* handle tab control callbacks */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2476 else if (nmhdr->code == TCN_SELCHANGE)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2477 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2478 TC_ITEM item;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2479 int idx = SendMessage (nmhdr->hwndFrom, TCM_GETCURSEL, 0, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2480 frame = XFRAME (mswindows_find_frame (hwnd));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2481
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2482 item.mask = TCIF_PARAM;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2483 SendMessage (nmhdr->hwndFrom, TCM_GETITEM, (WPARAM)idx,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2484 (LPARAM)&item);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2485
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2486 mswindows_handle_gui_wm_command (frame, 0, item.lParam);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2487 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2488 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2489 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2490
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2491 case WM_PAINT:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2492 /* hdc will be NULL unless this is a subwindow - in which case we
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2493 shouldn't have received a paint message for it here. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2494 assert (wParam == 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2495
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2496 /* Can't queue a magic event because windows goes modal and sends paint
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2497 messages directly to the windows procedure when doing solid drags
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2498 and the message queue doesn't get processed. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2499 mswindows_handle_paint (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2500 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2501
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2502 case WM_SIZE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2503 /* We only care about this message if our size has really changed */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2504 if (wParam==SIZE_RESTORED || wParam==SIZE_MAXIMIZED || wParam==SIZE_MINIMIZED)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2505 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2506 RECT rect;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2507 int columns, rows;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2508
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2509 fobj = mswindows_find_frame (hwnd);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2510 frame = XFRAME (fobj);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2511 msframe = FRAME_MSWINDOWS_DATA (frame);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2512
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2513 /* We cannot handle frame map and unmap hooks right in
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2514 this routine, because these may throw. We queue
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2515 magic events to run these hooks instead - kkm */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2516
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2517 if (wParam==SIZE_MINIMIZED)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2518 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2519 /* Iconified */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2520 FRAME_VISIBLE_P (frame) = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2521 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2522 }
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2523 else
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2524 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2525 GetClientRect(hwnd, &rect);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2526 FRAME_PIXWIDTH(frame) = rect.right;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2527 FRAME_PIXHEIGHT(frame) = rect.bottom;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2528
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2529 pixel_to_real_char_size (frame, rect.right, rect.bottom,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2530 &FRAME_MSWINDOWS_CHARWIDTH (frame),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2531 &FRAME_MSWINDOWS_CHARHEIGHT (frame));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2532
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2533 pixel_to_char_size (frame, rect.right, rect.bottom, &columns, &rows);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2534 change_frame_size (frame, rows, columns, 1);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2535
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2536 /* If we are inside frame creation, we have to apply geometric
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2537 properties now. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2538 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2539 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2540 /* Yes, we have to size again */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2541 mswindows_size_frame_internal ( frame,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2542 FRAME_MSWINDOWS_TARGET_RECT
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2543 (frame));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2544 /* Reset so we do not get here again. The SetWindowPos call in
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2545 * mswindows_size_frame_internal can cause recursion here. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2546 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2547 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2548 xfree (FRAME_MSWINDOWS_TARGET_RECT (frame));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2549 FRAME_MSWINDOWS_TARGET_RECT (frame) = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2550 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2551 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2552 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2553 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2554 if (!msframe->sizing && !FRAME_VISIBLE_P (frame))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2555 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2556 FRAME_VISIBLE_P (frame) = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2557
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2558 if (!msframe->sizing || mswindows_dynamic_frame_resize)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2559 redisplay ();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2560 }
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2561 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2562 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2563 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2564
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2565 case WM_DISPLAYCHANGE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2566 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2567 struct device *d;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2568 DWORD message_tick = GetMessageTime ();
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2569
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2570 fobj = mswindows_find_frame (hwnd);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2571 frame = XFRAME (fobj);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2572 d = XDEVICE (FRAME_DEVICE (frame));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2573
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2574 /* Do this only once per message. XEmacs can receive this message
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2575 through as many frames as it currently has open. Message time
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2576 will be the same for all these messages. Despite extreme
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2577 efficiency, the code below has about one in 4 billion
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2578 probability that the HDC is not recreated, provided that
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2579 XEmacs is running sufficiently longer than 52 days. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2580 if (DEVICE_MSWINDOWS_UPDATE_TICK(d) != message_tick)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2581 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2582 DEVICE_MSWINDOWS_UPDATE_TICK(d) = message_tick;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2583 DeleteDC (DEVICE_MSWINDOWS_HCDC(d));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2584 DEVICE_MSWINDOWS_HCDC(d) = CreateCompatibleDC (NULL);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2585 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2586 }
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2587 break;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2588
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2589 /* Misc magic events which only require that the frame be identified */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2590 case WM_SETFOCUS:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2591 case WM_KILLFOCUS:
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2592 mswindows_enqueue_magic_event (hwnd, message_);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2593 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2594
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2595 case WM_WINDOWPOSCHANGING:
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2596 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2597 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2598 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2599 GetWindowPlacement(hwnd, &wpl);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2600
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2601 /* Only interested if size is changing and we're not being iconified */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2602 if (wpl.showCmd != SW_SHOWMINIMIZED
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2603 && wpl.showCmd != SW_SHOWMAXIMIZED
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2604 && !(wp->flags & SWP_NOSIZE))
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2605 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2606 RECT ncsize = { 0, 0, 0, 0 };
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2607 int pixwidth, pixheight;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2608 AdjustWindowRectEx (&ncsize, GetWindowLong (hwnd, GWL_STYLE),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2609 GetMenu(hwnd) != NULL,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2610 GetWindowLong (hwnd, GWL_EXSTYLE));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2611
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2612 round_size_to_real_char (XFRAME (mswindows_find_frame (hwnd)),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2613 wp->cx - (ncsize.right - ncsize.left),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2614 wp->cy - (ncsize.bottom - ncsize.top),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2615 &pixwidth, &pixheight);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2616
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2617 /* Convert client sizes to window sizes */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2618 pixwidth += (ncsize.right - ncsize.left);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2619 pixheight += (ncsize.bottom - ncsize.top);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2620
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2621 if (wpl.showCmd != SW_SHOWMAXIMIZED)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2622 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2623 /* Adjust so that the bottom or right doesn't move if it's
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2624 * the top or left that's being changed */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2625 RECT rect;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2626 GetWindowRect (hwnd, &rect);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2627
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2628 if (rect.left != wp->x)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2629 wp->x += wp->cx - pixwidth;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2630 if (rect.top != wp->y)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2631 wp->y += wp->cy - pixheight;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2632 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2633
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2634 wp->cx = pixwidth;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2635 wp->cy = pixheight;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2636 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2637 /* DefWindowProc sends useful WM_GETMINMAXINFO message, and adjusts
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2638 window position if the user tries to track window too small */
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2639 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2640 goto defproc;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2641
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2642 case WM_ENTERSIZEMOVE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2643 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2644 msframe->sizing = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2645 return 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2646
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2647 case WM_EXITSIZEMOVE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2648 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2649 msframe->sizing = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2650 /* Queue noop event */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2651 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2652 return 0;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2653
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2654 #ifdef HAVE_SCROLLBARS
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2655 case WM_VSCROLL:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2656 case WM_HSCROLL:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2657 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2658 /* Direction of scroll is determined by scrollbar instance. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2659 int code = (int) LOWORD(wParam);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2660 int pos = (short int) HIWORD(wParam);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2661 HWND hwndScrollBar = (HWND) lParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2662 struct gcpro gcpro1, gcpro2;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2663
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2664 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2665 GCPRO2 (emacs_event, fobj);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2666 if (UNBOUNDP(mswindows_pump_outstanding_events())) /* Can GC */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2667 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2668 /* Error during event pumping - cancel scroll */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2669 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2670 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2671 UNGCPRO;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2672 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2673 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2674
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2675 case WM_MOUSEWHEEL:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2676 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2677 int keys = LOWORD (wParam); /* Modifier key flags */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2678 int delta = (short) HIWORD (wParam); /* Wheel rotation amount */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2679 struct gcpro gcpro1, gcpro2;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2680
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2681 if (mswindows_handle_mousewheel_event (mswindows_find_frame (hwnd), keys, delta))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2682 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2683 GCPRO2 (emacs_event, fobj);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2684 mswindows_pump_outstanding_events (); /* Can GC */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2685 UNGCPRO;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2686 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2687 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2688 goto defproc;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2689 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2690 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2691 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2692
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2693 #ifdef HAVE_MENUBARS
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2694 case WM_INITMENU:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2695 if (UNBOUNDP (mswindows_handle_wm_initmenu (
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2696 (HMENU) wParam,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2697 XFRAME (mswindows_find_frame (hwnd)))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2698 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2699 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2700
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2701 case WM_INITMENUPOPUP:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2702 if (!HIWORD(lParam))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2703 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2704 if (UNBOUNDP (mswindows_handle_wm_initmenupopup (
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2705 (HMENU) wParam,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2706 XFRAME (mswindows_find_frame (hwnd)))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2707 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2708 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2709 break;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2710
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2711 #endif /* HAVE_MENUBARS */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2712
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2713 case WM_COMMAND:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2714 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2715 WORD id = LOWORD (wParam);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2716 WORD nid = HIWORD (wParam);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2717 HWND cid = (HWND)lParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2718 frame = XFRAME (mswindows_find_frame (hwnd));
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2719
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2720 #ifdef HAVE_TOOLBARS
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2721 if (!NILP (mswindows_handle_toolbar_wm_command (frame, cid, id)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2722 break;
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
2723 #endif
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2724 /* widgets in a buffer only eval a callback for suitable events.*/
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2725 switch (nid)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2726 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2727 case BN_CLICKED:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2728 case EN_CHANGE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2729 case CBN_EDITCHANGE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2730 case CBN_SELCHANGE:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2731 if (!NILP (mswindows_handle_gui_wm_command (frame, cid, id)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2732 return 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2733 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2734 /* menubars always must come last since the hashtables do not
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2735 always exist*/
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2736 #ifdef HAVE_MENUBARS
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2737 if (!NILP (mswindows_handle_wm_command (frame, id)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2738 break;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2739 #endif
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2740
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2741 return DefWindowProc (hwnd, message_, wParam, lParam);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2742 /* Bite me - a spurious command. This used to not be able to
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2743 happen but with the introduction of widgets its now
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2744 possible. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2745 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2746 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2747
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2748 case WM_CTLCOLORBTN:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2749 case WM_CTLCOLORLISTBOX:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2750 case WM_CTLCOLOREDIT:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2751 case WM_CTLCOLORSTATIC:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2752 case WM_CTLCOLORSCROLLBAR:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2753 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2754 /* if we get an opportunity to paint a widget then do so if
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2755 there is an appropriate face */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2756 HWND crtlwnd = (HWND)lParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2757 LONG ii = GetWindowLong (crtlwnd, GWL_USERDATA);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2758 if (ii)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2759 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2760 Lisp_Object image_instance;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2761 VOID_TO_LISP (image_instance, ii);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2762 if (IMAGE_INSTANCEP (image_instance)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2763 &&
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2764 IMAGE_INSTANCE_TYPE_P (image_instance, IMAGE_WIDGET))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2765 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2766 /* set colors for the buttons */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2767 HDC hdc = (HDC)wParam;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2768 if (last_widget_brushed != ii)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2769 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2770 if (widget_brush)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2771 DeleteObject (widget_brush);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2772 widget_brush = CreateSolidBrush
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2773 (COLOR_INSTANCE_MSWINDOWS_COLOR
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2774 (XCOLOR_INSTANCE
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2775 (FACE_BACKGROUND
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2776 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2777 XIMAGE_INSTANCE_FRAME (image_instance)))));
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2778 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2779 last_widget_brushed = ii;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2780 SetTextColor
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2781 (hdc,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2782 COLOR_INSTANCE_MSWINDOWS_COLOR
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2783 (XCOLOR_INSTANCE
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2784 (FACE_FOREGROUND
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2785 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2786 XIMAGE_INSTANCE_FRAME (image_instance)))));
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2787 SetBkMode (hdc, OPAQUE);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2788 SetBkColor
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2789 (hdc,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2790 COLOR_INSTANCE_MSWINDOWS_COLOR
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2791 (XCOLOR_INSTANCE
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2792 (FACE_BACKGROUND
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2793 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2794 XIMAGE_INSTANCE_FRAME (image_instance)))));
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2795 return (LRESULT)widget_brush;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2796 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2797 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2798 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2799 goto defproc;
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
2800
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
2801 #ifdef HAVE_DRAGNDROP
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2802 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2803 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2804 UINT filecount, i, len;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2805 POINT point;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2806 char* filename;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2807 char* fname;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2808
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2809 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2810 struct gcpro gcpro1, gcpro2, gcpro3;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2811
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2812 emacs_event = Fmake_event (Qnil, Qnil);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2813 event = XEVENT(emacs_event);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2814
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2815 GCPRO3 (emacs_event, l_dndlist, l_item);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2816
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2817 if (!DragQueryPoint ((HDROP) wParam, &point))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2818 point.x = point.y = -1; /* outside client area */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2819
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2820 event->event_type = misc_user_event;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2821 event->channel = mswindows_find_frame(hwnd);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2822 event->timestamp = GetMessageTime();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2823 event->event.misc.button = 1; /* #### Should try harder */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2824 event->event.misc.modifiers = mswindows_modifier_state (NULL, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2825 event->event.misc.x = point.x;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2826 event->event.misc.y = point.y;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2827 event->event.misc.function = Qdragdrop_drop_dispatch;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2828
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2829 filecount = DragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2830 for (i=0; i<filecount; i++)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2831 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2832 len = DragQueryFile ((HDROP) wParam, i, NULL, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2833 /* The URLs that we make here aren't correct according to section
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2834 * 3.10 of rfc1738 because they're missing the //<host>/ part and
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2835 * because they may contain reserved characters. But that's OK -
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2836 * they just need to be good enough to keep dragdrop.el happy. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2837 fname = (char *)xmalloc (len+1);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2838 DragQueryFile ((HANDLE) wParam, i, fname, len+1);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2839
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2840 /* May be a shell link aka "shortcut" - replace fname if so */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2841 #if !(defined(CYGWIN) || defined(MINGW))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2842 /* cygwin doesn't define this COM stuff */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2843 if (!stricmp (fname + strlen (fname) - 4, ".LNK"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2844 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2845 IShellLink* psl;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2846
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2847 if (CoCreateInstance (&CLSID_ShellLink, NULL,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2848 CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl) == S_OK)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2849 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2850 IPersistFile* ppf;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2851
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2852 if (psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2853 &ppf) == S_OK)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2854 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2855 WORD wsz[MAX_PATH];
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2856 WIN32_FIND_DATA wfd;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2857 LPSTR resolved = (char *) xmalloc (MAX_PATH+1);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2858
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2859 MultiByteToWideChar (CP_ACP,0, fname, -1, wsz, MAX_PATH);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2860
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2861 if ((ppf->lpVtbl->Load (ppf, wsz, STGM_READ) == S_OK) &&
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2862 (psl->lpVtbl->GetPath (psl, resolved, MAX_PATH,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2863 &wfd, 0)==S_OK))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2864 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2865 xfree (fname);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2866 fname = resolved;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2867 len = strlen (fname);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2868 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2869
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2870 ppf->lpVtbl->Release (ppf);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2871 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2872
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2873 psl->lpVtbl->Release (psl);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2874 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2875 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2876 #endif
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2877
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2878 #ifdef CYGWIN
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2879 filename = xmalloc (cygwin32_win32_to_posix_path_list_buf_size (fname) + 5);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2880 strcpy (filename, "file:");
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2881 cygwin32_win32_to_posix_path_list (fname, filename+5);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2882 #else
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2883 filename = (char *)xmalloc (len+6);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2884 strcat (strcpy (filename, "file:"), fname);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2885 dostounix_filename (filename+5);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
2886 #endif
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2887 xfree (fname);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2888 l_item = make_string (filename, strlen (filename));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2889 l_dndlist = Fcons (l_item, l_dndlist);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2890 xfree (filename);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2891 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2892 DragFinish ((HDROP) wParam);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2893
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2894 event->event.misc.object = Fcons (Qdragdrop_URL, l_dndlist);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2895 mswindows_enqueue_dispatch_event (emacs_event);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2896 UNGCPRO;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2897 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2898 break;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2899 #endif
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2900
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2901 defproc:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2902 default:
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 408
diff changeset
2903 return DefWindowProc (hwnd, message_, wParam, lParam);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2904 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2905 return (0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2906 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2907
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2908
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2909 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2910 /* keyboard, mouse & other helpers for the windows procedure */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2911 /************************************************************************/
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2912 static void
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2913 mswindows_set_chord_timer (HWND hwnd)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2914 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2915 int interval;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2916
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2917 /* We get one third half system double click threshold */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2918 if (mswindows_mouse_button_tolerance <= 0)
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
2919 interval = GetDoubleClickTime () / 3;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2920 else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2921 interval = mswindows_mouse_button_tolerance;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2922
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2923 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2924 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2925
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2926 static int
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2927 mswindows_button2_near_enough (POINTS p1, POINTS p2)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2928 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2929 int dx, dy;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2930 if (mswindows_mouse_button_max_skew_x <= 0)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2931 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2932 else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2933 dx = mswindows_mouse_button_max_skew_x;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2934
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2935 if (mswindows_mouse_button_max_skew_y <= 0)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2936 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2937 else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
2938 dy = mswindows_mouse_button_max_skew_y;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2939
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2940 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
2941 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2942
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2943 static int
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2944 mswindows_current_layout_has_AltGr (void)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2945 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2946 /* This simple caching mechanism saves 10% of CPU
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2947 time when a key typed at autorepeat rate of 30 cps! */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2948 static HKL last_hkl = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2949 static int last_hkl_has_AltGr;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2950
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2951 HKL current_hkl = GetKeyboardLayout (0);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2952 if (current_hkl != last_hkl)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2953 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2954 TCHAR c;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2955 last_hkl_has_AltGr = 0;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2956 /* In this loop, we query whether a character requires
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2957 AltGr to be down to generate it. If at least such one
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2958 found, this means that the layout does regard AltGr */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2959 for (c = ' '; c <= 0xFFU && c != 0 && !last_hkl_has_AltGr; ++c)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2960 if (HIBYTE (VkKeyScan (c)) == 6)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2961 last_hkl_has_AltGr = 1;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2962 last_hkl = current_hkl;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2963 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2964 return last_hkl_has_AltGr;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2965 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2966
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2967
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2968 /* 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
2969 * Lisp_Event key_data, button_data and motion_data modifiers member */
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2970 static int
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2971 mswindows_modifier_state (BYTE* keymap, int has_AltGr)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2972 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2973 int mods = 0;
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2974 BYTE keymap2[256];
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2975
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2976 if (keymap == NULL)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2977 {
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
2978 keymap = keymap2;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2979 GetKeyboardState (keymap);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2980 has_AltGr = mswindows_current_layout_has_AltGr ();
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2981 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2982
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2983 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2984 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2985 mods |= (keymap [VK_LMENU] & 0x80) ? XEMACS_MOD_META : 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2986 mods |= (keymap [VK_RCONTROL] & 0x80) ? XEMACS_MOD_CONTROL : 0;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2987 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2988 else
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2989 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2990 mods |= (keymap [VK_MENU] & 0x80) ? XEMACS_MOD_META : 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2991 mods |= (keymap [VK_CONTROL] & 0x80) ? XEMACS_MOD_CONTROL : 0;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2992 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2993
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2994 mods |= (keymap [VK_SHIFT] & 0x80) ? XEMACS_MOD_SHIFT : 0;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2995
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2996 return mods;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2997 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2998
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
2999 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3000 * Translate a mswindows virtual key to a keysym.
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3001 * 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
3002 * or whose ASCII codes (like space) xemacs doesn't like.
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3003 * Virtual key values are defined in winresrc.h
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3004 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3005 Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3006 int extendedp)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3007 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3008 if (extendedp) /* Keys not present on a 82 key keyboard */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3009 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3010 switch (mswindows_key)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3011 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3012 case VK_RETURN: return KEYSYM ("kp-enter");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3013 case VK_PRIOR: return KEYSYM ("prior");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3014 case VK_NEXT: return KEYSYM ("next");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3015 case VK_END: return KEYSYM ("end");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3016 case VK_HOME: return KEYSYM ("home");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3017 case VK_LEFT: return KEYSYM ("left");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3018 case VK_UP: return KEYSYM ("up");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3019 case VK_RIGHT: return KEYSYM ("right");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3020 case VK_DOWN: return KEYSYM ("down");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3021 case VK_INSERT: return KEYSYM ("insert");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3022 case VK_DELETE: return QKdelete;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3023 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3024 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3025 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3026 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3027 switch (mswindows_key)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3028 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3029 case VK_BACK: return QKbackspace;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3030 case VK_TAB: return QKtab;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3031 case '\n': return QKlinefeed;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3032 case VK_CLEAR: return KEYSYM ("clear");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3033 case VK_RETURN: return QKreturn;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3034 case VK_ESCAPE: return QKescape;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3035 case VK_SPACE: return QKspace;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3036 case VK_PRIOR: return KEYSYM ("kp-prior");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3037 case VK_NEXT: return KEYSYM ("kp-next");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3038 case VK_END: return KEYSYM ("kp-end");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3039 case VK_HOME: return KEYSYM ("kp-home");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3040 case VK_LEFT: return KEYSYM ("kp-left");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3041 case VK_UP: return KEYSYM ("kp-up");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3042 case VK_RIGHT: return KEYSYM ("kp-right");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3043 case VK_DOWN: return KEYSYM ("kp-down");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3044 case VK_SELECT: return KEYSYM ("select");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3045 case VK_PRINT: return KEYSYM ("print");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3046 case VK_EXECUTE: return KEYSYM ("execute");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3047 case VK_SNAPSHOT: return KEYSYM ("print");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3048 case VK_INSERT: return KEYSYM ("kp-insert");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3049 case VK_DELETE: return KEYSYM ("kp-delete");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3050 case VK_HELP: return KEYSYM ("help");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3051 #if 0 /* FSF Emacs allows these to return configurable syms/mods */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3052 case VK_LWIN return KEYSYM ("");
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3053 case VK_RWIN return KEYSYM ("");
367
a4f53d9b3154 Import from CVS: tag r21-1-13
cvs
parents: 363
diff changeset
3054 #endif
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3055 case VK_APPS: return KEYSYM ("menu");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3056 case VK_NUMPAD0: return KEYSYM ("kp-0");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3057 case VK_NUMPAD1: return KEYSYM ("kp-1");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3058 case VK_NUMPAD2: return KEYSYM ("kp-2");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3059 case VK_NUMPAD3: return KEYSYM ("kp-3");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3060 case VK_NUMPAD4: return KEYSYM ("kp-4");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3061 case VK_NUMPAD5: return KEYSYM ("kp-5");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3062 case VK_NUMPAD6: return KEYSYM ("kp-6");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3063 case VK_NUMPAD7: return KEYSYM ("kp-7");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3064 case VK_NUMPAD8: return KEYSYM ("kp-8");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3065 case VK_NUMPAD9: return KEYSYM ("kp-9");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3066 case VK_MULTIPLY: return KEYSYM ("kp-multiply");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3067 case VK_ADD: return KEYSYM ("kp-add");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3068 case VK_SEPARATOR: return KEYSYM ("kp-separator");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3069 case VK_SUBTRACT: return KEYSYM ("kp-subtract");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3070 case VK_DECIMAL: return KEYSYM ("kp-decimal");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3071 case VK_DIVIDE: return KEYSYM ("kp-divide");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3072 case VK_F1: return KEYSYM ("f1");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3073 case VK_F2: return KEYSYM ("f2");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3074 case VK_F3: return KEYSYM ("f3");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3075 case VK_F4: return KEYSYM ("f4");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3076 case VK_F5: return KEYSYM ("f5");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3077 case VK_F6: return KEYSYM ("f6");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3078 case VK_F7: return KEYSYM ("f7");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3079 case VK_F8: return KEYSYM ("f8");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3080 case VK_F9: return KEYSYM ("f9");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3081 case VK_F10: return KEYSYM ("f10");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3082 case VK_F11: return KEYSYM ("f11");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3083 case VK_F12: return KEYSYM ("f12");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3084 case VK_F13: return KEYSYM ("f13");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3085 case VK_F14: return KEYSYM ("f14");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3086 case VK_F15: return KEYSYM ("f15");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3087 case VK_F16: return KEYSYM ("f16");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3088 case VK_F17: return KEYSYM ("f17");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3089 case VK_F18: return KEYSYM ("f18");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3090 case VK_F19: return KEYSYM ("f19");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3091 case VK_F20: return KEYSYM ("f20");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3092 case VK_F21: return KEYSYM ("f21");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3093 case VK_F22: return KEYSYM ("f22");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3094 case VK_F23: return KEYSYM ("f23");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3095 case VK_F24: return KEYSYM ("f24");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3096 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3097 }
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3098 return Qnil;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3099 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3100
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3101 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3102 * Find the console that matches the supplied mswindows window handle
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3103 */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3104 Lisp_Object
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3105 mswindows_find_console (HWND hwnd)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3106 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3107 /* We only support one console */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3108 return XCAR (Vconsole_list);
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3109 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3110
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3111 /*
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3112 * Find the frame that matches the supplied mswindows window handle
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3113 */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3114 static Lisp_Object
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3115 mswindows_find_frame (HWND hwnd)
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3116 {
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3117 LONG l = GetWindowLong (hwnd, XWL_FRAMEOBJ);
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3118 Lisp_Object f;
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3119 if (l == 0)
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3120 {
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3121 /* We are in progress of frame creation. Return the frame
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3122 being created, as it still not remembered in the window
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3123 extra storage. */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3124 assert (!NILP (Vmswindows_frame_being_created));
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3125 return Vmswindows_frame_being_created;
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3126 }
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3127 VOID_TO_LISP (f, l);
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 263
diff changeset
3128 return f;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3129 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3130
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3131
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3132 /************************************************************************/
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3133 /* methods */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3134 /************************************************************************/
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3135
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3136 static int
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3137 emacs_mswindows_add_timeout (EMACS_TIME thyme)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3138 {
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3139 int milliseconds;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3140 EMACS_TIME current_time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3141 EMACS_GET_TIME (current_time);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3142 EMACS_SUB_TIME (thyme, thyme, current_time);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3143 milliseconds = EMACS_SECS (thyme) * 1000 +
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3144 (EMACS_USECS (thyme) + 500) / 1000;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3145 if (milliseconds < 1)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3146 milliseconds = 1;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
3147 ++mswindows_pending_timers_count;
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3148 return SetTimer (NULL, 0, milliseconds,
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3149 (TIMERPROC) mswindows_wm_timer_callback);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3150 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3151
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3152 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3153 emacs_mswindows_remove_timeout (int id)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3154 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3155 Lisp_Event match_against;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3156 Lisp_Object emacs_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3157
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
3158 if (KillTimer (NULL, id))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
3159 --mswindows_pending_timers_count;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3160
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3161 /* If there is a dispatch event generated by this
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3162 timeout in the queue, we have to remove it too. */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3163 match_against.event_type = timeout_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3164 match_against.event.timeout.interval_id = id;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3165 emacs_event = mswindows_cancel_dispatch_event (&match_against);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3166 if (!NILP (emacs_event))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3167 Fdeallocate_event(emacs_event);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3168 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3169
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3170 /* 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
3171 * or subprocess events pending (that is, whether
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3172 * emacs_mswindows_next_event() would return immediately without blocking).
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3173 *
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3174 * 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
3175 * events available (that is, whether there are keyboard or mouse-click
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3176 * events ready to be read). This also implies that
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3177 * emacs_mswindows_next_event() would not block.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3178 */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3179 static int
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3180 emacs_mswindows_event_pending_p (int user_p)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3181 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3182 mswindows_need_event (0);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3183 return (!NILP (mswindows_u_dispatch_event_queue)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3184 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3185 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3186
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3187 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3188 * Return the next event
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3189 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3190 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3191 emacs_mswindows_next_event (Lisp_Event *emacs_event)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3192 {
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3193 Lisp_Object event, event2;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3194
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3195 mswindows_need_event (1);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3196
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3197 event = mswindows_dequeue_dispatch_event ();
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3198 XSETEVENT (event2, emacs_event);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3199 Fcopy_event (event, event2);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3200 Fdeallocate_event (event);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3201 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3202
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3203 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3204 * Handle a magic event off the dispatch queue.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3205 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3206 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3207 emacs_mswindows_handle_magic_event (Lisp_Event *emacs_event)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3208 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3209 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3210 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3211 case XM_BUMPQUEUE:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3212 break;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3213
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3214 case WM_PAINT:
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3215 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3216 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3217 mswindows_handle_paint (f);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3218 (FRAME_MSWINDOWS_DATA (f))->paint_pending = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3219 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3220 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3221
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3222 case WM_SETFOCUS:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3223 case WM_KILLFOCUS:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3224 {
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3225 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3226 struct frame *f = XFRAME (frame);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3227 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3228 Lisp_Object conser;
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3229 struct gcpro gcpro1;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3230
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3231 /* On focus change, clear all memory of sticky modifiers
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3232 to avoid non-intuitive behavior. */
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3233 clear_sticky_modifiers ();
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3234
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3235 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3236 GCPRO1 (conser);
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3237 emacs_handle_focus_change_preliminary (conser);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3238 /* 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
3239 I Don't know why */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3240 emacs_handle_focus_change_final (conser);
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3241 UNGCPRO;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3242
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3243 }
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3244 break;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3245
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3246 case XM_MAPFRAME:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3247 case XM_UNMAPFRAME:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3248 {
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3249 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3250 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3251 == XM_MAPFRAME ?
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3252 Qmap_frame_hook : Qunmap_frame_hook,
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3253 1, frame);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3254 }
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3255 break;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3256
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 245
diff changeset
3257 /* #### What about Enter & Leave */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3258 #if 0
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3259 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3260 Qmouse_leave_frame_hook, 1, frame);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3261 #endif
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3262
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3263 default:
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3264 assert(0);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
3265 }
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3266 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3267
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
3268 #ifndef HAVE_MSG_SELECT
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3269 static HANDLE
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3270 get_process_input_waitable (Lisp_Process *process)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3271 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3272 Lisp_Object instr, outstr, p;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3273 XSETPROCESS (p, process);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3274 get_process_streams (process, &instr, &outstr);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3275 assert (!NILP (instr));
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3276 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3277 return (network_connection_p (p)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3278 ? get_winsock_stream_waitable (XLSTREAM (instr))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3279 : get_ntpipe_input_stream_waitable (XLSTREAM (instr)));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3280 #else
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3281 return get_ntpipe_input_stream_waitable (XLSTREAM (instr));
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3282 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3283 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3284
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3285 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3286 emacs_mswindows_select_process (Lisp_Process *process)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3287 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3288 HANDLE hev = get_process_input_waitable (process);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3289
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3290 if (!add_waitable_handle (hev))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3291 error ("Too many active processes");
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3292
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3293 #ifdef HAVE_WIN32_PROCESSES
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3294 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3295 Lisp_Object p;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3296 XSETPROCESS (p, process);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3297 if (!network_connection_p (p))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3298 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3299 HANDLE hprocess = get_nt_process_handle (process);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3300 if (!add_waitable_handle (hprocess))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3301 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3302 remove_waitable_handle (hev);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3303 error ("Too many active processes");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3304 }
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3305 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3306 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3307 #endif
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3308 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3309
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3310 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3311 emacs_mswindows_unselect_process (Lisp_Process *process)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3312 {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3313 /* Process handle is removed in the event loop as soon
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3314 as it is signaled, so don't bother here about it */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3315 HANDLE hev = get_process_input_waitable (process);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3316 remove_waitable_handle (hev);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3317 }
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
3318 #endif /* HAVE_MSG_SELECT */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3319
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3320 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3321 emacs_mswindows_select_console (struct console *con)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3322 {
392
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3323 #ifdef HAVE_MSG_SELECT
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3324 if (CONSOLE_MSWINDOWS_P (con))
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3325 return; /* mswindows consoles are automatically selected */
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3326
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3327 event_stream_unixoid_select_console (con);
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3328 #endif
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3329 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3330
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3331 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3332 emacs_mswindows_unselect_console (struct console *con)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3333 {
392
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3334 #ifdef HAVE_MSG_SELECT
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3335 if (CONSOLE_MSWINDOWS_P (con))
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3336 return; /* mswindows consoles are automatically selected */
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3337
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3338 event_stream_unixoid_unselect_console (con);
1f50e6fe4f3f Import from CVS: tag r21-2-11
cvs
parents: 388
diff changeset
3339 #endif
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3340 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3341
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3342 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3343 emacs_mswindows_quit_p (void)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3344 {
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3345 /* Quit cannot happen in modal loop: all program
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3346 input is dedicated to Windows. */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3347 if (mswindows_in_modal_loop)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3348 return;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3349
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3350 /* Drain windows queue. This sets up number of quit characters in
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3351 the queue */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3352 mswindows_drain_windows_queue ();
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3353
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3354 if (mswindows_quit_chars_count > 0)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3355 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3356 /* Yes there's a hidden one... Throw it away */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3357 Lisp_Event match_against;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3358 Lisp_Object emacs_event;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3359 int critical_p = 0;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3360
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3361 match_against.event_type = key_press_event;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3362 match_against.event.key.modifiers = FAKE_MOD_QUIT;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3363
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3364 while (mswindows_quit_chars_count-- > 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3365 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3366 emacs_event = mswindows_cancel_dispatch_event (&match_against);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3367 assert (!NILP (emacs_event));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3368
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3369 if (XEVENT(emacs_event)->event.key.modifiers & XEMACS_MOD_SHIFT)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3370 critical_p = 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3371
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3372 Fdeallocate_event(emacs_event);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3373 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3374
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3375 Vquit_flag = critical_p ? Qcritical : Qt;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3376 }
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3377 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3378
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3379 USID
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3380 emacs_mswindows_create_stream_pair (void* inhandle, void* outhandle,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3381 Lisp_Object* instream,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3382 Lisp_Object* outstream,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3383 int flags)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3384 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3385 /* Handles for streams */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3386 HANDLE hin, hout;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3387 /* fds. These just stored along with the streams, and are closed in
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3388 delete stream pair method, because we need to handle fake unices
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3389 here. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3390 int fdi, fdo;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3391
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3392 /* Decode inhandle and outhandle. Their meaning depends on
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3393 the process implementation being used. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3394 #if defined (HAVE_WIN32_PROCESSES)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3395 /* We're passed in Windows handles. That's what we like most... */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3396 hin = (HANDLE) inhandle;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3397 hout = (HANDLE) outhandle;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3398 fdi = fdo = -1;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3399 #elif defined (HAVE_UNIX_PROCESSES)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3400 /* We are passed UNIX fds. This must be Cygwin.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3401 Fetch os handles */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3402 hin = inhandle >= 0 ? (HANDLE)get_osfhandle ((int)inhandle) : INVALID_HANDLE_VALUE;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3403 hout = outhandle >= 0 ? (HANDLE)get_osfhandle ((int)outhandle) : INVALID_HANDLE_VALUE;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3404 fdi=(int)inhandle;
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3405 fdo=(int)outhandle;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3406 #else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3407 #error "So, WHICH kind of processes do you want?"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3408 #endif
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3409
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3410 *instream = (hin == INVALID_HANDLE_VALUE
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3411 ? Qnil
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3412 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3413 : flags & STREAM_NETWORK_CONNECTION
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3414 ? make_winsock_input_stream ((SOCKET)hin, fdi)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3415 #endif
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3416 : make_ntpipe_input_stream (hin, fdi));
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3417
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3418 #ifdef HAVE_WIN32_PROCESSES
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3419 *outstream = (hout == INVALID_HANDLE_VALUE
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3420 ? Qnil
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3421 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3422 : flags & STREAM_NETWORK_CONNECTION
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3423 ? make_winsock_output_stream ((SOCKET)hout, fdo)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3424 #endif
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3425 : make_ntpipe_output_stream (hout, fdo));
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3426 #elif defined (HAVE_UNIX_PROCESSES)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3427 *outstream = (fdo >= 0
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3428 ? make_filedesc_output_stream (fdo, 0, -1, LSTR_BLOCKED_OK)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3429 : Qnil);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3430
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3431 #if defined(HAVE_UNIX_PROCESSES) && defined(HAVE_PTYS)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3432 /* FLAGS is process->pty_flag for UNIX_PROCESSES */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3433 if ((flags & STREAM_PTY_FLUSHING) && fdo >= 0)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3434 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3435 Bufbyte eof_char = get_eof_char (fdo);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3436 int pty_max_bytes = get_pty_max_bytes (fdo);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3437 filedesc_stream_set_pty_flushing (XLSTREAM(*outstream), pty_max_bytes, eof_char);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3438 }
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3439 #endif
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3440 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3441
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3442 return (NILP (*instream)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3443 ? USID_ERROR
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3444 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3445 : flags & STREAM_NETWORK_CONNECTION
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3446 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (*instream)))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3447 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3448 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (*instream))));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3449 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3450
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3451 USID
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3452 emacs_mswindows_delete_stream_pair (Lisp_Object instream,
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3453 Lisp_Object outstream)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3454 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3455 /* Oh nothing special here for Win32 at all */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3456 #if defined (HAVE_UNIX_PROCESSES)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3457 int in = (NILP(instream)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3458 ? -1
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3459 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3460 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3461 ? get_winsock_stream_param (XLSTREAM (instream))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3462 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3463 : get_ntpipe_input_stream_param (XLSTREAM (instream)));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3464 int out = (NILP(outstream) ? -1
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
3465 : filedesc_stream_fd (XLSTREAM (outstream)));
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3466
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3467 if (in >= 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3468 close (in);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3469 if (out != in && out >= 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3470 close (out);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3471 #endif
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3472
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3473 return (NILP (instream)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3474 ? USID_DONTHASH
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3475 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3476 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3477 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (instream)))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3478 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3479 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (instream))));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3480 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3481
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
3482 #ifndef HAVE_X_WINDOWS
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3483 /* 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
3484 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
3485 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3486 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3487 debug_process_finalization (Lisp_Process *p)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3488 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3489 #if 0 /* #### */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
3490 Lisp_Object instr, outstr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
3491
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
3492 get_process_streams (p, &instr, &outstr);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3493 /* 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
3494 assert (NILP(instr));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
3495 assert (NILP(outstr));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
3496
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
3497 /* #### More checks here */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3498 #endif
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3499 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
3500 #endif
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3501
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3502 /************************************************************************/
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3503 /* initialization */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3504 /************************************************************************/
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3505
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3506 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3507 reinit_vars_of_event_mswindows (void)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3508 {
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 227
diff changeset
3509 mswindows_in_modal_loop = 0;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
3510 mswindows_pending_timers_count = 0;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 225
diff changeset
3511
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3512 mswindows_event_stream = xnew (struct event_stream);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3513
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3514 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3515 mswindows_event_stream->force_event_pending = 0;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3516 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3517 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3518 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3519 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3520 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3521 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3522 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3523 #ifdef HAVE_MSG_SELECT
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3524 mswindows_event_stream->select_process_cb =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3525 (void (*)(Lisp_Process*))event_stream_unixoid_select_process;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3526 mswindows_event_stream->unselect_process_cb =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3527 (void (*)(Lisp_Process*))event_stream_unixoid_unselect_process;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3528 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
3529 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
3530 #else
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3531 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3532 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3533 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3534 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
3535 #endif
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3536 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3537
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3538 void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3539 vars_of_event_mswindows (void)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3540 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3541 reinit_vars_of_event_mswindows ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3542
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3543 mswindows_u_dispatch_event_queue = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3544 staticpro (&mswindows_u_dispatch_event_queue);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3545 mswindows_u_dispatch_event_queue_tail = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3546 pdump_wire (&mswindows_u_dispatch_event_queue_tail);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3547
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3548 mswindows_s_dispatch_event_queue = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3549 staticpro (&mswindows_s_dispatch_event_queue);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3550 mswindows_s_dispatch_event_queue_tail = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3551 pdump_wire (&mswindows_s_dispatch_event_queue_tail);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3552
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3553 mswindows_error_caught_in_modal_loop = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3554 staticpro (&mswindows_error_caught_in_modal_loop);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3555
408
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3556
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3557 #ifdef DEBUG_XEMACS
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3558 DEFVAR_INT ("mswindows-debug-events", &mswindows_debug_events /*
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3559 If non-zero, display debug information about Windows events that XEmacs sees.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3560 Information is displayed in a console window. Currently defined values are:
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3561
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3562 1 == non-verbose output
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3563 2 == verbose output
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3564
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3565 #### Unfortunately, not yet implemented.
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3566 */ );
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3567 mswindows_debug_events = 0;
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3568 #endif
501cfd01ee6d Import from CVS: tag r21-2-34
cvs
parents: 406
diff changeset
3569
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3570 DEFVAR_BOOL ("mswindows-alt-by-itself-activates-menu",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3571 &mswindows_alt_by_itself_activates_menu /*
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3572 *Controls whether pressing and releasing the Alt key activates the menubar.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3573 This applies only if no intervening key was pressed. See also
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3574 `menu-accelerator-enabled', which is probably the behavior you actually want.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3575 Default is t.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 392
diff changeset
3576 */ );
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3577
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3578 DEFVAR_BOOL ("mswindows-dynamic-frame-resize",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3579 &mswindows_dynamic_frame_resize /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3580 *Controls redrawing frame contents during mouse-drag or keyboard resize
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3581 operation. When non-nil, the frame is redrawn while being resized. When
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3582 nil, frame is not redrawn, and exposed areas are filled with default
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3583 MDI application background color. Note that this option only has effect
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3584 if "Show window contents while dragging" is on in system Display/Plus!
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3585 settings.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3586 Default is t on fast machines, nil on slow.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3587 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3588
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3589 DEFVAR_INT ("mswindows-mouse-button-tolerance",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3590 &mswindows_mouse_button_tolerance /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3591 *Analogue of double click interval for faking middle mouse events.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3592 The value is the minimum time in milliseconds that must elapse between
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3593 left/right button down events before they are considered distinct events.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3594 If both mouse buttons are depressed within this interval, a middle mouse
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3595 button down event is generated instead.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3596 If negative or zero, currently set system default is used instead.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3597 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3598
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 223
diff changeset
3599 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3600 Number of physical mouse buttons.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3601 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3602
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3603 DEFVAR_INT ("mswindows-mouse-button-max-skew-x",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3604 &mswindows_mouse_button_max_skew_x /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3605 *Maximum horizontal distance in pixels between points in which left and
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3606 right button clicks occurred for them to be translated into single
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3607 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
3608 by the variable `mswindows-mouse-button-tolerance'.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3609 If negative or zero, currently set system default is used instead.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3610 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3611
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3612 DEFVAR_INT ("mswindows-mouse-button-max-skew-y",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3613 &mswindows_mouse_button_max_skew_y /*
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3614 *Maximum vertical distance in pixels between points in which left and
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3615 right button clicks occurred for them to be translated into single
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3616 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
3617 by the variable `mswindows-mouse-button-tolerance'.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3618 If negative or zero, currently set system default is used instead.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3619 */ );
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3620
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
3621 mswindows_mouse_button_max_skew_x = 0;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
3622 mswindows_mouse_button_max_skew_y = 0;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
3623 mswindows_mouse_button_tolerance = 0;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
3624 mswindows_alt_by_itself_activates_menu = 1;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3625 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3626
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3627 void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3628 syms_of_event_mswindows (void)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3629 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3630 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3631
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3632 void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3633 lstream_type_create_mswindows_selectable (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3634 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3635 init_slurp_stream ();
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3636 init_shove_stream ();
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3637 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3638 init_winsock_stream ();
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
3639 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3640 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3641
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
3642 void
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3643 init_event_mswindows_late (void)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3644 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3645 #ifdef HAVE_MSG_SELECT
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3646 windows_fd = open("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3647 assert (windows_fd>=0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3648 FD_SET (windows_fd, &input_wait_mask);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3649 FD_ZERO(&zero_mask);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3650 #endif
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
3651
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3652 event_stream = mswindows_event_stream;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3653
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3654 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3655 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3656 }