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