aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2008-04-24 05:11:07 +0000
committerMiles Bader2008-04-24 05:11:07 +0000
commit08861c5cb87e91e83e5b0bf53cb53c1377434c8f (patch)
tree113fbc5d0f03e87489fb365f6383c4423469e492
parent254a60ecbfd8a7a89a9ee52ae3b0839b425c60c0 (diff)
parent285935fe5dbd6c60096abe4991ddac12d81a3ab6 (diff)
downloademacs-08861c5cb87e91e83e5b0bf53cb53c1377434c8f.tar.gz
emacs-08861c5cb87e91e83e5b0bf53cb53c1377434c8f.zip
Merge from emacs--rel--22
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1126
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/term/mac-win.el3
-rw-r--r--src/ChangeLog29
-rw-r--r--src/macterm.c227
-rw-r--r--src/mactoolbox.c379
-rw-r--r--src/xdisp.c10
6 files changed, 623 insertions, 29 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6a7c7e1eabe..448f92cdca5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12008-04-24 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
2
3 * term/mac-win.el (mac-ts-active-input-buf): Move defvar to macterm.c.
4
12008-04-24 Stefan Monnier <monnier@iro.umontreal.ca> 52008-04-24 Stefan Monnier <monnier@iro.umontreal.ca>
2 6
3 * emacs-lisp/easymenu.el (easy-menu-make-symbol): Don't wrap keyboard 7 * emacs-lisp/easymenu.el (easy-menu-make-symbol): Don't wrap keyboard
diff --git a/lisp/term/mac-win.el b/lisp/term/mac-win.el
index e15f2e4c873..91d14a9c8fa 100644
--- a/lisp/term/mac-win.el
+++ b/lisp/term/mac-win.el
@@ -83,6 +83,7 @@
83(defvar mac-apple-event-map) 83(defvar mac-apple-event-map)
84(defvar mac-font-panel-mode) 84(defvar mac-font-panel-mode)
85(defvar mac-ts-active-input-overlay) 85(defvar mac-ts-active-input-overlay)
86(defvar mac-ts-active-input-buf)
86(defvar x-invocation-args) 87(defvar x-invocation-args)
87(declare-function mac-code-convert-string "mac.c") 88(declare-function mac-code-convert-string "mac.c")
88(declare-function mac-coerce-ae-data "mac.c") 89(declare-function mac-coerce-ae-data "mac.c")
@@ -1926,8 +1927,6 @@ With numeric ARG, display the font panel if and only if ARG is positive."
1926) ;; (fboundp 'mac-set-font-panel-visible-p) 1927) ;; (fboundp 'mac-set-font-panel-visible-p)
1927 1928
1928;;; Text Services 1929;;; Text Services
1929(defvar mac-ts-active-input-buf ""
1930 "Byte sequence of the current Mac TSM active input area.")
1931(defvar mac-ts-update-active-input-area-seqno 0 1930(defvar mac-ts-update-active-input-area-seqno 0
1932 "Number of processed update-active-input-area events.") 1931 "Number of processed update-active-input-area events.")
1933(setq mac-ts-active-input-overlay (make-overlay 0 0)) 1932(setq mac-ts-active-input-overlay (make-overlay 0 0))
diff --git a/src/ChangeLog b/src/ChangeLog
index e75d3267888..61ef12c8479 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,32 @@
12008-04-23 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
2
3 * macterm.c (Vmac_ts_active_input_buf) [USE_MAC_TSM]: New variable.
4 (syms_of_macterm) [USE_MAC_TSM]: Defvar it.
5 (Qmouse_drag_overlay) [MAC_OSX]: New variable.
6 (syms_of_macterm) [MAC_OSX]: Intern and staticpro it.
7 (mac_get_selected_range, mac_store_buffer_text_to_unicode_chars)
8 (mac_ax_selected_text_range) [MAC_OSX]: New functions.
9 (mac_ax_number_of_characters) [MAC_OS_X_VERSION_MAX_ALLOWED >= 1030]:
10 Likewise.
11
12 * mactoolbox.c (Vmac_ts_active_input_buf) [USE_MAC_TSM]: Add extern.
13 (fast_find_position, x_y_to_hpos_vpos, mac_ax_selected_text_range):
14 (mac_ax_number_of_characters): Add externs.
15 (mac_get_selected_range, mac_store_buffer_text_to_unicode_chars)
16 [USE_MAC_TSM]: Likewise.
17 (mac_handle_text_input_event) [MAC_OSX]:
18 Handle kEventTextInputOffsetToPos for no active input area case.
19 Handle kEventTextInputPosToOffset and kEventTextInputGetSelectedText.
20 (mac_handle_document_access_event)
21 [MAC_OS_X_VERSION_MAX_ALLOWED >= 1030]: New function.
22 (install_application_handler) [MAC_OSX]: Register handlers for
23 kEventTextInputPosToOffset and kEventTextInputGetSelectedText.
24 (install_application_handler) [MAC_OS_X_VERSION_MAX_ALLOWED >= 1030]:
25 Register mac_handle_document_access_event.
26
27 * xdisp.c (x_y_to_hpos_vpos, fast_find_position) [HAVE_CARBON]:
28 Make functions non-static.
29
12008-04-23 Stefan Monnier <monnier@iro.umontreal.ca> 302008-04-23 Stefan Monnier <monnier@iro.umontreal.ca>
2 31
3 * fileio.c (Vread_file_name_function, Vread_file_name_predicate) 32 * fileio.c (Vread_file_name_function, Vread_file_name_predicate)
diff --git a/src/macterm.c b/src/macterm.c
index f4715c7f772..b458444f977 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -9647,9 +9647,9 @@ static Lisp_Object Qtoolbar_switch_mode;
9647#endif 9647#endif
9648#if USE_MAC_TSM 9648#if USE_MAC_TSM
9649static TSMDocumentID tsm_document_id; 9649static TSMDocumentID tsm_document_id;
9650static Lisp_Object Qtext_input; 9650Lisp_Object Qtext_input;
9651static Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event; 9651Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event;
9652static Lisp_Object Vmac_ts_active_input_overlay; 9652Lisp_Object Vmac_ts_active_input_overlay, Vmac_ts_active_input_buf;
9653extern Lisp_Object Qbefore_string; 9653extern Lisp_Object Qbefore_string;
9654static Lisp_Object Vmac_ts_script_language_on_focus; 9654static Lisp_Object Vmac_ts_script_language_on_focus;
9655static Lisp_Object saved_ts_script_language_on_focus; 9655static Lisp_Object saved_ts_script_language_on_focus;
@@ -9675,7 +9675,8 @@ extern OSStatus install_menu_target_item_handler P_ ((void));
9675 9675
9676#ifdef MAC_OSX 9676#ifdef MAC_OSX
9677extern OSStatus install_service_handler (); 9677extern OSStatus install_service_handler ();
9678static Lisp_Object Qservice, Qpaste, Qperform; 9678Lisp_Object Qservice, Qpaste, Qperform;
9679Lisp_Object Qmouse_drag_overlay;
9679#endif 9680#endif
9680#endif 9681#endif
9681 9682
@@ -9838,6 +9839,216 @@ mac_get_emulated_btn ( UInt32 modifiers )
9838 return result; 9839 return result;
9839} 9840}
9840 9841
9842#ifdef MAC_OSX
9843void
9844mac_get_selected_range (w, range)
9845 struct window *w;
9846 CFRange *range;
9847{
9848 Lisp_Object overlay = find_symbol_value (Qmouse_drag_overlay);
9849 struct buffer *b = XBUFFER (w->buffer);
9850 int begv = BUF_BEGV (b), zv = BUF_ZV (b);
9851 int start, end;
9852
9853 if (OVERLAYP (overlay)
9854 && EQ (Foverlay_buffer (overlay), w->buffer)
9855 && (start = XINT (Foverlay_start (overlay)),
9856 end = XINT (Foverlay_end (overlay)),
9857 start != end))
9858 ;
9859 else
9860 {
9861 if (w == XWINDOW (selected_window) && b == current_buffer)
9862 start = PT;
9863 else
9864 start = marker_position (w->pointm);
9865
9866 if (NILP (Vtransient_mark_mode) || NILP (b->mark_active))
9867 end = start;
9868 else
9869 {
9870 int mark_pos = marker_position (b->mark);
9871
9872 if (start <= mark_pos)
9873 end = mark_pos;
9874 else
9875 {
9876 end = start;
9877 start = mark_pos;
9878 }
9879 }
9880 }
9881
9882 if (start != end)
9883 {
9884 if (start < begv)
9885 start = begv;
9886 else if (start > zv)
9887 start = zv;
9888
9889 if (end < begv)
9890 end = begv;
9891 else if (end > zv)
9892 end = zv;
9893 }
9894
9895 range->location = start - begv;
9896 range->length = end - start;
9897}
9898
9899/* Store the text of the buffer BUF from START to END as Unicode
9900 characters in CHARACTERS. Return non-zero if successful. */
9901
9902int
9903mac_store_buffer_text_to_unicode_chars (buf, start, end, characters)
9904 struct buffer *buf;
9905 int start, end;
9906 UniChar *characters;
9907{
9908 int start_byte, end_byte, char_count, byte_count;
9909 struct coding_system coding;
9910 unsigned char *dst = (unsigned char *) characters;
9911
9912 start_byte = buf_charpos_to_bytepos (buf, start);
9913 end_byte = buf_charpos_to_bytepos (buf, end);
9914 char_count = end - start;
9915 byte_count = end_byte - start_byte;
9916
9917 if (setup_coding_system (
9918#ifdef WORDS_BIG_ENDIAN
9919 intern ("utf-16be")
9920#else
9921 intern ("utf-16le")
9922#endif
9923 , &coding) < 0)
9924 return 0;
9925
9926 coding.src_multibyte = !NILP (buf->enable_multibyte_characters);
9927 coding.dst_multibyte = 0;
9928 coding.mode |= CODING_MODE_LAST_BLOCK;
9929 coding.composing = COMPOSITION_DISABLED;
9930
9931 if (BUF_GPT_BYTE (buf) <= start_byte || end_byte <= BUF_GPT_BYTE (buf))
9932 encode_coding (&coding, BUF_BYTE_ADDRESS (buf, start_byte), dst,
9933 byte_count, char_count * sizeof (UniChar));
9934 else
9935 {
9936 int first_byte_count = BUF_GPT_BYTE (buf) - start_byte;
9937
9938 encode_coding (&coding, BUF_BYTE_ADDRESS (buf, start_byte), dst,
9939 first_byte_count, char_count * sizeof (UniChar));
9940 if (coding.result == CODING_FINISH_NORMAL)
9941 encode_coding (&coding,
9942 BUF_BYTE_ADDRESS (buf, start_byte + first_byte_count),
9943 dst + coding.produced,
9944 byte_count - first_byte_count,
9945 char_count * sizeof (UniChar) - coding.produced);
9946 }
9947
9948 if (coding.result != CODING_FINISH_NORMAL)
9949 return 0;
9950
9951 return 1;
9952}
9953
9954void
9955mac_ax_selected_text_range (f, range)
9956 struct frame *f;
9957 CFRange *range;
9958{
9959 mac_get_selected_range (XWINDOW (f->selected_window), range);
9960}
9961
9962#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
9963unsigned int
9964mac_ax_number_of_characters (f)
9965 struct frame *f;
9966{
9967 struct buffer *b = XBUFFER (XWINDOW (f->selected_window)->buffer);
9968
9969 return BUF_ZV (b) - BUF_BEGV (b);
9970}
9971#endif
9972#endif
9973
9974#if USE_MAC_TSM
9975OSStatus
9976mac_restore_keyboard_input_source ()
9977{
9978 OSStatus err = noErr;
9979 ScriptLanguageRecord slrec, *slptr = NULL;
9980
9981 if (EQ (Vmac_ts_script_language_on_focus, Qt)
9982 && EQ (saved_ts_script_language_on_focus, Qt))
9983 slptr = &saved_ts_language;
9984 else if (CONSP (Vmac_ts_script_language_on_focus)
9985 && INTEGERP (XCAR (Vmac_ts_script_language_on_focus))
9986 && INTEGERP (XCDR (Vmac_ts_script_language_on_focus))
9987 && CONSP (saved_ts_script_language_on_focus)
9988 && EQ (XCAR (saved_ts_script_language_on_focus),
9989 XCAR (Vmac_ts_script_language_on_focus))
9990 && EQ (XCDR (saved_ts_script_language_on_focus),
9991 XCDR (Vmac_ts_script_language_on_focus)))
9992 {
9993 slrec.fScript = XINT (XCAR (Vmac_ts_script_language_on_focus));
9994 slrec.fLanguage = XINT (XCDR (Vmac_ts_script_language_on_focus));
9995 slptr = &slrec;
9996 }
9997
9998 if (slptr)
9999 {
10000#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
10001 err = SetDefaultInputMethodOfClass (saved_ts_component, slptr,
10002 kKeyboardInputMethodClass);
10003#else
10004 err = SetDefaultInputMethod (saved_ts_component, slptr);
10005#endif
10006 if (err == noErr)
10007 err = SetTextServiceLanguage (slptr);
10008
10009 /* Seems to be needed on Mac OS X 10.2. */
10010 if (err == noErr)
10011 KeyScript (slptr->fScript | smKeyForceKeyScriptMask);
10012 }
10013
10014 return err;
10015}
10016
10017void
10018mac_save_keyboard_input_source ()
10019{
10020 OSStatus err;
10021 ScriptLanguageRecord slrec, *slptr = NULL;
10022
10023 saved_ts_script_language_on_focus = Vmac_ts_script_language_on_focus;
10024
10025 if (EQ (Vmac_ts_script_language_on_focus, Qt))
10026 {
10027 err = GetTextServiceLanguage (&saved_ts_language);
10028 if (err == noErr)
10029 slptr = &saved_ts_language;
10030 }
10031 else if (CONSP (Vmac_ts_script_language_on_focus)
10032 && INTEGERP (XCAR (Vmac_ts_script_language_on_focus))
10033 && INTEGERP (XCDR (Vmac_ts_script_language_on_focus)))
10034 {
10035 slrec.fScript = XINT (XCAR (Vmac_ts_script_language_on_focus));
10036 slrec.fLanguage = XINT (XCDR (Vmac_ts_script_language_on_focus));
10037 slptr = &slrec;
10038 }
10039
10040 if (slptr)
10041 {
10042#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
10043 GetDefaultInputMethodOfClass (&saved_ts_component, slptr,
10044 kKeyboardInputMethodClass);
10045#else
10046 GetDefaultInputMethod (&saved_ts_component, slptr);
10047#endif
10048 }
10049}
10050#endif
10051
9841#if TARGET_API_MAC_CARBON 10052#if TARGET_API_MAC_CARBON
9842/***** Code to handle C-g testing *****/ 10053/***** Code to handle C-g testing *****/
9843extern int quit_char; 10054extern int quit_char;
@@ -12982,6 +13193,9 @@ syms_of_macterm ()
12982 Qservice = intern ("service"); staticpro (&Qservice); 13193 Qservice = intern ("service"); staticpro (&Qservice);
12983 Qpaste = intern ("paste"); staticpro (&Qpaste); 13194 Qpaste = intern ("paste"); staticpro (&Qpaste);
12984 Qperform = intern ("perform"); staticpro (&Qperform); 13195 Qperform = intern ("perform"); staticpro (&Qperform);
13196
13197 Qmouse_drag_overlay = intern ("mouse-drag-overlay");
13198 staticpro (&Qmouse_drag_overlay);
12985#endif 13199#endif
12986#if USE_MAC_TSM 13200#if USE_MAC_TSM
12987 Qtext_input = intern ("text-input"); staticpro (&Qtext_input); 13201 Qtext_input = intern ("text-input"); staticpro (&Qtext_input);
@@ -13142,6 +13356,11 @@ CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */);
13142 doc: /* Overlay used to display Mac TSM active input area. */); 13356 doc: /* Overlay used to display Mac TSM active input area. */);
13143 Vmac_ts_active_input_overlay = Qnil; 13357 Vmac_ts_active_input_overlay = Qnil;
13144 13358
13359 DEFVAR_LISP ("mac-ts-active-input-buf", &Vmac_ts_active_input_buf,
13360 doc: /* Byte sequence of the current Mac TSM active input area. */);
13361 /* `empty_string' is not ready yet on Mac OS Classic. */
13362 Vmac_ts_active_input_buf = build_string ("");
13363
13145 DEFVAR_LISP ("mac-ts-script-language-on-focus", &Vmac_ts_script_language_on_focus, 13364 DEFVAR_LISP ("mac-ts-script-language-on-focus", &Vmac_ts_script_language_on_focus,
13146 doc: /* *How to change Mac TSM script/language when a frame gets focus. 13365 doc: /* *How to change Mac TSM script/language when a frame gets focus.
13147If the value is t, the input script and language are restored to those 13366If the value is t, the input script and language are restored to those
diff --git a/src/mactoolbox.c b/src/mactoolbox.c
index 71abce23fe0..45a86135422 100644
--- a/src/mactoolbox.c
+++ b/src/mactoolbox.c
@@ -118,7 +118,7 @@ extern Lisp_Object Qhi_command;
118static TSMDocumentID tsm_document_id; 118static TSMDocumentID tsm_document_id;
119extern Lisp_Object Qtext_input; 119extern Lisp_Object Qtext_input;
120extern Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event; 120extern Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event;
121extern Lisp_Object Vmac_ts_active_input_overlay; 121extern Lisp_Object Vmac_ts_active_input_overlay, Vmac_ts_active_input_buf;
122extern Lisp_Object Qbefore_string; 122extern Lisp_Object Qbefore_string;
123#endif 123#endif
124 124
@@ -134,6 +134,14 @@ extern OSStatus mac_store_event_ref_as_apple_event P_ ((AEEventClass, AEEventID,
134 EventRef, UInt32, 134 EventRef, UInt32,
135 const EventParamName *, 135 const EventParamName *,
136 const EventParamType *)); 136 const EventParamType *));
137extern int fast_find_position P_ ((struct window *, int, int *, int *,
138 int *, int *, Lisp_Object));
139extern struct glyph *x_y_to_hpos_vpos P_ ((struct window *, int, int,
140 int *, int *, int *, int *, int *));
141extern void mac_ax_selected_text_range P_ ((struct frame *, CFRange *));
142#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
143extern unsigned int mac_ax_number_of_characters P_ ((struct frame *));
144#endif
137 145
138#if USE_MAC_TSM 146#if USE_MAC_TSM
139extern OSStatus mac_restore_keyboard_input_source P_ ((void)); 147extern OSStatus mac_restore_keyboard_input_source P_ ((void));
@@ -374,6 +382,10 @@ mac_handle_mouse_event (next_handler, event, data)
374} 382}
375 383
376#if USE_MAC_TSM 384#if USE_MAC_TSM
385extern void mac_get_selected_range P_ ((struct window *, CFRange *));
386extern int mac_store_buffer_text_to_unicode_chars P_ ((struct buffer *,
387 int, int, UniChar *));
388
377static pascal OSStatus 389static pascal OSStatus
378mac_handle_text_input_event (next_handler, event, data) 390mac_handle_text_input_event (next_handler, event, data)
379 EventHandlerCallRef next_handler; 391 EventHandlerCallRef next_handler;
@@ -512,42 +524,268 @@ mac_handle_text_input_event (next_handler, event, data)
512 524
513 case kEventTextInputOffsetToPos: 525 case kEventTextInputOffsetToPos:
514 { 526 {
527 long byte_offset;
515 struct frame *f; 528 struct frame *f;
516 struct window *w; 529 struct window *w;
517 Point p; 530 Point p;
518 531
519 if (!OVERLAYP (Vmac_ts_active_input_overlay)) 532 err = GetEventParameter (event, kEventParamTextInputSendTextOffset,
533 typeLongInteger, NULL, sizeof (long), NULL,
534 &byte_offset);
535 if (err != noErr)
520 break; 536 break;
521 537
522 /* Strictly speaking, this is not always correct because 538 if (STRINGP (Vmac_ts_active_input_buf)
523 previous events may change some states about display. */ 539 && SBYTES (Vmac_ts_active_input_buf) != 0)
524 if (!NILP (Foverlay_get (Vmac_ts_active_input_overlay, Qbefore_string))) 540 {
541 if (!OVERLAYP (Vmac_ts_active_input_overlay))
542 break;
543
544 /* Strictly speaking, this is not always correct because
545 previous events may change some states about display. */
546 if (!NILP (Foverlay_get (Vmac_ts_active_input_overlay, Qbefore_string)))
547 {
548 /* Active input area is displayed around the current point. */
549 f = SELECTED_FRAME ();
550 w = XWINDOW (f->selected_window);
551 }
552 else if (WINDOWP (echo_area_window))
553 {
554 /* Active input area is displayed in the echo area. */
555 w = XWINDOW (echo_area_window);
556 f = WINDOW_XFRAME (w);
557 }
558 else
559 break;
560
561 p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x)
562 + WINDOW_LEFT_FRINGE_WIDTH (w)
563 + f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f));
564 p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y)
565 + FONT_BASE (FRAME_FONT (f))
566 + f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f));
567 }
568 else
525 { 569 {
526 /* Active input area is displayed around the current point. */ 570#ifndef MAC_OSX
527 f = SELECTED_FRAME (); 571 break;
572#else /* MAC_OSX */
573 CFRange sel_range;
574 int charpos;
575 int hpos, vpos, x, y;
576 struct glyph_row *row;
577 struct glyph *glyph;
578 XFontStruct *font;
579
580 f = mac_focus_frame (&one_mac_display_info);
528 w = XWINDOW (f->selected_window); 581 w = XWINDOW (f->selected_window);
582 mac_get_selected_range (w, &sel_range);
583 charpos = (BUF_BEGV (XBUFFER (w->buffer)) + sel_range.location
584 + byte_offset / (long) sizeof (UniChar));
585
586 if (!fast_find_position (w, charpos, &hpos, &vpos, &x, &y, Qnil))
587 {
588 result = errOffsetInvalid;
589 break;
590 }
591
592 row = MATRIX_ROW (w->current_matrix, vpos);
593 glyph = row->glyphs[TEXT_AREA] + hpos;
594 if (glyph->type != CHAR_GLYPH || glyph->glyph_not_available_p)
595 break;
596
597 p.h = (WINDOW_TEXT_TO_FRAME_PIXEL_X (w, x)
598 + f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f));
599 p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, y)
600 + row->visible_height
601 + f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f));
602
603 font = FACE_FROM_ID (f, glyph->face_id)->font;
604 if (font)
605 {
606 Fixed point_size = Long2Fix (font->mac_fontsize);
607 short height = row->visible_height;
608 short ascent = row->ascent;
609
610 SetEventParameter (event,
611 kEventParamTextInputReplyPointSize,
612 typeFixed, sizeof (Fixed), &point_size);
613 SetEventParameter (event,
614 kEventParamTextInputReplyLineHeight,
615 typeShortInteger, sizeof (short), &height);
616 SetEventParameter (event,
617 kEventParamTextInputReplyLineAscent,
618 typeShortInteger, sizeof (short), &ascent);
619 if (font->mac_fontnum != -1)
620 {
621 OSStatus err1;
622 FMFont fm_font;
623 FMFontStyle style;
624
625 err1 = FMGetFontFromFontFamilyInstance (font->mac_fontnum,
626 font->mac_fontface,
627 &fm_font, &style);
628 if (err1 == noErr)
629 SetEventParameter (event, kEventParamTextInputReplyFMFont,
630 typeUInt32, sizeof (UInt32), &fm_font);
631 else
632 {
633 long qd_font = font->mac_fontnum;
634
635 SetEventParameter (event, kEventParamTextInputReplyFont,
636 typeLongInteger, sizeof (long),
637 &qd_font);
638 }
639 }
640 else if (font->mac_style)
641 {
642 OSStatus err1;
643 ATSUFontID font_id;
644
645 err1 = ATSUGetAttribute (font->mac_style, kATSUFontTag,
646 sizeof (ATSUFontID), &font_id,
647 NULL);
648 if (err1 == noErr)
649 SetEventParameter (event, kEventParamTextInputReplyFMFont,
650 typeUInt32, sizeof (UInt32), &font_id);
651 }
652 else
653 abort ();
654 }
655#endif /* MAC_OSX */
529 } 656 }
530 else if (WINDOWP (echo_area_window)) 657
658 err = SetEventParameter (event, kEventParamTextInputReplyPoint,
659 typeQDPoint, sizeof (Point), &p);
660 if (err == noErr)
661 result = noErr;
662 }
663 break;
664
665#ifdef MAC_OSX
666 case kEventTextInputPosToOffset:
667 {
668 Point point;
669 Boolean leading_edge_p = true;
670 struct frame *f;
671 int x, y;
672 Lisp_Object window;
673 enum window_part part;
674 long region_class = kTSMOutsideOfBody, byte_offset = 0;
675
676 err = GetEventParameter (event, kEventParamTextInputSendCurrentPoint,
677 typeQDPoint, NULL, sizeof (Point), NULL,
678 &point);
679 if (err != noErr)
680 break;
681
682 GetEventParameter (event, kEventParamTextInputReplyLeadingEdge,
683 typeBoolean, NULL, sizeof (Boolean), NULL,
684 &leading_edge_p);
685
686 f = mac_focus_frame (&one_mac_display_info);
687 x = point.h - (f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f));
688 y = point.v - (f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f));
689 window = window_from_coordinates (f, x, y, &part, 0, 0, 1);
690 if (WINDOWP (window) && EQ (window, f->selected_window))
531 { 691 {
532 /* Active input area is displayed in the echo area. */ 692 struct window *w;
533 w = XWINDOW (echo_area_window); 693 struct buffer *b;
534 f = WINDOW_XFRAME (w); 694
695 /* Convert to window-relative pixel coordinates. */
696 w = XWINDOW (window);
697 frame_to_window_pixel_xy (w, &x, &y);
698
699 /* Are we in a window whose display is up to date?
700 And verify the buffer's text has not changed. */
701 b = XBUFFER (w->buffer);
702 if (part == ON_TEXT
703 && EQ (w->window_end_valid, w->buffer)
704 && XINT (w->last_modified) == BUF_MODIFF (b)
705 && XINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b))
706 {
707 int hpos, vpos, area;
708 struct glyph *glyph;
709
710 /* Find the glyph under X/Y. */
711 glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, 0, 0, &area);
712
713 if (glyph != NULL && area == TEXT_AREA)
714 {
715 byte_offset = ((glyph->charpos - BUF_BEGV (b))
716 * sizeof (UniChar));
717 region_class = kTSMInsideOfBody;
718 }
719 }
535 } 720 }
536 else 721
722 err = SetEventParameter (event, kEventParamTextInputReplyRegionClass,
723 typeLongInteger, sizeof (long),
724 &region_class);
725 if (err == noErr)
726 err = SetEventParameter (event, kEventParamTextInputReplyTextOffset,
727 typeLongInteger, sizeof (long),
728 &byte_offset);
729 if (err == noErr)
730 result = noErr;
731 }
732 break;
733
734 case kEventTextInputGetSelectedText:
735 {
736 struct frame *f = mac_focus_frame (&one_mac_display_info);
737 struct window *w = XWINDOW (f->selected_window);
738 struct buffer *b = XBUFFER (w->buffer);
739 CFRange sel_range;
740 int start, end;
741 UniChar *characters, c;
742
743 if (poll_suppress_count == 0 && !NILP (Vinhibit_quit))
744 /* Don't try to get buffer contents as the gap might be
745 being altered. */
537 break; 746 break;
538 747
539 p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) 748 mac_get_selected_range (w, &sel_range);
540 + WINDOW_LEFT_FRINGE_WIDTH (w) 749 if (sel_range.length == 0)
541 + f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f)); 750 {
542 p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) 751 Boolean leading_edge_p;
543 + FONT_BASE (FRAME_FONT (f)) 752
544 + f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f)); 753 err = GetEventParameter (event,
545 err = SetEventParameter (event, kEventParamTextInputReplyPoint, 754 kEventParamTextInputReplyLeadingEdge,
546 typeQDPoint, sizeof (typeQDPoint), &p); 755 typeBoolean, NULL, sizeof (Boolean), NULL,
756 &leading_edge_p);
757 if (err != noErr)
758 break;
759
760 start = BUF_BEGV (b) + sel_range.location;
761 if (!leading_edge_p)
762 start--;
763 end = start + 1;
764 characters = &c;
765
766 if (start < BUF_BEGV (b) || end > BUF_ZV (b))
767 break;
768 }
769 else
770 {
771 start = BUF_BEGV (b) + sel_range.location;
772 end = start + sel_range.length;
773 characters = xmalloc (sel_range.length * sizeof (UniChar));
774 }
775
776 if (mac_store_buffer_text_to_unicode_chars (b, start, end, characters))
777 err = SetEventParameter (event, kEventParamTextInputReplyText,
778 typeUnicodeText,
779 sel_range.length * sizeof (UniChar),
780 characters);
781 if (characters != &c)
782 xfree (characters);
783
547 if (err == noErr) 784 if (err == noErr)
548 result = noErr; 785 result = noErr;
549 } 786 }
550 break; 787 break;
788#endif /* MAC_OSX */
551 789
552 default: 790 default:
553 abort (); 791 abort ();
@@ -559,6 +797,86 @@ mac_handle_text_input_event (next_handler, event, data)
559 names, types); 797 names, types);
560 return result; 798 return result;
561} 799}
800
801#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
802static pascal OSStatus
803mac_handle_document_access_event (next_handler, event, data)
804 EventHandlerCallRef next_handler;
805 EventRef event;
806 void *data;
807{
808 OSStatus err, result;
809 struct frame *f = mac_focus_frame (&one_mac_display_info);
810
811 result = CallNextEventHandler (next_handler, event);
812 if (result != eventNotHandledErr)
813 return result;
814
815 switch (GetEventKind (event))
816 {
817 case kEventTSMDocumentAccessGetLength:
818 {
819 CFIndex count = mac_ax_number_of_characters (f);
820
821 err = SetEventParameter (event, kEventParamTSMDocAccessCharacterCount,
822 typeCFIndex, sizeof (CFIndex), &count);
823 if (err == noErr)
824 result = noErr;
825 }
826 break;
827
828 case kEventTSMDocumentAccessGetSelectedRange:
829 {
830 CFRange sel_range;
831
832 mac_ax_selected_text_range (f, &sel_range);
833 err = SetEventParameter (event,
834 kEventParamTSMDocAccessReplyCharacterRange,
835 typeCFRange, sizeof (CFRange), &sel_range);
836 if (err == noErr)
837 result = noErr;
838 }
839 break;
840
841 case kEventTSMDocumentAccessGetCharacters:
842 {
843 struct buffer *b = XBUFFER (XWINDOW (f->selected_window)->buffer);
844 CFRange range;
845 Ptr characters;
846 int start, end;
847
848 if (poll_suppress_count == 0 && !NILP (Vinhibit_quit))
849 /* Don't try to get buffer contents as the gap might be
850 being altered. */
851 break;
852
853 err = GetEventParameter (event,
854 kEventParamTSMDocAccessSendCharacterRange,
855 typeCFRange, NULL, sizeof (CFRange), NULL,
856 &range);
857 if (err == noErr)
858 err = GetEventParameter (event,
859 kEventParamTSMDocAccessSendCharactersPtr,
860 typePtr, NULL, sizeof (Ptr), NULL,
861 &characters);
862 if (err != noErr)
863 break;
864
865 start = BUF_BEGV (b) + range.location;
866 end = start + range.length;
867 if (mac_store_buffer_text_to_unicode_chars (b, start, end,
868 (UniChar *) characters))
869 result = noErr;
870 }
871 break;
872
873 default:
874 abort ();
875 }
876
877 return result;
878}
879#endif
562#endif 880#endif
563 881
564OSStatus 882OSStatus
@@ -607,13 +925,32 @@ install_application_handler ()
607 static const EventTypeSpec specs[] = 925 static const EventTypeSpec specs[] =
608 {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea}, 926 {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea},
609 {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, 927 {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent},
610 {kEventClassTextInput, kEventTextInputOffsetToPos}}; 928 {kEventClassTextInput, kEventTextInputOffsetToPos},
929#ifdef MAC_OSX
930 {kEventClassTextInput, kEventTextInputPosToOffset},
931 {kEventClassTextInput, kEventTextInputGetSelectedText}
932#endif
933 };
611 934
612 err = InstallApplicationEventHandler (NewEventHandlerUPP 935 err = InstallApplicationEventHandler (NewEventHandlerUPP
613 (mac_handle_text_input_event), 936 (mac_handle_text_input_event),
614 GetEventTypeCount (specs), 937 GetEventTypeCount (specs),
615 specs, NULL, NULL); 938 specs, NULL, NULL);
616 } 939 }
940
941#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
942 if (err == noErr)
943 {
944 static const EventTypeSpec specs[] =
945 {{kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetLength},
946 {kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetSelectedRange},
947 {kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetCharacters}};
948
949 err = InstallApplicationEventHandler (mac_handle_document_access_event,
950 GetEventTypeCount (specs),
951 specs, NULL, NULL);
952 }
953#endif
617#endif 954#endif
618 955
619 if (err == noErr) 956 if (err == noErr)
diff --git a/src/xdisp.c b/src/xdisp.c
index 50c115b42ca..bb9ec58792c 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -1723,7 +1723,10 @@ glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y)
1723 text, or we can't tell because W's current matrix is not up to 1723 text, or we can't tell because W's current matrix is not up to
1724 date. */ 1724 date. */
1725 1725
1726static struct glyph * 1726#ifndef HAVE_CARBON
1727static
1728#endif
1729struct glyph *
1727x_y_to_hpos_vpos (w, x, y, hpos, vpos, dx, dy, area) 1730x_y_to_hpos_vpos (w, x, y, hpos, vpos, dx, dy, area)
1728 struct window *w; 1731 struct window *w;
1729 int x, y; 1732 int x, y;
@@ -22498,7 +22501,10 @@ cursor_in_mouse_face_p (w)
22498 in 20.x as well, and I think it's too risky to install 22501 in 20.x as well, and I think it's too risky to install
22499 so near the release of 21.1. 2001-09-25 gerd. */ 22502 so near the release of 21.1. 2001-09-25 gerd. */
22500 22503
22501static int 22504#ifndef HAVE_CARBON
22505static
22506#endif
22507int
22502fast_find_position (w, charpos, hpos, vpos, x, y, stop) 22508fast_find_position (w, charpos, hpos, vpos, x, y, stop)
22503 struct window *w; 22509 struct window *w;
22504 EMACS_INT charpos; 22510 EMACS_INT charpos;