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