comparison src/macterm.c @ 61574:d3c53b9d1828

(x_autoselect_window_p): Remove variable. (last_window): New variable. (XTreassert_line_highlight, x_change_line_highlight): Remove declarations. (mac_focus_changed, x_detect_focus_change): New functions and declarations. (XTextExtents16, front_emacs_window): Remove function. (mac_focus_frame): New function. (XTmouse_position, do_menu_choice, do_zoom_window, XTread_socket) (mac_check_for_quit_char): Use it instead of front_emacs_window. (x_scroll_bar_report_motion): Obtain window from control owner. (x_make_frame_invisible): Set window manager size hint. (do_mouse_moved): Remove function. (XTread_socket): Move its contents here. Generate select-window event on mouse movement if needed. Use x_detect_focus_change on activate/deactivate events. Don't deiconify frame or invalidate window rectangle when dnd items are dropped. Don't activate/deactivate root control. (frame_highlight, frame_unhighlight): Activate/deactivate root control here. (syms_of_macterm): Delete DEFVAR_BOOL for x_autoselect_window_p.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Sat, 16 Apr 2005 03:05:15 +0000
parents ecffc47fdd94
children 351bda10c1b0 2c2b97b30980
comparison
equal deleted inserted replaced
61573:5b0b486b7f71 61574:d3c53b9d1828
93 #define macMetaKey (NILP (Vmac_reverse_ctrl_meta) ? \ 93 #define macMetaKey (NILP (Vmac_reverse_ctrl_meta) ? \
94 (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey) \ 94 (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey) \
95 : controlKey) 95 : controlKey)
96 #define macAltKey (NILP (Vmac_command_key_is_meta) ? cmdKey : optionKey) 96 #define macAltKey (NILP (Vmac_command_key_is_meta) ? cmdKey : optionKey)
97 97
98 #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
98 99
99 100
100 /* Non-nil means Emacs uses toolkit scroll bars. */ 101 /* Non-nil means Emacs uses toolkit scroll bars. */
101 102
102 Lisp_Object Vx_toolkit_scroll_bars; 103 Lisp_Object Vx_toolkit_scroll_bars;
108 /* Non-zero means that a HELP_EVENT has been generated since Emacs 109 /* Non-zero means that a HELP_EVENT has been generated since Emacs
109 start. */ 110 start. */
110 111
111 static int any_help_event_p; 112 static int any_help_event_p;
112 113
113 /* Non-zero means autoselect window with the mouse cursor. */ 114 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
114 115 static Lisp_Object last_window;
115 int x_autoselect_window_p;
116 116
117 /* Non-zero means make use of UNDERLINE_POSITION font properties. */ 117 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
118 118
119 int x_use_underline_position_properties; 119 int x_use_underline_position_properties;
120 120
271 void mac_initialize P_ ((void)); 271 void mac_initialize P_ ((void));
272 static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); 272 static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
273 static int x_compute_min_glyph_bounds P_ ((struct frame *)); 273 static int x_compute_min_glyph_bounds P_ ((struct frame *));
274 static void x_update_end P_ ((struct frame *)); 274 static void x_update_end P_ ((struct frame *));
275 static void XTframe_up_to_date P_ ((struct frame *)); 275 static void XTframe_up_to_date P_ ((struct frame *));
276 static void XTreassert_line_highlight P_ ((int, int));
277 static void x_change_line_highlight P_ ((int, int, int, int));
278 static void XTset_terminal_modes P_ ((void)); 276 static void XTset_terminal_modes P_ ((void));
279 static void XTreset_terminal_modes P_ ((void)); 277 static void XTreset_terminal_modes P_ ((void));
280 static void x_clear_frame P_ ((void)); 278 static void x_clear_frame P_ ((void));
281 static void frame_highlight P_ ((struct frame *)); 279 static void frame_highlight P_ ((struct frame *));
282 static void frame_unhighlight P_ ((struct frame *)); 280 static void frame_unhighlight P_ ((struct frame *));
283 static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *)); 281 static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *));
282 static void mac_focus_changed P_ ((int, struct mac_display_info *,
283 struct frame *, struct input_event *));
284 static void x_detect_focus_change P_ ((struct mac_display_info *,
285 EventRecord *, struct input_event *));
284 static void XTframe_rehighlight P_ ((struct frame *)); 286 static void XTframe_rehighlight P_ ((struct frame *));
285 static void x_frame_rehighlight P_ ((struct x_display_info *)); 287 static void x_frame_rehighlight P_ ((struct x_display_info *));
286 static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); 288 static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *));
287 static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int, 289 static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int,
288 enum text_cursor_kinds)); 290 enum text_cursor_kinds));
1193 Display *display; 1195 Display *display;
1194 GC gc; 1196 GC gc;
1195 XFontStruct *font; 1197 XFontStruct *font;
1196 { 1198 {
1197 gc->font = font; 1199 gc->font = font;
1198 }
1199
1200
1201 static void
1202 XTextExtents16 (XFontStruct *font, XChar2b *text, int nchars,
1203 int *direction,int *font_ascent,
1204 int *font_descent, XCharStruct *cs)
1205 {
1206 /* MAC_TODO: Use GetTextMetrics to do this and inline it below. */
1207 } 1200 }
1208 1201
1209 1202
1210 /* x_sync is a no-op on Mac. */ 1203 /* x_sync is a no-op on Mac. */
1211 void 1204 void
3492 3485
3493 static void 3486 static void
3494 frame_highlight (f) 3487 frame_highlight (f)
3495 struct frame *f; 3488 struct frame *f;
3496 { 3489 {
3490 OSErr err;
3491 ControlRef root_control;
3492
3493 BLOCK_INPUT;
3494 err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control);
3495 if (err == noErr)
3496 ActivateControl (root_control);
3497 UNBLOCK_INPUT;
3497 x_update_cursor (f, 1); 3498 x_update_cursor (f, 1);
3498 } 3499 }
3499 3500
3500 static void 3501 static void
3501 frame_unhighlight (f) 3502 frame_unhighlight (f)
3502 struct frame *f; 3503 struct frame *f;
3503 { 3504 {
3505 OSErr err;
3506 ControlRef root_control;
3507
3508 BLOCK_INPUT;
3509 err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control);
3510 if (err == noErr)
3511 DeactivateControl (root_control);
3512 UNBLOCK_INPUT;
3504 x_update_cursor (f, 1); 3513 x_update_cursor (f, 1);
3505 } 3514 }
3506 3515
3507 /* The focus has changed. Update the frames as necessary to reflect 3516 /* The focus has changed. Update the frames as necessary to reflect
3508 the new situation. Note that we can't change the selected frame 3517 the new situation. Note that we can't change the selected frame
3540 pending_autoraise_frame = 0; 3549 pending_autoraise_frame = 0;
3541 } 3550 }
3542 3551
3543 x_frame_rehighlight (dpyinfo); 3552 x_frame_rehighlight (dpyinfo);
3544 } 3553 }
3554
3555 /* Handle FocusIn and FocusOut state changes for FRAME.
3556 If FRAME has focus and there exists more than one frame, puts
3557 a FOCUS_IN_EVENT into *BUFP. */
3558
3559 static void
3560 mac_focus_changed (type, dpyinfo, frame, bufp)
3561 int type;
3562 struct mac_display_info *dpyinfo;
3563 struct frame *frame;
3564 struct input_event *bufp;
3565 {
3566 if (type == activeFlag)
3567 {
3568 if (dpyinfo->x_focus_event_frame != frame)
3569 {
3570 x_new_focus_frame (dpyinfo, frame);
3571 dpyinfo->x_focus_event_frame = frame;
3572
3573 /* Don't stop displaying the initial startup message
3574 for a switch-frame event we don't need. */
3575 if (GC_NILP (Vterminal_frame)
3576 && GC_CONSP (Vframe_list)
3577 && !GC_NILP (XCDR (Vframe_list)))
3578 {
3579 bufp->kind = FOCUS_IN_EVENT;
3580 XSETFRAME (bufp->frame_or_window, frame);
3581 }
3582 }
3583 }
3584 else
3585 {
3586 if (dpyinfo->x_focus_event_frame == frame)
3587 {
3588 dpyinfo->x_focus_event_frame = 0;
3589 x_new_focus_frame (dpyinfo, 0);
3590 }
3591 }
3592 }
3593
3594 /* The focus may have changed. Figure out if it is a real focus change,
3595 by checking both FocusIn/Out and Enter/LeaveNotify events.
3596
3597 Returns FOCUS_IN_EVENT event in *BUFP. */
3598
3599 static void
3600 x_detect_focus_change (dpyinfo, event, bufp)
3601 struct mac_display_info *dpyinfo;
3602 EventRecord *event;
3603 struct input_event *bufp;
3604 {
3605 struct frame *frame;
3606
3607 frame = mac_window_to_frame ((WindowPtr) event->message);
3608 if (! frame)
3609 return;
3610
3611 /* On Mac, this is only called from focus events, so no switch needed. */
3612 mac_focus_changed ((event->modifiers & activeFlag),
3613 dpyinfo, frame, bufp);
3614 }
3615
3545 3616
3546 /* Handle an event saying the mouse has moved out of an Emacs frame. */ 3617 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3547 3618
3548 void 3619 void
3549 x_mouse_leave (dpyinfo) 3620 x_mouse_leave (dpyinfo)
3978 last_mouse_glyph.bottom = gy + height; 4049 last_mouse_glyph.bottom = gy + height;
3979 } 4050 }
3980 } 4051 }
3981 4052
3982 4053
3983 static WindowPtr 4054 static struct frame *
3984 front_emacs_window () 4055 mac_focus_frame (dpyinfo)
3985 { 4056 struct mac_display_info *dpyinfo;
3986 #if TARGET_API_MAC_CARBON 4057 {
3987 WindowPtr wp = GetFrontWindowOfClass (kDocumentWindowClass, true); 4058 if (dpyinfo->x_focus_frame)
3988 4059 return dpyinfo->x_focus_frame;
3989 while (wp && !is_emacs_window (wp)) 4060 else
3990 wp = GetNextWindowOfClass (wp, kDocumentWindowClass, true); 4061 /* Mac version may get events, such as a menu bar click, even when
3991 #else 4062 all the frames are invisible. In this case, we regard the
3992 WindowPtr wp = FrontWindow (); 4063 event came to the selected frame. */
3993 4064 return SELECTED_FRAME ();
3994 while (wp && (wp == tip_window || !is_emacs_window (wp))) 4065 }
3995 wp = GetNextWindow (wp); 4066
3996 #endif
3997
3998 return wp;
3999 }
4000
4001 #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
4002 4067
4003 /* Return the current position of the mouse. 4068 /* Return the current position of the mouse.
4004 *fp should be a frame which indicates which display to ask about. 4069 *fp should be a frame which indicates which display to ask about.
4005 4070
4006 If the mouse movement started in a scroll bar, set *fp, *bar_window, 4071 If the mouse movement started in a scroll bar, set *fp, *bar_window,
4029 Lisp_Object *x, *y; 4094 Lisp_Object *x, *y;
4030 unsigned long *time; 4095 unsigned long *time;
4031 { 4096 {
4032 Point mouse_pos; 4097 Point mouse_pos;
4033 int ignore1, ignore2; 4098 int ignore1, ignore2;
4034 WindowPtr wp = front_emacs_window (); 4099 struct frame *f = mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp));
4035 struct frame *f; 4100 WindowPtr wp = FRAME_MAC_WINDOW (f);
4036 Lisp_Object frame, tail; 4101 Lisp_Object frame, tail;
4037
4038 if (is_emacs_window(wp))
4039 f = mac_window_to_frame (wp);
4040 4102
4041 BLOCK_INPUT; 4103 BLOCK_INPUT;
4042 4104
4043 if (! NILP (last_mouse_scroll_bar) && insist == 0) 4105 if (! NILP (last_mouse_scroll_bar) && insist == 0)
4044 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); 4106 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
4602 enum scroll_bar_part *part; 4664 enum scroll_bar_part *part;
4603 Lisp_Object *x, *y; 4665 Lisp_Object *x, *y;
4604 unsigned long *time; 4666 unsigned long *time;
4605 { 4667 {
4606 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 4668 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
4607 WindowPtr wp = front_emacs_window (); 4669 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar);
4670 #if TARGET_API_MAC_CARBON
4671 WindowPtr wp = GetControlOwner (ch);
4672 #else
4673 WindowPtr wp = (*ch)->contrlOwner;
4674 #endif
4608 Point mouse_pos; 4675 Point mouse_pos;
4609 struct frame *f = mac_window_to_frame (wp); 4676 struct frame *f = mac_window_to_frame (wp);
4610 int win_y, top_range; 4677 int win_y, top_range;
4611 4678
4612 SetPortWindowPort (wp); 4679 SetPortWindowPort (wp);
5048 if (!STRINGP (result)) 5115 if (!STRINGP (result))
5049 /* Can't load ASCII font. */ 5116 /* Can't load ASCII font. */
5050 return Qnil; 5117 return Qnil;
5051 5118
5052 /* Since x_new_font doesn't update any fontset information, do it now. */ 5119 /* Since x_new_font doesn't update any fontset information, do it now. */
5053 FRAME_FONTSET(f) = fontset; 5120 FRAME_FONTSET (f) = fontset;
5054 5121
5055 return build_string (fontsetname); 5122 return build_string (fontsetname);
5056 } 5123 }
5057 5124
5058 5125
5495 /* Don't keep the highlight on an invisible frame. */ 5562 /* Don't keep the highlight on an invisible frame. */
5496 if (FRAME_MAC_DISPLAY_INFO (f)->x_highlight_frame == f) 5563 if (FRAME_MAC_DISPLAY_INFO (f)->x_highlight_frame == f)
5497 FRAME_MAC_DISPLAY_INFO (f)->x_highlight_frame = 0; 5564 FRAME_MAC_DISPLAY_INFO (f)->x_highlight_frame = 0;
5498 5565
5499 BLOCK_INPUT; 5566 BLOCK_INPUT;
5567
5568 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5569 that the current position of the window is user-specified, rather than
5570 program-specified, so that when the window is mapped again, it will be
5571 placed at the same location, without forcing the user to position it
5572 by hand again (they have already done that once for this window.) */
5573 x_wm_set_size_hint (f, (long) 0, 1);
5500 5574
5501 HideWindow (FRAME_MAC_WINDOW (f)); 5575 HideWindow (FRAME_MAC_WINDOW (f));
5502 5576
5503 /* We can't distinguish this from iconification 5577 /* We can't distinguish this from iconification
5504 just by the event that we get from the server. 5578 just by the event that we get from the server.
7452 static void 7526 static void
7453 do_app_resume () 7527 do_app_resume ()
7454 { 7528 {
7455 /* Window-activate events will do the job. */ 7529 /* Window-activate events will do the job. */
7456 #if 0 7530 #if 0
7457 WindowPtr wp;
7458 struct frame *f;
7459
7460 wp = front_emacs_window ();
7461 if (wp)
7462 {
7463 f = mac_window_to_frame (wp);
7464
7465 if (f)
7466 {
7467 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f), f);
7468 activate_scroll_bars (f);
7469 }
7470 }
7471
7472 app_is_suspended = false; 7531 app_is_suspended = false;
7473 app_sleep_time = WNE_SLEEP_AT_RESUME; 7532 app_sleep_time = WNE_SLEEP_AT_RESUME;
7474 #endif 7533 #endif
7475 } 7534 }
7476 7535
7477 static void 7536 static void
7478 do_app_suspend () 7537 do_app_suspend ()
7479 { 7538 {
7480 /* Window-deactivate events will do the job. */ 7539 /* Window-deactivate events will do the job. */
7481 #if 0 7540 #if 0
7482 WindowPtr wp;
7483 struct frame *f;
7484
7485 wp = front_emacs_window ();
7486 if (wp)
7487 {
7488 f = mac_window_to_frame (wp);
7489
7490 if (f == FRAME_MAC_DISPLAY_INFO (f)->x_focus_frame)
7491 {
7492 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f), 0);
7493 deactivate_scroll_bars (f);
7494 }
7495 }
7496
7497 app_is_suspended = true; 7541 app_is_suspended = true;
7498 app_sleep_time = WNE_SLEEP_AT_SUSPEND; 7542 app_sleep_time = WNE_SLEEP_AT_SUSPEND;
7499 #endif 7543 #endif
7500 }
7501
7502
7503 static void
7504 do_mouse_moved (mouse_pos, f)
7505 Point mouse_pos;
7506 FRAME_PTR *f;
7507 {
7508 WindowPtr wp = front_emacs_window ();
7509 struct x_display_info *dpyinfo;
7510
7511 if (wp)
7512 {
7513 *f = mac_window_to_frame (wp);
7514 dpyinfo = FRAME_MAC_DISPLAY_INFO (*f);
7515
7516 if (dpyinfo->mouse_face_hidden)
7517 {
7518 dpyinfo->mouse_face_hidden = 0;
7519 clear_mouse_face (dpyinfo);
7520 }
7521
7522 SetPortWindowPort (wp);
7523
7524 GlobalToLocal (&mouse_pos);
7525
7526 if (dpyinfo->grabbed && tracked_scroll_bar)
7527 x_scroll_bar_note_movement (tracked_scroll_bar,
7528 mouse_pos.v
7529 - XINT (tracked_scroll_bar->top),
7530 TickCount() * (1000 / 60));
7531 else
7532 note_mouse_movement (*f, &mouse_pos);
7533 }
7534 } 7544 }
7535 7545
7536 7546
7537 static void 7547 static void
7538 do_apple_menu (SInt16 menu_item) 7548 do_apple_menu (SInt16 menu_item)
7568 do_apple_menu (menu_item); 7578 do_apple_menu (menu_item);
7569 break; 7579 break;
7570 7580
7571 default: 7581 default:
7572 { 7582 {
7573 struct frame *f = mac_window_to_frame (front_emacs_window ()); 7583 struct frame *f = mac_focus_frame (&one_mac_display_info);
7574 MenuHandle menu = GetMenuHandle (menu_id); 7584 MenuHandle menu = GetMenuHandle (menu_id);
7575 if (menu) 7585 if (menu)
7576 { 7586 {
7577 UInt32 refcon; 7587 UInt32 refcon;
7578 7588
7646 GrafPtr save_port; 7656 GrafPtr save_port;
7647 Rect zoom_rect, port_rect; 7657 Rect zoom_rect, port_rect;
7648 Point top_left; 7658 Point top_left;
7649 int w_title_height, columns, rows, width, height; 7659 int w_title_height, columns, rows, width, height;
7650 struct frame *f = mac_window_to_frame (w); 7660 struct frame *f = mac_window_to_frame (w);
7661 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
7651 7662
7652 #if TARGET_API_MAC_CARBON 7663 #if TARGET_API_MAC_CARBON
7653 { 7664 {
7654 Point standard_size; 7665 Point standard_size;
7655 7666
7656 standard_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS); 7667 standard_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS);
7657 standard_size.v = FRAME_MAC_DISPLAY_INFO (f)->height; 7668 standard_size.v = dpyinfo->height;
7658 7669
7659 if (IsWindowInStandardState (w, &standard_size, &zoom_rect)) 7670 if (IsWindowInStandardState (w, &standard_size, &zoom_rect))
7660 zoom_in_or_out = inZoomIn; 7671 zoom_in_or_out = inZoomIn;
7661 else 7672 else
7662 { 7673 {
7708 7719
7709 (**((WStateDataHandle) ((WindowPeek) w)->dataHandle)).stdState 7720 (**((WStateDataHandle) ((WindowPeek) w)->dataHandle)).stdState
7710 = zoom_rect; 7721 = zoom_rect;
7711 } 7722 }
7712 7723
7713 ZoomWindow (w, zoom_in_or_out, w == front_emacs_window ()); 7724 ZoomWindow (w, zoom_in_or_out, f == mac_focus_frame (dpyinfo));
7714 7725
7715 SetPort (save_port); 7726 SetPort (save_port);
7716 #endif /* not TARGET_API_MAC_CARBON */ 7727 #endif /* not TARGET_API_MAC_CARBON */
7717 7728
7718 /* retrieve window size and update application values */ 7729 /* retrieve window size and update application values */
8574 case kEventClassMouse: 8585 case kEventClassMouse:
8575 if (GetEventKind (eventRef) == kEventMouseWheelMoved) 8586 if (GetEventKind (eventRef) == kEventMouseWheelMoved)
8576 { 8587 {
8577 SInt32 delta; 8588 SInt32 delta;
8578 Point point; 8589 Point point;
8579 WindowPtr window_ptr = front_emacs_window (); 8590 struct frame *f = mac_focus_frame (dpyinfo);
8580 8591 WindowPtr window_ptr;
8581 if (!IsValidWindowPtr (window_ptr)) 8592
8593 if (!f)
8582 { 8594 {
8595 /* Beep if wheel move occurs when all the frames
8596 are invisible. */
8583 SysBeep(1); 8597 SysBeep(1);
8584 break; 8598 break;
8585 } 8599 }
8586 8600
8587 GetEventParameter(eventRef, kEventParamMouseWheelDelta, 8601 GetEventParameter(eventRef, kEventParamMouseWheelDelta,
8593 inev.kind = WHEEL_EVENT; 8607 inev.kind = WHEEL_EVENT;
8594 inev.code = 0; 8608 inev.code = 0;
8595 inev.modifiers = (mac_event_to_emacs_modifiers (eventRef) 8609 inev.modifiers = (mac_event_to_emacs_modifiers (eventRef)
8596 | ((delta < 0) ? down_modifier 8610 | ((delta < 0) ? down_modifier
8597 : up_modifier)); 8611 : up_modifier));
8612 window_ptr = FRAME_MAC_WINDOW (f);
8598 SetPortWindowPort (window_ptr); 8613 SetPortWindowPort (window_ptr);
8599 GlobalToLocal (&point); 8614 GlobalToLocal (&point);
8600 XSETINT (inev.x, point.h); 8615 XSETINT (inev.x, point.h);
8601 XSETINT (inev.y, point.v); 8616 XSETINT (inev.y, point.v);
8602 XSETFRAME (inev.frame_or_window, 8617 XSETFRAME (inev.frame_or_window,
8651 break; 8666 break;
8652 8667
8653 switch (part_code) 8668 switch (part_code)
8654 { 8669 {
8655 case inMenuBar: 8670 case inMenuBar:
8656 f = mac_window_to_frame (front_emacs_window ()); 8671 f = mac_focus_frame (dpyinfo);
8657 saved_menu_event_location = er.where; 8672 saved_menu_event_location = er.where;
8658 inev.kind = MENU_BAR_ACTIVATE_EVENT; 8673 inev.kind = MENU_BAR_ACTIVATE_EVENT;
8659 XSETFRAME (inev.frame_or_window, f); 8674 XSETFRAME (inev.frame_or_window, f);
8660 break; 8675 break;
8661 8676
8662 case inContent: 8677 case inContent:
8663 if (window_ptr != front_emacs_window ()) 8678 if (window_ptr != FRAME_MAC_WINDOW (mac_focus_frame (dpyinfo)))
8664 SelectWindow (window_ptr); 8679 SelectWindow (window_ptr);
8665 else 8680 else
8666 { 8681 {
8667 SInt16 control_part_code; 8682 SInt16 control_part_code;
8668 ControlHandle ch; 8683 ControlHandle ch;
8849 #endif 8864 #endif
8850 previous_help_echo_string = help_echo_string; 8865 previous_help_echo_string = help_echo_string;
8851 help_echo_string = help_echo_object = help_echo_window = Qnil; 8866 help_echo_string = help_echo_object = help_echo_window = Qnil;
8852 help_echo_pos = -1; 8867 help_echo_pos = -1;
8853 8868
8854 do_mouse_moved (er.where, &f); 8869 if (dpyinfo->grabbed && last_mouse_frame
8870 && FRAME_LIVE_P (last_mouse_frame))
8871 f = last_mouse_frame;
8872 else
8873 f = dpyinfo->x_focus_frame;
8874
8875 if (dpyinfo->mouse_face_hidden)
8876 {
8877 dpyinfo->mouse_face_hidden = 0;
8878 clear_mouse_face (dpyinfo);
8879 }
8880
8881 if (f)
8882 {
8883 WindowPtr wp = FRAME_MAC_WINDOW (f);
8884 Point mouse_pos = er.where;
8885
8886 SetPortWindowPort (wp);
8887
8888 GlobalToLocal (&mouse_pos);
8889
8890 if (dpyinfo->grabbed && tracked_scroll_bar)
8891 x_scroll_bar_note_movement (tracked_scroll_bar,
8892 mouse_pos.v
8893 - XINT (tracked_scroll_bar->top),
8894 TickCount() * (1000 / 60));
8895 else
8896 {
8897 /* Generate SELECT_WINDOW_EVENTs when needed. */
8898 if (mouse_autoselect_window)
8899 {
8900 Lisp_Object window;
8901
8902 window = window_from_coordinates (f,
8903 mouse_pos.h,
8904 mouse_pos.v,
8905 0, 0, 0, 0);
8906
8907 /* Window will be selected only when it is
8908 not selected now and last mouse movement
8909 event was not in it. Minibuffer window
8910 will be selected iff it is active. */
8911 if (WINDOWP (window)
8912 && !EQ (window, last_window)
8913 && !EQ (window, selected_window))
8914 {
8915 inev.kind = SELECT_WINDOW_EVENT;
8916 inev.frame_or_window = window;
8917 }
8918
8919 last_window=window;
8920 }
8921 note_mouse_movement (f, &mouse_pos);
8922 }
8923 }
8855 8924
8856 /* If the contents of the global variable 8925 /* If the contents of the global variable
8857 help_echo_string has changed, generate a 8926 help_echo_string has changed, generate a
8858 HELP_EVENT. */ 8927 HELP_EVENT. */
8859 if (!NILP (help_echo_string) || !NILP (previous_help_echo_string)) 8928 if (!NILP (help_echo_string) || !NILP (previous_help_echo_string))
8863 break; 8932 break;
8864 8933
8865 case activateEvt: 8934 case activateEvt:
8866 { 8935 {
8867 WindowPtr window_ptr = (WindowPtr) er.message; 8936 WindowPtr window_ptr = (WindowPtr) er.message;
8868 ControlRef root_control;
8869 8937
8870 #if USE_CARBON_EVENTS 8938 #if USE_CARBON_EVENTS
8871 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) 8939 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
8872 != eventNotHandledErr) 8940 != eventNotHandledErr)
8873 break; 8941 break;
8879 } 8947 }
8880 8948
8881 if (!is_emacs_window (window_ptr)) 8949 if (!is_emacs_window (window_ptr))
8882 break; 8950 break;
8883 8951
8884 f = mac_window_to_frame (window_ptr);
8885 GetRootControl (window_ptr, &root_control);
8886
8887 if ((er.modifiers & activeFlag) != 0) 8952 if ((er.modifiers & activeFlag) != 0)
8888 { 8953 {
8889 /* A window has been activated */ 8954 /* A window has been activated */
8890 Point mouse_loc = er.where; 8955 Point mouse_loc = er.where;
8891 8956
8892 x_new_focus_frame (dpyinfo, f); 8957 x_detect_focus_change (dpyinfo, &er, &inev);
8893 ActivateControl (root_control);
8894 8958
8895 SetPortWindowPort (window_ptr); 8959 SetPortWindowPort (window_ptr);
8896 GlobalToLocal (&mouse_loc); 8960 GlobalToLocal (&mouse_loc);
8897 /* Window-activated event counts as mouse movement, 8961 /* Window-activated event counts as mouse movement,
8898 so update things that depend on mouse position. */ 8962 so update things that depend on mouse position. */
8902 else 8966 else
8903 { 8967 {
8904 /* A window has been deactivated */ 8968 /* A window has been deactivated */
8905 dpyinfo->grabbed = 0; 8969 dpyinfo->grabbed = 0;
8906 8970
8907 if (f == dpyinfo->x_focus_frame) 8971 x_detect_focus_change (dpyinfo, &er, &inev);
8908 { 8972
8909 x_new_focus_frame (dpyinfo, 0); 8973 f = mac_window_to_frame (window_ptr);
8910 DeactivateControl (root_control);
8911 }
8912
8913
8914 if (f == dpyinfo->mouse_face_mouse_frame) 8974 if (f == dpyinfo->mouse_face_mouse_frame)
8915 { 8975 {
8916 /* If we move outside the frame, then we're 8976 /* If we move outside the frame, then we're
8917 certainly no longer on any text in the 8977 certainly no longer on any text in the
8918 frame. */ 8978 frame. */
8949 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) 9009 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
8950 != eventNotHandledErr) 9010 != eventNotHandledErr)
8951 break; 9011 break;
8952 #endif 9012 #endif
8953 9013
8954 #if TARGET_API_MAC_CARBON 9014 if (dpyinfo->x_focus_frame == NULL)
8955 if (!IsValidWindowPtr (front_emacs_window ()))
8956 { 9015 {
9016 /* Beep if keyboard input occurs when all the frames
9017 are invisible. */
8957 SysBeep (1); 9018 SysBeep (1);
8958 break; 9019 break;
8959 } 9020 }
8960 #endif 9021
8961 { 9022 {
8962 static SInt16 last_key_script = -1; 9023 static SInt16 last_key_script = -1;
8963 SInt16 current_key_script = GetScriptManagerVariable (smKeyScript); 9024 SInt16 current_key_script = GetScriptManagerVariable (smKeyScript);
8964 9025
8965 if (last_key_script != current_key_script) 9026 if (last_key_script != current_key_script)
8966 { 9027 {
8967 struct input_event event; 9028 struct input_event event;
8968 9029
8969 EVENT_INIT (event); 9030 EVENT_INIT (event);
8970 event.kind = LANGUAGE_CHANGE_EVENT; 9031 event.kind = LANGUAGE_CHANGE_EVENT;
8971 event.arg = Qnil; 9032 event.arg = Qnil;
8972 event.code = current_key_script; 9033 event.code = current_key_script;
8973 kbd_buffer_store_event (&event); 9034 kbd_buffer_store_event (&event);
9007 int new_keycode = keycode | new_modifiers; 9068 int new_keycode = keycode | new_modifiers;
9008 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); 9069 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
9009 unsigned long some_state = 0; 9070 unsigned long some_state = 0;
9010 inev.code = KeyTranslate (kchr_ptr, new_keycode, 9071 inev.code = KeyTranslate (kchr_ptr, new_keycode,
9011 &some_state) & 0xff; 9072 &some_state) & 0xff;
9012 } else if (!NILP(Vmac_option_modifier) && (er.modifiers & optionKey)) 9073 }
9013 { 9074 else if (!NILP (Vmac_option_modifier)
9014 /* When using the option key as an emacs modifier, convert 9075 && (er.modifiers & optionKey))
9015 the pressed key code back to one without the Mac option 9076 {
9016 modifier applied. */ 9077 /* When using the option key as an emacs modifier,
9017 int new_modifiers = er.modifiers & ~optionKey; 9078 convert the pressed key code back to one
9018 int new_keycode = keycode | new_modifiers; 9079 without the Mac option modifier applied. */
9019 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); 9080 int new_modifiers = er.modifiers & ~optionKey;
9020 unsigned long some_state = 0; 9081 int new_keycode = keycode | new_modifiers;
9021 inev.code = KeyTranslate (kchr_ptr, new_keycode, 9082 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
9022 &some_state) & 0xff; 9083 unsigned long some_state = 0;
9023 } 9084 inev.code = KeyTranslate (kchr_ptr, new_keycode,
9085 &some_state) & 0xff;
9086 }
9024 else 9087 else
9025 inev.code = er.message & charCodeMask; 9088 inev.code = er.message & charCodeMask;
9026 inev.kind = ASCII_KEYSTROKE_EVENT; 9089 inev.kind = ASCII_KEYSTROKE_EVENT;
9027 } 9090 }
9028 } 9091 }
9030 #if USE_CARBON_EVENTS 9093 #if USE_CARBON_EVENTS
9031 inev.modifiers = mac_event_to_emacs_modifiers (eventRef); 9094 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
9032 #else 9095 #else
9033 inev.modifiers = mac_to_emacs_modifiers (er.modifiers); 9096 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
9034 #endif 9097 #endif
9035 XSETFRAME (inev.frame_or_window, 9098 XSETFRAME (inev.frame_or_window, mac_focus_frame (dpyinfo));
9036 mac_window_to_frame (front_emacs_window ()));
9037 inev.timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ 9099 inev.timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
9038 break; 9100 break;
9039 9101
9040 case kHighLevelEvent: 9102 case kHighLevelEvent:
9041 drag_and_drop_file_list = Qnil; 9103 drag_and_drop_file_list = Qnil;
9044 9106
9045 /* Build a DRAG_N_DROP_EVENT type event as is done in 9107 /* Build a DRAG_N_DROP_EVENT type event as is done in
9046 constuct_drag_n_drop in w32term.c. */ 9108 constuct_drag_n_drop in w32term.c. */
9047 if (!NILP (drag_and_drop_file_list)) 9109 if (!NILP (drag_and_drop_file_list))
9048 { 9110 {
9049 struct frame *f = NULL; 9111 struct frame *f = mac_focus_frame (dpyinfo);
9050 WindowPtr wp; 9112 WindowPtr wp;
9051 Lisp_Object frame; 9113 Lisp_Object frame;
9052
9053 wp = front_emacs_window ();
9054
9055 if (!wp)
9056 {
9057 struct frame *f = XFRAME (XCAR (Vframe_list));
9058 CollapseWindow (FRAME_MAC_WINDOW (f), false);
9059 wp = front_emacs_window ();
9060 }
9061
9062 if (wp)
9063 f = mac_window_to_frame (wp);
9064 9114
9065 inev.kind = DRAG_N_DROP_EVENT; 9115 inev.kind = DRAG_N_DROP_EVENT;
9066 inev.code = 0; 9116 inev.code = 0;
9067 inev.timestamp = er.when * (1000 / 60); 9117 inev.timestamp = er.when * (1000 / 60);
9068 /* ticks to milliseconds */ 9118 /* ticks to milliseconds */
9076 XSETINT (inev.y, 0); 9126 XSETINT (inev.y, 0);
9077 9127
9078 XSETFRAME (frame, f); 9128 XSETFRAME (frame, f);
9079 inev.frame_or_window = Fcons (frame, drag_and_drop_file_list); 9129 inev.frame_or_window = Fcons (frame, drag_and_drop_file_list);
9080 9130
9131 #if 0
9081 /* Regardless of whether Emacs was suspended or in the 9132 /* Regardless of whether Emacs was suspended or in the
9082 foreground, ask it to redraw its entire screen. 9133 foreground, ask it to redraw its entire screen.
9083 Otherwise parts of the screen can be left in an 9134 Otherwise parts of the screen can be left in an
9084 inconsistent state. */ 9135 inconsistent state. */
9136 wp = FRAME_MAC_WINDOW (f);
9085 if (wp) 9137 if (wp)
9086 #if TARGET_API_MAC_CARBON 9138 #if TARGET_API_MAC_CARBON
9087 { 9139 {
9088 Rect r; 9140 Rect r;
9089 9141
9091 InvalWindowRect (wp, &r); 9143 InvalWindowRect (wp, &r);
9092 } 9144 }
9093 #else /* not TARGET_API_MAC_CARBON */ 9145 #else /* not TARGET_API_MAC_CARBON */
9094 InvalRect (&(wp->portRect)); 9146 InvalRect (&(wp->portRect));
9095 #endif /* not TARGET_API_MAC_CARBON */ 9147 #endif /* not TARGET_API_MAC_CARBON */
9148 #endif
9096 } 9149 }
9097 default: 9150 default:
9098 break; 9151 break;
9099 } 9152 }
9100 #if USE_CARBON_EVENTS 9153 #if USE_CARBON_EVENTS
9570 e.kind = ASCII_KEYSTROKE_EVENT; 9623 e.kind = ASCII_KEYSTROKE_EVENT;
9571 e.code = quit_char; 9624 e.code = quit_char;
9572 e.arg = Qnil; 9625 e.arg = Qnil;
9573 e.modifiers = NULL; 9626 e.modifiers = NULL;
9574 e.timestamp = EventTimeToTicks (GetEventTime (event)) * (1000/60); 9627 e.timestamp = EventTimeToTicks (GetEventTime (event)) * (1000/60);
9575 XSETFRAME (e.frame_or_window, mac_window_to_frame (front_emacs_window ())); 9628 XSETFRAME (e.frame_or_window, mac_focus_frame (&one_mac_display_info));
9576 /* Remove event from queue to prevent looping. */ 9629 /* Remove event from queue to prevent looping. */
9577 RemoveEventFromQueue (GetMainEventQueue (), event); 9630 RemoveEventFromQueue (GetMainEventQueue (), event);
9578 ReleaseEvent (event); 9631 ReleaseEvent (event);
9579 kbd_buffer_store_event (&e); 9632 kbd_buffer_store_event (&e);
9580 } 9633 }
9763 staticpro (&Qsjis); 9816 staticpro (&Qsjis);
9764 9817
9765 Qeuc_kr = intern ("euc-kr"); 9818 Qeuc_kr = intern ("euc-kr");
9766 staticpro (&Qeuc_kr); 9819 staticpro (&Qeuc_kr);
9767 9820
9768 DEFVAR_BOOL ("x-autoselect-window", &x_autoselect_window_p,
9769 doc: /* *Non-nil means autoselect window with mouse pointer. */);
9770 x_autoselect_window_p = 0;
9771
9772 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, 9821 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
9773 doc: /* If not nil, Emacs uses toolkit scroll bars. */); 9822 doc: /* If not nil, Emacs uses toolkit scroll bars. */);
9774 Vx_toolkit_scroll_bars = Qt; 9823 Vx_toolkit_scroll_bars = Qt;
9775 9824
9776 DEFVAR_BOOL ("x-use-underline-position-properties", 9825 DEFVAR_BOOL ("x-use-underline-position-properties",