Mercurial > emacs
comparison src/keyboard.c @ 51384:de51ce646828
(Qmouse_wheel): Declare only if MAC_OSX defined.
(mouse_wheel_syms, lispy_mouse_wheel_names): Likewise.
(discard_mouse_events): Discard WHEEL_EVENT events too.
(lispy_wheel_names, wheel_syms): New.
(syms_of_keyboard): Init and staticpro `wheel_syms'. Init and
staticpro `Qmouse_wheel' and `mouse_wheel_syms' only if MAC_OSX
defined.
(make_lispy_event): Added WHEEL_EVENT handler.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Sun, 01 Jun 2003 21:40:38 +0000 |
parents | 730bcd34a440 |
children | a838a46a67a6 |
comparison
equal
deleted
inserted
replaced
51383:8f30748bdf8f | 51384:de51ce646828 |
---|---|
545 Lisp_Object Qhelp_echo; | 545 Lisp_Object Qhelp_echo; |
546 | 546 |
547 /* Symbols to denote kinds of events. */ | 547 /* Symbols to denote kinds of events. */ |
548 Lisp_Object Qfunction_key; | 548 Lisp_Object Qfunction_key; |
549 Lisp_Object Qmouse_click; | 549 Lisp_Object Qmouse_click; |
550 #if defined(WINDOWSNT) || defined(MAC_OSX) | 550 #if defined(MAC_OSX) |
551 Lisp_Object Qmouse_wheel; | 551 Lisp_Object Qmouse_wheel; |
552 #endif | 552 #endif |
553 #ifdef WINDOWSNT | 553 #ifdef WINDOWSNT |
554 Lisp_Object Qlanguage_change; | 554 Lisp_Object Qlanguage_change; |
555 #endif | 555 #endif |
3735 { | 3735 { |
3736 if (sp == kbd_buffer + KBD_BUFFER_SIZE) | 3736 if (sp == kbd_buffer + KBD_BUFFER_SIZE) |
3737 sp = kbd_buffer; | 3737 sp = kbd_buffer; |
3738 | 3738 |
3739 if (sp->kind == MOUSE_CLICK_EVENT | 3739 if (sp->kind == MOUSE_CLICK_EVENT |
3740 || sp->kind == WHEEL_EVENT | |
3740 #ifdef WINDOWSNT | 3741 #ifdef WINDOWSNT |
3741 || sp->kind == W32_SCROLL_BAR_CLICK_EVENT | 3742 || sp->kind == W32_SCROLL_BAR_CLICK_EVENT |
3742 #endif | 3743 #endif |
3743 || sp->kind == SCROLL_BAR_CLICK_EVENT) | 3744 || sp->kind == SCROLL_BAR_CLICK_EVENT) |
3744 { | 3745 { |
4434 | 4435 |
4435 /* Caches for modify_event_symbol. */ | 4436 /* Caches for modify_event_symbol. */ |
4436 static Lisp_Object accent_key_syms; | 4437 static Lisp_Object accent_key_syms; |
4437 static Lisp_Object func_key_syms; | 4438 static Lisp_Object func_key_syms; |
4438 static Lisp_Object mouse_syms; | 4439 static Lisp_Object mouse_syms; |
4439 #if defined(WINDOWSNT) || defined(MAC_OSX) | 4440 static Lisp_Object wheel_syms; |
4441 #if defined(MAC_OSX) | |
4440 static Lisp_Object mouse_wheel_syms; | 4442 static Lisp_Object mouse_wheel_syms; |
4441 #endif | 4443 #endif |
4442 static Lisp_Object drag_n_drop_syms; | 4444 static Lisp_Object drag_n_drop_syms; |
4443 | 4445 |
4444 /* This is a list of keysym codes for special "accent" characters. | 4446 /* This is a list of keysym codes for special "accent" characters. |
4890 | 4892 |
4891 #endif /* not HAVE_NTGUI */ | 4893 #endif /* not HAVE_NTGUI */ |
4892 | 4894 |
4893 Lisp_Object Vlispy_mouse_stem; | 4895 Lisp_Object Vlispy_mouse_stem; |
4894 | 4896 |
4895 #if defined(WINDOWSNT) || defined(MAC_OSX) | 4897 static char *lispy_wheel_names[] = |
4898 { | |
4899 "wheel-up", "wheel-down" | |
4900 }; | |
4901 | |
4902 #if defined(MAC_OSX) | |
4896 /* mouse-wheel events are generated by the wheel on devices such as | 4903 /* mouse-wheel events are generated by the wheel on devices such as |
4897 the MS Intellimouse. The wheel sits in between the left and right | 4904 the MS Intellimouse. The wheel sits in between the left and right |
4898 mouse buttons, and is typically used to scroll or zoom the window | 4905 mouse buttons, and is typically used to scroll or zoom the window |
4899 underneath the pointer. mouse-wheel events specify the object on | 4906 underneath the pointer. mouse-wheel events specify the object on |
4900 which they operate, and a delta corresponding to the amount and | 4907 which they operate, and a delta corresponding to the amount and |
4903 static char *lispy_mouse_wheel_names[] = | 4910 static char *lispy_mouse_wheel_names[] = |
4904 { | 4911 { |
4905 "mouse-wheel" | 4912 "mouse-wheel" |
4906 }; | 4913 }; |
4907 | 4914 |
4908 #endif /* WINDOWSNT */ | 4915 #endif /* MAC_OSX */ |
4909 | 4916 |
4910 /* drag-n-drop events are generated when a set of selected files are | 4917 /* drag-n-drop events are generated when a set of selected files are |
4911 dragged from another application and dropped onto an Emacs window. */ | 4918 dragged from another application and dropped onto an Emacs window. */ |
4912 static char *lispy_drag_n_drop_names[] = | 4919 static char *lispy_drag_n_drop_names[] = |
4913 { | 4920 { |
5413 return Fcons (head, | 5420 return Fcons (head, |
5414 Fcons (position, | 5421 Fcons (position, |
5415 Qnil)); | 5422 Qnil)); |
5416 } | 5423 } |
5417 } | 5424 } |
5425 | |
5426 case WHEEL_EVENT: | |
5427 { | |
5428 Lisp_Object position; | |
5429 Lisp_Object window; | |
5430 Lisp_Object head; | |
5431 | |
5432 position = Qnil; | |
5433 /* Build the position as appropriate for this mouse click. */ | |
5434 enum window_part part; | |
5435 struct frame *f = XFRAME (event->frame_or_window); | |
5436 Lisp_Object posn; | |
5437 Lisp_Object string_info = Qnil; | |
5438 int row, column; | |
5439 int wx, wy; | |
5440 | |
5441 /* Ignore wheel events that were made on frame that have been | |
5442 deleted. */ | |
5443 if (! FRAME_LIVE_P (f)) | |
5444 return Qnil; | |
5445 | |
5446 /* EVENT->x and EVENT->y are frame-relative pixel | |
5447 coordinates at this place. Under old redisplay, COLUMN | |
5448 and ROW are set to frame relative glyph coordinates | |
5449 which are then used to determine whether this click is | |
5450 in a menu (non-toolkit version). */ | |
5451 pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
5452 &column, &row, NULL, 1); | |
5453 | |
5454 /* Set `window' to the window under frame pixel coordinates | |
5455 event->x/event->y. */ | |
5456 window = window_from_coordinates (f, XINT (event->x), | |
5457 XINT (event->y), | |
5458 &part, &wx, &wy, 0); | |
5459 | |
5460 if (!WINDOWP (window)) | |
5461 { | |
5462 window = event->frame_or_window; | |
5463 posn = Qnil; | |
5464 } | |
5465 else | |
5466 { | |
5467 /* It's a click in window window at frame coordinates | |
5468 event->x/ event->y. */ | |
5469 struct window *w = XWINDOW (window); | |
5470 | |
5471 /* Set event coordinates to window-relative coordinates | |
5472 for constructing the Lisp event below. */ | |
5473 XSETINT (event->x, wx); | |
5474 XSETINT (event->y, wy); | |
5475 | |
5476 if (part == ON_MODE_LINE || part == ON_HEADER_LINE) | |
5477 { | |
5478 /* Mode line or header line. Look for a string under | |
5479 the mouse that may have a `local-map' property. */ | |
5480 Lisp_Object string; | |
5481 int charpos; | |
5482 | |
5483 posn = part == ON_MODE_LINE ? Qmode_line : Qheader_line; | |
5484 string = mode_line_string (w, wx, wy, part, &charpos); | |
5485 if (STRINGP (string)) | |
5486 string_info = Fcons (string, make_number (charpos)); | |
5487 } | |
5488 else if (part == ON_VERTICAL_BORDER) | |
5489 posn = Qvertical_line; | |
5490 else if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN) | |
5491 { | |
5492 int charpos; | |
5493 Lisp_Object object = marginal_area_string (w, wx, wy, part, | |
5494 &charpos); | |
5495 posn = (part == ON_LEFT_MARGIN) ? Qleft_margin : Qright_margin; | |
5496 if (STRINGP (object)) | |
5497 string_info = Fcons (object, make_number (charpos)); | |
5498 } | |
5499 else | |
5500 { | |
5501 Lisp_Object object; | |
5502 struct display_pos p; | |
5503 buffer_posn_from_coords (w, &wx, &wy, &object, &p); | |
5504 posn = make_number (CHARPOS (p.pos)); | |
5505 if (STRINGP (object)) | |
5506 string_info | |
5507 = Fcons (object, | |
5508 make_number (CHARPOS (p.string_pos))); | |
5509 } | |
5510 } | |
5511 | |
5512 position | |
5513 = Fcons (window, | |
5514 Fcons (posn, | |
5515 Fcons (Fcons (event->x, event->y), | |
5516 Fcons (make_number (event->timestamp), | |
5517 (NILP (string_info) | |
5518 ? Qnil | |
5519 : Fcons (string_info, Qnil)))))); | |
5520 | |
5521 /* Set double or triple modifiers to indicate the wheel speed. */ | |
5522 { | |
5523 /* On window-system frames, use the value of | |
5524 double-click-fuzz as is. On other frames, interpret it | |
5525 as a multiple of 1/8 characters. */ | |
5526 struct frame *f; | |
5527 int fuzz; | |
5528 int is_double; | |
5529 | |
5530 if (WINDOWP (event->frame_or_window)) | |
5531 f = XFRAME (XWINDOW (event->frame_or_window)->frame); | |
5532 else if (FRAMEP (event->frame_or_window)) | |
5533 f = XFRAME (event->frame_or_window); | |
5534 else | |
5535 abort (); | |
5536 | |
5537 if (FRAME_WINDOW_P (f)) | |
5538 fuzz = double_click_fuzz; | |
5539 else | |
5540 fuzz = double_click_fuzz / 8; | |
5541 | |
5542 is_double = (last_mouse_button < 0 | |
5543 && (abs (XINT (event->x) - last_mouse_x) <= fuzz) | |
5544 && (abs (XINT (event->y) - last_mouse_y) <= fuzz) | |
5545 && button_down_time != 0 | |
5546 && (EQ (Vdouble_click_time, Qt) | |
5547 || (INTEGERP (Vdouble_click_time) | |
5548 && ((int)(event->timestamp - button_down_time) | |
5549 < XINT (Vdouble_click_time))))); | |
5550 if (is_double) | |
5551 { | |
5552 double_click_count++; | |
5553 event->modifiers |= ((double_click_count > 2) | |
5554 ? triple_modifier | |
5555 : double_modifier); | |
5556 } | |
5557 else | |
5558 { | |
5559 double_click_count = 1; | |
5560 event->modifiers |= click_modifier; | |
5561 } | |
5562 | |
5563 button_down_time = event->timestamp; | |
5564 /* Use a negative value to distinguish wheel from mouse button. */ | |
5565 last_mouse_button = -1; | |
5566 last_mouse_x = XINT (event->x); | |
5567 last_mouse_y = XINT (event->y); | |
5568 } | |
5569 | |
5570 { | |
5571 int symbol_num; | |
5572 | |
5573 if (event->modifiers & up_modifier) | |
5574 { | |
5575 /* Emit a wheel-up event. */ | |
5576 event->modifiers &= ~up_modifier; | |
5577 symbol_num = 0; | |
5578 } | |
5579 else if (event->modifiers & down_modifier) | |
5580 { | |
5581 /* Emit a wheel-down event. */ | |
5582 event->modifiers &= ~down_modifier; | |
5583 symbol_num = 1; | |
5584 } | |
5585 else | |
5586 /* Every wheel event should either have the down_modifier or | |
5587 the up_modifier set. */ | |
5588 abort (); | |
5589 | |
5590 /* Get the symbol we should use for the wheel event. */ | |
5591 head = modify_event_symbol (symbol_num, | |
5592 event->modifiers, | |
5593 Qmouse_click, | |
5594 Qnil, | |
5595 lispy_wheel_names, | |
5596 &wheel_syms, | |
5597 ASIZE (wheel_syms)); | |
5598 } | |
5599 | |
5600 if (event->modifiers & (double_modifier | triple_modifier)) | |
5601 return Fcons (head, | |
5602 Fcons (position, | |
5603 Fcons (make_number (double_click_count), | |
5604 Qnil))); | |
5605 else | |
5606 return Fcons (head, | |
5607 Fcons (position, | |
5608 Qnil)); | |
5609 } | |
5610 | |
5418 | 5611 |
5419 #ifdef USE_TOOLKIT_SCROLL_BARS | 5612 #ifdef USE_TOOLKIT_SCROLL_BARS |
5420 | 5613 |
5421 /* We don't have down and up events if using toolkit scroll bars, | 5614 /* We don't have down and up events if using toolkit scroll bars, |
5422 so make this always a click event. Store in the `part' of | 5615 so make this always a click event. Store in the `part' of |
10673 | 10866 |
10674 Qfunction_key = intern ("function-key"); | 10867 Qfunction_key = intern ("function-key"); |
10675 staticpro (&Qfunction_key); | 10868 staticpro (&Qfunction_key); |
10676 Qmouse_click = intern ("mouse-click"); | 10869 Qmouse_click = intern ("mouse-click"); |
10677 staticpro (&Qmouse_click); | 10870 staticpro (&Qmouse_click); |
10678 #if defined(WINDOWSNT) || defined(MAC_OSX) | 10871 #if defined(MAC_OSX) |
10679 Qmouse_wheel = intern ("mouse-wheel"); | 10872 Qmouse_wheel = intern ("mouse-wheel"); |
10680 staticpro (&Qmouse_wheel); | 10873 staticpro (&Qmouse_wheel); |
10681 #endif | 10874 #endif |
10682 #ifdef WINDOWSNT | 10875 #ifdef WINDOWSNT |
10683 Qlanguage_change = intern ("language-change"); | 10876 Qlanguage_change = intern ("language-change"); |
10791 | 10984 |
10792 button_down_location = Fmake_vector (make_number (1), Qnil); | 10985 button_down_location = Fmake_vector (make_number (1), Qnil); |
10793 staticpro (&button_down_location); | 10986 staticpro (&button_down_location); |
10794 mouse_syms = Fmake_vector (make_number (1), Qnil); | 10987 mouse_syms = Fmake_vector (make_number (1), Qnil); |
10795 staticpro (&mouse_syms); | 10988 staticpro (&mouse_syms); |
10989 wheel_syms = Fmake_vector (make_number (2), Qnil); | |
10990 staticpro (&wheel_syms); | |
10796 | 10991 |
10797 { | 10992 { |
10798 int i; | 10993 int i; |
10799 int len = sizeof (modifier_names) / sizeof (modifier_names[0]); | 10994 int len = sizeof (modifier_names) / sizeof (modifier_names[0]); |
10800 | 10995 |
10825 staticpro (&accent_key_syms); | 11020 staticpro (&accent_key_syms); |
10826 | 11021 |
10827 func_key_syms = Qnil; | 11022 func_key_syms = Qnil; |
10828 staticpro (&func_key_syms); | 11023 staticpro (&func_key_syms); |
10829 | 11024 |
10830 #if defined(WINDOWSNT) || defined(MAC_OSX) | 11025 #if defined(MAC_OSX) |
10831 mouse_wheel_syms = Qnil; | 11026 mouse_wheel_syms = Qnil; |
10832 staticpro (&mouse_wheel_syms); | 11027 staticpro (&mouse_wheel_syms); |
10833 drag_n_drop_syms = Qnil; | 11028 drag_n_drop_syms = Qnil; |
10834 staticpro (&drag_n_drop_syms); | 11029 staticpro (&drag_n_drop_syms); |
10835 #endif | 11030 #endif |