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