annotate src/event-msw.c @ 470:8a548306e08d

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