aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu2006-06-03 02:34:11 +0000
committerYAMAMOTO Mitsuharu2006-06-03 02:34:11 +0000
commit02236cbc8c55400fa78800065da0fb1e0ddd2ef0 (patch)
treebda7cb3f8ad39bff26323bb55bb27e04d97e5713 /src
parenta625bb4ef2f27aada39b6906c6de1b5d1f875ff9 (diff)
downloademacs-02236cbc8c55400fa78800065da0fb1e0ddd2ef0.tar.gz
emacs-02236cbc8c55400fa78800065da0fb1e0ddd2ef0.zip
(tsm_document_id) [USE_MAC_TSM]: New variable.
(Qtext_input, Qupdate_active_input_area, Qunicode_for_key_event) [USE_MAC_TSM]: Likewise. (syms_of_macterm) [USE_MAC_TSM]: Intern and staticpro them. (Qbefore_string) [USE_MAC_TSM]: Add extern. (do_app_resume, do_app_suspend) [USE_MAC_TSM]: Call ActivateTSMDocument/DeactivateTSMDocument. (mac_store_event_ref_as_apple_event): Call mac_post_mouse_moved_event. (mac_handle_window_event) [USE_MAC_TSM]: Handle kEventWindowFocusAcquired/kEventWindowFocusRelinquish. (mac_handle_text_input_event) [USE_MAC_TSM]: New function. (install_window_handler) [USE_MAC_TSM]: Install it. Register kEventWindowFocusAcquired/kEventWindowFocusRelinquish. (keycode_to_xkeysym_table): Add entry for f16. (XTread_socket) [USE_MAC_TSM]: Set/reset read_socket_inev before/after passing keystroke event to toolbox dispatcher. (init_tsm) [USE_MAC_TSM]: New function. (mac_initialize) [USE_MAC_TSM]: Call it. (Vmac_ts_active_input_overlay) [USE_MAC_TSM]: New defvar.
Diffstat (limited to 'src')
-rw-r--r--src/macterm.c272
1 files changed, 267 insertions, 5 deletions
diff --git a/src/macterm.c b/src/macterm.c
index 0d166595773..995422b90fc 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -8506,6 +8506,13 @@ static Lisp_Object Qtoolbar_switch_mode;
8506extern Lisp_Object Qfont; 8506extern Lisp_Object Qfont;
8507static Lisp_Object Qpanel_closed, Qselection; 8507static Lisp_Object Qpanel_closed, Qselection;
8508#endif 8508#endif
8509#if USE_MAC_TSM
8510static TSMDocumentID tsm_document_id;
8511static Lisp_Object Qtext_input;
8512static Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event;
8513static Lisp_Object Vmac_ts_active_input_overlay;
8514extern Lisp_Object Qbefore_string;
8515#endif
8509#endif 8516#endif
8510extern int mac_ready_for_apple_events; 8517extern int mac_ready_for_apple_events;
8511extern Lisp_Object Qundefined; 8518extern Lisp_Object Qundefined;
@@ -8857,13 +8864,17 @@ is_emacs_window (WindowPtr win)
8857static void 8864static void
8858do_app_resume () 8865do_app_resume ()
8859{ 8866{
8860 /* Window-activate events will do the job. */ 8867#if USE_MAC_TSM
8868 ActivateTSMDocument (tsm_document_id);
8869#endif
8861} 8870}
8862 8871
8863static void 8872static void
8864do_app_suspend () 8873do_app_suspend ()
8865{ 8874{
8866 /* Window-deactivate events will do the job. */ 8875#if USE_MAC_TSM
8876 DeactivateTSMDocument (tsm_document_id);
8877#endif
8867} 8878}
8868 8879
8869 8880
@@ -9123,6 +9134,9 @@ mac_store_event_ref_as_apple_event (class, id, class_key, id_key,
9123 { 9134 {
9124 mac_store_apple_event (class_key, id_key, &apple_event); 9135 mac_store_apple_event (class_key, id_key, &apple_event);
9125 AEDisposeDesc (&apple_event); 9136 AEDisposeDesc (&apple_event);
9137 /* Post a harmless event so as to wake up from
9138 ReceiveNextEvent. */
9139 mac_post_mouse_moved_event ();
9126 } 9140 }
9127 } 9141 }
9128 } 9142 }
@@ -9312,6 +9326,18 @@ mac_handle_window_event (next_handler, event, data)
9312 } 9326 }
9313 return err == noErr ? noErr : result; 9327 return err == noErr ? noErr : result;
9314#endif 9328#endif
9329
9330#if USE_MAC_TSM
9331 case kEventWindowFocusAcquired:
9332 result = CallNextEventHandler (next_handler, event);
9333 err = ActivateTSMDocument (tsm_document_id);
9334 return err == noErr ? noErr : result;
9335
9336 case kEventWindowFocusRelinquish:
9337 result = CallNextEventHandler (next_handler, event);
9338 err = DeactivateTSMDocument (tsm_document_id);
9339 return err == noErr ? noErr : result;
9340#endif
9315 } 9341 }
9316 9342
9317 return eventNotHandledErr; 9343 return eventNotHandledErr;
@@ -9438,6 +9464,183 @@ mac_handle_font_event (next_handler, event, data)
9438} 9464}
9439#endif 9465#endif
9440 9466
9467#if USE_MAC_TSM
9468static pascal OSStatus
9469mac_handle_text_input_event (next_handler, event, data)
9470 EventHandlerCallRef next_handler;
9471 EventRef event;
9472 void *data;
9473{
9474 OSStatus result, err = noErr;
9475 Lisp_Object id_key = Qnil;
9476 int num_params;
9477 EventParamName *names;
9478 EventParamType *types;
9479 static UInt32 seqno_uaia = 0;
9480 static EventParamName names_uaia[] =
9481 {kEventParamTextInputSendComponentInstance,
9482 kEventParamTextInputSendRefCon,
9483 kEventParamTextInputSendSLRec,
9484 kEventParamTextInputSendFixLen,
9485 kEventParamTextInputSendText,
9486 kEventParamTextInputSendUpdateRng,
9487 kEventParamTextInputSendHiliteRng,
9488 kEventParamTextInputSendClauseRng,
9489 kEventParamTextInputSendPinRng,
9490 kEventParamTextInputSendTextServiceEncoding,
9491 kEventParamTextInputSendTextServiceMacEncoding,
9492 EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER};
9493 static EventParamType types_uaia[] =
9494 {typeComponentInstance,
9495 typeLongInteger,
9496 typeIntlWritingCode,
9497 typeLongInteger,
9498 typeUnicodeText,
9499 typeTextRangeArray,
9500 typeTextRangeArray,
9501 typeOffsetArray,
9502 typeTextRange,
9503 typeUInt32,
9504 typeUInt32,
9505 typeUInt32};
9506 static EventParamName names_ufke[] =
9507 {kEventParamTextInputSendComponentInstance,
9508 kEventParamTextInputSendRefCon,
9509 kEventParamTextInputSendSLRec,
9510 kEventParamTextInputSendText};
9511 static EventParamType types_ufke[] =
9512 {typeComponentInstance,
9513 typeLongInteger,
9514 typeIntlWritingCode,
9515 typeUnicodeText};
9516
9517 result = CallNextEventHandler (next_handler, event);
9518
9519 switch (GetEventKind (event))
9520 {
9521 case kEventTextInputUpdateActiveInputArea:
9522 id_key = Qupdate_active_input_area;
9523 num_params = sizeof (names_uaia) / sizeof (names_uaia[0]);
9524 names = names_uaia;
9525 types = types_uaia;
9526 SetEventParameter (event, EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER,
9527 typeUInt32, sizeof (UInt32), &seqno_uaia);
9528 seqno_uaia++;
9529 break;
9530
9531 case kEventTextInputUnicodeForKeyEvent:
9532 {
9533 EventRef kbd_event;
9534 UInt32 actual_size, modifiers, mapped_modifiers;
9535 UniChar code;
9536
9537 err = GetEventParameter (event, kEventParamTextInputSendKeyboardEvent,
9538 typeEventRef, NULL, sizeof (EventRef), NULL,
9539 &kbd_event);
9540 if (err == noErr)
9541 err = GetEventParameter (kbd_event, kEventParamKeyModifiers,
9542 typeUInt32, NULL,
9543 sizeof (UInt32), NULL, &modifiers);
9544 if (err == noErr)
9545 {
9546 mapped_modifiers =
9547 (NILP (Vmac_control_modifier) ? 0 : controlKey)
9548 | (NILP (Vmac_option_modifier) ? 0 : optionKey)
9549 | (NILP (Vmac_command_modifier) ? 0 : cmdKey);
9550#ifdef MAC_OSX
9551 mapped_modifiers |=
9552 (NILP (Vmac_function_modifier) ? 0 : kEventKeyModifierFnMask);
9553#endif
9554 if (modifiers & mapped_modifiers)
9555 /* There're mapped modifier keys. Process it in
9556 XTread_socket. */
9557 return eventNotHandledErr;
9558 }
9559 if (err == noErr)
9560 err = GetEventParameter (kbd_event, kEventParamKeyUnicodes,
9561 typeUnicodeText, NULL, 0, &actual_size,
9562 NULL);
9563 if (err == noErr)
9564 {
9565 if (actual_size == sizeof (UniChar))
9566 err = GetEventParameter (kbd_event, kEventParamKeyUnicodes,
9567 typeUnicodeText, NULL,
9568 sizeof (UniChar), NULL, &code);
9569 if (err == noErr && code < 0x80)
9570 {
9571 /* ASCII character. Process it in XTread_socket. */
9572 if (read_socket_inev && code >= 0x20)
9573 {
9574 struct frame *f = mac_focus_frame (&one_mac_display_info);
9575
9576 read_socket_inev->kind = ASCII_KEYSTROKE_EVENT;
9577 read_socket_inev->code = code;
9578 read_socket_inev->modifiers =
9579 (extra_keyboard_modifiers
9580 & (meta_modifier | alt_modifier
9581 | hyper_modifier | super_modifier));
9582 XSETFRAME (read_socket_inev->frame_or_window, f);
9583 }
9584 return eventNotHandledErr;
9585 }
9586 }
9587 }
9588 /* Non-ASCII keystrokes without mapped modifiers are processed
9589 at the Lisp level. */
9590 id_key = Qunicode_for_key_event;
9591 num_params = sizeof (names_ufke) / sizeof (names_ufke[0]);
9592 names = names_ufke;
9593 types = types_ufke;
9594 break;
9595
9596 case kEventTextInputOffsetToPos:
9597 {
9598 struct frame *f;
9599 struct window *w;
9600 Point p;
9601
9602 if (!OVERLAYP (Vmac_ts_active_input_overlay))
9603 return eventNotHandledErr;
9604
9605 /* Strictly speaking, this is not always correct because
9606 previous events may change some states about display. */
9607 if (NILP (Foverlay_get (Vmac_ts_active_input_overlay, Qbefore_string)))
9608 {
9609 /* Active input area is displayed in the echo area. */
9610 w = XWINDOW (echo_area_window);
9611 f = WINDOW_XFRAME (w);
9612 }
9613 else
9614 {
9615 /* Active input area is displayed around the current point. */
9616 f = SELECTED_FRAME ();
9617 w = XWINDOW (f->selected_window);
9618 }
9619
9620 p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x)
9621 + WINDOW_LEFT_FRINGE_WIDTH (w));
9622 p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y)
9623 + FONT_BASE (FRAME_FONT (f)));
9624 SetPortWindowPort (FRAME_MAC_WINDOW (f));
9625 LocalToGlobal (&p);
9626 err = SetEventParameter (event, kEventParamTextInputReplyPoint,
9627 typeQDPoint, sizeof (typeQDPoint), &p);
9628 }
9629 break;
9630
9631 default:
9632 abort ();
9633 }
9634
9635 if (!NILP (id_key))
9636 err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key,
9637 event, num_params,
9638 names, types);
9639
9640 return err == noErr ? noErr : result;
9641}
9642#endif
9643
9441#ifdef MAC_OSX 9644#ifdef MAC_OSX
9442OSStatus 9645OSStatus
9443mac_store_service_event (event) 9646mac_store_service_event (event)
@@ -9499,6 +9702,10 @@ install_window_handler (window)
9499#ifdef MAC_OSX 9702#ifdef MAC_OSX
9500 {kEventClassWindow, kEventWindowToolbarSwitchMode}, 9703 {kEventClassWindow, kEventWindowToolbarSwitchMode},
9501#endif 9704#endif
9705#if USE_MAC_TSM
9706 {kEventClassWindow, kEventWindowFocusAcquired},
9707 {kEventClassWindow, kEventWindowFocusRelinquish},
9708#endif
9502 }; 9709 };
9503 EventTypeSpec specs_mouse[] = {{kEventClassMouse, kEventMouseWheelMoved}}; 9710 EventTypeSpec specs_mouse[] = {{kEventClassMouse, kEventMouseWheelMoved}};
9504 static EventHandlerUPP handle_window_eventUPP = NULL; 9711 static EventHandlerUPP handle_window_eventUPP = NULL;
@@ -9508,6 +9715,13 @@ install_window_handler (window)
9508 {kEventClassFont, kEventFontSelection}}; 9715 {kEventClassFont, kEventFontSelection}};
9509 static EventHandlerUPP handle_font_eventUPP = NULL; 9716 static EventHandlerUPP handle_font_eventUPP = NULL;
9510#endif 9717#endif
9718#if USE_MAC_TSM
9719 EventTypeSpec specs_text_input[] =
9720 {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea},
9721 {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent},
9722 {kEventClassTextInput, kEventTextInputOffsetToPos}};
9723 static EventHandlerUPP handle_text_input_eventUPP = NULL;
9724#endif
9511 9725
9512 if (handle_window_eventUPP == NULL) 9726 if (handle_window_eventUPP == NULL)
9513 handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); 9727 handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event);
@@ -9517,6 +9731,11 @@ install_window_handler (window)
9517 if (handle_font_eventUPP == NULL) 9731 if (handle_font_eventUPP == NULL)
9518 handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event); 9732 handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event);
9519#endif 9733#endif
9734#if USE_MAC_TSM
9735 if (handle_text_input_eventUPP == NULL)
9736 handle_text_input_eventUPP =
9737 NewEventHandlerUPP (mac_handle_text_input_event);
9738#endif
9520 err = InstallWindowEventHandler (window, handle_window_eventUPP, 9739 err = InstallWindowEventHandler (window, handle_window_eventUPP,
9521 GetEventTypeCount (specs_window), 9740 GetEventTypeCount (specs_window),
9522 specs_window, NULL, NULL); 9741 specs_window, NULL, NULL);
@@ -9530,6 +9749,12 @@ install_window_handler (window)
9530 GetEventTypeCount (specs_font), 9749 GetEventTypeCount (specs_font),
9531 specs_font, NULL, NULL); 9750 specs_font, NULL, NULL);
9532#endif 9751#endif
9752#if USE_MAC_TSM
9753 if (err == noErr)
9754 err = InstallWindowEventHandler (window, handle_text_input_eventUPP,
9755 GetEventTypeCount (specs_text_input),
9756 specs_text_input, window, NULL);
9757#endif
9533#endif 9758#endif
9534 if (err == noErr) 9759 if (err == noErr)
9535 err = install_drag_handler (window); 9760 err = install_drag_handler (window);
@@ -9655,7 +9880,7 @@ static unsigned char keycode_to_xkeysym_table[] = {
9655 9880
9656 /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/, 9881 /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/,
9657 /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/, 9882 /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/,
9658 /*0x68*/ 0, 0xca /*f13*/, 0, 0xcb /*f14*/, 9883 /*0x68*/ 0, 0xca /*f13*/, 0xcd /*f16*/, 0xcb /*f14*/,
9659 /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/, 9884 /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/,
9660 9885
9661 /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/, 9886 /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/,
@@ -10363,9 +10588,15 @@ XTread_socket (sd, expected, hold_quit)
10363 if (!(mapped_modifiers 10588 if (!(mapped_modifiers
10364 & ~(mac_pass_command_to_system ? cmdKey : 0) 10589 & ~(mac_pass_command_to_system ? cmdKey : 0)
10365 & ~(mac_pass_control_to_system ? controlKey : 0))) 10590 & ~(mac_pass_control_to_system ? controlKey : 0)))
10366 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) 10591 {
10367 != eventNotHandledErr) 10592 OSStatus err;
10593
10594 read_socket_inev = &inev;
10595 err = SendEventToEventTarget (eventRef, toolbox_dispatcher);
10596 read_socket_inev = NULL;
10597 if (err != eventNotHandledErr)
10368 break; 10598 break;
10599 }
10369#endif 10600#endif
10370 if (er.what == keyUp) 10601 if (er.what == keyUp)
10371 break; 10602 break;
@@ -10396,6 +10627,11 @@ XTread_socket (sd, expected, hold_quit)
10396 last_key_script = current_key_script; 10627 last_key_script = current_key_script;
10397 } 10628 }
10398 10629
10630#if USE_MAC_TSM
10631 if (inev.kind != NO_EVENT)
10632 break;
10633#endif
10634
10399#ifdef MAC_OSX 10635#ifdef MAC_OSX
10400 if (mapped_modifiers & kEventKeyModifierFnMask 10636 if (mapped_modifiers & kEventKeyModifierFnMask
10401 && keycode <= 0x7f 10637 && keycode <= 0x7f
@@ -11004,6 +11240,16 @@ init_menu_bar ()
11004#endif 11240#endif
11005} 11241}
11006 11242
11243#if USE_MAC_TSM
11244static void
11245init_tsm ()
11246{
11247 static InterfaceTypeList types = {kUnicodeDocument};
11248
11249 NewTSMDocument (sizeof (types) / sizeof (types[0]), types,
11250 &tsm_document_id, 0);
11251}
11252#endif
11007 11253
11008/* Set up use of X before we make the first connection. */ 11254/* Set up use of X before we make the first connection. */
11009 11255
@@ -11098,6 +11344,10 @@ mac_initialize ()
11098 init_command_handler (); 11344 init_command_handler ();
11099 11345
11100 init_menu_bar (); 11346 init_menu_bar ();
11347
11348#if USE_MAC_TSM
11349 init_tsm ();
11350#endif
11101#endif /* USE_CARBON_EVENTS */ 11351#endif /* USE_CARBON_EVENTS */
11102 11352
11103#ifdef MAC_OSX 11353#ifdef MAC_OSX
@@ -11154,6 +11404,13 @@ syms_of_macterm ()
11154 Qpaste = intern ("paste"); staticpro (&Qpaste); 11404 Qpaste = intern ("paste"); staticpro (&Qpaste);
11155 Qperform = intern ("perform"); staticpro (&Qperform); 11405 Qperform = intern ("perform"); staticpro (&Qperform);
11156#endif 11406#endif
11407#if USE_MAC_TSM
11408 Qtext_input = intern ("text-input"); staticpro (&Qtext_input);
11409 Qupdate_active_input_area = intern ("update-active-input-area");
11410 staticpro (&Qupdate_active_input_area);
11411 Qunicode_for_key_event = intern ("unicode-for-key-event");
11412 staticpro (&Qunicode_for_key_event);
11413#endif
11157#endif 11414#endif
11158 11415
11159#ifdef MAC_OSX 11416#ifdef MAC_OSX
@@ -11296,6 +11553,11 @@ order. */);
11296 make_float (DEFAULT_REHASH_THRESHOLD), 11553 make_float (DEFAULT_REHASH_THRESHOLD),
11297 Qnil, Qnil, Qnil); 11554 Qnil, Qnil, Qnil);
11298#endif 11555#endif
11556#if USE_MAC_TSM
11557 DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay,
11558 doc: /* Overlay used to display Mac TSM active input area. */);
11559 Vmac_ts_active_input_overlay = Qnil;
11560#endif
11299} 11561}
11300 11562
11301/* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b 11563/* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b