442
+ − 1 /* The mswindows event_stream interface.
428
+ − 2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+ − 3 Copyright (C) 1995 Sun Microsystems, Inc.
771
+ − 4 Copyright (C) 1996, 2000, 2001, 2002 Ben Wing.
428
+ − 5 Copyright (C) 1997 Jonathan Harris.
+ − 6
+ − 7 This file is part of XEmacs.
+ − 8
+ − 9 XEmacs is free software; you can redistribute it and/or modify it
+ − 10 under the terms of the GNU General Public License as published by the
+ − 11 Free Software Foundation; either version 2, or (at your option) any
+ − 12 later version.
+ − 13
+ − 14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
+ − 15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ − 16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ − 17 for more details.
+ − 18
+ − 19 You should have received a copy of the GNU General Public License
+ − 20 along with XEmacs; see the file COPYING. If not, write to
+ − 21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 22 Boston, MA 02111-1307, USA. */
+ − 23
+ − 24 /* Synched up with: Not in FSF. */
+ − 25
771
+ − 26 /* This file essentially Mule-ized (except perhaps some Unicode splitting).
+ − 27 5-2000. */
+ − 28
428
+ − 29 /* Authorship:
+ − 30
+ − 31 Ultimately based on FSF.
+ − 32 Rewritten by Ben Wing.
+ − 33 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
+ − 34 Subprocess and modal loop support by Kirill M. Katsnelson.
+ − 35 */
+ − 36
771
+ − 37 #define NEED_MSWINDOWS_SHLOBJ /* for IShellLink */
+ − 38
428
+ − 39 #include <config.h>
+ − 40 #include "lisp.h"
+ − 41
853
+ − 42 #if defined (CYGWIN) && !defined (HAVE_MSG_SELECT)
+ − 43 #error We do not support non-select() versions (i.e. very old) of Cygwin.
+ − 44 #endif
+ − 45
+ − 46 /* Acceptable are:
+ − 47
+ − 48 WIN32_NATIVE and HAVE_WIN32_PROCESSES and nothing else
+ − 49
+ − 50 CYGWIN and HAVE_MSG_SELECT and HAVE_UNIX_PROCESSES and nothing else
+ − 51 */
+ − 52 #ifdef WIN32_NATIVE
856
+ − 53 # if !(defined (HAVE_WIN32_PROCESSES) && !defined (HAVE_UNIX_PROCESSES) && !defined (HAVE_MSG_SELECT) && !defined (CYGWIN))
853
+ − 54 # error Something is wrong with your process definitions for Windows native.
+ − 55 # endif
+ − 56 #elif defined (CYGWIN)
+ − 57 # if !(defined (HAVE_UNIX_PROCESSES) && defined (HAVE_MSG_SELECT) && !defined (HAVE_WIN32_PROCESSES) && !defined (WIN32_NATIVE))
+ − 58 # error Something is wrong with your process definitions for Cygwin.
+ − 59 # endif
+ − 60 #else
+ − 61 # error Something is wrong -- you are neither Windows native (possibly MinGW) nor Cygwin.
+ − 62 #endif
+ − 63
800
+ − 64 #include "buffer.h"
872
+ − 65 #include "device-impl.h"
800
+ − 66 #include "events.h"
+ − 67 #include "faces.h"
872
+ − 68 #include "frame-impl.h"
800
+ − 69 #include "glyphs.h"
+ − 70 #include "lstream.h"
+ − 71 #include "process.h"
+ − 72 #include "redisplay.h"
+ − 73 #include "sysdep.h"
+ − 74 #include "window.h"
+ − 75
872
+ − 76 #include "console-msw-impl.h"
+ − 77 #include "objects-msw-impl.h"
428
+ − 78
+ − 79 #ifdef HAVE_SCROLLBARS
+ − 80 # include "scrollbar-msw.h"
+ − 81 #endif
+ − 82
+ − 83 #ifdef HAVE_MENUBARS
442
+ − 84 # include "menubar.h"
428
+ − 85 # include "menubar-msw.h"
+ − 86 #endif
+ − 87
+ − 88 #ifdef HAVE_DRAGNDROP
+ − 89 # include "dragdrop.h"
+ − 90 #endif
+ − 91
558
+ − 92 #include "sysfile.h"
428
+ − 93 #include "sysproc.h"
558
+ − 94 #include "systime.h"
428
+ − 95 #include "syswait.h"
+ − 96
853
+ − 97 #ifdef CYGWIN
428
+ − 98 #include "console-tty.h"
+ − 99 #endif
+ − 100
+ − 101 #ifdef HAVE_MENUBARS
+ − 102 #define ADJR_MENUFLAG TRUE
+ − 103 #else
+ − 104 #define ADJR_MENUFLAG FALSE
+ − 105 #endif
+ − 106
+ − 107 /* Fake key modifier which is attached to a quit char event.
+ − 108 Removed upon dequeueing an event */
502
+ − 109 #define FAKE_MOD_QUIT (1 << 20)
+ − 110 #define FAKE_MOD_QUIT_CRITICAL (1 << 21)
428
+ − 111
+ − 112 /* Timer ID used for button2 emulation */
+ − 113 #define BUTTON_2_TIMER_ID 1
+ − 114
+ − 115 static Lisp_Object mswindows_find_console (HWND hwnd);
+ − 116 static Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
+ − 117 int extendedp);
771
+ − 118 static int mswindows_modifier_state (BYTE *keymap, DWORD fwKeys,
442
+ − 119 int has_AltGr);
428
+ − 120 static void mswindows_set_chord_timer (HWND hwnd);
+ − 121 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
+ − 122 static int mswindows_current_layout_has_AltGr (void);
442
+ − 123 static int mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam,
+ − 124 int downp, int keyp);
428
+ − 125
+ − 126 static struct event_stream *mswindows_event_stream;
+ − 127
853
+ − 128 #ifdef CYGWIN
+ − 129
428
+ − 130 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
+ − 131 extern SELECT_TYPE process_only_mask, tty_only_mask;
+ − 132 SELECT_TYPE zero_mask;
+ − 133 extern int signal_event_pipe_initialized;
+ − 134 int windows_fd;
853
+ − 135
+ − 136 #else
+ − 137
856
+ − 138 /* The number of things we can wait on */
+ − 139 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1)
+ − 140
853
+ − 141 /* List of mswindows waitable handles. */
+ − 142 static HANDLE mswindows_waitable_handles[MAX_WAITABLE];
+ − 143
+ − 144 /* Number of wait handles */
+ − 145 static int mswindows_waitable_count = 0;
+ − 146
428
+ − 147 #endif
+ − 148
+ − 149 /*
+ − 150 * Two separate queues, for efficiency, one (_u_) for user events, and
+ − 151 * another (_s_) for non-user ones. We always return events out of the
+ − 152 * first one until it is empty and only then proceed with the second
+ − 153 * one.
+ − 154 */
+ − 155 static Lisp_Object mswindows_u_dispatch_event_queue, mswindows_u_dispatch_event_queue_tail;
+ − 156 static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail;
+ − 157
+ − 158 /* Brush for painting widgets */
+ − 159 static HBRUSH widget_brush = 0;
+ − 160 static LONG last_widget_brushed = 0;
+ − 161
+ − 162 /* Count of quit chars currently in the queue */
+ − 163 /* Incremented in WM_[SYS]KEYDOWN handler in the mswindows_wnd_proc()
+ − 164 Decremented in mswindows_dequeue_dispatch_event() */
+ − 165 int mswindows_quit_chars_count = 0;
+ − 166
+ − 167 /* These are Lisp integers; see DEFVARS in this file for description. */
+ − 168 int mswindows_dynamic_frame_resize;
442
+ − 169 int mswindows_alt_by_itself_activates_menu;
458
+ − 170 Fixnum mswindows_num_mouse_buttons;
+ − 171 Fixnum mswindows_mouse_button_max_skew_x;
+ − 172 Fixnum mswindows_mouse_button_max_skew_y;
+ − 173 Fixnum mswindows_mouse_button_tolerance;
428
+ − 174
442
+ − 175 #ifdef DEBUG_XEMACS
458
+ − 176 Fixnum debug_mswindows_events;
593
+ − 177
+ − 178 static void debug_output_mswin_message (HWND hwnd, UINT message_,
+ − 179 WPARAM wParam, LPARAM lParam);
442
+ − 180 #endif
+ − 181
428
+ − 182 /* This is the event signaled by the event pump.
+ − 183 See mswindows_pump_outstanding_events for comments */
853
+ − 184 static int mswindows_error_caught_in_modal_loop;
428
+ − 185 static int mswindows_in_modal_loop;
+ − 186
+ − 187 /* Count of wound timers */
+ − 188 static int mswindows_pending_timers_count;
442
+ − 189
+ − 190 static DWORD mswindows_last_mouse_button_state;
853
+ − 191
428
+ − 192
853
+ − 193 #ifndef CYGWIN /* Skips past slurp, shove, or winsock streams */
+ − 194
428
+ − 195 /************************************************************************/
+ − 196 /* Pipe instream - reads process output */
+ − 197 /************************************************************************/
+ − 198
+ − 199 #define PIPE_READ_DELAY 20
+ − 200
+ − 201 #define HANDLE_TO_USID(h) ((USID)(h))
+ − 202
+ − 203 #define NTPIPE_SLURP_STREAM_DATA(stream) \
+ − 204 LSTREAM_TYPE_DATA (stream, ntpipe_slurp)
+ − 205
+ − 206 /* This structure is allocated by the main thread, and is deallocated
+ − 207 in the thread upon exit. There are situations when a thread
+ − 208 remains blocked for a long time, much longer than the lstream
+ − 209 exists. For example, "start notepad" command is issued from the
+ − 210 shell, then the shell is closed by C-c C-d. Although the shell
+ − 211 process exits, its output pipe will not get closed until the
656
+ − 212 notepad process exits also, because it inherits the pipe from the
428
+ − 213 shell. In this case, we abandon the thread, and let it live until
+ − 214 all such processes exit. While struct ntpipe_slurp_stream is
+ − 215 deallocated in this case, ntpipe_slurp_stream_shared_data are not. */
+ − 216
+ − 217 struct ntpipe_slurp_stream_shared_data
+ − 218 {
+ − 219 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
853
+ − 220 /* This is a manual-reset object. */
428
+ − 221 HANDLE hev_caller; /* Caller blocks on this, and we signal it */
853
+ − 222 /* This is a manual-reset object. */
428
+ − 223 HANDLE hev_unsleep; /* Pipe read delay is canceled if this is set */
853
+ − 224 /* This is a manual-reset object. */
428
+ − 225 HANDLE hpipe; /* Pipe read end handle. */
+ − 226 LONG die_p; /* Thread must exit ASAP if non-zero */
+ − 227 BOOL eof_p : 1; /* Set when thread saw EOF */
+ − 228 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
+ − 229 BOOL inuse_p : 1; /* this structure is in use */
+ − 230 LONG lock_count; /* Client count of this struct, 0=safe to free */
+ − 231 BYTE onebyte; /* One byte buffer read by thread */
+ − 232 };
+ − 233
+ − 234 #define MAX_SLURP_STREAMS 32
+ − 235 struct ntpipe_slurp_stream_shared_data
+ − 236 shared_data_block[MAX_SLURP_STREAMS]={{0}};
+ − 237
+ − 238 struct ntpipe_slurp_stream
+ − 239 {
+ − 240 LPARAM user_data; /* Any user data stored in the stream object */
771
+ − 241 struct ntpipe_slurp_stream_shared_data *thread_data;
428
+ − 242 };
+ − 243
771
+ − 244 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-input", ntpipe_slurp);
428
+ − 245
+ − 246 /* This function is thread-safe, and is called from either thread
+ − 247 context. It serializes freeing shared data structure */
+ − 248 static void
771
+ − 249 slurper_free_shared_data_maybe (struct ntpipe_slurp_stream_shared_data *s)
428
+ − 250 {
+ − 251 if (InterlockedDecrement (&s->lock_count) == 0)
+ − 252 {
+ − 253 /* Destroy events */
+ − 254 CloseHandle (s->hev_thread);
+ − 255 CloseHandle (s->hev_caller);
+ − 256 CloseHandle (s->hev_unsleep);
673
+ − 257 CloseHandle (s->hpipe);
428
+ − 258 s->inuse_p = 0;
+ − 259 }
+ − 260 }
+ − 261
771
+ − 262 static struct ntpipe_slurp_stream_shared_data *
442
+ − 263 slurper_allocate_shared_data (void)
428
+ − 264 {
+ − 265 int i=0;
771
+ − 266 for (i = 0; i < MAX_SLURP_STREAMS; i++)
428
+ − 267 {
+ − 268 if (!shared_data_block[i].inuse_p)
+ − 269 {
771
+ − 270 shared_data_block[i].inuse_p = 1;
428
+ − 271 return &shared_data_block[i];
+ − 272 }
+ − 273 }
771
+ − 274 return (struct ntpipe_slurp_stream_shared_data *)0;
428
+ − 275 }
+ − 276
+ − 277 static DWORD WINAPI
+ − 278 slurp_thread (LPVOID vparam)
+ − 279 {
+ − 280 struct ntpipe_slurp_stream_shared_data *s =
771
+ − 281 (struct ntpipe_slurp_stream_shared_data *)vparam;
428
+ − 282
+ − 283 for (;;)
+ − 284 {
+ − 285 /* Read one byte from the pipe */
+ − 286 DWORD actually_read;
+ − 287 if (!ReadFile (s->hpipe, &s->onebyte, 1, &actually_read, NULL))
+ − 288 {
+ − 289 DWORD err = GetLastError ();
+ − 290 if (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
+ − 291 s->eof_p = TRUE;
+ − 292 else
+ − 293 s->error_p = TRUE;
+ − 294 }
+ − 295 else if (actually_read == 0)
+ − 296 s->eof_p = TRUE;
+ − 297
+ − 298 /* We must terminate on an error or eof */
+ − 299 if (s->eof_p || s->error_p)
+ − 300 InterlockedIncrement (&s->die_p);
+ − 301
+ − 302 /* Before we notify caller, we unsignal our event. */
+ − 303 ResetEvent (s->hev_thread);
+ − 304
+ − 305 /* Now we got something to notify caller, either a byte or an
+ − 306 error/eof indication. Before we do, allow internal pipe
+ − 307 buffer to accumulate little bit more data.
+ − 308 Reader function pulses this event before waiting for
+ − 309 a character, to avoid pipe delay, and to get the byte
+ − 310 immediately. */
+ − 311 if (!s->die_p)
+ − 312 WaitForSingleObject (s->hev_unsleep, PIPE_READ_DELAY);
+ − 313
+ − 314 /* Either make event loop generate a process event, or
+ − 315 inblock reader */
+ − 316 SetEvent (s->hev_caller);
+ − 317
+ − 318 /* Cleanup and exit if we're shot off */
+ − 319 if (s->die_p)
+ − 320 break;
+ − 321
+ − 322 /* Block until the client finishes with retrieving the rest of
+ − 323 pipe data */
+ − 324 WaitForSingleObject (s->hev_thread, INFINITE);
+ − 325 }
+ − 326
+ − 327 slurper_free_shared_data_maybe (s);
+ − 328
+ − 329 return 0;
+ − 330 }
+ − 331
+ − 332 static Lisp_Object
+ − 333 make_ntpipe_input_stream (HANDLE hpipe, LPARAM param)
+ − 334 {
+ − 335 Lstream *lstr = Lstream_new (lstream_ntpipe_slurp, "r");
771
+ − 336 struct ntpipe_slurp_stream *s = NTPIPE_SLURP_STREAM_DATA (lstr);
428
+ − 337 DWORD thread_id_unused;
+ − 338 HANDLE hthread;
+ − 339
+ − 340 /* We deal only with pipes, for we're using PeekNamedPipe api */
+ − 341 assert (GetFileType (hpipe) == FILE_TYPE_PIPE);
+ − 342
+ − 343 s->thread_data = slurper_allocate_shared_data();
+ − 344
+ − 345 /* Create reader thread. This could fail, so do not create events
+ − 346 until thread is created */
+ − 347 hthread = CreateThread (NULL, 0, slurp_thread, (LPVOID)s->thread_data,
+ − 348 CREATE_SUSPENDED, &thread_id_unused);
+ − 349 if (hthread == NULL)
+ − 350 {
+ − 351 Lstream_delete (lstr);
+ − 352 s->thread_data->inuse_p=0;
+ − 353 return Qnil;
+ − 354 }
+ − 355
+ − 356 /* Shared data are initially owned by both main and slurper
+ − 357 threads. */
+ − 358 s->thread_data->lock_count = 2;
+ − 359 s->thread_data->die_p = 0;
+ − 360 s->thread_data->eof_p = FALSE;
+ − 361 s->thread_data->error_p = FALSE;
+ − 362 s->thread_data->hpipe = hpipe;
+ − 363 s->user_data = param;
+ − 364
+ − 365 /* hev_thread is a manual-reset event, initially signaled */
771
+ − 366 s->thread_data->hev_thread = qxeCreateEvent (NULL, TRUE, TRUE, NULL);
428
+ − 367 /* hev_caller is a manual-reset event, initially nonsignaled */
771
+ − 368 s->thread_data->hev_caller = qxeCreateEvent (NULL, TRUE, FALSE, NULL);
428
+ − 369 /* hev_unsleep is a manual-reset event, initially nonsignaled */
771
+ − 370 s->thread_data->hev_unsleep = qxeCreateEvent (NULL, TRUE, FALSE, NULL);
428
+ − 371
+ − 372 /* Now let it go */
+ − 373 ResumeThread (hthread);
+ − 374 CloseHandle (hthread);
+ − 375
+ − 376 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
793
+ − 377 return wrap_lstream (lstr);
428
+ − 378 }
+ − 379
+ − 380 static LPARAM
+ − 381 get_ntpipe_input_stream_param (Lstream *stream)
+ − 382 {
771
+ − 383 struct ntpipe_slurp_stream *s = NTPIPE_SLURP_STREAM_DATA(stream);
428
+ − 384 return s->user_data;
+ − 385 }
+ − 386
+ − 387 static HANDLE
+ − 388 get_ntpipe_input_stream_waitable (Lstream *stream)
+ − 389 {
771
+ − 390 struct ntpipe_slurp_stream *s = NTPIPE_SLURP_STREAM_DATA(stream);
428
+ − 391 return s->thread_data->hev_caller;
+ − 392 }
+ − 393
665
+ − 394 static Bytecount
462
+ − 395 ntpipe_slurp_reader (Lstream *stream, unsigned char *data,
665
+ − 396 Bytecount size)
428
+ − 397 {
+ − 398 /* This function must be called from the main thread only */
771
+ − 399 struct ntpipe_slurp_stream_shared_data *s =
428
+ − 400 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
+ − 401
+ − 402 if (!s->die_p)
+ − 403 {
+ − 404 DWORD wait_result;
+ − 405 /* Disallow pipe read delay for the thread: we need a character
+ − 406 ASAP */
+ − 407 SetEvent (s->hev_unsleep);
+ − 408
+ − 409 /* Check if we have a character ready. Give it a short delay,
771
+ − 410 for the thread to awake from pipe delay, just ion case */
428
+ − 411 wait_result = WaitForSingleObject (s->hev_caller, 2);
+ − 412
+ − 413 /* Revert to the normal sleep behavior. */
+ − 414 ResetEvent (s->hev_unsleep);
+ − 415
+ − 416 /* If there's no byte buffered yet, give up */
+ − 417 if (wait_result == WAIT_TIMEOUT)
+ − 418 {
+ − 419 errno = EAGAIN;
+ − 420 return -1;
+ − 421 }
+ − 422 }
+ − 423
+ − 424 /* Reset caller unlock event now, as we've handled the pending
+ − 425 process output event */
+ − 426 ResetEvent (s->hev_caller);
+ − 427
+ − 428 /* It is now safe to do anything with contents of S, except for
+ − 429 changing s->die_p, which still should be interlocked */
+ − 430
+ − 431 if (s->eof_p)
+ − 432 return 0;
+ − 433 if (s->error_p || s->die_p)
+ − 434 return -1;
+ − 435
+ − 436 /* Ok, there were no error neither eof - we've got a byte from the
+ − 437 pipe */
+ − 438 *(data++) = s->onebyte;
+ − 439 --size;
+ − 440
+ − 441 {
+ − 442 DWORD bytes_read = 0;
+ − 443 if (size > 0)
+ − 444 {
+ − 445 DWORD bytes_available;
+ − 446
+ − 447 /* If the api call fails, return at least one byte already
+ − 448 read. ReadFile in thread will return error */
+ − 449 if (PeekNamedPipe (s->hpipe, NULL, 0, NULL, &bytes_available, NULL))
+ − 450 {
+ − 451
+ − 452 /* Fetch available bytes. The same consideration applies,
+ − 453 so do not check for errors. ReadFile in the thread will
+ − 454 fail if the next call fails. */
+ − 455 if (bytes_available)
647
+ − 456 ReadFile (s->hpipe, data, min (bytes_available, (DWORD) size),
428
+ − 457 &bytes_read, NULL);
+ − 458 }
+ − 459
+ − 460 /* Now we can unblock thread, so it attempts to read more */
+ − 461 SetEvent (s->hev_thread);
+ − 462 return bytes_read + 1;
+ − 463 }
+ − 464 }
+ − 465 return 0;
+ − 466 }
+ − 467
+ − 468 static int
+ − 469 ntpipe_slurp_closer (Lstream *stream)
+ − 470 {
+ − 471 /* This function must be called from the main thread only */
771
+ − 472 struct ntpipe_slurp_stream_shared_data *s =
428
+ − 473 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
+ − 474
+ − 475 /* Force thread to stop */
+ − 476 InterlockedIncrement (&s->die_p);
+ − 477
+ − 478 /* Set events which could possibly block slurper. Let it finish soon
+ − 479 or later. */
+ − 480 SetEvent (s->hev_unsleep);
+ − 481 SetEvent (s->hev_thread);
+ − 482
+ − 483 /* Unlock and maybe free shared data */
+ − 484 slurper_free_shared_data_maybe (s);
+ − 485
+ − 486 return 0;
+ − 487 }
+ − 488
+ − 489 static void
+ − 490 init_slurp_stream (void)
+ − 491 {
+ − 492 LSTREAM_HAS_METHOD (ntpipe_slurp, reader);
+ − 493 LSTREAM_HAS_METHOD (ntpipe_slurp, closer);
+ − 494 }
853
+ − 495
428
+ − 496
+ − 497 /************************************************************************/
+ − 498 /* Pipe outstream - writes process input */
+ − 499 /************************************************************************/
+ − 500
+ − 501 #define NTPIPE_SHOVE_STREAM_DATA(stream) \
+ − 502 LSTREAM_TYPE_DATA (stream, ntpipe_shove)
+ − 503
442
+ − 504 #define MAX_SHOVE_BUFFER_SIZE 512
428
+ − 505
+ − 506 struct ntpipe_shove_stream
+ − 507 {
+ − 508 LPARAM user_data; /* Any user data stored in the stream object */
+ − 509 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
853
+ − 510 /* This is an auto-reset object. */
428
+ − 511 HANDLE hpipe; /* Pipe write end handle. */
+ − 512 HANDLE hthread; /* Reader thread handle. */
+ − 513 char buffer[MAX_SHOVE_BUFFER_SIZE]; /* Buffer being written */
+ − 514 DWORD size; /* Number of bytes to write */
+ − 515 LONG die_p; /* Thread must exit ASAP if non-zero */
+ − 516 LONG idle_p; /* Non-zero if thread is waiting for job */
+ − 517 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
+ − 518 BOOL blocking_p : 1;/* Last write attempt would cause blocking */
+ − 519 };
+ − 520
771
+ − 521 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-output", ntpipe_shove);
428
+ − 522
+ − 523 static DWORD WINAPI
+ − 524 shove_thread (LPVOID vparam)
+ − 525 {
771
+ − 526 struct ntpipe_shove_stream *s = (struct ntpipe_shove_stream *) vparam;
428
+ − 527
+ − 528 for (;;)
+ − 529 {
+ − 530 DWORD bytes_written;
+ − 531
+ − 532 /* Block on event and wait for a job */
+ − 533 InterlockedIncrement (&s->idle_p);
+ − 534 WaitForSingleObject (s->hev_thread, INFINITE);
+ − 535
771
+ − 536 if (s->die_p)
+ − 537 break;
+ − 538
442
+ − 539 /* Write passed buffer if any */
+ − 540 if (s->size > 0)
428
+ − 541 {
442
+ − 542 if (!WriteFile (s->hpipe, s->buffer, s->size, &bytes_written, NULL)
+ − 543 || bytes_written != s->size)
+ − 544 {
+ − 545 s->error_p = TRUE;
+ − 546 InterlockedIncrement (&s->die_p);
+ − 547 }
+ − 548 /* Set size to zero so we won't write it again if the closer sets
+ − 549 die_p and kicks us */
+ − 550 s->size = 0;
428
+ − 551 }
+ − 552
+ − 553 if (s->die_p)
+ − 554 break;
+ − 555 }
+ − 556
+ − 557 return 0;
+ − 558 }
+ − 559
+ − 560 static Lisp_Object
+ − 561 make_ntpipe_output_stream (HANDLE hpipe, LPARAM param)
+ − 562 {
+ − 563 Lstream *lstr = Lstream_new (lstream_ntpipe_shove, "w");
771
+ − 564 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA (lstr);
428
+ − 565 DWORD thread_id_unused;
+ − 566
+ − 567 s->die_p = 0;
+ − 568 s->error_p = FALSE;
+ − 569 s->hpipe = hpipe;
+ − 570 s->user_data = param;
+ − 571
+ − 572 /* Create reader thread. This could fail, so do not
+ − 573 create the event until thread is created */
+ − 574 s->hthread = CreateThread (NULL, 0, shove_thread, (LPVOID)s,
+ − 575 CREATE_SUSPENDED, &thread_id_unused);
+ − 576 if (s->hthread == NULL)
+ − 577 {
+ − 578 Lstream_delete (lstr);
+ − 579 return Qnil;
+ − 580 }
+ − 581
442
+ − 582 /* Set the priority of the thread higher so we don't end up waiting
+ − 583 on it to send things. */
+ − 584 if (!SetThreadPriority (s->hthread, THREAD_PRIORITY_HIGHEST))
+ − 585 {
+ − 586 CloseHandle (s->hthread);
+ − 587 Lstream_delete (lstr);
+ − 588 return Qnil;
+ − 589 }
+ − 590
428
+ − 591 /* hev_thread is an auto-reset event, initially nonsignaled */
771
+ − 592 s->hev_thread = qxeCreateEvent (NULL, FALSE, FALSE, NULL);
428
+ − 593
+ − 594 /* Now let it go */
+ − 595 ResumeThread (s->hthread);
+ − 596
+ − 597 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
793
+ − 598 return wrap_lstream (lstr);
428
+ − 599 }
+ − 600
+ − 601 static LPARAM
+ − 602 get_ntpipe_output_stream_param (Lstream *stream)
+ − 603 {
771
+ − 604 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
428
+ − 605 return s->user_data;
+ − 606 }
+ − 607
665
+ − 608 static Bytecount
462
+ − 609 ntpipe_shove_writer (Lstream *stream, const unsigned char *data,
665
+ − 610 Bytecount size)
428
+ − 611 {
771
+ − 612 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
428
+ − 613
+ − 614 if (s->error_p)
+ − 615 return -1;
+ − 616
+ − 617 s->blocking_p = !s->idle_p;
+ − 618 if (s->blocking_p)
+ − 619 return 0;
+ − 620
+ − 621 if (size>MAX_SHOVE_BUFFER_SIZE)
+ − 622 return 0;
+ − 623
+ − 624 memcpy (s->buffer, data, size);
+ − 625 s->size = size;
+ − 626
+ − 627 /* Start output */
+ − 628 InterlockedDecrement (&s->idle_p);
+ − 629 SetEvent (s->hev_thread);
442
+ − 630 /* Give it a chance to run -- this dramatically improves performance
+ − 631 of things like crypt. */
771
+ − 632 if (xSwitchToThread) /* not in Win9x */
442
+ − 633 (void) xSwitchToThread ();
428
+ − 634 return size;
+ − 635 }
+ − 636
+ − 637 static int
+ − 638 ntpipe_shove_was_blocked_p (Lstream *stream)
+ − 639 {
771
+ − 640 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
428
+ − 641 return s->blocking_p;
+ − 642 }
+ − 643
+ − 644 static int
+ − 645 ntpipe_shove_closer (Lstream *stream)
+ − 646 {
771
+ − 647 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
428
+ − 648
+ − 649 /* Force thread stop */
+ − 650 InterlockedIncrement (&s->die_p);
+ − 651
771
+ − 652 /* Close pipe handle, possibly breaking it */
+ − 653 CloseHandle (s->hpipe);
+ − 654
442
+ − 655 /* Thread will end upon unblocking. If it's already unblocked this will
+ − 656 do nothing, but the thread won't look at die_p until it's written any
+ − 657 pending output. */
428
+ − 658 SetEvent (s->hev_thread);
+ − 659
+ − 660 /* Wait while thread terminates */
+ − 661 WaitForSingleObject (s->hthread, INFINITE);
442
+ − 662
+ − 663 /* Close the thread handle */
428
+ − 664 CloseHandle (s->hthread);
+ − 665
+ − 666 /* Destroy the event */
+ − 667 CloseHandle (s->hev_thread);
+ − 668
+ − 669 return 0;
+ − 670 }
+ − 671
+ − 672 static void
+ − 673 init_shove_stream (void)
+ − 674 {
+ − 675 LSTREAM_HAS_METHOD (ntpipe_shove, writer);
+ − 676 LSTREAM_HAS_METHOD (ntpipe_shove, was_blocked_p);
+ − 677 LSTREAM_HAS_METHOD (ntpipe_shove, closer);
+ − 678 }
+ − 679
+ − 680 /************************************************************************/
+ − 681 /* Winsock I/O stream */
+ − 682 /************************************************************************/
+ − 683
+ − 684 #define WINSOCK_READ_BUFFER_SIZE 1024
+ − 685
+ − 686 struct winsock_stream
+ − 687 {
+ − 688 LPARAM user_data; /* Any user data stored in the stream object */
+ − 689 SOCKET s; /* Socket handle (which is a Win32 handle) */
+ − 690 OVERLAPPED ov; /* Overlapped I/O structure */
647
+ − 691 void *buffer; /* Buffer. */
+ − 692 DWORD bufsize; /* Number of bytes last read */
665
+ − 693 DWORD charbpos; /* Position in buffer for next fetch */
428
+ − 694 unsigned int error_p :1; /* I/O Error seen */
+ − 695 unsigned int eof_p :1; /* EOF Error seen */
+ − 696 unsigned int pending_p :1; /* There is a pending I/O operation */
+ − 697 unsigned int blocking_p :1; /* Last write attempt would block */
+ − 698 };
+ − 699
+ − 700 #define WINSOCK_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, winsock)
+ − 701
771
+ − 702 DEFINE_LSTREAM_IMPLEMENTATION ("winsock", winsock);
428
+ − 703
+ − 704 static void
+ − 705 winsock_initiate_read (struct winsock_stream *str)
+ − 706 {
+ − 707 ResetEvent (str->ov.hEvent);
665
+ − 708 str->charbpos = 0;
428
+ − 709
+ − 710 if (!ReadFile ((HANDLE)str->s, str->buffer, WINSOCK_READ_BUFFER_SIZE,
+ − 711 &str->bufsize, &str->ov))
+ − 712 {
+ − 713 if (GetLastError () == ERROR_IO_PENDING)
+ − 714 str->pending_p = 1;
+ − 715 else if (GetLastError () == ERROR_HANDLE_EOF)
+ − 716 str->eof_p = 1;
+ − 717 else
+ − 718 str->error_p = 1;
+ − 719 }
+ − 720 else if (str->bufsize == 0)
+ − 721 str->eof_p = 1;
+ − 722 }
+ − 723
665
+ − 724 static Bytecount
+ − 725 winsock_reader (Lstream *stream, unsigned char *data, Bytecount size)
428
+ − 726 {
+ − 727 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
+ − 728
+ − 729 /* If the current operation is not yet complete, there's nothing to
+ − 730 give back */
+ − 731 if (str->pending_p)
+ − 732 {
+ − 733 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
+ − 734 {
+ − 735 errno = EAGAIN;
+ − 736 return -1;
+ − 737 }
+ − 738 else
+ − 739 {
+ − 740 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &str->bufsize, TRUE))
+ − 741 {
+ − 742 if (GetLastError() == ERROR_HANDLE_EOF)
+ − 743 str->bufsize = 0;
+ − 744 else
+ − 745 str->error_p = 1;
+ − 746 }
+ − 747 if (str->bufsize == 0)
+ − 748 str->eof_p = 1;
+ − 749 str->pending_p = 0;
+ − 750 }
+ − 751 }
+ − 752
+ − 753 if (str->eof_p)
+ − 754 return 0;
+ − 755 if (str->error_p)
+ − 756 return -1;
+ − 757
+ − 758 /* Return as much of buffer as we have */
665
+ − 759 size = min (size, (Bytecount) (str->bufsize - str->charbpos));
771
+ − 760 memcpy (data, (void *) ((BYTE *) str->buffer + str->charbpos), size);
665
+ − 761 str->charbpos += size;
428
+ − 762
+ − 763 /* Read more if buffer is exhausted */
665
+ − 764 if (str->bufsize == str->charbpos)
428
+ − 765 winsock_initiate_read (str);
+ − 766
+ − 767 return size;
+ − 768 }
+ − 769
665
+ − 770 static Bytecount
462
+ − 771 winsock_writer (Lstream *stream, const unsigned char *data,
665
+ − 772 Bytecount size)
428
+ − 773 {
+ − 774 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
+ − 775
+ − 776 if (str->pending_p)
+ − 777 {
+ − 778 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
+ − 779 {
+ − 780 str->blocking_p = 1;
+ − 781 return -1;
+ − 782 }
+ − 783 else
+ − 784 {
+ − 785 DWORD dw_unused;
+ − 786 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &dw_unused, TRUE))
+ − 787 str->error_p = 1;
+ − 788 str->pending_p = 0;
+ − 789 }
+ − 790 }
+ − 791
+ − 792 str->blocking_p = 0;
+ − 793
+ − 794 if (str->error_p)
+ − 795 return -1;
+ − 796
+ − 797 if (size == 0)
+ − 798 return 0;
+ − 799
558
+ − 800 ResetEvent (str->ov.hEvent);
+ − 801
+ − 802 /* According to WriteFile docs, we must hold onto the data we pass to it
+ − 803 and not make any changes until it finishes -- which may not be until
+ − 804 the next time we get here, since we use asynchronous I/O. We have
+ − 805 in fact seen data loss as a result of not doing this. */
+ − 806 str->buffer = xrealloc (str->buffer, size);
+ − 807 memcpy (str->buffer, data, size);
+ − 808
560
+ − 809 /* According to MSDN WriteFile docs, the fourth parameter cannot be NULL
+ − 810 on Win95 even when doing an overlapped operation, as we are, where
+ − 811 the return value through that parameter is not meaningful. */
+ − 812 if (WriteFile ((HANDLE)str->s, str->buffer, size, &str->bufsize,
558
+ − 813 &str->ov)
+ − 814 || GetLastError() == ERROR_IO_PENDING)
+ − 815 str->pending_p = 1;
+ − 816 else
+ − 817 str->error_p = 1;
428
+ − 818
+ − 819 return str->error_p ? -1 : size;
+ − 820 }
+ − 821
+ − 822 static int
+ − 823 winsock_closer (Lstream *lstr)
+ − 824 {
+ − 825 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
+ − 826
+ − 827 if (lstr->flags & LSTREAM_FL_READ)
+ − 828 shutdown (str->s, 0);
+ − 829 else
+ − 830 shutdown (str->s, 1);
+ − 831
+ − 832 CloseHandle ((HANDLE)str->s);
+ − 833 if (str->pending_p)
+ − 834 WaitForSingleObject (str->ov.hEvent, INFINITE);
+ − 835
558
+ − 836 if (str->buffer)
560
+ − 837 {
+ − 838 xfree (str->buffer);
+ − 839 str->buffer = 0;
+ − 840 }
428
+ − 841
+ − 842 CloseHandle (str->ov.hEvent);
+ − 843 return 0;
+ − 844 }
+ − 845
+ − 846 static int
+ − 847 winsock_was_blocked_p (Lstream *stream)
+ − 848 {
+ − 849 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
+ − 850 return str->blocking_p;
+ − 851 }
+ − 852
+ − 853 static Lisp_Object
442
+ − 854 make_winsock_stream_1 (SOCKET s, LPARAM param, const char *mode)
428
+ − 855 {
+ − 856 Lstream *lstr = Lstream_new (lstream_winsock, mode);
+ − 857 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
+ − 858
558
+ − 859 xzero (*str);
428
+ − 860 str->s = s;
+ − 861 str->user_data = param;
+ − 862
771
+ − 863 str->ov.hEvent = qxeCreateEvent (NULL, TRUE, FALSE, NULL);
428
+ − 864
+ − 865 if (lstr->flags & LSTREAM_FL_READ)
+ − 866 {
+ − 867 str->buffer = xmalloc (WINSOCK_READ_BUFFER_SIZE);
+ − 868 winsock_initiate_read (str);
+ − 869 }
+ − 870
+ − 871 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
793
+ − 872 return wrap_lstream (lstr);
428
+ − 873 }
+ − 874
+ − 875 static Lisp_Object
+ − 876 make_winsock_input_stream (SOCKET s, LPARAM param)
+ − 877 {
+ − 878 return make_winsock_stream_1 (s, param, "r");
+ − 879 }
+ − 880
+ − 881 static Lisp_Object
+ − 882 make_winsock_output_stream (SOCKET s, LPARAM param)
+ − 883 {
+ − 884 return make_winsock_stream_1 (s, param, "w");
+ − 885 }
+ − 886
+ − 887 static HANDLE
+ − 888 get_winsock_stream_waitable (Lstream *lstr)
+ − 889 {
+ − 890 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
+ − 891 return str->ov.hEvent;
+ − 892 }
+ − 893
+ − 894 static LPARAM
+ − 895 get_winsock_stream_param (Lstream *lstr)
+ − 896 {
+ − 897 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
+ − 898 return str->user_data;
+ − 899 }
+ − 900
+ − 901 static void
+ − 902 init_winsock_stream (void)
+ − 903 {
+ − 904 LSTREAM_HAS_METHOD (winsock, reader);
+ − 905 LSTREAM_HAS_METHOD (winsock, writer);
+ − 906 LSTREAM_HAS_METHOD (winsock, closer);
+ − 907 LSTREAM_HAS_METHOD (winsock, was_blocked_p);
+ − 908 }
853
+ − 909 #endif /* ! CYGWIN */
428
+ − 910
+ − 911 /************************************************************************/
+ − 912 /* Dispatch queue management */
+ − 913 /************************************************************************/
+ − 914
+ − 915 static int
771
+ − 916 mswindows_user_event_p (Lisp_Event *sevt)
428
+ − 917 {
+ − 918 return (sevt->event_type == key_press_event
+ − 919 || sevt->event_type == button_press_event
+ − 920 || sevt->event_type == button_release_event
+ − 921 || sevt->event_type == misc_user_event);
+ − 922 }
+ − 923
+ − 924 /*
+ − 925 * Add an emacs event to the proper dispatch queue
+ − 926 */
442
+ − 927 void
428
+ − 928 mswindows_enqueue_dispatch_event (Lisp_Object event)
+ − 929 {
+ − 930 int user_p = mswindows_user_event_p (XEVENT(event));
+ − 931 enqueue_event (event,
+ − 932 user_p ? &mswindows_u_dispatch_event_queue :
442
+ − 933 &mswindows_s_dispatch_event_queue,
428
+ − 934 user_p ? &mswindows_u_dispatch_event_queue_tail :
442
+ − 935 &mswindows_s_dispatch_event_queue_tail);
428
+ − 936
+ − 937 /* Avoid blocking on WaitMessage */
771
+ − 938 qxePostMessage (NULL, XM_BUMPQUEUE, 0, 0);
428
+ − 939 }
+ − 940
+ − 941 /*
+ − 942 * Add a misc-user event to the dispatch queue.
+ − 943 *
+ − 944 * Stuff it into our own dispatch queue, so we have something
+ − 945 * to return from next_event callback.
+ − 946 */
+ − 947 void
+ − 948 mswindows_enqueue_misc_user_event (Lisp_Object channel, Lisp_Object function,
+ − 949 Lisp_Object object)
+ − 950 {
+ − 951 Lisp_Object event = Fmake_event (Qnil, Qnil);
771
+ − 952 Lisp_Event *e = XEVENT (event);
428
+ − 953
+ − 954 e->event_type = misc_user_event;
+ − 955 e->channel = channel;
440
+ − 956 e->timestamp = GetTickCount ();
428
+ − 957 e->event.misc.function = function;
+ − 958 e->event.misc.object = object;
+ − 959
+ − 960 mswindows_enqueue_dispatch_event (event);
+ − 961 }
+ − 962
+ − 963 void
440
+ − 964 mswindows_enqueue_magic_event (HWND hwnd, UINT msg)
428
+ − 965 {
+ − 966 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
771
+ − 967 Lisp_Event *event = XEVENT (emacs_event);
428
+ − 968
+ − 969 event->channel = hwnd ? mswindows_find_frame (hwnd) : Qnil;
+ − 970 event->timestamp = GetMessageTime();
+ − 971 event->event_type = magic_event;
440
+ − 972 EVENT_MSWINDOWS_MAGIC_TYPE (event) = msg;
428
+ − 973
+ − 974 mswindows_enqueue_dispatch_event (emacs_event);
+ − 975 }
+ − 976
+ − 977 static void
771
+ − 978 mswindows_enqueue_process_event (Lisp_Process *p)
428
+ − 979 {
+ − 980 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
771
+ − 981 Lisp_Event *event = XEVENT (emacs_event);
793
+ − 982 Lisp_Object process = wrap_process (p);
+ − 983
428
+ − 984
+ − 985 event->event_type = process_event;
+ − 986 event->timestamp = GetTickCount ();
+ − 987 event->event.process.process = process;
+ − 988
+ − 989 mswindows_enqueue_dispatch_event (emacs_event);
+ − 990 }
+ − 991
+ − 992 static void
442
+ − 993 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT msg, POINTS where,
+ − 994 int mods, DWORD when)
428
+ − 995 {
442
+ − 996 int downp = (msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN ||
+ − 997 msg == WM_RBUTTONDOWN);
428
+ − 998
+ − 999 /* We always use last message time, because mouse button
+ − 1000 events may get delayed, and XEmacs double click
+ − 1001 recognition will fail */
+ − 1002
+ − 1003 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
771
+ − 1004 Lisp_Event *event = XEVENT (emacs_event);
442
+ − 1005
+ − 1006 mswindows_handle_sticky_modifiers (0, 0, downp, 0);
+ − 1007 event->channel = mswindows_find_frame (hwnd);
428
+ − 1008 event->timestamp = when;
+ − 1009 event->event.button.button =
440
+ − 1010 (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP) ? 1 :
+ − 1011 ((msg==WM_RBUTTONDOWN || msg==WM_RBUTTONUP) ? 3 : 2);
428
+ − 1012 event->event.button.x = where.x;
+ − 1013 event->event.button.y = where.y;
442
+ − 1014 event->event.button.modifiers = mswindows_modifier_state (NULL, mods, 0);
+ − 1015
+ − 1016 if (downp)
428
+ − 1017 {
+ − 1018 event->event_type = button_press_event;
+ − 1019 SetCapture (hwnd);
+ − 1020 /* we need this to make sure the main window regains the focus
+ − 1021 from control subwindows */
+ − 1022 if (GetFocus() != hwnd)
+ − 1023 {
+ − 1024 SetFocus (hwnd);
+ − 1025 mswindows_enqueue_magic_event (hwnd, WM_SETFOCUS);
+ − 1026 }
+ − 1027 }
+ − 1028 else
+ − 1029 {
+ − 1030 event->event_type = button_release_event;
+ − 1031 ReleaseCapture ();
+ − 1032 }
+ − 1033
+ − 1034 mswindows_enqueue_dispatch_event (emacs_event);
+ − 1035 }
+ − 1036
771
+ − 1037 static Lisp_Object
428
+ − 1038 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
+ − 1039 {
+ − 1040 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
771
+ − 1041 Lisp_Event *event = XEVENT(emacs_event);
428
+ − 1042
+ − 1043 event->channel = mswindows_find_console(hwnd);
+ − 1044 event->timestamp = GetMessageTime();
+ − 1045 event->event_type = key_press_event;
+ − 1046 event->event.key.keysym = keysym;
+ − 1047 event->event.key.modifiers = mods;
+ − 1048 mswindows_enqueue_dispatch_event (emacs_event);
771
+ − 1049 return emacs_event;
428
+ − 1050 }
+ − 1051
+ − 1052 /*
+ − 1053 * Remove and return the first emacs event on the dispatch queue.
+ − 1054 * Give a preference to user events over non-user ones.
+ − 1055 */
+ − 1056 static Lisp_Object
442
+ − 1057 mswindows_dequeue_dispatch_event (void)
428
+ − 1058 {
+ − 1059 Lisp_Object event;
771
+ − 1060 Lisp_Event *sevt;
428
+ − 1061
+ − 1062 assert (!NILP(mswindows_u_dispatch_event_queue) ||
+ − 1063 !NILP(mswindows_s_dispatch_event_queue));
+ − 1064
+ − 1065 event = dequeue_event (
442
+ − 1066 NILP(mswindows_u_dispatch_event_queue) ?
428
+ − 1067 &mswindows_s_dispatch_event_queue :
+ − 1068 &mswindows_u_dispatch_event_queue,
442
+ − 1069 NILP(mswindows_u_dispatch_event_queue) ?
428
+ − 1070 &mswindows_s_dispatch_event_queue_tail :
+ − 1071 &mswindows_u_dispatch_event_queue_tail);
+ − 1072
593
+ − 1073 sevt = XEVENT (event);
428
+ − 1074 if (sevt->event_type == key_press_event
+ − 1075 && (sevt->event.key.modifiers & FAKE_MOD_QUIT))
593
+ − 1076 sevt->event.key.modifiers &=
+ − 1077 ~(FAKE_MOD_QUIT | FAKE_MOD_QUIT_CRITICAL);
428
+ − 1078
+ − 1079 return event;
+ − 1080 }
+ − 1081
+ − 1082 /*
+ − 1083 * Remove and return the first emacs event on the dispatch queue that matches
+ − 1084 * the supplied event.
+ − 1085 * Timeout event matches if interval_id is equal to that of the given event.
+ − 1086 * Keypress event matches if logical AND between modifiers bitmask of the
+ − 1087 * event in the queue and that of the given event is non-zero.
+ − 1088 * For all other event types, this function aborts.
+ − 1089 */
+ − 1090
+ − 1091 Lisp_Object
440
+ − 1092 mswindows_cancel_dispatch_event (Lisp_Event *match)
428
+ − 1093 {
+ − 1094 Lisp_Object event;
+ − 1095 Lisp_Object previous_event = Qnil;
+ − 1096 int user_p = mswindows_user_event_p (match);
771
+ − 1097 Lisp_Object *head = user_p ? &mswindows_u_dispatch_event_queue :
442
+ − 1098 &mswindows_s_dispatch_event_queue;
771
+ − 1099 Lisp_Object *tail = user_p ? &mswindows_u_dispatch_event_queue_tail :
442
+ − 1100 &mswindows_s_dispatch_event_queue_tail;
428
+ − 1101
+ − 1102 assert (match->event_type == timeout_event
+ − 1103 || match->event_type == key_press_event);
+ − 1104
+ − 1105 EVENT_CHAIN_LOOP (event, *head)
+ − 1106 {
440
+ − 1107 Lisp_Event *e = XEVENT (event);
428
+ − 1108 if ((e->event_type == match->event_type) &&
+ − 1109 ((e->event_type == timeout_event) ?
+ − 1110 (e->event.timeout.interval_id == match->event.timeout.interval_id) :
+ − 1111 /* Must be key_press_event */
+ − 1112 ((e->event.key.modifiers & match->event.key.modifiers) != 0)))
+ − 1113 {
+ − 1114 if (NILP (previous_event))
+ − 1115 dequeue_event (head, tail);
+ − 1116 else
+ − 1117 {
+ − 1118 XSET_EVENT_NEXT (previous_event, XEVENT_NEXT (event));
+ − 1119 if (EQ (*tail, event))
+ − 1120 *tail = previous_event;
+ − 1121 }
+ − 1122
+ − 1123 return event;
+ − 1124 }
+ − 1125 previous_event = event;
+ − 1126 }
+ − 1127 return Qnil;
+ − 1128 }
+ − 1129
853
+ − 1130 #ifndef CYGWIN
428
+ − 1131 /************************************************************************/
+ − 1132 /* Waitable handles manipulation */
+ − 1133 /************************************************************************/
+ − 1134 static int
+ − 1135 find_waitable_handle (HANDLE h)
+ − 1136 {
+ − 1137 int i;
+ − 1138 for (i = 0; i < mswindows_waitable_count; ++i)
+ − 1139 if (mswindows_waitable_handles[i] == h)
+ − 1140 return i;
+ − 1141
+ − 1142 return -1;
+ − 1143 }
+ − 1144
+ − 1145 static BOOL
+ − 1146 add_waitable_handle (HANDLE h)
+ − 1147 {
+ − 1148 assert (find_waitable_handle (h) < 0);
+ − 1149 if (mswindows_waitable_count == MAX_WAITABLE)
+ − 1150 return FALSE;
+ − 1151
+ − 1152 mswindows_waitable_handles [mswindows_waitable_count++] = h;
+ − 1153 return TRUE;
+ − 1154 }
+ − 1155
+ − 1156 static void
+ − 1157 remove_waitable_handle (HANDLE h)
+ − 1158 {
+ − 1159 int ix = find_waitable_handle (h);
+ − 1160 if (ix < 0)
+ − 1161 return;
+ − 1162
+ − 1163 mswindows_waitable_handles [ix] =
+ − 1164 mswindows_waitable_handles [--mswindows_waitable_count];
+ − 1165 }
853
+ − 1166
+ − 1167 #endif /* CYGWIN */
428
+ − 1168
791
+ − 1169 /*
+ − 1170 * Given a lisp process pointer remove the corresponding process handle
+ − 1171 * from mswindows_waitable_handles if it is in it. Normally the handle is
+ − 1172 * removed when the process terminates, but if the lisp process structure
+ − 1173 * is deleted before the process terminates we must delete the process
+ − 1174 * handle since it will be invalid and will cause the wait to fail
+ − 1175 */
+ − 1176 void
+ − 1177 mswindows_unwait_process (Lisp_Process *p)
+ − 1178 {
853
+ − 1179 #ifndef CYGWIN
791
+ − 1180 remove_waitable_handle (get_nt_process_handle (p));
853
+ − 1181 #endif /* CYGWIN */
791
+ − 1182 }
+ − 1183
428
+ − 1184
+ − 1185 /************************************************************************/
+ − 1186 /* Event pump */
+ − 1187 /************************************************************************/
+ − 1188
771
+ − 1189 int
+ − 1190 mswindows_window_is_xemacs (HWND hwnd)
+ − 1191 {
+ − 1192 /* GetClassName will truncate a longer class name. By adding one
+ − 1193 extra character, we are forcing textual comparison to fail
+ − 1194 if the name is longer than XEMACS_CLASS */
+ − 1195 Extbyte class_name_buf[sizeof (XEMACS_CLASS) + 2];
+ − 1196
+ − 1197 /* Use GetClassNameA because XEMACS_CLASS is not in Unicode format. */
+ − 1198 if (!GetClassNameA (hwnd, class_name_buf, sizeof (class_name_buf) - 1))
+ − 1199 return 0;
+ − 1200
+ − 1201 return !ascii_strcasecmp (class_name_buf, XEMACS_CLASS);
+ − 1202 }
+ − 1203
853
+ − 1204 struct mswindows_protect_modal_loop
+ − 1205 {
+ − 1206 Lisp_Object (*bfun) (Lisp_Object barg);
+ − 1207 Lisp_Object barg;
+ − 1208 };
+ − 1209
428
+ − 1210 static Lisp_Object
853
+ − 1211 mswindows_protect_modal_loop_1 (void *gack)
428
+ − 1212 {
853
+ − 1213 struct mswindows_protect_modal_loop *gata =
+ − 1214 (struct mswindows_protect_modal_loop *) gack;
+ − 1215
+ − 1216 return (gata->bfun) (gata->barg);
428
+ − 1217 }
+ − 1218
+ − 1219 Lisp_Object
853
+ − 1220 mswindows_protect_modal_loop (const char *error_string,
+ − 1221 Lisp_Object (*bfun) (Lisp_Object barg),
+ − 1222 Lisp_Object barg, int flags)
428
+ − 1223 {
+ − 1224 Lisp_Object tmp;
853
+ − 1225 struct mswindows_protect_modal_loop bluh;
+ − 1226
+ − 1227 bluh.bfun = bfun;
+ − 1228 bluh.barg = barg;
428
+ − 1229
+ − 1230 ++mswindows_in_modal_loop;
853
+ − 1231 tmp = call_trapping_problems (Qevent, error_string,
+ − 1232 flags, 0,
+ − 1233 mswindows_protect_modal_loop_1, &bluh);
+ − 1234 if (UNBOUNDP (tmp))
+ − 1235 mswindows_error_caught_in_modal_loop = 1;
428
+ − 1236 --mswindows_in_modal_loop;
+ − 1237
+ − 1238 return tmp;
+ − 1239 }
+ − 1240
+ − 1241 void
+ − 1242 mswindows_unmodalize_signal_maybe (void)
+ − 1243 {
853
+ − 1244 mswindows_error_caught_in_modal_loop = 0;
428
+ − 1245 }
+ − 1246
+ − 1247 /*
+ − 1248 * This is an unsafe part of event pump, guarded by
+ − 1249 * condition_case. See mswindows_pump_outstanding_events
+ − 1250 */
+ − 1251 static Lisp_Object
+ − 1252 mswindows_unsafe_pump_events (Lisp_Object u_n_u_s_e_d)
+ − 1253 {
+ − 1254 /* This function can call lisp */
+ − 1255 Lisp_Object event = Fmake_event (Qnil, Qnil);
+ − 1256 struct gcpro gcpro1;
+ − 1257 int do_redisplay = 0;
+ − 1258 GCPRO1 (event);
+ − 1259
+ − 1260 while (detect_input_pending ())
+ − 1261 {
+ − 1262 Fnext_event (event, Qnil);
+ − 1263 Fdispatch_event (event);
+ − 1264 do_redisplay = 1;
+ − 1265 }
+ − 1266
+ − 1267 if (do_redisplay)
+ − 1268 redisplay ();
+ − 1269
+ − 1270 Fdeallocate_event (event);
+ − 1271 UNGCPRO;
+ − 1272
+ − 1273 /* Qt becomes return value of mswindows_pump_outstanding_events
+ − 1274 once we get here */
+ − 1275 return Qt;
+ − 1276 }
+ − 1277
+ − 1278 /*
+ − 1279 * This function pumps emacs events, while available, by using
+ − 1280 * next_message/dispatch_message loop. Errors are trapped around
+ − 1281 * the loop so the function always returns.
+ − 1282 *
+ − 1283 * Windows message queue is not looked into during the call,
+ − 1284 * neither are waitable handles checked. The function pumps
+ − 1285 * thus only dispatch events already queued, as well as those
+ − 1286 * resulted in dispatching thereof. This is done by setting
+ − 1287 * module local variable mswindows_in_modal_loop to nonzero.
+ − 1288 *
+ − 1289 * Return value is Qt if no errors was trapped, or Qunbound if
+ − 1290 * there was an error.
+ − 1291 *
853
+ − 1292 * In case of error, a warning is issued and the module local variable
+ − 1293 * mswindows_error_caught_in_modal_loop is set to non-zero. Thus,
+ − 1294 * Windows internal modal loops are protected against throws, which
+ − 1295 * are proven to corrupt internal Windows structures.
428
+ − 1296 *
+ − 1297 * In case of success, mswindows_error_caught_in_modal_loop is
853
+ − 1298 * assigned 0.
428
+ − 1299 *
+ − 1300 * If the value of mswindows_error_caught_in_modal_loop is not
853
+ − 1301 * zero already upon entry, the function just returns non-nil.
428
+ − 1302 * This situation means that a new event has been queued while
+ − 1303 * in cancel mode. The event will be dequeued on the next regular
+ − 1304 * call of next-event; the pump is off since error is caught.
+ − 1305 * The caller must *unconditionally* cancel modal loop if the
+ − 1306 * value returned by this function is nil. Otherwise, everything
+ − 1307 * will become frozen until the modal loop exits under normal
853
+ − 1308 * condition (scrollbar drag is released, menu closed etc.) */
428
+ − 1309 Lisp_Object
+ − 1310 mswindows_pump_outstanding_events (void)
+ − 1311 {
+ − 1312 /* This function can call lisp */
+ − 1313
+ − 1314 Lisp_Object result = Qt;
+ − 1315 struct gcpro gcpro1;
+ − 1316 GCPRO1 (result);
+ − 1317
853
+ − 1318 if (!mswindows_error_caught_in_modal_loop)
+ − 1319 result = mswindows_protect_modal_loop
+ − 1320 ("Error during event handling", mswindows_unsafe_pump_events, Qnil, 0);
428
+ − 1321 UNGCPRO;
+ − 1322 return result;
+ − 1323 }
+ − 1324
440
+ − 1325 /*
+ − 1326 * KEYBOARD_ONLY_P is set to non-zero when we are called from
+ − 1327 * QUITP, and are interesting in keyboard messages only.
+ − 1328 */
428
+ − 1329 static void
442
+ − 1330 mswindows_drain_windows_queue (void)
428
+ − 1331 {
+ − 1332 MSG msg;
440
+ − 1333
442
+ − 1334 /* should call mswindows_need_event_in_modal_loop() if in modal loop */
+ − 1335 assert (!mswindows_in_modal_loop);
+ − 1336
771
+ − 1337 while (qxePeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
428
+ − 1338 {
771
+ − 1339 #ifdef HAVE_DIALOGS
444
+ − 1340 /* Don't translate messages destined for a dialog box, this
+ − 1341 makes keyboard traversal work. I think?? */
442
+ − 1342 if (mswindows_is_dialog_msg (&msg))
+ − 1343 {
+ − 1344 mswindows_unmodalize_signal_maybe ();
+ − 1345 continue;
+ − 1346 }
771
+ − 1347 #endif /* HAVE_DIALOGS */
442
+ − 1348
+ − 1349 /* We have to translate messages that are not sent to an XEmacs
+ − 1350 frame. This is so that key presses work ok in things like
+ − 1351 edit fields. However, we *musn't* translate message for XEmacs
+ − 1352 frames as this is handled in the wnd proc.
+ − 1353 We also have to avoid generating paint magic events for windows
+ − 1354 that aren't XEmacs frames */
771
+ − 1355
+ − 1356 if (!mswindows_window_is_xemacs (msg.hwnd))
+ − 1357 TranslateMessage (&msg);
442
+ − 1358 else if (msg.message == WM_PAINT)
+ − 1359 {
771
+ − 1360 struct mswindows_frame *msframe;
+ − 1361
442
+ − 1362 /* hdc will be NULL unless this is a subwindow - in which case we
+ − 1363 shouldn't have received a paint message for it here. */
+ − 1364 assert (msg.wParam == 0);
+ − 1365
+ − 1366 /* Queue a magic event for handling when safe */
+ − 1367 msframe =
+ − 1368 FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (msg.hwnd)));
+ − 1369 if (!msframe->paint_pending)
+ − 1370 {
+ − 1371 msframe->paint_pending = 1;
+ − 1372 mswindows_enqueue_magic_event (msg.hwnd, WM_PAINT);
+ − 1373 }
+ − 1374 /* Don't dispatch. WM_PAINT is always the last message in the
+ − 1375 queue so it's OK to just return. */
+ − 1376 return;
+ − 1377 }
771
+ − 1378 qxeDispatchMessage (&msg);
428
+ − 1379 mswindows_unmodalize_signal_maybe ();
+ − 1380 }
+ − 1381 }
+ − 1382
+ − 1383 /*
+ − 1384 * This is a special flavor of the mswindows_need_event function,
+ − 1385 * used while in event pump. Actually, there is only kind of events
+ − 1386 * allowed while in event pump: a timer. An attempt to fetch any
+ − 1387 * other event leads to a deadlock, as there's no source of user input
+ − 1388 * ('cause event pump mirrors windows modal loop, which is a sole
+ − 1389 * owner of thread message queue).
+ − 1390 *
+ − 1391 * To detect this, we use a counter of active timers, and allow
+ − 1392 * fetching WM_TIMER messages. Instead of trying to fetch a WM_TIMER
+ − 1393 * which will never come when there are no pending timers, which leads
+ − 1394 * to deadlock, we simply signal an error.
487
+ − 1395 *
+ − 1396 * It might be possible to combine this with mswindows_drain_windows_queue
+ − 1397 * which fetches events when not in a modal loop. It's not clear
+ − 1398 * whether the result would be more complex than is justified.
428
+ − 1399 */
+ − 1400 static void
+ − 1401 mswindows_need_event_in_modal_loop (int badly_p)
+ − 1402 {
+ − 1403 MSG msg;
+ − 1404
+ − 1405 /* Check if already have one */
+ − 1406 if (!NILP (mswindows_u_dispatch_event_queue)
+ − 1407 || !NILP (mswindows_s_dispatch_event_queue))
+ − 1408 return;
+ − 1409
+ − 1410 /* No event is ok */
+ − 1411 if (!badly_p)
+ − 1412 return;
+ − 1413
+ − 1414 /* We do not check the _u_ queue, because timers go to _s_ */
+ − 1415 while (NILP (mswindows_s_dispatch_event_queue))
+ − 1416 {
+ − 1417 /* We'll deadlock if go waiting */
+ − 1418 if (mswindows_pending_timers_count == 0)
563
+ − 1419 invalid_operation ("Deadlock due to an attempt to call next-event in a wrong context", Qunbound);
428
+ − 1420
+ − 1421 /* Fetch and dispatch any pending timers */
771
+ − 1422 if (qxeGetMessage (&msg, NULL, WM_TIMER, WM_TIMER) > 0)
+ − 1423 qxeDispatchMessage (&msg);
428
+ − 1424 }
+ − 1425 }
+ − 1426
+ − 1427 /*
+ − 1428 * This drains the event queue and fills up two internal queues until
+ − 1429 * an event of a type specified by USER_P is retrieved.
+ − 1430 *
+ − 1431 *
+ − 1432 * Used by emacs_mswindows_event_pending_p and emacs_mswindows_next_event
+ − 1433 */
+ − 1434 static void
+ − 1435 mswindows_need_event (int badly_p)
+ − 1436 {
+ − 1437 while (NILP (mswindows_u_dispatch_event_queue)
+ − 1438 && NILP (mswindows_s_dispatch_event_queue))
+ − 1439 {
853
+ − 1440 #ifdef CYGWIN
428
+ − 1441 int i;
647
+ − 1442 int active;
428
+ − 1443 SELECT_TYPE temp_mask = input_wait_mask;
+ − 1444 EMACS_TIME sometime;
+ − 1445 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this;
+ − 1446
+ − 1447 if (badly_p)
+ − 1448 pointer_to_this = 0;
+ − 1449 else
+ − 1450 {
+ − 1451 EMACS_SET_SECS_USECS (sometime, 0, 0);
+ − 1452 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
+ − 1453 pointer_to_this = &select_time_to_block;
534
+ − 1454 if (mswindows_in_modal_loop)
+ − 1455 /* In modal loop with badly_p false, don't care about
+ − 1456 Windows events. */
+ − 1457 FD_CLR (windows_fd, &temp_mask);
428
+ − 1458 }
+ − 1459
+ − 1460 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
+ − 1461
+ − 1462 if (active == 0)
+ − 1463 {
+ − 1464 assert (!badly_p);
+ − 1465 return; /* timeout */
+ − 1466 }
+ − 1467 else if (active > 0)
+ − 1468 {
+ − 1469 if (FD_ISSET (windows_fd, &temp_mask))
+ − 1470 {
534
+ − 1471 if (mswindows_in_modal_loop)
+ − 1472 mswindows_need_event_in_modal_loop (badly_p);
+ − 1473 else
+ − 1474 mswindows_drain_windows_queue ();
428
+ − 1475 }
442
+ − 1476 else
428
+ − 1477 {
442
+ − 1478 #ifdef HAVE_TTY
+ − 1479 /* Look for a TTY event */
+ − 1480 for (i = 0; i < MAXDESC-1; i++)
428
+ − 1481 {
442
+ − 1482 /* To avoid race conditions (among other things, an infinite
+ − 1483 loop when called from Fdiscard_input()), we must return
+ − 1484 user events ahead of process events. */
+ − 1485 if (FD_ISSET (i, &temp_mask) && FD_ISSET (i, &tty_only_mask))
428
+ − 1486 {
442
+ − 1487 struct console *c = tty_find_console_from_fd (i);
+ − 1488 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
771
+ − 1489 Lisp_Event *event = XEVENT (emacs_event);
+ − 1490
442
+ − 1491 assert (c);
771
+ − 1492 if (read_event_from_tty_or_stream_desc (event, c))
442
+ − 1493 {
+ − 1494 mswindows_enqueue_dispatch_event (emacs_event);
+ − 1495 return;
+ − 1496 }
428
+ − 1497 }
+ − 1498 }
+ − 1499 #endif
442
+ − 1500 /* Look for a process event */
+ − 1501 for (i = 0; i < MAXDESC-1; i++)
428
+ − 1502 {
442
+ − 1503 if (FD_ISSET (i, &temp_mask))
428
+ − 1504 {
442
+ − 1505 if (FD_ISSET (i, &process_only_mask))
+ − 1506 {
+ − 1507 Lisp_Process *p =
+ − 1508 get_process_from_usid (FD_TO_USID(i));
+ − 1509
+ − 1510 mswindows_enqueue_process_event (p);
+ − 1511 }
+ − 1512 else
+ − 1513 {
+ − 1514 /* We might get here when a fake event came
+ − 1515 through a signal. Return a dummy event, so
+ − 1516 that a cycle of the command loop will
+ − 1517 occur. */
+ − 1518 drain_signal_event_pipe ();
+ − 1519 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
+ − 1520 }
428
+ − 1521 }
+ − 1522 }
+ − 1523 }
+ − 1524 }
771
+ − 1525 else if (active == -1)
428
+ − 1526 {
+ − 1527 if (errno != EINTR)
+ − 1528 {
+ − 1529 /* something bad happened */
+ − 1530 assert(0);
+ − 1531 }
+ − 1532 }
+ − 1533 else
+ − 1534 {
+ − 1535 assert(0);
+ − 1536 }
853
+ − 1537 #else /* not CYGWIN */
428
+ − 1538 /* Now try getting a message or process event */
647
+ − 1539 DWORD active;
487
+ − 1540 DWORD what_events;
+ − 1541 if (mswindows_in_modal_loop)
534
+ − 1542 /* In a modal loop, only look for timer events, and only if
+ − 1543 we really need one. */
+ − 1544 {
+ − 1545 if (badly_p)
+ − 1546 what_events = QS_TIMER;
+ − 1547 else
+ − 1548 what_events = 0;
+ − 1549 }
487
+ − 1550 else
534
+ − 1551 /* Look for any event */
+ − 1552 what_events = QS_ALLINPUT;
487
+ − 1553
771
+ − 1554 /*
+ − 1555 #### YUCK YUCK YUCK!!!!
+ − 1556
+ − 1557 When running under a debugger, every time I hit F12 (which for me
+ − 1558 is mapped to right-brace) I hit a breakpoint inside of Windows!
+ − 1559
+ − 1560 NTDLL! DbgBreakPoint@0 address 0x77f9eea9
+ − 1561 KERNEL32! BaseAttachComplete@4 + 41 bytes
+ − 1562 KERNEL32! BaseAttachCompleteThunk@0 + 19 bytes
+ − 1563 USER32! MsgWaitForMultipleObjectsEx@20 + 224 bytes
+ − 1564 USER32! MsgWaitForMultipleObjects@20 + 30 bytes
+ − 1565
+ − 1566 Microsoft says:
+ − 1567
+ − 1568 (Knowledge Base Q130667, PRB: F12 Causes Hard-Coded Breakpoint
+ − 1569 Exception When Debugging)
+ − 1570
+ − 1571 CAUSE
+ − 1572
+ − 1573 When the F12 key is pressed and the application in focus is being
+ − 1574 debugged, Windows NT calls a function similar to DebugBreak(),
+ − 1575 which executes a hard coded breakpoint instruction. The integrated
+ − 1576 debugger then traps the exception generated by this instruction.
+ − 1577
+ − 1578 This behavior is intentional and occurs with other debuggers such
+ − 1579 as WinDbg from the Windows 32-bit SDK.
+ − 1580
+ − 1581 RESOLUTION
+ − 1582
+ − 1583 While there is no way to disable this functionality, it doesn't
+ − 1584 affect the application that's being debugged other than to pause
+ − 1585 debugging and change focus. You can continue debugging by pressing
+ − 1586 the F5 key.
+ − 1587
+ − 1588 This can be annoying if you have an application that heavily uses
+ − 1589 the F12 key, so you may want to temporarily assign another key to
+ − 1590 handle the F12 key functionality in your program when debugging.
+ − 1591
+ − 1592 STATUS
+ − 1593
+ − 1594 This behavior is by design.
+ − 1595
+ − 1596
+ − 1597 However, elsewhere I found this:
+ − 1598
+ − 1599 UserDebuggerHotKey
+ − 1600 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug
+ − 1601
+ − 1602 Data type Range Default value
+ − 1603 REG_DWORD 0x0 - 0xFF 0x0
+ − 1604
+ − 1605 Description
+ − 1606
+ − 1607 Specifies the key that, when pressed, establishes a breakpoint in
+ − 1608 code being debugged.
+ − 1609
+ − 1610 The debugger interrupts code processing at the breakpoint so the
+ − 1611 programmer can examine a suspected problem.
+ − 1612
+ − 1613 The key specified in this value only sets a breakpoint. It does
+ − 1614 not invoke the debugger (the debugger must be running before the
+ − 1615 key is pressed) and it does not switch the debugger to single-step
+ − 1616 mode.
+ − 1617
+ − 1618 The value of this entry is a keyboard scan code. The default
+ − 1619 value, 0x0, represents the F12 key on a 101-key keyboard or the -
+ − 1620 (hyphen, VK_SUBTRACT) key on an 82-key keyboard.
+ − 1621 */
+ − 1622
853
+ − 1623 __try
+ − 1624 {
923
+ − 1625 /* This fixes a long outstanding bug, where XEmacs would occasionally
+ − 1626 * not redraw its window (or process other events) until "something
+ − 1627 * happened" - usually the mouse moving over a frame.
+ − 1628 *
+ − 1629 * The problem is that MsgWaitForMultipleObjects only checks to see
+ − 1630 * if NEW messages have been placed into the thread queue. So we
+ − 1631 * specifically check to see if the queue is empty (using PeekMessage
+ − 1632 * with the PM_NOREMOVE flag) before we wait.
+ − 1633 */
+ − 1634 MSG msg;
+ − 1635 if (what_events == QS_ALLINPUT && badly_p &&
+ − 1636 qxePeekMessage (&msg, 0, 0, 0, PM_NOREMOVE))
+ − 1637 active = WAIT_OBJECT_0 + mswindows_waitable_count;
+ − 1638 else
+ − 1639 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
+ − 1640 mswindows_waitable_handles,
+ − 1641 FALSE, badly_p ? INFINITE : 0,
+ − 1642 what_events);
853
+ − 1643 }
+ − 1644 __except (GetExceptionCode () == EXCEPTION_BREAKPOINT ?
+ − 1645 EXCEPTION_CONTINUE_EXECUTION :
+ − 1646 EXCEPTION_CONTINUE_SEARCH)
+ − 1647 {
+ − 1648 }
442
+ − 1649
+ − 1650 /* This will assert if handle being waited for becomes abandoned.
+ − 1651 Not the case currently tho */
+ − 1652 assert ((!badly_p && active == WAIT_TIMEOUT) ||
+ − 1653 (active >= WAIT_OBJECT_0 &&
+ − 1654 active <= WAIT_OBJECT_0 + mswindows_waitable_count));
+ − 1655
+ − 1656 if (active == WAIT_TIMEOUT)
+ − 1657 {
+ − 1658 /* No luck trying - just return what we've already got */
+ − 1659 return;
+ − 1660 }
+ − 1661 else if (active == WAIT_OBJECT_0 + mswindows_waitable_count)
+ − 1662 {
+ − 1663 /* Got your message, thanks */
534
+ − 1664 if (mswindows_in_modal_loop)
+ − 1665 mswindows_need_event_in_modal_loop (badly_p);
+ − 1666 else
+ − 1667 mswindows_drain_windows_queue ();
442
+ − 1668 }
+ − 1669 else
+ − 1670 {
+ − 1671 int ix = active - WAIT_OBJECT_0;
+ − 1672 /* First, try to find which process' output has signaled */
+ − 1673 Lisp_Process *p =
853
+ − 1674 get_process_from_usid (HANDLE_TO_USID
+ − 1675 (mswindows_waitable_handles[ix]));
442
+ − 1676 if (p != NULL)
+ − 1677 {
+ − 1678 /* Found a signaled process input handle */
+ − 1679 mswindows_enqueue_process_event (p);
+ − 1680 }
+ − 1681 else
+ − 1682 {
+ − 1683 /* None. This means that the process handle itself has signaled.
+ − 1684 Remove the handle from the wait vector, and make status_notify
534
+ − 1685 note the exited process. First find the process object if
+ − 1686 possible. */
+ − 1687 LIST_LOOP_3 (vaffanculo, Vprocess_list, vproctail)
+ − 1688 if (get_nt_process_handle (XPROCESS (vaffanculo)) ==
+ − 1689 mswindows_waitable_handles [ix])
+ − 1690 break;
442
+ − 1691 mswindows_waitable_handles [ix] =
+ − 1692 mswindows_waitable_handles [--mswindows_waitable_count];
+ − 1693 kick_status_notify ();
+ − 1694 /* We need to return a process event here so that
+ − 1695 (1) accept-process-output will return when called on this
+ − 1696 process, and (2) status notifications will happen in
+ − 1697 accept-process-output, sleep-for, and sit-for. */
534
+ − 1698 if (!NILP (vproctail))
853
+ − 1699 mswindows_enqueue_process_event (XPROCESS (vaffanculo));
+ − 1700 else
442
+ − 1701 {
853
+ − 1702 /* abort (); */
+ − 1703 /* #### FUCKME! When can this happen? I hit this abort()
+ − 1704 when I tried enabling it. */
+ − 1705 /* Have to return something: there may be no accompanying
+ − 1706 process event */
+ − 1707 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
442
+ − 1708 }
+ − 1709 }
+ − 1710 }
853
+ − 1711 #endif /* not CYGWIN */
442
+ − 1712 } /* while */
428
+ − 1713 }
+ − 1714
+ − 1715 /************************************************************************/
+ − 1716 /* Event generators */
+ − 1717 /************************************************************************/
+ − 1718
+ − 1719 /*
+ − 1720 * Callback procedure for synchronous timer messages
+ − 1721 */
+ − 1722 static void CALLBACK
+ − 1723 mswindows_wm_timer_callback (HWND hwnd, UINT umsg, UINT id_timer, DWORD dwtime)
+ − 1724 {
+ − 1725 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
440
+ − 1726 Lisp_Event *event = XEVENT (emacs_event);
428
+ − 1727
+ − 1728 if (KillTimer (NULL, id_timer))
+ − 1729 --mswindows_pending_timers_count;
+ − 1730
+ − 1731 event->channel = Qnil;
+ − 1732 event->timestamp = dwtime;
+ − 1733 event->event_type = timeout_event;
+ − 1734 event->event.timeout.interval_id = id_timer;
+ − 1735 event->event.timeout.function = Qnil;
+ − 1736 event->event.timeout.object = Qnil;
+ − 1737
+ − 1738 mswindows_enqueue_dispatch_event (emacs_event);
+ − 1739 }
+ − 1740
+ − 1741 /*
+ − 1742 * Callback procedure for dde messages
+ − 1743 *
+ − 1744 * We execute a dde Open("file") by simulating a file drop, so dde support
+ − 1745 * depends on dnd support.
+ − 1746 */
+ − 1747 #ifdef HAVE_DRAGNDROP
657
+ − 1748 extern int mswindows_dde_enable;
+ − 1749
903
+ − 1750 EXFUN(Fread_from_string, 3);
+ − 1751
+ − 1752 /* The following variables are used to maintain consistency of result and
+ − 1753 * error reporting to the client.
+ − 1754 * The basic protocol is to Execute a lisp form, and then Request one or
+ − 1755 * more of the following items: Status (1 = OK, 0 = Error), Result, or Error.
+ − 1756 * When the lisp form is queued, the dde_eval_pending flag is set to 1,
+ − 1757 * to indicate that the items are not yet available. The dde_eval_pending
+ − 1758 * flag is set to 0 when the evaluation is complete. Requests for the result
+ − 1759 * items will block while the dde_eval_pending flag is 1, to avoid clients
+ − 1760 * getting inconsistent results.
+ − 1761 */
+ − 1762 static int dde_eval_pending;
+ − 1763 static Lisp_Object dde_eval_result;
+ − 1764 static Lisp_Object dde_eval_error;
+ − 1765
+ − 1766 static Lisp_Object
+ − 1767 dde_error (Lisp_Object err, Lisp_Object obj)
+ − 1768 {
+ − 1769 dde_eval_error = err;
+ − 1770 return Qnil;
+ − 1771 }
+ − 1772
+ − 1773 /* Read lisp forms from a string. Evaluate the forms as if they were
+ − 1774 * wrapped in a progn form. Return the result of the form.
+ − 1775 */
+ − 1776 static Lisp_Object
+ − 1777 dde_eval_string (Lisp_Object str)
+ − 1778 {
+ − 1779 struct gcpro gcpro1, gcpro2;
+ − 1780 Lisp_Object args[3];
+ − 1781 Lisp_Object obj;
+ − 1782
+ − 1783 /* Heavy handed GCPROing, on the principle of it's better to be safe than
+ − 1784 * sorry...
+ − 1785 */
+ − 1786 args[0] = Qnil;
+ − 1787 args[1] = Qnil;
+ − 1788 args[2] = Qnil;
+ − 1789 GCPRO2 (args[0], str);
+ − 1790 gcpro1.nvars = 3;
+ − 1791
+ − 1792 /* Wrap the user supplied string in string "(progn ...)".
+ − 1793 * We can now just read-from-string a single form. If we
+ − 1794 * get an error, or finish before the end of the string,
+ − 1795 * we know the original string had syntax errors.
+ − 1796 */
+ − 1797 args[0] = build_string ("(progn ");
+ − 1798 args[1] = str;
+ − 1799 args[2] = build_string (")");
+ − 1800 str = Fconcat (3, args);
+ − 1801
+ − 1802 obj = Fread_from_string (str, Qnil, Qnil);
+ − 1803 UNGCPRO;
+ − 1804
+ − 1805 /* The following doesn't check that the length fits in an EMACS_INT.
+ − 1806 * This won't be a problem in reality...?
+ − 1807 *
+ − 1808 * If the read didn't get to the end of the string, we have a syntax
+ − 1809 * error in the string supplied by the user.
+ − 1810 */
+ − 1811 if (XINT (XCDR (obj)) != XSTRING_LENGTH (str))
+ − 1812 return Qnil;
+ − 1813
+ − 1814 GCPRO1 (obj);
+ − 1815 obj = Feval (XCAR (obj));
+ − 1816
+ − 1817 RETURN_UNGCPRO(obj);
+ − 1818 }
+ − 1819
+ − 1820 /* Evaluate the supplied string as a sequence of Lisp forms, wrapped in
+ − 1821 * a progn. Catch any evaluation errors. Set the evaluation status and
+ − 1822 * result variables.
+ − 1823 */
+ − 1824 static void
+ − 1825 dde_eval (Lisp_Object str)
+ − 1826 {
+ − 1827 dde_eval_error = Qnil;
+ − 1828 dde_eval_result = condition_case_1 (Qt, dde_eval_string, str,
+ − 1829 dde_error, Qnil);
+ − 1830 dde_eval_pending = 0;
+ − 1831
+ − 1832 /* Re-enable callbacks in case the client is waiting on a request */
+ − 1833 DdeEnableCallback (mswindows_dde_mlid, NULL, EC_ENABLEALL);
+ − 1834
+ − 1835 /* Post advise notifications on the result item */
+ − 1836 DdePostAdvise (mswindows_dde_mlid, mswindows_dde_topic_eval,
+ − 1837 mswindows_dde_item_result);
+ − 1838 }
+ − 1839
+ − 1840 /* A list of DDE advise tokens. Each token is an uninterned symbol,
+ − 1841 * whose value is the DDE string handle for its name (stored as a float,
+ − 1842 * as a Lisp int cannot hold a full C int).
+ − 1843 * The token's 'dde-data property is used to store data for a dde-advise.
+ − 1844 */
+ − 1845 Lisp_Object Vdde_advise_items;
+ − 1846
+ − 1847 /* The symbol 'HSZ */
+ − 1848 Lisp_Object QHSZ;
+ − 1849
+ − 1850 DEFUN("dde-alloc-advise-item", Fdde_alloc_advise_item, 0, 1, 0, /*
+ − 1851 Allocate an advise item, and return its token.
+ − 1852 */
+ − 1853 (name))
+ − 1854 {
+ − 1855 Lisp_Object token;
+ − 1856 Extbyte *str;
+ − 1857 HSZ hsz;
+ − 1858 struct gcpro gcpro1, gcpro2;
+ − 1859
+ − 1860 if (!NILP (name))
+ − 1861 CHECK_STRING (name);
+ − 1862 else
+ − 1863 {
+ − 1864 static int num = 0;
+ − 1865 char buf[20];
+ − 1866 sprintf (buf, "Tok%d", num);
+ − 1867 ++num;
+ − 1868 name = build_string (buf);
+ − 1869 }
+ − 1870
+ − 1871 token = Qnil;
+ − 1872 GCPRO2 (name, token);
+ − 1873 token = Fmake_symbol (name);
+ − 1874 TO_EXTERNAL_FORMAT (LISP_STRING, name, C_STRING_ALLOCA, str,
+ − 1875 Qmswindows_tstr);
+ − 1876 hsz = qxeDdeCreateStringHandle (mswindows_dde_mlid, str,
+ − 1877 XEUNICODE_P ? CP_WINUNICODE : CP_WINANSI);
+ − 1878
+ − 1879 Fput(token, QHSZ, make_float ((int)hsz));
+ − 1880 Vdde_advise_items = Fcons (token, Vdde_advise_items);
+ − 1881
+ − 1882 RETURN_UNGCPRO(token);
+ − 1883 }
+ − 1884
+ − 1885 DEFUN("dde-free-advise-item", Fdde_free_advise_item, 1, 1, 0, /*
+ − 1886 Free the resources associated with advise item ITEM.
+ − 1887
+ − 1888 Frees all resources allocated to allow clients to set up advise loops
+ − 1889 on ITEM. It is assumed that no active advise loops remain. However, no
+ − 1890 problems should arise if they do - it's just that we won't ever send any
+ − 1891 notifications again.
+ − 1892
+ − 1893 If the user does not free an advise item, resources will be leaked.
+ − 1894 */
+ − 1895 (item))
+ − 1896 {
+ − 1897 HSZ hsz;
+ − 1898 Lisp_Object val;
+ − 1899
+ − 1900 CHECK_SYMBOL (item);
+ − 1901 val = Fget (item, QHSZ, Qnil);
+ − 1902 if (!FLOATP (val))
+ − 1903 return Qnil;
+ − 1904 hsz = (HSZ)(int)XFLOAT_DATA (val);
+ − 1905 DdeFreeStringHandle (mswindows_dde_mlid, hsz);
+ − 1906 Vdde_advise_items = delq_no_quit (item, Vdde_advise_items);
+ − 1907 return Qnil;
+ − 1908 }
+ − 1909
+ − 1910 DEFUN("dde-advise", Fdde_advise, 2, 2, 0, /*
+ − 1911 Post a DDE advise for ITEM with associated data DATA.
+ − 1912
+ − 1913 Records the value DATA for sending back to clients waiting for
+ − 1914 notifications on DDE item ITEM in the system topic, and posts
+ − 1915 the advise transaction.
+ − 1916
+ − 1917 ITEM must be an advise token allocated using dde-alloc-advise-item.
+ − 1918 */
+ − 1919 (item, data))
+ − 1920 {
+ − 1921 HSZ hsz;
+ − 1922 Lisp_Object val;
+ − 1923
+ − 1924 CHECK_SYMBOL (item);
+ − 1925 val = Fget (item, QHSZ, Qnil);
+ − 1926 if (!FLOATP (val))
+ − 1927 return Qnil;
+ − 1928 hsz = (HSZ)(int)XFLOAT_DATA (val);
+ − 1929
+ − 1930 Fset (item, data);
+ − 1931 DdePostAdvise (mswindows_dde_mlid, mswindows_dde_topic_eval, hsz);
+ − 1932 return Qnil;
+ − 1933 }
+ − 1934
428
+ − 1935 HDDEDATA CALLBACK
+ − 1936 mswindows_dde_callback (UINT uType, UINT uFmt, HCONV hconv,
+ − 1937 HSZ hszTopic, HSZ hszItem, HDDEDATA hdata,
+ − 1938 DWORD dwData1, DWORD dwData2)
+ − 1939 {
+ − 1940 switch (uType)
+ − 1941 {
+ − 1942 case XTYP_CONNECT:
903
+ − 1943 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)
+ − 1944 || !DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval))
853
+ − 1945 return (HDDEDATA) TRUE;
+ − 1946 return (HDDEDATA) FALSE;
428
+ − 1947
+ − 1948 case XTYP_WILDCONNECT:
+ − 1949 {
903
+ − 1950 /* We support two {service,topic} pairs */
+ − 1951 HSZPAIR pairs[3] =
771
+ − 1952 {
903
+ − 1953 { mswindows_dde_service, mswindows_dde_topic_system },
+ − 1954 { mswindows_dde_service, mswindows_dde_topic_eval },
+ − 1955 { 0, 0 }
+ − 1956 };
+ − 1957
+ − 1958 if ((!hszItem
+ − 1959 || !DdeCmpStringHandles (hszItem, mswindows_dde_service)) &&
+ − 1960 (!hszTopic
+ − 1961 || !DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)
+ − 1962 || !DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval)))
853
+ − 1963 return (DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE) pairs,
428
+ − 1964 sizeof (pairs), 0L, 0, uFmt, 0));
+ − 1965 }
853
+ − 1966 return (HDDEDATA) NULL;
428
+ − 1967
903
+ − 1968 case XTYP_ADVSTART:
+ − 1969 if (!mswindows_dde_enable)
+ − 1970 return (HDDEDATA) FALSE;
+ − 1971
+ − 1972 /* We only support advise loops on the eval topic for text data */
+ − 1973 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval)
+ − 1974 && (uFmt == CF_TEXT || uFmt == CF_UNICODETEXT))
+ − 1975 {
+ − 1976 /* Only allocated items or Result, are allowed */
+ − 1977 if (!DdeCmpStringHandles (hszItem, mswindows_dde_item_result))
+ − 1978 return (HDDEDATA) TRUE;
+ − 1979
+ − 1980 {
+ − 1981 EXTERNAL_LIST_LOOP_2 (elt, Vdde_advise_items)
+ − 1982 {
+ − 1983 Lisp_Object val;
+ − 1984 HSZ hsz;
+ − 1985 if (!SYMBOLP (elt))
+ − 1986 continue;
+ − 1987 val = Fget (elt, QHSZ, Qnil);
+ − 1988 if (!FLOATP (val))
+ − 1989 continue;
+ − 1990 hsz = (HSZ) (int) XFLOAT_DATA (val);
+ − 1991 if (!DdeCmpStringHandles (hszItem, hsz))
+ − 1992 return (HDDEDATA) TRUE;
+ − 1993 }
+ − 1994 }
+ − 1995 }
+ − 1996 return (HDDEDATA) FALSE;
+ − 1997
+ − 1998 /* Both advise requests and normal requests work the same */
+ − 1999 case XTYP_ADVREQ:
+ − 2000 case XTYP_REQUEST:
+ − 2001 if (!mswindows_dde_enable)
+ − 2002 return (HDDEDATA) NULL;
+ − 2003
+ − 2004 if (DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval) != 0)
+ − 2005 return (HDDEDATA) NULL;
+ − 2006
+ − 2007 /* If this is a normal request and we're in the middle of
+ − 2008 * an Execute, block until the Execute completes.
+ − 2009 */
+ − 2010 if (dde_eval_pending && uType == XTYP_REQUEST)
+ − 2011 return (HDDEDATA) CBR_BLOCK;
+ − 2012
+ − 2013 /* We can only support requests for ANSI or Unicode text */
+ − 2014 if (uFmt != CF_TEXT && uFmt != CF_UNICODETEXT)
+ − 2015 return (HDDEDATA) NULL;
+ − 2016
+ − 2017 {
+ − 2018 Lisp_Object args[2];
+ − 2019 struct gcpro gcpro1;
+ − 2020 Lisp_Object res;
+ − 2021 Extbyte *result;
+ − 2022 DWORD bytes;
+ − 2023
+ − 2024 args[0] = Qnil;
+ − 2025 args[1] = Qnil;
+ − 2026 GCPRO1 (args[0]);
+ − 2027 gcpro1.nvars = 2;
+ − 2028
+ − 2029
+ − 2030 if (!DdeCmpStringHandles (hszItem, mswindows_dde_item_result))
+ − 2031 {
+ − 2032 if (NILP (dde_eval_error))
+ − 2033 {
+ − 2034 args[0] = build_string ("OK: %s");
+ − 2035 args[1] = dde_eval_result;
+ − 2036 }
+ − 2037 else
+ − 2038 {
+ − 2039 args[0] = build_string ("ERR: %s");
+ − 2040 args[1] = dde_eval_error;
+ − 2041 }
+ − 2042 }
+ − 2043 else
+ − 2044 {
+ − 2045 EXTERNAL_LIST_LOOP_2 (elt, Vdde_advise_items)
+ − 2046 {
+ − 2047 Lisp_Object val;
+ − 2048 HSZ hsz;
+ − 2049 if (!SYMBOLP (elt))
+ − 2050 continue;
+ − 2051 val = Fget (elt, QHSZ, Qnil);
+ − 2052 if (!FLOATP (val))
+ − 2053 continue;
+ − 2054 hsz = (HSZ) (int) XFLOAT_DATA (val);
+ − 2055 if (!DdeCmpStringHandles (hszItem, hsz))
+ − 2056 args[1] = Fsymbol_value (elt);
+ − 2057 }
+ − 2058 args[0] = build_string ("%s");
+ − 2059 }
+ − 2060
+ − 2061 res = Fformat (2, args);
+ − 2062 UNGCPRO;
+ − 2063
+ − 2064 bytes = (uFmt == CF_TEXT ? 1 : 2) * (XSTRING_LENGTH (res) + 1);
+ − 2065 TO_EXTERNAL_FORMAT (LISP_STRING, res,
+ − 2066 C_STRING_ALLOCA, result,
+ − 2067 uFmt == CF_TEXT ? Qmswindows_multibyte
+ − 2068 : Qmswindows_unicode);
+ − 2069
+ − 2070 /* If we cannot create the data handle, this passes the null
+ − 2071 * return back to the client, which signals an error as we wish.
+ − 2072 */
+ − 2073 return DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE)result,
+ − 2074 bytes, 0L, hszItem, uFmt, 0);
+ − 2075 }
+ − 2076
428
+ − 2077 case XTYP_EXECUTE:
657
+ − 2078 if (!mswindows_dde_enable)
+ − 2079 return (HDDEDATA) DDE_FBUSY;
+ − 2080
903
+ − 2081 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval))
+ − 2082 {
+ − 2083 DWORD len;
+ − 2084 LPBYTE extcmd;
+ − 2085 Lisp_Object tmp;
+ − 2086
+ − 2087 /* Grab a pointer to the raw data supplied */
+ − 2088 extcmd = DdeAccessData (hdata, &len);
+ − 2089
+ − 2090 TO_INTERNAL_FORMAT (DATA, (extcmd, len),
+ − 2091 LISP_STRING, tmp,
+ − 2092 Qmswindows_tstr);
+ − 2093
+ − 2094 /* Release and free the data handle */
+ − 2095 DdeUnaccessData (hdata);
+ − 2096 DdeFreeDataHandle (hdata);
+ − 2097
+ − 2098 /* Set a flag to say that the evaluation isn't yet complete,
+ − 2099 * enqueue the evaluation, send a dummy event to trigger the
+ − 2100 * event loop (I've no idea why this is needed, but it works...)
+ − 2101 * and return success to the client.
+ − 2102 */
+ − 2103 dde_eval_pending = 1;
+ − 2104 enqueue_magic_eval_event (dde_eval, tmp);
+ − 2105 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
+ − 2106 return (HDDEDATA) DDE_FACK;
+ − 2107 }
+ − 2108 else if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
428
+ − 2109 {
+ − 2110 DWORD len = DdeGetData (hdata, NULL, 0, 0);
853
+ − 2111 LPBYTE extcmd = (LPBYTE) ALLOCA (len + 1);
867
+ − 2112 Ibyte *cmd;
+ − 2113 Ibyte *end;
428
+ − 2114 struct gcpro gcpro1, gcpro2;
657
+ − 2115 Lisp_Object l_dndlist = Qnil;
428
+ − 2116 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
+ − 2117 Lisp_Object frmcons, devcons, concons;
440
+ − 2118 Lisp_Event *event = XEVENT (emacs_event);
428
+ − 2119
771
+ − 2120 DdeGetData (hdata, extcmd, len, 0);
428
+ − 2121 DdeFreeDataHandle (hdata);
+ − 2122
771
+ − 2123 TO_INTERNAL_FORMAT (DATA, (extcmd, len),
+ − 2124 C_STRING_ALLOCA, cmd,
+ − 2125 Qmswindows_tstr);
+ − 2126
428
+ − 2127 /* Check syntax & that it's an [Open("foo")] command, which we
+ − 2128 * treat like a file drop */
+ − 2129 if (*cmd == '[')
+ − 2130 cmd++;
771
+ − 2131 if (qxestrncasecmp_c (cmd, MSWINDOWS_DDE_ITEM_OPEN,
+ − 2132 strlen (MSWINDOWS_DDE_ITEM_OPEN)))
428
+ − 2133 return DDE_FNOTPROCESSED;
+ − 2134 cmd += strlen (MSWINDOWS_DDE_ITEM_OPEN);
771
+ − 2135 while (*cmd == ' ')
428
+ − 2136 cmd++;
771
+ − 2137 if (*cmd != '(' || *(cmd + 1) != '\"')
428
+ − 2138 return DDE_FNOTPROCESSED;
771
+ − 2139 end = (cmd += 2);
+ − 2140 while (*end && *end != '\"')
428
+ − 2141 end++;
+ − 2142 if (!*end)
+ − 2143 return DDE_FNOTPROCESSED;
+ − 2144 *end = '\0';
771
+ − 2145 if (*++end != ')')
428
+ − 2146 return DDE_FNOTPROCESSED;
771
+ − 2147 if (*++end == ']')
428
+ − 2148 end++;
+ − 2149 if (*end)
+ − 2150 return DDE_FNOTPROCESSED;
+ − 2151
771
+ − 2152 {
+ − 2153 /* The drag-n-drop code in dragdrop.el expects pseudo-URL's,
+ − 2154 consisting of just file: followed by the filename. This
+ − 2155 should maybe work, but both Netscape and IE complain
+ − 2156 whenever they're not given the full file spec, like
+ − 2157
+ − 2158 file:///C|/foo/bar/ or equivalently
+ − 2159 file:///C:/foo/bar/ (less portably)
+ − 2160
+ − 2161 they don't allow relative paths at all! this is way bogus. */
+ − 2162 cmd = urlify_filename (cmd);
+ − 2163 l_dndlist = build_intstring (cmd);
+ − 2164 xfree (cmd);
+ − 2165 }
428
+ − 2166 GCPRO2 (emacs_event, l_dndlist);
+ − 2167
+ − 2168 /* Find a mswindows frame */
+ − 2169 event->channel = Qnil;
+ − 2170 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
+ − 2171 {
+ − 2172 Lisp_Object frame = XCAR (frmcons);
+ − 2173 if (FRAME_TYPE_P (XFRAME (frame), mswindows))
+ − 2174 event->channel = frame;
+ − 2175 };
+ − 2176 assert (!NILP (event->channel));
+ − 2177
+ − 2178 event->timestamp = GetTickCount();
+ − 2179 event->event_type = misc_user_event;
+ − 2180 event->event.misc.button = 1;
+ − 2181 event->event.misc.modifiers = 0;
+ − 2182 event->event.misc.x = -1;
+ − 2183 event->event.misc.y = -1;
+ − 2184 event->event.misc.function = Qdragdrop_drop_dispatch;
+ − 2185 event->event.misc.object = Fcons (Qdragdrop_URL,
+ − 2186 Fcons (l_dndlist, Qnil));
+ − 2187 mswindows_enqueue_dispatch_event (emacs_event);
+ − 2188 UNGCPRO;
+ − 2189 return (HDDEDATA) DDE_FACK;
+ − 2190 }
+ − 2191 DdeFreeDataHandle (hdata);
+ − 2192 return (HDDEDATA) DDE_FNOTPROCESSED;
+ − 2193
+ − 2194 default:
+ − 2195 return (HDDEDATA) NULL;
+ − 2196 }
+ − 2197 }
+ − 2198 #endif
+ − 2199
+ − 2200 /*
442
+ − 2201 * Helper to do repainting - repaints can happen both from the windows
+ − 2202 * procedure and from magic events
+ − 2203 */
+ − 2204 static void
+ − 2205 mswindows_handle_paint (struct frame *frame)
+ − 2206 {
+ − 2207 HWND hwnd = FRAME_MSWINDOWS_HANDLE (frame);
+ − 2208
+ − 2209 /* According to the docs we need to check GetUpdateRect() before
+ − 2210 actually doing a WM_PAINT */
+ − 2211 if (GetUpdateRect (hwnd, NULL, FALSE))
+ − 2212 {
+ − 2213 PAINTSTRUCT paintStruct;
+ − 2214 int x, y, width, height;
+ − 2215
+ − 2216 BeginPaint (hwnd, &paintStruct);
+ − 2217 x = paintStruct.rcPaint.left;
+ − 2218 y = paintStruct.rcPaint.top;
+ − 2219 width = paintStruct.rcPaint.right - paintStruct.rcPaint.left;
+ − 2220 height = paintStruct.rcPaint.bottom - paintStruct.rcPaint.top;
+ − 2221 /* Normally we want to ignore expose events when child
+ − 2222 windows are unmapped, however once we are in the guts of
+ − 2223 WM_PAINT we need to make sure that we don't register
+ − 2224 unmaps then because they will not actually occur. */
+ − 2225 /* #### commenting out the next line seems to fix some problems
+ − 2226 but not all. only andy currently understands this stuff and
+ − 2227 he needs to review it more carefully. --ben */
+ − 2228 if (!check_for_ignored_expose (frame, x, y, width, height))
+ − 2229 {
+ − 2230 hold_ignored_expose_registration = 1;
+ − 2231 mswindows_redraw_exposed_area (frame, x, y, width, height);
+ − 2232 hold_ignored_expose_registration = 0;
+ − 2233 }
+ − 2234 EndPaint (hwnd, &paintStruct);
+ − 2235 }
+ − 2236 }
+ − 2237
+ − 2238 /*
+ − 2239 * Returns 1 if a key is a real modifier or special key, which
440
+ − 2240 * is better handled by DefWindowProc
+ − 2241 */
+ − 2242 static int
+ − 2243 key_needs_default_processing_p (UINT vkey)
+ − 2244 {
442
+ − 2245 if (mswindows_alt_by_itself_activates_menu && vkey == VK_MENU
+ − 2246 /* if we let ALT activate the menu like this, then sticky ALT-modified
+ − 2247 keystrokes become impossible. */
+ − 2248 && !modifier_keys_are_sticky)
440
+ − 2249 return 1;
+ − 2250
+ − 2251 return 0;
+ − 2252 }
+ − 2253
442
+ − 2254 /* key-handling code is always ugly. It just ends up working out
+ − 2255 that way.
+ − 2256
+ − 2257 #### Most of the sticky-modifier code below is copied from similar
+ − 2258 code in event-Xt.c. They should somehow or other be merged.
+ − 2259
+ − 2260 Here are some pointers:
+ − 2261
+ − 2262 -- DOWN_MASK indicates which modifiers should be treated as "down"
+ − 2263 when the corresponding upstroke happens. It gets reset for
+ − 2264 a particular modifier when that modifier goes up, and reset
+ − 2265 for all modifiers when a non-modifier key is pressed. Example:
+ − 2266
+ − 2267 I press Control-A-Shift and then release Control-A-Shift.
+ − 2268 I want the Shift key to be sticky but not the Control key.
+ − 2269
+ − 2270 -- If a modifier key is sticky, I can unstick it by pressing
+ − 2271 the modifier key again. */
+ − 2272
+ − 2273 static WPARAM last_downkey;
+ − 2274 static int need_to_add_mask, down_mask;
+ − 2275
+ − 2276 #define XEMSW_LCONTROL (1<<0)
+ − 2277 #define XEMSW_RCONTROL (1<<1)
+ − 2278 #define XEMSW_LSHIFT (1<<2)
+ − 2279 #define XEMSW_RSHIFT (1<<3)
+ − 2280 #define XEMSW_LMENU (1<<4)
+ − 2281 #define XEMSW_RMENU (1<<5)
+ − 2282
+ − 2283 static int
+ − 2284 mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam,
+ − 2285 int downp, int keyp)
+ − 2286 {
+ − 2287 int mods = 0;
+ − 2288
+ − 2289 if (!modifier_keys_are_sticky) /* Optimize for non-sticky modifiers */
+ − 2290 return 0;
+ − 2291
+ − 2292 if (! (keyp &&
+ − 2293 (wParam == VK_CONTROL || wParam == VK_LCONTROL ||
+ − 2294 wParam == VK_RCONTROL ||
+ − 2295 wParam == VK_MENU || wParam == VK_LMENU ||
+ − 2296 wParam == VK_RMENU ||
+ − 2297 wParam == VK_SHIFT || wParam == VK_LSHIFT ||
+ − 2298 wParam == VK_RSHIFT)))
+ − 2299 { /* Not a modifier key */
+ − 2300 if (downp && keyp && !last_downkey)
+ − 2301 last_downkey = wParam;
+ − 2302 /* If I hold press-and-release the Control key and then press
+ − 2303 and hold down the right arrow, I want it to auto-repeat
+ − 2304 Control-Right. On the other hand, if I do the same but
+ − 2305 manually press the Right arrow a bunch of times, I want
+ − 2306 to see one Control-Right and then a bunch of Rights.
+ − 2307 This means that we need to distinguish between an
+ − 2308 auto-repeated key and a key pressed and released a bunch
+ − 2309 of times. */
+ − 2310 else if ((downp && !keyp) ||
+ − 2311 (downp && keyp && last_downkey &&
+ − 2312 (wParam != last_downkey ||
+ − 2313 /* the "previous key state" bit indicates autorepeat */
+ − 2314 ! (lParam & (1 << 30)))))
+ − 2315 {
+ − 2316 need_to_add_mask = 0;
+ − 2317 last_downkey = 0;
+ − 2318 }
+ − 2319 if (downp)
+ − 2320 down_mask = 0;
+ − 2321
+ − 2322 mods = need_to_add_mask;
+ − 2323 }
+ − 2324 else /* Modifier key pressed */
+ − 2325 {
+ − 2326 /* If a non-modifier key was pressed in the middle of a bunch
+ − 2327 of modifiers, then it unsticks all the modifiers that were
+ − 2328 previously pressed. We cannot unstick the modifiers until
+ − 2329 now because we want to check for auto-repeat of the
+ − 2330 non-modifier key. */
+ − 2331
+ − 2332 if (last_downkey)
+ − 2333 {
+ − 2334 last_downkey = 0;
+ − 2335 need_to_add_mask = 0;
+ − 2336 }
+ − 2337
+ − 2338 #define FROB(mask) \
+ − 2339 do { \
+ − 2340 if (downp && keyp) \
+ − 2341 { \
+ − 2342 /* If modifier key is already sticky, \
+ − 2343 then unstick it. Note that we do \
+ − 2344 not test down_mask to deal with the \
+ − 2345 unlikely but possible case that the \
+ − 2346 modifier key auto-repeats. */ \
+ − 2347 if (need_to_add_mask & mask) \
+ − 2348 { \
+ − 2349 need_to_add_mask &= ~mask; \
+ − 2350 down_mask &= ~mask; \
+ − 2351 } \
+ − 2352 else \
+ − 2353 down_mask |= mask; \
+ − 2354 } \
+ − 2355 else \
+ − 2356 { \
+ − 2357 if (down_mask & mask) \
+ − 2358 { \
+ − 2359 down_mask &= ~mask; \
+ − 2360 need_to_add_mask |= mask; \
+ − 2361 } \
+ − 2362 } \
+ − 2363 } while (0)
+ − 2364
+ − 2365 if ((wParam == VK_CONTROL && (lParam & 0x1000000))
+ − 2366 || wParam == VK_RCONTROL)
+ − 2367 FROB (XEMSW_RCONTROL);
+ − 2368 if ((wParam == VK_CONTROL && !(lParam & 0x1000000))
+ − 2369 || wParam == VK_LCONTROL)
+ − 2370 FROB (XEMSW_LCONTROL);
+ − 2371
+ − 2372 if ((wParam == VK_SHIFT && (lParam & 0x1000000))
+ − 2373 || wParam == VK_RSHIFT)
+ − 2374 FROB (XEMSW_RSHIFT);
+ − 2375 if ((wParam == VK_SHIFT && !(lParam & 0x1000000))
+ − 2376 || wParam == VK_LSHIFT)
+ − 2377 FROB (XEMSW_LSHIFT);
+ − 2378
+ − 2379 if ((wParam == VK_MENU && (lParam & 0x1000000))
+ − 2380 || wParam == VK_RMENU)
+ − 2381 FROB (XEMSW_RMENU);
+ − 2382 if ((wParam == VK_MENU && !(lParam & 0x1000000))
+ − 2383 || wParam == VK_LMENU)
+ − 2384 FROB (XEMSW_LMENU);
+ − 2385 }
+ − 2386 #undef FROB
+ − 2387
+ − 2388 if (mods && downp)
+ − 2389 {
+ − 2390 BYTE keymap[256];
+ − 2391
+ − 2392 GetKeyboardState (keymap);
+ − 2393
+ − 2394 if (mods & XEMSW_LCONTROL)
+ − 2395 {
+ − 2396 keymap [VK_CONTROL] |= 0x80;
+ − 2397 keymap [VK_LCONTROL] |= 0x80;
+ − 2398 }
+ − 2399 if (mods & XEMSW_RCONTROL)
+ − 2400 {
+ − 2401 keymap [VK_CONTROL] |= 0x80;
+ − 2402 keymap [VK_RCONTROL] |= 0x80;
+ − 2403 }
+ − 2404
+ − 2405 if (mods & XEMSW_LSHIFT)
+ − 2406 {
+ − 2407 keymap [VK_SHIFT] |= 0x80;
+ − 2408 keymap [VK_LSHIFT] |= 0x80;
+ − 2409 }
+ − 2410 if (mods & XEMSW_RSHIFT)
+ − 2411 {
+ − 2412 keymap [VK_SHIFT] |= 0x80;
+ − 2413 keymap [VK_RSHIFT] |= 0x80;
+ − 2414 }
+ − 2415
+ − 2416 if (mods & XEMSW_LMENU)
+ − 2417 {
+ − 2418 keymap [VK_MENU] |= 0x80;
+ − 2419 keymap [VK_LMENU] |= 0x80;
+ − 2420 }
+ − 2421 if (mods & XEMSW_RMENU)
+ − 2422 {
+ − 2423 keymap [VK_MENU] |= 0x80;
+ − 2424 keymap [VK_RMENU] |= 0x80;
+ − 2425 }
+ − 2426
+ − 2427 SetKeyboardState (keymap);
+ − 2428 return 1;
+ − 2429 }
+ − 2430
+ − 2431 return 0;
+ − 2432 }
+ − 2433
+ − 2434 static void
+ − 2435 clear_sticky_modifiers (void)
+ − 2436 {
+ − 2437 need_to_add_mask = 0;
+ − 2438 last_downkey = 0;
+ − 2439 down_mask = 0;
+ − 2440 }
+ − 2441
+ − 2442 #ifdef DEBUG_XEMACS
+ − 2443
+ − 2444 #if 0
+ − 2445
+ − 2446 static void
+ − 2447 output_modifier_keyboard_state (void)
+ − 2448 {
+ − 2449 BYTE keymap[256];
+ − 2450
+ − 2451 GetKeyboardState (keymap);
+ − 2452
+ − 2453 stderr_out ("GetKeyboardState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
+ − 2454 keymap[VK_MENU] & 0x80 ? 1 : 0,
+ − 2455 keymap[VK_MENU] & 0x1 ? 1 : 0,
+ − 2456 keymap[VK_LMENU] & 0x80 ? 1 : 0,
+ − 2457 keymap[VK_LMENU] & 0x1 ? 1 : 0,
+ − 2458 keymap[VK_RMENU] & 0x80 ? 1 : 0,
+ − 2459 keymap[VK_RMENU] & 0x1 ? 1 : 0);
+ − 2460 stderr_out ("GetKeyboardState VK_CONTROL %d %d VK_LCONTROL %d %d VK_RCONTROL %d %d\n",
+ − 2461 keymap[VK_CONTROL] & 0x80 ? 1 : 0,
+ − 2462 keymap[VK_CONTROL] & 0x1 ? 1 : 0,
+ − 2463 keymap[VK_LCONTROL] & 0x80 ? 1 : 0,
+ − 2464 keymap[VK_LCONTROL] & 0x1 ? 1 : 0,
+ − 2465 keymap[VK_RCONTROL] & 0x80 ? 1 : 0,
+ − 2466 keymap[VK_RCONTROL] & 0x1 ? 1 : 0);
+ − 2467 stderr_out ("GetKeyboardState VK_SHIFT %d %d VK_LSHIFT %d %d VK_RSHIFT %d %d\n",
+ − 2468 keymap[VK_SHIFT] & 0x80 ? 1 : 0,
+ − 2469 keymap[VK_SHIFT] & 0x1 ? 1 : 0,
+ − 2470 keymap[VK_LSHIFT] & 0x80 ? 1 : 0,
+ − 2471 keymap[VK_LSHIFT] & 0x1 ? 1 : 0,
+ − 2472 keymap[VK_RSHIFT] & 0x80 ? 1 : 0,
+ − 2473 keymap[VK_RSHIFT] & 0x1 ? 1 : 0);
+ − 2474 }
+ − 2475
+ − 2476 #endif
+ − 2477
+ − 2478 /* try to debug the stuck-alt-key problem.
+ − 2479
+ − 2480 #### this happens only inconsistently, and may only happen when using
+ − 2481 StickyKeys in the Win2000 accessibility section of the control panel,
+ − 2482 which is extremely broken for other reasons. */
+ − 2483
+ − 2484 static void
+ − 2485 output_alt_keyboard_state (void)
+ − 2486 {
+ − 2487 BYTE keymap[256];
+ − 2488 SHORT keystate[3];
+ − 2489 // SHORT asyncstate[3];
+ − 2490
+ − 2491 GetKeyboardState (keymap);
+ − 2492 keystate[0] = GetKeyState (VK_MENU);
+ − 2493 keystate[1] = GetKeyState (VK_LMENU);
+ − 2494 keystate[2] = GetKeyState (VK_RMENU);
+ − 2495 /* Doing this interferes with key processing. */
+ − 2496 /* asyncstate[0] = GetAsyncKeyState (VK_MENU); */
+ − 2497 /* asyncstate[1] = GetAsyncKeyState (VK_LMENU); */
+ − 2498 /* asyncstate[2] = GetAsyncKeyState (VK_RMENU); */
+ − 2499
+ − 2500 stderr_out ("GetKeyboardState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
+ − 2501 keymap[VK_MENU] & 0x80 ? 1 : 0,
+ − 2502 keymap[VK_MENU] & 0x1 ? 1 : 0,
+ − 2503 keymap[VK_LMENU] & 0x80 ? 1 : 0,
+ − 2504 keymap[VK_LMENU] & 0x1 ? 1 : 0,
+ − 2505 keymap[VK_RMENU] & 0x80 ? 1 : 0,
+ − 2506 keymap[VK_RMENU] & 0x1 ? 1 : 0);
+ − 2507 stderr_out ("GetKeyState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
+ − 2508 keystate[0] & 0x8000 ? 1 : 0,
+ − 2509 keystate[0] & 0x1 ? 1 : 0,
+ − 2510 keystate[1] & 0x8000 ? 1 : 0,
+ − 2511 keystate[1] & 0x1 ? 1 : 0,
+ − 2512 keystate[2] & 0x8000 ? 1 : 0,
+ − 2513 keystate[2] & 0x1 ? 1 : 0);
+ − 2514 /* stderr_out ("GetAsyncKeyState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n", */
+ − 2515 /* asyncstate[0] & 0x8000 ? 1 : 0, */
+ − 2516 /* asyncstate[0] & 0x1 ? 1 : 0, */
+ − 2517 /* asyncstate[1] & 0x8000 ? 1 : 0, */
+ − 2518 /* asyncstate[1] & 0x1 ? 1 : 0, */
+ − 2519 /* asyncstate[2] & 0x8000 ? 1 : 0, */
+ − 2520 /* asyncstate[2] & 0x1 ? 1 : 0); */
+ − 2521 }
+ − 2522
+ − 2523 #endif /* DEBUG_XEMACS */
+ − 2524
+ − 2525
440
+ − 2526 /*
428
+ − 2527 * The windows procedure for the window class XEMACS_CLASS
+ − 2528 */
+ − 2529 LRESULT WINAPI
442
+ − 2530 mswindows_wnd_proc (HWND hwnd, UINT message_, WPARAM wParam, LPARAM lParam)
428
+ − 2531 {
+ − 2532 /* Note: Remember to initialize emacs_event and event before use.
+ − 2533 This code calls code that can GC. You must GCPRO before calling such code. */
+ − 2534 Lisp_Object emacs_event = Qnil;
+ − 2535 Lisp_Object fobj = Qnil;
+ − 2536
440
+ − 2537 Lisp_Event *event;
428
+ − 2538 struct frame *frame;
647
+ − 2539 struct mswindows_frame *msframe;
428
+ − 2540
611
+ − 2541 /* If you hit this, rewrite the offending API call to occur after GC,
+ − 2542 using register_post_gc_action(). */
+ − 2543 assert (!gc_in_progress);
593
+ − 2544
+ − 2545 #ifdef DEBUG_XEMACS
+ − 2546 if (debug_mswindows_events)
+ − 2547 debug_output_mswin_message (hwnd, message_, wParam, lParam);
+ − 2548 #endif /* DEBUG_XEMACS */
442
+ − 2549
771
+ − 2550 assert (!qxeGetWindowLong (hwnd, GWL_USERDATA));
442
+ − 2551 switch (message_)
428
+ − 2552 {
442
+ − 2553 case WM_DESTROYCLIPBOARD:
771
+ − 2554 mswindows_handle_destroyclipboard ();
442
+ − 2555 break;
+ − 2556
+ − 2557 case WM_ERASEBKGND:
+ − 2558 /* Erase background only during non-dynamic sizing */
771
+ − 2559 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
442
+ − 2560 if (msframe->sizing && !mswindows_dynamic_frame_resize)
+ − 2561 goto defproc;
+ − 2562 return 1;
+ − 2563
+ − 2564 case WM_CLOSE:
+ − 2565 fobj = mswindows_find_frame (hwnd);
853
+ − 2566 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj,
+ − 2567 Qt));
440
+ − 2568 break;
428
+ − 2569
442
+ − 2570 case WM_KEYUP:
+ − 2571 case WM_SYSKEYUP:
+ − 2572
+ − 2573 /* See Win95 comment under WM_KEYDOWN */
+ − 2574 {
+ − 2575 BYTE keymap[256];
+ − 2576 int should_set_keymap = 0;
+ − 2577
+ − 2578 #ifdef DEBUG_XEMACS
593
+ − 2579 if (debug_mswindows_events > 2)
+ − 2580 output_alt_keyboard_state ();
442
+ − 2581 #endif /* DEBUG_XEMACS */
+ − 2582
+ − 2583 mswindows_handle_sticky_modifiers (wParam, lParam, 0, 1);
+ − 2584 if (wParam == VK_CONTROL)
+ − 2585 {
+ − 2586 GetKeyboardState (keymap);
+ − 2587 keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] &= ~0x80;
+ − 2588 should_set_keymap = 1;
+ − 2589 }
+ − 2590 else if (wParam == VK_MENU)
+ − 2591 {
+ − 2592 GetKeyboardState (keymap);
+ − 2593 keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] &= ~0x80;
+ − 2594 should_set_keymap = 1;
+ − 2595 }
+ − 2596
+ − 2597 if (should_set_keymap)
+ − 2598 // && (message_ != WM_SYSKEYUP
+ − 2599 // || NILP (Vmenu_accelerator_enabled)))
428
+ − 2600 SetKeyboardState (keymap);
+ − 2601
+ − 2602 }
442
+ − 2603
+ − 2604 if (key_needs_default_processing_p (wParam))
+ − 2605 goto defproc;
+ − 2606 else
+ − 2607 break;
+ − 2608
+ − 2609 case WM_KEYDOWN:
+ − 2610 case WM_SYSKEYDOWN:
+ − 2611
+ − 2612 /* In some locales the right-hand Alt key is labelled AltGr. This key
+ − 2613 * should produce alternative characters when combined with another key.
+ − 2614 * eg on a German keyboard pressing AltGr+q should produce '@'.
+ − 2615 * AltGr generates exactly the same keystrokes as LCtrl+RAlt. But if
+ − 2616 * TranslateMessage() is called with *any* combination of Ctrl+Alt down,
+ − 2617 * it translates as if AltGr were down.
+ − 2618 * We get round this by removing all modifiers from the keymap before
+ − 2619 * calling TranslateMessage() unless AltGr is *really* down. */
428
+ − 2620 {
442
+ − 2621 BYTE keymap_trans[256];
+ − 2622 BYTE keymap_orig[256];
+ − 2623 BYTE keymap_sticky[256];
771
+ − 2624 /* WARNING: XEmacs code paths are far more subtle than you
+ − 2625 think. In particular, QUIT checking will query and remove
+ − 2626 events, including keyboard events, from the queue. (QUIT is
+ − 2627 definitely invoked from TO_INTERNAL_FORMAT().) If we do
+ − 2628 this recursively anywhere in the following code, it will
+ − 2629 mess certain things up -- in particular, the OS-provided
+ − 2630 sticky modifier code available as part of the accessibility
+ − 2631 package.
+ − 2632
+ − 2633 (Academic question: If QUIT checking is supposed to be
+ − 2634 triggered only every 1/4 second, why is it getting
+ − 2635 consistently triggered here? I saw the problem
+ − 2636 consistently. Answer: It appears that, currently,
+ − 2637 sometimes the code to pump messages is wrapped with
+ − 2638 begin_dont_check_for_quit() and sometimes it isn't. (####
+ − 2639 FIX THIS SHIT!) cmdloop.c, for example, has it, but not
+ − 2640 everywhere. The current games with avoiding QUIT mean that
+ − 2641 the 1/4-second timer consistently fires while
+ − 2642 dont_check_for_quit is set [which causes the quit check to
+ − 2643 get deferred but the flag is still on], and so the next
+ − 2644 time it's unset and we call QUIT is *right here*.
+ − 2645
+ − 2646 In my stderr-proc ws I majorly cleaned up the whole shit by
+ − 2647 just wrapping all the entry points in dont_check_for_quit.
+ − 2648 This fixed the remaining bugs with C-g getting interpreted
+ − 2649 wrong.)
+ − 2650
+ − 2651 #### We should probably wrap this whole function in
+ − 2652 begin_dont_check_for_quit(); but then we should set this
+ − 2653 back to 0 when handling a menu callback, which gets invoked
+ − 2654 from within this function, specifically from
+ − 2655 DefWindowProc(). (We already do the latter in my new
+ − 2656 stderr-proc ws, because in that ws next_event_internal()
+ − 2657 calls begin_dont_check_for_quit(). */
+ − 2658
+ − 2659 int count = begin_dont_check_for_quit ();
442
+ − 2660 int has_AltGr = mswindows_current_layout_has_AltGr ();
502
+ − 2661 int mods = 0, mods_with_shift = 0;
442
+ − 2662 int extendedp = lParam & 0x1000000;
+ − 2663 Lisp_Object keysym;
+ − 2664 int sticky_changed;
+ − 2665
+ − 2666 #ifdef DEBUG_XEMACS
593
+ − 2667 if (debug_mswindows_events > 2)
+ − 2668 output_alt_keyboard_state ();
442
+ − 2669 #endif /* DEBUG_XEMACS */
+ − 2670
+ − 2671 GetKeyboardState (keymap_orig);
+ − 2672 frame = XFRAME (mswindows_find_frame (hwnd));
+ − 2673 if ((sticky_changed =
+ − 2674 mswindows_handle_sticky_modifiers (wParam, lParam, 1, 1)))
428
+ − 2675 {
442
+ − 2676 GetKeyboardState (keymap_sticky);
+ − 2677 if (keymap_sticky[VK_MENU] & 0x80)
+ − 2678 {
+ − 2679 message_ = WM_SYSKEYDOWN;
+ − 2680 /* We have to set the "context bit" so that the
+ − 2681 TranslateMessage() call below that generates the
+ − 2682 SYSCHAR message does its thing; see the documentation
+ − 2683 on WM_SYSKEYDOWN */
+ − 2684 lParam |= 1 << 29;
+ − 2685 }
428
+ − 2686 }
+ − 2687 else
442
+ − 2688 memcpy (keymap_sticky, keymap_orig, 256);
+ − 2689
+ − 2690 mods = mswindows_modifier_state (keymap_sticky, (DWORD) -1, has_AltGr);
502
+ − 2691 mods_with_shift = mods;
442
+ − 2692
+ − 2693 /* Handle non-printables */
+ − 2694 if (!NILP (keysym = mswindows_key_to_emacs_keysym (wParam, mods,
+ − 2695 extendedp)))
428
+ − 2696 {
442
+ − 2697 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
+ − 2698 if (sticky_changed)
+ − 2699 SetKeyboardState (keymap_orig);
428
+ − 2700 }
442
+ − 2701 else /* Normal keys & modifiers */
428
+ − 2702 {
867
+ − 2703 Ichar quit_ch =
442
+ − 2704 CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
+ − 2705 POINT pnt = { LOWORD (GetMessagePos()), HIWORD (GetMessagePos()) };
+ − 2706 MSG msg, tranmsg;
+ − 2707 int potential_accelerator = 0;
+ − 2708 int got_accelerator = 0;
771
+ − 2709 /* No need to gcpro because the event is already on a
+ − 2710 queue when we retrieve it. */
+ − 2711 Lisp_Object lastev = Qnil;
442
+ − 2712
+ − 2713 msg.hwnd = hwnd;
+ − 2714 msg.message = message_;
+ − 2715 msg.wParam = wParam;
+ − 2716 msg.lParam = lParam;
+ − 2717 msg.time = GetMessageTime();
+ − 2718 msg.pt = pnt;
+ − 2719
+ − 2720 /* GetKeyboardState() does not work as documented on Win95. We have
+ − 2721 * to loosely track Left and Right modifiers on behalf of the OS,
+ − 2722 * without screwing up Windows NT which tracks them properly. */
+ − 2723 if (wParam == VK_CONTROL)
+ − 2724 {
+ − 2725 keymap_orig[extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
+ − 2726 keymap_sticky[extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
+ − 2727 }
+ − 2728 else if (wParam == VK_MENU)
+ − 2729 {
+ − 2730 keymap_orig[extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
+ − 2731 keymap_sticky[extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
+ − 2732 }
+ − 2733
827
+ − 2734 #ifdef HAVE_MENUBARS
442
+ − 2735 if (!NILP (Vmenu_accelerator_enabled) &&
+ − 2736 !(mods & XEMACS_MOD_SHIFT) && message_ == WM_SYSKEYDOWN)
+ − 2737 potential_accelerator = 1;
827
+ − 2738 #endif
442
+ − 2739
+ − 2740 /* Remove shift modifier from an ascii character */
+ − 2741 mods &= ~XEMACS_MOD_SHIFT;
+ − 2742
+ − 2743 memcpy (keymap_trans, keymap_sticky, 256);
+ − 2744
+ − 2745 /* Clear control and alt modifiers unless AltGr is pressed */
+ − 2746 keymap_trans[VK_RCONTROL] = 0;
+ − 2747 keymap_trans[VK_LMENU] = 0;
+ − 2748 if (!has_AltGr || !(keymap_trans[VK_LCONTROL] & 0x80)
+ − 2749 || !(keymap_trans[VK_RMENU] & 0x80))
+ − 2750 {
+ − 2751 keymap_trans[VK_LCONTROL] = 0;
+ − 2752 keymap_trans[VK_CONTROL] = 0;
+ − 2753 keymap_trans[VK_RMENU] = 0;
+ − 2754 keymap_trans[VK_MENU] = 0;
+ − 2755 }
+ − 2756 SetKeyboardState (keymap_trans);
+ − 2757
+ − 2758 /* Maybe generate some WM_[SYS]CHARs in the queue */
+ − 2759 TranslateMessage (&msg);
+ − 2760
771
+ − 2761 while (qxePeekMessage (&tranmsg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
+ − 2762 || qxePeekMessage (&tranmsg, hwnd, WM_SYSCHAR, WM_SYSCHAR,
+ − 2763 PM_REMOVE))
442
+ − 2764 {
502
+ − 2765 int mods_with_quit = mods;
771
+ − 2766 int length;
+ − 2767 Extbyte extchar[4];
867
+ − 2768 Ibyte *intchar;
+ − 2769 Ichar ch;
771
+ − 2770
+ − 2771 if (XEUNICODE_P)
+ − 2772 {
+ − 2773 length = unicode_char_to_text (tranmsg.wParam, extchar);
+ − 2774 TO_INTERNAL_FORMAT (DATA, (extchar, length),
+ − 2775 C_STRING_ALLOCA, (intchar),
+ − 2776 Qmswindows_unicode);
867
+ − 2777 ch = itext_ichar (intchar);
771
+ − 2778 }
+ − 2779 else
+ − 2780 {
+ − 2781 length = ansi_char_to_text (tranmsg.wParam, extchar);
+ − 2782 intchar = (convert_multibyte_to_internal_malloc
+ − 2783 (extchar, length,
+ − 2784 mswindows_locale_to_code_page
+ − 2785 /* See intl-win32.c for an explanation of
+ − 2786 the following */
+ − 2787 ((LCID) GetKeyboardLayout (0) & 0xFFFF),
+ − 2788 NULL));
867
+ − 2789 ch = itext_ichar (intchar);
771
+ − 2790 xfree (intchar);
+ − 2791 }
442
+ − 2792
593
+ − 2793 #ifdef DEBUG_XEMACS
+ − 2794 if (debug_mswindows_events)
+ − 2795 {
+ − 2796 stderr_out ("-> ");
+ − 2797 debug_output_mswin_message (tranmsg.hwnd, tranmsg.message,
+ − 2798 tranmsg.wParam,
+ − 2799 tranmsg.lParam);
+ − 2800 }
+ − 2801 #endif /* DEBUG_XEMACS */
+ − 2802
442
+ − 2803 /* If a quit char with no modifiers other than control and
+ − 2804 shift, then mark it with a fake modifier, which is removed
+ − 2805 upon dequeueing the event */
+ − 2806 if (((quit_ch < ' ' && (mods & XEMACS_MOD_CONTROL)
771
+ − 2807 && DOWNCASE (0, quit_ch + 'a' - 1) ==
+ − 2808 DOWNCASE (0, ch))
442
+ − 2809 || (quit_ch >= ' ' && !(mods & XEMACS_MOD_CONTROL)
771
+ − 2810 && DOWNCASE (0, quit_ch) ==
+ − 2811 DOWNCASE (0, ch)))
502
+ − 2812 && ((mods_with_shift &
+ − 2813 ~(XEMACS_MOD_CONTROL | XEMACS_MOD_SHIFT))
442
+ − 2814 == 0))
+ − 2815 {
502
+ − 2816 mods_with_quit |= FAKE_MOD_QUIT;
+ − 2817 if (mods_with_shift & XEMACS_MOD_SHIFT)
+ − 2818 mods_with_quit |= FAKE_MOD_QUIT_CRITICAL;
593
+ − 2819 mswindows_quit_chars_count++;
442
+ − 2820 }
827
+ − 2821 #ifdef HAVE_MENUBARS
442
+ − 2822 else if (potential_accelerator && !got_accelerator &&
+ − 2823 mswindows_char_is_accelerator (frame, ch))
+ − 2824 {
+ − 2825 got_accelerator = 1;
+ − 2826 break;
+ − 2827 }
827
+ − 2828 #endif /* HAVE_MENUBARS */
+ − 2829
771
+ − 2830 lastev = mswindows_enqueue_keypress_event (hwnd,
+ − 2831 make_char (ch),
+ − 2832 mods_with_quit);
442
+ − 2833 } /* while */
+ − 2834
771
+ − 2835 #ifdef MULE
+ − 2836 /* Also figure out what the character would be in other
+ − 2837 possible keyboard layouts, in this order:
+ − 2838
+ − 2839 -- current language environment
+ − 2840 -- user default language environment
+ − 2841 -- system default language environment
+ − 2842 -- same three, but checking the underlying virtual key,
+ − 2843 and only paying attention if it's alphabetic
+ − 2844 -- US ASCII
+ − 2845
+ − 2846 See events.h, struct key_data, for why we do this.
+ − 2847 */
+ − 2848
+ − 2849 if (!NILP (lastev))
+ − 2850 {
+ − 2851 int i;
+ − 2852 int scan = (lParam >> 16) && 0xFF;
+ − 2853
+ − 2854 for (i = 0; i < KEYCHAR_LAST; i++)
+ − 2855 {
+ − 2856 int vk_only = 0;
+ − 2857 LCID lcid;
+ − 2858 int virtual_key;
+ − 2859
+ − 2860 switch (i)
+ − 2861 {
+ − 2862 case KEYCHAR_UNDERLYING_VIRTUAL_KEY_CURRENT_LANGENV:
+ − 2863 vk_only = 1;
+ − 2864 case KEYCHAR_CURRENT_LANGENV:
+ − 2865 lcid = mswindows_current_locale ();
+ − 2866 break;
+ − 2867
+ − 2868 case KEYCHAR_UNDERLYING_VIRTUAL_KEY_DEFAULT_USER:
+ − 2869 vk_only = 1;
+ − 2870 case KEYCHAR_DEFAULT_USER:
+ − 2871 lcid = GetUserDefaultLCID ();
+ − 2872 break;
+ − 2873
+ − 2874 case KEYCHAR_UNDERLYING_VIRTUAL_KEY_DEFAULT_SYSTEM:
+ − 2875 vk_only = 1;
+ − 2876 case KEYCHAR_DEFAULT_SYSTEM:
+ − 2877 lcid = GetSystemDefaultLCID ();
+ − 2878 break;
+ − 2879
+ − 2880 case KEYCHAR_QWERTY:
+ − 2881 lcid = MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US);
+ − 2882 break;
+ − 2883
+ − 2884 default: abort (); lcid = 0;
+ − 2885 }
+ − 2886
+ − 2887 /* VERY CONFUSING! See intl-win32.c. */
+ − 2888 lcid = lcid & 0xFFFF;
+ − 2889
800
+ − 2890 virtual_key = qxeMapVirtualKeyEx (scan, 1, (HKL) lcid);
771
+ − 2891 if (!vk_only)
+ − 2892 {
+ − 2893 if (XEUNICODE_P)
+ − 2894 {
+ − 2895 Extbyte received_keys[32];
+ − 2896 int tounret =
+ − 2897 ToUnicodeEx
+ − 2898 (virtual_key, scan, keymap_trans,
+ − 2899 (LPWSTR) received_keys,
+ − 2900 sizeof (received_keys) / XETCHAR_SIZE,
+ − 2901 0, /* #### what about this flag? "if
+ − 2902 bit 0 is set, a menu is
+ − 2903 active???" */
+ − 2904 (HKL) lcid);
+ − 2905 if (tounret > 0)
+ − 2906 {
867
+ − 2907 Ibyte *intchar;
771
+ − 2908
+ − 2909 TO_INTERNAL_FORMAT
+ − 2910 (DATA,
+ − 2911 (received_keys + (tounret - 1) * 2, 2),
+ − 2912 C_STRING_ALLOCA, intchar,
+ − 2913 Qmswindows_unicode);
+ − 2914 XEVENT (lastev)->event.key.alt_keychars[i] =
867
+ − 2915 itext_ichar (intchar);
771
+ − 2916 }
+ − 2917 }
+ − 2918 else
+ − 2919 {
+ − 2920 WORD received_keys[32];
+ − 2921 int tounret =
+ − 2922 ToAsciiEx (virtual_key, scan, keymap_trans,
+ − 2923 received_keys,
+ − 2924 0, /* #### what about this
+ − 2925 flag? "if bit 0 is set, a
+ − 2926 menu is active???" */
+ − 2927 (HKL) lcid);
+ − 2928 if (tounret > 0)
+ − 2929 {
+ − 2930 /* #### I cannot find proper
+ − 2931 documentation on what format the
+ − 2932 return value is in. I'm assuming
+ − 2933 it's like WM_IME_CHAR: DBCS chars
+ − 2934 have the lead byte in bits 8-15 of
+ − 2935 the short. */
867
+ − 2936 Ibyte *intchar;
771
+ − 2937 Extbyte mbstuff[2];
+ − 2938 Bytecount mblength = 0;
+ − 2939 WORD thechar = received_keys[tounret - 1];
+ − 2940
+ − 2941 mbstuff[mblength++] =
+ − 2942 (Extbyte) (thechar & 0xFF);
+ − 2943 if (thechar > 0xFF)
+ − 2944 mbstuff[mblength++] =
+ − 2945 (Extbyte) ((thechar >> 8) & 0xFF);
+ − 2946
+ − 2947 intchar = convert_multibyte_to_internal_malloc
+ − 2948 (mbstuff, mblength,
+ − 2949 mswindows_locale_to_code_page (lcid),
+ − 2950 NULL);
+ − 2951
+ − 2952 XEVENT (lastev)->event.key.alt_keychars[i] =
867
+ − 2953 itext_ichar (intchar);
771
+ − 2954 xfree (intchar);
+ − 2955 }
+ − 2956 }
+ − 2957 }
+ − 2958 else
+ − 2959 {
867
+ − 2960 Ichar altch;
771
+ − 2961
+ − 2962 if (virtual_key >= 'A' && virtual_key <= 'Z')
+ − 2963 altch =
+ − 2964 virtual_key + (mods_with_shift & XEMACS_MOD_SHIFT ?
+ − 2965 'a' - 'A' : 0);
+ − 2966 else
+ − 2967 altch = 0;
+ − 2968
+ − 2969 XEVENT (lastev)->event.key.alt_keychars[i] = altch;
+ − 2970 }
+ − 2971 }
+ − 2972 }
+ − 2973 #endif /* MULE */
+ − 2974
442
+ − 2975 /* This generates WM_SYSCHAR messages, which are interpreted
+ − 2976 by DefWindowProc as the menu selections. */
+ − 2977 if (got_accelerator)
+ − 2978 {
+ − 2979 SetKeyboardState (keymap_sticky);
+ − 2980 TranslateMessage (&msg);
+ − 2981 SetKeyboardState (keymap_orig);
771
+ − 2982 unbind_to (count);
442
+ − 2983 goto defproc;
+ − 2984 }
+ − 2985
+ − 2986 SetKeyboardState (keymap_orig);
+ − 2987 } /* else */
771
+ − 2988
+ − 2989 if (key_needs_default_processing_p (wParam))
+ − 2990 {
+ − 2991 unbind_to (count);
+ − 2992 goto defproc;
+ − 2993 }
+ − 2994 else
+ − 2995 {
+ − 2996 unbind_to (count);
+ − 2997 break;
+ − 2998 }
428
+ − 2999 }
442
+ − 3000
+ − 3001 case WM_MBUTTONDOWN:
+ − 3002 case WM_MBUTTONUP:
+ − 3003 /* Real middle mouse button has nothing to do with emulated one:
+ − 3004 if one wants to exercise fingers playing chords on the mouse,
+ − 3005 he is allowed to do that! */
+ − 3006 mswindows_enqueue_mouse_button_event (hwnd, message_,
+ − 3007 MAKEPOINTS (lParam),
+ − 3008 wParam &~ MK_MBUTTON,
+ − 3009 GetMessageTime());
+ − 3010 break;
+ − 3011
+ − 3012 case WM_LBUTTONUP:
771
+ − 3013 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
+ − 3014 msframe->last_click_time = GetMessageTime();
442
+ − 3015
+ − 3016 KillTimer (hwnd, BUTTON_2_TIMER_ID);
+ − 3017 msframe->button2_need_lbutton = 0;
+ − 3018 if (msframe->ignore_next_lbutton_up)
+ − 3019 {
+ − 3020 msframe->ignore_next_lbutton_up = 0;
+ − 3021 }
+ − 3022 else if (msframe->button2_is_down)
+ − 3023 {
+ − 3024 msframe->button2_is_down = 0;
+ − 3025 msframe->ignore_next_rbutton_up = 1;
+ − 3026 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
+ − 3027 MAKEPOINTS (lParam),
+ − 3028 wParam
+ − 3029 &~ (MK_LBUTTON | MK_MBUTTON
+ − 3030 | MK_RBUTTON),
+ − 3031 GetMessageTime());
+ − 3032 }
+ − 3033 else
+ − 3034 {
+ − 3035 if (msframe->button2_need_rbutton)
+ − 3036 {
+ − 3037 msframe->button2_need_rbutton = 0;
+ − 3038 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
+ − 3039 MAKEPOINTS (lParam),
+ − 3040 wParam &~ MK_LBUTTON,
+ − 3041 GetMessageTime());
+ − 3042 }
+ − 3043 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
+ − 3044 MAKEPOINTS (lParam),
+ − 3045 wParam &~ MK_LBUTTON,
+ − 3046 GetMessageTime());
+ − 3047 }
+ − 3048 break;
+ − 3049
+ − 3050 case WM_RBUTTONUP:
771
+ − 3051 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
+ − 3052 msframe->last_click_time = GetMessageTime();
442
+ − 3053
+ − 3054 KillTimer (hwnd, BUTTON_2_TIMER_ID);
+ − 3055 msframe->button2_need_rbutton = 0;
+ − 3056 if (msframe->ignore_next_rbutton_up)
+ − 3057 {
+ − 3058 msframe->ignore_next_rbutton_up = 0;
+ − 3059 }
+ − 3060 else if (msframe->button2_is_down)
+ − 3061 {
+ − 3062 msframe->button2_is_down = 0;
+ − 3063 msframe->ignore_next_lbutton_up = 1;
+ − 3064 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
+ − 3065 MAKEPOINTS (lParam),
+ − 3066 wParam
+ − 3067 &~ (MK_LBUTTON | MK_MBUTTON
+ − 3068 | MK_RBUTTON),
+ − 3069 GetMessageTime());
+ − 3070 }
+ − 3071 else
+ − 3072 {
+ − 3073 if (msframe->button2_need_lbutton)
+ − 3074 {
+ − 3075 msframe->button2_need_lbutton = 0;
+ − 3076 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
+ − 3077 MAKEPOINTS (lParam),
+ − 3078 wParam &~ MK_RBUTTON,
+ − 3079 GetMessageTime());
+ − 3080 }
+ − 3081 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
+ − 3082 MAKEPOINTS (lParam),
+ − 3083 wParam &~ MK_RBUTTON,
+ − 3084 GetMessageTime());
+ − 3085 }
+ − 3086 break;
+ − 3087
+ − 3088 case WM_LBUTTONDOWN:
771
+ − 3089 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
442
+ − 3090
+ − 3091 if (msframe->button2_need_lbutton)
428
+ − 3092 {
+ − 3093 KillTimer (hwnd, BUTTON_2_TIMER_ID);
442
+ − 3094 msframe->button2_need_lbutton = 0;
+ − 3095 msframe->button2_need_rbutton = 0;
+ − 3096 if (mswindows_button2_near_enough (msframe->last_click_point,
+ − 3097 MAKEPOINTS (lParam)))
428
+ − 3098 {
442
+ − 3099 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
+ − 3100 MAKEPOINTS (lParam),
+ − 3101 wParam
+ − 3102 &~ (MK_LBUTTON | MK_MBUTTON
+ − 3103 | MK_RBUTTON),
+ − 3104 GetMessageTime());
+ − 3105 msframe->button2_is_down = 1;
428
+ − 3106 }
442
+ − 3107 else
428
+ − 3108 {
442
+ − 3109 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
+ − 3110 msframe->last_click_point,
+ − 3111 msframe->last_click_mods
+ − 3112 &~ MK_RBUTTON,
+ − 3113 msframe->last_click_time);
+ − 3114 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
+ − 3115 MAKEPOINTS (lParam),
+ − 3116 wParam &~ MK_LBUTTON,
+ − 3117 GetMessageTime());
428
+ − 3118 }
+ − 3119 }
+ − 3120 else
442
+ − 3121 {
+ − 3122 mswindows_set_chord_timer (hwnd);
+ − 3123 msframe->button2_need_rbutton = 1;
+ − 3124 msframe->last_click_point = MAKEPOINTS (lParam);
+ − 3125 msframe->last_click_mods = wParam;
+ − 3126 }
771
+ − 3127 msframe->last_click_time = GetMessageTime();
442
+ − 3128 break;
+ − 3129
+ − 3130 case WM_RBUTTONDOWN:
771
+ − 3131 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
442
+ − 3132
+ − 3133 if (msframe->button2_need_rbutton)
428
+ − 3134 {
442
+ − 3135 KillTimer (hwnd, BUTTON_2_TIMER_ID);
+ − 3136 msframe->button2_need_lbutton = 0;
+ − 3137 msframe->button2_need_rbutton = 0;
+ − 3138 if (mswindows_button2_near_enough (msframe->last_click_point,
+ − 3139 MAKEPOINTS (lParam)))
+ − 3140 {
+ − 3141 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
+ − 3142 MAKEPOINTS (lParam),
+ − 3143 wParam
+ − 3144 &~ (MK_LBUTTON | MK_MBUTTON
+ − 3145 | MK_RBUTTON),
+ − 3146 GetMessageTime());
+ − 3147 msframe->button2_is_down = 1;
+ − 3148 }
+ − 3149 else
+ − 3150 {
+ − 3151 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
+ − 3152 msframe->last_click_point,
+ − 3153 msframe->last_click_mods
+ − 3154 &~ MK_LBUTTON,
+ − 3155 msframe->last_click_time);
+ − 3156 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
+ − 3157 MAKEPOINTS (lParam),
+ − 3158 wParam &~ MK_RBUTTON,
+ − 3159 GetMessageTime());
+ − 3160 }
428
+ − 3161 }
+ − 3162 else
+ − 3163 {
442
+ − 3164 mswindows_set_chord_timer (hwnd);
+ − 3165 msframe->button2_need_lbutton = 1;
+ − 3166 msframe->last_click_point = MAKEPOINTS (lParam);
+ − 3167 msframe->last_click_mods = wParam;
+ − 3168 }
771
+ − 3169 msframe->last_click_time = GetMessageTime();
442
+ − 3170 break;
+ − 3171
+ − 3172 case WM_TIMER:
+ − 3173 if (wParam == BUTTON_2_TIMER_ID)
+ − 3174 {
771
+ − 3175 msframe =
+ − 3176 FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
442
+ − 3177 KillTimer (hwnd, BUTTON_2_TIMER_ID);
+ − 3178
+ − 3179 if (msframe->button2_need_lbutton)
+ − 3180 {
+ − 3181 msframe->button2_need_lbutton = 0;
+ − 3182 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
+ − 3183 msframe->last_click_point,
+ − 3184 msframe->last_click_mods
+ − 3185 &~ MK_RBUTTON,
+ − 3186 msframe->last_click_time);
+ − 3187 }
+ − 3188 else if (msframe->button2_need_rbutton)
+ − 3189 {
+ − 3190 msframe->button2_need_rbutton = 0;
+ − 3191 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
+ − 3192 msframe->last_click_point,
+ − 3193 msframe->last_click_mods
+ − 3194 &~ MK_LBUTTON,
+ − 3195 msframe->last_click_time);
+ − 3196 }
+ − 3197 }
+ − 3198 else
+ − 3199 assert ("Spurious timer fired" == 0);
+ − 3200 break;
+ − 3201
+ − 3202 case WM_MOUSEMOVE:
+ − 3203 /* Optimization: don't report mouse movement while size is changing */
771
+ − 3204 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
442
+ − 3205 if (!msframe->sizing)
+ − 3206 {
+ − 3207 /* When waiting for the second mouse button to finish
+ − 3208 button2 emulation, and have moved too far, just pretend
+ − 3209 as if timer has expired. This improves drag-select feedback */
+ − 3210 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
+ − 3211 && !mswindows_button2_near_enough (msframe->last_click_point,
+ − 3212 MAKEPOINTS (lParam)))
428
+ − 3213 {
442
+ − 3214 KillTimer (hwnd, BUTTON_2_TIMER_ID);
771
+ − 3215 qxeSendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
442
+ − 3216 }
+ − 3217
+ − 3218 emacs_event = Fmake_event (Qnil, Qnil);
+ − 3219 event = XEVENT(emacs_event);
+ − 3220
771
+ − 3221 event->channel = mswindows_find_frame (hwnd);
+ − 3222 event->timestamp = GetMessageTime ();
442
+ − 3223 event->event_type = pointer_motion_event;
771
+ − 3224 event->event.motion.x = MAKEPOINTS (lParam).x;
+ − 3225 event->event.motion.y = MAKEPOINTS (lParam).y;
442
+ − 3226 event->event.motion.modifiers =
+ − 3227 mswindows_modifier_state (NULL, wParam, 0);
+ − 3228
+ − 3229 mswindows_enqueue_dispatch_event (emacs_event);
+ − 3230 }
+ − 3231 break;
+ − 3232
+ − 3233 case WM_CANCELMODE:
+ − 3234 ReleaseCapture ();
+ − 3235 /* Queue a `cancel-mode-internal' misc user event, so mouse
+ − 3236 selection would be canceled if any */
+ − 3237 mswindows_enqueue_misc_user_event (mswindows_find_frame (hwnd),
+ − 3238 Qcancel_mode_internal, Qnil);
+ − 3239 break;
+ − 3240
+ − 3241 case WM_NOTIFY:
+ − 3242 {
647
+ − 3243 LPNMHDR nmhdr = (LPNMHDR) lParam;
+ − 3244
+ − 3245 if ((int) nmhdr->code == TTN_NEEDTEXT)
442
+ − 3246 {
+ − 3247 #ifdef HAVE_TOOLBARS
771
+ − 3248 LPTOOLTIPTEXTW tttextw = (LPTOOLTIPTEXTW) lParam;
442
+ − 3249 Lisp_Object btext;
771
+ − 3250 Extbyte *btextext = 0;
442
+ − 3251
+ − 3252 /* find out which toolbar */
+ − 3253 frame = XFRAME (mswindows_find_frame (hwnd));
647
+ − 3254 btext = mswindows_get_toolbar_button_text (frame, nmhdr->idFrom);
442
+ − 3255
771
+ − 3256 tttextw->hinst = NULL;
+ − 3257
+ − 3258 if (!NILP (btext))
+ − 3259 LISP_STRING_TO_TSTR (btext, btextext);
+ − 3260
+ − 3261 if (btextext)
442
+ − 3262 {
771
+ − 3263 /* WARNING: We can't just write a '\0' into the 79th
+ − 3264 "character" because tttextw->szText is in WCHAR's but we
+ − 3265 may be copying an ANSI string into it. Easiest to just
+ − 3266 zero the whole thing. */
+ − 3267 xzero (*tttextw->szText);
+ − 3268 xetcsncpy ((Extbyte *) tttextw->szText, btextext, 79);
442
+ − 3269 }
771
+ − 3270 else
+ − 3271 tttextw->lpszText = NULL;
442
+ − 3272 #endif
+ − 3273 }
+ − 3274 /* handle tree view callbacks */
647
+ − 3275 else if ((int) nmhdr->code == TVN_SELCHANGED)
442
+ − 3276 {
647
+ − 3277 NM_TREEVIEW *ptree = (NM_TREEVIEW *) lParam;
442
+ − 3278 frame = XFRAME (mswindows_find_frame (hwnd));
+ − 3279 mswindows_handle_gui_wm_command (frame, 0, ptree->itemNew.lParam);
+ − 3280 }
+ − 3281 /* handle tab control callbacks */
647
+ − 3282 else if ((int) nmhdr->code == TCN_SELCHANGE)
442
+ − 3283 {
+ − 3284 TC_ITEM item;
771
+ − 3285 int idx = qxeSendMessage (nmhdr->hwndFrom, TCM_GETCURSEL, 0, 0);
442
+ − 3286 frame = XFRAME (mswindows_find_frame (hwnd));
+ − 3287
+ − 3288 item.mask = TCIF_PARAM;
771
+ − 3289 qxeSendMessage (nmhdr->hwndFrom, TCM_GETITEM, (WPARAM) idx,
+ − 3290 (LPARAM) &item);
442
+ − 3291
+ − 3292 mswindows_handle_gui_wm_command (frame, 0, item.lParam);
+ − 3293 }
+ − 3294 }
+ − 3295 break;
+ − 3296
+ − 3297 case WM_PAINT:
+ − 3298 /* hdc will be NULL unless this is a subwindow - in which case we
+ − 3299 shouldn't have received a paint message for it here. */
+ − 3300 assert (wParam == 0);
+ − 3301
+ − 3302 /* Can't queue a magic event because windows goes modal and sends paint
+ − 3303 messages directly to the windows procedure when doing solid drags
+ − 3304 and the message queue doesn't get processed. */
+ − 3305 mswindows_handle_paint (XFRAME (mswindows_find_frame (hwnd)));
+ − 3306 break;
+ − 3307
903
+ − 3308 case WM_ACTIVATE:
+ − 3309 {
+ − 3310 /*
+ − 3311 * If we receive a WM_ACTIVATE message that indicates that our frame
+ − 3312 * is being activated, make sure that the frame is marked visible
+ − 3313 * if the window itself is visible. This seems to fix the problem
+ − 3314 * where XEmacs appears to lock-up after switching desktops with
+ − 3315 * some virtual window managers.
+ − 3316 */
+ − 3317 int state = (int)(short) LOWORD(wParam);
+ − 3318 #ifdef DEBUG_XEMACS
+ − 3319 if (debug_mswindows_events)
+ − 3320 stderr_out("state = %d\n", state);
+ − 3321 #endif /* DEBUG_XEMACS */
+ − 3322 if (state == WA_ACTIVE || state == WA_CLICKACTIVE)
+ − 3323 {
+ − 3324 #ifdef DEBUG_XEMACS
+ − 3325 if (debug_mswindows_events)
+ − 3326 stderr_out(" activating\n");
+ − 3327 #endif /* DEBUG_XEMACS */
+ − 3328
+ − 3329 fobj = mswindows_find_frame (hwnd);
+ − 3330 frame = XFRAME (fobj);
+ − 3331 if (IsWindowVisible (hwnd))
+ − 3332 {
+ − 3333 #ifdef DEBUG_XEMACS
+ − 3334 if (debug_mswindows_events)
+ − 3335 stderr_out(" window is visible\n");
+ − 3336 #endif /* DEBUG_XEMACS */
+ − 3337 if (!FRAME_VISIBLE_P (frame))
+ − 3338 {
+ − 3339 #ifdef DEBUG_XEMACS
+ − 3340 if (debug_mswindows_events)
+ − 3341 stderr_out(" frame is not visible\n");
+ − 3342 #endif /* DEBUG_XEMACS */
+ − 3343 /*
+ − 3344 * It seems that we have to enqueue the XM_MAPFRAME event
+ − 3345 * prior to setting the frame visible so that
+ − 3346 * suspend-or-iconify-emacs works properly.
+ − 3347 */
+ − 3348 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
+ − 3349 FRAME_VISIBLE_P (frame) = 1;
+ − 3350 FRAME_ICONIFIED_P (frame) = 0;
+ − 3351 }
+ − 3352 #ifdef DEBUG_XEMACS
+ − 3353 else
+ − 3354 {
+ − 3355 if (debug_mswindows_events)
+ − 3356 stderr_out(" frame is visible\n");
+ − 3357 }
+ − 3358 #endif /* DEBUG_XEMACS */
+ − 3359 }
+ − 3360 #ifdef DEBUG_XEMACS
+ − 3361 else
+ − 3362 {
+ − 3363 if (debug_mswindows_events)
+ − 3364 stderr_out(" window is not visible\n");
+ − 3365 }
+ − 3366 #endif /* DEBUG_XEMACS */
+ − 3367 }
+ − 3368 return qxeDefWindowProc (hwnd, message_, wParam, lParam);
+ − 3369 }
+ − 3370 break;
+ − 3371
593
+ − 3372 case WM_WINDOWPOSCHANGED:
+ − 3373 /* This is sent before WM_SIZE; in fact, the processing of this
+ − 3374 by DefWindowProc() sends WM_SIZE. But WM_SIZE is not sent when
+ − 3375 a window is hidden (make-frame-invisible), so we need to process
+ − 3376 this and update the state flags. */
+ − 3377 {
+ − 3378 fobj = mswindows_find_frame (hwnd);
+ − 3379 frame = XFRAME (fobj);
+ − 3380 if (IsIconic (hwnd))
+ − 3381 {
+ − 3382 FRAME_VISIBLE_P (frame) = 0;
+ − 3383 FRAME_ICONIFIED_P (frame) = 1;
+ − 3384 }
+ − 3385 else if (IsWindowVisible (hwnd))
+ − 3386 {
707
+ − 3387 /* APA: It's too early here to set the frame visible.
+ − 3388 * Let's do this later, in WM_SIZE processing, after the
+ − 3389 * magic XM_MAPFRAME event has been sent (just like 21.1
+ − 3390 * did). */
+ − 3391 /* FRAME_VISIBLE_P (frame) = 1; */
593
+ − 3392 FRAME_ICONIFIED_P (frame) = 0;
+ − 3393 }
+ − 3394 else
+ − 3395 {
+ − 3396 FRAME_VISIBLE_P (frame) = 0;
+ − 3397 FRAME_ICONIFIED_P (frame) = 0;
+ − 3398 }
+ − 3399
771
+ − 3400 goto defproc;
593
+ − 3401 }
+ − 3402
731
+ − 3403 case WM_SHOWWINDOW:
+ − 3404 /*
+ − 3405 The WM_SHOWWINDOW message is sent to a window when the window
+ − 3406 is about to be hidden or shown.
+ − 3407 APA: This message is also sent when switching to a virtual
+ − 3408 desktop under the virtuawin virtual window manager.
+ − 3409
+ − 3410 */
+ − 3411 {
+ − 3412 fobj = mswindows_find_frame (hwnd);
+ − 3413 frame = XFRAME (fobj);
+ − 3414 if (wParam == TRUE)
+ − 3415 {
+ − 3416 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
+ − 3417 FRAME_VISIBLE_P (frame) = 1;
+ − 3418 }
+ − 3419 else
+ − 3420 {
+ − 3421 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
+ − 3422 FRAME_VISIBLE_P (frame) = 0;
+ − 3423 }
+ − 3424 }
+ − 3425 break;
+ − 3426
442
+ − 3427 case WM_SIZE:
+ − 3428 /* We only care about this message if our size has really changed */
771
+ − 3429 if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED ||
+ − 3430 wParam == SIZE_MINIMIZED)
442
+ − 3431 {
+ − 3432 RECT rect;
+ − 3433 int columns, rows;
+ − 3434
+ − 3435 fobj = mswindows_find_frame (hwnd);
+ − 3436 frame = XFRAME (fobj);
771
+ − 3437 msframe = FRAME_MSWINDOWS_DATA (frame);
442
+ − 3438
+ − 3439 /* We cannot handle frame map and unmap hooks right in
+ − 3440 this routine, because these may throw. We queue
+ − 3441 magic events to run these hooks instead - kkm */
+ − 3442
771
+ − 3443 if (wParam == SIZE_MINIMIZED)
442
+ − 3444 {
+ − 3445 /* Iconified */
+ − 3446 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
428
+ − 3447 }
+ − 3448 else
+ − 3449 {
442
+ − 3450 GetClientRect(hwnd, &rect);
+ − 3451 FRAME_PIXWIDTH(frame) = rect.right;
+ − 3452 FRAME_PIXHEIGHT(frame) = rect.bottom;
+ − 3453
+ − 3454 pixel_to_real_char_size (frame, rect.right, rect.bottom,
+ − 3455 &FRAME_MSWINDOWS_CHARWIDTH (frame),
+ − 3456 &FRAME_MSWINDOWS_CHARHEIGHT (frame));
+ − 3457
771
+ − 3458 pixel_to_char_size (frame, rect.right, rect.bottom, &columns,
+ − 3459 &rows);
442
+ − 3460 change_frame_size (frame, rows, columns, 1);
+ − 3461
+ − 3462 /* If we are inside frame creation, we have to apply geometric
+ − 3463 properties now. */
+ − 3464 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
+ − 3465 {
+ − 3466 /* Yes, we have to size again */
771
+ − 3467 mswindows_size_frame_internal (frame,
+ − 3468 FRAME_MSWINDOWS_TARGET_RECT
+ − 3469 (frame));
+ − 3470 /* Reset so we do not get here again. The SetWindowPos
+ − 3471 * call in mswindows_size_frame_internal can cause
+ − 3472 * recursion here. */
442
+ − 3473 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
+ − 3474 {
+ − 3475 xfree (FRAME_MSWINDOWS_TARGET_RECT (frame));
+ − 3476 FRAME_MSWINDOWS_TARGET_RECT (frame) = 0;
+ − 3477 }
+ − 3478 }
+ − 3479 else
+ − 3480 {
903
+ − 3481 if (!msframe->sizing && !FRAME_VISIBLE_P (frame))
+ − 3482 {
+ − 3483 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
+ − 3484 /* APA: Now that the magic XM_MAPFRAME event has
+ − 3485 * been sent we can mark the frame as visible (just
+ − 3486 * like 21.1 did). */
+ − 3487 FRAME_VISIBLE_P (frame) = 1;
+ − 3488 }
442
+ − 3489
+ − 3490 if (!msframe->sizing || mswindows_dynamic_frame_resize)
+ − 3491 redisplay ();
+ − 3492 }
428
+ − 3493 }
+ − 3494 }
442
+ − 3495 break;
+ − 3496
+ − 3497 case WM_DISPLAYCHANGE:
+ − 3498 {
+ − 3499 struct device *d;
+ − 3500 DWORD message_tick = GetMessageTime ();
+ − 3501
+ − 3502 fobj = mswindows_find_frame (hwnd);
+ − 3503 frame = XFRAME (fobj);
+ − 3504 d = XDEVICE (FRAME_DEVICE (frame));
+ − 3505
+ − 3506 /* Do this only once per message. XEmacs can receive this message
+ − 3507 through as many frames as it currently has open. Message time
+ − 3508 will be the same for all these messages. Despite extreme
+ − 3509 efficiency, the code below has about one in 4 billion
+ − 3510 probability that the HDC is not recreated, provided that
+ − 3511 XEmacs is running sufficiently longer than 52 days. */
+ − 3512 if (DEVICE_MSWINDOWS_UPDATE_TICK(d) != message_tick)
+ − 3513 {
+ − 3514 DEVICE_MSWINDOWS_UPDATE_TICK(d) = message_tick;
+ − 3515 DeleteDC (DEVICE_MSWINDOWS_HCDC(d));
+ − 3516 DEVICE_MSWINDOWS_HCDC(d) = CreateCompatibleDC (NULL);
+ − 3517 }
+ − 3518 }
+ − 3519 break;
+ − 3520
+ − 3521 /* Misc magic events which only require that the frame be identified */
+ − 3522 case WM_SETFOCUS:
+ − 3523 case WM_KILLFOCUS:
+ − 3524 mswindows_enqueue_magic_event (hwnd, message_);
+ − 3525 break;
+ − 3526
+ − 3527 case WM_WINDOWPOSCHANGING:
428
+ − 3528 {
442
+ − 3529 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
+ − 3530 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
+ − 3531 GetWindowPlacement(hwnd, &wpl);
+ − 3532
+ − 3533 /* Only interested if size is changing and we're not being iconified */
+ − 3534 if (wpl.showCmd != SW_SHOWMINIMIZED
+ − 3535 && wpl.showCmd != SW_SHOWMAXIMIZED
+ − 3536 && !(wp->flags & SWP_NOSIZE))
428
+ − 3537 {
442
+ − 3538 RECT ncsize = { 0, 0, 0, 0 };
+ − 3539 int pixwidth, pixheight;
771
+ − 3540 AdjustWindowRectEx (&ncsize, qxeGetWindowLong (hwnd, GWL_STYLE),
442
+ − 3541 GetMenu(hwnd) != NULL,
771
+ − 3542 qxeGetWindowLong (hwnd, GWL_EXSTYLE));
442
+ − 3543
+ − 3544 round_size_to_real_char (XFRAME (mswindows_find_frame (hwnd)),
+ − 3545 wp->cx - (ncsize.right - ncsize.left),
+ − 3546 wp->cy - (ncsize.bottom - ncsize.top),
+ − 3547 &pixwidth, &pixheight);
+ − 3548
+ − 3549 /* Convert client sizes to window sizes */
+ − 3550 pixwidth += (ncsize.right - ncsize.left);
+ − 3551 pixheight += (ncsize.bottom - ncsize.top);
+ − 3552
+ − 3553 if (wpl.showCmd != SW_SHOWMAXIMIZED)
+ − 3554 {
+ − 3555 /* Adjust so that the bottom or right doesn't move if it's
+ − 3556 * the top or left that's being changed */
+ − 3557 RECT rect;
+ − 3558 GetWindowRect (hwnd, &rect);
+ − 3559
+ − 3560 if (rect.left != wp->x)
+ − 3561 wp->x += wp->cx - pixwidth;
+ − 3562 if (rect.top != wp->y)
+ − 3563 wp->y += wp->cy - pixheight;
+ − 3564 }
+ − 3565
+ − 3566 wp->cx = pixwidth;
+ − 3567 wp->cy = pixheight;
428
+ − 3568 }
442
+ − 3569 /* DefWindowProc sends useful WM_GETMINMAXINFO message, and adjusts
+ − 3570 window position if the user tries to track window too small */
428
+ − 3571 }
442
+ − 3572 goto defproc;
+ − 3573
+ − 3574 case WM_ENTERSIZEMOVE:
771
+ − 3575 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
442
+ − 3576 msframe->sizing = 1;
+ − 3577 return 0;
+ − 3578
+ − 3579 case WM_EXITSIZEMOVE:
771
+ − 3580 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
442
+ − 3581 msframe->sizing = 0;
+ − 3582 /* Queue noop event */
+ − 3583 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
+ − 3584 return 0;
428
+ − 3585
+ − 3586 #ifdef HAVE_SCROLLBARS
442
+ − 3587 case WM_VSCROLL:
+ − 3588 case WM_HSCROLL:
+ − 3589 {
+ − 3590 /* Direction of scroll is determined by scrollbar instance. */
+ − 3591 int code = (int) LOWORD(wParam);
+ − 3592 int pos = (short int) HIWORD(wParam);
+ − 3593 HWND hwndScrollBar = (HWND) lParam;
+ − 3594 struct gcpro gcpro1, gcpro2;
+ − 3595
+ − 3596 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
+ − 3597 GCPRO2 (emacs_event, fobj);
853
+ − 3598 if (UNBOUNDP (mswindows_pump_outstanding_events ())) /* Can GC */
442
+ − 3599 {
+ − 3600 /* Error during event pumping - cancel scroll */
771
+ − 3601 qxeSendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
442
+ − 3602 }
+ − 3603 UNGCPRO;
+ − 3604 break;
+ − 3605 }
+ − 3606
+ − 3607 case WM_MOUSEWHEEL:
+ − 3608 {
+ − 3609 int keys = LOWORD (wParam); /* Modifier key flags */
+ − 3610 int delta = (short) HIWORD (wParam); /* Wheel rotation amount */
+ − 3611
464
+ − 3612 if (mswindows_handle_mousewheel_event (mswindows_find_frame (hwnd),
+ − 3613 keys, delta,
+ − 3614 MAKEPOINTS (lParam)))
707
+ − 3615 /* We are not in a modal loop so no pumping is necessary. */
+ − 3616 break;
442
+ − 3617 else
+ − 3618 goto defproc;
+ − 3619 }
428
+ − 3620 #endif
+ − 3621
+ − 3622 #ifdef HAVE_MENUBARS
442
+ − 3623 case WM_INITMENU:
771
+ − 3624 if (UNBOUNDP (mswindows_handle_wm_initmenu
+ − 3625 ((HMENU) wParam,
+ − 3626 XFRAME (mswindows_find_frame (hwnd)))))
+ − 3627 qxeSendMessage (hwnd, WM_CANCELMODE, 0, 0);
442
+ − 3628 break;
+ − 3629
+ − 3630 case WM_INITMENUPOPUP:
+ − 3631 if (!HIWORD(lParam))
+ − 3632 {
771
+ − 3633 if (UNBOUNDP (mswindows_handle_wm_initmenupopup
+ − 3634 ((HMENU) wParam,
+ − 3635 XFRAME (mswindows_find_frame (hwnd)))))
+ − 3636 qxeSendMessage (hwnd, WM_CANCELMODE, 0, 0);
442
+ − 3637 }
+ − 3638 break;
428
+ − 3639
+ − 3640 #endif /* HAVE_MENUBARS */
+ − 3641
442
+ − 3642 case WM_COMMAND:
+ − 3643 {
+ − 3644 WORD id = LOWORD (wParam);
+ − 3645 WORD nid = HIWORD (wParam);
+ − 3646 HWND cid = (HWND)lParam;
+ − 3647 frame = XFRAME (mswindows_find_frame (hwnd));
428
+ − 3648
+ − 3649 #ifdef HAVE_TOOLBARS
442
+ − 3650 if (!NILP (mswindows_handle_toolbar_wm_command (frame, cid, id)))
+ − 3651 break;
428
+ − 3652 #endif
771
+ − 3653 /* widgets in a buffer only eval a callback for suitable events. */
442
+ − 3654 switch (nid)
+ − 3655 {
+ − 3656 case BN_CLICKED:
+ − 3657 case EN_CHANGE:
+ − 3658 case CBN_EDITCHANGE:
+ − 3659 case CBN_SELCHANGE:
+ − 3660 if (!NILP (mswindows_handle_gui_wm_command (frame, cid, id)))
+ − 3661 return 0;
+ − 3662 }
+ − 3663 /* menubars always must come last since the hashtables do not
771
+ − 3664 always exist */
428
+ − 3665 #ifdef HAVE_MENUBARS
442
+ − 3666 if (!NILP (mswindows_handle_wm_command (frame, id)))
+ − 3667 break;
428
+ − 3668 #endif
+ − 3669
771
+ − 3670 goto defproc;
+ − 3671 /* Bite me - a spurious command. This used to not be able to
+ − 3672 happen but with the introduction of widgets it's now
+ − 3673 possible. #### Andy, fix the god-damn widget code! It has
+ − 3674 more bugs than a termite's nest! */
442
+ − 3675 }
+ − 3676 break;
+ − 3677
+ − 3678 case WM_CTLCOLORBTN:
+ − 3679 case WM_CTLCOLORLISTBOX:
+ − 3680 case WM_CTLCOLOREDIT:
+ − 3681 case WM_CTLCOLORSTATIC:
+ − 3682 case WM_CTLCOLORSCROLLBAR:
+ − 3683 {
+ − 3684 /* if we get an opportunity to paint a widget then do so if
+ − 3685 there is an appropriate face */
771
+ − 3686 HWND crtlwnd = (HWND) lParam;
+ − 3687 LONG ii = qxeGetWindowLong (crtlwnd, GWL_USERDATA);
442
+ − 3688 if (ii)
+ − 3689 {
+ − 3690 Lisp_Object image_instance;
826
+ − 3691 image_instance = VOID_TO_LISP ((void *) ii);
442
+ − 3692 if (IMAGE_INSTANCEP (image_instance)
+ − 3693 &&
+ − 3694 IMAGE_INSTANCE_TYPE_P (image_instance, IMAGE_WIDGET))
+ − 3695 {
+ − 3696 /* set colors for the buttons */
771
+ − 3697 HDC hdc = (HDC) wParam;
442
+ − 3698 if (last_widget_brushed != ii)
+ − 3699 {
+ − 3700 if (widget_brush)
+ − 3701 DeleteObject (widget_brush);
+ − 3702 widget_brush = CreateSolidBrush
+ − 3703 (COLOR_INSTANCE_MSWINDOWS_COLOR
+ − 3704 (XCOLOR_INSTANCE
+ − 3705 (FACE_BACKGROUND
+ − 3706 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
+ − 3707 XIMAGE_INSTANCE_FRAME (image_instance)))));
+ − 3708 }
+ − 3709 last_widget_brushed = ii;
+ − 3710 SetTextColor
+ − 3711 (hdc,
+ − 3712 COLOR_INSTANCE_MSWINDOWS_COLOR
+ − 3713 (XCOLOR_INSTANCE
+ − 3714 (FACE_FOREGROUND
+ − 3715 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
+ − 3716 XIMAGE_INSTANCE_FRAME (image_instance)))));
+ − 3717 SetBkMode (hdc, OPAQUE);
+ − 3718 SetBkColor
+ − 3719 (hdc,
+ − 3720 COLOR_INSTANCE_MSWINDOWS_COLOR
+ − 3721 (XCOLOR_INSTANCE
+ − 3722 (FACE_BACKGROUND
+ − 3723 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
+ − 3724 XIMAGE_INSTANCE_FRAME (image_instance)))));
+ − 3725 return (LRESULT)widget_brush;
+ − 3726 }
+ − 3727 }
+ − 3728 }
+ − 3729 goto defproc;
428
+ − 3730
+ − 3731 #ifdef HAVE_DRAGNDROP
853
+ − 3732 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
442
+ − 3733 {
771
+ − 3734 UINT filecount, i;
442
+ − 3735 POINT point;
+ − 3736
+ − 3737 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
+ − 3738 struct gcpro gcpro1, gcpro2, gcpro3;
+ − 3739
+ − 3740 emacs_event = Fmake_event (Qnil, Qnil);
771
+ − 3741 event = XEVENT (emacs_event);
442
+ − 3742
+ − 3743 GCPRO3 (emacs_event, l_dndlist, l_item);
+ − 3744
+ − 3745 if (!DragQueryPoint ((HDROP) wParam, &point))
853
+ − 3746 point.x = point.y = -1; /* outside client area */
442
+ − 3747
+ − 3748 event->event_type = misc_user_event;
771
+ − 3749 event->channel = mswindows_find_frame (hwnd);
442
+ − 3750 event->timestamp = GetMessageTime();
+ − 3751 event->event.misc.button = 1; /* #### Should try harder */
+ − 3752 event->event.misc.modifiers = mswindows_modifier_state (NULL,
+ − 3753 (DWORD) -1, 0);
+ − 3754 event->event.misc.x = point.x;
+ − 3755 event->event.misc.y = point.y;
+ − 3756 event->event.misc.function = Qdragdrop_drop_dispatch;
+ − 3757
771
+ − 3758 filecount = qxeDragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0);
+ − 3759 for (i = 0; i < filecount; i++)
442
+ − 3760 {
867
+ − 3761 Ibyte *fname;
771
+ − 3762 Extbyte *fname_ext;
+ − 3763 Bytecount fnamelen;
+ − 3764 Charcount len = qxeDragQueryFile ((HDROP) wParam, i, NULL, 0);
442
+ − 3765 /* The URLs that we make here aren't correct according to section
+ − 3766 * 3.10 of rfc1738 because they're missing the //<host>/ part and
+ − 3767 * because they may contain reserved characters. But that's OK -
+ − 3768 * they just need to be good enough to keep dragdrop.el happy. */
851
+ − 3769 fname_ext = (Extbyte *) ALLOCA ((len + 1) * XETCHAR_SIZE);
771
+ − 3770 qxeDragQueryFile ((HDROP) wParam, i, fname_ext, len + 1);
+ − 3771
+ − 3772 TO_INTERNAL_FORMAT (DATA, (fname_ext, len * XETCHAR_SIZE),
+ − 3773 ALLOCA, (fname, fnamelen),
+ − 3774 Qmswindows_tstr);
442
+ − 3775
+ − 3776 /* May be a shell link aka "shortcut" - replace fname if so */
771
+ − 3777 #if !defined (NO_CYGWIN_COM_SUPPORT)
+ − 3778 if (!qxestrcasecmp_c (fname + fnamelen - 4, ".LNK"))
442
+ − 3779 {
771
+ − 3780 /* ####
+ − 3781
+ − 3782 Note the following in the docs:
+ − 3783
+ − 3784 Note: The IShellLink interface has an ANSI version
+ − 3785 (IShellLinkA) and a Unicode version (IShellLinkW). The
+ − 3786 version that will be used depends on whether you compile
+ − 3787 for ANSI or Unicode. However, Microsoft� Windows 95 and
+ − 3788 Microsoft� Windows 98 only support IShellLinkA.
+ − 3789
+ − 3790 We haven't yet implemented COM support in the
+ − 3791 Unicode-splitting library. I don't quite understand how
+ − 3792 COM works yet, but it looks like what's happening is
+ − 3793 that the ShellLink class implements both the IShellLinkA
+ − 3794 and IShellLinkW interfaces. To make this work at
+ − 3795 run-time, we have to do something like this:
+ − 3796
+ − 3797 -- define a new interface qxeIShellLink that uses
+ − 3798 Extbyte * instead of LPSTR or LPWSTR. (not totally
+ − 3799 necessary since Extbyte * == LPSTR).
+ − 3800
+ − 3801 -- define a new class qxeShellLink that implements
+ − 3802 qxeIShellLink. the methods on this class need to create
+ − 3803 a shadow ShellLink object to do all the real work, and
+ − 3804 call the corresponding function from either the
+ − 3805 IShellLinkA or IShellLinkW interfaces on this object,
+ − 3806 depending on whether XEUNICODE_P is defined.
+ − 3807
+ − 3808 -- with appropriate preprocessor magic, of course, we
+ − 3809 could make things appear transparent; but we've decided
+ − 3810 not to do preprocessor magic for the moment.
+ − 3811 */
+ − 3812
+ − 3813 /* #### Not Unicode-split for the moment; we have to do it
+ − 3814 ourselves. */
+ − 3815 if (XEUNICODE_P)
442
+ − 3816 {
771
+ − 3817 IShellLinkW *psl;
+ − 3818
+ − 3819 if (CoCreateInstance (
+ − 3820 XECOMID (CLSID_ShellLink),
+ − 3821 NULL,
+ − 3822 CLSCTX_INPROC_SERVER,
+ − 3823 XECOMID (IID_IShellLinkW),
+ − 3824 (void **) &psl) == S_OK)
442
+ − 3825 {
771
+ − 3826 IPersistFile *ppf;
+ − 3827
+ − 3828 if (XECOMCALL2 (psl, QueryInterface,
+ − 3829 XECOMID (IID_IPersistFile),
+ − 3830 (void **) &ppf) ==
+ − 3831 S_OK)
442
+ − 3832 {
771
+ − 3833 Extbyte *fname_unicode;
+ − 3834 WIN32_FIND_DATAW wfd;
+ − 3835 LPWSTR resolved =
+ − 3836 alloca_array (WCHAR, PATH_MAX + 1);
+ − 3837
+ − 3838 TO_EXTERNAL_FORMAT (DATA, (fname, fnamelen),
+ − 3839 C_STRING_ALLOCA,
+ − 3840 fname_unicode,
+ − 3841 Qmswindows_unicode);
+ − 3842
+ − 3843 if (XECOMCALL2 (ppf, Load,
+ − 3844 (LPWSTR) fname_unicode,
+ − 3845 STGM_READ) == S_OK &&
+ − 3846 /* #### YUCK! Docs read
+ − 3847
+ − 3848 cchMaxPath
+ − 3849
+ − 3850 Maximum number of bytes to copy to the buffer pointed to by the
+ − 3851 pszFile parameter.
+ − 3852
+ − 3853 But "cch" means "count of characters", not bytes. I'll assume the doc
+ − 3854 writers messed up and the programmer was correct. Also, this approach
+ − 3855 is safe even if it's actually the other way around. */
+ − 3856 #ifdef CYGWIN_HEADERS /* Another Cygwin prototype error */
+ − 3857 XECOMCALL4 (psl, GetPath, (LPSTR) resolved,
+ − 3858 PATH_MAX, &wfd, 0)
+ − 3859 #else
+ − 3860 XECOMCALL4 (psl, GetPath, resolved,
+ − 3861 PATH_MAX, &wfd, 0)
+ − 3862 #endif
+ − 3863 == S_OK)
+ − 3864 TO_INTERNAL_FORMAT (C_STRING, resolved,
+ − 3865 ALLOCA, (fname, fnamelen),
+ − 3866 Qmswindows_tstr);
+ − 3867
+ − 3868 XECOMCALL0 (ppf, Release);
442
+ − 3869 }
+ − 3870
771
+ − 3871 XECOMCALL0 (psl, Release);
442
+ − 3872 }
771
+ − 3873 }
+ − 3874 else
+ − 3875 {
+ − 3876 IShellLinkA *psl;
+ − 3877
+ − 3878 if (CoCreateInstance (
+ − 3879 XECOMID (CLSID_ShellLink),
+ − 3880 NULL,
+ − 3881 CLSCTX_INPROC_SERVER,
+ − 3882 XECOMID (IID_IShellLinkA),
+ − 3883 (void **) &psl) == S_OK)
+ − 3884 {
+ − 3885 IPersistFile *ppf;
+ − 3886
+ − 3887 if (XECOMCALL2 (psl, QueryInterface,
+ − 3888 XECOMID (IID_IPersistFile),
+ − 3889 (void **) &ppf) ==
+ − 3890 S_OK)
+ − 3891 {
+ − 3892 Extbyte *fname_unicode;
+ − 3893 WIN32_FIND_DATAA wfd;
+ − 3894 LPSTR resolved =
+ − 3895 alloca_array (CHAR, PATH_MAX + 1);
+ − 3896
+ − 3897 /* Always Unicode. Not obvious from the
+ − 3898 IPersistFile documentation, but look under
+ − 3899 "Shell Link" for example code. */
+ − 3900 TO_EXTERNAL_FORMAT (DATA, (fname, fnamelen),
+ − 3901 C_STRING_ALLOCA,
+ − 3902 fname_unicode,
+ − 3903 Qmswindows_unicode);
+ − 3904
+ − 3905 if (XECOMCALL2 (ppf, Load,
+ − 3906 (LPWSTR) fname_unicode,
+ − 3907 STGM_READ) == S_OK
+ − 3908 && XECOMCALL4 (psl, GetPath, resolved,
+ − 3909 PATH_MAX, &wfd, 0) == S_OK)
+ − 3910 TO_INTERNAL_FORMAT (C_STRING, resolved,
+ − 3911 ALLOCA, (fname, fnamelen),
+ − 3912 Qmswindows_tstr);
+ − 3913
+ − 3914 XECOMCALL0 (ppf, Release);
+ − 3915 }
+ − 3916
+ − 3917 XECOMCALL0 (psl, Release);
+ − 3918 }
442
+ − 3919 }
+ − 3920 }
771
+ − 3921 #endif /* !defined (NO_CYGWIN_COM_SUPPORT) */
+ − 3922 {
+ − 3923 fname = urlify_filename (fname);
+ − 3924 l_item = build_intstring (fname);
+ − 3925 xfree (fname);
+ − 3926 l_dndlist = Fcons (l_item, l_dndlist);
+ − 3927 }
442
+ − 3928 }
771
+ − 3929
442
+ − 3930 DragFinish ((HDROP) wParam);
+ − 3931
+ − 3932 event->event.misc.object = Fcons (Qdragdrop_URL, l_dndlist);
+ − 3933 mswindows_enqueue_dispatch_event (emacs_event);
+ − 3934 UNGCPRO;
+ − 3935 }
+ − 3936 break;
771
+ − 3937 #endif /* HAVE_DRAGNDROP */
+ − 3938
+ − 3939 #ifdef MULE
+ − 3940 case WM_IME_CHAR:
+ − 3941
+ − 3942 case WM_IME_STARTCOMPOSITION:
+ − 3943 mswindows_start_ime_composition (XFRAME (mswindows_find_frame (hwnd)));
+ − 3944 goto defproc;
+ − 3945
+ − 3946 case WM_IME_COMPOSITION:
+ − 3947 if (lParam & GCS_RESULTSTR)
+ − 3948 {
+ − 3949 HIMC imc = ImmGetContext (hwnd);
+ − 3950 Extbyte *result;
+ − 3951 Bytecount len;
867
+ − 3952 Ibyte *resultint, *endptr;
771
+ − 3953 Bytecount lenint;
+ − 3954 int speccount;
+ − 3955
+ − 3956 if (!imc)
+ − 3957 break;
+ − 3958
+ − 3959 /* See WM_KEYDOWN above. */
+ − 3960 speccount = begin_dont_check_for_quit ();
+ − 3961
+ − 3962 /* Sizes always in bytes, even for unicode.
+ − 3963 ImmGetCompositionStringW is supported even on Windows 9x, and
+ − 3964 allows us to handle multiple languages. */
+ − 3965 len = ImmGetCompositionStringW (imc, GCS_RESULTSTR, NULL, 0);
+ − 3966 result = alloca_array (Extbyte, len);
+ − 3967 ImmGetCompositionStringW (imc, GCS_RESULTSTR, (WCHAR *) result, len);
+ − 3968 ImmReleaseContext (hwnd, imc);
+ − 3969
+ − 3970 TO_INTERNAL_FORMAT (DATA, (result, len),
+ − 3971 ALLOCA, (resultint, lenint),
+ − 3972 Qmswindows_tstr);
+ − 3973
+ − 3974 endptr = resultint + lenint;
+ − 3975
+ − 3976 while (resultint < endptr)
+ − 3977 {
867
+ − 3978 Ichar ch = itext_ichar (resultint);
771
+ − 3979 if (ch == ' ')
+ − 3980 mswindows_enqueue_keypress_event (hwnd, QKspace, 0);
+ − 3981 else
+ − 3982 mswindows_enqueue_keypress_event (hwnd, make_char (ch), 0);
867
+ − 3983 INC_IBYTEPTR (resultint);
771
+ − 3984 }
+ − 3985
+ − 3986 unbind_to (speccount);
+ − 3987 }
+ − 3988 goto defproc;
+ − 3989 #endif /* MULE */
442
+ − 3990
+ − 3991 defproc:
+ − 3992 default:
771
+ − 3993 return qxeDefWindowProc (hwnd, message_, wParam, lParam);
428
+ − 3994 }
+ − 3995 return (0);
+ − 3996 }
+ − 3997
+ − 3998
+ − 3999 /************************************************************************/
+ − 4000 /* keyboard, mouse & other helpers for the windows procedure */
+ − 4001 /************************************************************************/
+ − 4002 static void
+ − 4003 mswindows_set_chord_timer (HWND hwnd)
+ − 4004 {
+ − 4005 int interval;
+ − 4006
+ − 4007 /* We get one third half system double click threshold */
+ − 4008 if (mswindows_mouse_button_tolerance <= 0)
+ − 4009 interval = GetDoubleClickTime () / 3;
+ − 4010 else
+ − 4011 interval = mswindows_mouse_button_tolerance;
+ − 4012
+ − 4013 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
+ − 4014 }
+ − 4015
+ − 4016 static int
+ − 4017 mswindows_button2_near_enough (POINTS p1, POINTS p2)
+ − 4018 {
+ − 4019 int dx, dy;
+ − 4020 if (mswindows_mouse_button_max_skew_x <= 0)
+ − 4021 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
+ − 4022 else
+ − 4023 dx = mswindows_mouse_button_max_skew_x;
+ − 4024
+ − 4025 if (mswindows_mouse_button_max_skew_y <= 0)
+ − 4026 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
+ − 4027 else
+ − 4028 dy = mswindows_mouse_button_max_skew_y;
+ − 4029
+ − 4030 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
+ − 4031 }
+ − 4032
+ − 4033 static int
+ − 4034 mswindows_current_layout_has_AltGr (void)
+ − 4035 {
+ − 4036 /* This simple caching mechanism saves 10% of CPU
+ − 4037 time when a key typed at autorepeat rate of 30 cps! */
+ − 4038 static HKL last_hkl = 0;
+ − 4039 static int last_hkl_has_AltGr;
771
+ − 4040 HKL current_hkl = GetKeyboardLayout (0);
+ − 4041
428
+ − 4042 if (current_hkl != last_hkl)
+ − 4043 {
647
+ − 4044 int c;
428
+ − 4045 last_hkl_has_AltGr = 0;
+ − 4046 /* In this loop, we query whether a character requires
+ − 4047 AltGr to be down to generate it. If at least such one
+ − 4048 found, this means that the layout does regard AltGr */
647
+ − 4049 for (c = ' '; c <= 255 && !last_hkl_has_AltGr; ++c)
+ − 4050 /* #### This is not really such a good check. What about under
+ − 4051 CJK locales? It may not matter there, though. We always
+ − 4052 call VkKeyScanA so that we check the locale-specific characters
+ − 4053 in non-Latin-1 locales, instead of just the Latin-1 characters. */
+ − 4054 if (HIBYTE (VkKeyScanA ((char) c)) == 6)
428
+ − 4055 last_hkl_has_AltGr = 1;
+ − 4056 last_hkl = current_hkl;
+ − 4057 }
+ − 4058 return last_hkl_has_AltGr;
+ − 4059 }
+ − 4060
+ − 4061
+ − 4062 /* Returns the state of the modifier keys in the format expected by the
+ − 4063 * Lisp_Event key_data, button_data and motion_data modifiers member */
442
+ − 4064 static int
771
+ − 4065 mswindows_modifier_state (BYTE *keymap, DWORD fwKeys, int has_AltGr)
428
+ − 4066 {
+ − 4067 int mods = 0;
442
+ − 4068 int keys_is_real = 0;
+ − 4069 BYTE keymap2[256];
+ − 4070
+ − 4071 if (fwKeys == (DWORD) -1)
+ − 4072 fwKeys = mswindows_last_mouse_button_state;
+ − 4073 else
+ − 4074 {
+ − 4075 keys_is_real = 1;
+ − 4076 mswindows_last_mouse_button_state = fwKeys;
+ − 4077 }
428
+ − 4078
+ − 4079 if (keymap == NULL)
+ − 4080 {
442
+ − 4081 keymap = keymap2;
428
+ − 4082 GetKeyboardState (keymap);
+ − 4083 has_AltGr = mswindows_current_layout_has_AltGr ();
+ − 4084 }
+ − 4085
442
+ − 4086 /* #### should look at fwKeys for MK_CONTROL. I don't understand how
+ − 4087 AltGr works. */
428
+ − 4088 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
+ − 4089 {
442
+ − 4090 mods |= (keymap [VK_LMENU] & 0x80) ? XEMACS_MOD_META : 0;
+ − 4091 mods |= (keymap [VK_RCONTROL] & 0x80) ? XEMACS_MOD_CONTROL : 0;
428
+ − 4092 }
+ − 4093 else
+ − 4094 {
442
+ − 4095 mods |= (keymap [VK_MENU] & 0x80) ? XEMACS_MOD_META : 0;
+ − 4096 mods |= (keymap [VK_CONTROL] & 0x80) ? XEMACS_MOD_CONTROL : 0;
428
+ − 4097 }
+ − 4098
442
+ − 4099 mods |= (keys_is_real ? fwKeys & MK_SHIFT : (keymap [VK_SHIFT] & 0x80))
+ − 4100 ? XEMACS_MOD_SHIFT : 0;
+ − 4101 mods |= fwKeys & MK_LBUTTON ? XEMACS_MOD_BUTTON1 : 0;
+ − 4102 mods |= fwKeys & MK_MBUTTON ? XEMACS_MOD_BUTTON2 : 0;
+ − 4103 mods |= fwKeys & MK_RBUTTON ? XEMACS_MOD_BUTTON3 : 0;
428
+ − 4104
+ − 4105 return mods;
+ − 4106 }
+ − 4107
+ − 4108 /*
+ − 4109 * Translate a mswindows virtual key to a keysym.
+ − 4110 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
+ − 4111 * or whose ASCII codes (like space) xemacs doesn't like.
+ − 4112 */
+ − 4113 Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
+ − 4114 int extendedp)
+ − 4115 {
+ − 4116 if (extendedp) /* Keys not present on a 82 key keyboard */
+ − 4117 {
+ − 4118 switch (mswindows_key)
+ − 4119 {
442
+ − 4120 case VK_CANCEL: return KEYSYM ("pause");
428
+ − 4121 case VK_RETURN: return KEYSYM ("kp-enter");
+ − 4122 case VK_PRIOR: return KEYSYM ("prior");
+ − 4123 case VK_NEXT: return KEYSYM ("next");
+ − 4124 case VK_END: return KEYSYM ("end");
+ − 4125 case VK_HOME: return KEYSYM ("home");
+ − 4126 case VK_LEFT: return KEYSYM ("left");
+ − 4127 case VK_UP: return KEYSYM ("up");
+ − 4128 case VK_RIGHT: return KEYSYM ("right");
+ − 4129 case VK_DOWN: return KEYSYM ("down");
+ − 4130 case VK_INSERT: return KEYSYM ("insert");
+ − 4131 case VK_DELETE: return QKdelete;
442
+ − 4132 #if 0 /* FSF Emacs allows these to return configurable syms/mods */
+ − 4133 case VK_LWIN return KEYSYM ("");
+ − 4134 case VK_RWIN return KEYSYM ("");
+ − 4135 #endif
+ − 4136 case VK_APPS: return KEYSYM ("menu");
428
+ − 4137 }
+ − 4138 }
+ − 4139 else
+ − 4140 {
+ − 4141 switch (mswindows_key)
+ − 4142 {
771
+ − 4143
+ − 4144 #if 0
+ − 4145 VK_LBUTTON:
+ − 4146 VK_RBUTTON:
+ − 4147 VK_CANCEL:
+ − 4148 VK_MBUTTON:
+ − 4149 VK_XBUTTON1:
+ − 4150 VK_XBUTTON2:
+ − 4151 #endif /* 0 */
+ − 4152
428
+ − 4153 case VK_BACK: return QKbackspace;
+ − 4154 case VK_TAB: return QKtab;
771
+ − 4155 /* #### Officially 0A (and 0B too) are "reserved". */
428
+ − 4156 case '\n': return QKlinefeed;
+ − 4157 case VK_CLEAR: return KEYSYM ("clear");
+ − 4158 case VK_RETURN: return QKreturn;
771
+ − 4159
+ − 4160 #if 0
+ − 4161 VK_SHIFT: "shift"
+ − 4162 VK_CONTROL: "control"
+ − 4163 VK_MENU: "alt"
+ − 4164 #endif /* 0 */
+ − 4165
442
+ − 4166 case VK_PAUSE: return KEYSYM ("pause");
771
+ − 4167
+ − 4168 #if 0
+ − 4169 VK_CAPITAL: "caps-lock"
+ − 4170 VK_KANA: IME Kana mode
+ − 4171 VK_HANGUEL: IME Hanguel mode (maintained for compatibility; use VK_HANGUL)
+ − 4172 VK_HANGUL: IME Hangul mode
+ − 4173 VK_JUNJA: IME Junja mode
+ − 4174 VK_FINAL: IME final mode
+ − 4175 VK_HANJA: IME Hanja mode
+ − 4176 VK_KANJI: IME Kanji mode
+ − 4177 #endif /* 0 */
+ − 4178
428
+ − 4179 case VK_ESCAPE: return QKescape;
771
+ − 4180
+ − 4181 #if 0
+ − 4182 VK_CONVERT: IME convert
+ − 4183 VK_NONCONVERT: IME nonconvert
+ − 4184 VK_ACCEPT: IME accept
+ − 4185 VK_MODECHANGE: IME mode change request
+ − 4186 #endif /* 0 */
+ − 4187
428
+ − 4188 case VK_SPACE: return QKspace;
+ − 4189 case VK_PRIOR: return KEYSYM ("kp-prior");
+ − 4190 case VK_NEXT: return KEYSYM ("kp-next");
+ − 4191 case VK_END: return KEYSYM ("kp-end");
+ − 4192 case VK_HOME: return KEYSYM ("kp-home");
+ − 4193 case VK_LEFT: return KEYSYM ("kp-left");
+ − 4194 case VK_UP: return KEYSYM ("kp-up");
+ − 4195 case VK_RIGHT: return KEYSYM ("kp-right");
+ − 4196 case VK_DOWN: return KEYSYM ("kp-down");
+ − 4197 case VK_SELECT: return KEYSYM ("select");
+ − 4198 case VK_PRINT: return KEYSYM ("print");
+ − 4199 case VK_EXECUTE: return KEYSYM ("execute");
+ − 4200 case VK_SNAPSHOT: return KEYSYM ("print");
+ − 4201 case VK_INSERT: return KEYSYM ("kp-insert");
+ − 4202 case VK_DELETE: return KEYSYM ("kp-delete");
+ − 4203 case VK_HELP: return KEYSYM ("help");
771
+ − 4204 #if 0
+ − 4205 '0' through '9': numeric keys
+ − 4206 'A' through 'Z': alphabetic keys
+ − 4207 VK_LWIN: "lwin"
+ − 4208 VK_RWIN: "rwin"
+ − 4209 VK_APPS: "apps"
+ − 4210 VK_SLEEP: "sleep"
+ − 4211 #endif /* 0 */
428
+ − 4212 case VK_NUMPAD0: return KEYSYM ("kp-0");
+ − 4213 case VK_NUMPAD1: return KEYSYM ("kp-1");
+ − 4214 case VK_NUMPAD2: return KEYSYM ("kp-2");
+ − 4215 case VK_NUMPAD3: return KEYSYM ("kp-3");
+ − 4216 case VK_NUMPAD4: return KEYSYM ("kp-4");
+ − 4217 case VK_NUMPAD5: return KEYSYM ("kp-5");
+ − 4218 case VK_NUMPAD6: return KEYSYM ("kp-6");
+ − 4219 case VK_NUMPAD7: return KEYSYM ("kp-7");
+ − 4220 case VK_NUMPAD8: return KEYSYM ("kp-8");
+ − 4221 case VK_NUMPAD9: return KEYSYM ("kp-9");
+ − 4222 case VK_MULTIPLY: return KEYSYM ("kp-multiply");
+ − 4223 case VK_ADD: return KEYSYM ("kp-add");
+ − 4224 case VK_SEPARATOR: return KEYSYM ("kp-separator");
+ − 4225 case VK_SUBTRACT: return KEYSYM ("kp-subtract");
+ − 4226 case VK_DECIMAL: return KEYSYM ("kp-decimal");
+ − 4227 case VK_DIVIDE: return KEYSYM ("kp-divide");
+ − 4228 case VK_F1: return KEYSYM ("f1");
+ − 4229 case VK_F2: return KEYSYM ("f2");
+ − 4230 case VK_F3: return KEYSYM ("f3");
+ − 4231 case VK_F4: return KEYSYM ("f4");
+ − 4232 case VK_F5: return KEYSYM ("f5");
+ − 4233 case VK_F6: return KEYSYM ("f6");
+ − 4234 case VK_F7: return KEYSYM ("f7");
+ − 4235 case VK_F8: return KEYSYM ("f8");
+ − 4236 case VK_F9: return KEYSYM ("f9");
+ − 4237 case VK_F10: return KEYSYM ("f10");
+ − 4238 case VK_F11: return KEYSYM ("f11");
+ − 4239 case VK_F12: return KEYSYM ("f12");
+ − 4240 case VK_F13: return KEYSYM ("f13");
+ − 4241 case VK_F14: return KEYSYM ("f14");
+ − 4242 case VK_F15: return KEYSYM ("f15");
+ − 4243 case VK_F16: return KEYSYM ("f16");
+ − 4244 case VK_F17: return KEYSYM ("f17");
+ − 4245 case VK_F18: return KEYSYM ("f18");
+ − 4246 case VK_F19: return KEYSYM ("f19");
+ − 4247 case VK_F20: return KEYSYM ("f20");
+ − 4248 case VK_F21: return KEYSYM ("f21");
+ − 4249 case VK_F22: return KEYSYM ("f22");
+ − 4250 case VK_F23: return KEYSYM ("f23");
+ − 4251 case VK_F24: return KEYSYM ("f24");
771
+ − 4252
+ − 4253 #if 0
+ − 4254 VK_NUMLOCK: 90 NUM LOCK key
+ − 4255 VK_SCROLL: 91 SCROLL LOCK key
+ − 4256 92~96 OEM specific;
+ − 4257 VK_LSHIFT:
+ − 4258 VK_RSHIFT:
+ − 4259 VK_LCONTROL:
+ − 4260 VK_RCONTROL:
+ − 4261 VK_LMENU:
+ − 4262 VK_RMENU:
+ − 4263
+ − 4264 #ifdef VK_BROWSER_BACK /* Windows 2000 only */
+ − 4265 VK_BROWSER_BACK: Browser Back key
+ − 4266 VK_BROWSER_FORWARD: Browser Forward key
+ − 4267 VK_BROWSER_REFRESH: Browser Refresh key
+ − 4268 VK_BROWSER_STOP: Browser Stop key
+ − 4269 VK_BROWSER_SEARCH: Browser Search key
+ − 4270 VK_BROWSER_FAVORITES: Browser Favorites key
+ − 4271 VK_BROWSER_HOME: Browser Start and Home key
+ − 4272 VK_VOLUME_MUTE: Volume Mute key
+ − 4273 VK_VOLUME_DOWN: Volume Down key
+ − 4274 VK_VOLUME_UP: Volume Up key
+ − 4275 VK_MEDIA_NEXT_TRACK: Next Track key
+ − 4276 VK_MEDIA_PREV_TRACK: Previous Track key
+ − 4277 VK_MEDIA_STOP: Stop Media key
+ − 4278 VK_MEDIA_PLAY_PAUSE: Play/Pause Media key
+ − 4279 VK_LAUNCH_MAIL: Start Mail key
+ − 4280 VK_LAUNCH_MEDIA_SELECT: Select Media key
+ − 4281 VK_LAUNCH_APP1: Start Application 1 key
+ − 4282 VK_LAUNCH_APP2: Start Application 2 key
+ − 4283 B8-B9 Reserved;
+ − 4284 VK_OEM_1: For the US standard keyboard, the ';:' key
+ − 4285 VK_OEM_PLUS: For any country/region, the '+' key
+ − 4286 VK_OEM_COMMA: For any country/region, the ',' key
+ − 4287 VK_OEM_MINUS: For any country/region, the '-' key
+ − 4288 VK_OEM_PERIOD: For any country/region, the '.' key
+ − 4289 VK_OEM_2: For the US standard keyboard, the '/?' key
+ − 4290 VK_OEM_3: For the US standard keyboard, the '`~' key
+ − 4291 C1~D7 Reserved;
+ − 4292 D8~DA Unassigned;
+ − 4293 VK_OEM_4: For the US standard keyboard, the '[{' key
+ − 4294 VK_OEM_5: For the US standard keyboard, the '\|' key
+ − 4295 VK_OEM_6: For the US standard keyboard, the ']}' key
+ − 4296 VK_OEM_7: For the US standard keyboard, the 'single-quote/double-quote' key
+ − 4297 VK_OEM_8:
+ − 4298 E0 Reserved;
+ − 4299 E1 OEM specific;
+ − 4300 VK_OEM_102: Either the angle bracket key or the backslash key on the RT 102-key keyboard
+ − 4301 E3~E4 OEM specific;
+ − 4302 #endif /* VK_BROWSER_BACK */
+ − 4303 VK_PROCESSKEY: E5 Windows 95/98, Windows NT 4.0, Windows 2000: IME PROCESS key
+ − 4304 E6 OEM specific;
+ − 4305 VK_PACKET: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
+ − 4306 E8 Unassigned;
+ − 4307 E9~F5 OEM specific;
+ − 4308 VK_ATTN: Attn key
+ − 4309 VK_CRSEL: CrSel key
+ − 4310 VK_EXSEL: ExSel key
+ − 4311 VK_EREOF: Erase EOF key
+ − 4312 VK_PLAY: Play key
+ − 4313 VK_ZOOM: Zoom key
+ − 4314 VK_NONAME: Reserved for future use
+ − 4315 VK_PA1: PA1 key
+ − 4316 VK_OEM_CLEAR: Clear key
+ − 4317 #endif /* 0 */
+ − 4318
428
+ − 4319 }
+ − 4320 }
+ − 4321 return Qnil;
+ − 4322 }
+ − 4323
+ − 4324 /*
+ − 4325 * Find the console that matches the supplied mswindows window handle
+ − 4326 */
+ − 4327 Lisp_Object
+ − 4328 mswindows_find_console (HWND hwnd)
+ − 4329 {
+ − 4330 /* We only support one console */
+ − 4331 return XCAR (Vconsole_list);
+ − 4332 }
+ − 4333
+ − 4334 /*
+ − 4335 * Find the frame that matches the supplied mswindows window handle
+ − 4336 */
546
+ − 4337 Lisp_Object
428
+ − 4338 mswindows_find_frame (HWND hwnd)
+ − 4339 {
771
+ − 4340 LONG l = qxeGetWindowLong (hwnd, XWL_FRAMEOBJ);
428
+ − 4341 Lisp_Object f;
+ − 4342 if (l == 0)
+ − 4343 {
+ − 4344 /* We are in progress of frame creation. Return the frame
+ − 4345 being created, as it still not remembered in the window
+ − 4346 extra storage. */
+ − 4347 assert (!NILP (Vmswindows_frame_being_created));
+ − 4348 return Vmswindows_frame_being_created;
+ − 4349 }
826
+ − 4350 f = VOID_TO_LISP ((void *) l);
428
+ − 4351 return f;
+ − 4352 }
+ − 4353
+ − 4354
+ − 4355 /************************************************************************/
+ − 4356 /* methods */
+ − 4357 /************************************************************************/
+ − 4358
+ − 4359 static int
+ − 4360 emacs_mswindows_add_timeout (EMACS_TIME thyme)
+ − 4361 {
+ − 4362 int milliseconds;
+ − 4363 EMACS_TIME current_time;
+ − 4364 EMACS_GET_TIME (current_time);
+ − 4365 EMACS_SUB_TIME (thyme, thyme, current_time);
+ − 4366 milliseconds = EMACS_SECS (thyme) * 1000 +
+ − 4367 (EMACS_USECS (thyme) + 500) / 1000;
+ − 4368 if (milliseconds < 1)
+ − 4369 milliseconds = 1;
+ − 4370 ++mswindows_pending_timers_count;
+ − 4371 return SetTimer (NULL, 0, milliseconds,
+ − 4372 (TIMERPROC) mswindows_wm_timer_callback);
+ − 4373 }
+ − 4374
+ − 4375 static void
+ − 4376 emacs_mswindows_remove_timeout (int id)
+ − 4377 {
440
+ − 4378 Lisp_Event match_against;
428
+ − 4379 Lisp_Object emacs_event;
+ − 4380
+ − 4381 if (KillTimer (NULL, id))
+ − 4382 --mswindows_pending_timers_count;
+ − 4383
+ − 4384 /* If there is a dispatch event generated by this
+ − 4385 timeout in the queue, we have to remove it too. */
+ − 4386 match_against.event_type = timeout_event;
+ − 4387 match_against.event.timeout.interval_id = id;
+ − 4388 emacs_event = mswindows_cancel_dispatch_event (&match_against);
+ − 4389 if (!NILP (emacs_event))
+ − 4390 Fdeallocate_event(emacs_event);
+ − 4391 }
+ − 4392
+ − 4393 /* If `user_p' is false, then return whether there are any win32, timeout,
+ − 4394 * or subprocess events pending (that is, whether
+ − 4395 * emacs_mswindows_next_event() would return immediately without blocking).
+ − 4396 *
+ − 4397 * if `user_p' is true, then return whether there are any *user generated*
+ − 4398 * events available (that is, whether there are keyboard or mouse-click
+ − 4399 * events ready to be read). This also implies that
+ − 4400 * emacs_mswindows_next_event() would not block.
+ − 4401 */
+ − 4402 static int
+ − 4403 emacs_mswindows_event_pending_p (int user_p)
+ − 4404 {
+ − 4405 mswindows_need_event (0);
+ − 4406 return (!NILP (mswindows_u_dispatch_event_queue)
+ − 4407 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
+ − 4408 }
+ − 4409
+ − 4410 /*
+ − 4411 * Return the next event
+ − 4412 */
+ − 4413 static void
440
+ − 4414 emacs_mswindows_next_event (Lisp_Event *emacs_event)
428
+ − 4415 {
+ − 4416 Lisp_Object event, event2;
+ − 4417
+ − 4418 mswindows_need_event (1);
+ − 4419
+ − 4420 event = mswindows_dequeue_dispatch_event ();
793
+ − 4421 event2 = wrap_event (emacs_event);
428
+ − 4422 Fcopy_event (event, event2);
+ − 4423 Fdeallocate_event (event);
+ − 4424 }
+ − 4425
788
+ − 4426 static void
+ − 4427 emacs_mswindows_format_magic_event (Lisp_Event *emacs_event,
+ − 4428 Lisp_Object pstream)
+ − 4429 {
826
+ − 4430 #define FROB(msg) case msg: write_c_string (pstream, "type=" #msg); break
788
+ − 4431
+ − 4432 switch (EVENT_MSWINDOWS_MAGIC_TYPE (emacs_event))
+ − 4433 {
+ − 4434 FROB (XM_BUMPQUEUE);
+ − 4435 FROB (WM_PAINT);
+ − 4436 FROB (WM_SETFOCUS);
+ − 4437 FROB (WM_KILLFOCUS);
+ − 4438 FROB (XM_MAPFRAME);
+ − 4439 FROB (XM_UNMAPFRAME);
+ − 4440
+ − 4441 default: abort ();
+ − 4442 }
+ − 4443 #undef FROB
+ − 4444
+ − 4445 if (!NILP (EVENT_CHANNEL (emacs_event)))
+ − 4446 {
826
+ − 4447 write_c_string (pstream, " ");
788
+ − 4448 print_internal (EVENT_CHANNEL (emacs_event), pstream, 1);
+ − 4449 }
+ − 4450 }
+ − 4451
+ − 4452 static int
+ − 4453 emacs_mswindows_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2)
+ − 4454 {
+ − 4455 return (e1->event.magic.underlying_mswindows_event ==
+ − 4456 e2->event.magic.underlying_mswindows_event);
+ − 4457 }
+ − 4458
+ − 4459 static Hashcode
+ − 4460 emacs_mswindows_hash_magic_event (Lisp_Event *e)
+ − 4461 {
+ − 4462 return e->event.magic.underlying_mswindows_event;
+ − 4463 }
+ − 4464
428
+ − 4465 /*
+ − 4466 * Handle a magic event off the dispatch queue.
+ − 4467 */
+ − 4468 static void
440
+ − 4469 emacs_mswindows_handle_magic_event (Lisp_Event *emacs_event)
428
+ − 4470 {
771
+ − 4471 switch (EVENT_MSWINDOWS_MAGIC_TYPE (emacs_event))
428
+ − 4472 {
+ − 4473 case XM_BUMPQUEUE:
+ − 4474 break;
+ − 4475
442
+ − 4476 case WM_PAINT:
+ − 4477 {
+ − 4478 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
+ − 4479 mswindows_handle_paint (f);
+ − 4480 (FRAME_MSWINDOWS_DATA (f))->paint_pending = 0;
+ − 4481 }
+ − 4482 break;
+ − 4483
428
+ − 4484 case WM_SETFOCUS:
+ − 4485 case WM_KILLFOCUS:
+ − 4486 {
+ − 4487 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
+ − 4488 struct frame *f = XFRAME (frame);
771
+ − 4489 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE (emacs_event) == WM_SETFOCUS);
428
+ − 4490 Lisp_Object conser;
442
+ − 4491 struct gcpro gcpro1;
+ − 4492
+ − 4493 /* On focus change, clear all memory of sticky modifiers
+ − 4494 to avoid non-intuitive behavior. */
+ − 4495 clear_sticky_modifiers ();
428
+ − 4496
+ − 4497 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
442
+ − 4498 GCPRO1 (conser);
428
+ − 4499 emacs_handle_focus_change_preliminary (conser);
+ − 4500 /* Under X the stuff up to here is done in the X event handler.
+ − 4501 I Don't know why */
+ − 4502 emacs_handle_focus_change_final (conser);
442
+ − 4503 UNGCPRO;
428
+ − 4504
+ − 4505 }
+ − 4506 break;
+ − 4507
+ − 4508 case XM_MAPFRAME:
+ − 4509 case XM_UNMAPFRAME:
+ − 4510 {
+ − 4511 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
771
+ − 4512 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE (emacs_event)
428
+ − 4513 == XM_MAPFRAME ?
+ − 4514 Qmap_frame_hook : Qunmap_frame_hook,
+ − 4515 1, frame);
+ − 4516 }
+ − 4517 break;
+ − 4518
+ − 4519 /* #### What about Enter & Leave */
+ − 4520 #if 0
+ − 4521 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
+ − 4522 Qmouse_leave_frame_hook, 1, frame);
+ − 4523 #endif
+ − 4524
+ − 4525 default:
+ − 4526 assert(0);
+ − 4527 }
+ − 4528 }
+ − 4529
853
+ − 4530 #ifndef CYGWIN
+ − 4531
428
+ − 4532 static HANDLE
440
+ − 4533 get_process_input_waitable (Lisp_Process *process)
428
+ − 4534 {
853
+ − 4535 Lisp_Object instr, outstr, errstr, p;
793
+ − 4536 p = wrap_process (process);
853
+ − 4537 get_process_streams (process, &instr, &outstr, &errstr);
428
+ − 4538 assert (!NILP (instr));
+ − 4539 return (network_connection_p (p)
+ − 4540 ? get_winsock_stream_waitable (XLSTREAM (instr))
+ − 4541 : get_ntpipe_input_stream_waitable (XLSTREAM (instr)));
+ − 4542 }
+ − 4543
853
+ − 4544 static HANDLE
+ − 4545 get_process_stderr_waitable (Lisp_Process *process)
+ − 4546 {
+ − 4547 Lisp_Object instr, outstr, errstr;
+ − 4548 get_process_streams (process, &instr, &outstr, &errstr);
+ − 4549 if (NILP (errstr))
+ − 4550 return INVALID_HANDLE_VALUE;
+ − 4551 return get_ntpipe_input_stream_waitable (XLSTREAM (errstr));
+ − 4552 }
+ − 4553
+ − 4554 #endif /* not CYGWIN */
+ − 4555
428
+ − 4556 static void
853
+ − 4557 emacs_mswindows_select_process (Lisp_Process *process, int doin, int doerr)
428
+ − 4558 {
853
+ − 4559 #ifdef CYGWIN
+ − 4560 int infd, errfd;
+ − 4561
+ − 4562 event_stream_unixoid_select_process (process, doin, doerr, &infd, &errfd);
+ − 4563 #else
+ − 4564 HANDLE hev = INVALID_HANDLE_VALUE;
+ − 4565 HANDLE herr = INVALID_HANDLE_VALUE;
+ − 4566
+ − 4567 if (doin)
+ − 4568 {
+ − 4569 hev = get_process_input_waitable (process);
+ − 4570 if (!add_waitable_handle (hev))
+ − 4571 {
+ − 4572 hev = INVALID_HANDLE_VALUE;
+ − 4573 goto err;
+ − 4574 }
+ − 4575 }
+ − 4576
+ − 4577 if (doerr)
+ − 4578 {
+ − 4579 herr = get_process_stderr_waitable (process);
+ − 4580 if (herr != INVALID_HANDLE_VALUE && !add_waitable_handle (herr))
+ − 4581 {
+ − 4582 herr = INVALID_HANDLE_VALUE;
+ − 4583 goto err;
+ − 4584 }
+ − 4585 }
+ − 4586
428
+ − 4587 {
853
+ − 4588 /* Also select on the process handle itself, so we can receive
+ − 4589 exit notifications. Only do this once, not each time this
+ − 4590 function is called (which can happen many times, e.g. if
+ − 4591 (set-process-filter proc t) is called and then a process filter
+ − 4592 is set again). It will be unselected in mswindows_need_event(). */
793
+ − 4593 Lisp_Object p = wrap_process (process);
+ − 4594
428
+ − 4595 if (!network_connection_p (p))
+ − 4596 {
853
+ − 4597 HANDLE hprocess = get_nt_process_handle_only_first_time (process);
+ − 4598 if (hprocess != INVALID_HANDLE_VALUE
+ − 4599 && !add_waitable_handle (hprocess))
+ − 4600 goto err;
428
+ − 4601 }
+ − 4602 }
853
+ − 4603
+ − 4604 return;
+ − 4605
+ − 4606 err:
+ − 4607 if (hev != INVALID_HANDLE_VALUE)
+ − 4608 remove_waitable_handle (hev);
+ − 4609 if (herr != INVALID_HANDLE_VALUE)
+ − 4610 remove_waitable_handle (herr);
+ − 4611 invalid_operation ("Too many active processes", wrap_process (process));
+ − 4612 #endif /* CYGWIN */
428
+ − 4613 }
+ − 4614
+ − 4615 static void
853
+ − 4616 emacs_mswindows_unselect_process (Lisp_Process *process, int doin, int doerr)
428
+ − 4617 {
853
+ − 4618 #ifdef CYGWIN
+ − 4619 int infd, errfd;
+ − 4620
+ − 4621 event_stream_unixoid_unselect_process (process, doin, doerr, &infd, &errfd);
+ − 4622 #else
+ − 4623 if (doin)
+ − 4624 {
+ − 4625 /* Process handle is removed in the event loop as soon
+ − 4626 as it is signaled, so don't bother here about it */
+ − 4627 HANDLE hev = get_process_input_waitable (process);
+ − 4628 remove_waitable_handle (hev);
+ − 4629 }
+ − 4630 if (doerr)
+ − 4631 {
+ − 4632 /* Process handle is removed in the event loop as soon
+ − 4633 as it is signaled, so don't bother here about it */
+ − 4634 HANDLE herr = get_process_stderr_waitable (process);
+ − 4635 if (herr != INVALID_HANDLE_VALUE)
+ − 4636 remove_waitable_handle (herr);
+ − 4637 }
+ − 4638 #endif /* CYGWIN */
428
+ − 4639 }
+ − 4640
+ − 4641 static void
+ − 4642 emacs_mswindows_select_console (struct console *con)
+ − 4643 {
853
+ − 4644 #ifdef CYGWIN
428
+ − 4645 if (CONSOLE_MSWINDOWS_P (con))
+ − 4646 return; /* mswindows consoles are automatically selected */
+ − 4647
+ − 4648 event_stream_unixoid_select_console (con);
+ − 4649 #endif
+ − 4650 }
+ − 4651
+ − 4652 static void
+ − 4653 emacs_mswindows_unselect_console (struct console *con)
+ − 4654 {
853
+ − 4655 #ifdef CYGWIN
428
+ − 4656 if (CONSOLE_MSWINDOWS_P (con))
+ − 4657 return; /* mswindows consoles are automatically selected */
+ − 4658
+ − 4659 event_stream_unixoid_unselect_console (con);
+ − 4660 #endif
+ − 4661 }
+ − 4662
+ − 4663 static void
+ − 4664 emacs_mswindows_quit_p (void)
+ − 4665 {
+ − 4666 /* Quit cannot happen in modal loop: all program
+ − 4667 input is dedicated to Windows. */
+ − 4668 if (mswindows_in_modal_loop)
+ − 4669 return;
+ − 4670
593
+ − 4671 mswindows_quit_chars_count = 0;
502
+ − 4672 /* Drain windows queue. This sets up number of quit characters in
+ − 4673 the queue. */
442
+ − 4674 mswindows_drain_windows_queue ();
428
+ − 4675
+ − 4676 if (mswindows_quit_chars_count > 0)
+ − 4677 {
+ − 4678 /* Yes there's a hidden one... Throw it away */
440
+ − 4679 Lisp_Event match_against;
428
+ − 4680 Lisp_Object emacs_event;
440
+ − 4681 int critical_p = 0;
428
+ − 4682
+ − 4683 match_against.event_type = key_press_event;
+ − 4684 match_against.event.key.modifiers = FAKE_MOD_QUIT;
+ − 4685
593
+ − 4686 while (mswindows_quit_chars_count > 0)
440
+ − 4687 {
+ − 4688 emacs_event = mswindows_cancel_dispatch_event (&match_against);
+ − 4689 assert (!NILP (emacs_event));
442
+ − 4690
502
+ − 4691 if (XEVENT (emacs_event)->event.key.modifiers &
+ − 4692 FAKE_MOD_QUIT_CRITICAL)
440
+ − 4693 critical_p = 1;
+ − 4694
502
+ − 4695 Fdeallocate_event (emacs_event);
593
+ − 4696 mswindows_quit_chars_count--;
440
+ − 4697 }
+ − 4698
+ − 4699 Vquit_flag = critical_p ? Qcritical : Qt;
428
+ − 4700 }
+ − 4701 }
+ − 4702
853
+ − 4703 static void
+ − 4704 emacs_mswindows_create_io_streams (void *inhandle, void *outhandle,
+ − 4705 void *errhandle, Lisp_Object *instream,
+ − 4706 Lisp_Object *outstream,
+ − 4707 Lisp_Object *errstream,
+ − 4708 USID *in_usid,
+ − 4709 USID *err_usid,
+ − 4710 int flags)
428
+ − 4711 {
853
+ − 4712 #ifdef CYGWIN
+ − 4713 event_stream_unixoid_create_io_streams (inhandle, outhandle,
+ − 4714 errhandle, instream,
+ − 4715 outstream, errstream,
+ − 4716 in_usid, err_usid, flags);
+ − 4717 #else
428
+ − 4718 /* Handles for streams */
853
+ − 4719 HANDLE hin, hout, herr;
428
+ − 4720 /* fds. These just stored along with the streams, and are closed in
+ − 4721 delete stream pair method, because we need to handle fake unices
+ − 4722 here. */
853
+ − 4723 int fdi, fdo, fde;
+ − 4724
+ − 4725 /* Decode inhandle, outhandle, errhandle. Their meaning depends on
428
+ − 4726 the process implementation being used. */
+ − 4727 hin = (HANDLE) inhandle;
+ − 4728 hout = (HANDLE) outhandle;
853
+ − 4729 if (errhandle == (void *) -1)
+ − 4730 herr = INVALID_HANDLE_VALUE;
+ − 4731 else
+ − 4732 herr = (HANDLE) errhandle;
+ − 4733 fdi = fdo = fde = -1;
428
+ − 4734
+ − 4735 *instream = (hin == INVALID_HANDLE_VALUE
+ − 4736 ? Qnil
+ − 4737 : flags & STREAM_NETWORK_CONNECTION
853
+ − 4738 ? make_winsock_input_stream ((SOCKET) hin, fdi)
428
+ − 4739 : make_ntpipe_input_stream (hin, fdi));
+ − 4740
853
+ − 4741 *errstream = (herr == INVALID_HANDLE_VALUE
+ − 4742 ? Qnil
+ − 4743 : make_ntpipe_input_stream (herr, fde));
+ − 4744
428
+ − 4745 *outstream = (hout == INVALID_HANDLE_VALUE
+ − 4746 ? Qnil
+ − 4747 : flags & STREAM_NETWORK_CONNECTION
+ − 4748 ? make_winsock_output_stream ((SOCKET)hout, fdo)
+ − 4749 : make_ntpipe_output_stream (hout, fdo));
853
+ − 4750
+ − 4751 *in_usid =
+ − 4752 (NILP (*instream)
+ − 4753 ? USID_ERROR
+ − 4754 : flags & STREAM_NETWORK_CONNECTION
+ − 4755 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (*instream)))
+ − 4756 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
+ − 4757 (*instream))));
+ − 4758
+ − 4759 *err_usid =
+ − 4760 (NILP (*errstream)
+ − 4761 ? USID_DONTHASH
+ − 4762 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
+ − 4763 (*errstream))));
+ − 4764 #endif /* CYGWIN */
428
+ − 4765 }
+ − 4766
853
+ − 4767 static void
+ − 4768 emacs_mswindows_delete_io_streams (Lisp_Object instream,
+ − 4769 Lisp_Object outstream,
+ − 4770 Lisp_Object errstream,
+ − 4771 USID *in_usid,
+ − 4772 USID *err_usid)
428
+ − 4773 {
853
+ − 4774 #ifdef CYGWIN
+ − 4775 event_stream_unixoid_delete_io_streams (instream, outstream, errstream,
+ − 4776 in_usid, err_usid);
+ − 4777 #else
+ − 4778 *in_usid =
+ − 4779 (NILP (instream)
+ − 4780 ? USID_DONTHASH
+ − 4781 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
+ − 4782 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (instream)))
+ − 4783 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
+ − 4784 (instream))));
+ − 4785
+ − 4786 *err_usid =
+ − 4787 (NILP (errstream)
+ − 4788 ? USID_DONTHASH
+ − 4789 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
+ − 4790 (errstream))));
+ − 4791 #endif /* CYGWIN */
428
+ − 4792 }
+ − 4793
442
+ − 4794 static int
+ − 4795 emacs_mswindows_current_event_timestamp (struct console *c)
+ − 4796 {
+ − 4797 return GetTickCount ();
+ − 4798 }
+ − 4799
428
+ − 4800 #ifndef HAVE_X_WINDOWS
+ − 4801 /* This is called from GC when a process object is about to be freed.
+ − 4802 If we've still got pointers to it in this file, we're gonna lose hard.
853
+ − 4803 */
+ − 4804 void debug_process_finalization (Lisp_Process *p);
428
+ − 4805 void
440
+ − 4806 debug_process_finalization (Lisp_Process *p)
428
+ − 4807 {
+ − 4808 #if 0 /* #### */
853
+ − 4809 Lisp_Object instr, outstr, errstr;
+ − 4810
+ − 4811 get_process_streams (p, &instr, &outstr, &errstr);
428
+ − 4812 /* if it still has fds, then it hasn't been killed yet. */
771
+ − 4813 assert (NILP (instr));
+ − 4814 assert (NILP (outstr));
853
+ − 4815 assert (NILP (errstr));
428
+ − 4816
+ − 4817 /* #### More checks here */
+ − 4818 #endif
+ − 4819 }
+ − 4820 #endif
+ − 4821
593
+ − 4822 #ifdef DEBUG_XEMACS
+ − 4823
+ − 4824 struct mswin_message_debug
+ − 4825 {
+ − 4826 int mess;
+ − 4827 char *string;
+ − 4828 };
+ − 4829
+ − 4830 #define FROB(val) { val, #val, },
+ − 4831
+ − 4832 struct mswin_message_debug debug_mswin_messages[] =
+ − 4833 {
+ − 4834 FROB (WM_NULL)
+ − 4835 FROB (WM_CREATE)
+ − 4836 FROB (WM_DESTROY)
+ − 4837 FROB (WM_MOVE)
+ − 4838 FROB (WM_SIZE)
+ − 4839
+ − 4840 FROB (WM_ACTIVATE)
+ − 4841
+ − 4842 FROB (WM_SETFOCUS)
+ − 4843 FROB (WM_KILLFOCUS)
+ − 4844 FROB (WM_ENABLE)
+ − 4845 FROB (WM_SETREDRAW)
+ − 4846 FROB (WM_SETTEXT)
+ − 4847 FROB (WM_GETTEXT)
+ − 4848 FROB (WM_GETTEXTLENGTH)
+ − 4849 FROB (WM_PAINT)
+ − 4850 FROB (WM_CLOSE)
+ − 4851 FROB (WM_QUERYENDSESSION)
+ − 4852 FROB (WM_QUIT)
+ − 4853 FROB (WM_QUERYOPEN)
+ − 4854 FROB (WM_ERASEBKGND)
+ − 4855 FROB (WM_SYSCOLORCHANGE)
+ − 4856 FROB (WM_ENDSESSION)
+ − 4857 FROB (WM_SHOWWINDOW)
+ − 4858 FROB (WM_WININICHANGE)
+ − 4859 #if(WINVER >= 0x0400)
+ − 4860 FROB (WM_SETTINGCHANGE)
+ − 4861 #endif /* WINVER >= 0x0400 */
+ − 4862
+ − 4863 FROB (WM_DEVMODECHANGE)
+ − 4864 FROB (WM_ACTIVATEAPP)
+ − 4865 FROB (WM_FONTCHANGE)
+ − 4866 FROB (WM_TIMECHANGE)
+ − 4867 FROB (WM_CANCELMODE)
+ − 4868 FROB (WM_SETCURSOR)
+ − 4869 FROB (WM_MOUSEACTIVATE)
+ − 4870 FROB (WM_CHILDACTIVATE)
+ − 4871 FROB (WM_QUEUESYNC)
+ − 4872
+ − 4873 FROB (WM_GETMINMAXINFO)
+ − 4874
+ − 4875 FROB (WM_PAINTICON)
+ − 4876 FROB (WM_ICONERASEBKGND)
+ − 4877 FROB (WM_NEXTDLGCTL)
+ − 4878 FROB (WM_SPOOLERSTATUS)
+ − 4879 FROB (WM_DRAWITEM)
+ − 4880 FROB (WM_MEASUREITEM)
+ − 4881 FROB (WM_DELETEITEM)
+ − 4882 FROB (WM_VKEYTOITEM)
+ − 4883 FROB (WM_CHARTOITEM)
+ − 4884 FROB (WM_SETFONT)
+ − 4885 FROB (WM_GETFONT)
+ − 4886 FROB (WM_SETHOTKEY)
+ − 4887 FROB (WM_GETHOTKEY)
+ − 4888 FROB (WM_QUERYDRAGICON)
+ − 4889 FROB (WM_COMPAREITEM)
+ − 4890 #if(WINVER >= 0x0500)
+ − 4891 FROB (WM_GETOBJECT)
+ − 4892 #endif /* WINVER >= 0x0500 */
+ − 4893 FROB (WM_COMPACTING)
+ − 4894 FROB (WM_COMMNOTIFY)
+ − 4895 FROB (WM_WINDOWPOSCHANGING)
+ − 4896 FROB (WM_WINDOWPOSCHANGED)
+ − 4897
+ − 4898 FROB (WM_POWER)
+ − 4899
+ − 4900 FROB (WM_COPYDATA)
+ − 4901 FROB (WM_CANCELJOURNAL)
+ − 4902
+ − 4903 #if(WINVER >= 0x0400)
+ − 4904 FROB (WM_NOTIFY)
+ − 4905 FROB (WM_INPUTLANGCHANGEREQUEST)
+ − 4906 FROB (WM_INPUTLANGCHANGE)
+ − 4907 FROB (WM_TCARD)
+ − 4908 FROB (WM_HELP)
+ − 4909 FROB (WM_USERCHANGED)
+ − 4910 FROB (WM_NOTIFYFORMAT)
+ − 4911
+ − 4912 FROB (WM_CONTEXTMENU)
+ − 4913 FROB (WM_STYLECHANGING)
+ − 4914 FROB (WM_STYLECHANGED)
+ − 4915 FROB (WM_DISPLAYCHANGE)
+ − 4916 FROB (WM_GETICON)
+ − 4917 FROB (WM_SETICON)
+ − 4918 #endif /* WINVER >= 0x0400 */
+ − 4919
+ − 4920 FROB (WM_NCCREATE)
+ − 4921 FROB (WM_NCDESTROY)
+ − 4922 FROB (WM_NCCALCSIZE)
+ − 4923 FROB (WM_NCHITTEST)
+ − 4924 FROB (WM_NCPAINT)
+ − 4925 FROB (WM_NCACTIVATE)
+ − 4926 FROB (WM_GETDLGCODE)
604
+ − 4927 #ifdef WM_SYNCPAINT /* not in VC 5 */
593
+ − 4928 FROB (WM_SYNCPAINT)
604
+ − 4929 #endif /* WM_SYNCPAINT */
593
+ − 4930 FROB (WM_NCMOUSEMOVE)
+ − 4931 FROB (WM_NCLBUTTONDOWN)
+ − 4932 FROB (WM_NCLBUTTONUP)
+ − 4933 FROB (WM_NCLBUTTONDBLCLK)
+ − 4934 FROB (WM_NCRBUTTONDOWN)
+ − 4935 FROB (WM_NCRBUTTONUP)
+ − 4936 FROB (WM_NCRBUTTONDBLCLK)
+ − 4937 FROB (WM_NCMBUTTONDOWN)
+ − 4938 FROB (WM_NCMBUTTONUP)
+ − 4939 FROB (WM_NCMBUTTONDBLCLK)
+ − 4940
+ − 4941 /* FROB (WM_KEYFIRST) */
+ − 4942 FROB (WM_KEYDOWN)
+ − 4943 FROB (WM_KEYUP)
+ − 4944 FROB (WM_CHAR)
+ − 4945 FROB (WM_DEADCHAR)
+ − 4946 FROB (WM_SYSKEYDOWN)
+ − 4947 FROB (WM_SYSKEYUP)
+ − 4948 FROB (WM_SYSCHAR)
+ − 4949 FROB (WM_SYSDEADCHAR)
+ − 4950 FROB (WM_KEYLAST)
+ − 4951
604
+ − 4952 #if(WINVER >= 0x0400) && defined (WM_IME_STARTCOMPOSITION)
+ − 4953 /* not in Cygwin? */
593
+ − 4954 FROB (WM_IME_STARTCOMPOSITION)
+ − 4955 FROB (WM_IME_ENDCOMPOSITION)
+ − 4956 FROB (WM_IME_COMPOSITION)
+ − 4957 FROB (WM_IME_KEYLAST)
604
+ − 4958 #endif /* WINVER >= 0x0400 && defined (WM_IME_STARTCOMPOSITION) */
593
+ − 4959
+ − 4960 FROB (WM_INITDIALOG)
+ − 4961 FROB (WM_COMMAND)
+ − 4962 FROB (WM_SYSCOMMAND)
+ − 4963 FROB (WM_TIMER)
+ − 4964 FROB (WM_HSCROLL)
+ − 4965 FROB (WM_VSCROLL)
+ − 4966 FROB (WM_INITMENU)
+ − 4967 FROB (WM_INITMENUPOPUP)
+ − 4968 FROB (WM_MENUSELECT)
+ − 4969 FROB (WM_MENUCHAR)
+ − 4970 FROB (WM_ENTERIDLE)
+ − 4971 #if(WINVER >= 0x0500)
+ − 4972 FROB (WM_MENURBUTTONUP)
+ − 4973 FROB (WM_MENUDRAG)
+ − 4974 FROB (WM_MENUGETOBJECT)
+ − 4975 FROB (WM_UNINITMENUPOPUP)
+ − 4976 FROB (WM_MENUCOMMAND)
+ − 4977 #endif /* WINVER >= 0x0500 */
+ − 4978
+ − 4979
+ − 4980 FROB (WM_CTLCOLORMSGBOX)
+ − 4981 FROB (WM_CTLCOLOREDIT)
+ − 4982 FROB (WM_CTLCOLORLISTBOX)
+ − 4983 FROB (WM_CTLCOLORBTN)
+ − 4984 FROB (WM_CTLCOLORDLG)
+ − 4985 FROB (WM_CTLCOLORSCROLLBAR)
+ − 4986 FROB (WM_CTLCOLORSTATIC)
+ − 4987
+ − 4988
+ − 4989 /* FROB (WM_MOUSEFIRST) */
+ − 4990 FROB (WM_MOUSEMOVE)
+ − 4991 FROB (WM_LBUTTONDOWN)
+ − 4992 FROB (WM_LBUTTONUP)
+ − 4993 FROB (WM_LBUTTONDBLCLK)
+ − 4994 FROB (WM_RBUTTONDOWN)
+ − 4995 FROB (WM_RBUTTONUP)
+ − 4996 FROB (WM_RBUTTONDBLCLK)
+ − 4997 FROB (WM_MBUTTONDOWN)
+ − 4998 FROB (WM_MBUTTONUP)
+ − 4999 FROB (WM_MBUTTONDBLCLK)
+ − 5000
+ − 5001 #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
+ − 5002 FROB (WM_MOUSEWHEEL)
+ − 5003 FROB (WM_MOUSELAST)
+ − 5004 #else
+ − 5005 FROB (WM_MOUSELAST)
+ − 5006 #endif /* if (_WIN32_WINNT < 0x0400) */
+ − 5007
+ − 5008 FROB (WM_PARENTNOTIFY)
+ − 5009 FROB (WM_ENTERMENULOOP)
+ − 5010 FROB (WM_EXITMENULOOP)
+ − 5011
+ − 5012 #if(WINVER >= 0x0400)
+ − 5013 FROB (WM_NEXTMENU)
+ − 5014
+ − 5015 FROB (WM_SIZING)
+ − 5016 FROB (WM_CAPTURECHANGED)
+ − 5017 FROB (WM_MOVING)
+ − 5018 FROB (WM_POWERBROADCAST)
+ − 5019
+ − 5020 FROB (WM_DEVICECHANGE)
+ − 5021
+ − 5022 #endif /* WINVER >= 0x0400 */
+ − 5023
+ − 5024 FROB (WM_MDICREATE)
+ − 5025 FROB (WM_MDIDESTROY)
+ − 5026 FROB (WM_MDIACTIVATE)
+ − 5027 FROB (WM_MDIRESTORE)
+ − 5028 FROB (WM_MDINEXT)
+ − 5029 FROB (WM_MDIMAXIMIZE)
+ − 5030 FROB (WM_MDITILE)
+ − 5031 FROB (WM_MDICASCADE)
+ − 5032 FROB (WM_MDIICONARRANGE)
+ − 5033 FROB (WM_MDIGETACTIVE)
+ − 5034
+ − 5035
+ − 5036 FROB (WM_MDISETMENU)
+ − 5037 FROB (WM_ENTERSIZEMOVE)
+ − 5038 FROB (WM_EXITSIZEMOVE)
+ − 5039 FROB (WM_DROPFILES)
+ − 5040 FROB (WM_MDIREFRESHMENU)
+ − 5041
604
+ − 5042 #ifdef WM_IME_SETCONTEXT /* not in Cygwin? */
593
+ − 5043
+ − 5044 #if(WINVER >= 0x0400)
+ − 5045 FROB (WM_IME_SETCONTEXT)
+ − 5046 FROB (WM_IME_NOTIFY)
+ − 5047 FROB (WM_IME_CONTROL)
+ − 5048 FROB (WM_IME_COMPOSITIONFULL)
+ − 5049 FROB (WM_IME_SELECT)
+ − 5050 FROB (WM_IME_CHAR)
+ − 5051 #endif /* WINVER >= 0x0400 */
+ − 5052 #if(WINVER >= 0x0500)
+ − 5053 FROB (WM_IME_REQUEST)
+ − 5054 #endif /* WINVER >= 0x0500 */
+ − 5055 #if(WINVER >= 0x0400)
+ − 5056 FROB (WM_IME_KEYDOWN)
+ − 5057 FROB (WM_IME_KEYUP)
+ − 5058 #endif /* WINVER >= 0x0400 */
+ − 5059
604
+ − 5060 #endif /* WM_IME_SETCONTEXT */
593
+ − 5061
+ − 5062 #if(_WIN32_WINNT >= 0x0400)
+ − 5063 FROB (WM_MOUSEHOVER)
+ − 5064 FROB (WM_MOUSELEAVE)
+ − 5065 #endif /* _WIN32_WINNT >= 0x0400 */
+ − 5066
+ − 5067 FROB (WM_CUT)
+ − 5068 FROB (WM_COPY)
+ − 5069 FROB (WM_PASTE)
+ − 5070 FROB (WM_CLEAR)
+ − 5071 FROB (WM_UNDO)
+ − 5072 FROB (WM_RENDERFORMAT)
+ − 5073 FROB (WM_RENDERALLFORMATS)
+ − 5074 FROB (WM_DESTROYCLIPBOARD)
+ − 5075 FROB (WM_DRAWCLIPBOARD)
+ − 5076 FROB (WM_PAINTCLIPBOARD)
+ − 5077 FROB (WM_VSCROLLCLIPBOARD)
+ − 5078 FROB (WM_SIZECLIPBOARD)
+ − 5079 FROB (WM_ASKCBFORMATNAME)
+ − 5080 FROB (WM_CHANGECBCHAIN)
+ − 5081 FROB (WM_HSCROLLCLIPBOARD)
+ − 5082 FROB (WM_QUERYNEWPALETTE)
+ − 5083 FROB (WM_PALETTEISCHANGING)
+ − 5084 FROB (WM_PALETTECHANGED)
+ − 5085 FROB (WM_HOTKEY)
+ − 5086
+ − 5087 #if(WINVER >= 0x0400)
+ − 5088 FROB (WM_PRINT)
+ − 5089 FROB (WM_PRINTCLIENT)
+ − 5090
+ − 5091 FROB (WM_HANDHELDFIRST)
+ − 5092 FROB (WM_HANDHELDLAST)
+ − 5093
+ − 5094 FROB (WM_AFXFIRST)
+ − 5095 FROB (WM_AFXLAST)
+ − 5096 #endif /* WINVER >= 0x0400 */
+ − 5097
+ − 5098 FROB (WM_PENWINFIRST)
+ − 5099 FROB (WM_PENWINLAST)
+ − 5100 };
+ − 5101
+ − 5102 #undef FROB
+ − 5103
+ − 5104 static void
+ − 5105 debug_output_mswin_message (HWND hwnd, UINT message_, WPARAM wParam,
+ − 5106 LPARAM lParam)
+ − 5107 {
+ − 5108 Lisp_Object frame = mswindows_find_frame (hwnd);
+ − 5109 int i;
+ − 5110 char *str = 0;
+ − 5111 /* struct mswin_message_debug *i_hate_cranking_out_code_like_this; */
+ − 5112
+ − 5113 for (i = 0; i < countof (debug_mswin_messages); i++)
+ − 5114 {
647
+ − 5115 if (debug_mswin_messages[i].mess == (int) message_)
593
+ − 5116 {
+ − 5117 str = debug_mswin_messages[i].string;
+ − 5118 break;
+ − 5119 }
+ − 5120 }
+ − 5121
+ − 5122 if (str)
+ − 5123 stderr_out ("%s", str);
+ − 5124 else
+ − 5125 stderr_out ("%x", message_);
+ − 5126
+ − 5127 if (debug_mswindows_events > 1)
+ − 5128 {
+ − 5129 stderr_out (" wparam=%d lparam=%d hwnd=%x frame: ",
+ − 5130 wParam, (int) lParam, (unsigned int) hwnd);
+ − 5131 debug_print (frame);
903
+ − 5132 if (message_ == WM_WINDOWPOSCHANGED ||
+ − 5133 message_ == WM_WINDOWPOSCHANGING)
+ − 5134 {
+ − 5135 WINDOWPOS *wp = (WINDOWPOS *) lParam;
+ − 5136 stderr_out(" WINDOWPOS: x=%d, y=%d, h=%d, w=%d\n",
+ − 5137 wp->x, wp->y, wp->cx, wp->cy);
+ − 5138 }
+ − 5139 else if (message_ == WM_MOVE)
+ − 5140 {
+ − 5141 int x = (int)(short) LOWORD(lParam); /* horizontal position */
+ − 5142 int y = (int)(short) HIWORD(lParam); /* vertical position */
+ − 5143 stderr_out(" MOVE: x=%d, y=%d\n", x, y);
+ − 5144 }
+ − 5145 else if (message_ == WM_SIZE)
+ − 5146 {
+ − 5147 int w = (int)(short) LOWORD(lParam); /* width */
+ − 5148 int h = (int)(short) HIWORD(lParam); /* height */
+ − 5149 stderr_out(" SIZE: w=%d, h=%d\n", w, h);
+ − 5150 }
593
+ − 5151 }
+ − 5152 else
+ − 5153 stderr_out ("\n");
+ − 5154 }
+ − 5155
+ − 5156 #endif /* DEBUG_XEMACS */
+ − 5157
428
+ − 5158 /************************************************************************/
+ − 5159 /* initialization */
+ − 5160 /************************************************************************/
+ − 5161
+ − 5162 void
+ − 5163 reinit_vars_of_event_mswindows (void)
+ − 5164 {
+ − 5165 mswindows_in_modal_loop = 0;
+ − 5166 mswindows_pending_timers_count = 0;
+ − 5167
+ − 5168 mswindows_event_stream = xnew (struct event_stream);
+ − 5169
+ − 5170 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
442
+ − 5171 mswindows_event_stream->force_event_pending = 0;
428
+ − 5172 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
+ − 5173 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
788
+ − 5174 mswindows_event_stream->format_magic_event_cb = emacs_mswindows_format_magic_event;
+ − 5175 mswindows_event_stream->compare_magic_event_cb= emacs_mswindows_compare_magic_event;
+ − 5176 mswindows_event_stream->hash_magic_event_cb = emacs_mswindows_hash_magic_event;
428
+ − 5177 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
+ − 5178 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
+ − 5179 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
+ − 5180 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
+ − 5181 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
+ − 5182 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
+ − 5183 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
853
+ − 5184 mswindows_event_stream->create_io_streams_cb = emacs_mswindows_create_io_streams;
+ − 5185 mswindows_event_stream->delete_io_streams_cb = emacs_mswindows_delete_io_streams;
442
+ − 5186 mswindows_event_stream->current_event_timestamp_cb =
+ − 5187 emacs_mswindows_current_event_timestamp;
903
+ − 5188
+ − 5189 dde_eval_pending = 0;
428
+ − 5190 }
+ − 5191
+ − 5192 void
+ − 5193 vars_of_event_mswindows (void)
+ − 5194 {
+ − 5195 reinit_vars_of_event_mswindows ();
+ − 5196
+ − 5197 mswindows_u_dispatch_event_queue = Qnil;
+ − 5198 staticpro (&mswindows_u_dispatch_event_queue);
+ − 5199 mswindows_u_dispatch_event_queue_tail = Qnil;
452
+ − 5200 dump_add_root_object (&mswindows_u_dispatch_event_queue_tail);
428
+ − 5201
+ − 5202 mswindows_s_dispatch_event_queue = Qnil;
+ − 5203 staticpro (&mswindows_s_dispatch_event_queue);
+ − 5204 mswindows_s_dispatch_event_queue_tail = Qnil;
452
+ − 5205 dump_add_root_object (&mswindows_s_dispatch_event_queue_tail);
428
+ − 5206
853
+ − 5207 mswindows_error_caught_in_modal_loop = 0;
442
+ − 5208
903
+ − 5209 #ifdef HAVE_DRAGNDROP
+ − 5210 Fprovide (Qdde);
+ − 5211
+ − 5212 DEFVAR_LISP ("dde-advise-items", &Vdde_advise_items /*
+ − 5213 A list of allocated DDE advise items.
+ − 5214 Each item is an uninterned symbol, created using dde-alloc-advise-item.
+ − 5215
+ − 5216 The symbol's value is the data which is returned to the DDE client when
+ − 5217 a request for the item is made (or a dde-advise call is made).
+ − 5218
+ − 5219 The symbol also has a 'HSZ property, which holds the DDE string handle
+ − 5220 for the item, as a float. This is for internal use only, and should not
+ − 5221 be modified.
+ − 5222 */ );
+ − 5223 Vdde_advise_items = Qnil;
+ − 5224
+ − 5225 dde_eval_result = Qnil;
+ − 5226 staticpro (&dde_eval_result);
+ − 5227 dde_eval_error = Qnil;
+ − 5228 staticpro (&dde_eval_error);
+ − 5229 #endif
+ − 5230
442
+ − 5231 #ifdef DEBUG_XEMACS
+ − 5232 DEFVAR_INT ("debug-mswindows-events", &debug_mswindows_events /*
593
+ − 5233 If non-zero, display debug information about Windows messages that XEmacs sees.
442
+ − 5234 Information is displayed in a console window. Currently defined values are:
+ − 5235
593
+ − 5236 1 == non-verbose output (just the message name)
+ − 5237 2 == verbose output (all parameters)
+ − 5238 3 == even more verbose output (extra debugging info)
442
+ − 5239 */ );
+ − 5240 debug_mswindows_events = 0;
+ − 5241 #endif
+ − 5242
+ − 5243 DEFVAR_BOOL ("mswindows-alt-by-itself-activates-menu",
+ − 5244 &mswindows_alt_by_itself_activates_menu /*
+ − 5245 *Controls whether pressing and releasing the Alt key activates the menubar.
+ − 5246 This applies only if no intervening key was pressed. See also
+ − 5247 `menu-accelerator-enabled', which is probably the behavior you actually want.
428
+ − 5248 Default is t.
+ − 5249 */ );
+ − 5250
442
+ − 5251 DEFVAR_BOOL ("mswindows-dynamic-frame-resize",
+ − 5252 &mswindows_dynamic_frame_resize /*
428
+ − 5253 *Controls redrawing frame contents during mouse-drag or keyboard resize
+ − 5254 operation. When non-nil, the frame is redrawn while being resized. When
+ − 5255 nil, frame is not redrawn, and exposed areas are filled with default
+ − 5256 MDI application background color. Note that this option only has effect
+ − 5257 if "Show window contents while dragging" is on in system Display/Plus!
+ − 5258 settings.
+ − 5259 Default is t on fast machines, nil on slow.
+ − 5260 */ );
+ − 5261
442
+ − 5262 DEFVAR_INT ("mswindows-mouse-button-tolerance",
+ − 5263 &mswindows_mouse_button_tolerance /*
428
+ − 5264 *Analogue of double click interval for faking middle mouse events.
+ − 5265 The value is the minimum time in milliseconds that must elapse between
+ − 5266 left/right button down events before they are considered distinct events.
+ − 5267 If both mouse buttons are depressed within this interval, a middle mouse
+ − 5268 button down event is generated instead.
+ − 5269 If negative or zero, currently set system default is used instead.
+ − 5270 */ );
+ − 5271
+ − 5272 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
+ − 5273 Number of physical mouse buttons.
+ − 5274 */ );
+ − 5275
442
+ − 5276 DEFVAR_INT ("mswindows-mouse-button-max-skew-x",
+ − 5277 &mswindows_mouse_button_max_skew_x /*
428
+ − 5278 *Maximum horizontal distance in pixels between points in which left and
+ − 5279 right button clicks occurred for them to be translated into single
+ − 5280 middle button event. Clicks must occur in time not longer than defined
+ − 5281 by the variable `mswindows-mouse-button-tolerance'.
+ − 5282 If negative or zero, currently set system default is used instead.
+ − 5283 */ );
+ − 5284
442
+ − 5285 DEFVAR_INT ("mswindows-mouse-button-max-skew-y",
+ − 5286 &mswindows_mouse_button_max_skew_y /*
428
+ − 5287 *Maximum vertical distance in pixels between points in which left and
+ − 5288 right button clicks occurred for them to be translated into single
+ − 5289 middle button event. Clicks must occur in time not longer than defined
+ − 5290 by the variable `mswindows-mouse-button-tolerance'.
+ − 5291 If negative or zero, currently set system default is used instead.
+ − 5292 */ );
+ − 5293
+ − 5294 mswindows_mouse_button_max_skew_x = 0;
+ − 5295 mswindows_mouse_button_max_skew_y = 0;
+ − 5296 mswindows_mouse_button_tolerance = 0;
442
+ − 5297 mswindows_alt_by_itself_activates_menu = 1;
428
+ − 5298 }
+ − 5299
+ − 5300 void
+ − 5301 syms_of_event_mswindows (void)
+ − 5302 {
903
+ − 5303 #ifdef HAVE_DRAGNDROP
+ − 5304 DEFSYMBOL(QHSZ);
+ − 5305 DEFSUBR(Fdde_alloc_advise_item);
+ − 5306 DEFSUBR(Fdde_free_advise_item);
+ − 5307 DEFSUBR(Fdde_advise);
+ − 5308 #endif
428
+ − 5309 }
+ − 5310
+ − 5311 void
+ − 5312 lstream_type_create_mswindows_selectable (void)
+ − 5313 {
853
+ − 5314 #ifndef CYGWIN
428
+ − 5315 init_slurp_stream ();
+ − 5316 init_shove_stream ();
+ − 5317 init_winsock_stream ();
+ − 5318 #endif
+ − 5319 }
+ − 5320
+ − 5321 void
+ − 5322 init_event_mswindows_late (void)
+ − 5323 {
853
+ − 5324 #ifdef CYGWIN
771
+ − 5325 windows_fd = retry_open ("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
814
+ − 5326 assert (windows_fd >= 0);
428
+ − 5327 FD_SET (windows_fd, &input_wait_mask);
814
+ − 5328 FD_ZERO (&zero_mask);
428
+ − 5329 #endif
+ − 5330
+ − 5331 event_stream = mswindows_event_stream;
+ − 5332
+ − 5333 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
+ − 5334 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
+ − 5335 }