aboutsummaryrefslogtreecommitdiffstats
path: root/src/macterm.c
diff options
context:
space:
mode:
authorMiles Bader2008-04-24 05:11:07 +0000
committerMiles Bader2008-04-24 05:11:07 +0000
commit08861c5cb87e91e83e5b0bf53cb53c1377434c8f (patch)
tree113fbc5d0f03e87489fb365f6383c4423469e492 /src/macterm.c
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
Diffstat (limited to 'src/macterm.c')
-rw-r--r--src/macterm.c227
1 files changed, 223 insertions, 4 deletions
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