diff options
| author | YAMAMOTO Mitsuharu | 2008-04-06 01:58:59 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2008-04-06 01:58:59 +0000 |
| commit | f2ec385ecd26c73ea9014ddfa009999b4cc2b24b (patch) | |
| tree | c6adaf8b1f0eb9e3ede03a00c3eee52bf24cfc39 /src/macterm.c | |
| parent | 5d6c5138509b0bba003bf93d0b6fe9bcc77195af (diff) | |
| download | emacs-f2ec385ecd26c73ea9014ddfa009999b4cc2b24b.tar.gz emacs-f2ec385ecd26c73ea9014ddfa009999b4cc2b24b.zip | |
(mac_end_cg_clip): Add argument F. All uses changed.
(mac_begin_cg_clip, mac_end_cg_clip): Allow null GC.
(mac_invert_rectangle, mac_compute_glyph_string_overhangs)
(mac_load_query_font): Use them instead of SetPortWindowPort.
(mac_clear_window) [!USE_CG_DRAWING]: Likewise.
(mac_draw_image_string_cg): Call CGContextSetTextMatrix.
(x_update_begin, x_update_end): Call mac_update_begin and
mac_update_end.
(XTframe_up_to_date): Call mac_frame_up_to_date.
(XTring_bell): Use mac_alert_sound_play.
(note_mouse_movement): Use mac_get_frame_bounds.
(XTmouse_position): Use mac_get_frame_mouse.
(x_scroll_bar_create): Use mac_create_scroll_bar.
(x_scroll_bar_remove): Use mac_dispose_scroll_bar.
(XTset_vertical_scroll_bar): Use mac_set_scroll_bar_bounds and
mac_redraw_scroll_bar.
(mac_move_window_with_gravity) [USE_MAC_TOOLBAR]: Use mac_move_window
instead of MoveWindow.
(mac_handle_size_change) [TARGET_API_MAC_CARBON]:
Use mac_reposition_hourglass.
(x_set_offset): Use mac_move_window_structure instead of
MoveWindowStructure.
(x_set_window_size): Use mac_size_window instead of SizeWindow.
(x_set_mouse_pixel_position) [MAC_OSX]:
Use mac_convert_frame_point_to_global.
(x_raise_frame): Use mac_bring_window_to_front instead of BringToFront.
(x_lower_frame): Use mac_send_window_behind instead of SendBehind.
(mac_handle_visibility_change): Use Window instead of WindowRef.
Use mac_is_window_visible/mac_is_window_collapsed instead of
IsWindowVisible/IsWindowCollapsed, respectively.
Use mac_collapse_window/mac_show_window instead of
CollapseWindow/ShowWindow, respectively.
(x_make_frame_invisible): Use mac_hide_window instead of HideWindow.
(x_iconify_frame): Use mac_show_window instead of ShowWindow.
Use mac_collapse_window instead of CollapseWindow.
(x_free_frame_resources): Use Window instead of WindowRef.
Use mac_dispose_frame_window. Clean up focus-related variables before
calling mac_dispose_frame_window.
(do_zoom_window) [MAC_OS8]: Use mac_clear_area instead of
mac_clear_window.
(mac_initialize): Use mac_toolbox_initialize instead of
initializing any_help_event_p and calling init_apple_event_handler,
init_tsm, and init_menu_bar.
(any_help_event_p, last_window, save_port_clip_region)
(read_socket_inev, saved_menu_event_location): Move variables to
mactoolbox.c.
(last_scroll_bar_part, scroll_bar_timer)
(scroll_bar_timer_event_posted_p) [USE_TOOLKIT_SCROLL_BARS]: Likewise.
(font_panel_shown_p) [USE_MAC_FONT_PANEL]: Likewise.
(tsm_document_id) [USE_MAC_TSM]: Likewise.
(mouse_region) [!TARGET_API_MAC_CARBON]: Likewise.
(mac_window_to_frame, DEFAULT_NUM_COLS, MIN_DOC_SIZE, MAX_DOC_SIZE):
Move defines to mactoolbox.c.
(FRAME_CG_CONTEXT) [USE_CG_DRAWING]: Likewise.
(SCROLL_BAR_FIRST_DELAY, SCROLL_BAR_CONTINUOUS_DELAY)
[USE_TOOLKIT_SCROLL_BARS]: Likewise.
(TOOLBAR_IDENTIFIER, TOOLBAR_ICON_ITEM_IDENTIFIER)
(TOOLBAR_ITEM_COMMAND_ID_OFFSET, TOOLBAR_ITEM_COMMAND_ID_P)
(TOOLBAR_ITEM_COMMAND_ID_VALUE, TOOLBAR_ITEM_MAKE_COMMAND_ID)
[USE_MAC_TOOLBAR]: Likewise.
(M_APPLE, I_ABOUT, EXTRA_STACK_ALLOC, ARGV_STRING_LIST_ID)
(RAM_TOO_LARGE_ALERT_ID, ABOUT_ALERT_ID): Move defines to macgui.h
(x_flush, is_emacs_window, mac_begin_clip, mac_end_clip)
(x_scroll_bar_handle_click, x_scroll_bar_report_motion)
(mac_get_window_bounds, do_window_update, is_emacs_window)
(do_grow_window, do_zoom_window, install_window_handler)
(remove_window_handler, XTread_socket, init_menu_bar): Move functions
to mactoolbox.c.
(mac_flush_display_optional, mac_begin_cg_clip, mac_end_cg_clip)
(mac_prepare_for_quickdraw) [USE_CG_DRAWING]: Likewise.
(mac_scroll_area, mac_event_to_emacs_modifiers, mac_get_mouse_btn)
(mac_convert_event_ref, mac_get_ideal_size, mac_store_drag_event)
(mac_handle_window_event, mac_handle_keyboard_event)
(mac_handle_command_event, mac_handle_mouse_event)
(install_application_handler, mac_post_mouse_moved_event)
[TARGET_API_MAC_CARBON]: Likewise.
(scroll_bar_timer_callback, install_scroll_bar_timer)
(set_scroll_bar_timer, control_part_code_to_scroll_bar_part)
(construct_scroll_bar_click, get_control_part_bounds)
(x_scroll_bar_handle_press, x_scroll_bar_handle_release)
(x_scroll_bar_handle_drag, x_set_toolkit_scroll_bar_thumb)
[USE_TOOLKIT_SCROLL_BARS]: Likewise.
(x_scroll_bar_set_handle, x_scroll_bar_note_movement)
[!USE_TOOLKIT_SCROLL_BARS]: Likewise.
(mac_handle_toolbar_event, mac_create_frame_tool_bar)
(update_frame_tool_bar, free_frame_tool_bar)
(mac_tool_bar_note_mouse_movement, mac_handle_toolbar_command_event)
[USE_MAC_TOOLBAR]: Likewise.
(mac_font_panel_visible_p, mac_handle_font_event)
(mac_show_hide_font_panel, mac_set_font_info_for_selection)
[USE_MAC_FONT_PANEL]: Likewise.
(mac_handle_text_input_event, init_tsm) [USE_MAC_TSM]: Likewise.
(do_apple_menu, mac_wait_next_event) [!TARGET_API_MAC_CARBON]: Likewise.
(mac_store_service_event) [MAC_OSX]: Likewise.
(last_mouse_glyph, last_mouse_glyph_frame, last_mouse_scroll_bar)
(last_mouse_movement_time, input_signal_count)
(mac_screen_config_changed, Qhi_command, Qtoolbar_switch_mode)
(Qservice, Qpaste, Qperform, keycode_to_xkeysym_table): Make variables
non-static.
(Qpanel_closed, Qselection) [USE_MAC_FONT_PANEL]: Likewise.
(Qtext_input, Vmac_ts_active_input_overlay, Qupdate_active_input_area)
(Qunicode_for_key_event, Vmac_ts_script_language_on_focus)
(saved_ts_script_language_on_focus) [USE_MAC_TSM]: Likewise.
(mac_focus_changed, note_mouse_movement, mac_focus_frame)
(mac_handle_origin_change, mac_handle_size_change)
(mac_handle_visibility_change, mac_to_emacs_modifiers)
(mac_mapped_modifiers, mac_get_emulated_btn, do_keystroke)
(mac_get_screen_info): Make functions non-static.
(mac_move_window_with_gravity, mac_get_window_origin_with_gravity)
(mac_image_spec_to_cg_image) [USE_MAC_TOOLBAR]: Likewise.
(mac_store_event_ref_as_apple_event) [TARGET_API_MAC_CARBON]: Likewise.
(Qwindow, mac_ready_for_apple_events): Move externs to mactoolbox.c.
(Qbefore_string) [USE_MAC_TSM]: Likewise.
(mac_toolbox_initialize, x_scroll_bar_report_motion, XTread_socket):
Add externs.
(mac_flush_display_optional) [USE_CG_DRAWING]: Likewise.
(install_drag_handler, remove_drag_handler, install_service_handler)
(install_menu_target_item_handler): Remove externs.
(XSetWindowBackground): Rename to mac_set_frame_window_background.
Take frame as argument instead of display and window.
Move to mactoolbox.c.
(mac_restore_keyboard_input_source, mac_save_keyboard_input_source)
[USE_MAC_TSM]: New functions created from mac_tsm_resume and
mac_tsm_suspend, respectively.
(mac_tsm_resume, mac_tsm_suspend) [USE_MAC_TSM]: Use them.
Move to mactoolbox.c.
Diffstat (limited to 'src/macterm.c')
| -rw-r--r-- | src/macterm.c | 4028 |
1 files changed, 256 insertions, 3772 deletions
diff --git a/src/macterm.c b/src/macterm.c index 9e5753ec3cc..a043e5a4860 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -91,15 +91,6 @@ Lisp_Object Vx_toolkit_scroll_bars; | |||
| 91 | rendering which may anti-alias the text. */ | 91 | rendering which may anti-alias the text. */ |
| 92 | int mac_use_core_graphics; | 92 | int mac_use_core_graphics; |
| 93 | 93 | ||
| 94 | |||
| 95 | /* Non-zero means that a HELP_EVENT has been generated since Emacs | ||
| 96 | start. */ | ||
| 97 | |||
| 98 | static int any_help_event_p; | ||
| 99 | |||
| 100 | /* Last window where we saw the mouse. Used by mouse-autoselect-window. */ | ||
| 101 | static Lisp_Object last_window; | ||
| 102 | |||
| 103 | /* Non-zero means make use of UNDERLINE_POSITION font properties. | 94 | /* Non-zero means make use of UNDERLINE_POSITION font properties. |
| 104 | (Not yet supported.) */ | 95 | (Not yet supported.) */ |
| 105 | int x_use_underline_position_properties; | 96 | int x_use_underline_position_properties; |
| @@ -159,8 +150,8 @@ struct frame *pending_autoraise_frame; | |||
| 159 | 150 | ||
| 160 | /* Where the mouse was last time we reported a mouse event. */ | 151 | /* Where the mouse was last time we reported a mouse event. */ |
| 161 | 152 | ||
| 162 | static Rect last_mouse_glyph; | 153 | Rect last_mouse_glyph; |
| 163 | static FRAME_PTR last_mouse_glyph_frame; | 154 | FRAME_PTR last_mouse_glyph_frame; |
| 164 | 155 | ||
| 165 | /* The scroll bar in which the last X motion event occurred. | 156 | /* The scroll bar in which the last X motion event occurred. |
| 166 | 157 | ||
| @@ -172,7 +163,7 @@ static FRAME_PTR last_mouse_glyph_frame; | |||
| 172 | this to Qnil, to tell XTmouse_position to return an ordinary motion | 163 | this to Qnil, to tell XTmouse_position to return an ordinary motion |
| 173 | event. */ | 164 | event. */ |
| 174 | 165 | ||
| 175 | static Lisp_Object last_mouse_scroll_bar; | 166 | Lisp_Object last_mouse_scroll_bar; |
| 176 | 167 | ||
| 177 | /* This is a hack. We would really prefer that XTmouse_position would | 168 | /* This is a hack. We would really prefer that XTmouse_position would |
| 178 | return the time associated with the position it returns, but there | 169 | return the time associated with the position it returns, but there |
| @@ -181,7 +172,7 @@ static Lisp_Object last_mouse_scroll_bar; | |||
| 181 | of the last movement we received, and return that in hopes that | 172 | of the last movement we received, and return that in hopes that |
| 182 | it's somewhat accurate. */ | 173 | it's somewhat accurate. */ |
| 183 | 174 | ||
| 184 | static Time last_mouse_movement_time; | 175 | Time last_mouse_movement_time; |
| 185 | 176 | ||
| 186 | struct scroll_bar *tracked_scroll_bar = NULL; | 177 | struct scroll_bar *tracked_scroll_bar = NULL; |
| 187 | 178 | ||
| @@ -189,9 +180,9 @@ struct scroll_bar *tracked_scroll_bar = NULL; | |||
| 189 | events. */ | 180 | events. */ |
| 190 | 181 | ||
| 191 | #ifdef __STDC__ | 182 | #ifdef __STDC__ |
| 192 | static int volatile input_signal_count; | 183 | int volatile input_signal_count; |
| 193 | #else | 184 | #else |
| 194 | static int input_signal_count; | 185 | int input_signal_count; |
| 195 | #endif | 186 | #endif |
| 196 | 187 | ||
| 197 | extern Lisp_Object Vsystem_name; | 188 | extern Lisp_Object Vsystem_name; |
| @@ -212,8 +203,6 @@ extern int inhibit_window_system; | |||
| 212 | QDGlobals qd; /* QuickDraw global information structure. */ | 203 | QDGlobals qd; /* QuickDraw global information structure. */ |
| 213 | #endif | 204 | #endif |
| 214 | 205 | ||
| 215 | #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP) | ||
| 216 | |||
| 217 | struct mac_display_info *mac_display_info_for_display (Display *); | 206 | struct mac_display_info *mac_display_info_for_display (Display *); |
| 218 | static void x_update_window_end P_ ((struct window *, int, int)); | 207 | static void x_update_window_end P_ ((struct window *, int, int)); |
| 219 | int x_catch_errors P_ ((Display *)); | 208 | int x_catch_errors P_ ((Display *)); |
| @@ -237,11 +226,6 @@ static void x_clear_frame P_ ((void)); | |||
| 237 | static void frame_highlight P_ ((struct frame *)); | 226 | static void frame_highlight P_ ((struct frame *)); |
| 238 | static void frame_unhighlight P_ ((struct frame *)); | 227 | static void frame_unhighlight P_ ((struct frame *)); |
| 239 | static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *)); | 228 | static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *)); |
| 240 | static void mac_focus_changed P_ ((int, struct mac_display_info *, | ||
| 241 | struct frame *, struct input_event *)); | ||
| 242 | static void x_detect_focus_change P_ ((struct mac_display_info *, | ||
| 243 | const EventRecord *, | ||
| 244 | struct input_event *)); | ||
| 245 | static void XTframe_rehighlight P_ ((struct frame *)); | 229 | static void XTframe_rehighlight P_ ((struct frame *)); |
| 246 | static void x_frame_rehighlight P_ ((struct x_display_info *)); | 230 | static void x_frame_rehighlight P_ ((struct x_display_info *)); |
| 247 | static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); | 231 | static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); |
| @@ -249,19 +233,22 @@ static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int, | |||
| 249 | enum text_cursor_kinds)); | 233 | enum text_cursor_kinds)); |
| 250 | 234 | ||
| 251 | static void x_clip_to_row P_ ((struct window *, struct glyph_row *, int, GC)); | 235 | static void x_clip_to_row P_ ((struct window *, struct glyph_row *, int, GC)); |
| 252 | static void x_flush P_ ((struct frame *f)); | ||
| 253 | static void x_update_begin P_ ((struct frame *)); | 236 | static void x_update_begin P_ ((struct frame *)); |
| 254 | static void x_update_window_begin P_ ((struct window *)); | 237 | static void x_update_window_begin P_ ((struct window *)); |
| 255 | static void x_after_update_window_line P_ ((struct glyph_row *)); | 238 | static void x_after_update_window_line P_ ((struct glyph_row *)); |
| 256 | static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *, | ||
| 257 | enum scroll_bar_part *, | ||
| 258 | Lisp_Object *, Lisp_Object *, | ||
| 259 | unsigned long *)); | ||
| 260 | 239 | ||
| 261 | static int is_emacs_window P_ ((WindowRef)); | ||
| 262 | static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int)); | 240 | static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int)); |
| 263 | static void XSetFont P_ ((Display *, GC, XFontStruct *)); | 241 | static void XSetFont P_ ((Display *, GC, XFontStruct *)); |
| 264 | 242 | ||
| 243 | extern void mac_toolbox_initialize P_ ((void)); | ||
| 244 | extern void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *, | ||
| 245 | enum scroll_bar_part *, | ||
| 246 | Lisp_Object *, Lisp_Object *, | ||
| 247 | unsigned long *)); | ||
| 248 | #if USE_CG_DRAWING | ||
| 249 | extern void mac_flush_display_optional P_ ((struct frame *)); | ||
| 250 | #endif | ||
| 251 | |||
| 265 | #define GC_FORE_COLOR(gc) (&(gc)->fore_color) | 252 | #define GC_FORE_COLOR(gc) (&(gc)->fore_color) |
| 266 | #define GC_BACK_COLOR(gc) (&(gc)->back_color) | 253 | #define GC_BACK_COLOR(gc) (&(gc)->back_color) |
| 267 | #define GC_FONT(gc) ((gc)->xgcv.font) | 254 | #define GC_FONT(gc) ((gc)->xgcv.font) |
| @@ -324,8 +311,6 @@ static void XSetFont P_ ((Display *, GC, XFontStruct *)); | |||
| 324 | (gc)->cg_fore_color) | 311 | (gc)->cg_fore_color) |
| 325 | 312 | ||
| 326 | #if USE_CG_DRAWING | 313 | #if USE_CG_DRAWING |
| 327 | #define FRAME_CG_CONTEXT(f) ((f)->output_data.mac->cg_context) | ||
| 328 | |||
| 329 | /* Fringe bitmaps. */ | 314 | /* Fringe bitmaps. */ |
| 330 | 315 | ||
| 331 | static int max_fringe_bmp = 0; | 316 | static int max_fringe_bmp = 0; |
| @@ -353,96 +338,7 @@ init_cg_color () | |||
| 353 | } | 338 | } |
| 354 | #endif | 339 | #endif |
| 355 | } | 340 | } |
| 356 | 341 | #endif /* USE_CG_DRAWING */ | |
| 357 | static CGContextRef | ||
| 358 | mac_begin_cg_clip (f, gc) | ||
| 359 | struct frame *f; | ||
| 360 | GC gc; | ||
| 361 | { | ||
| 362 | CGContextRef context = FRAME_CG_CONTEXT (f); | ||
| 363 | |||
| 364 | if (!context) | ||
| 365 | { | ||
| 366 | QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), &context); | ||
| 367 | FRAME_CG_CONTEXT (f) = context; | ||
| 368 | } | ||
| 369 | |||
| 370 | CGContextSaveGState (context); | ||
| 371 | CGContextTranslateCTM (context, 0, FRAME_PIXEL_HEIGHT (f)); | ||
| 372 | CGContextScaleCTM (context, 1, -1); | ||
| 373 | if (gc && gc->n_clip_rects) | ||
| 374 | CGContextClipToRects (context, gc->clip_rects, gc->n_clip_rects); | ||
| 375 | |||
| 376 | return context; | ||
| 377 | } | ||
| 378 | |||
| 379 | static void | ||
| 380 | mac_end_cg_clip (f) | ||
| 381 | struct frame *f; | ||
| 382 | { | ||
| 383 | CGContextRestoreGState (FRAME_CG_CONTEXT (f)); | ||
| 384 | } | ||
| 385 | |||
| 386 | void | ||
| 387 | mac_prepare_for_quickdraw (f) | ||
| 388 | struct frame *f; | ||
| 389 | { | ||
| 390 | if (f == NULL) | ||
| 391 | { | ||
| 392 | Lisp_Object rest, frame; | ||
| 393 | FOR_EACH_FRAME (rest, frame) | ||
| 394 | if (FRAME_MAC_P (XFRAME (frame))) | ||
| 395 | mac_prepare_for_quickdraw (XFRAME (frame)); | ||
| 396 | } | ||
| 397 | else | ||
| 398 | { | ||
| 399 | CGContextRef context = FRAME_CG_CONTEXT (f); | ||
| 400 | |||
| 401 | if (context) | ||
| 402 | { | ||
| 403 | CGContextSynchronize (context); | ||
| 404 | QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), | ||
| 405 | &FRAME_CG_CONTEXT (f)); | ||
| 406 | } | ||
| 407 | } | ||
| 408 | } | ||
| 409 | #endif | ||
| 410 | |||
| 411 | static RgnHandle saved_port_clip_region = NULL; | ||
| 412 | |||
| 413 | static void | ||
| 414 | mac_begin_clip (f, gc) | ||
| 415 | struct frame *f; | ||
| 416 | GC gc; | ||
| 417 | { | ||
| 418 | static RgnHandle new_region = NULL; | ||
| 419 | |||
| 420 | if (saved_port_clip_region == NULL) | ||
| 421 | saved_port_clip_region = NewRgn (); | ||
| 422 | if (new_region == NULL) | ||
| 423 | new_region = NewRgn (); | ||
| 424 | |||
| 425 | #if USE_CG_DRAWING | ||
| 426 | mac_prepare_for_quickdraw (f); | ||
| 427 | #endif | ||
| 428 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 429 | |||
| 430 | if (gc->n_clip_rects) | ||
| 431 | { | ||
| 432 | GetClip (saved_port_clip_region); | ||
| 433 | SectRgn (saved_port_clip_region, gc->clip_region, new_region); | ||
| 434 | SetClip (new_region); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | static void | ||
| 439 | mac_end_clip (gc) | ||
| 440 | GC gc; | ||
| 441 | { | ||
| 442 | if (gc->n_clip_rects) | ||
| 443 | SetClip (saved_port_clip_region); | ||
| 444 | } | ||
| 445 | |||
| 446 | 342 | ||
| 447 | /* X display function emulation */ | 343 | /* X display function emulation */ |
| 448 | 344 | ||
| @@ -491,7 +387,7 @@ mac_draw_line (f, gc, x1, y1, x2, y2) | |||
| 491 | RGBForeColor (GC_FORE_COLOR (gc)); | 387 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 492 | MoveTo (x1, y1); | 388 | MoveTo (x1, y1); |
| 493 | LineTo (x2, y2); | 389 | LineTo (x2, y2); |
| 494 | mac_end_clip (gc); | 390 | mac_end_clip (f, gc); |
| 495 | #endif | 391 | #endif |
| 496 | } | 392 | } |
| 497 | 393 | ||
| @@ -561,7 +457,7 @@ mac_erase_rectangle (f, gc, x, y, width, height) | |||
| 561 | SetRect (&r, x, y, x + width, y + height); | 457 | SetRect (&r, x, y, x + width, y + height); |
| 562 | EraseRect (&r); | 458 | EraseRect (&r); |
| 563 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 459 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 564 | mac_end_clip (gc); | 460 | mac_end_clip (f, gc); |
| 565 | } | 461 | } |
| 566 | #endif | 462 | #endif |
| 567 | } | 463 | } |
| @@ -596,10 +492,8 @@ mac_clear_window (f) | |||
| 596 | mac_end_cg_clip (f); | 492 | mac_end_cg_clip (f); |
| 597 | } | 493 | } |
| 598 | #else /* !USE_CG_DRAWING */ | 494 | #else /* !USE_CG_DRAWING */ |
| 599 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 495 | mac_begin_clip (f, NULL); |
| 600 | |||
| 601 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 496 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 602 | |||
| 603 | #if TARGET_API_MAC_CARBON | 497 | #if TARGET_API_MAC_CARBON |
| 604 | { | 498 | { |
| 605 | Rect r; | 499 | Rect r; |
| @@ -610,6 +504,7 @@ mac_clear_window (f) | |||
| 610 | #else /* not TARGET_API_MAC_CARBON */ | 504 | #else /* not TARGET_API_MAC_CARBON */ |
| 611 | EraseRect (&(FRAME_MAC_WINDOW (f)->portRect)); | 505 | EraseRect (&(FRAME_MAC_WINDOW (f)->portRect)); |
| 612 | #endif /* not TARGET_API_MAC_CARBON */ | 506 | #endif /* not TARGET_API_MAC_CARBON */ |
| 507 | mac_end_clip (f, NULL); | ||
| 613 | #endif | 508 | #endif |
| 614 | } | 509 | } |
| 615 | 510 | ||
| @@ -688,7 +583,7 @@ mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p) | |||
| 688 | overlay_p ? srcOr : srcCopy, 0); | 583 | overlay_p ? srcOr : srcCopy, 0); |
| 689 | #endif /* not TARGET_API_MAC_CARBON */ | 584 | #endif /* not TARGET_API_MAC_CARBON */ |
| 690 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 585 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 691 | mac_end_clip (gc); | 586 | mac_end_clip (f, gc); |
| 692 | } | 587 | } |
| 693 | #endif /* !USE_CG_DRAWING */ | 588 | #endif /* !USE_CG_DRAWING */ |
| 694 | 589 | ||
| @@ -843,7 +738,7 @@ mac_fill_rectangle (f, gc, x, y, width, height) | |||
| 843 | RGBForeColor (GC_FORE_COLOR (gc)); | 738 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 844 | SetRect (&r, x, y, x + width, y + height); | 739 | SetRect (&r, x, y, x + width, y + height); |
| 845 | PaintRect (&r); /* using foreground color of gc */ | 740 | PaintRect (&r); /* using foreground color of gc */ |
| 846 | mac_end_clip (gc); | 741 | mac_end_clip (f, gc); |
| 847 | #endif | 742 | #endif |
| 848 | } | 743 | } |
| 849 | 744 | ||
| @@ -872,7 +767,7 @@ mac_draw_rectangle (f, gc, x, y, width, height) | |||
| 872 | RGBForeColor (GC_FORE_COLOR (gc)); | 767 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 873 | SetRect (&r, x, y, x + width + 1, y + height + 1); | 768 | SetRect (&r, x, y, x + width + 1, y + height + 1); |
| 874 | FrameRect (&r); /* using foreground color of gc */ | 769 | FrameRect (&r); /* using foreground color of gc */ |
| 875 | mac_end_clip (gc); | 770 | mac_end_clip (f, gc); |
| 876 | #endif | 771 | #endif |
| 877 | } | 772 | } |
| 878 | 773 | ||
| @@ -885,14 +780,10 @@ mac_invert_rectangle (f, x, y, width, height) | |||
| 885 | { | 780 | { |
| 886 | Rect r; | 781 | Rect r; |
| 887 | 782 | ||
| 888 | #if USE_CG_DRAWING | 783 | mac_begin_clip (f, NULL); |
| 889 | mac_prepare_for_quickdraw (f); | ||
| 890 | #endif | ||
| 891 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 892 | |||
| 893 | SetRect (&r, x, y, x + width, y + height); | 784 | SetRect (&r, x, y, x + width, y + height); |
| 894 | |||
| 895 | InvertRect (&r); | 785 | InvertRect (&r); |
| 786 | mac_end_clip (f, NULL); | ||
| 896 | } | 787 | } |
| 897 | 788 | ||
| 898 | 789 | ||
| @@ -1008,7 +899,7 @@ mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width, | |||
| 1008 | kATSUFromTextBeginning, kATSUToTextEnd, | 899 | kATSUFromTextBeginning, kATSUToTextEnd, |
| 1009 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | 900 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); |
| 1010 | } | 901 | } |
| 1011 | mac_end_clip (gc); | 902 | mac_end_clip (f, gc); |
| 1012 | #ifdef MAC_OSX | 903 | #ifdef MAC_OSX |
| 1013 | } | 904 | } |
| 1014 | else | 905 | else |
| @@ -1142,7 +1033,7 @@ mac_draw_image_string_qd (f, gc, x, y, buf, nchars, bg_width, | |||
| 1142 | } | 1033 | } |
| 1143 | if (bg_width) | 1034 | if (bg_width) |
| 1144 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1035 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1145 | mac_end_clip (gc); | 1036 | mac_end_clip (f, gc); |
| 1146 | 1037 | ||
| 1147 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | 1038 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 |
| 1148 | if (mac_use_core_graphics) | 1039 | if (mac_use_core_graphics) |
| @@ -1437,6 +1328,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1437 | CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc); | 1328 | CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc); |
| 1438 | CGContextSetFont (context, GC_FONT (gc)->cg_font); | 1329 | CGContextSetFont (context, GC_FONT (gc)->cg_font); |
| 1439 | CGContextSetFontSize (context, GC_FONT (gc)->mac_fontsize); | 1330 | CGContextSetFontSize (context, GC_FONT (gc)->mac_fontsize); |
| 1331 | CGContextSetTextMatrix (context, CGAffineTransformIdentity); | ||
| 1440 | if (GC_FONT (gc)->mac_fontsize <= cg_text_anti_aliasing_threshold) | 1332 | if (GC_FONT (gc)->mac_fontsize <= cg_text_anti_aliasing_threshold) |
| 1441 | CGContextSetShouldAntialias (context, false); | 1333 | CGContextSetShouldAntialias (context, false); |
| 1442 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 | 1334 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 |
| @@ -1521,7 +1413,7 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1521 | 1413 | ||
| 1522 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1414 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1523 | 1415 | ||
| 1524 | mac_end_clip (gc); | 1416 | mac_end_clip (f, gc); |
| 1525 | } | 1417 | } |
| 1526 | 1418 | ||
| 1527 | 1419 | ||
| @@ -1567,13 +1459,18 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y, | |||
| 1567 | 1459 | ||
| 1568 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1460 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1569 | 1461 | ||
| 1570 | mac_end_clip (gc); | 1462 | mac_end_clip (f, gc); |
| 1571 | } | 1463 | } |
| 1572 | #endif /* !USE_CG_DRAWING */ | 1464 | #endif /* !USE_CG_DRAWING */ |
| 1573 | 1465 | ||
| 1574 | 1466 | ||
| 1575 | /* Mac replacement for XCopyArea: used only for scrolling. */ | 1467 | /* Mac replacement for XCopyArea: used only for scrolling. */ |
| 1576 | 1468 | ||
| 1469 | #if TARGET_API_MAC_CARBON | ||
| 1470 | /* Defined in mactoolbox.c. */ | ||
| 1471 | extern void mac_scroll_area P_ ((struct frame *, GC, int, int, | ||
| 1472 | unsigned int, unsigned int, int, int)); | ||
| 1473 | #else /* not TARGET_API_MAC_CARBON */ | ||
| 1577 | static void | 1474 | static void |
| 1578 | mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y) | 1475 | mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y) |
| 1579 | struct frame *f; | 1476 | struct frame *f; |
| @@ -1582,19 +1479,6 @@ mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1582 | unsigned int width, height; | 1479 | unsigned int width, height; |
| 1583 | int dest_x, dest_y; | 1480 | int dest_x, dest_y; |
| 1584 | { | 1481 | { |
| 1585 | #if TARGET_API_MAC_CARBON | ||
| 1586 | Rect src_r; | ||
| 1587 | RgnHandle dummy = NewRgn (); /* For avoiding update events. */ | ||
| 1588 | |||
| 1589 | SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); | ||
| 1590 | #if USE_CG_DRAWING | ||
| 1591 | mac_prepare_for_quickdraw (f); | ||
| 1592 | #endif | ||
| 1593 | ScrollWindowRect (FRAME_MAC_WINDOW (f), | ||
| 1594 | &src_r, dest_x - src_x, dest_y - src_y, | ||
| 1595 | kScrollWindowNoOptions, dummy); | ||
| 1596 | DisposeRgn (dummy); | ||
| 1597 | #else /* not TARGET_API_MAC_CARBON */ | ||
| 1598 | Rect src_r, dest_r; | 1482 | Rect src_r, dest_r; |
| 1599 | WindowRef w = FRAME_MAC_WINDOW (f); | 1483 | WindowRef w = FRAME_MAC_WINDOW (f); |
| 1600 | 1484 | ||
| @@ -1611,9 +1495,9 @@ mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1611 | 1495 | ||
| 1612 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1496 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1613 | 1497 | ||
| 1614 | mac_end_clip (gc); | 1498 | mac_end_clip (f, gc); |
| 1615 | #endif /* not TARGET_API_MAC_CARBON */ | ||
| 1616 | } | 1499 | } |
| 1500 | #endif /* not TARGET_API_MAC_CARBON */ | ||
| 1617 | 1501 | ||
| 1618 | 1502 | ||
| 1619 | /* Mac replacement for XChangeGC. */ | 1503 | /* Mac replacement for XChangeGC. */ |
| @@ -1850,70 +1734,6 @@ mac_reset_clip_rectangles (display, gc) | |||
| 1850 | gc->n_clip_rects = 0; | 1734 | gc->n_clip_rects = 0; |
| 1851 | } | 1735 | } |
| 1852 | 1736 | ||
| 1853 | |||
| 1854 | /* Mac replacement for XSetWindowBackground. */ | ||
| 1855 | |||
| 1856 | void | ||
| 1857 | XSetWindowBackground (display, w, color) | ||
| 1858 | Display *display; | ||
| 1859 | WindowRef w; | ||
| 1860 | unsigned long color; | ||
| 1861 | { | ||
| 1862 | #if !TARGET_API_MAC_CARBON | ||
| 1863 | AuxWinHandle aw_handle; | ||
| 1864 | CTabHandle ctab_handle; | ||
| 1865 | ColorSpecPtr ct_table; | ||
| 1866 | short ct_size; | ||
| 1867 | #endif | ||
| 1868 | RGBColor bg_color; | ||
| 1869 | |||
| 1870 | bg_color.red = RED16_FROM_ULONG (color); | ||
| 1871 | bg_color.green = GREEN16_FROM_ULONG (color); | ||
| 1872 | bg_color.blue = BLUE16_FROM_ULONG (color); | ||
| 1873 | |||
| 1874 | #if TARGET_API_MAC_CARBON | ||
| 1875 | SetWindowContentColor (w, &bg_color); | ||
| 1876 | #else | ||
| 1877 | if (GetAuxWin (w, &aw_handle)) | ||
| 1878 | { | ||
| 1879 | ctab_handle = (*aw_handle)->awCTable; | ||
| 1880 | HandToHand ((Handle *) &ctab_handle); | ||
| 1881 | ct_table = (*ctab_handle)->ctTable; | ||
| 1882 | ct_size = (*ctab_handle)->ctSize; | ||
| 1883 | while (ct_size > -1) | ||
| 1884 | { | ||
| 1885 | if (ct_table->value == 0) | ||
| 1886 | { | ||
| 1887 | ct_table->rgb = bg_color; | ||
| 1888 | CTabChanged (ctab_handle); | ||
| 1889 | SetWinColor (w, (WCTabHandle) ctab_handle); | ||
| 1890 | } | ||
| 1891 | ct_size--; | ||
| 1892 | } | ||
| 1893 | } | ||
| 1894 | #endif | ||
| 1895 | } | ||
| 1896 | |||
| 1897 | /* Flush display of frame F, or of all frames if F is null. */ | ||
| 1898 | |||
| 1899 | static void | ||
| 1900 | x_flush (f) | ||
| 1901 | struct frame *f; | ||
| 1902 | { | ||
| 1903 | #if TARGET_API_MAC_CARBON | ||
| 1904 | BLOCK_INPUT; | ||
| 1905 | #if USE_CG_DRAWING | ||
| 1906 | mac_prepare_for_quickdraw (f); | ||
| 1907 | #endif | ||
| 1908 | if (f) | ||
| 1909 | QDFlushPortBuffer (GetWindowPort (FRAME_MAC_WINDOW (f)), NULL); | ||
| 1910 | else | ||
| 1911 | QDFlushPortBuffer (GetQDGlobalsThePort (), NULL); | ||
| 1912 | UNBLOCK_INPUT; | ||
| 1913 | #endif | ||
| 1914 | } | ||
| 1915 | |||
| 1916 | |||
| 1917 | /* Remove calls to XFlush by defining XFlush to an empty replacement. | 1737 | /* Remove calls to XFlush by defining XFlush to an empty replacement. |
| 1918 | Calls to XFlush should be unnecessary because the X output buffer | 1738 | Calls to XFlush should be unnecessary because the X output buffer |
| 1919 | is flushed automatically as needed by calls to XPending, | 1739 | is flushed automatically as needed by calls to XPending, |
| @@ -1923,16 +1743,6 @@ x_flush (f) | |||
| 1923 | 1743 | ||
| 1924 | #define XFlush(DISPLAY) (void) 0 | 1744 | #define XFlush(DISPLAY) (void) 0 |
| 1925 | 1745 | ||
| 1926 | #if USE_CG_DRAWING | ||
| 1927 | static void | ||
| 1928 | mac_flush_display_optional (f) | ||
| 1929 | struct frame *f; | ||
| 1930 | { | ||
| 1931 | BLOCK_INPUT; | ||
| 1932 | mac_prepare_for_quickdraw (f); | ||
| 1933 | UNBLOCK_INPUT; | ||
| 1934 | } | ||
| 1935 | #endif | ||
| 1936 | 1746 | ||
| 1937 | /*********************************************************************** | 1747 | /*********************************************************************** |
| 1938 | Starting and ending an update | 1748 | Starting and ending an update |
| @@ -1947,17 +1757,9 @@ static void | |||
| 1947 | x_update_begin (f) | 1757 | x_update_begin (f) |
| 1948 | struct frame *f; | 1758 | struct frame *f; |
| 1949 | { | 1759 | { |
| 1950 | #if TARGET_API_MAC_CARBON | ||
| 1951 | /* During update of a frame, availability of input events is | ||
| 1952 | periodically checked with ReceiveNextEvent if | ||
| 1953 | redisplay-dont-pause is nil. That normally flushes window buffer | ||
| 1954 | changes for every check, and thus screen update looks waving even | ||
| 1955 | if no input is available. So we disable screen updates during | ||
| 1956 | update of a frame. */ | ||
| 1957 | BLOCK_INPUT; | 1760 | BLOCK_INPUT; |
| 1958 | DisableScreenUpdates (); | 1761 | mac_update_begin (f); |
| 1959 | UNBLOCK_INPUT; | 1762 | UNBLOCK_INPUT; |
| 1960 | #endif | ||
| 1961 | } | 1763 | } |
| 1962 | 1764 | ||
| 1963 | 1765 | ||
| @@ -2095,9 +1897,7 @@ x_update_end (f) | |||
| 2095 | FRAME_MAC_DISPLAY_INFO (f)->mouse_face_defer = 0; | 1897 | FRAME_MAC_DISPLAY_INFO (f)->mouse_face_defer = 0; |
| 2096 | 1898 | ||
| 2097 | BLOCK_INPUT; | 1899 | BLOCK_INPUT; |
| 2098 | #if TARGET_API_MAC_CARBON | 1900 | mac_update_end (f); |
| 2099 | EnableScreenUpdates (); | ||
| 2100 | #endif | ||
| 2101 | XFlush (FRAME_MAC_DISPLAY (f)); | 1901 | XFlush (FRAME_MAC_DISPLAY (f)); |
| 2102 | UNBLOCK_INPUT; | 1902 | UNBLOCK_INPUT; |
| 2103 | } | 1903 | } |
| @@ -2126,6 +1926,8 @@ XTframe_up_to_date (f) | |||
| 2126 | dpyinfo->mouse_face_deferred_gc = 0; | 1926 | dpyinfo->mouse_face_deferred_gc = 0; |
| 2127 | UNBLOCK_INPUT; | 1927 | UNBLOCK_INPUT; |
| 2128 | } | 1928 | } |
| 1929 | |||
| 1930 | mac_frame_up_to_date (f); | ||
| 2129 | } | 1931 | } |
| 2130 | } | 1932 | } |
| 2131 | 1933 | ||
| @@ -2881,10 +2683,7 @@ mac_compute_glyph_string_overhangs (s) | |||
| 2881 | Rect r; | 2683 | Rect r; |
| 2882 | MacFontStruct *font = s->font; | 2684 | MacFontStruct *font = s->font; |
| 2883 | 2685 | ||
| 2884 | #if USE_CG_DRAWING | 2686 | mac_begin_clip (s->f, NULL); |
| 2885 | mac_prepare_for_quickdraw (s->f); | ||
| 2886 | #endif | ||
| 2887 | SetPortWindowPort (FRAME_MAC_WINDOW (s->f)); | ||
| 2888 | 2687 | ||
| 2889 | TextFont (font->mac_fontnum); | 2688 | TextFont (font->mac_fontnum); |
| 2890 | TextSize (font->mac_fontsize); | 2689 | TextSize (font->mac_fontsize); |
| @@ -2892,6 +2691,8 @@ mac_compute_glyph_string_overhangs (s) | |||
| 2892 | 2691 | ||
| 2893 | QDTextBounds (s->nchars * 2, (char *)s->char2b, &r); | 2692 | QDTextBounds (s->nchars * 2, (char *)s->char2b, &r); |
| 2894 | 2693 | ||
| 2694 | mac_end_clip (s->f, NULL); | ||
| 2695 | |||
| 2895 | s->right_overhang = r.right > s->width ? r.right - s->width : 0; | 2696 | s->right_overhang = r.right > s->width ? r.right - s->width : 0; |
| 2896 | s->left_overhang = r.left < 0 ? -r.left : 0; | 2697 | s->left_overhang = r.left < 0 ? -r.left : 0; |
| 2897 | } | 2698 | } |
| @@ -4250,7 +4051,7 @@ XTring_bell () | |||
| 4250 | #endif | 4051 | #endif |
| 4251 | { | 4052 | { |
| 4252 | BLOCK_INPUT; | 4053 | BLOCK_INPUT; |
| 4253 | SysBeep (1); | 4054 | mac_alert_sound_play (); |
| 4254 | XFlush (FRAME_MAC_DISPLAY (f)); | 4055 | XFlush (FRAME_MAC_DISPLAY (f)); |
| 4255 | UNBLOCK_INPUT; | 4056 | UNBLOCK_INPUT; |
| 4256 | } | 4057 | } |
| @@ -4407,7 +4208,7 @@ x_new_focus_frame (dpyinfo, frame) | |||
| 4407 | If FRAME has focus and there exists more than one frame, puts | 4208 | If FRAME has focus and there exists more than one frame, puts |
| 4408 | a FOCUS_IN_EVENT into *BUFP. */ | 4209 | a FOCUS_IN_EVENT into *BUFP. */ |
| 4409 | 4210 | ||
| 4410 | static void | 4211 | void |
| 4411 | mac_focus_changed (type, dpyinfo, frame, bufp) | 4212 | mac_focus_changed (type, dpyinfo, frame, bufp) |
| 4412 | int type; | 4213 | int type; |
| 4413 | struct mac_display_info *dpyinfo; | 4214 | struct mac_display_info *dpyinfo; |
| @@ -4442,29 +4243,6 @@ mac_focus_changed (type, dpyinfo, frame, bufp) | |||
| 4442 | } | 4243 | } |
| 4443 | } | 4244 | } |
| 4444 | 4245 | ||
| 4445 | /* The focus may have changed. Figure out if it is a real focus change, | ||
| 4446 | by checking both FocusIn/Out and Enter/LeaveNotify events. | ||
| 4447 | |||
| 4448 | Returns FOCUS_IN_EVENT event in *BUFP. */ | ||
| 4449 | |||
| 4450 | static void | ||
| 4451 | x_detect_focus_change (dpyinfo, event, bufp) | ||
| 4452 | struct mac_display_info *dpyinfo; | ||
| 4453 | const EventRecord *event; | ||
| 4454 | struct input_event *bufp; | ||
| 4455 | { | ||
| 4456 | struct frame *frame; | ||
| 4457 | |||
| 4458 | frame = mac_window_to_frame ((WindowRef) event->message); | ||
| 4459 | if (! frame) | ||
| 4460 | return; | ||
| 4461 | |||
| 4462 | /* On Mac, this is only called from focus events, so no switch needed. */ | ||
| 4463 | mac_focus_changed ((event->modifiers & activeFlag), | ||
| 4464 | dpyinfo, frame, bufp); | ||
| 4465 | } | ||
| 4466 | |||
| 4467 | |||
| 4468 | /* Handle an event saying the mouse has moved out of an Emacs frame. */ | 4246 | /* Handle an event saying the mouse has moved out of an Emacs frame. */ |
| 4469 | 4247 | ||
| 4470 | void | 4248 | void |
| @@ -4553,27 +4331,20 @@ x_get_keysym_name (keysym) | |||
| 4553 | static Point last_mouse_motion_position; | 4331 | static Point last_mouse_motion_position; |
| 4554 | static Lisp_Object last_mouse_motion_frame; | 4332 | static Lisp_Object last_mouse_motion_frame; |
| 4555 | 4333 | ||
| 4556 | static int | 4334 | int |
| 4557 | note_mouse_movement (frame, pos) | 4335 | note_mouse_movement (frame, pos) |
| 4558 | FRAME_PTR frame; | 4336 | FRAME_PTR frame; |
| 4559 | Point *pos; | 4337 | Point *pos; |
| 4560 | { | 4338 | { |
| 4561 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (frame); | 4339 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (frame); |
| 4562 | #if TARGET_API_MAC_CARBON | ||
| 4563 | Rect r; | 4340 | Rect r; |
| 4564 | #endif | ||
| 4565 | 4341 | ||
| 4566 | last_mouse_movement_time = TickCount () * (1000 / 60); /* to milliseconds */ | 4342 | last_mouse_movement_time = TickCount () * (1000 / 60); /* to milliseconds */ |
| 4567 | last_mouse_motion_position = *pos; | 4343 | last_mouse_motion_position = *pos; |
| 4568 | XSETFRAME (last_mouse_motion_frame, frame); | 4344 | XSETFRAME (last_mouse_motion_frame, frame); |
| 4569 | 4345 | ||
| 4570 | if (frame == dpyinfo->mouse_face_mouse_frame | 4346 | if (frame == dpyinfo->mouse_face_mouse_frame |
| 4571 | #if TARGET_API_MAC_CARBON | 4347 | && !PtInRect (*pos, mac_get_frame_bounds (frame, &r))) |
| 4572 | && !PtInRect (*pos, GetWindowPortBounds (FRAME_MAC_WINDOW (frame), &r)) | ||
| 4573 | #else | ||
| 4574 | && !PtInRect (*pos, &FRAME_MAC_WINDOW (frame)->portRect) | ||
| 4575 | #endif | ||
| 4576 | ) | ||
| 4577 | { | 4348 | { |
| 4578 | /* This case corresponds to LeaveNotify in X11. If we move | 4349 | /* This case corresponds to LeaveNotify in X11. If we move |
| 4579 | outside the frame, then we're certainly no longer on any text | 4350 | outside the frame, then we're certainly no longer on any text |
| @@ -4619,7 +4390,7 @@ redo_mouse_highlight () | |||
| 4619 | } | 4390 | } |
| 4620 | 4391 | ||
| 4621 | 4392 | ||
| 4622 | static struct frame * | 4393 | struct frame * |
| 4623 | mac_focus_frame (dpyinfo) | 4394 | mac_focus_frame (dpyinfo) |
| 4624 | struct mac_display_info *dpyinfo; | 4395 | struct mac_display_info *dpyinfo; |
| 4625 | { | 4396 | { |
| @@ -4695,14 +4466,7 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time) | |||
| 4695 | the frame are divided into. */ | 4466 | the frame are divided into. */ |
| 4696 | Point mouse_pos; | 4467 | Point mouse_pos; |
| 4697 | 4468 | ||
| 4698 | #if TARGET_API_MAC_CARBON | 4469 | mac_get_frame_mouse (f1, &mouse_pos); |
| 4699 | GetGlobalMouse (&mouse_pos); | ||
| 4700 | mouse_pos.h -= f1->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f1); | ||
| 4701 | mouse_pos.v -= f1->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f1); | ||
| 4702 | #else | ||
| 4703 | SetPortWindowPort (FRAME_MAC_WINDOW (f1)); | ||
| 4704 | GetMouse (&mouse_pos); | ||
| 4705 | #endif | ||
| 4706 | remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, | 4470 | remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, |
| 4707 | &last_mouse_glyph); | 4471 | &last_mouse_glyph); |
| 4708 | last_mouse_glyph_frame = f1; | 4472 | last_mouse_glyph_frame = f1; |
| @@ -4721,305 +4485,6 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time) | |||
| 4721 | 4485 | ||
| 4722 | 4486 | ||
| 4723 | /************************************************************************ | 4487 | /************************************************************************ |
| 4724 | Toolkit scroll bars | ||
| 4725 | ************************************************************************/ | ||
| 4726 | |||
| 4727 | #ifdef USE_TOOLKIT_SCROLL_BARS | ||
| 4728 | |||
| 4729 | static pascal void scroll_bar_timer_callback P_ ((EventLoopTimerRef, void *)); | ||
| 4730 | static OSStatus install_scroll_bar_timer P_ ((void)); | ||
| 4731 | static OSStatus set_scroll_bar_timer P_ ((EventTimerInterval)); | ||
| 4732 | static int control_part_code_to_scroll_bar_part P_ ((ControlPartCode)); | ||
| 4733 | static void construct_scroll_bar_click P_ ((struct scroll_bar *, int, | ||
| 4734 | struct input_event *)); | ||
| 4735 | static OSStatus get_control_part_bounds P_ ((ControlRef, ControlPartCode, | ||
| 4736 | Rect *)); | ||
| 4737 | static void x_scroll_bar_handle_press P_ ((struct scroll_bar *, | ||
| 4738 | ControlPartCode, Point, | ||
| 4739 | struct input_event *)); | ||
| 4740 | static void x_scroll_bar_handle_release P_ ((struct scroll_bar *, | ||
| 4741 | struct input_event *)); | ||
| 4742 | static void x_scroll_bar_handle_drag P_ ((WindowRef, struct scroll_bar *, | ||
| 4743 | Point, struct input_event *)); | ||
| 4744 | static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *, | ||
| 4745 | int, int, int)); | ||
| 4746 | |||
| 4747 | /* Last scroll bar part sent in x_scroll_bar_handle_*. */ | ||
| 4748 | |||
| 4749 | static int last_scroll_bar_part; | ||
| 4750 | |||
| 4751 | static EventLoopTimerRef scroll_bar_timer; | ||
| 4752 | |||
| 4753 | static int scroll_bar_timer_event_posted_p; | ||
| 4754 | |||
| 4755 | #define SCROLL_BAR_FIRST_DELAY 0.5 | ||
| 4756 | #define SCROLL_BAR_CONTINUOUS_DELAY (1.0 / 15) | ||
| 4757 | |||
| 4758 | static pascal void | ||
| 4759 | scroll_bar_timer_callback (timer, data) | ||
| 4760 | EventLoopTimerRef timer; | ||
| 4761 | void *data; | ||
| 4762 | { | ||
| 4763 | OSStatus err; | ||
| 4764 | |||
| 4765 | err = mac_post_mouse_moved_event (); | ||
| 4766 | if (err == noErr) | ||
| 4767 | scroll_bar_timer_event_posted_p = 1; | ||
| 4768 | } | ||
| 4769 | |||
| 4770 | static OSStatus | ||
| 4771 | install_scroll_bar_timer () | ||
| 4772 | { | ||
| 4773 | static EventLoopTimerUPP scroll_bar_timer_callbackUPP = NULL; | ||
| 4774 | |||
| 4775 | if (scroll_bar_timer_callbackUPP == NULL) | ||
| 4776 | scroll_bar_timer_callbackUPP = | ||
| 4777 | NewEventLoopTimerUPP (scroll_bar_timer_callback); | ||
| 4778 | |||
| 4779 | if (scroll_bar_timer == NULL) | ||
| 4780 | /* Mac OS X and CarbonLib 1.5 and later allow us to specify | ||
| 4781 | kEventDurationForever as delays. */ | ||
| 4782 | return | ||
| 4783 | InstallEventLoopTimer (GetCurrentEventLoop (), | ||
| 4784 | kEventDurationForever, kEventDurationForever, | ||
| 4785 | scroll_bar_timer_callbackUPP, NULL, | ||
| 4786 | &scroll_bar_timer); | ||
| 4787 | } | ||
| 4788 | |||
| 4789 | static OSStatus | ||
| 4790 | set_scroll_bar_timer (delay) | ||
| 4791 | EventTimerInterval delay; | ||
| 4792 | { | ||
| 4793 | if (scroll_bar_timer == NULL) | ||
| 4794 | install_scroll_bar_timer (); | ||
| 4795 | |||
| 4796 | scroll_bar_timer_event_posted_p = 0; | ||
| 4797 | |||
| 4798 | return SetEventLoopTimerNextFireTime (scroll_bar_timer, delay); | ||
| 4799 | } | ||
| 4800 | |||
| 4801 | static int | ||
| 4802 | control_part_code_to_scroll_bar_part (part_code) | ||
| 4803 | ControlPartCode part_code; | ||
| 4804 | { | ||
| 4805 | switch (part_code) | ||
| 4806 | { | ||
| 4807 | case kControlUpButtonPart: return scroll_bar_up_arrow; | ||
| 4808 | case kControlDownButtonPart: return scroll_bar_down_arrow; | ||
| 4809 | case kControlPageUpPart: return scroll_bar_above_handle; | ||
| 4810 | case kControlPageDownPart: return scroll_bar_below_handle; | ||
| 4811 | case kControlIndicatorPart: return scroll_bar_handle; | ||
| 4812 | } | ||
| 4813 | |||
| 4814 | return -1; | ||
| 4815 | } | ||
| 4816 | |||
| 4817 | static void | ||
| 4818 | construct_scroll_bar_click (bar, part, bufp) | ||
| 4819 | struct scroll_bar *bar; | ||
| 4820 | int part; | ||
| 4821 | struct input_event *bufp; | ||
| 4822 | { | ||
| 4823 | bufp->kind = SCROLL_BAR_CLICK_EVENT; | ||
| 4824 | bufp->frame_or_window = bar->window; | ||
| 4825 | bufp->arg = Qnil; | ||
| 4826 | bufp->part = part; | ||
| 4827 | bufp->code = 0; | ||
| 4828 | XSETINT (bufp->x, 0); | ||
| 4829 | XSETINT (bufp->y, 0); | ||
| 4830 | bufp->modifiers = 0; | ||
| 4831 | } | ||
| 4832 | |||
| 4833 | static OSStatus | ||
| 4834 | get_control_part_bounds (ch, part_code, rect) | ||
| 4835 | ControlRef ch; | ||
| 4836 | ControlPartCode part_code; | ||
| 4837 | Rect *rect; | ||
| 4838 | { | ||
| 4839 | RgnHandle region = NewRgn (); | ||
| 4840 | OSStatus err; | ||
| 4841 | |||
| 4842 | err = GetControlRegion (ch, part_code, region); | ||
| 4843 | if (err == noErr) | ||
| 4844 | GetRegionBounds (region, rect); | ||
| 4845 | DisposeRgn (region); | ||
| 4846 | |||
| 4847 | return err; | ||
| 4848 | } | ||
| 4849 | |||
| 4850 | static void | ||
| 4851 | x_scroll_bar_handle_press (bar, part_code, mouse_pos, bufp) | ||
| 4852 | struct scroll_bar *bar; | ||
| 4853 | ControlPartCode part_code; | ||
| 4854 | Point mouse_pos; | ||
| 4855 | struct input_event *bufp; | ||
| 4856 | { | ||
| 4857 | int part = control_part_code_to_scroll_bar_part (part_code); | ||
| 4858 | |||
| 4859 | if (part < 0) | ||
| 4860 | return; | ||
| 4861 | |||
| 4862 | if (part != scroll_bar_handle) | ||
| 4863 | { | ||
| 4864 | construct_scroll_bar_click (bar, part, bufp); | ||
| 4865 | HiliteControl (SCROLL_BAR_CONTROL_REF (bar), part_code); | ||
| 4866 | set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY); | ||
| 4867 | bar->dragging = Qnil; | ||
| 4868 | } | ||
| 4869 | else | ||
| 4870 | { | ||
| 4871 | Rect r; | ||
| 4872 | |||
| 4873 | get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar), | ||
| 4874 | kControlIndicatorPart, &r); | ||
| 4875 | XSETINT (bar->dragging, - (mouse_pos.v - r.top) - 1); | ||
| 4876 | } | ||
| 4877 | |||
| 4878 | last_scroll_bar_part = part; | ||
| 4879 | tracked_scroll_bar = bar; | ||
| 4880 | } | ||
| 4881 | |||
| 4882 | static void | ||
| 4883 | x_scroll_bar_handle_release (bar, bufp) | ||
| 4884 | struct scroll_bar *bar; | ||
| 4885 | struct input_event *bufp; | ||
| 4886 | { | ||
| 4887 | if (last_scroll_bar_part != scroll_bar_handle | ||
| 4888 | || (INTEGERP (bar->dragging) && XINT (bar->dragging) >= 0)) | ||
| 4889 | construct_scroll_bar_click (bar, scroll_bar_end_scroll, bufp); | ||
| 4890 | |||
| 4891 | HiliteControl (SCROLL_BAR_CONTROL_REF (bar), 0); | ||
| 4892 | set_scroll_bar_timer (kEventDurationForever); | ||
| 4893 | |||
| 4894 | last_scroll_bar_part = -1; | ||
| 4895 | bar->dragging = Qnil; | ||
| 4896 | tracked_scroll_bar = NULL; | ||
| 4897 | } | ||
| 4898 | |||
| 4899 | static void | ||
| 4900 | x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp) | ||
| 4901 | WindowRef win; | ||
| 4902 | struct scroll_bar *bar; | ||
| 4903 | Point mouse_pos; | ||
| 4904 | struct input_event *bufp; | ||
| 4905 | { | ||
| 4906 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); | ||
| 4907 | |||
| 4908 | if (last_scroll_bar_part == scroll_bar_handle) | ||
| 4909 | { | ||
| 4910 | int top, top_range; | ||
| 4911 | Rect r; | ||
| 4912 | |||
| 4913 | get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar), | ||
| 4914 | kControlIndicatorPart, &r); | ||
| 4915 | |||
| 4916 | if (INTEGERP (bar->dragging) && XINT (bar->dragging) < 0) | ||
| 4917 | XSETINT (bar->dragging, - (XINT (bar->dragging) + 1)); | ||
| 4918 | |||
| 4919 | top = mouse_pos.v - XINT (bar->dragging) - XINT (bar->track_top); | ||
| 4920 | top_range = XINT (bar->track_height) - XINT (bar->min_handle); | ||
| 4921 | |||
| 4922 | if (top < 0) | ||
| 4923 | top = 0; | ||
| 4924 | if (top > top_range) | ||
| 4925 | top = top_range; | ||
| 4926 | |||
| 4927 | construct_scroll_bar_click (bar, scroll_bar_handle, bufp); | ||
| 4928 | XSETINT (bufp->x, top); | ||
| 4929 | XSETINT (bufp->y, top_range); | ||
| 4930 | } | ||
| 4931 | else | ||
| 4932 | { | ||
| 4933 | ControlPartCode part_code; | ||
| 4934 | int unhilite_p = 0, part; | ||
| 4935 | |||
| 4936 | if (ch != FindControlUnderMouse (mouse_pos, win, &part_code)) | ||
| 4937 | unhilite_p = 1; | ||
| 4938 | else | ||
| 4939 | { | ||
| 4940 | part = control_part_code_to_scroll_bar_part (part_code); | ||
| 4941 | |||
| 4942 | switch (last_scroll_bar_part) | ||
| 4943 | { | ||
| 4944 | case scroll_bar_above_handle: | ||
| 4945 | case scroll_bar_below_handle: | ||
| 4946 | if (part != scroll_bar_above_handle | ||
| 4947 | && part != scroll_bar_below_handle) | ||
| 4948 | unhilite_p = 1; | ||
| 4949 | break; | ||
| 4950 | |||
| 4951 | case scroll_bar_up_arrow: | ||
| 4952 | case scroll_bar_down_arrow: | ||
| 4953 | if (part != scroll_bar_up_arrow | ||
| 4954 | && part != scroll_bar_down_arrow) | ||
| 4955 | unhilite_p = 1; | ||
| 4956 | break; | ||
| 4957 | } | ||
| 4958 | } | ||
| 4959 | |||
| 4960 | if (unhilite_p) | ||
| 4961 | HiliteControl (SCROLL_BAR_CONTROL_REF (bar), 0); | ||
| 4962 | else if (part != last_scroll_bar_part | ||
| 4963 | || scroll_bar_timer_event_posted_p) | ||
| 4964 | { | ||
| 4965 | construct_scroll_bar_click (bar, part, bufp); | ||
| 4966 | last_scroll_bar_part = part; | ||
| 4967 | HiliteControl (SCROLL_BAR_CONTROL_REF (bar), part_code); | ||
| 4968 | set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY); | ||
| 4969 | } | ||
| 4970 | } | ||
| 4971 | } | ||
| 4972 | |||
| 4973 | /* Set the thumb size and position of scroll bar BAR. We are currently | ||
| 4974 | displaying PORTION out of a whole WHOLE, and our position POSITION. */ | ||
| 4975 | |||
| 4976 | static void | ||
| 4977 | x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole) | ||
| 4978 | struct scroll_bar *bar; | ||
| 4979 | int portion, position, whole; | ||
| 4980 | { | ||
| 4981 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); | ||
| 4982 | int value, viewsize, maximum; | ||
| 4983 | |||
| 4984 | if (XINT (bar->track_height) == 0) | ||
| 4985 | return; | ||
| 4986 | |||
| 4987 | if (whole <= portion) | ||
| 4988 | value = 0, viewsize = 1, maximum = 0; | ||
| 4989 | else | ||
| 4990 | { | ||
| 4991 | float scale; | ||
| 4992 | |||
| 4993 | maximum = XINT (bar->track_height) - XINT (bar->min_handle); | ||
| 4994 | scale = (float) maximum / (whole - portion); | ||
| 4995 | value = position * scale + 0.5f; | ||
| 4996 | viewsize = (int) (portion * scale + 0.5f) + XINT (bar->min_handle); | ||
| 4997 | } | ||
| 4998 | |||
| 4999 | BLOCK_INPUT; | ||
| 5000 | |||
| 5001 | if (GetControlViewSize (ch) != viewsize | ||
| 5002 | || GetControl32BitValue (ch) != value | ||
| 5003 | || GetControl32BitMaximum (ch) != maximum) | ||
| 5004 | { | ||
| 5005 | /* Temporarily hide the scroll bar to avoid multiple redraws. */ | ||
| 5006 | SetControlVisibility (ch, false, false); | ||
| 5007 | |||
| 5008 | SetControl32BitMaximum (ch, maximum); | ||
| 5009 | SetControl32BitValue (ch, value); | ||
| 5010 | SetControlViewSize (ch, viewsize); | ||
| 5011 | |||
| 5012 | SetControlVisibility (ch, true, true); | ||
| 5013 | } | ||
| 5014 | |||
| 5015 | UNBLOCK_INPUT; | ||
| 5016 | } | ||
| 5017 | |||
| 5018 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | ||
| 5019 | |||
| 5020 | |||
| 5021 | |||
| 5022 | /************************************************************************ | ||
| 5023 | Scroll bars, general | 4488 | Scroll bars, general |
| 5024 | ************************************************************************/ | 4489 | ************************************************************************/ |
| 5025 | 4490 | ||
| @@ -5037,49 +4502,27 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height) | |||
| 5037 | struct scroll_bar *bar | 4502 | struct scroll_bar *bar |
| 5038 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | 4503 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); |
| 5039 | Rect r; | 4504 | Rect r; |
| 5040 | ControlRef ch; | ||
| 5041 | 4505 | ||
| 5042 | BLOCK_INPUT; | 4506 | BLOCK_INPUT; |
| 5043 | 4507 | ||
| 5044 | r.left = left; | ||
| 5045 | r.top = disp_top; | ||
| 5046 | r.right = left + width; | ||
| 5047 | r.bottom = disp_top + disp_height; | ||
| 5048 | |||
| 5049 | #if USE_CG_DRAWING | ||
| 5050 | mac_prepare_for_quickdraw (f); | ||
| 5051 | #endif | ||
| 5052 | #if TARGET_API_MAC_CARBON | ||
| 5053 | ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", | ||
| 5054 | #ifdef USE_TOOLKIT_SCROLL_BARS | ||
| 5055 | false, | ||
| 5056 | #else | ||
| 5057 | width < disp_height, | ||
| 5058 | #endif | ||
| 5059 | 0, 0, 0, kControlScrollBarProc, (long) bar); | ||
| 5060 | #else | ||
| 5061 | ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height, | ||
| 5062 | 0, 0, 0, scrollBarProc, (long) bar); | ||
| 5063 | #endif | ||
| 5064 | SET_SCROLL_BAR_CONTROL_REF (bar, ch); | ||
| 5065 | |||
| 5066 | XSETWINDOW (bar->window, w); | 4508 | XSETWINDOW (bar->window, w); |
| 5067 | XSETINT (bar->top, top); | 4509 | XSETINT (bar->top, top); |
| 5068 | XSETINT (bar->left, left); | 4510 | XSETINT (bar->left, left); |
| 5069 | XSETINT (bar->width, width); | 4511 | XSETINT (bar->width, width); |
| 5070 | XSETINT (bar->height, height); | 4512 | XSETINT (bar->height, height); |
| 5071 | XSETINT (bar->start, 0); | ||
| 5072 | XSETINT (bar->end, 0); | ||
| 5073 | bar->dragging = Qnil; | ||
| 5074 | #ifdef MAC_OSX | 4513 | #ifdef MAC_OSX |
| 5075 | bar->fringe_extended_p = Qnil; | 4514 | bar->fringe_extended_p = Qnil; |
| 5076 | #endif | 4515 | #endif |
| 5077 | bar->redraw_needed_p = Qnil; | 4516 | bar->redraw_needed_p = Qnil; |
| 4517 | |||
| 4518 | SetRect (&r, left, disp_top, left + width, disp_top + disp_height); | ||
| 4519 | mac_create_scroll_bar (bar, &r, | ||
| 5078 | #ifdef USE_TOOLKIT_SCROLL_BARS | 4520 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| 5079 | bar->track_top = Qnil; | 4521 | false |
| 5080 | bar->track_height = Qnil; | 4522 | #else |
| 5081 | bar->min_handle = Qnil; | 4523 | width < disp_height |
| 5082 | #endif | 4524 | #endif |
| 4525 | ); | ||
| 5083 | 4526 | ||
| 5084 | /* Add bar to its frame's list of scroll bars. */ | 4527 | /* Add bar to its frame's list of scroll bars. */ |
| 5085 | bar->next = FRAME_SCROLL_BARS (f); | 4528 | bar->next = FRAME_SCROLL_BARS (f); |
| @@ -5093,82 +4536,6 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height) | |||
| 5093 | } | 4536 | } |
| 5094 | 4537 | ||
| 5095 | 4538 | ||
| 5096 | /* Draw BAR's handle in the proper position. | ||
| 5097 | |||
| 5098 | If the handle is already drawn from START to END, don't bother | ||
| 5099 | redrawing it, unless REBUILD is non-zero; in that case, always | ||
| 5100 | redraw it. (REBUILD is handy for drawing the handle after expose | ||
| 5101 | events.) | ||
| 5102 | |||
| 5103 | Normally, we want to constrain the start and end of the handle to | ||
| 5104 | fit inside its rectangle, but if the user is dragging the scroll | ||
| 5105 | bar handle, we want to let them drag it down all the way, so that | ||
| 5106 | the bar's top is as far down as it goes; otherwise, there's no way | ||
| 5107 | to move to the very end of the buffer. */ | ||
| 5108 | |||
| 5109 | #ifndef USE_TOOLKIT_SCROLL_BARS | ||
| 5110 | |||
| 5111 | static void | ||
| 5112 | x_scroll_bar_set_handle (bar, start, end, rebuild) | ||
| 5113 | struct scroll_bar *bar; | ||
| 5114 | int start, end; | ||
| 5115 | int rebuild; | ||
| 5116 | { | ||
| 5117 | int dragging = ! NILP (bar->dragging); | ||
| 5118 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); | ||
| 5119 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | ||
| 5120 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | ||
| 5121 | int length = end - start; | ||
| 5122 | |||
| 5123 | /* If the display is already accurate, do nothing. */ | ||
| 5124 | if (! rebuild | ||
| 5125 | && start == XINT (bar->start) | ||
| 5126 | && end == XINT (bar->end)) | ||
| 5127 | return; | ||
| 5128 | |||
| 5129 | BLOCK_INPUT; | ||
| 5130 | |||
| 5131 | /* Make sure the values are reasonable, and try to preserve the | ||
| 5132 | distance between start and end. */ | ||
| 5133 | if (start < 0) | ||
| 5134 | start = 0; | ||
| 5135 | else if (start > top_range) | ||
| 5136 | start = top_range; | ||
| 5137 | end = start + length; | ||
| 5138 | |||
| 5139 | if (end < start) | ||
| 5140 | end = start; | ||
| 5141 | else if (end > top_range && ! dragging) | ||
| 5142 | end = top_range; | ||
| 5143 | |||
| 5144 | /* Store the adjusted setting in the scroll bar. */ | ||
| 5145 | XSETINT (bar->start, start); | ||
| 5146 | XSETINT (bar->end, end); | ||
| 5147 | |||
| 5148 | /* Clip the end position, just for display. */ | ||
| 5149 | if (end > top_range) | ||
| 5150 | end = top_range; | ||
| 5151 | |||
| 5152 | /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below | ||
| 5153 | top positions, to make sure the handle is always at least that | ||
| 5154 | many pixels tall. */ | ||
| 5155 | end += VERTICAL_SCROLL_BAR_MIN_HANDLE; | ||
| 5156 | |||
| 5157 | SetControlMinimum (ch, 0); | ||
| 5158 | /* Don't inadvertently activate deactivated scroll bars */ | ||
| 5159 | if (GetControlMaximum (ch) != -1) | ||
| 5160 | SetControlMaximum (ch, top_range + VERTICAL_SCROLL_BAR_MIN_HANDLE | ||
| 5161 | - (end - start)); | ||
| 5162 | SetControlValue (ch, start); | ||
| 5163 | #if TARGET_API_MAC_CARBON | ||
| 5164 | SetControlViewSize (ch, end - start); | ||
| 5165 | #endif | ||
| 5166 | |||
| 5167 | UNBLOCK_INPUT; | ||
| 5168 | } | ||
| 5169 | |||
| 5170 | #endif /* !USE_TOOLKIT_SCROLL_BARS */ | ||
| 5171 | |||
| 5172 | /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to | 4539 | /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to |
| 5173 | nil. */ | 4540 | nil. */ |
| 5174 | 4541 | ||
| @@ -5176,15 +4543,10 @@ static void | |||
| 5176 | x_scroll_bar_remove (bar) | 4543 | x_scroll_bar_remove (bar) |
| 5177 | struct scroll_bar *bar; | 4544 | struct scroll_bar *bar; |
| 5178 | { | 4545 | { |
| 5179 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | ||
| 5180 | |||
| 5181 | BLOCK_INPUT; | 4546 | BLOCK_INPUT; |
| 5182 | 4547 | ||
| 5183 | #if USE_CG_DRAWING | ||
| 5184 | mac_prepare_for_quickdraw (f); | ||
| 5185 | #endif | ||
| 5186 | /* Destroy the Mac scroll bar control */ | 4548 | /* Destroy the Mac scroll bar control */ |
| 5187 | DisposeControl (SCROLL_BAR_CONTROL_REF (bar)); | 4549 | mac_dispose_scroll_bar (bar); |
| 5188 | 4550 | ||
| 5189 | /* Disassociate this scroll bar from its window. */ | 4551 | /* Disassociate this scroll bar from its window. */ |
| 5190 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | 4552 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; |
| @@ -5283,10 +4645,7 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5283 | else | 4645 | else |
| 5284 | { | 4646 | { |
| 5285 | /* It may just need to be moved and resized. */ | 4647 | /* It may just need to be moved and resized. */ |
| 5286 | ControlRef ch; | ||
| 5287 | |||
| 5288 | bar = XSCROLL_BAR (w->vertical_scroll_bar); | 4648 | bar = XSCROLL_BAR (w->vertical_scroll_bar); |
| 5289 | ch = SCROLL_BAR_CONTROL_REF (bar); | ||
| 5290 | 4649 | ||
| 5291 | BLOCK_INPUT; | 4650 | BLOCK_INPUT; |
| 5292 | 4651 | ||
| @@ -5301,15 +4660,12 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5301 | ) | 4660 | ) |
| 5302 | { | 4661 | { |
| 5303 | if (!NILP (bar->redraw_needed_p)) | 4662 | if (!NILP (bar->redraw_needed_p)) |
| 5304 | { | 4663 | mac_redraw_scroll_bar (bar); |
| 5305 | #if USE_CG_DRAWING | ||
| 5306 | mac_prepare_for_quickdraw (f); | ||
| 5307 | #endif | ||
| 5308 | Draw1Control (SCROLL_BAR_CONTROL_REF (bar)); | ||
| 5309 | } | ||
| 5310 | } | 4664 | } |
| 5311 | else | 4665 | else |
| 5312 | { | 4666 | { |
| 4667 | Rect r; | ||
| 4668 | |||
| 5313 | /* Since toolkit scroll bars are smaller than the space reserved | 4669 | /* Since toolkit scroll bars are smaller than the space reserved |
| 5314 | for them on the frame, we have to clear "under" them. */ | 4670 | for them on the frame, we have to clear "under" them. */ |
| 5315 | #ifdef MAC_OSX | 4671 | #ifdef MAC_OSX |
| @@ -5319,28 +4675,16 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5319 | #endif | 4675 | #endif |
| 5320 | mac_clear_area (f, left, top, width, height); | 4676 | mac_clear_area (f, left, top, width, height); |
| 5321 | 4677 | ||
| 5322 | #if USE_CG_DRAWING | 4678 | SetRect (&r, sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, disp_top, |
| 5323 | mac_prepare_for_quickdraw (f); | 4679 | sb_left + sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM, |
| 5324 | #endif | 4680 | disp_top + disp_height); |
| 5325 | HideControl (ch); | 4681 | mac_set_scroll_bar_bounds (bar, &r); |
| 5326 | MoveControl (ch, sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, disp_top); | ||
| 5327 | SizeControl (ch, sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | ||
| 5328 | disp_height); | ||
| 5329 | #ifndef USE_TOOLKIT_SCROLL_BARS | ||
| 5330 | if (sb_width < disp_height) | ||
| 5331 | ShowControl (ch); | ||
| 5332 | #endif | ||
| 5333 | 4682 | ||
| 5334 | /* Remember new settings. */ | 4683 | /* Remember new settings. */ |
| 5335 | XSETINT (bar->left, sb_left); | 4684 | XSETINT (bar->left, sb_left); |
| 5336 | XSETINT (bar->top, top); | 4685 | XSETINT (bar->top, top); |
| 5337 | XSETINT (bar->width, sb_width); | 4686 | XSETINT (bar->width, sb_width); |
| 5338 | XSETINT (bar->height, height); | 4687 | XSETINT (bar->height, height); |
| 5339 | #ifdef USE_TOOLKIT_SCROLL_BARS | ||
| 5340 | bar->track_top = Qnil; | ||
| 5341 | bar->track_height = Qnil; | ||
| 5342 | bar->min_handle = Qnil; | ||
| 5343 | #endif | ||
| 5344 | } | 4688 | } |
| 5345 | 4689 | ||
| 5346 | UNBLOCK_INPUT; | 4690 | UNBLOCK_INPUT; |
| @@ -5352,51 +4696,6 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5352 | bar->redraw_needed_p = Qnil; | 4696 | bar->redraw_needed_p = Qnil; |
| 5353 | 4697 | ||
| 5354 | #ifdef USE_TOOLKIT_SCROLL_BARS | 4698 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| 5355 | if (NILP (bar->track_top)) | ||
| 5356 | { | ||
| 5357 | if (sb_width >= disp_height | ||
| 5358 | #ifdef MAC_OSX | ||
| 5359 | || sb_width < MAC_AQUA_SMALL_VERTICAL_SCROLL_BAR_WIDTH | ||
| 5360 | #endif | ||
| 5361 | ) | ||
| 5362 | { | ||
| 5363 | XSETINT (bar->track_top, 0); | ||
| 5364 | XSETINT (bar->track_height, 0); | ||
| 5365 | XSETINT (bar->min_handle, 0); | ||
| 5366 | } | ||
| 5367 | else | ||
| 5368 | { | ||
| 5369 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); | ||
| 5370 | Rect r0, r1; | ||
| 5371 | |||
| 5372 | BLOCK_INPUT; | ||
| 5373 | |||
| 5374 | SetControl32BitMinimum (ch, 0); | ||
| 5375 | SetControl32BitMaximum (ch, 1 << 30); | ||
| 5376 | SetControlViewSize (ch, 1); | ||
| 5377 | |||
| 5378 | /* Move the scroll bar thumb to the top. */ | ||
| 5379 | SetControl32BitValue (ch, 0); | ||
| 5380 | get_control_part_bounds (ch, kControlIndicatorPart, &r0); | ||
| 5381 | |||
| 5382 | /* Move the scroll bar thumb to the bottom. */ | ||
| 5383 | SetControl32BitValue (ch, 1 << 30); | ||
| 5384 | get_control_part_bounds (ch, kControlIndicatorPart, &r1); | ||
| 5385 | |||
| 5386 | UnionRect (&r0, &r1, &r0); | ||
| 5387 | XSETINT (bar->track_top, r0.top); | ||
| 5388 | XSETINT (bar->track_height, r0.bottom - r0.top); | ||
| 5389 | XSETINT (bar->min_handle, r1.bottom - r1.top); | ||
| 5390 | |||
| 5391 | /* Don't show the scroll bar if its height is not enough to | ||
| 5392 | display the scroll bar thumb. */ | ||
| 5393 | if (r0.bottom - r0.top > 0) | ||
| 5394 | ShowControl (ch); | ||
| 5395 | |||
| 5396 | UNBLOCK_INPUT; | ||
| 5397 | } | ||
| 5398 | } | ||
| 5399 | |||
| 5400 | x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole); | 4699 | x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole); |
| 5401 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | 4700 | #else /* not USE_TOOLKIT_SCROLL_BARS */ |
| 5402 | /* Set the scroll bar's current state, unless we're currently being | 4701 | /* Set the scroll bar's current state, unless we're currently being |
| @@ -5524,181 +4823,6 @@ XTjudge_scroll_bars (f) | |||
| 5524 | and they should get garbage-collected. */ | 4823 | and they should get garbage-collected. */ |
| 5525 | } | 4824 | } |
| 5526 | 4825 | ||
| 5527 | |||
| 5528 | /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind | ||
| 5529 | is set to something other than NO_EVENT, it is enqueued. | ||
| 5530 | |||
| 5531 | This may be called from a signal handler, so we have to ignore GC | ||
| 5532 | mark bits. */ | ||
| 5533 | |||
| 5534 | static void | ||
| 5535 | x_scroll_bar_handle_click (bar, part_code, er, bufp) | ||
| 5536 | struct scroll_bar *bar; | ||
| 5537 | ControlPartCode part_code; | ||
| 5538 | const EventRecord *er; | ||
| 5539 | struct input_event *bufp; | ||
| 5540 | { | ||
| 5541 | int win_y, top_range; | ||
| 5542 | |||
| 5543 | if (! GC_WINDOWP (bar->window)) | ||
| 5544 | abort (); | ||
| 5545 | |||
| 5546 | bufp->kind = SCROLL_BAR_CLICK_EVENT; | ||
| 5547 | bufp->frame_or_window = bar->window; | ||
| 5548 | bufp->arg = Qnil; | ||
| 5549 | |||
| 5550 | bar->dragging = Qnil; | ||
| 5551 | |||
| 5552 | switch (part_code) | ||
| 5553 | { | ||
| 5554 | case kControlUpButtonPart: | ||
| 5555 | bufp->part = scroll_bar_up_arrow; | ||
| 5556 | break; | ||
| 5557 | case kControlDownButtonPart: | ||
| 5558 | bufp->part = scroll_bar_down_arrow; | ||
| 5559 | break; | ||
| 5560 | case kControlPageUpPart: | ||
| 5561 | bufp->part = scroll_bar_above_handle; | ||
| 5562 | break; | ||
| 5563 | case kControlPageDownPart: | ||
| 5564 | bufp->part = scroll_bar_below_handle; | ||
| 5565 | break; | ||
| 5566 | #if TARGET_API_MAC_CARBON | ||
| 5567 | default: | ||
| 5568 | #else | ||
| 5569 | case kControlIndicatorPart: | ||
| 5570 | #endif | ||
| 5571 | if (er->what == mouseDown) | ||
| 5572 | bar->dragging = make_number (0); | ||
| 5573 | XSETVECTOR (last_mouse_scroll_bar, bar); | ||
| 5574 | bufp->part = scroll_bar_handle; | ||
| 5575 | break; | ||
| 5576 | } | ||
| 5577 | |||
| 5578 | win_y = XINT (bufp->y) - XINT (bar->top); | ||
| 5579 | top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (0/*dummy*/, XINT (bar->height)); | ||
| 5580 | |||
| 5581 | win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER; | ||
| 5582 | |||
| 5583 | win_y -= 24; | ||
| 5584 | |||
| 5585 | if (! NILP (bar->dragging)) | ||
| 5586 | win_y -= XINT (bar->dragging); | ||
| 5587 | |||
| 5588 | if (win_y < 0) | ||
| 5589 | win_y = 0; | ||
| 5590 | if (win_y > top_range) | ||
| 5591 | win_y = top_range; | ||
| 5592 | |||
| 5593 | XSETINT (bufp->x, win_y); | ||
| 5594 | XSETINT (bufp->y, top_range); | ||
| 5595 | } | ||
| 5596 | |||
| 5597 | #ifndef USE_TOOLKIT_SCROLL_BARS | ||
| 5598 | |||
| 5599 | /* Handle some mouse motion while someone is dragging the scroll bar. | ||
| 5600 | |||
| 5601 | This may be called from a signal handler, so we have to ignore GC | ||
| 5602 | mark bits. */ | ||
| 5603 | |||
| 5604 | static void | ||
| 5605 | x_scroll_bar_note_movement (bar, y_pos, t) | ||
| 5606 | struct scroll_bar *bar; | ||
| 5607 | int y_pos; | ||
| 5608 | Time t; | ||
| 5609 | { | ||
| 5610 | FRAME_PTR f = XFRAME (XWINDOW (bar->window)->frame); | ||
| 5611 | |||
| 5612 | last_mouse_movement_time = t; | ||
| 5613 | |||
| 5614 | f->mouse_moved = 1; | ||
| 5615 | XSETVECTOR (last_mouse_scroll_bar, bar); | ||
| 5616 | |||
| 5617 | /* If we're dragging the bar, display it. */ | ||
| 5618 | if (! GC_NILP (bar->dragging)) | ||
| 5619 | { | ||
| 5620 | /* Where should the handle be now? */ | ||
| 5621 | int new_start = y_pos - 24; | ||
| 5622 | |||
| 5623 | if (new_start != XINT (bar->start)) | ||
| 5624 | { | ||
| 5625 | int new_end = new_start + (XINT (bar->end) - XINT (bar->start)); | ||
| 5626 | |||
| 5627 | x_scroll_bar_set_handle (bar, new_start, new_end, 0); | ||
| 5628 | } | ||
| 5629 | } | ||
| 5630 | } | ||
| 5631 | |||
| 5632 | #endif /* !USE_TOOLKIT_SCROLL_BARS */ | ||
| 5633 | |||
| 5634 | /* Return information to the user about the current position of the mouse | ||
| 5635 | on the scroll bar. */ | ||
| 5636 | |||
| 5637 | static void | ||
| 5638 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) | ||
| 5639 | FRAME_PTR *fp; | ||
| 5640 | Lisp_Object *bar_window; | ||
| 5641 | enum scroll_bar_part *part; | ||
| 5642 | Lisp_Object *x, *y; | ||
| 5643 | unsigned long *time; | ||
| 5644 | { | ||
| 5645 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); | ||
| 5646 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); | ||
| 5647 | #if TARGET_API_MAC_CARBON | ||
| 5648 | WindowRef wp = GetControlOwner (ch); | ||
| 5649 | #else | ||
| 5650 | WindowRef wp = (*ch)->contrlOwner; | ||
| 5651 | #endif | ||
| 5652 | Point mouse_pos; | ||
| 5653 | struct frame *f = mac_window_to_frame (wp); | ||
| 5654 | int win_y, top_range; | ||
| 5655 | |||
| 5656 | #if TARGET_API_MAC_CARBON | ||
| 5657 | GetGlobalMouse (&mouse_pos); | ||
| 5658 | mouse_pos.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); | ||
| 5659 | mouse_pos.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); | ||
| 5660 | #else | ||
| 5661 | SetPortWindowPort (wp); | ||
| 5662 | GetMouse (&mouse_pos); | ||
| 5663 | #endif | ||
| 5664 | |||
| 5665 | win_y = mouse_pos.v - XINT (bar->top); | ||
| 5666 | top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | ||
| 5667 | |||
| 5668 | win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER; | ||
| 5669 | |||
| 5670 | win_y -= 24; | ||
| 5671 | |||
| 5672 | if (! NILP (bar->dragging)) | ||
| 5673 | win_y -= XINT (bar->dragging); | ||
| 5674 | |||
| 5675 | if (win_y < 0) | ||
| 5676 | win_y = 0; | ||
| 5677 | if (win_y > top_range) | ||
| 5678 | win_y = top_range; | ||
| 5679 | |||
| 5680 | *fp = f; | ||
| 5681 | *bar_window = bar->window; | ||
| 5682 | |||
| 5683 | if (! NILP (bar->dragging)) | ||
| 5684 | *part = scroll_bar_handle; | ||
| 5685 | else if (win_y < XINT (bar->start)) | ||
| 5686 | *part = scroll_bar_above_handle; | ||
| 5687 | else if (win_y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE) | ||
| 5688 | *part = scroll_bar_handle; | ||
| 5689 | else | ||
| 5690 | *part = scroll_bar_below_handle; | ||
| 5691 | |||
| 5692 | XSETINT (*x, win_y); | ||
| 5693 | XSETINT (*y, top_range); | ||
| 5694 | |||
| 5695 | f->mouse_moved = 0; | ||
| 5696 | last_mouse_scroll_bar = Qnil; | ||
| 5697 | |||
| 5698 | *time = last_mouse_movement_time; | ||
| 5699 | } | ||
| 5700 | |||
| 5701 | |||
| 5702 | /* The screen has been cleared so we may have changed foreground or | 4826 | /* The screen has been cleared so we may have changed foreground or |
| 5703 | background colors, and the scroll bars may need to be redrawn. | 4827 | background colors, and the scroll bars may need to be redrawn. |
| 5704 | Clear out the scroll bars, and ask for expose events, so we can | 4828 | Clear out the scroll bars, and ask for expose events, so we can |
| @@ -5724,27 +4848,7 @@ x_scroll_bar_clear (f) | |||
| 5724 | Tool-bars | 4848 | Tool-bars |
| 5725 | ***********************************************************************/ | 4849 | ***********************************************************************/ |
| 5726 | #if USE_MAC_TOOLBAR | 4850 | #if USE_MAC_TOOLBAR |
| 5727 | 4851 | void | |
| 5728 | /* In identifiers such as function/variable names, Emacs tool bar is | ||
| 5729 | referred to as `tool_bar', and Carbon HIToolbar as `toolbar'. */ | ||
| 5730 | |||
| 5731 | #define TOOLBAR_IDENTIFIER (CFSTR ("org.gnu.Emacs.toolbar")) | ||
| 5732 | #define TOOLBAR_ICON_ITEM_IDENTIFIER (CFSTR ("org.gnu.Emacs.toolbar.icon")) | ||
| 5733 | |||
| 5734 | #define TOOLBAR_ITEM_COMMAND_ID_OFFSET 'Tb\0\0' | ||
| 5735 | #define TOOLBAR_ITEM_COMMAND_ID_P(id) \ | ||
| 5736 | (((id) & ~0xffff) == TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5737 | #define TOOLBAR_ITEM_COMMAND_ID_VALUE(id) \ | ||
| 5738 | ((id) - TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5739 | #define TOOLBAR_ITEM_MAKE_COMMAND_ID(value) \ | ||
| 5740 | ((value) + TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5741 | |||
| 5742 | static int mac_event_to_emacs_modifiers P_ ((EventRef)); | ||
| 5743 | static void mac_handle_origin_change P_ ((struct frame *)); | ||
| 5744 | static OSStatus mac_handle_toolbar_command_event P_ ((EventHandlerCallRef, | ||
| 5745 | EventRef, void *)); | ||
| 5746 | |||
| 5747 | static void | ||
| 5748 | mac_move_window_with_gravity (f, win_gravity, left, top) | 4852 | mac_move_window_with_gravity (f, win_gravity, left, top) |
| 5749 | struct frame *f; | 4853 | struct frame *f; |
| 5750 | int win_gravity; | 4854 | int win_gravity; |
| @@ -5796,10 +4900,10 @@ mac_move_window_with_gravity (f, win_gravity, left, top) | |||
| 5796 | break; | 4900 | break; |
| 5797 | } | 4901 | } |
| 5798 | 4902 | ||
| 5799 | MoveWindow (FRAME_MAC_WINDOW (f), left, top, false); | 4903 | mac_move_window (FRAME_MAC_WINDOW (f), left, top, false); |
| 5800 | } | 4904 | } |
| 5801 | 4905 | ||
| 5802 | static void | 4906 | void |
| 5803 | mac_get_window_origin_with_gravity (f, win_gravity, left, top) | 4907 | mac_get_window_origin_with_gravity (f, win_gravity, left, top) |
| 5804 | struct frame *f; | 4908 | struct frame *f; |
| 5805 | int win_gravity; | 4909 | int win_gravity; |
| @@ -5854,65 +4958,7 @@ mac_get_window_origin_with_gravity (f, win_gravity, left, top) | |||
| 5854 | } | 4958 | } |
| 5855 | } | 4959 | } |
| 5856 | 4960 | ||
| 5857 | static OSStatus | 4961 | CGImageRef |
| 5858 | mac_handle_toolbar_event (next_handler, event, data) | ||
| 5859 | EventHandlerCallRef next_handler; | ||
| 5860 | EventRef event; | ||
| 5861 | void *data; | ||
| 5862 | { | ||
| 5863 | OSStatus err, result = eventNotHandledErr; | ||
| 5864 | |||
| 5865 | switch (GetEventKind (event)) | ||
| 5866 | { | ||
| 5867 | case kEventToolbarGetDefaultIdentifiers: | ||
| 5868 | result = noErr; | ||
| 5869 | break; | ||
| 5870 | |||
| 5871 | case kEventToolbarGetAllowedIdentifiers: | ||
| 5872 | { | ||
| 5873 | CFMutableArrayRef array; | ||
| 5874 | |||
| 5875 | GetEventParameter (event, kEventParamMutableArray, | ||
| 5876 | typeCFMutableArrayRef, NULL, | ||
| 5877 | sizeof (CFMutableArrayRef), NULL, &array); | ||
| 5878 | CFArrayAppendValue (array, TOOLBAR_ICON_ITEM_IDENTIFIER); | ||
| 5879 | result = noErr; | ||
| 5880 | } | ||
| 5881 | break; | ||
| 5882 | |||
| 5883 | case kEventToolbarCreateItemWithIdentifier: | ||
| 5884 | { | ||
| 5885 | CFStringRef identifier; | ||
| 5886 | HIToolbarItemRef item = NULL; | ||
| 5887 | |||
| 5888 | GetEventParameter (event, kEventParamToolbarItemIdentifier, | ||
| 5889 | typeCFStringRef, NULL, | ||
| 5890 | sizeof (CFStringRef), NULL, &identifier); | ||
| 5891 | |||
| 5892 | if (CFStringCompare (identifier, TOOLBAR_ICON_ITEM_IDENTIFIER, 0) | ||
| 5893 | == kCFCompareEqualTo) | ||
| 5894 | HIToolbarItemCreate (identifier, | ||
| 5895 | kHIToolbarItemAllowDuplicates | ||
| 5896 | | kHIToolbarItemCantBeRemoved, &item); | ||
| 5897 | |||
| 5898 | if (item) | ||
| 5899 | { | ||
| 5900 | SetEventParameter (event, kEventParamToolbarItem, | ||
| 5901 | typeHIToolbarItemRef, | ||
| 5902 | sizeof (HIToolbarItemRef), &item); | ||
| 5903 | result = noErr; | ||
| 5904 | } | ||
| 5905 | } | ||
| 5906 | break; | ||
| 5907 | |||
| 5908 | default: | ||
| 5909 | abort (); | ||
| 5910 | } | ||
| 5911 | |||
| 5912 | return result; | ||
| 5913 | } | ||
| 5914 | |||
| 5915 | static CGImageRef | ||
| 5916 | mac_image_spec_to_cg_image (f, image) | 4962 | mac_image_spec_to_cg_image (f, image) |
| 5917 | struct frame *f; | 4963 | struct frame *f; |
| 5918 | Lisp_Object image; | 4964 | Lisp_Object image; |
| @@ -5929,341 +4975,6 @@ mac_image_spec_to_cg_image (f, image) | |||
| 5929 | return img->data.ptr_val; | 4975 | return img->data.ptr_val; |
| 5930 | } | 4976 | } |
| 5931 | } | 4977 | } |
| 5932 | |||
| 5933 | /* Create a tool bar for frame F. */ | ||
| 5934 | |||
| 5935 | static OSStatus | ||
| 5936 | mac_create_frame_tool_bar (f) | ||
| 5937 | FRAME_PTR f; | ||
| 5938 | { | ||
| 5939 | OSStatus err; | ||
| 5940 | HIToolbarRef toolbar; | ||
| 5941 | |||
| 5942 | err = HIToolbarCreate (TOOLBAR_IDENTIFIER, kHIToolbarNoAttributes, | ||
| 5943 | &toolbar); | ||
| 5944 | if (err == noErr) | ||
| 5945 | { | ||
| 5946 | static const EventTypeSpec specs[] = | ||
| 5947 | {{kEventClassToolbar, kEventToolbarGetDefaultIdentifiers}, | ||
| 5948 | {kEventClassToolbar, kEventToolbarGetAllowedIdentifiers}, | ||
| 5949 | {kEventClassToolbar, kEventToolbarCreateItemWithIdentifier}}; | ||
| 5950 | |||
| 5951 | err = InstallEventHandler (HIObjectGetEventTarget (toolbar), | ||
| 5952 | mac_handle_toolbar_event, | ||
| 5953 | GetEventTypeCount (specs), specs, | ||
| 5954 | f, NULL); | ||
| 5955 | } | ||
| 5956 | |||
| 5957 | if (err == noErr) | ||
| 5958 | err = HIToolbarSetDisplayMode (toolbar, kHIToolbarDisplayModeIconOnly); | ||
| 5959 | if (err == noErr) | ||
| 5960 | { | ||
| 5961 | static const EventTypeSpec specs[] = | ||
| 5962 | {{kEventClassCommand, kEventCommandProcess}}; | ||
| 5963 | |||
| 5964 | err = InstallWindowEventHandler (FRAME_MAC_WINDOW (f), | ||
| 5965 | mac_handle_toolbar_command_event, | ||
| 5966 | GetEventTypeCount (specs), | ||
| 5967 | specs, f, NULL); | ||
| 5968 | } | ||
| 5969 | if (err == noErr) | ||
| 5970 | err = SetWindowToolbar (FRAME_MAC_WINDOW (f), toolbar); | ||
| 5971 | |||
| 5972 | if (toolbar) | ||
| 5973 | CFRelease (toolbar); | ||
| 5974 | |||
| 5975 | return err; | ||
| 5976 | } | ||
| 5977 | |||
| 5978 | /* Update the tool bar for frame F. Add new buttons and remove old. */ | ||
| 5979 | |||
| 5980 | void | ||
| 5981 | update_frame_tool_bar (f) | ||
| 5982 | FRAME_PTR f; | ||
| 5983 | { | ||
| 5984 | HIToolbarRef toolbar = NULL; | ||
| 5985 | short left, top; | ||
| 5986 | CFArrayRef old_items = NULL; | ||
| 5987 | CFIndex old_count; | ||
| 5988 | int i, pos, win_gravity = f->output_data.mac->toolbar_win_gravity; | ||
| 5989 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 5990 | |||
| 5991 | BLOCK_INPUT; | ||
| 5992 | |||
| 5993 | GetWindowToolbar (FRAME_MAC_WINDOW (f), &toolbar); | ||
| 5994 | if (toolbar == NULL) | ||
| 5995 | { | ||
| 5996 | mac_create_frame_tool_bar (f); | ||
| 5997 | GetWindowToolbar (FRAME_MAC_WINDOW (f), &toolbar); | ||
| 5998 | if (toolbar == NULL) | ||
| 5999 | goto out; | ||
| 6000 | if (win_gravity >= NorthWestGravity && win_gravity <= SouthEastGravity) | ||
| 6001 | mac_get_window_origin_with_gravity (f, win_gravity, &left, &top); | ||
| 6002 | } | ||
| 6003 | |||
| 6004 | HIToolbarCopyItems (toolbar, &old_items); | ||
| 6005 | if (old_items == NULL) | ||
| 6006 | goto out; | ||
| 6007 | |||
| 6008 | old_count = CFArrayGetCount (old_items); | ||
| 6009 | pos = 0; | ||
| 6010 | for (i = 0; i < f->n_tool_bar_items; ++i) | ||
| 6011 | { | ||
| 6012 | #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX)) | ||
| 6013 | |||
| 6014 | int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); | ||
| 6015 | int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); | ||
| 6016 | int idx; | ||
| 6017 | Lisp_Object image; | ||
| 6018 | CGImageRef cg_image; | ||
| 6019 | CFStringRef label; | ||
| 6020 | HIToolbarItemRef item; | ||
| 6021 | |||
| 6022 | /* If image is a vector, choose the image according to the | ||
| 6023 | button state. */ | ||
| 6024 | image = PROP (TOOL_BAR_ITEM_IMAGES); | ||
| 6025 | if (VECTORP (image)) | ||
| 6026 | { | ||
| 6027 | if (enabled_p) | ||
| 6028 | idx = (selected_p | ||
| 6029 | ? TOOL_BAR_IMAGE_ENABLED_SELECTED | ||
| 6030 | : TOOL_BAR_IMAGE_ENABLED_DESELECTED); | ||
| 6031 | else | ||
| 6032 | idx = (selected_p | ||
| 6033 | ? TOOL_BAR_IMAGE_DISABLED_SELECTED | ||
| 6034 | : TOOL_BAR_IMAGE_DISABLED_DESELECTED); | ||
| 6035 | |||
| 6036 | xassert (ASIZE (image) >= idx); | ||
| 6037 | image = AREF (image, idx); | ||
| 6038 | } | ||
| 6039 | else | ||
| 6040 | idx = -1; | ||
| 6041 | |||
| 6042 | cg_image = mac_image_spec_to_cg_image (f, image); | ||
| 6043 | /* Ignore invalid image specifications. */ | ||
| 6044 | if (cg_image == NULL) | ||
| 6045 | continue; | ||
| 6046 | |||
| 6047 | label = cfstring_create_with_string (PROP (TOOL_BAR_ITEM_CAPTION)); | ||
| 6048 | if (label == NULL) | ||
| 6049 | label = CFSTR (""); | ||
| 6050 | |||
| 6051 | if (pos < old_count) | ||
| 6052 | { | ||
| 6053 | CGImageRef old_cg_image = NULL; | ||
| 6054 | CFStringRef old_label = NULL; | ||
| 6055 | Boolean old_enabled_p; | ||
| 6056 | |||
| 6057 | item = (HIToolbarItemRef) CFArrayGetValueAtIndex (old_items, pos); | ||
| 6058 | |||
| 6059 | HIToolbarItemCopyImage (item, &old_cg_image); | ||
| 6060 | if (cg_image != old_cg_image) | ||
| 6061 | HIToolbarItemSetImage (item, cg_image); | ||
| 6062 | CGImageRelease (old_cg_image); | ||
| 6063 | |||
| 6064 | HIToolbarItemCopyLabel (item, &old_label); | ||
| 6065 | if (CFStringCompare (label, old_label, 0) != kCFCompareEqualTo) | ||
| 6066 | HIToolbarItemSetLabel (item, label); | ||
| 6067 | CFRelease (old_label); | ||
| 6068 | |||
| 6069 | old_enabled_p = HIToolbarItemIsEnabled (item); | ||
| 6070 | if ((enabled_p || idx >= 0) != old_enabled_p) | ||
| 6071 | HIToolbarItemSetEnabled (item, (enabled_p || idx >= 0)); | ||
| 6072 | } | ||
| 6073 | else | ||
| 6074 | { | ||
| 6075 | item = NULL; | ||
| 6076 | HIToolbarCreateItemWithIdentifier (toolbar, | ||
| 6077 | TOOLBAR_ICON_ITEM_IDENTIFIER, | ||
| 6078 | NULL, &item); | ||
| 6079 | if (item) | ||
| 6080 | { | ||
| 6081 | HIToolbarItemSetImage (item, cg_image); | ||
| 6082 | HIToolbarItemSetLabel (item, label); | ||
| 6083 | HIToolbarItemSetEnabled (item, (enabled_p || idx >= 0)); | ||
| 6084 | HIToolbarAppendItem (toolbar, item); | ||
| 6085 | CFRelease (item); | ||
| 6086 | } | ||
| 6087 | } | ||
| 6088 | |||
| 6089 | CFRelease (label); | ||
| 6090 | if (item) | ||
| 6091 | { | ||
| 6092 | HIToolbarItemSetCommandID (item, TOOLBAR_ITEM_MAKE_COMMAND_ID (i)); | ||
| 6093 | pos++; | ||
| 6094 | } | ||
| 6095 | } | ||
| 6096 | |||
| 6097 | CFRelease (old_items); | ||
| 6098 | |||
| 6099 | while (pos < old_count) | ||
| 6100 | HIToolbarRemoveItemAtIndex (toolbar, --old_count); | ||
| 6101 | |||
| 6102 | ShowHideWindowToolbar (FRAME_MAC_WINDOW (f), true, | ||
| 6103 | !win_gravity && f == mac_focus_frame (dpyinfo)); | ||
| 6104 | /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events on | ||
| 6105 | toolbar visibility change. */ | ||
| 6106 | mac_handle_origin_change (f); | ||
| 6107 | if (win_gravity >= NorthWestGravity && win_gravity <= SouthEastGravity) | ||
| 6108 | { | ||
| 6109 | mac_move_window_with_gravity (f, win_gravity, left, top); | ||
| 6110 | /* If the title bar is completely outside the screen, adjust the | ||
| 6111 | position. */ | ||
| 6112 | ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, | ||
| 6113 | kWindowConstrainMoveRegardlessOfFit | ||
| 6114 | | kWindowConstrainAllowPartial, NULL, NULL); | ||
| 6115 | f->output_data.mac->toolbar_win_gravity = 0; | ||
| 6116 | } | ||
| 6117 | |||
| 6118 | out: | ||
| 6119 | UNBLOCK_INPUT; | ||
| 6120 | } | ||
| 6121 | |||
| 6122 | /* Hide the tool bar on frame F. Unlike the counterpart on GTK+, it | ||
| 6123 | doesn't deallocate the resources. */ | ||
| 6124 | |||
| 6125 | void | ||
| 6126 | free_frame_tool_bar (f) | ||
| 6127 | FRAME_PTR f; | ||
| 6128 | { | ||
| 6129 | if (IsWindowToolbarVisible (FRAME_MAC_WINDOW (f))) | ||
| 6130 | { | ||
| 6131 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 6132 | |||
| 6133 | BLOCK_INPUT; | ||
| 6134 | ShowHideWindowToolbar (FRAME_MAC_WINDOW (f), false, | ||
| 6135 | (NILP (find_symbol_value | ||
| 6136 | (intern ("frame-notice-user-settings"))) | ||
| 6137 | && f == mac_focus_frame (dpyinfo))); | ||
| 6138 | /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events | ||
| 6139 | on toolbar visibility change. */ | ||
| 6140 | mac_handle_origin_change (f); | ||
| 6141 | UNBLOCK_INPUT; | ||
| 6142 | } | ||
| 6143 | } | ||
| 6144 | |||
| 6145 | static void | ||
| 6146 | mac_tool_bar_note_mouse_movement (f, event) | ||
| 6147 | struct frame *f; | ||
| 6148 | EventRef event; | ||
| 6149 | { | ||
| 6150 | OSStatus err; | ||
| 6151 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 6152 | int mouse_down_p; | ||
| 6153 | WindowRef window; | ||
| 6154 | WindowPartCode part_code; | ||
| 6155 | HIViewRef item_view; | ||
| 6156 | UInt32 command_id; | ||
| 6157 | |||
| 6158 | mouse_down_p = (dpyinfo->grabbed | ||
| 6159 | && f == last_mouse_frame | ||
| 6160 | && FRAME_LIVE_P (f)); | ||
| 6161 | if (mouse_down_p) | ||
| 6162 | return; | ||
| 6163 | |||
| 6164 | err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, NULL, | ||
| 6165 | sizeof (WindowRef), NULL, &window); | ||
| 6166 | if (err != noErr || window != FRAME_MAC_WINDOW (f)) | ||
| 6167 | return; | ||
| 6168 | |||
| 6169 | err = GetEventParameter (event, kEventParamWindowPartCode, | ||
| 6170 | typeWindowPartCode, NULL, | ||
| 6171 | sizeof (WindowPartCode), NULL, &part_code); | ||
| 6172 | if (err != noErr || part_code != inStructure) | ||
| 6173 | return; | ||
| 6174 | |||
| 6175 | err = HIViewGetViewForMouseEvent (HIViewGetRoot (window), event, &item_view); | ||
| 6176 | /* This doesn't work on Mac OS X 10.2. On Mac OS X 10.3 and 10.4, a | ||
| 6177 | toolbar item view seems to have the same command ID with that of | ||
| 6178 | the toolbar item. */ | ||
| 6179 | if (err == noErr) | ||
| 6180 | err = GetControlCommandID (item_view, &command_id); | ||
| 6181 | if (err == noErr && TOOLBAR_ITEM_COMMAND_ID_P (command_id)) | ||
| 6182 | { | ||
| 6183 | int i = TOOLBAR_ITEM_COMMAND_ID_VALUE (command_id); | ||
| 6184 | |||
| 6185 | if (i < f->n_tool_bar_items) | ||
| 6186 | { | ||
| 6187 | HIRect bounds; | ||
| 6188 | HIViewRef content_view; | ||
| 6189 | |||
| 6190 | err = HIViewGetBounds (item_view, &bounds); | ||
| 6191 | if (err == noErr) | ||
| 6192 | err = HIViewFindByID (HIViewGetRoot (window), | ||
| 6193 | kHIViewWindowContentID, &content_view); | ||
| 6194 | if (err == noErr) | ||
| 6195 | err = HIViewConvertRect (&bounds, item_view, content_view); | ||
| 6196 | if (err == noErr) | ||
| 6197 | SetRect (&last_mouse_glyph, | ||
| 6198 | CGRectGetMinX (bounds), CGRectGetMinY (bounds), | ||
| 6199 | CGRectGetMaxX (bounds), CGRectGetMaxY (bounds)); | ||
| 6200 | |||
| 6201 | help_echo_object = help_echo_window = Qnil; | ||
| 6202 | help_echo_pos = -1; | ||
| 6203 | help_echo_string = PROP (TOOL_BAR_ITEM_HELP); | ||
| 6204 | if (NILP (help_echo_string)) | ||
| 6205 | help_echo_string = PROP (TOOL_BAR_ITEM_CAPTION); | ||
| 6206 | } | ||
| 6207 | } | ||
| 6208 | } | ||
| 6209 | |||
| 6210 | static OSStatus | ||
| 6211 | mac_handle_toolbar_command_event (next_handler, event, data) | ||
| 6212 | EventHandlerCallRef next_handler; | ||
| 6213 | EventRef event; | ||
| 6214 | void *data; | ||
| 6215 | { | ||
| 6216 | OSStatus err, result = eventNotHandledErr; | ||
| 6217 | struct frame *f = (struct frame *) data; | ||
| 6218 | HICommand command; | ||
| 6219 | |||
| 6220 | err = GetEventParameter (event, kEventParamDirectObject, | ||
| 6221 | typeHICommand, NULL, | ||
| 6222 | sizeof (HICommand), NULL, &command); | ||
| 6223 | if (err != noErr) | ||
| 6224 | return result; | ||
| 6225 | |||
| 6226 | switch (GetEventKind (event)) | ||
| 6227 | { | ||
| 6228 | case kEventCommandProcess: | ||
| 6229 | if (!TOOLBAR_ITEM_COMMAND_ID_P (command.commandID)) | ||
| 6230 | result = CallNextEventHandler (next_handler, event); | ||
| 6231 | else | ||
| 6232 | { | ||
| 6233 | int i = TOOLBAR_ITEM_COMMAND_ID_VALUE (command.commandID); | ||
| 6234 | |||
| 6235 | if (i < f->n_tool_bar_items | ||
| 6236 | && !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P))) | ||
| 6237 | { | ||
| 6238 | Lisp_Object frame; | ||
| 6239 | struct input_event buf; | ||
| 6240 | |||
| 6241 | EVENT_INIT (buf); | ||
| 6242 | |||
| 6243 | XSETFRAME (frame, f); | ||
| 6244 | buf.kind = TOOL_BAR_EVENT; | ||
| 6245 | buf.frame_or_window = frame; | ||
| 6246 | buf.arg = frame; | ||
| 6247 | kbd_buffer_store_event (&buf); | ||
| 6248 | |||
| 6249 | buf.kind = TOOL_BAR_EVENT; | ||
| 6250 | buf.frame_or_window = frame; | ||
| 6251 | buf.arg = PROP (TOOL_BAR_ITEM_KEY); | ||
| 6252 | buf.modifiers = mac_event_to_emacs_modifiers (event); | ||
| 6253 | kbd_buffer_store_event (&buf); | ||
| 6254 | |||
| 6255 | result = noErr; | ||
| 6256 | } | ||
| 6257 | } | ||
| 6258 | break; | ||
| 6259 | |||
| 6260 | default: | ||
| 6261 | abort (); | ||
| 6262 | } | ||
| 6263 | #undef PROP | ||
| 6264 | |||
| 6265 | return result; | ||
| 6266 | } | ||
| 6267 | #endif /* USE_MAC_TOOLBAR */ | 4978 | #endif /* USE_MAC_TOOLBAR */ |
| 6268 | 4979 | ||
| 6269 | 4980 | ||
| @@ -6691,32 +5402,13 @@ xim_close_dpy (dpyinfo) | |||
| 6691 | 5402 | ||
| 6692 | 5403 | ||
| 6693 | void | 5404 | void |
| 6694 | mac_get_window_bounds (f, inner, outer) | ||
| 6695 | struct frame *f; | ||
| 6696 | Rect *inner, *outer; | ||
| 6697 | { | ||
| 6698 | #if TARGET_API_MAC_CARBON | ||
| 6699 | GetWindowBounds (FRAME_MAC_WINDOW (f), kWindowContentRgn, inner); | ||
| 6700 | GetWindowBounds (FRAME_MAC_WINDOW (f), kWindowStructureRgn, outer); | ||
| 6701 | #else /* not TARGET_API_MAC_CARBON */ | ||
| 6702 | RgnHandle region = NewRgn (); | ||
| 6703 | |||
| 6704 | GetWindowRegion (FRAME_MAC_WINDOW (f), kWindowContentRgn, region); | ||
| 6705 | *inner = (*region)->rgnBBox; | ||
| 6706 | GetWindowRegion (FRAME_MAC_WINDOW (f), kWindowStructureRgn, region); | ||
| 6707 | *outer = (*region)->rgnBBox; | ||
| 6708 | DisposeRgn (region); | ||
| 6709 | #endif /* not TARGET_API_MAC_CARBON */ | ||
| 6710 | } | ||
| 6711 | |||
| 6712 | static void | ||
| 6713 | mac_handle_origin_change (f) | 5405 | mac_handle_origin_change (f) |
| 6714 | struct frame *f; | 5406 | struct frame *f; |
| 6715 | { | 5407 | { |
| 6716 | x_real_positions (f, &f->left_pos, &f->top_pos); | 5408 | x_real_positions (f, &f->left_pos, &f->top_pos); |
| 6717 | } | 5409 | } |
| 6718 | 5410 | ||
| 6719 | static void | 5411 | void |
| 6720 | mac_handle_size_change (f, pixelwidth, pixelheight) | 5412 | mac_handle_size_change (f, pixelwidth, pixelheight) |
| 6721 | struct frame *f; | 5413 | struct frame *f; |
| 6722 | int pixelwidth, pixelheight; | 5414 | int pixelwidth, pixelheight; |
| @@ -6749,14 +5441,7 @@ mac_handle_size_change (f, pixelwidth, pixelheight) | |||
| 6749 | cancel_mouse_face (f); | 5441 | cancel_mouse_face (f); |
| 6750 | 5442 | ||
| 6751 | #if TARGET_API_MAC_CARBON | 5443 | #if TARGET_API_MAC_CARBON |
| 6752 | if (f->output_data.mac->hourglass_control) | 5444 | mac_reposition_hourglass (f); |
| 6753 | { | ||
| 6754 | #if USE_CG_DRAWING | ||
| 6755 | mac_prepare_for_quickdraw (f); | ||
| 6756 | #endif | ||
| 6757 | MoveControl (f->output_data.mac->hourglass_control, | ||
| 6758 | pixelwidth - HOURGLASS_WIDTH, 0); | ||
| 6759 | } | ||
| 6760 | #endif | 5445 | #endif |
| 6761 | } | 5446 | } |
| 6762 | } | 5447 | } |
| @@ -6836,7 +5521,7 @@ x_set_offset (f, xoff, yoff, change_gravity) | |||
| 6836 | x_wm_set_size_hint (f, (long) 0, 0); | 5521 | x_wm_set_size_hint (f, (long) 0, 0); |
| 6837 | 5522 | ||
| 6838 | #if TARGET_API_MAC_CARBON | 5523 | #if TARGET_API_MAC_CARBON |
| 6839 | MoveWindowStructure (FRAME_MAC_WINDOW (f), f->left_pos, f->top_pos); | 5524 | mac_move_window_structure (FRAME_MAC_WINDOW (f), f->left_pos, f->top_pos); |
| 6840 | /* If the title bar is completely outside the screen, adjust the | 5525 | /* If the title bar is completely outside the screen, adjust the |
| 6841 | position. */ | 5526 | position. */ |
| 6842 | ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, | 5527 | ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, |
| @@ -6916,7 +5601,7 @@ x_set_window_size (f, change_gravity, cols, rows) | |||
| 6916 | f->win_gravity = NorthWestGravity; | 5601 | f->win_gravity = NorthWestGravity; |
| 6917 | x_wm_set_size_hint (f, (long) 0, 0); | 5602 | x_wm_set_size_hint (f, (long) 0, 0); |
| 6918 | 5603 | ||
| 6919 | SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0); | 5604 | mac_size_window (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0); |
| 6920 | 5605 | ||
| 6921 | #if TARGET_API_MAC_CARBON | 5606 | #if TARGET_API_MAC_CARBON |
| 6922 | if (!NILP (tip_frame) && f == XFRAME (tip_frame)) | 5607 | if (!NILP (tip_frame) && f == XFRAME (tip_frame)) |
| @@ -6965,10 +5650,8 @@ x_set_mouse_pixel_position (f, pix_x, pix_y) | |||
| 6965 | int pix_x, pix_y; | 5650 | int pix_x, pix_y; |
| 6966 | { | 5651 | { |
| 6967 | #ifdef MAC_OSX | 5652 | #ifdef MAC_OSX |
| 6968 | pix_x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); | ||
| 6969 | pix_y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); | ||
| 6970 | |||
| 6971 | BLOCK_INPUT; | 5653 | BLOCK_INPUT; |
| 5654 | mac_convert_frame_point_to_global (f, &pix_x, &pix_y); | ||
| 6972 | CGWarpMouseCursorPosition (CGPointMake (pix_x, pix_y)); | 5655 | CGWarpMouseCursorPosition (CGPointMake (pix_x, pix_y)); |
| 6973 | UNBLOCK_INPUT; | 5656 | UNBLOCK_INPUT; |
| 6974 | #else | 5657 | #else |
| @@ -7015,7 +5698,7 @@ x_raise_frame (f) | |||
| 7015 | if (f->async_visible) | 5698 | if (f->async_visible) |
| 7016 | { | 5699 | { |
| 7017 | BLOCK_INPUT; | 5700 | BLOCK_INPUT; |
| 7018 | BringToFront (FRAME_MAC_WINDOW (f)); | 5701 | mac_bring_window_to_front (FRAME_MAC_WINDOW (f)); |
| 7019 | UNBLOCK_INPUT; | 5702 | UNBLOCK_INPUT; |
| 7020 | } | 5703 | } |
| 7021 | } | 5704 | } |
| @@ -7029,7 +5712,7 @@ x_lower_frame (f) | |||
| 7029 | if (f->async_visible) | 5712 | if (f->async_visible) |
| 7030 | { | 5713 | { |
| 7031 | BLOCK_INPUT; | 5714 | BLOCK_INPUT; |
| 7032 | SendBehind (FRAME_MAC_WINDOW (f), NULL); | 5715 | mac_send_window_behind (FRAME_MAC_WINDOW (f), NULL); |
| 7033 | UNBLOCK_INPUT; | 5716 | UNBLOCK_INPUT; |
| 7034 | } | 5717 | } |
| 7035 | } | 5718 | } |
| @@ -7047,17 +5730,17 @@ XTframe_raise_lower (f, raise_flag) | |||
| 7047 | 5730 | ||
| 7048 | /* Change of visibility. */ | 5731 | /* Change of visibility. */ |
| 7049 | 5732 | ||
| 7050 | static void | 5733 | void |
| 7051 | mac_handle_visibility_change (f) | 5734 | mac_handle_visibility_change (f) |
| 7052 | struct frame *f; | 5735 | struct frame *f; |
| 7053 | { | 5736 | { |
| 7054 | WindowRef wp = FRAME_MAC_WINDOW (f); | 5737 | Window wp = FRAME_MAC_WINDOW (f); |
| 7055 | int visible = 0, iconified = 0; | 5738 | int visible = 0, iconified = 0; |
| 7056 | struct input_event buf; | 5739 | struct input_event buf; |
| 7057 | 5740 | ||
| 7058 | if (IsWindowVisible (wp)) | 5741 | if (mac_is_window_visible (wp)) |
| 7059 | { | 5742 | { |
| 7060 | if (IsWindowCollapsed (wp)) | 5743 | if (mac_is_window_collapsed (wp)) |
| 7061 | iconified = 1; | 5744 | iconified = 1; |
| 7062 | else | 5745 | else |
| 7063 | visible = 1; | 5746 | visible = 1; |
| @@ -7123,8 +5806,8 @@ x_make_frame_visible (f) | |||
| 7123 | 5806 | ||
| 7124 | f->output_data.mac->asked_for_visible = 1; | 5807 | f->output_data.mac->asked_for_visible = 1; |
| 7125 | 5808 | ||
| 7126 | CollapseWindow (FRAME_MAC_WINDOW (f), false); | 5809 | mac_collapse_window (FRAME_MAC_WINDOW (f), false); |
| 7127 | ShowWindow (FRAME_MAC_WINDOW (f)); | 5810 | mac_show_window (FRAME_MAC_WINDOW (f)); |
| 7128 | } | 5811 | } |
| 7129 | 5812 | ||
| 7130 | XFlush (FRAME_MAC_DISPLAY (f)); | 5813 | XFlush (FRAME_MAC_DISPLAY (f)); |
| @@ -7202,7 +5885,7 @@ x_make_frame_invisible (f) | |||
| 7202 | x_wm_set_size_hint (f, (long) 0, 1); | 5885 | x_wm_set_size_hint (f, (long) 0, 1); |
| 7203 | #endif | 5886 | #endif |
| 7204 | 5887 | ||
| 7205 | HideWindow (FRAME_MAC_WINDOW (f)); | 5888 | mac_hide_window (FRAME_MAC_WINDOW (f)); |
| 7206 | 5889 | ||
| 7207 | UNBLOCK_INPUT; | 5890 | UNBLOCK_INPUT; |
| 7208 | 5891 | ||
| @@ -7236,9 +5919,9 @@ x_iconify_frame (f) | |||
| 7236 | FRAME_SAMPLE_VISIBILITY (f); | 5919 | FRAME_SAMPLE_VISIBILITY (f); |
| 7237 | 5920 | ||
| 7238 | if (! FRAME_VISIBLE_P (f)) | 5921 | if (! FRAME_VISIBLE_P (f)) |
| 7239 | ShowWindow (FRAME_MAC_WINDOW (f)); | 5922 | mac_show_window (FRAME_MAC_WINDOW (f)); |
| 7240 | 5923 | ||
| 7241 | err = CollapseWindow (FRAME_MAC_WINDOW (f), true); | 5924 | err = mac_collapse_window (FRAME_MAC_WINDOW (f), true); |
| 7242 | 5925 | ||
| 7243 | UNBLOCK_INPUT; | 5926 | UNBLOCK_INPUT; |
| 7244 | 5927 | ||
| @@ -7258,35 +5941,14 @@ x_free_frame_resources (f) | |||
| 7258 | struct frame *f; | 5941 | struct frame *f; |
| 7259 | { | 5942 | { |
| 7260 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | 5943 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); |
| 7261 | WindowRef wp = FRAME_MAC_WINDOW (f); | 5944 | Window wp = FRAME_MAC_WINDOW (f); |
| 7262 | 5945 | ||
| 7263 | BLOCK_INPUT; | 5946 | BLOCK_INPUT; |
| 7264 | 5947 | ||
| 7265 | if (wp != tip_window) | 5948 | /* AppKit version of mac_dispose_frame_window, which is implemented |
| 7266 | remove_window_handler (wp); | 5949 | as -[NSWindow close], will change the focus to the next window |
| 7267 | 5950 | during its call. So, unlike other platforms, we clean up the | |
| 7268 | #if USE_CG_DRAWING | 5951 | focus-related variables before calling mac_dispose_frame_window. */ |
| 7269 | mac_prepare_for_quickdraw (f); | ||
| 7270 | #endif | ||
| 7271 | DisposeWindow (wp); | ||
| 7272 | if (wp == tip_window) | ||
| 7273 | /* Neither WaitNextEvent nor ReceiveNextEvent receives `window | ||
| 7274 | closed' event. So we reset tip_window here. */ | ||
| 7275 | tip_window = NULL; | ||
| 7276 | |||
| 7277 | free_frame_menubar (f); | ||
| 7278 | |||
| 7279 | if (FRAME_FACE_CACHE (f)) | ||
| 7280 | free_frame_faces (f); | ||
| 7281 | |||
| 7282 | x_free_gcs (f); | ||
| 7283 | |||
| 7284 | if (FRAME_SIZE_HINTS (f)) | ||
| 7285 | xfree (FRAME_SIZE_HINTS (f)); | ||
| 7286 | |||
| 7287 | xfree (f->output_data.mac); | ||
| 7288 | f->output_data.mac = NULL; | ||
| 7289 | |||
| 7290 | if (f == dpyinfo->x_focus_frame) | 5952 | if (f == dpyinfo->x_focus_frame) |
| 7291 | { | 5953 | { |
| 7292 | dpyinfo->x_focus_frame = 0; | 5954 | dpyinfo->x_focus_frame = 0; |
| @@ -7310,6 +5972,25 @@ x_free_frame_resources (f) | |||
| 7310 | dpyinfo->mouse_face_mouse_frame = 0; | 5972 | dpyinfo->mouse_face_mouse_frame = 0; |
| 7311 | } | 5973 | } |
| 7312 | 5974 | ||
| 5975 | mac_dispose_frame_window (f); | ||
| 5976 | if (wp == tip_window) | ||
| 5977 | /* Neither WaitNextEvent nor ReceiveNextEvent receives `window | ||
| 5978 | closed' event. So we reset tip_window here. */ | ||
| 5979 | tip_window = NULL; | ||
| 5980 | |||
| 5981 | free_frame_menubar (f); | ||
| 5982 | |||
| 5983 | if (FRAME_FACE_CACHE (f)) | ||
| 5984 | free_frame_faces (f); | ||
| 5985 | |||
| 5986 | x_free_gcs (f); | ||
| 5987 | |||
| 5988 | if (FRAME_SIZE_HINTS (f)) | ||
| 5989 | xfree (FRAME_SIZE_HINTS (f)); | ||
| 5990 | |||
| 5991 | xfree (f->output_data.mac); | ||
| 5992 | f->output_data.mac = NULL; | ||
| 5993 | |||
| 7313 | UNBLOCK_INPUT; | 5994 | UNBLOCK_INPUT; |
| 7314 | } | 5995 | } |
| 7315 | 5996 | ||
| @@ -7823,6 +6504,9 @@ static Lisp_Object atsu_font_id_hash; | |||
| 7823 | static Lisp_Object fm_style_face_attributes_alist; | 6504 | static Lisp_Object fm_style_face_attributes_alist; |
| 7824 | extern Lisp_Object QCfamily, QCweight, QCslant, Qnormal, Qbold, Qitalic; | 6505 | extern Lisp_Object QCfamily, QCweight, QCslant, Qnormal, Qbold, Qitalic; |
| 7825 | #endif | 6506 | #endif |
| 6507 | #if USE_MAC_FONT_PANEL | ||
| 6508 | Lisp_Object Qpanel_closed, Qselection; | ||
| 6509 | #endif | ||
| 7826 | 6510 | ||
| 7827 | /* Alist linking character set strings to Mac text encoding and Emacs | 6511 | /* Alist linking character set strings to Mac text encoding and Emacs |
| 7828 | coding system. */ | 6512 | coding system. */ |
| @@ -8968,10 +7652,7 @@ mac_load_query_font (f, fontname) | |||
| 8968 | FontInfo the_fontinfo; | 7652 | FontInfo the_fontinfo; |
| 8969 | int is_two_byte_font; | 7653 | int is_two_byte_font; |
| 8970 | 7654 | ||
| 8971 | #if USE_CG_DRAWING | 7655 | mac_begin_clip (f, NULL); |
| 8972 | mac_prepare_for_quickdraw (f); | ||
| 8973 | #endif | ||
| 8974 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 8975 | 7656 | ||
| 8976 | TextFont (fontnum); | 7657 | TextFont (fontnum); |
| 8977 | TextSize (size); | 7658 | TextSize (size); |
| @@ -9058,6 +7739,8 @@ mac_load_query_font (f, fontname) | |||
| 9058 | for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++) | 7739 | for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++) |
| 9059 | mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL); | 7740 | mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL); |
| 9060 | } | 7741 | } |
| 7742 | |||
| 7743 | mac_end_clip (f, NULL); | ||
| 9061 | } | 7744 | } |
| 9062 | 7745 | ||
| 9063 | if (space_bounds) | 7746 | if (space_bounds) |
| @@ -9386,158 +8069,6 @@ x_find_ccl_program (fontp) | |||
| 9386 | } | 8069 | } |
| 9387 | } | 8070 | } |
| 9388 | 8071 | ||
| 9389 | #if USE_MAC_FONT_PANEL | ||
| 9390 | /* Whether Font Panel has been shown before. The first call to font | ||
| 9391 | panel functions (FPIsFontPanelVisible, SetFontInfoForSelection) is | ||
| 9392 | slow. This variable is used for deferring such a call as much as | ||
| 9393 | possible. */ | ||
| 9394 | static int font_panel_shown_p = 0; | ||
| 9395 | |||
| 9396 | extern Lisp_Object Qfont; | ||
| 9397 | static Lisp_Object Qpanel_closed, Qselection; | ||
| 9398 | |||
| 9399 | static OSStatus mac_store_event_ref_as_apple_event P_ ((AEEventClass, AEEventID, | ||
| 9400 | Lisp_Object, | ||
| 9401 | Lisp_Object, | ||
| 9402 | EventRef, UInt32, | ||
| 9403 | const EventParamName *, | ||
| 9404 | const EventParamType *)); | ||
| 9405 | |||
| 9406 | int | ||
| 9407 | mac_font_panel_visible_p () | ||
| 9408 | { | ||
| 9409 | return font_panel_shown_p && FPIsFontPanelVisible (); | ||
| 9410 | } | ||
| 9411 | |||
| 9412 | static pascal OSStatus | ||
| 9413 | mac_handle_font_event (next_handler, event, data) | ||
| 9414 | EventHandlerCallRef next_handler; | ||
| 9415 | EventRef event; | ||
| 9416 | void *data; | ||
| 9417 | { | ||
| 9418 | OSStatus result, err; | ||
| 9419 | Lisp_Object id_key; | ||
| 9420 | int num_params; | ||
| 9421 | const EventParamName *names; | ||
| 9422 | const EventParamType *types; | ||
| 9423 | static const EventParamName names_sel[] = {kEventParamATSUFontID, | ||
| 9424 | kEventParamATSUFontSize, | ||
| 9425 | kEventParamFMFontFamily, | ||
| 9426 | kEventParamFMFontStyle, | ||
| 9427 | kEventParamFMFontSize, | ||
| 9428 | kEventParamFontColor}; | ||
| 9429 | static const EventParamType types_sel[] = {typeATSUFontID, | ||
| 9430 | typeATSUSize, | ||
| 9431 | typeFMFontFamily, | ||
| 9432 | typeFMFontStyle, | ||
| 9433 | typeFMFontSize, | ||
| 9434 | typeFontColor}; | ||
| 9435 | |||
| 9436 | result = CallNextEventHandler (next_handler, event); | ||
| 9437 | if (result != eventNotHandledErr) | ||
| 9438 | return result; | ||
| 9439 | |||
| 9440 | switch (GetEventKind (event)) | ||
| 9441 | { | ||
| 9442 | case kEventFontPanelClosed: | ||
| 9443 | id_key = Qpanel_closed; | ||
| 9444 | num_params = 0; | ||
| 9445 | names = NULL; | ||
| 9446 | types = NULL; | ||
| 9447 | break; | ||
| 9448 | |||
| 9449 | case kEventFontSelection: | ||
| 9450 | id_key = Qselection; | ||
| 9451 | num_params = sizeof (names_sel) / sizeof (names_sel[0]); | ||
| 9452 | names = names_sel; | ||
| 9453 | types = types_sel; | ||
| 9454 | break; | ||
| 9455 | } | ||
| 9456 | |||
| 9457 | err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key, | ||
| 9458 | event, num_params, | ||
| 9459 | names, types); | ||
| 9460 | if (err == noErr) | ||
| 9461 | result = noErr; | ||
| 9462 | |||
| 9463 | return result; | ||
| 9464 | } | ||
| 9465 | |||
| 9466 | OSStatus | ||
| 9467 | mac_show_hide_font_panel () | ||
| 9468 | { | ||
| 9469 | if (!font_panel_shown_p) | ||
| 9470 | { | ||
| 9471 | OSStatus err; | ||
| 9472 | |||
| 9473 | static const EventTypeSpec specs[] = | ||
| 9474 | {{kEventClassFont, kEventFontPanelClosed}, | ||
| 9475 | {kEventClassFont, kEventFontSelection}}; | ||
| 9476 | |||
| 9477 | err = InstallApplicationEventHandler (mac_handle_font_event, | ||
| 9478 | GetEventTypeCount (specs), | ||
| 9479 | specs, NULL, NULL); | ||
| 9480 | if (err != noErr) | ||
| 9481 | return err; | ||
| 9482 | |||
| 9483 | font_panel_shown_p = 1; | ||
| 9484 | } | ||
| 9485 | |||
| 9486 | return FPShowHideFontPanel (); | ||
| 9487 | } | ||
| 9488 | |||
| 9489 | OSStatus | ||
| 9490 | mac_set_font_info_for_selection (f, face_id, c) | ||
| 9491 | struct frame *f; | ||
| 9492 | int face_id, c; | ||
| 9493 | { | ||
| 9494 | OSStatus err; | ||
| 9495 | EventTargetRef target = NULL; | ||
| 9496 | XFontStruct *font = NULL; | ||
| 9497 | |||
| 9498 | if (!mac_font_panel_visible_p ()) | ||
| 9499 | return noErr; | ||
| 9500 | |||
| 9501 | if (f) | ||
| 9502 | { | ||
| 9503 | target = GetWindowEventTarget (FRAME_MAC_WINDOW (f)); | ||
| 9504 | |||
| 9505 | if (FRAME_FACE_CACHE (f) && CHAR_VALID_P (c, 0)) | ||
| 9506 | { | ||
| 9507 | struct face *face; | ||
| 9508 | |||
| 9509 | face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c); | ||
| 9510 | face = FACE_FROM_ID (f, face_id); | ||
| 9511 | font = face->font; | ||
| 9512 | } | ||
| 9513 | } | ||
| 9514 | |||
| 9515 | if (font == NULL) | ||
| 9516 | err = SetFontInfoForSelection (kFontSelectionATSUIType, 0, NULL, target); | ||
| 9517 | else | ||
| 9518 | { | ||
| 9519 | if (font->mac_fontnum != -1) | ||
| 9520 | { | ||
| 9521 | FontSelectionQDStyle qd_style; | ||
| 9522 | |||
| 9523 | qd_style.version = kFontSelectionQDStyleVersionZero; | ||
| 9524 | qd_style.instance.fontFamily = font->mac_fontnum; | ||
| 9525 | qd_style.instance.fontStyle = font->mac_fontface; | ||
| 9526 | qd_style.size = font->mac_fontsize; | ||
| 9527 | qd_style.hasColor = false; | ||
| 9528 | |||
| 9529 | err = SetFontInfoForSelection (kFontSelectionQDType, | ||
| 9530 | 1, &qd_style, target); | ||
| 9531 | } | ||
| 9532 | else | ||
| 9533 | err = SetFontInfoForSelection (kFontSelectionATSUIType, | ||
| 9534 | 1, &font->mac_style, target); | ||
| 9535 | } | ||
| 9536 | |||
| 9537 | return err; | ||
| 9538 | } | ||
| 9539 | #endif | ||
| 9540 | |||
| 9541 | 8072 | ||
| 9542 | /* The Mac Event loop code */ | 8073 | /* The Mac Event loop code */ |
| 9543 | 8074 | ||
| @@ -9563,20 +8094,6 @@ mac_set_font_info_for_selection (f, face_id, c) | |||
| 9563 | #endif | 8094 | #endif |
| 9564 | #endif /* ! TARGET_API_MAC_CARBON */ | 8095 | #endif /* ! TARGET_API_MAC_CARBON */ |
| 9565 | 8096 | ||
| 9566 | #define M_APPLE 234 | ||
| 9567 | #define I_ABOUT 1 | ||
| 9568 | |||
| 9569 | #define DEFAULT_NUM_COLS 80 | ||
| 9570 | |||
| 9571 | #define MIN_DOC_SIZE 64 | ||
| 9572 | #define MAX_DOC_SIZE 32767 | ||
| 9573 | |||
| 9574 | #define EXTRA_STACK_ALLOC (256 * 1024) | ||
| 9575 | |||
| 9576 | #define ARGV_STRING_LIST_ID 129 | ||
| 9577 | #define ABOUT_ALERT_ID 128 | ||
| 9578 | #define RAM_TOO_LARGE_ALERT_ID 129 | ||
| 9579 | |||
| 9580 | /* Contains the string "reverse", which is a constant for mouse button emu.*/ | 8097 | /* Contains the string "reverse", which is a constant for mouse button emu.*/ |
| 9581 | Lisp_Object Qreverse; | 8098 | Lisp_Object Qreverse; |
| 9582 | 8099 | ||
| @@ -9611,70 +8128,43 @@ int mac_pass_command_to_system; | |||
| 9611 | int mac_pass_control_to_system; | 8128 | int mac_pass_control_to_system; |
| 9612 | #endif | 8129 | #endif |
| 9613 | 8130 | ||
| 9614 | /* Points to the variable `inev' in the function XTread_socket. It is | ||
| 9615 | used for passing an input event to the function back from | ||
| 9616 | Carbon/Apple event handlers. */ | ||
| 9617 | static struct input_event *read_socket_inev = NULL; | ||
| 9618 | |||
| 9619 | /* Whether or not the screen configuration has changed. */ | 8131 | /* Whether or not the screen configuration has changed. */ |
| 9620 | static int mac_screen_config_changed = 0; | 8132 | int mac_screen_config_changed = 0; |
| 9621 | |||
| 9622 | Point saved_menu_event_location; | ||
| 9623 | 8133 | ||
| 9624 | /* Apple Events */ | 8134 | /* Apple Events */ |
| 9625 | #if TARGET_API_MAC_CARBON | 8135 | #if TARGET_API_MAC_CARBON |
| 9626 | static Lisp_Object Qhi_command; | 8136 | Lisp_Object Qhi_command; |
| 9627 | #ifdef MAC_OSX | 8137 | #ifdef MAC_OSX |
| 9628 | extern Lisp_Object Qwindow; | 8138 | Lisp_Object Qtoolbar_switch_mode; |
| 9629 | static Lisp_Object Qtoolbar_switch_mode; | ||
| 9630 | #endif | 8139 | #endif |
| 9631 | #if USE_MAC_TSM | 8140 | #if USE_MAC_TSM |
| 9632 | static TSMDocumentID tsm_document_id; | 8141 | Lisp_Object Qtext_input; |
| 9633 | static Lisp_Object Qtext_input; | 8142 | Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event; |
| 9634 | static Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event; | 8143 | Lisp_Object Vmac_ts_active_input_overlay; |
| 9635 | static Lisp_Object Vmac_ts_active_input_overlay; | 8144 | Lisp_Object Vmac_ts_script_language_on_focus; |
| 9636 | extern Lisp_Object Qbefore_string; | 8145 | Lisp_Object saved_ts_script_language_on_focus; |
| 9637 | static Lisp_Object Vmac_ts_script_language_on_focus; | ||
| 9638 | static Lisp_Object saved_ts_script_language_on_focus; | ||
| 9639 | static ScriptLanguageRecord saved_ts_language; | 8146 | static ScriptLanguageRecord saved_ts_language; |
| 9640 | static Component saved_ts_component; | 8147 | static Component saved_ts_component; |
| 9641 | #endif | 8148 | #endif |
| 8149 | #ifdef MAC_OSX | ||
| 8150 | Lisp_Object Qservice, Qpaste, Qperform; | ||
| 8151 | #endif | ||
| 9642 | #endif /* TARGET_API_MAC_CARBON */ | 8152 | #endif /* TARGET_API_MAC_CARBON */ |
| 9643 | extern int mac_ready_for_apple_events; | ||
| 9644 | extern Lisp_Object Qundefined; | 8153 | extern Lisp_Object Qundefined; |
| 8154 | extern int XTread_socket P_ ((int, int, struct input_event *)); | ||
| 9645 | extern void init_apple_event_handler P_ ((void)); | 8155 | extern void init_apple_event_handler P_ ((void)); |
| 9646 | extern void mac_find_apple_event_spec P_ ((AEEventClass, AEEventID, | 8156 | extern void mac_find_apple_event_spec P_ ((AEEventClass, AEEventID, |
| 9647 | Lisp_Object *, Lisp_Object *, | 8157 | Lisp_Object *, Lisp_Object *, |
| 9648 | Lisp_Object *)); | 8158 | Lisp_Object *)); |
| 9649 | extern OSErr init_coercion_handler P_ ((void)); | 8159 | extern OSErr init_coercion_handler P_ ((void)); |
| 9650 | 8160 | ||
| 9651 | /* Drag and Drop */ | ||
| 9652 | extern OSErr install_drag_handler P_ ((WindowRef)); | ||
| 9653 | extern void remove_drag_handler P_ ((WindowRef)); | ||
| 9654 | |||
| 9655 | #if TARGET_API_MAC_CARBON | ||
| 9656 | /* Showing help echo string during menu tracking */ | ||
| 9657 | extern OSStatus install_menu_target_item_handler P_ ((void)); | ||
| 9658 | |||
| 9659 | #ifdef MAC_OSX | ||
| 9660 | extern OSStatus install_service_handler (); | ||
| 9661 | static Lisp_Object Qservice, Qpaste, Qperform; | ||
| 9662 | #endif | ||
| 9663 | #endif | ||
| 9664 | |||
| 9665 | extern void init_emacs_passwd_dir (); | ||
| 9666 | extern int emacs_main (int, char **, char **); | ||
| 9667 | |||
| 9668 | extern void initialize_applescript(); | ||
| 9669 | extern void terminate_applescript(); | ||
| 9670 | |||
| 9671 | /* Table for translating Mac keycode to X keysym values. Contributed | 8161 | /* Table for translating Mac keycode to X keysym values. Contributed |
| 9672 | by Sudhir Shenoy. | 8162 | by Sudhir Shenoy. |
| 9673 | Mapping for special keys is now identical to that in Apple X11 | 8163 | Mapping for special keys is now identical to that in Apple X11 |
| 9674 | except `clear' (-> <clear>) on the KeyPad, `enter' (-> <kp-enter>) | 8164 | except `clear' (-> <clear>) on the KeyPad, `enter' (-> <kp-enter>) |
| 9675 | on the right of the Cmd key on laptops, and fn + `enter' (-> | 8165 | on the right of the Cmd key on laptops, and fn + `enter' (-> |
| 9676 | <linefeed>). */ | 8166 | <linefeed>). */ |
| 9677 | static const unsigned char keycode_to_xkeysym_table[] = { | 8167 | const unsigned char keycode_to_xkeysym_table[] = { |
| 9678 | /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 8168 | /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 9679 | /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 8169 | /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 9680 | /*0x20*/ 0, 0, 0, 0, 0x0d /*return*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 8170 | /*0x20*/ 0, 0, 0, 0, 0x0d /*return*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| @@ -9743,7 +8233,7 @@ static const unsigned char fn_keycode_to_keycode_table[] = { | |||
| 9743 | }; | 8233 | }; |
| 9744 | #endif /* MAC_OSX */ | 8234 | #endif /* MAC_OSX */ |
| 9745 | 8235 | ||
| 9746 | static int | 8236 | int |
| 9747 | #if TARGET_API_MAC_CARBON | 8237 | #if TARGET_API_MAC_CARBON |
| 9748 | mac_to_emacs_modifiers (UInt32 mods, UInt32 unmapped_mods) | 8238 | mac_to_emacs_modifiers (UInt32 mods, UInt32 unmapped_mods) |
| 9749 | #else | 8239 | #else |
| @@ -9790,7 +8280,7 @@ mac_to_emacs_modifiers (EventModifiers mods, EventModifiers unmapped_mods) | |||
| 9790 | return result; | 8280 | return result; |
| 9791 | } | 8281 | } |
| 9792 | 8282 | ||
| 9793 | static UInt32 | 8283 | UInt32 |
| 9794 | mac_mapped_modifiers (modifiers, key_code) | 8284 | mac_mapped_modifiers (modifiers, key_code) |
| 9795 | UInt32 modifiers, key_code; | 8285 | UInt32 modifiers, key_code; |
| 9796 | { | 8286 | { |
| @@ -9818,7 +8308,7 @@ mac_mapped_modifiers (modifiers, key_code) | |||
| 9818 | return mapped_modifiers_all & modifiers; | 8308 | return mapped_modifiers_all & modifiers; |
| 9819 | } | 8309 | } |
| 9820 | 8310 | ||
| 9821 | static int | 8311 | int |
| 9822 | mac_get_emulated_btn ( UInt32 modifiers ) | 8312 | mac_get_emulated_btn ( UInt32 modifiers ) |
| 9823 | { | 8313 | { |
| 9824 | int result = 0; | 8314 | int result = 0; |
| @@ -9832,337 +8322,28 @@ mac_get_emulated_btn ( UInt32 modifiers ) | |||
| 9832 | return result; | 8322 | return result; |
| 9833 | } | 8323 | } |
| 9834 | 8324 | ||
| 9835 | #if TARGET_API_MAC_CARBON | ||
| 9836 | /***** Code to handle C-g testing *****/ | ||
| 9837 | extern int quit_char; | ||
| 9838 | extern int make_ctrl_char P_ ((int)); | ||
| 9839 | |||
| 9840 | int | ||
| 9841 | mac_quit_char_key_p (modifiers, key_code) | ||
| 9842 | UInt32 modifiers, key_code; | ||
| 9843 | { | ||
| 9844 | UInt32 char_code, mapped_modifiers; | ||
| 9845 | unsigned long some_state = 0; | ||
| 9846 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); | ||
| 9847 | int c, emacs_modifiers; | ||
| 9848 | |||
| 9849 | /* Mask off modifier keys that are mapped to some Emacs modifiers. */ | ||
| 9850 | mapped_modifiers = mac_mapped_modifiers (modifiers, key_code); | ||
| 9851 | key_code |= (modifiers & ~mapped_modifiers); | ||
| 9852 | char_code = KeyTranslate (kchr_ptr, key_code, &some_state); | ||
| 9853 | if (char_code & ~0xff) | ||
| 9854 | return 0; | ||
| 9855 | |||
| 9856 | emacs_modifiers = mac_to_emacs_modifiers (mapped_modifiers, modifiers); | ||
| 9857 | if (emacs_modifiers & ctrl_modifier) | ||
| 9858 | c = make_ctrl_char (char_code); | ||
| 9859 | |||
| 9860 | c |= (emacs_modifiers | ||
| 9861 | & (meta_modifier | alt_modifier | ||
| 9862 | | hyper_modifier | super_modifier)); | ||
| 9863 | |||
| 9864 | return c == quit_char; | ||
| 9865 | } | ||
| 9866 | #endif | ||
| 9867 | |||
| 9868 | #if TARGET_API_MAC_CARBON | ||
| 9869 | /* Obtains the event modifiers from the event ref and then calls | ||
| 9870 | mac_to_emacs_modifiers. */ | ||
| 9871 | static int | ||
| 9872 | mac_event_to_emacs_modifiers (EventRef eventRef) | ||
| 9873 | { | ||
| 9874 | UInt32 mods = 0, class; | ||
| 9875 | |||
| 9876 | GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, | ||
| 9877 | sizeof (UInt32), NULL, &mods); | ||
| 9878 | class = GetEventClass (eventRef); | ||
| 9879 | if (!NILP (Vmac_emulate_three_button_mouse) && | ||
| 9880 | (class == kEventClassMouse || class == kEventClassCommand)) | ||
| 9881 | { | ||
| 9882 | mods &= ~(optionKey | cmdKey); | ||
| 9883 | } | ||
| 9884 | return mac_to_emacs_modifiers (mods, 0); | ||
| 9885 | } | ||
| 9886 | |||
| 9887 | /* Given an event ref, return the code to use for the mouse button | ||
| 9888 | code in the emacs input_event. */ | ||
| 9889 | static int | ||
| 9890 | mac_get_mouse_btn (EventRef ref) | ||
| 9891 | { | ||
| 9892 | EventMouseButton result = kEventMouseButtonPrimary; | ||
| 9893 | GetEventParameter (ref, kEventParamMouseButton, typeMouseButton, NULL, | ||
| 9894 | sizeof (EventMouseButton), NULL, &result); | ||
| 9895 | switch (result) | ||
| 9896 | { | ||
| 9897 | case kEventMouseButtonPrimary: | ||
| 9898 | if (NILP (Vmac_emulate_three_button_mouse)) | ||
| 9899 | return 0; | ||
| 9900 | else { | ||
| 9901 | UInt32 mods = 0; | ||
| 9902 | GetEventParameter (ref, kEventParamKeyModifiers, typeUInt32, NULL, | ||
| 9903 | sizeof (UInt32), NULL, &mods); | ||
| 9904 | return mac_get_emulated_btn(mods); | ||
| 9905 | } | ||
| 9906 | case kEventMouseButtonSecondary: | ||
| 9907 | return mac_wheel_button_is_mouse_2 ? 2 : 1; | ||
| 9908 | case kEventMouseButtonTertiary: | ||
| 9909 | case 4: /* 4 is the number for the mouse wheel button */ | ||
| 9910 | return mac_wheel_button_is_mouse_2 ? 1 : 2; | ||
| 9911 | default: | ||
| 9912 | return 0; | ||
| 9913 | } | ||
| 9914 | } | ||
| 9915 | |||
| 9916 | /* Normally, ConvertEventRefToEventRecord will correctly handle all | ||
| 9917 | events. However the click of the mouse wheel is not converted to a | ||
| 9918 | mouseDown or mouseUp event. Likewise for dead key events. This | ||
| 9919 | calls ConvertEventRefToEventRecord, but then checks to see if it is | ||
| 9920 | a mouse up/down, or a dead key Carbon event that has not been | ||
| 9921 | converted, and if so, converts it by hand (to be picked up in the | ||
| 9922 | XTread_socket loop). */ | ||
| 9923 | static Boolean mac_convert_event_ref (EventRef eventRef, EventRecord *eventRec) | ||
| 9924 | { | ||
| 9925 | OSStatus err; | ||
| 9926 | Boolean result = ConvertEventRefToEventRecord (eventRef, eventRec); | ||
| 9927 | EventKind action; | ||
| 9928 | |||
| 9929 | if (result) | ||
| 9930 | return result; | ||
| 9931 | |||
| 9932 | switch (GetEventClass (eventRef)) | ||
| 9933 | { | ||
| 9934 | case kEventClassMouse: | ||
| 9935 | switch (GetEventKind (eventRef)) | ||
| 9936 | { | ||
| 9937 | case kEventMouseDown: | ||
| 9938 | eventRec->what = mouseDown; | ||
| 9939 | result = 1; | ||
| 9940 | break; | ||
| 9941 | |||
| 9942 | case kEventMouseUp: | ||
| 9943 | eventRec->what = mouseUp; | ||
| 9944 | result = 1; | ||
| 9945 | break; | ||
| 9946 | |||
| 9947 | default: | ||
| 9948 | break; | ||
| 9949 | } | ||
| 9950 | break; | ||
| 9951 | |||
| 9952 | case kEventClassKeyboard: | ||
| 9953 | switch (GetEventKind (eventRef)) | ||
| 9954 | { | ||
| 9955 | case kEventRawKeyDown: | ||
| 9956 | action = keyDown; | ||
| 9957 | goto keystroke_common; | ||
| 9958 | case kEventRawKeyRepeat: | ||
| 9959 | action = autoKey; | ||
| 9960 | goto keystroke_common; | ||
| 9961 | case kEventRawKeyUp: | ||
| 9962 | action = keyUp; | ||
| 9963 | keystroke_common: | ||
| 9964 | { | ||
| 9965 | unsigned char char_codes; | ||
| 9966 | UInt32 key_code; | ||
| 9967 | |||
| 9968 | err = GetEventParameter (eventRef, kEventParamKeyMacCharCodes, | ||
| 9969 | typeChar, NULL, sizeof (char), | ||
| 9970 | NULL, &char_codes); | ||
| 9971 | if (err == noErr) | ||
| 9972 | err = GetEventParameter (eventRef, kEventParamKeyCode, | ||
| 9973 | typeUInt32, NULL, sizeof (UInt32), | ||
| 9974 | NULL, &key_code); | ||
| 9975 | if (err == noErr) | ||
| 9976 | { | ||
| 9977 | eventRec->what = action; | ||
| 9978 | eventRec->message = char_codes | ((key_code & 0xff) << 8); | ||
| 9979 | result = 1; | ||
| 9980 | } | ||
| 9981 | } | ||
| 9982 | break; | ||
| 9983 | |||
| 9984 | default: | ||
| 9985 | break; | ||
| 9986 | } | ||
| 9987 | break; | ||
| 9988 | |||
| 9989 | default: | ||
| 9990 | break; | ||
| 9991 | } | ||
| 9992 | |||
| 9993 | if (result) | ||
| 9994 | { | ||
| 9995 | /* Need where and when. */ | ||
| 9996 | UInt32 mods = 0; | ||
| 9997 | |||
| 9998 | GetEventParameter (eventRef, kEventParamMouseLocation, typeQDPoint, | ||
| 9999 | NULL, sizeof (Point), NULL, &eventRec->where); | ||
| 10000 | /* Use two step process because new event modifiers are 32-bit | ||
| 10001 | and old are 16-bit. Currently, only loss is NumLock & Fn. */ | ||
| 10002 | GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, | ||
| 10003 | NULL, sizeof (UInt32), NULL, &mods); | ||
| 10004 | eventRec->modifiers = mods; | ||
| 10005 | |||
| 10006 | eventRec->when = EventTimeToTicks (GetEventTime (eventRef)); | ||
| 10007 | } | ||
| 10008 | |||
| 10009 | return result; | ||
| 10010 | } | ||
| 10011 | |||
| 10012 | #endif | ||
| 10013 | |||
| 10014 | #ifdef MAC_OS8 | ||
| 10015 | static void | ||
| 10016 | do_get_menus (void) | ||
| 10017 | { | ||
| 10018 | Handle menubar_handle; | ||
| 10019 | MenuRef menu; | ||
| 10020 | |||
| 10021 | menubar_handle = GetNewMBar (128); | ||
| 10022 | if(menubar_handle == NULL) | ||
| 10023 | abort (); | ||
| 10024 | SetMenuBar (menubar_handle); | ||
| 10025 | DrawMenuBar (); | ||
| 10026 | |||
| 10027 | #if !TARGET_API_MAC_CARBON | ||
| 10028 | menu = GetMenuRef (M_APPLE); | ||
| 10029 | if (menu != NULL) | ||
| 10030 | AppendResMenu (menu, 'DRVR'); | ||
| 10031 | else | ||
| 10032 | abort (); | ||
| 10033 | #endif | ||
| 10034 | } | ||
| 10035 | |||
| 10036 | |||
| 10037 | static void | ||
| 10038 | do_init_managers (void) | ||
| 10039 | { | ||
| 10040 | #if !TARGET_API_MAC_CARBON | ||
| 10041 | InitGraf (&qd.thePort); | ||
| 10042 | InitFonts (); | ||
| 10043 | FlushEvents (everyEvent, 0); | ||
| 10044 | InitWindows (); | ||
| 10045 | InitMenus (); | ||
| 10046 | TEInit (); | ||
| 10047 | InitDialogs (NULL); | ||
| 10048 | #endif /* !TARGET_API_MAC_CARBON */ | ||
| 10049 | InitCursor (); | ||
| 10050 | |||
| 10051 | #if !TARGET_API_MAC_CARBON | ||
| 10052 | /* set up some extra stack space for use by emacs */ | ||
| 10053 | SetApplLimit ((Ptr) ((long) GetApplLimit () - EXTRA_STACK_ALLOC)); | ||
| 10054 | |||
| 10055 | /* MaxApplZone must be called for AppleScript to execute more | ||
| 10056 | complicated scripts */ | ||
| 10057 | MaxApplZone (); | ||
| 10058 | MoreMasters (); | ||
| 10059 | #endif /* !TARGET_API_MAC_CARBON */ | ||
| 10060 | } | ||
| 10061 | |||
| 10062 | static void | ||
| 10063 | do_check_ram_size (void) | ||
| 10064 | { | ||
| 10065 | SInt32 physical_ram_size, logical_ram_size; | ||
| 10066 | |||
| 10067 | if (Gestalt (gestaltPhysicalRAMSize, &physical_ram_size) != noErr | ||
| 10068 | || Gestalt (gestaltLogicalRAMSize, &logical_ram_size) != noErr | ||
| 10069 | || physical_ram_size > (1 << VALBITS) | ||
| 10070 | || logical_ram_size > (1 << VALBITS)) | ||
| 10071 | { | ||
| 10072 | StopAlert (RAM_TOO_LARGE_ALERT_ID, NULL); | ||
| 10073 | exit (1); | ||
| 10074 | } | ||
| 10075 | } | ||
| 10076 | #endif /* MAC_OS8 */ | ||
| 10077 | |||
| 10078 | static void | ||
| 10079 | do_window_update (WindowRef win) | ||
| 10080 | { | ||
| 10081 | struct frame *f = mac_window_to_frame (win); | ||
| 10082 | |||
| 10083 | BeginUpdate (win); | ||
| 10084 | |||
| 10085 | /* The tooltip has been drawn already. Avoid the SET_FRAME_GARBAGED | ||
| 10086 | below. */ | ||
| 10087 | if (win != tip_window) | ||
| 10088 | { | ||
| 10089 | if (f->async_visible == 0) | ||
| 10090 | { | ||
| 10091 | /* Update events may occur when a frame gets iconified. */ | ||
| 10092 | #if 0 | ||
| 10093 | f->async_visible = 1; | ||
| 10094 | f->async_iconified = 0; | ||
| 10095 | SET_FRAME_GARBAGED (f); | ||
| 10096 | #endif | ||
| 10097 | } | ||
| 10098 | else | ||
| 10099 | { | ||
| 10100 | Rect r; | ||
| 10101 | #if TARGET_API_MAC_CARBON | ||
| 10102 | RgnHandle region = NewRgn (); | ||
| 10103 | |||
| 10104 | GetPortVisibleRegion (GetWindowPort (win), region); | ||
| 10105 | GetRegionBounds (region, &r); | ||
| 10106 | expose_frame (f, r.left, r.top, r.right - r.left, r.bottom - r.top); | ||
| 10107 | #if USE_CG_DRAWING | ||
| 10108 | mac_prepare_for_quickdraw (f); | ||
| 10109 | #endif | ||
| 10110 | UpdateControls (win, region); | ||
| 10111 | DisposeRgn (region); | ||
| 10112 | #else | ||
| 10113 | r = (*win->visRgn)->rgnBBox; | ||
| 10114 | expose_frame (f, r.left, r.top, r.right - r.left, r.bottom - r.top); | ||
| 10115 | UpdateControls (win, win->visRgn); | ||
| 10116 | #endif | ||
| 10117 | } | ||
| 10118 | } | ||
| 10119 | |||
| 10120 | EndUpdate (win); | ||
| 10121 | } | ||
| 10122 | |||
| 10123 | static int | ||
| 10124 | is_emacs_window (WindowRef win) | ||
| 10125 | { | ||
| 10126 | Lisp_Object tail, frame; | ||
| 10127 | |||
| 10128 | if (!win) | ||
| 10129 | return 0; | ||
| 10130 | |||
| 10131 | FOR_EACH_FRAME (tail, frame) | ||
| 10132 | if (FRAME_MAC_P (XFRAME (frame))) | ||
| 10133 | if (FRAME_MAC_WINDOW (XFRAME (frame)) == win) | ||
| 10134 | return 1; | ||
| 10135 | |||
| 10136 | return 0; | ||
| 10137 | } | ||
| 10138 | |||
| 10139 | #if USE_MAC_TSM | 8325 | #if USE_MAC_TSM |
| 10140 | static OSStatus | 8326 | OSStatus |
| 10141 | mac_tsm_resume () | 8327 | mac_restore_keyboard_input_source () |
| 10142 | { | 8328 | { |
| 10143 | OSStatus err; | 8329 | OSStatus err = noErr; |
| 10144 | ScriptLanguageRecord slrec, *slptr = NULL; | 8330 | ScriptLanguageRecord slrec, *slptr = NULL; |
| 10145 | 8331 | ||
| 10146 | err = ActivateTSMDocument (tsm_document_id); | 8332 | if (EQ (Vmac_ts_script_language_on_focus, Qt) |
| 10147 | 8333 | && EQ (saved_ts_script_language_on_focus, Qt)) | |
| 10148 | if (err == noErr) | 8334 | slptr = &saved_ts_language; |
| 8335 | else if (CONSP (Vmac_ts_script_language_on_focus) | ||
| 8336 | && INTEGERP (XCAR (Vmac_ts_script_language_on_focus)) | ||
| 8337 | && INTEGERP (XCDR (Vmac_ts_script_language_on_focus)) | ||
| 8338 | && CONSP (saved_ts_script_language_on_focus) | ||
| 8339 | && EQ (XCAR (saved_ts_script_language_on_focus), | ||
| 8340 | XCAR (Vmac_ts_script_language_on_focus)) | ||
| 8341 | && EQ (XCDR (saved_ts_script_language_on_focus), | ||
| 8342 | XCDR (Vmac_ts_script_language_on_focus))) | ||
| 10149 | { | 8343 | { |
| 10150 | if (EQ (Vmac_ts_script_language_on_focus, Qt) | 8344 | slrec.fScript = XINT (XCAR (Vmac_ts_script_language_on_focus)); |
| 10151 | && EQ (saved_ts_script_language_on_focus, Qt)) | 8345 | slrec.fLanguage = XINT (XCDR (Vmac_ts_script_language_on_focus)); |
| 10152 | slptr = &saved_ts_language; | 8346 | slptr = &slrec; |
| 10153 | else if (CONSP (Vmac_ts_script_language_on_focus) | ||
| 10154 | && INTEGERP (XCAR (Vmac_ts_script_language_on_focus)) | ||
| 10155 | && INTEGERP (XCDR (Vmac_ts_script_language_on_focus)) | ||
| 10156 | && CONSP (saved_ts_script_language_on_focus) | ||
| 10157 | && EQ (XCAR (saved_ts_script_language_on_focus), | ||
| 10158 | XCAR (Vmac_ts_script_language_on_focus)) | ||
| 10159 | && EQ (XCDR (saved_ts_script_language_on_focus), | ||
| 10160 | XCDR (Vmac_ts_script_language_on_focus))) | ||
| 10161 | { | ||
| 10162 | slrec.fScript = XINT (XCAR (Vmac_ts_script_language_on_focus)); | ||
| 10163 | slrec.fLanguage = XINT (XCDR (Vmac_ts_script_language_on_focus)); | ||
| 10164 | slptr = &slrec; | ||
| 10165 | } | ||
| 10166 | } | 8347 | } |
| 10167 | 8348 | ||
| 10168 | if (slptr) | 8349 | if (slptr) |
| @@ -10184,8 +8365,8 @@ mac_tsm_resume () | |||
| 10184 | return err; | 8365 | return err; |
| 10185 | } | 8366 | } |
| 10186 | 8367 | ||
| 10187 | static OSStatus | 8368 | void |
| 10188 | mac_tsm_suspend () | 8369 | mac_save_keyboard_input_source () |
| 10189 | { | 8370 | { |
| 10190 | OSStatus err; | 8371 | OSStatus err; |
| 10191 | ScriptLanguageRecord slrec, *slptr = NULL; | 8372 | ScriptLanguageRecord slrec, *slptr = NULL; |
| @@ -10216,186 +8397,41 @@ mac_tsm_suspend () | |||
| 10216 | GetDefaultInputMethod (&saved_ts_component, slptr); | 8397 | GetDefaultInputMethod (&saved_ts_component, slptr); |
| 10217 | #endif | 8398 | #endif |
| 10218 | } | 8399 | } |
| 10219 | |||
| 10220 | err = DeactivateTSMDocument (tsm_document_id); | ||
| 10221 | |||
| 10222 | return err; | ||
| 10223 | } | ||
| 10224 | #endif | ||
| 10225 | |||
| 10226 | #if !TARGET_API_MAC_CARBON | ||
| 10227 | void | ||
| 10228 | do_apple_menu (SInt16 menu_item) | ||
| 10229 | { | ||
| 10230 | Str255 item_name; | ||
| 10231 | SInt16 da_driver_refnum; | ||
| 10232 | |||
| 10233 | if (menu_item == I_ABOUT) | ||
| 10234 | NoteAlert (ABOUT_ALERT_ID, NULL); | ||
| 10235 | else | ||
| 10236 | { | ||
| 10237 | GetMenuItemText (GetMenuRef (M_APPLE), menu_item, item_name); | ||
| 10238 | da_driver_refnum = OpenDeskAcc (item_name); | ||
| 10239 | } | ||
| 10240 | } | 8400 | } |
| 10241 | #endif /* !TARGET_API_MAC_CARBON */ | ||
| 10242 | |||
| 10243 | /* Handle drags in size box. Based on code contributed by Ben | ||
| 10244 | Mesander and IM - Window Manager A. */ | ||
| 10245 | |||
| 10246 | static void | ||
| 10247 | do_grow_window (w, e) | ||
| 10248 | WindowRef w; | ||
| 10249 | const EventRecord *e; | ||
| 10250 | { | ||
| 10251 | Rect limit_rect; | ||
| 10252 | int rows, columns, width, height; | ||
| 10253 | struct frame *f = mac_window_to_frame (w); | ||
| 10254 | XSizeHints *size_hints = FRAME_SIZE_HINTS (f); | ||
| 10255 | int min_width = MIN_DOC_SIZE, min_height = MIN_DOC_SIZE; | ||
| 10256 | #if TARGET_API_MAC_CARBON | ||
| 10257 | Rect new_rect; | ||
| 10258 | #else | ||
| 10259 | long grow_size; | ||
| 10260 | #endif | ||
| 10261 | |||
| 10262 | if (size_hints->flags & PMinSize) | ||
| 10263 | { | ||
| 10264 | min_width = size_hints->min_width; | ||
| 10265 | min_height = size_hints->min_height; | ||
| 10266 | } | ||
| 10267 | SetRect (&limit_rect, min_width, min_height, MAX_DOC_SIZE, MAX_DOC_SIZE); | ||
| 10268 | |||
| 10269 | #if TARGET_API_MAC_CARBON | ||
| 10270 | if (!ResizeWindow (w, e->where, &limit_rect, &new_rect)) | ||
| 10271 | return; | ||
| 10272 | height = new_rect.bottom - new_rect.top; | ||
| 10273 | width = new_rect.right - new_rect.left; | ||
| 10274 | #else | ||
| 10275 | grow_size = GrowWindow (w, e->where, &limit_rect); | ||
| 10276 | /* see if it really changed size */ | ||
| 10277 | if (grow_size == 0) | ||
| 10278 | return; | ||
| 10279 | height = HiWord (grow_size); | ||
| 10280 | width = LoWord (grow_size); | ||
| 10281 | #endif | 8401 | #endif |
| 10282 | 8402 | ||
| 10283 | if (width != FRAME_PIXEL_WIDTH (f) | ||
| 10284 | || height != FRAME_PIXEL_HEIGHT (f)) | ||
| 10285 | { | ||
| 10286 | rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); | ||
| 10287 | columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); | ||
| 10288 | |||
| 10289 | x_set_window_size (f, 0, columns, rows); | ||
| 10290 | } | ||
| 10291 | } | ||
| 10292 | |||
| 10293 | |||
| 10294 | #if TARGET_API_MAC_CARBON | 8403 | #if TARGET_API_MAC_CARBON |
| 10295 | static Point | 8404 | /***** Code to handle C-g testing *****/ |
| 10296 | mac_get_ideal_size (f) | 8405 | extern int quit_char; |
| 10297 | struct frame *f; | 8406 | extern int make_ctrl_char P_ ((int)); |
| 10298 | { | ||
| 10299 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 10300 | WindowRef w = FRAME_MAC_WINDOW (f); | ||
| 10301 | Point ideal_size; | ||
| 10302 | Rect standard_rect; | ||
| 10303 | int height, width, columns, rows; | ||
| 10304 | |||
| 10305 | ideal_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS); | ||
| 10306 | ideal_size.v = dpyinfo->height; | ||
| 10307 | IsWindowInStandardState (w, &ideal_size, &standard_rect); | ||
| 10308 | /* Adjust the standard size according to character boundaries. */ | ||
| 10309 | width = standard_rect.right - standard_rect.left; | ||
| 10310 | height = standard_rect.bottom - standard_rect.top; | ||
| 10311 | columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); | ||
| 10312 | rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); | ||
| 10313 | ideal_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, columns); | ||
| 10314 | ideal_size.v = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows); | ||
| 10315 | |||
| 10316 | return ideal_size; | ||
| 10317 | } | ||
| 10318 | #endif | ||
| 10319 | |||
| 10320 | /* Handle clicks in zoom box. Calculation of "standard state" based | ||
| 10321 | on code in IM - Window Manager A and code contributed by Ben | ||
| 10322 | Mesander. The standard state of an Emacs window is 80-characters | ||
| 10323 | wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */ | ||
| 10324 | 8407 | ||
| 10325 | static void | 8408 | int |
| 10326 | do_zoom_window (WindowRef w, int zoom_in_or_out) | 8409 | mac_quit_char_key_p (modifiers, key_code) |
| 8410 | UInt32 modifiers, key_code; | ||
| 10327 | { | 8411 | { |
| 10328 | Rect zoom_rect, port_rect; | 8412 | UInt32 char_code, mapped_modifiers; |
| 10329 | int width, height; | 8413 | unsigned long some_state = 0; |
| 10330 | struct frame *f = mac_window_to_frame (w); | 8414 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); |
| 10331 | #if TARGET_API_MAC_CARBON | 8415 | int c, emacs_modifiers; |
| 10332 | Point ideal_size = mac_get_ideal_size (f); | ||
| 10333 | |||
| 10334 | GetWindowBounds (w, kWindowContentRgn, &port_rect); | ||
| 10335 | if (IsWindowInStandardState (w, &ideal_size, &zoom_rect) | ||
| 10336 | && port_rect.left == zoom_rect.left | ||
| 10337 | && port_rect.top == zoom_rect.top) | ||
| 10338 | zoom_in_or_out = inZoomIn; | ||
| 10339 | else | ||
| 10340 | zoom_in_or_out = inZoomOut; | ||
| 10341 | |||
| 10342 | #ifdef MAC_OS8 | ||
| 10343 | mac_clear_window (f); | ||
| 10344 | #endif | ||
| 10345 | ZoomWindowIdeal (w, zoom_in_or_out, &ideal_size); | ||
| 10346 | #else /* not TARGET_API_MAC_CARBON */ | ||
| 10347 | GrafPtr save_port; | ||
| 10348 | Point top_left; | ||
| 10349 | int w_title_height, rows; | ||
| 10350 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 10351 | |||
| 10352 | GetPort (&save_port); | ||
| 10353 | |||
| 10354 | SetPortWindowPort (w); | ||
| 10355 | |||
| 10356 | /* Clear window to avoid flicker. */ | ||
| 10357 | EraseRect (&(w->portRect)); | ||
| 10358 | if (zoom_in_or_out == inZoomOut) | ||
| 10359 | { | ||
| 10360 | SetPt (&top_left, w->portRect.left, w->portRect.top); | ||
| 10361 | LocalToGlobal (&top_left); | ||
| 10362 | |||
| 10363 | /* calculate height of window's title bar */ | ||
| 10364 | w_title_height = top_left.v - 1 | ||
| 10365 | - (**((WindowPeek) w)->strucRgn).rgnBBox.top + GetMBarHeight (); | ||
| 10366 | |||
| 10367 | /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */ | ||
| 10368 | zoom_rect = qd.screenBits.bounds; | ||
| 10369 | zoom_rect.top += w_title_height; | ||
| 10370 | InsetRect (&zoom_rect, 8, 4); /* not too tight */ | ||
| 10371 | |||
| 10372 | zoom_rect.right = zoom_rect.left | ||
| 10373 | + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS); | ||
| 10374 | |||
| 10375 | /* Adjust the standard size according to character boundaries. */ | ||
| 10376 | rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, zoom_rect.bottom - zoom_rect.top); | ||
| 10377 | zoom_rect.bottom = | ||
| 10378 | zoom_rect.top + FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows); | ||
| 10379 | |||
| 10380 | (**((WStateDataHandle) ((WindowPeek) w)->dataHandle)).stdState | ||
| 10381 | = zoom_rect; | ||
| 10382 | } | ||
| 10383 | 8416 | ||
| 10384 | ZoomWindow (w, zoom_in_or_out, f == mac_focus_frame (dpyinfo)); | 8417 | /* Mask off modifier keys that are mapped to some Emacs modifiers. */ |
| 8418 | mapped_modifiers = mac_mapped_modifiers (modifiers, key_code); | ||
| 8419 | key_code |= (modifiers & ~mapped_modifiers); | ||
| 8420 | char_code = KeyTranslate (kchr_ptr, key_code, &some_state); | ||
| 8421 | if (char_code & ~0xff) | ||
| 8422 | return 0; | ||
| 10385 | 8423 | ||
| 10386 | SetPort (save_port); | 8424 | emacs_modifiers = mac_to_emacs_modifiers (mapped_modifiers, modifiers); |
| 10387 | #endif /* not TARGET_API_MAC_CARBON */ | 8425 | if (emacs_modifiers & ctrl_modifier) |
| 8426 | c = make_ctrl_char (char_code); | ||
| 10388 | 8427 | ||
| 10389 | #if !TARGET_API_MAC_CARBON | 8428 | c |= (emacs_modifiers |
| 10390 | /* retrieve window size and update application values */ | 8429 | & (meta_modifier | alt_modifier |
| 10391 | port_rect = w->portRect; | 8430 | | hyper_modifier | super_modifier)); |
| 10392 | height = port_rect.bottom - port_rect.top; | ||
| 10393 | width = port_rect.right - port_rect.left; | ||
| 10394 | 8431 | ||
| 10395 | mac_handle_size_change (f, width, height); | 8432 | return c == quit_char; |
| 10396 | mac_handle_origin_change (f); | ||
| 10397 | #endif | ||
| 10398 | } | 8433 | } |
| 8434 | #endif | ||
| 10399 | 8435 | ||
| 10400 | static void | 8436 | static void |
| 10401 | mac_set_unicode_keystroke_event (code, buf) | 8437 | mac_set_unicode_keystroke_event (code, buf) |
| @@ -10435,7 +8471,7 @@ mac_set_unicode_keystroke_event (code, buf) | |||
| 10435 | } | 8471 | } |
| 10436 | } | 8472 | } |
| 10437 | 8473 | ||
| 10438 | static void | 8474 | void |
| 10439 | do_keystroke (action, char_code, key_code, modifiers, timestamp, buf) | 8475 | do_keystroke (action, char_code, key_code, modifiers, timestamp, buf) |
| 10440 | EventKind action; | 8476 | EventKind action; |
| 10441 | unsigned char char_code; | 8477 | unsigned char char_code; |
| @@ -10616,7 +8652,7 @@ mac_store_apple_event (class, id, desc) | |||
| 10616 | } | 8652 | } |
| 10617 | 8653 | ||
| 10618 | #if TARGET_API_MAC_CARBON | 8654 | #if TARGET_API_MAC_CARBON |
| 10619 | static OSStatus | 8655 | OSStatus |
| 10620 | mac_store_event_ref_as_apple_event (class, id, class_key, id_key, | 8656 | mac_store_event_ref_as_apple_event (class, id, class_key, id_key, |
| 10621 | event, num_params, names, types) | 8657 | event, num_params, names, types) |
| 10622 | AEEventClass class; | 8658 | AEEventClass class; |
| @@ -10652,830 +8688,8 @@ mac_store_event_ref_as_apple_event (class, id, class_key, id_key, | |||
| 10652 | 8688 | ||
| 10653 | return err; | 8689 | return err; |
| 10654 | } | 8690 | } |
| 10655 | |||
| 10656 | void | ||
| 10657 | mac_store_drag_event (window, mouse_pos, modifiers, desc) | ||
| 10658 | WindowRef window; | ||
| 10659 | Point mouse_pos; | ||
| 10660 | SInt16 modifiers; | ||
| 10661 | const AEDesc *desc; | ||
| 10662 | { | ||
| 10663 | struct input_event buf; | ||
| 10664 | |||
| 10665 | EVENT_INIT (buf); | ||
| 10666 | |||
| 10667 | buf.kind = DRAG_N_DROP_EVENT; | ||
| 10668 | buf.modifiers = mac_to_emacs_modifiers (modifiers, 0); | ||
| 10669 | buf.timestamp = TickCount () * (1000 / 60); | ||
| 10670 | XSETINT (buf.x, mouse_pos.h); | ||
| 10671 | XSETINT (buf.y, mouse_pos.v); | ||
| 10672 | XSETFRAME (buf.frame_or_window, mac_window_to_frame (window)); | ||
| 10673 | buf.arg = mac_aedesc_to_lisp (desc); | ||
| 10674 | kbd_buffer_store_event (&buf); | ||
| 10675 | } | ||
| 10676 | |||
| 10677 | #ifdef MAC_OSX | ||
| 10678 | OSStatus | ||
| 10679 | mac_store_service_event (event) | ||
| 10680 | EventRef event; | ||
| 10681 | { | ||
| 10682 | OSStatus err; | ||
| 10683 | Lisp_Object id_key; | ||
| 10684 | int num_params; | ||
| 10685 | const EventParamName *names; | ||
| 10686 | const EventParamType *types; | ||
| 10687 | static const EventParamName names_pfm[] = | ||
| 10688 | {kEventParamServiceMessageName, kEventParamServiceUserData}; | ||
| 10689 | static const EventParamType types_pfm[] = | ||
| 10690 | {typeCFStringRef, typeCFStringRef}; | ||
| 10691 | |||
| 10692 | switch (GetEventKind (event)) | ||
| 10693 | { | ||
| 10694 | case kEventServicePaste: | ||
| 10695 | id_key = Qpaste; | ||
| 10696 | num_params = 0; | ||
| 10697 | names = NULL; | ||
| 10698 | types = NULL; | ||
| 10699 | break; | ||
| 10700 | |||
| 10701 | case kEventServicePerform: | ||
| 10702 | id_key = Qperform; | ||
| 10703 | num_params = sizeof (names_pfm) / sizeof (names_pfm[0]); | ||
| 10704 | names = names_pfm; | ||
| 10705 | types = types_pfm; | ||
| 10706 | break; | ||
| 10707 | |||
| 10708 | default: | ||
| 10709 | abort (); | ||
| 10710 | } | ||
| 10711 | |||
| 10712 | err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key, | ||
| 10713 | event, num_params, | ||
| 10714 | names, types); | ||
| 10715 | |||
| 10716 | return err; | ||
| 10717 | } | ||
| 10718 | #endif /* MAC_OSX */ | ||
| 10719 | |||
| 10720 | static pascal OSStatus | ||
| 10721 | mac_handle_window_event (next_handler, event, data) | ||
| 10722 | EventHandlerCallRef next_handler; | ||
| 10723 | EventRef event; | ||
| 10724 | void *data; | ||
| 10725 | { | ||
| 10726 | WindowRef wp; | ||
| 10727 | OSStatus err, result = eventNotHandledErr; | ||
| 10728 | struct frame *f; | ||
| 10729 | UInt32 attributes; | ||
| 10730 | XSizeHints *size_hints; | ||
| 10731 | |||
| 10732 | err = GetEventParameter (event, kEventParamDirectObject, typeWindowRef, | ||
| 10733 | NULL, sizeof (WindowRef), NULL, &wp); | ||
| 10734 | if (err != noErr) | ||
| 10735 | return eventNotHandledErr; | ||
| 10736 | |||
| 10737 | f = mac_window_to_frame (wp); | ||
| 10738 | switch (GetEventKind (event)) | ||
| 10739 | { | ||
| 10740 | /* -- window refresh events -- */ | ||
| 10741 | |||
| 10742 | case kEventWindowUpdate: | ||
| 10743 | result = CallNextEventHandler (next_handler, event); | ||
| 10744 | if (result != eventNotHandledErr) | ||
| 10745 | break; | ||
| 10746 | |||
| 10747 | do_window_update (wp); | ||
| 10748 | result = noErr; | ||
| 10749 | break; | ||
| 10750 | |||
| 10751 | /* -- window state change events -- */ | ||
| 10752 | |||
| 10753 | case kEventWindowShowing: | ||
| 10754 | size_hints = FRAME_SIZE_HINTS (f); | ||
| 10755 | if (!(size_hints->flags & (USPosition | PPosition))) | ||
| 10756 | { | ||
| 10757 | struct frame *sf = SELECTED_FRAME (); | ||
| 10758 | |||
| 10759 | if (!(FRAME_MAC_P (sf) && sf->async_visible)) | ||
| 10760 | RepositionWindow (wp, NULL, kWindowCenterOnMainScreen); | ||
| 10761 | else | ||
| 10762 | { | ||
| 10763 | RepositionWindow (wp, FRAME_MAC_WINDOW (sf), | ||
| 10764 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 10765 | kWindowCascadeStartAtParentWindowScreen | ||
| 10766 | #else | ||
| 10767 | kWindowCascadeOnParentWindowScreen | ||
| 10768 | #endif | ||
| 10769 | ); | ||
| 10770 | #if USE_MAC_TOOLBAR | ||
| 10771 | /* This is a workaround. RepositionWindow fails to put | ||
| 10772 | a window at the cascading position when its parent | ||
| 10773 | window has a Carbon HIToolbar. */ | ||
| 10774 | if ((f->left_pos == sf->left_pos | ||
| 10775 | && f->top_pos == sf->top_pos) | ||
| 10776 | || (f->left_pos == sf->left_pos + 10 * 2 | ||
| 10777 | && f->top_pos == sf->top_pos + 32 * 2)) | ||
| 10778 | MoveWindowStructure (wp, sf->left_pos + 10, sf->top_pos + 32); | ||
| 10779 | #endif | ||
| 10780 | } | ||
| 10781 | result = noErr; | ||
| 10782 | } | ||
| 10783 | break; | ||
| 10784 | |||
| 10785 | case kEventWindowHiding: | ||
| 10786 | /* Before unmapping the window, update the WM_SIZE_HINTS | ||
| 10787 | property to claim that the current position of the window is | ||
| 10788 | user-specified, rather than program-specified, so that when | ||
| 10789 | the window is mapped again, it will be placed at the same | ||
| 10790 | location, without forcing the user to position it by hand | ||
| 10791 | again (they have already done that once for this window.) */ | ||
| 10792 | x_wm_set_size_hint (f, (long) 0, 1); | ||
| 10793 | result = noErr; | ||
| 10794 | break; | ||
| 10795 | |||
| 10796 | case kEventWindowShown: | ||
| 10797 | case kEventWindowHidden: | ||
| 10798 | case kEventWindowCollapsed: | ||
| 10799 | case kEventWindowExpanded: | ||
| 10800 | mac_handle_visibility_change (f); | ||
| 10801 | result = noErr; | ||
| 10802 | break; | ||
| 10803 | |||
| 10804 | case kEventWindowBoundsChanging: | ||
| 10805 | result = CallNextEventHandler (next_handler, event); | ||
| 10806 | if (result != eventNotHandledErr) | ||
| 10807 | break; | ||
| 10808 | |||
| 10809 | err = GetEventParameter (event, kEventParamAttributes, typeUInt32, | ||
| 10810 | NULL, sizeof (UInt32), NULL, &attributes); | ||
| 10811 | if (err != noErr) | ||
| 10812 | break; | ||
| 10813 | |||
| 10814 | size_hints = FRAME_SIZE_HINTS (f); | ||
| 10815 | if ((attributes & kWindowBoundsChangeUserResize) | ||
| 10816 | && ((size_hints->flags & (PResizeInc | PBaseSize | PMinSize)) | ||
| 10817 | == (PResizeInc | PBaseSize | PMinSize))) | ||
| 10818 | { | ||
| 10819 | Rect bounds; | ||
| 10820 | int width, height; | ||
| 10821 | |||
| 10822 | err = GetEventParameter (event, kEventParamCurrentBounds, | ||
| 10823 | typeQDRectangle, NULL, sizeof (Rect), | ||
| 10824 | NULL, &bounds); | ||
| 10825 | if (err != noErr) | ||
| 10826 | break; | ||
| 10827 | |||
| 10828 | width = bounds.right - bounds.left; | ||
| 10829 | height = bounds.bottom - bounds.top; | ||
| 10830 | |||
| 10831 | if (width < size_hints->min_width) | ||
| 10832 | width = size_hints->min_width; | ||
| 10833 | else | ||
| 10834 | width = size_hints->base_width | ||
| 10835 | + (int) ((width - size_hints->base_width) | ||
| 10836 | / (float) size_hints->width_inc + .5) | ||
| 10837 | * size_hints->width_inc; | ||
| 10838 | |||
| 10839 | if (height < size_hints->min_height) | ||
| 10840 | height = size_hints->min_height; | ||
| 10841 | else | ||
| 10842 | height = size_hints->base_height | ||
| 10843 | + (int) ((height - size_hints->base_height) | ||
| 10844 | / (float) size_hints->height_inc + .5) | ||
| 10845 | * size_hints->height_inc; | ||
| 10846 | |||
| 10847 | bounds.right = bounds.left + width; | ||
| 10848 | bounds.bottom = bounds.top + height; | ||
| 10849 | SetEventParameter (event, kEventParamCurrentBounds, | ||
| 10850 | typeQDRectangle, sizeof (Rect), &bounds); | ||
| 10851 | result = noErr; | ||
| 10852 | } | ||
| 10853 | break; | ||
| 10854 | |||
| 10855 | case kEventWindowBoundsChanged: | ||
| 10856 | err = GetEventParameter (event, kEventParamAttributes, typeUInt32, | ||
| 10857 | NULL, sizeof (UInt32), NULL, &attributes); | ||
| 10858 | if (err != noErr) | ||
| 10859 | break; | ||
| 10860 | |||
| 10861 | if (attributes & kWindowBoundsChangeSizeChanged) | ||
| 10862 | { | ||
| 10863 | Rect bounds; | ||
| 10864 | |||
| 10865 | err = GetEventParameter (event, kEventParamCurrentBounds, | ||
| 10866 | typeQDRectangle, NULL, sizeof (Rect), | ||
| 10867 | NULL, &bounds); | ||
| 10868 | if (err == noErr) | ||
| 10869 | { | ||
| 10870 | int width, height; | ||
| 10871 | |||
| 10872 | width = bounds.right - bounds.left; | ||
| 10873 | height = bounds.bottom - bounds.top; | ||
| 10874 | mac_handle_size_change (f, width, height); | ||
| 10875 | mac_wakeup_from_rne (); | ||
| 10876 | } | ||
| 10877 | } | ||
| 10878 | |||
| 10879 | if (attributes & kWindowBoundsChangeOriginChanged) | ||
| 10880 | mac_handle_origin_change (f); | ||
| 10881 | |||
| 10882 | result = noErr; | ||
| 10883 | break; | ||
| 10884 | |||
| 10885 | /* -- window action events -- */ | ||
| 10886 | |||
| 10887 | case kEventWindowClose: | ||
| 10888 | { | ||
| 10889 | struct input_event buf; | ||
| 10890 | |||
| 10891 | EVENT_INIT (buf); | ||
| 10892 | buf.kind = DELETE_WINDOW_EVENT; | ||
| 10893 | XSETFRAME (buf.frame_or_window, f); | ||
| 10894 | buf.arg = Qnil; | ||
| 10895 | kbd_buffer_store_event (&buf); | ||
| 10896 | } | ||
| 10897 | result = noErr; | ||
| 10898 | break; | ||
| 10899 | |||
| 10900 | case kEventWindowGetIdealSize: | ||
| 10901 | result = CallNextEventHandler (next_handler, event); | ||
| 10902 | if (result != eventNotHandledErr) | ||
| 10903 | break; | ||
| 10904 | |||
| 10905 | { | ||
| 10906 | Point ideal_size = mac_get_ideal_size (f); | ||
| 10907 | |||
| 10908 | err = SetEventParameter (event, kEventParamDimensions, | ||
| 10909 | typeQDPoint, sizeof (Point), &ideal_size); | ||
| 10910 | if (err == noErr) | ||
| 10911 | result = noErr; | ||
| 10912 | } | ||
| 10913 | break; | ||
| 10914 | |||
| 10915 | #ifdef MAC_OSX | ||
| 10916 | case kEventWindowToolbarSwitchMode: | ||
| 10917 | { | ||
| 10918 | static const EventParamName names[] = {kEventParamDirectObject, | ||
| 10919 | kEventParamWindowMouseLocation, | ||
| 10920 | kEventParamKeyModifiers, | ||
| 10921 | kEventParamMouseButton, | ||
| 10922 | kEventParamClickCount, | ||
| 10923 | kEventParamMouseChord}; | ||
| 10924 | static const EventParamType types[] = {typeWindowRef, | ||
| 10925 | typeQDPoint, | ||
| 10926 | typeUInt32, | ||
| 10927 | typeMouseButton, | ||
| 10928 | typeUInt32, | ||
| 10929 | typeUInt32}; | ||
| 10930 | int num_params = sizeof (names) / sizeof (names[0]); | ||
| 10931 | |||
| 10932 | err = mac_store_event_ref_as_apple_event (0, 0, | ||
| 10933 | Qwindow, | ||
| 10934 | Qtoolbar_switch_mode, | ||
| 10935 | event, num_params, | ||
| 10936 | names, types); | ||
| 10937 | } | ||
| 10938 | if (err == noErr) | ||
| 10939 | result = noErr; | ||
| 10940 | break; | ||
| 10941 | #endif | ||
| 10942 | |||
| 10943 | #if USE_MAC_TSM | ||
| 10944 | /* -- window focus events -- */ | ||
| 10945 | |||
| 10946 | case kEventWindowFocusAcquired: | ||
| 10947 | err = mac_tsm_resume (); | ||
| 10948 | if (err == noErr) | ||
| 10949 | result = noErr; | ||
| 10950 | break; | ||
| 10951 | |||
| 10952 | case kEventWindowFocusRelinquish: | ||
| 10953 | err = mac_tsm_suspend (); | ||
| 10954 | if (err == noErr) | ||
| 10955 | result = noErr; | ||
| 10956 | break; | ||
| 10957 | #endif | ||
| 10958 | |||
| 10959 | default: | ||
| 10960 | abort (); | ||
| 10961 | } | ||
| 10962 | |||
| 10963 | return result; | ||
| 10964 | } | ||
| 10965 | |||
| 10966 | static pascal OSStatus | ||
| 10967 | mac_handle_keyboard_event (next_handler, event, data) | ||
| 10968 | EventHandlerCallRef next_handler; | ||
| 10969 | EventRef event; | ||
| 10970 | void *data; | ||
| 10971 | { | ||
| 10972 | OSStatus err, result = eventNotHandledErr; | ||
| 10973 | UInt32 event_kind, key_code, modifiers; | ||
| 10974 | unsigned char char_code; | ||
| 10975 | |||
| 10976 | event_kind = GetEventKind (event); | ||
| 10977 | switch (event_kind) | ||
| 10978 | { | ||
| 10979 | case kEventRawKeyDown: | ||
| 10980 | case kEventRawKeyRepeat: | ||
| 10981 | case kEventRawKeyUp: | ||
| 10982 | /* When using Carbon Events, we need to pass raw keyboard events | ||
| 10983 | to the TSM ourselves. If TSM handles it, it will pass back | ||
| 10984 | noErr, otherwise it will pass back "eventNotHandledErr" and | ||
| 10985 | we can process it normally. */ | ||
| 10986 | result = CallNextEventHandler (next_handler, event); | ||
| 10987 | if (result != eventNotHandledErr) | ||
| 10988 | break; | ||
| 10989 | |||
| 10990 | if (read_socket_inev == NULL) | ||
| 10991 | break; | ||
| 10992 | |||
| 10993 | #if USE_MAC_TSM | ||
| 10994 | if (read_socket_inev->kind != NO_EVENT) | ||
| 10995 | { | ||
| 10996 | result = noErr; | ||
| 10997 | break; | ||
| 10998 | } | ||
| 10999 | #endif | ||
| 11000 | |||
| 11001 | if (event_kind == kEventRawKeyUp) | ||
| 11002 | break; | ||
| 11003 | |||
| 11004 | err = GetEventParameter (event, kEventParamKeyMacCharCodes, | ||
| 11005 | typeChar, NULL, | ||
| 11006 | sizeof (char), NULL, &char_code); | ||
| 11007 | if (err != noErr) | ||
| 11008 | break; | ||
| 11009 | |||
| 11010 | err = GetEventParameter (event, kEventParamKeyCode, | ||
| 11011 | typeUInt32, NULL, | ||
| 11012 | sizeof (UInt32), NULL, &key_code); | ||
| 11013 | if (err != noErr) | ||
| 11014 | break; | ||
| 11015 | |||
| 11016 | err = GetEventParameter (event, kEventParamKeyModifiers, | ||
| 11017 | typeUInt32, NULL, | ||
| 11018 | sizeof (UInt32), NULL, &modifiers); | ||
| 11019 | if (err != noErr) | ||
| 11020 | break; | ||
| 11021 | |||
| 11022 | do_keystroke ((event_kind == kEventRawKeyDown ? keyDown : autoKey), | ||
| 11023 | char_code, key_code, modifiers, | ||
| 11024 | ((unsigned long) | ||
| 11025 | (GetEventTime (event) / kEventDurationMillisecond)), | ||
| 11026 | read_socket_inev); | ||
| 11027 | result = noErr; | ||
| 11028 | break; | ||
| 11029 | |||
| 11030 | default: | ||
| 11031 | abort (); | ||
| 11032 | } | ||
| 11033 | |||
| 11034 | return result; | ||
| 11035 | } | ||
| 11036 | |||
| 11037 | static pascal OSStatus | ||
| 11038 | mac_handle_command_event (next_handler, event, data) | ||
| 11039 | EventHandlerCallRef next_handler; | ||
| 11040 | EventRef event; | ||
| 11041 | void *data; | ||
| 11042 | { | ||
| 11043 | OSStatus err, result = eventNotHandledErr; | ||
| 11044 | HICommand command; | ||
| 11045 | static const EventParamName names[] = | ||
| 11046 | {kEventParamDirectObject, kEventParamKeyModifiers}; | ||
| 11047 | static const EventParamType types[] = | ||
| 11048 | {typeHICommand, typeUInt32}; | ||
| 11049 | int num_params = sizeof (names) / sizeof (names[0]); | ||
| 11050 | |||
| 11051 | err = GetEventParameter (event, kEventParamDirectObject, typeHICommand, | ||
| 11052 | NULL, sizeof (HICommand), NULL, &command); | ||
| 11053 | if (err != noErr) | ||
| 11054 | return eventNotHandledErr; | ||
| 11055 | |||
| 11056 | switch (GetEventKind (event)) | ||
| 11057 | { | ||
| 11058 | case kEventCommandProcess: | ||
| 11059 | result = CallNextEventHandler (next_handler, event); | ||
| 11060 | if (result != eventNotHandledErr) | ||
| 11061 | break; | ||
| 11062 | |||
| 11063 | err = GetEventParameter (event, kEventParamDirectObject, | ||
| 11064 | typeHICommand, NULL, | ||
| 11065 | sizeof (HICommand), NULL, &command); | ||
| 11066 | |||
| 11067 | if (err != noErr || command.commandID == 0) | ||
| 11068 | break; | ||
| 11069 | |||
| 11070 | /* A HI command event is mapped to an Apple event whose event | ||
| 11071 | class symbol is `hi-command' and event ID is its command | ||
| 11072 | ID. */ | ||
| 11073 | err = mac_store_event_ref_as_apple_event (0, command.commandID, | ||
| 11074 | Qhi_command, Qnil, | ||
| 11075 | event, num_params, | ||
| 11076 | names, types); | ||
| 11077 | if (err == noErr) | ||
| 11078 | result = noErr; | ||
| 11079 | break; | ||
| 11080 | |||
| 11081 | default: | ||
| 11082 | abort (); | ||
| 11083 | } | ||
| 11084 | |||
| 11085 | return result; | ||
| 11086 | } | ||
| 11087 | |||
| 11088 | static pascal OSStatus | ||
| 11089 | mac_handle_mouse_event (next_handler, event, data) | ||
| 11090 | EventHandlerCallRef next_handler; | ||
| 11091 | EventRef event; | ||
| 11092 | void *data; | ||
| 11093 | { | ||
| 11094 | OSStatus err, result = eventNotHandledErr; | ||
| 11095 | |||
| 11096 | switch (GetEventKind (event)) | ||
| 11097 | { | ||
| 11098 | case kEventMouseWheelMoved: | ||
| 11099 | { | ||
| 11100 | WindowRef wp; | ||
| 11101 | struct frame *f; | ||
| 11102 | EventMouseWheelAxis axis; | ||
| 11103 | SInt32 delta; | ||
| 11104 | Point point; | ||
| 11105 | |||
| 11106 | result = CallNextEventHandler (next_handler, event); | ||
| 11107 | if (result != eventNotHandledErr || read_socket_inev == NULL) | ||
| 11108 | break; | ||
| 11109 | |||
| 11110 | f = mac_focus_frame (&one_mac_display_info); | ||
| 11111 | |||
| 11112 | err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, | ||
| 11113 | NULL, sizeof (WindowRef), NULL, &wp); | ||
| 11114 | if (err != noErr | ||
| 11115 | || wp != FRAME_MAC_WINDOW (f)) | ||
| 11116 | break; | ||
| 11117 | |||
| 11118 | err = GetEventParameter (event, kEventParamMouseWheelAxis, | ||
| 11119 | typeMouseWheelAxis, NULL, | ||
| 11120 | sizeof (EventMouseWheelAxis), NULL, &axis); | ||
| 11121 | if (err != noErr || axis != kEventMouseWheelAxisY) | ||
| 11122 | break; | ||
| 11123 | |||
| 11124 | err = GetEventParameter (event, kEventParamMouseLocation, | ||
| 11125 | typeQDPoint, NULL, sizeof (Point), | ||
| 11126 | NULL, &point); | ||
| 11127 | if (err != noErr) | ||
| 11128 | break; | ||
| 11129 | |||
| 11130 | point.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); | ||
| 11131 | point.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); | ||
| 11132 | if (point.h < 0 || point.v < 0 | ||
| 11133 | || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1), | ||
| 11134 | f->tool_bar_window)) | ||
| 11135 | break; | ||
| 11136 | |||
| 11137 | err = GetEventParameter (event, kEventParamMouseWheelDelta, | ||
| 11138 | typeSInt32, NULL, sizeof (SInt32), | ||
| 11139 | NULL, &delta); | ||
| 11140 | if (err != noErr) | ||
| 11141 | break; | ||
| 11142 | |||
| 11143 | read_socket_inev->kind = WHEEL_EVENT; | ||
| 11144 | read_socket_inev->code = 0; | ||
| 11145 | read_socket_inev->modifiers = | ||
| 11146 | (mac_event_to_emacs_modifiers (event) | ||
| 11147 | | ((delta < 0) ? down_modifier : up_modifier)); | ||
| 11148 | XSETINT (read_socket_inev->x, point.h); | ||
| 11149 | XSETINT (read_socket_inev->y, point.v); | ||
| 11150 | XSETFRAME (read_socket_inev->frame_or_window, f); | ||
| 11151 | |||
| 11152 | result = noErr; | ||
| 11153 | } | ||
| 11154 | break; | ||
| 11155 | |||
| 11156 | default: | ||
| 11157 | abort (); | ||
| 11158 | } | ||
| 11159 | |||
| 11160 | return result; | ||
| 11161 | } | ||
| 11162 | |||
| 11163 | #if USE_MAC_TSM | ||
| 11164 | static pascal OSStatus | ||
| 11165 | mac_handle_text_input_event (next_handler, event, data) | ||
| 11166 | EventHandlerCallRef next_handler; | ||
| 11167 | EventRef event; | ||
| 11168 | void *data; | ||
| 11169 | { | ||
| 11170 | OSStatus err, result; | ||
| 11171 | Lisp_Object id_key = Qnil; | ||
| 11172 | int num_params; | ||
| 11173 | const EventParamName *names; | ||
| 11174 | const EventParamType *types; | ||
| 11175 | static UInt32 seqno_uaia = 0; | ||
| 11176 | static const EventParamName names_uaia[] = | ||
| 11177 | {kEventParamTextInputSendComponentInstance, | ||
| 11178 | kEventParamTextInputSendRefCon, | ||
| 11179 | kEventParamTextInputSendSLRec, | ||
| 11180 | kEventParamTextInputSendFixLen, | ||
| 11181 | kEventParamTextInputSendText, | ||
| 11182 | kEventParamTextInputSendUpdateRng, | ||
| 11183 | kEventParamTextInputSendHiliteRng, | ||
| 11184 | kEventParamTextInputSendClauseRng, | ||
| 11185 | kEventParamTextInputSendPinRng, | ||
| 11186 | kEventParamTextInputSendTextServiceEncoding, | ||
| 11187 | kEventParamTextInputSendTextServiceMacEncoding, | ||
| 11188 | EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER}; | ||
| 11189 | static const EventParamType types_uaia[] = | ||
| 11190 | {typeComponentInstance, | ||
| 11191 | typeLongInteger, | ||
| 11192 | typeIntlWritingCode, | ||
| 11193 | typeLongInteger, | ||
| 11194 | #ifdef MAC_OSX | ||
| 11195 | typeUnicodeText, | ||
| 11196 | #else | ||
| 11197 | typeChar, | ||
| 11198 | #endif | ||
| 11199 | typeTextRangeArray, | ||
| 11200 | typeTextRangeArray, | ||
| 11201 | typeOffsetArray, | ||
| 11202 | typeTextRange, | ||
| 11203 | typeUInt32, | ||
| 11204 | typeUInt32, | ||
| 11205 | typeUInt32}; | ||
| 11206 | static const EventParamName names_ufke[] = | ||
| 11207 | {kEventParamTextInputSendComponentInstance, | ||
| 11208 | kEventParamTextInputSendRefCon, | ||
| 11209 | kEventParamTextInputSendSLRec, | ||
| 11210 | kEventParamTextInputSendText}; | ||
| 11211 | static const EventParamType types_ufke[] = | ||
| 11212 | {typeComponentInstance, | ||
| 11213 | typeLongInteger, | ||
| 11214 | typeIntlWritingCode, | ||
| 11215 | typeUnicodeText}; | ||
| 11216 | |||
| 11217 | result = CallNextEventHandler (next_handler, event); | ||
| 11218 | if (result != eventNotHandledErr) | ||
| 11219 | return result; | ||
| 11220 | |||
| 11221 | switch (GetEventKind (event)) | ||
| 11222 | { | ||
| 11223 | case kEventTextInputUpdateActiveInputArea: | ||
| 11224 | id_key = Qupdate_active_input_area; | ||
| 11225 | num_params = sizeof (names_uaia) / sizeof (names_uaia[0]); | ||
| 11226 | names = names_uaia; | ||
| 11227 | types = types_uaia; | ||
| 11228 | SetEventParameter (event, EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER, | ||
| 11229 | typeUInt32, sizeof (UInt32), &seqno_uaia); | ||
| 11230 | seqno_uaia++; | ||
| 11231 | result = noErr; | ||
| 11232 | break; | ||
| 11233 | |||
| 11234 | case kEventTextInputUnicodeForKeyEvent: | ||
| 11235 | { | ||
| 11236 | EventRef kbd_event; | ||
| 11237 | UInt32 actual_size, modifiers, key_code; | ||
| 11238 | |||
| 11239 | err = GetEventParameter (event, kEventParamTextInputSendKeyboardEvent, | ||
| 11240 | typeEventRef, NULL, sizeof (EventRef), NULL, | ||
| 11241 | &kbd_event); | ||
| 11242 | if (err == noErr) | ||
| 11243 | err = GetEventParameter (kbd_event, kEventParamKeyModifiers, | ||
| 11244 | typeUInt32, NULL, | ||
| 11245 | sizeof (UInt32), NULL, &modifiers); | ||
| 11246 | if (err == noErr) | ||
| 11247 | err = GetEventParameter (kbd_event, kEventParamKeyCode, | ||
| 11248 | typeUInt32, NULL, sizeof (UInt32), | ||
| 11249 | NULL, &key_code); | ||
| 11250 | if (err == noErr && mac_mapped_modifiers (modifiers, key_code)) | ||
| 11251 | /* There're mapped modifier keys. Process it in | ||
| 11252 | do_keystroke. */ | ||
| 11253 | break; | ||
| 11254 | if (err == noErr) | ||
| 11255 | err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, | ||
| 11256 | typeUnicodeText, NULL, 0, &actual_size, | ||
| 11257 | NULL); | ||
| 11258 | if (err == noErr && actual_size == sizeof (UniChar)) | ||
| 11259 | { | ||
| 11260 | UniChar code; | ||
| 11261 | |||
| 11262 | err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, | ||
| 11263 | typeUnicodeText, NULL, | ||
| 11264 | sizeof (UniChar), NULL, &code); | ||
| 11265 | if (err == noErr && code < 0x80) | ||
| 11266 | { | ||
| 11267 | /* ASCII character. Process it in do_keystroke. */ | ||
| 11268 | if (read_socket_inev && code >= 0x20 && code <= 0x7e | ||
| 11269 | && !(key_code <= 0x7f | ||
| 11270 | && keycode_to_xkeysym_table [key_code])) | ||
| 11271 | { | ||
| 11272 | struct frame *f = mac_focus_frame (&one_mac_display_info); | ||
| 11273 | |||
| 11274 | read_socket_inev->kind = ASCII_KEYSTROKE_EVENT; | ||
| 11275 | read_socket_inev->code = code; | ||
| 11276 | read_socket_inev->modifiers = | ||
| 11277 | mac_to_emacs_modifiers (modifiers, 0); | ||
| 11278 | read_socket_inev->modifiers |= | ||
| 11279 | (extra_keyboard_modifiers | ||
| 11280 | & (meta_modifier | alt_modifier | ||
| 11281 | | hyper_modifier | super_modifier)); | ||
| 11282 | XSETFRAME (read_socket_inev->frame_or_window, f); | ||
| 11283 | } | ||
| 11284 | break; | ||
| 11285 | } | ||
| 11286 | } | ||
| 11287 | if (err == noErr) | ||
| 11288 | { | ||
| 11289 | /* Non-ASCII keystrokes without mapped modifiers are | ||
| 11290 | processed at the Lisp level. */ | ||
| 11291 | id_key = Qunicode_for_key_event; | ||
| 11292 | num_params = sizeof (names_ufke) / sizeof (names_ufke[0]); | ||
| 11293 | names = names_ufke; | ||
| 11294 | types = types_ufke; | ||
| 11295 | result = noErr; | ||
| 11296 | } | ||
| 11297 | } | ||
| 11298 | break; | ||
| 11299 | |||
| 11300 | case kEventTextInputOffsetToPos: | ||
| 11301 | { | ||
| 11302 | struct frame *f; | ||
| 11303 | struct window *w; | ||
| 11304 | Point p; | ||
| 11305 | |||
| 11306 | if (!OVERLAYP (Vmac_ts_active_input_overlay)) | ||
| 11307 | break; | ||
| 11308 | |||
| 11309 | /* Strictly speaking, this is not always correct because | ||
| 11310 | previous events may change some states about display. */ | ||
| 11311 | if (!NILP (Foverlay_get (Vmac_ts_active_input_overlay, Qbefore_string))) | ||
| 11312 | { | ||
| 11313 | /* Active input area is displayed around the current point. */ | ||
| 11314 | f = SELECTED_FRAME (); | ||
| 11315 | w = XWINDOW (f->selected_window); | ||
| 11316 | } | ||
| 11317 | else if (WINDOWP (echo_area_window)) | ||
| 11318 | { | ||
| 11319 | /* Active input area is displayed in the echo area. */ | ||
| 11320 | w = XWINDOW (echo_area_window); | ||
| 11321 | f = WINDOW_XFRAME (w); | ||
| 11322 | } | ||
| 11323 | else | ||
| 11324 | break; | ||
| 11325 | |||
| 11326 | p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) | ||
| 11327 | + WINDOW_LEFT_FRINGE_WIDTH (w) | ||
| 11328 | + f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f)); | ||
| 11329 | p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) | ||
| 11330 | + FONT_BASE (FRAME_FONT (f)) | ||
| 11331 | + f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f)); | ||
| 11332 | err = SetEventParameter (event, kEventParamTextInputReplyPoint, | ||
| 11333 | typeQDPoint, sizeof (typeQDPoint), &p); | ||
| 11334 | if (err == noErr) | ||
| 11335 | result = noErr; | ||
| 11336 | } | ||
| 11337 | break; | ||
| 11338 | |||
| 11339 | default: | ||
| 11340 | abort (); | ||
| 11341 | } | ||
| 11342 | |||
| 11343 | if (!NILP (id_key)) | ||
| 11344 | err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key, | ||
| 11345 | event, num_params, | ||
| 11346 | names, types); | ||
| 11347 | return result; | ||
| 11348 | } | ||
| 11349 | #endif | ||
| 11350 | #endif /* TARGET_API_MAC_CARBON */ | 8691 | #endif /* TARGET_API_MAC_CARBON */ |
| 11351 | 8692 | ||
| 11352 | |||
| 11353 | OSStatus | ||
| 11354 | install_window_handler (window) | ||
| 11355 | WindowRef window; | ||
| 11356 | { | ||
| 11357 | OSStatus err = noErr; | ||
| 11358 | |||
| 11359 | #if TARGET_API_MAC_CARBON | ||
| 11360 | if (err == noErr) | ||
| 11361 | { | ||
| 11362 | static const EventTypeSpec specs[] = | ||
| 11363 | { | ||
| 11364 | /* -- window refresh events -- */ | ||
| 11365 | {kEventClassWindow, kEventWindowUpdate}, | ||
| 11366 | /* -- window state change events -- */ | ||
| 11367 | {kEventClassWindow, kEventWindowShowing}, | ||
| 11368 | {kEventClassWindow, kEventWindowHiding}, | ||
| 11369 | {kEventClassWindow, kEventWindowShown}, | ||
| 11370 | {kEventClassWindow, kEventWindowHidden}, | ||
| 11371 | {kEventClassWindow, kEventWindowCollapsed}, | ||
| 11372 | {kEventClassWindow, kEventWindowExpanded}, | ||
| 11373 | {kEventClassWindow, kEventWindowBoundsChanging}, | ||
| 11374 | {kEventClassWindow, kEventWindowBoundsChanged}, | ||
| 11375 | /* -- window action events -- */ | ||
| 11376 | {kEventClassWindow, kEventWindowClose}, | ||
| 11377 | {kEventClassWindow, kEventWindowGetIdealSize}, | ||
| 11378 | #ifdef MAC_OSX | ||
| 11379 | {kEventClassWindow, kEventWindowToolbarSwitchMode}, | ||
| 11380 | #endif | ||
| 11381 | #if USE_MAC_TSM | ||
| 11382 | /* -- window focus events -- */ | ||
| 11383 | {kEventClassWindow, kEventWindowFocusAcquired}, | ||
| 11384 | {kEventClassWindow, kEventWindowFocusRelinquish}, | ||
| 11385 | #endif | ||
| 11386 | }; | ||
| 11387 | static EventHandlerUPP handle_window_eventUPP = NULL; | ||
| 11388 | |||
| 11389 | if (handle_window_eventUPP == NULL) | ||
| 11390 | handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); | ||
| 11391 | |||
| 11392 | err = InstallWindowEventHandler (window, handle_window_eventUPP, | ||
| 11393 | GetEventTypeCount (specs), | ||
| 11394 | specs, NULL, NULL); | ||
| 11395 | } | ||
| 11396 | #endif | ||
| 11397 | |||
| 11398 | if (err == noErr) | ||
| 11399 | err = install_drag_handler (window); | ||
| 11400 | |||
| 11401 | return err; | ||
| 11402 | } | ||
| 11403 | |||
| 11404 | void | ||
| 11405 | remove_window_handler (window) | ||
| 11406 | WindowRef window; | ||
| 11407 | { | ||
| 11408 | remove_drag_handler (window); | ||
| 11409 | } | ||
| 11410 | |||
| 11411 | #if TARGET_API_MAC_CARBON | ||
| 11412 | static OSStatus | ||
| 11413 | install_application_handler () | ||
| 11414 | { | ||
| 11415 | OSStatus err = noErr; | ||
| 11416 | |||
| 11417 | if (err == noErr) | ||
| 11418 | { | ||
| 11419 | static const EventTypeSpec specs[] = | ||
| 11420 | {{kEventClassKeyboard, kEventRawKeyDown}, | ||
| 11421 | {kEventClassKeyboard, kEventRawKeyRepeat}, | ||
| 11422 | {kEventClassKeyboard, kEventRawKeyUp}}; | ||
| 11423 | |||
| 11424 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 11425 | (mac_handle_keyboard_event), | ||
| 11426 | GetEventTypeCount (specs), | ||
| 11427 | specs, NULL, NULL); | ||
| 11428 | } | ||
| 11429 | |||
| 11430 | if (err == noErr) | ||
| 11431 | { | ||
| 11432 | static const EventTypeSpec specs[] = | ||
| 11433 | {{kEventClassCommand, kEventCommandProcess}}; | ||
| 11434 | |||
| 11435 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 11436 | (mac_handle_command_event), | ||
| 11437 | GetEventTypeCount (specs), | ||
| 11438 | specs, NULL, NULL); | ||
| 11439 | } | ||
| 11440 | |||
| 11441 | if (err == noErr) | ||
| 11442 | { | ||
| 11443 | static const EventTypeSpec specs[] = | ||
| 11444 | {{kEventClassMouse, kEventMouseWheelMoved}}; | ||
| 11445 | |||
| 11446 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 11447 | (mac_handle_mouse_event), | ||
| 11448 | GetEventTypeCount (specs), | ||
| 11449 | specs, NULL, NULL); | ||
| 11450 | } | ||
| 11451 | |||
| 11452 | #if USE_MAC_TSM | ||
| 11453 | if (err == noErr) | ||
| 11454 | { | ||
| 11455 | static const EventTypeSpec spec[] = | ||
| 11456 | {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea}, | ||
| 11457 | {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, | ||
| 11458 | {kEventClassTextInput, kEventTextInputOffsetToPos}}; | ||
| 11459 | |||
| 11460 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 11461 | (mac_handle_text_input_event), | ||
| 11462 | GetEventTypeCount (spec), | ||
| 11463 | spec, NULL, NULL); | ||
| 11464 | } | ||
| 11465 | #endif | ||
| 11466 | |||
| 11467 | if (err == noErr) | ||
| 11468 | err = install_menu_target_item_handler (); | ||
| 11469 | |||
| 11470 | #ifdef MAC_OSX | ||
| 11471 | if (err == noErr) | ||
| 11472 | err = install_service_handler (); | ||
| 11473 | #endif | ||
| 11474 | |||
| 11475 | return err; | ||
| 11476 | } | ||
| 11477 | #endif | ||
| 11478 | |||
| 11479 | static pascal void | 8693 | static pascal void |
| 11480 | mac_handle_dm_notification (event) | 8694 | mac_handle_dm_notification (event) |
| 11481 | AppleEvent *event; | 8695 | AppleEvent *event; |
| @@ -11529,7 +8743,7 @@ init_dm_notification_handler () | |||
| 11529 | return err; | 8743 | return err; |
| 11530 | } | 8744 | } |
| 11531 | 8745 | ||
| 11532 | static void | 8746 | void |
| 11533 | mac_get_screen_info (dpyinfo) | 8747 | mac_get_screen_info (dpyinfo) |
| 11534 | struct mac_display_info *dpyinfo; | 8748 | struct mac_display_info *dpyinfo; |
| 11535 | { | 8749 | { |
| @@ -11584,6 +8798,78 @@ mac_get_screen_info (dpyinfo) | |||
| 11584 | #endif /* !MAC_OSX */ | 8798 | #endif /* !MAC_OSX */ |
| 11585 | } | 8799 | } |
| 11586 | 8800 | ||
| 8801 | |||
| 8802 | /*********************************************************************** | ||
| 8803 | Initialization (Mac OS Classic) | ||
| 8804 | ***********************************************************************/ | ||
| 8805 | |||
| 8806 | #ifdef MAC_OS8 | ||
| 8807 | extern void init_emacs_passwd_dir (); | ||
| 8808 | extern int emacs_main (int, char **, char **); | ||
| 8809 | |||
| 8810 | extern void initialize_applescript(); | ||
| 8811 | extern void terminate_applescript(); | ||
| 8812 | |||
| 8813 | static void | ||
| 8814 | do_get_menus (void) | ||
| 8815 | { | ||
| 8816 | Handle menubar_handle; | ||
| 8817 | MenuRef menu; | ||
| 8818 | |||
| 8819 | menubar_handle = GetNewMBar (128); | ||
| 8820 | if(menubar_handle == NULL) | ||
| 8821 | abort (); | ||
| 8822 | SetMenuBar (menubar_handle); | ||
| 8823 | DrawMenuBar (); | ||
| 8824 | |||
| 8825 | #if !TARGET_API_MAC_CARBON | ||
| 8826 | menu = GetMenuRef (M_APPLE); | ||
| 8827 | if (menu != NULL) | ||
| 8828 | AppendResMenu (menu, 'DRVR'); | ||
| 8829 | else | ||
| 8830 | abort (); | ||
| 8831 | #endif | ||
| 8832 | } | ||
| 8833 | |||
| 8834 | static void | ||
| 8835 | do_init_managers (void) | ||
| 8836 | { | ||
| 8837 | #if !TARGET_API_MAC_CARBON | ||
| 8838 | InitGraf (&qd.thePort); | ||
| 8839 | InitFonts (); | ||
| 8840 | FlushEvents (everyEvent, 0); | ||
| 8841 | InitWindows (); | ||
| 8842 | InitMenus (); | ||
| 8843 | TEInit (); | ||
| 8844 | InitDialogs (NULL); | ||
| 8845 | #endif /* !TARGET_API_MAC_CARBON */ | ||
| 8846 | InitCursor (); | ||
| 8847 | |||
| 8848 | #if !TARGET_API_MAC_CARBON | ||
| 8849 | /* set up some extra stack space for use by emacs */ | ||
| 8850 | SetApplLimit ((Ptr) ((long) GetApplLimit () - EXTRA_STACK_ALLOC)); | ||
| 8851 | |||
| 8852 | /* MaxApplZone must be called for AppleScript to execute more | ||
| 8853 | complicated scripts */ | ||
| 8854 | MaxApplZone (); | ||
| 8855 | MoreMasters (); | ||
| 8856 | #endif /* !TARGET_API_MAC_CARBON */ | ||
| 8857 | } | ||
| 8858 | |||
| 8859 | static void | ||
| 8860 | do_check_ram_size (void) | ||
| 8861 | { | ||
| 8862 | SInt32 physical_ram_size, logical_ram_size; | ||
| 8863 | |||
| 8864 | if (Gestalt (gestaltPhysicalRAMSize, &physical_ram_size) != noErr | ||
| 8865 | || Gestalt (gestaltLogicalRAMSize, &logical_ram_size) != noErr | ||
| 8866 | || physical_ram_size > (1 << VALBITS) | ||
| 8867 | || logical_ram_size > (1 << VALBITS)) | ||
| 8868 | { | ||
| 8869 | StopAlert (RAM_TOO_LARGE_ALERT_ID, NULL); | ||
| 8870 | exit (1); | ||
| 8871 | } | ||
| 8872 | } | ||
| 11587 | 8873 | ||
| 11588 | #if __profile__ | 8874 | #if __profile__ |
| 11589 | void | 8875 | void |
| @@ -11608,7 +8894,6 @@ profiler_exit_proc () | |||
| 11608 | (defined further below) to read input. This is where | 8894 | (defined further below) to read input. This is where |
| 11609 | WaitNextEvent/ReceiveNextEvent is called to process Mac events. */ | 8895 | WaitNextEvent/ReceiveNextEvent is called to process Mac events. */ |
| 11610 | 8896 | ||
| 11611 | #ifdef MAC_OS8 | ||
| 11612 | #undef main | 8897 | #undef main |
| 11613 | int | 8898 | int |
| 11614 | main (void) | 8899 | main (void) |
| @@ -11667,755 +8952,6 @@ main (void) | |||
| 11667 | /* Never reached - real exit in Fkill_emacs */ | 8952 | /* Never reached - real exit in Fkill_emacs */ |
| 11668 | return 0; | 8953 | return 0; |
| 11669 | } | 8954 | } |
| 11670 | #endif | ||
| 11671 | |||
| 11672 | #if !TARGET_API_MAC_CARBON | ||
| 11673 | static RgnHandle mouse_region = NULL; | ||
| 11674 | |||
| 11675 | Boolean | ||
| 11676 | mac_wait_next_event (er, sleep_time, dequeue) | ||
| 11677 | EventRecord *er; | ||
| 11678 | UInt32 sleep_time; | ||
| 11679 | Boolean dequeue; | ||
| 11680 | { | ||
| 11681 | static EventRecord er_buf = {nullEvent}; | ||
| 11682 | UInt32 target_tick, current_tick; | ||
| 11683 | EventMask event_mask; | ||
| 11684 | |||
| 11685 | if (mouse_region == NULL) | ||
| 11686 | mouse_region = NewRgn (); | ||
| 11687 | |||
| 11688 | event_mask = everyEvent; | ||
| 11689 | if (!mac_ready_for_apple_events) | ||
| 11690 | event_mask -= highLevelEventMask; | ||
| 11691 | |||
| 11692 | current_tick = TickCount (); | ||
| 11693 | target_tick = current_tick + sleep_time; | ||
| 11694 | |||
| 11695 | if (er_buf.what == nullEvent) | ||
| 11696 | while (!WaitNextEvent (event_mask, &er_buf, | ||
| 11697 | target_tick - current_tick, mouse_region)) | ||
| 11698 | { | ||
| 11699 | current_tick = TickCount (); | ||
| 11700 | if (target_tick <= current_tick) | ||
| 11701 | return false; | ||
| 11702 | } | ||
| 11703 | |||
| 11704 | *er = er_buf; | ||
| 11705 | if (dequeue) | ||
| 11706 | er_buf.what = nullEvent; | ||
| 11707 | return true; | ||
| 11708 | } | ||
| 11709 | #endif /* not TARGET_API_MAC_CARBON */ | ||
| 11710 | |||
| 11711 | #if TARGET_API_MAC_CARBON | ||
| 11712 | OSStatus | ||
| 11713 | mac_post_mouse_moved_event () | ||
| 11714 | { | ||
| 11715 | EventRef event = NULL; | ||
| 11716 | OSStatus err; | ||
| 11717 | |||
| 11718 | err = CreateEvent (NULL, kEventClassMouse, kEventMouseMoved, 0, | ||
| 11719 | kEventAttributeNone, &event); | ||
| 11720 | if (err == noErr) | ||
| 11721 | { | ||
| 11722 | Point mouse_pos; | ||
| 11723 | |||
| 11724 | GetGlobalMouse (&mouse_pos); | ||
| 11725 | err = SetEventParameter (event, kEventParamMouseLocation, typeQDPoint, | ||
| 11726 | sizeof (Point), &mouse_pos); | ||
| 11727 | } | ||
| 11728 | if (err == noErr) | ||
| 11729 | { | ||
| 11730 | UInt32 modifiers = GetCurrentKeyModifiers (); | ||
| 11731 | |||
| 11732 | err = SetEventParameter (event, kEventParamKeyModifiers, typeUInt32, | ||
| 11733 | sizeof (UInt32), &modifiers); | ||
| 11734 | } | ||
| 11735 | if (err == noErr) | ||
| 11736 | err = PostEventToQueue (GetCurrentEventQueue (), event, | ||
| 11737 | kEventPriorityStandard); | ||
| 11738 | if (event) | ||
| 11739 | ReleaseEvent (event); | ||
| 11740 | |||
| 11741 | return err; | ||
| 11742 | } | ||
| 11743 | #endif | ||
| 11744 | |||
| 11745 | /* Emacs calls this whenever it wants to read an input event from the | ||
| 11746 | user. */ | ||
| 11747 | int | ||
| 11748 | XTread_socket (sd, expected, hold_quit) | ||
| 11749 | int sd, expected; | ||
| 11750 | struct input_event *hold_quit; | ||
| 11751 | { | ||
| 11752 | struct input_event inev; | ||
| 11753 | int count = 0; | ||
| 11754 | #if TARGET_API_MAC_CARBON | ||
| 11755 | EventRef eventRef; | ||
| 11756 | EventTargetRef toolbox_dispatcher; | ||
| 11757 | #endif | ||
| 11758 | EventRecord er; | ||
| 11759 | struct mac_display_info *dpyinfo = &one_mac_display_info; | ||
| 11760 | |||
| 11761 | if (interrupt_input_blocked) | ||
| 11762 | { | ||
| 11763 | interrupt_input_pending = 1; | ||
| 11764 | return -1; | ||
| 11765 | } | ||
| 11766 | |||
| 11767 | interrupt_input_pending = 0; | ||
| 11768 | BLOCK_INPUT; | ||
| 11769 | |||
| 11770 | /* So people can tell when we have read the available input. */ | ||
| 11771 | input_signal_count++; | ||
| 11772 | |||
| 11773 | ++handling_signal; | ||
| 11774 | |||
| 11775 | #if TARGET_API_MAC_CARBON | ||
| 11776 | toolbox_dispatcher = GetEventDispatcherTarget (); | ||
| 11777 | |||
| 11778 | while ( | ||
| 11779 | #if USE_CG_DRAWING | ||
| 11780 | mac_prepare_for_quickdraw (NULL), | ||
| 11781 | #endif | ||
| 11782 | !ReceiveNextEvent (0, NULL, kEventDurationNoWait, | ||
| 11783 | kEventRemoveFromQueue, &eventRef)) | ||
| 11784 | #else /* !TARGET_API_MAC_CARBON */ | ||
| 11785 | while (mac_wait_next_event (&er, 0, true)) | ||
| 11786 | #endif /* !TARGET_API_MAC_CARBON */ | ||
| 11787 | { | ||
| 11788 | int do_help = 0; | ||
| 11789 | struct frame *f; | ||
| 11790 | unsigned long timestamp; | ||
| 11791 | |||
| 11792 | EVENT_INIT (inev); | ||
| 11793 | inev.kind = NO_EVENT; | ||
| 11794 | inev.arg = Qnil; | ||
| 11795 | |||
| 11796 | #if TARGET_API_MAC_CARBON | ||
| 11797 | timestamp = GetEventTime (eventRef) / kEventDurationMillisecond; | ||
| 11798 | |||
| 11799 | if (!mac_convert_event_ref (eventRef, &er)) | ||
| 11800 | goto OTHER; | ||
| 11801 | #else /* !TARGET_API_MAC_CARBON */ | ||
| 11802 | timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ | ||
| 11803 | #endif /* !TARGET_API_MAC_CARBON */ | ||
| 11804 | |||
| 11805 | switch (er.what) | ||
| 11806 | { | ||
| 11807 | case mouseDown: | ||
| 11808 | case mouseUp: | ||
| 11809 | { | ||
| 11810 | WindowRef window_ptr; | ||
| 11811 | ControlPartCode part_code; | ||
| 11812 | int tool_bar_p = 0; | ||
| 11813 | |||
| 11814 | #if TARGET_API_MAC_CARBON | ||
| 11815 | OSStatus err; | ||
| 11816 | |||
| 11817 | /* This is needed to send mouse events like aqua window | ||
| 11818 | buttons to the correct handler. */ | ||
| 11819 | read_socket_inev = &inev; | ||
| 11820 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); | ||
| 11821 | read_socket_inev = NULL; | ||
| 11822 | if (err != eventNotHandledErr) | ||
| 11823 | break; | ||
| 11824 | #endif | ||
| 11825 | last_mouse_glyph_frame = 0; | ||
| 11826 | |||
| 11827 | if (dpyinfo->grabbed && last_mouse_frame | ||
| 11828 | && FRAME_LIVE_P (last_mouse_frame)) | ||
| 11829 | { | ||
| 11830 | window_ptr = FRAME_MAC_WINDOW (last_mouse_frame); | ||
| 11831 | part_code = inContent; | ||
| 11832 | } | ||
| 11833 | else | ||
| 11834 | { | ||
| 11835 | part_code = FindWindow (er.where, &window_ptr); | ||
| 11836 | if (tip_window && window_ptr == tip_window) | ||
| 11837 | { | ||
| 11838 | HideWindow (tip_window); | ||
| 11839 | part_code = FindWindow (er.where, &window_ptr); | ||
| 11840 | } | ||
| 11841 | } | ||
| 11842 | |||
| 11843 | if (er.what != mouseDown && | ||
| 11844 | (part_code != inContent || dpyinfo->grabbed == 0)) | ||
| 11845 | break; | ||
| 11846 | |||
| 11847 | switch (part_code) | ||
| 11848 | { | ||
| 11849 | case inMenuBar: | ||
| 11850 | f = mac_focus_frame (dpyinfo); | ||
| 11851 | saved_menu_event_location = er.where; | ||
| 11852 | inev.kind = MENU_BAR_ACTIVATE_EVENT; | ||
| 11853 | XSETFRAME (inev.frame_or_window, f); | ||
| 11854 | break; | ||
| 11855 | |||
| 11856 | case inContent: | ||
| 11857 | if ( | ||
| 11858 | #if TARGET_API_MAC_CARBON | ||
| 11859 | FrontNonFloatingWindow () | ||
| 11860 | #else | ||
| 11861 | FrontWindow () | ||
| 11862 | #endif | ||
| 11863 | != window_ptr | ||
| 11864 | || (mac_window_to_frame (window_ptr) | ||
| 11865 | != dpyinfo->x_focus_frame)) | ||
| 11866 | SelectWindow (window_ptr); | ||
| 11867 | else | ||
| 11868 | { | ||
| 11869 | ControlPartCode control_part_code; | ||
| 11870 | ControlRef ch; | ||
| 11871 | Point mouse_loc; | ||
| 11872 | #ifdef MAC_OSX | ||
| 11873 | ControlKind control_kind; | ||
| 11874 | #endif | ||
| 11875 | |||
| 11876 | f = mac_window_to_frame (window_ptr); | ||
| 11877 | /* convert to local coordinates of new window */ | ||
| 11878 | mouse_loc.h = (er.where.h | ||
| 11879 | - (f->left_pos | ||
| 11880 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); | ||
| 11881 | mouse_loc.v = (er.where.v | ||
| 11882 | - (f->top_pos | ||
| 11883 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 11884 | #if TARGET_API_MAC_CARBON | ||
| 11885 | ch = FindControlUnderMouse (mouse_loc, window_ptr, | ||
| 11886 | &control_part_code); | ||
| 11887 | #ifdef MAC_OSX | ||
| 11888 | if (ch) | ||
| 11889 | GetControlKind (ch, &control_kind); | ||
| 11890 | #endif | ||
| 11891 | #else | ||
| 11892 | control_part_code = FindControl (mouse_loc, window_ptr, | ||
| 11893 | &ch); | ||
| 11894 | #endif | ||
| 11895 | |||
| 11896 | #if TARGET_API_MAC_CARBON | ||
| 11897 | inev.code = mac_get_mouse_btn (eventRef); | ||
| 11898 | inev.modifiers = mac_event_to_emacs_modifiers (eventRef); | ||
| 11899 | #else | ||
| 11900 | inev.code = mac_get_emulated_btn (er.modifiers); | ||
| 11901 | inev.modifiers = mac_to_emacs_modifiers (er.modifiers, 0); | ||
| 11902 | #endif | ||
| 11903 | XSETINT (inev.x, mouse_loc.h); | ||
| 11904 | XSETINT (inev.y, mouse_loc.v); | ||
| 11905 | |||
| 11906 | if ((dpyinfo->grabbed && tracked_scroll_bar) | ||
| 11907 | || (ch != 0 | ||
| 11908 | #ifndef USE_TOOLKIT_SCROLL_BARS | ||
| 11909 | /* control_part_code becomes kControlNoPart if | ||
| 11910 | a progress indicator is clicked. */ | ||
| 11911 | && control_part_code != kControlNoPart | ||
| 11912 | #else /* USE_TOOLKIT_SCROLL_BARS */ | ||
| 11913 | #ifdef MAC_OSX | ||
| 11914 | && control_kind.kind == kControlKindScrollBar | ||
| 11915 | #endif /* MAC_OSX */ | ||
| 11916 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | ||
| 11917 | )) | ||
| 11918 | { | ||
| 11919 | struct scroll_bar *bar; | ||
| 11920 | |||
| 11921 | if (dpyinfo->grabbed && tracked_scroll_bar) | ||
| 11922 | { | ||
| 11923 | bar = tracked_scroll_bar; | ||
| 11924 | #ifndef USE_TOOLKIT_SCROLL_BARS | ||
| 11925 | control_part_code = kControlIndicatorPart; | ||
| 11926 | #endif | ||
| 11927 | } | ||
| 11928 | else | ||
| 11929 | bar = (struct scroll_bar *) GetControlReference (ch); | ||
| 11930 | #ifdef USE_TOOLKIT_SCROLL_BARS | ||
| 11931 | /* Make the "Ctrl-Mouse-2 splits window" work | ||
| 11932 | for toolkit scroll bars. */ | ||
| 11933 | if (inev.modifiers & ctrl_modifier) | ||
| 11934 | x_scroll_bar_handle_click (bar, control_part_code, | ||
| 11935 | &er, &inev); | ||
| 11936 | else if (er.what == mouseDown) | ||
| 11937 | x_scroll_bar_handle_press (bar, control_part_code, | ||
| 11938 | mouse_loc, &inev); | ||
| 11939 | else | ||
| 11940 | x_scroll_bar_handle_release (bar, &inev); | ||
| 11941 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | ||
| 11942 | x_scroll_bar_handle_click (bar, control_part_code, | ||
| 11943 | &er, &inev); | ||
| 11944 | if (er.what == mouseDown | ||
| 11945 | && control_part_code == kControlIndicatorPart) | ||
| 11946 | tracked_scroll_bar = bar; | ||
| 11947 | else | ||
| 11948 | tracked_scroll_bar = NULL; | ||
| 11949 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ | ||
| 11950 | } | ||
| 11951 | else | ||
| 11952 | { | ||
| 11953 | Lisp_Object window; | ||
| 11954 | int x = mouse_loc.h; | ||
| 11955 | int y = mouse_loc.v; | ||
| 11956 | |||
| 11957 | window = window_from_coordinates (f, x, y, 0, 0, 0, 1); | ||
| 11958 | if (EQ (window, f->tool_bar_window)) | ||
| 11959 | { | ||
| 11960 | if (er.what == mouseDown) | ||
| 11961 | handle_tool_bar_click (f, x, y, 1, 0); | ||
| 11962 | else | ||
| 11963 | handle_tool_bar_click (f, x, y, 0, | ||
| 11964 | inev.modifiers); | ||
| 11965 | tool_bar_p = 1; | ||
| 11966 | } | ||
| 11967 | else | ||
| 11968 | { | ||
| 11969 | XSETFRAME (inev.frame_or_window, f); | ||
| 11970 | inev.kind = MOUSE_CLICK_EVENT; | ||
| 11971 | } | ||
| 11972 | } | ||
| 11973 | |||
| 11974 | if (er.what == mouseDown) | ||
| 11975 | { | ||
| 11976 | dpyinfo->grabbed |= (1 << inev.code); | ||
| 11977 | last_mouse_frame = f; | ||
| 11978 | |||
| 11979 | if (!tool_bar_p) | ||
| 11980 | last_tool_bar_item = -1; | ||
| 11981 | } | ||
| 11982 | else | ||
| 11983 | { | ||
| 11984 | if ((dpyinfo->grabbed & (1 << inev.code)) == 0) | ||
| 11985 | /* If a button is released though it was not | ||
| 11986 | previously pressed, that would be because | ||
| 11987 | of multi-button emulation. */ | ||
| 11988 | dpyinfo->grabbed = 0; | ||
| 11989 | else | ||
| 11990 | dpyinfo->grabbed &= ~(1 << inev.code); | ||
| 11991 | } | ||
| 11992 | |||
| 11993 | /* Ignore any mouse motion that happened before | ||
| 11994 | this event; any subsequent mouse-movement Emacs | ||
| 11995 | events should reflect only motion after the | ||
| 11996 | ButtonPress. */ | ||
| 11997 | if (f != 0) | ||
| 11998 | f->mouse_moved = 0; | ||
| 11999 | |||
| 12000 | #ifdef USE_TOOLKIT_SCROLL_BARS | ||
| 12001 | if (inev.kind == MOUSE_CLICK_EVENT | ||
| 12002 | || (inev.kind == SCROLL_BAR_CLICK_EVENT | ||
| 12003 | && (inev.modifiers & ctrl_modifier))) | ||
| 12004 | #endif | ||
| 12005 | switch (er.what) | ||
| 12006 | { | ||
| 12007 | case mouseDown: | ||
| 12008 | inev.modifiers |= down_modifier; | ||
| 12009 | break; | ||
| 12010 | case mouseUp: | ||
| 12011 | inev.modifiers |= up_modifier; | ||
| 12012 | break; | ||
| 12013 | } | ||
| 12014 | } | ||
| 12015 | break; | ||
| 12016 | |||
| 12017 | case inDrag: | ||
| 12018 | #if TARGET_API_MAC_CARBON | ||
| 12019 | case inProxyIcon: | ||
| 12020 | if (IsWindowPathSelectClick (window_ptr, &er)) | ||
| 12021 | { | ||
| 12022 | WindowPathSelect (window_ptr, NULL, NULL); | ||
| 12023 | break; | ||
| 12024 | } | ||
| 12025 | if (part_code == inProxyIcon | ||
| 12026 | && (TrackWindowProxyDrag (window_ptr, er.where) | ||
| 12027 | != errUserWantsToDragWindow)) | ||
| 12028 | break; | ||
| 12029 | DragWindow (window_ptr, er.where, NULL); | ||
| 12030 | #else /* not TARGET_API_MAC_CARBON */ | ||
| 12031 | DragWindow (window_ptr, er.where, &qd.screenBits.bounds); | ||
| 12032 | /* Update the frame parameters. */ | ||
| 12033 | { | ||
| 12034 | struct frame *f = mac_window_to_frame (window_ptr); | ||
| 12035 | |||
| 12036 | if (f && !f->async_iconified) | ||
| 12037 | mac_handle_origin_change (f); | ||
| 12038 | } | ||
| 12039 | #endif /* not TARGET_API_MAC_CARBON */ | ||
| 12040 | break; | ||
| 12041 | |||
| 12042 | case inGoAway: | ||
| 12043 | if (TrackGoAway (window_ptr, er.where)) | ||
| 12044 | { | ||
| 12045 | inev.kind = DELETE_WINDOW_EVENT; | ||
| 12046 | XSETFRAME (inev.frame_or_window, | ||
| 12047 | mac_window_to_frame (window_ptr)); | ||
| 12048 | } | ||
| 12049 | break; | ||
| 12050 | |||
| 12051 | /* window resize handling added --ben */ | ||
| 12052 | case inGrow: | ||
| 12053 | do_grow_window (window_ptr, &er); | ||
| 12054 | break; | ||
| 12055 | |||
| 12056 | /* window zoom handling added --ben */ | ||
| 12057 | case inZoomIn: | ||
| 12058 | case inZoomOut: | ||
| 12059 | if (TrackBox (window_ptr, er.where, part_code)) | ||
| 12060 | do_zoom_window (window_ptr, part_code); | ||
| 12061 | break; | ||
| 12062 | |||
| 12063 | #if USE_MAC_TOOLBAR | ||
| 12064 | case inStructure: | ||
| 12065 | { | ||
| 12066 | OSStatus err; | ||
| 12067 | HIViewRef ch; | ||
| 12068 | |||
| 12069 | err = HIViewGetViewForMouseEvent (HIViewGetRoot (window_ptr), | ||
| 12070 | eventRef, &ch); | ||
| 12071 | /* This doesn't work on Mac OS X 10.2. */ | ||
| 12072 | if (err == noErr) | ||
| 12073 | HIViewClick (ch, eventRef); | ||
| 12074 | } | ||
| 12075 | break; | ||
| 12076 | #endif /* USE_MAC_TOOLBAR */ | ||
| 12077 | |||
| 12078 | default: | ||
| 12079 | break; | ||
| 12080 | } | ||
| 12081 | } | ||
| 12082 | break; | ||
| 12083 | |||
| 12084 | #if !TARGET_API_MAC_CARBON | ||
| 12085 | case updateEvt: | ||
| 12086 | do_window_update ((WindowRef) er.message); | ||
| 12087 | break; | ||
| 12088 | #endif | ||
| 12089 | |||
| 12090 | case osEvt: | ||
| 12091 | #if TARGET_API_MAC_CARBON | ||
| 12092 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | ||
| 12093 | != eventNotHandledErr) | ||
| 12094 | break; | ||
| 12095 | #endif | ||
| 12096 | switch ((er.message >> 24) & 0x000000FF) | ||
| 12097 | { | ||
| 12098 | #if USE_MAC_TSM | ||
| 12099 | case suspendResumeMessage: | ||
| 12100 | if (er.message & resumeFlag) | ||
| 12101 | mac_tsm_resume (); | ||
| 12102 | else | ||
| 12103 | mac_tsm_suspend (); | ||
| 12104 | break; | ||
| 12105 | #endif | ||
| 12106 | |||
| 12107 | case mouseMovedMessage: | ||
| 12108 | #if !TARGET_API_MAC_CARBON | ||
| 12109 | SetRectRgn (mouse_region, er.where.h, er.where.v, | ||
| 12110 | er.where.h + 1, er.where.v + 1); | ||
| 12111 | #endif | ||
| 12112 | previous_help_echo_string = help_echo_string; | ||
| 12113 | help_echo_string = Qnil; | ||
| 12114 | |||
| 12115 | if (dpyinfo->grabbed && last_mouse_frame | ||
| 12116 | && FRAME_LIVE_P (last_mouse_frame)) | ||
| 12117 | f = last_mouse_frame; | ||
| 12118 | else | ||
| 12119 | f = dpyinfo->x_focus_frame; | ||
| 12120 | |||
| 12121 | if (dpyinfo->mouse_face_hidden) | ||
| 12122 | { | ||
| 12123 | dpyinfo->mouse_face_hidden = 0; | ||
| 12124 | clear_mouse_face (dpyinfo); | ||
| 12125 | } | ||
| 12126 | |||
| 12127 | if (f) | ||
| 12128 | { | ||
| 12129 | WindowRef wp = FRAME_MAC_WINDOW (f); | ||
| 12130 | Point mouse_pos; | ||
| 12131 | |||
| 12132 | mouse_pos.h = (er.where.h | ||
| 12133 | - (f->left_pos | ||
| 12134 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); | ||
| 12135 | mouse_pos.v = (er.where.v | ||
| 12136 | - (f->top_pos | ||
| 12137 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 12138 | if (dpyinfo->grabbed && tracked_scroll_bar) | ||
| 12139 | #ifdef USE_TOOLKIT_SCROLL_BARS | ||
| 12140 | x_scroll_bar_handle_drag (wp, tracked_scroll_bar, | ||
| 12141 | mouse_pos, &inev); | ||
| 12142 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | ||
| 12143 | x_scroll_bar_note_movement (tracked_scroll_bar, | ||
| 12144 | mouse_pos.v | ||
| 12145 | - XINT (tracked_scroll_bar->top), | ||
| 12146 | er.when * (1000 / 60)); | ||
| 12147 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ | ||
| 12148 | else | ||
| 12149 | { | ||
| 12150 | /* Generate SELECT_WINDOW_EVENTs when needed. */ | ||
| 12151 | if (!NILP (Vmouse_autoselect_window)) | ||
| 12152 | { | ||
| 12153 | Lisp_Object window; | ||
| 12154 | |||
| 12155 | window = window_from_coordinates (f, | ||
| 12156 | mouse_pos.h, | ||
| 12157 | mouse_pos.v, | ||
| 12158 | 0, 0, 0, 0); | ||
| 12159 | |||
| 12160 | /* Window will be selected only when it is | ||
| 12161 | not selected now and last mouse movement | ||
| 12162 | event was not in it. Minibuffer window | ||
| 12163 | will be selected only when it is active. */ | ||
| 12164 | if (WINDOWP (window) | ||
| 12165 | && !EQ (window, last_window) | ||
| 12166 | && !EQ (window, selected_window) | ||
| 12167 | /* For click-to-focus window managers | ||
| 12168 | create event iff we don't leave the | ||
| 12169 | selected frame. */ | ||
| 12170 | && (focus_follows_mouse | ||
| 12171 | || (EQ (XWINDOW (window)->frame, | ||
| 12172 | XWINDOW (selected_window)->frame)))) | ||
| 12173 | { | ||
| 12174 | inev.kind = SELECT_WINDOW_EVENT; | ||
| 12175 | inev.frame_or_window = window; | ||
| 12176 | } | ||
| 12177 | |||
| 12178 | last_window=window; | ||
| 12179 | } | ||
| 12180 | if (!note_mouse_movement (f, &mouse_pos)) | ||
| 12181 | help_echo_string = previous_help_echo_string; | ||
| 12182 | #if USE_MAC_TOOLBAR | ||
| 12183 | else | ||
| 12184 | mac_tool_bar_note_mouse_movement (f, eventRef); | ||
| 12185 | #endif | ||
| 12186 | } | ||
| 12187 | } | ||
| 12188 | |||
| 12189 | /* If the contents of the global variable | ||
| 12190 | help_echo_string has changed, generate a | ||
| 12191 | HELP_EVENT. */ | ||
| 12192 | if (!NILP (help_echo_string) || !NILP (previous_help_echo_string)) | ||
| 12193 | do_help = 1; | ||
| 12194 | break; | ||
| 12195 | } | ||
| 12196 | break; | ||
| 12197 | |||
| 12198 | case activateEvt: | ||
| 12199 | { | ||
| 12200 | WindowRef window_ptr = (WindowRef) er.message; | ||
| 12201 | OSErr err; | ||
| 12202 | ControlRef root_control; | ||
| 12203 | |||
| 12204 | if (window_ptr == tip_window) | ||
| 12205 | { | ||
| 12206 | HideWindow (tip_window); | ||
| 12207 | break; | ||
| 12208 | } | ||
| 12209 | |||
| 12210 | if (!is_emacs_window (window_ptr)) | ||
| 12211 | goto OTHER; | ||
| 12212 | |||
| 12213 | f = mac_window_to_frame (window_ptr); | ||
| 12214 | |||
| 12215 | if ((er.modifiers & activeFlag) != 0) | ||
| 12216 | { | ||
| 12217 | /* A window has been activated */ | ||
| 12218 | Point mouse_loc; | ||
| 12219 | |||
| 12220 | err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control); | ||
| 12221 | if (err == noErr) | ||
| 12222 | ActivateControl (root_control); | ||
| 12223 | |||
| 12224 | x_detect_focus_change (dpyinfo, &er, &inev); | ||
| 12225 | |||
| 12226 | mouse_loc.h = (er.where.h | ||
| 12227 | - (f->left_pos | ||
| 12228 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); | ||
| 12229 | mouse_loc.v = (er.where.v | ||
| 12230 | - (f->top_pos | ||
| 12231 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 12232 | /* Window-activated event counts as mouse movement, | ||
| 12233 | so update things that depend on mouse position. */ | ||
| 12234 | note_mouse_movement (f, &mouse_loc); | ||
| 12235 | } | ||
| 12236 | else | ||
| 12237 | { | ||
| 12238 | /* A window has been deactivated */ | ||
| 12239 | err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control); | ||
| 12240 | if (err == noErr) | ||
| 12241 | DeactivateControl (root_control); | ||
| 12242 | |||
| 12243 | #ifdef USE_TOOLKIT_SCROLL_BARS | ||
| 12244 | if (dpyinfo->grabbed && tracked_scroll_bar) | ||
| 12245 | { | ||
| 12246 | struct input_event event; | ||
| 12247 | |||
| 12248 | EVENT_INIT (event); | ||
| 12249 | event.kind = NO_EVENT; | ||
| 12250 | x_scroll_bar_handle_release (tracked_scroll_bar, &event); | ||
| 12251 | if (event.kind != NO_EVENT) | ||
| 12252 | { | ||
| 12253 | event.timestamp = timestamp; | ||
| 12254 | kbd_buffer_store_event_hold (&event, hold_quit); | ||
| 12255 | count++; | ||
| 12256 | } | ||
| 12257 | } | ||
| 12258 | #endif | ||
| 12259 | dpyinfo->grabbed = 0; | ||
| 12260 | |||
| 12261 | x_detect_focus_change (dpyinfo, &er, &inev); | ||
| 12262 | |||
| 12263 | if (f == dpyinfo->mouse_face_mouse_frame) | ||
| 12264 | { | ||
| 12265 | /* If we move outside the frame, then we're | ||
| 12266 | certainly no longer on any text in the | ||
| 12267 | frame. */ | ||
| 12268 | clear_mouse_face (dpyinfo); | ||
| 12269 | dpyinfo->mouse_face_mouse_frame = 0; | ||
| 12270 | } | ||
| 12271 | |||
| 12272 | /* Generate a nil HELP_EVENT to cancel a help-echo. | ||
| 12273 | Do it only if there's something to cancel. | ||
| 12274 | Otherwise, the startup message is cleared when the | ||
| 12275 | mouse leaves the frame. */ | ||
| 12276 | if (any_help_event_p) | ||
| 12277 | do_help = -1; | ||
| 12278 | } | ||
| 12279 | } | ||
| 12280 | break; | ||
| 12281 | |||
| 12282 | case keyDown: | ||
| 12283 | case keyUp: | ||
| 12284 | case autoKey: | ||
| 12285 | ObscureCursor (); | ||
| 12286 | |||
| 12287 | f = mac_focus_frame (dpyinfo); | ||
| 12288 | XSETFRAME (inev.frame_or_window, f); | ||
| 12289 | |||
| 12290 | /* If mouse-highlight is an integer, input clears out mouse | ||
| 12291 | highlighting. */ | ||
| 12292 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight) | ||
| 12293 | && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)) | ||
| 12294 | { | ||
| 12295 | clear_mouse_face (dpyinfo); | ||
| 12296 | dpyinfo->mouse_face_hidden = 1; | ||
| 12297 | } | ||
| 12298 | |||
| 12299 | { | ||
| 12300 | UInt32 modifiers = er.modifiers, mapped_modifiers; | ||
| 12301 | UInt32 key_code = (er.message & keyCodeMask) >> 8; | ||
| 12302 | |||
| 12303 | #ifdef MAC_OSX | ||
| 12304 | GetEventParameter (eventRef, kEventParamKeyModifiers, | ||
| 12305 | typeUInt32, NULL, | ||
| 12306 | sizeof (UInt32), NULL, &modifiers); | ||
| 12307 | #endif | ||
| 12308 | mapped_modifiers = mac_mapped_modifiers (modifiers, key_code); | ||
| 12309 | |||
| 12310 | #if TARGET_API_MAC_CARBON | ||
| 12311 | if (!(mapped_modifiers | ||
| 12312 | & ~(mac_pass_command_to_system ? cmdKey : 0) | ||
| 12313 | & ~(mac_pass_control_to_system ? controlKey : 0))) | ||
| 12314 | goto OTHER; | ||
| 12315 | else | ||
| 12316 | #endif | ||
| 12317 | if (er.what != keyUp) | ||
| 12318 | do_keystroke (er.what, er.message & charCodeMask, | ||
| 12319 | key_code, modifiers, timestamp, &inev); | ||
| 12320 | } | ||
| 12321 | break; | ||
| 12322 | |||
| 12323 | case kHighLevelEvent: | ||
| 12324 | AEProcessAppleEvent (&er); | ||
| 12325 | break; | ||
| 12326 | |||
| 12327 | default: | ||
| 12328 | OTHER: | ||
| 12329 | #if TARGET_API_MAC_CARBON | ||
| 12330 | { | ||
| 12331 | OSStatus err; | ||
| 12332 | |||
| 12333 | read_socket_inev = &inev; | ||
| 12334 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); | ||
| 12335 | read_socket_inev = NULL; | ||
| 12336 | } | ||
| 12337 | #endif | ||
| 12338 | break; | ||
| 12339 | } | ||
| 12340 | #if TARGET_API_MAC_CARBON | ||
| 12341 | ReleaseEvent (eventRef); | ||
| 12342 | #endif | ||
| 12343 | |||
| 12344 | if (inev.kind != NO_EVENT) | ||
| 12345 | { | ||
| 12346 | inev.timestamp = timestamp; | ||
| 12347 | kbd_buffer_store_event_hold (&inev, hold_quit); | ||
| 12348 | count++; | ||
| 12349 | } | ||
| 12350 | |||
| 12351 | if (do_help | ||
| 12352 | && !(hold_quit && hold_quit->kind != NO_EVENT)) | ||
| 12353 | { | ||
| 12354 | Lisp_Object frame; | ||
| 12355 | |||
| 12356 | if (f) | ||
| 12357 | XSETFRAME (frame, f); | ||
| 12358 | else | ||
| 12359 | frame = Qnil; | ||
| 12360 | |||
| 12361 | if (do_help > 0) | ||
| 12362 | { | ||
| 12363 | any_help_event_p = 1; | ||
| 12364 | gen_help_event (help_echo_string, frame, help_echo_window, | ||
| 12365 | help_echo_object, help_echo_pos); | ||
| 12366 | } | ||
| 12367 | else | ||
| 12368 | { | ||
| 12369 | help_echo_string = Qnil; | ||
| 12370 | gen_help_event (Qnil, frame, Qnil, Qnil, 0); | ||
| 12371 | } | ||
| 12372 | count++; | ||
| 12373 | } | ||
| 12374 | } | ||
| 12375 | |||
| 12376 | /* If the focus was just given to an autoraising frame, | ||
| 12377 | raise it now. */ | ||
| 12378 | /* ??? This ought to be able to handle more than one such frame. */ | ||
| 12379 | if (pending_autoraise_frame) | ||
| 12380 | { | ||
| 12381 | x_raise_frame (pending_autoraise_frame); | ||
| 12382 | pending_autoraise_frame = 0; | ||
| 12383 | } | ||
| 12384 | |||
| 12385 | if (mac_screen_config_changed) | ||
| 12386 | { | ||
| 12387 | mac_get_screen_info (dpyinfo); | ||
| 12388 | mac_screen_config_changed = 0; | ||
| 12389 | } | ||
| 12390 | |||
| 12391 | #if !TARGET_API_MAC_CARBON | ||
| 12392 | /* Check which frames are still visible. We do this here because | ||
| 12393 | there doesn't seem to be any direct notification from the Window | ||
| 12394 | Manager that the visibility of a window has changed (at least, | ||
| 12395 | not in all cases). */ | ||
| 12396 | { | ||
| 12397 | Lisp_Object tail, frame; | ||
| 12398 | |||
| 12399 | FOR_EACH_FRAME (tail, frame) | ||
| 12400 | { | ||
| 12401 | struct frame *f = XFRAME (frame); | ||
| 12402 | |||
| 12403 | /* The tooltip has been drawn already. Avoid the | ||
| 12404 | SET_FRAME_GARBAGED in mac_handle_visibility_change. */ | ||
| 12405 | if (EQ (frame, tip_frame)) | ||
| 12406 | continue; | ||
| 12407 | |||
| 12408 | if (FRAME_MAC_P (f)) | ||
| 12409 | mac_handle_visibility_change (f); | ||
| 12410 | } | ||
| 12411 | } | ||
| 12412 | #endif | ||
| 12413 | |||
| 12414 | --handling_signal; | ||
| 12415 | UNBLOCK_INPUT; | ||
| 12416 | return count; | ||
| 12417 | } | ||
| 12418 | |||
| 12419 | 8955 | ||
| 12420 | /* Need to override CodeWarrior's input function so no conversion is | 8956 | /* Need to override CodeWarrior's input function so no conversion is |
| 12421 | done on newlines Otherwise compiled functions in .elc files will be | 8957 | done on newlines Otherwise compiled functions in .elc files will be |
| @@ -12435,7 +8971,6 @@ __convert_from_newlines (unsigned char * p, size_t * n) | |||
| 12435 | } | 8971 | } |
| 12436 | #endif | 8972 | #endif |
| 12437 | 8973 | ||
| 12438 | #ifdef MAC_OS8 | ||
| 12439 | void | 8974 | void |
| 12440 | make_mac_terminal_frame (struct frame *f) | 8975 | make_mac_terminal_frame (struct frame *f) |
| 12441 | { | 8976 | { |
| @@ -12515,7 +9050,7 @@ make_mac_terminal_frame (struct frame *f) | |||
| 12515 | Fcons (Fcons (Qbackground_color, | 9050 | Fcons (Fcons (Qbackground_color, |
| 12516 | build_string ("white")), Qnil)); | 9051 | build_string ("white")), Qnil)); |
| 12517 | } | 9052 | } |
| 12518 | #endif | 9053 | #endif /* MAC_OS8 */ |
| 12519 | 9054 | ||
| 12520 | 9055 | ||
| 12521 | /*********************************************************************** | 9056 | /*********************************************************************** |
| @@ -12671,51 +9206,6 @@ x_delete_display (dpyinfo) | |||
| 12671 | } | 9206 | } |
| 12672 | 9207 | ||
| 12673 | 9208 | ||
| 12674 | static void | ||
| 12675 | init_menu_bar () | ||
| 12676 | { | ||
| 12677 | #ifdef MAC_OSX | ||
| 12678 | OSStatus err; | ||
| 12679 | MenuRef menu; | ||
| 12680 | MenuItemIndex menu_index; | ||
| 12681 | |||
| 12682 | err = GetIndMenuItemWithCommandID (NULL, kHICommandQuit, 1, | ||
| 12683 | &menu, &menu_index); | ||
| 12684 | if (err == noErr) | ||
| 12685 | SetMenuItemCommandKey (menu, menu_index, false, 0); | ||
| 12686 | EnableMenuCommand (NULL, kHICommandPreferences); | ||
| 12687 | err = GetIndMenuItemWithCommandID (NULL, kHICommandPreferences, 1, | ||
| 12688 | &menu, &menu_index); | ||
| 12689 | if (err == noErr) | ||
| 12690 | { | ||
| 12691 | SetMenuItemCommandKey (menu, menu_index, false, 0); | ||
| 12692 | InsertMenuItemTextWithCFString (menu, NULL, | ||
| 12693 | 0, kMenuItemAttrSeparator, 0); | ||
| 12694 | InsertMenuItemTextWithCFString (menu, CFSTR ("About Emacs"), | ||
| 12695 | 0, 0, kHICommandAbout); | ||
| 12696 | } | ||
| 12697 | #else /* !MAC_OSX */ | ||
| 12698 | #if TARGET_API_MAC_CARBON | ||
| 12699 | SetMenuItemCommandID (GetMenuRef (M_APPLE), I_ABOUT, kHICommandAbout); | ||
| 12700 | #endif | ||
| 12701 | #endif | ||
| 12702 | } | ||
| 12703 | |||
| 12704 | #if USE_MAC_TSM | ||
| 12705 | static void | ||
| 12706 | init_tsm () | ||
| 12707 | { | ||
| 12708 | #ifdef MAC_OSX | ||
| 12709 | static InterfaceTypeList types = {kUnicodeDocument}; | ||
| 12710 | #else | ||
| 12711 | static InterfaceTypeList types = {kTextService}; | ||
| 12712 | #endif | ||
| 12713 | |||
| 12714 | NewTSMDocument (sizeof (types) / sizeof (types[0]), types, | ||
| 12715 | &tsm_document_id, 0); | ||
| 12716 | } | ||
| 12717 | #endif | ||
| 12718 | |||
| 12719 | /* Set up use of X before we make the first connection. */ | 9209 | /* Set up use of X before we make the first connection. */ |
| 12720 | 9210 | ||
| 12721 | extern frame_parm_handler mac_frame_parm_handlers[]; | 9211 | extern frame_parm_handler mac_frame_parm_handlers[]; |
| @@ -12794,7 +9284,6 @@ mac_initialize () | |||
| 12794 | baud_rate = 19200; | 9284 | baud_rate = 19200; |
| 12795 | 9285 | ||
| 12796 | last_tool_bar_item = -1; | 9286 | last_tool_bar_item = -1; |
| 12797 | any_help_event_p = 0; | ||
| 12798 | 9287 | ||
| 12799 | /* Try to use interrupt input; if we can't, then start polling. */ | 9288 | /* Try to use interrupt input; if we can't, then start polling. */ |
| 12800 | Fset_input_mode (Qt, Qnil, Qt, Qnil); | 9289 | Fset_input_mode (Qt, Qnil, Qt, Qnil); |
| @@ -12802,22 +9291,17 @@ mac_initialize () | |||
| 12802 | BLOCK_INPUT; | 9291 | BLOCK_INPUT; |
| 12803 | 9292 | ||
| 12804 | #if TARGET_API_MAC_CARBON | 9293 | #if TARGET_API_MAC_CARBON |
| 12805 | |||
| 12806 | install_application_handler (); | ||
| 12807 | |||
| 12808 | init_menu_bar (); | ||
| 12809 | |||
| 12810 | #if USE_MAC_TSM | ||
| 12811 | init_tsm (); | ||
| 12812 | #endif | ||
| 12813 | |||
| 12814 | #ifdef MAC_OSX | 9294 | #ifdef MAC_OSX |
| 12815 | init_coercion_handler (); | 9295 | init_coercion_handler (); |
| 12816 | 9296 | ||
| 12817 | init_apple_event_handler (); | ||
| 12818 | |||
| 12819 | init_dm_notification_handler (); | 9297 | init_dm_notification_handler (); |
| 9298 | #endif | ||
| 9299 | |||
| 9300 | install_application_handler (); | ||
| 9301 | |||
| 9302 | mac_toolbox_initialize (); | ||
| 12820 | 9303 | ||
| 9304 | #ifdef MAC_OSX | ||
| 12821 | if (!inhibit_window_system) | 9305 | if (!inhibit_window_system) |
| 12822 | { | 9306 | { |
| 12823 | static const ProcessSerialNumber psn = {0, kCurrentProcess}; | 9307 | static const ProcessSerialNumber psn = {0, kCurrentProcess}; |