*** lisp/loadup.el.org Wed Mar 3 10:30:51 2004 --- lisp/loadup.el Wed Mar 3 10:53:24 2004 *************** *** 187,192 **** --- 187,195 ---- (if (fboundp 'atan) ; preload some constants and (progn ; floating pt. functions if we have float support. (load "emacs-lisp/float-sup"))) + (if (eq system-type 'darwin) + (progn + (load "international/mac-im"))) (message "%s" (garbage-collect)) (load "vc-hooks") --- src/Makefile.in.orig Fri May 21 07:41:40 2004 +++ src/Makefile.in Fri May 21 09:37:42 2004 @@ -570,7 +570,7 @@ #ifdef HAVE_CARBON mac = $(dot)$(dot)/mac/ -MAC_OBJ = mac.o macterm.o macfns.o macmenu.o fontset.o fringe.o image.o +MAC_OBJ = mac.o macterm.o macfns.o macmenu.o fontset.o fringe.o image.o macim.o emacsapp = $(PWD)/$(mac)Emacs.app/ emacsappsrc = ${srcdir}/../mac/Emacs.app/ #endif @@ -597,7 +597,7 @@ in case they are needed there. */ SOME_MACHINE_OBJECTS = sunfns.o dosfns.o msdos.o \ xterm.o xfns.o xmenu.o xselect.o xrdb.o \ - mac.o macterm.o macfns.o macmenu.o fontset.o + mac.o macterm.o macfns.o macmenu.o fontset.o macim.o #ifdef TERMINFO @@ -1218,6 +1218,10 @@ macmenu.o: macmenu.c termhooks.h frame.h window.h dispextern.h macgui.h \ keyboard.h blockinput.h atimer.h systime.h buffer.h macterm.h $(config_h) macterm.o: blockinput.h atimer.h systime.h syssignal.h macterm.h macgui.h \ + frame.h charset.h ccl.h dispextern.h fontset.h termhooks.h termopts.h \ + termchar.h gnu.h disptab.h buffer.h window.h keyboard.h $(INTERVAL_SRC) \ + process.h coding.h $(config_h) +macim.o: blockinput.h atimer.h systime.h syssignal.h macterm.h macgui.h \ frame.h charset.h ccl.h dispextern.h fontset.h termhooks.h termopts.h \ termchar.h gnu.h disptab.h buffer.h window.h keyboard.h $(INTERVAL_SRC) \ process.h coding.h $(config_h) *** src/macterm.c.org Fri Feb 27 09:27:08 2004 --- src/macterm.c Tue Mar 2 09:49:32 2004 *************** extern int inhibit_window_system; *** 271,277 **** QDGlobals qd; /* QuickDraw global information structure. */ #endif - struct frame * x_window_to_frame (struct mac_display_info *, WindowPtr); struct mac_display_info *mac_display_info_for_display (Display *); static void x_update_window_end P_ ((struct window *, int, int)); --- 271,276 ---- *************** mac_draw_window_cursor (w, glyph_row, x, *** 4598,4603 **** --- 4597,4607 ---- default: abort (); } + + #ifdef MAC_OSX + mac_im_set_position(x, y + glyph_row->visible_height); + #endif + } } *************** mac_initialize () *** 8658,8664 **** init_service_handler (); init_quit_char_handler (); ! #endif DisableMenuCommand (NULL, kHICommandQuit); --- 8662,8670 ---- init_service_handler (); init_quit_char_handler (); ! ! mac_im_initialize(); ! #endif DisableMenuCommand (NULL, kHICommandQuit); *** src/macim.c.org Wed Mar 3 11:20:03 2004 --- src/macim.c Wed Mar 3 00:59:39 2004 *************** *** 0 **** --- 1,332 ---- + /* Implementation of Inline Input Method for MacOS X. + Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + + This file is part of GNU Emacs. + + GNU Emacs is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Emacs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Emacs; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + /* Written by Taiichi Hashimoto (taiichi2@mac.com). */ + + + #include + #include + #include + #include + #include "lisp.h" + #include "charset.h" + #include "blockinput.h" + + #include "macterm.h" + + #ifndef MAC_OSX + #include + #endif + + #ifdef MAC_OSX + #undef mktime + #undef DEBUG + #undef free + #undef malloc + #undef realloc + /* Macros max and min defined in lisp.h conflict with those in + precompiled header Carbon.h. */ + #undef max + #undef min + #undef init_process + #include + #undef free + #define free unexec_free + #undef malloc + #define malloc unexec_malloc + #undef realloc + #define realloc unexec_realloc + #undef min + #define min(a, b) ((a) < (b) ? (a) : (b)) + #undef max + #define max(a, b) ((a) > (b) ? (a) : (b)) + #undef init_process + #define init_process emacs_init_process + /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to + obtain events from the event queue. If set to 0, WaitNextEvent is + used instead. */ + #define USE_CARBON_EVENTS 1 + #else /* not MAC_OSX */ + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #if defined (__MRC__) || (__MSL__ >= 0x6000) + #include + #endif + #include + + #if __profile__ + #include + #endif + #endif /* not MAC_OSX */ + + #include "systty.h" + #include "systime.h" + #include "atimer.h" + #include "keymap.h" + + #include + #include + #include + #include + + #include "keyboard.h" + #include "frame.h" + #include "dispextern.h" + #include "fontset.h" + #include "termhooks.h" + #include "termopts.h" + #include "termchar.h" + #include "gnu.h" + #include "disptab.h" + #include "buffer.h" + #include "window.h" + #include "intervals.h" + #include "composite.h" + #include "coding.h" + + #ifdef MAC_OSX + + static EventTypeSpec events[] = { + { kEventClassTextInput, kEventTextInputOffsetToPos }, + { kEventClassTextInput, kEventTextInputUpdateActiveInputArea }, + { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, + { kEventClassTextInput, kEventTextInputPosToOffset }, + { kEventClassTextInput, kEventTextInputGetSelectedText } + }; + + static EventHandlerRef mac_im_handler = NULL; + static EventHandlerUPP mac_im_handlerUPP = NULL; + static TSMDocumentID mac_tsm_doc_id; + + static Lisp_Object Qmac_im_hook; + static Lisp_Object Qmac_im_offset_to_pos; + static Lisp_Object Qmac_im_pos_to_offset; + static Lisp_Object Qmac_im_update_active_input_text; + static Lisp_Object Qmac_im_get_selected_text; + + static Point mac_im_pt; + + pascal OSStatus mac_handle_im_event(EventHandlerCallRef, EventRef, void *); + void mac_im_initialize(void); + + + void mac_im_initialize(void) + { + if(!mac_im_handler) { + OSErr err; + InterfaceTypeList itl = { kUnicodeDocument }; + + err = NewTSMDocument(1, itl, &mac_tsm_doc_id, 715); + if (err != noErr) abort (); + + err = ActivateTSMDocument(mac_tsm_doc_id); + if (err != noErr) abort (); + + err = InstallEventHandler(GetApplicationEventTarget(), + NewEventHandlerUPP(mac_handle_im_event), + GetEventTypeCount(events), + events, + NULL, + &mac_im_handler); + if (err != noErr) abort (); + } + + Qmac_im_hook = intern("mac-im-hook"); + Qmac_im_offset_to_pos = intern("offset-to-pos"); + Qmac_im_pos_to_offset = intern("pos-to-offset"); + Qmac_im_update_active_input_text = intern("update-active-input-text"); + Qmac_im_get_selected_text = intern("get-selected-text"); + } + + void mac_im_set_position(int x, int y) + { + mac_im_pt.h = x; + mac_im_pt.v = y; + LocalToGlobal(&mac_im_pt); + } + + pascal OSStatus + mac_handle_im_event(EventHandlerCallRef er, EventRef event, void *data) + { + UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event); + OSStatus ret = noErr, err; + Lisp_Object argv[256]; + int argc = 0; + + switch(eclass) { + case kEventClassTextInput: + switch(ekind) { + case kEventTextInputOffsetToPos: + { + err = SetEventParameter(event, kEventParamTextInputReplyPoint, + typeQDPoint, sizeof(mac_im_pt), &mac_im_pt); + if(!err == noErr) abort(); + argv[argc++] = Qmac_im_hook; + argv[argc++] = Qmac_im_offset_to_pos; + } + break; + case kEventTextInputPosToOffset: + argv[argc++] = Qmac_im_hook; + argv[argc++] = Qmac_im_pos_to_offset; + break; + case kEventTextInputUpdateActiveInputArea: + { + UInt32 bufsize = 0, unilen = 0; + UniChar *unicode; + CFStringRef cfstring; + unsigned char cstring[1024], estring[4096]; + TextRangeArray *array; + long fixedlen = 0; + int i; + + if (!NILP(Feval(Qbuffer_read_only))) { + ret = eventNotHandledErr; + break; + } + + err = GetEventParameter(event, kEventParamTextInputSendFixLen, + typeLongInteger, NULL, + sizeof(fixedlen), NULL, &fixedlen); + if (err != noErr) abort(); + + err = GetEventParameter(event, + kEventParamTextInputSendText, + typeUnicodeText, + NULL, 0, &bufsize, NULL); + if (err != noErr) abort(); + + if (bufsize) { + unilen = bufsize / sizeof(UniChar); + unicode = (UniChar *)NewPtr(bufsize); + if (!unicode) abort(); + + err = GetEventParameter(event, + kEventParamTextInputSendText, + typeUnicodeText, + NULL, bufsize, NULL, unicode); + if (err != noErr) abort(); + + /* UniChar -> CFString */ + cfstring = CFStringCreateWithCharacters(NULL, unicode, unilen); + if (!cfstring) abort(); + + /* CFString -> CString */ + for (i = 0; i < sizeof(cstring); i++) cstring[i] = '\0'; + CFStringGetCString(cfstring, cstring, sizeof(cstring) - 1, kCFStringEncodingUTF8); + + /* CString -> CString for Emacs */ + for (i = 0; i < sizeof(estring); i++) estring[i] = '\0'; + decode_coding(&keyboard_coding, + cstring, + estring, + strlen(cstring), + sizeof(estring) - 1); + + /* run hook */ + argv[argc++] = Qmac_im_hook; + argv[argc++] = Qmac_im_update_active_input_text; + argv[argc++] = make_string(estring, strlen(estring)); + argv[argc++] = make_number(fixedlen); + + DisposePtr((char *)unicode); + CFRelease(cfstring); + + err = GetEventParameter(event, kEventParamTextInputSendHiliteRng, + typeTextRangeArray, NULL, 0, &bufsize, NULL); + if (bufsize) { + array = (TextRangeArray *)NewPtr(bufsize); + if (!array) abort(); + err = GetEventParameter(event, kEventParamTextInputSendHiliteRng, + typeTextRangeArray, + NULL, bufsize, NULL, array); + + for (i = 0; i < array->fNumOfRanges; i++) { + Lisp_Object pos; + int start, end; + + if (argc < 255) { + start = array->fRange[i].fEnd / sizeof(UniChar); + end = array->fRange[i].fStart / sizeof(UniChar); + pos = Fcons(make_number(start), Qnil); + pos = Fcons(make_number(end), pos); + + switch (array->fRange[i].fHiliteStyle) { + case kCaretPosition: + argv[argc++] = Fcons(intern("caret-position"), pos); + break; + case kRawText: + argv[argc++] = Fcons(intern("raw-text"), pos); + break; + case kSelectedRawText: + argv[argc++] = Fcons(intern("selected-raw-text"), pos); + break; + case kConvertedText: + argv[argc++] = Fcons(intern("converted-text"), pos); + break; + case kSelectedConvertedText: + argv[argc++] = Fcons(intern("selected-converted-text"), pos); + break; + default: + break; + } + } + } + DisposePtr((char *)array); + } + + } else { /* bufsize == 0 */ + /* run hook */ + argv[argc++] = Qmac_im_hook; + argv[argc++] = Qmac_im_update_active_input_text; + argv[argc++] = make_string("", 0); + argv[argc++] = make_number(fixedlen); + } + } + break; + case kEventTextInputGetSelectedText: + break; + case kEventTextInputUnicodeForKeyEvent: + ret = eventNotHandledErr; + break; + default: + break; + } + break; + default: + break; + } + + if (argc) { + Frun_hook_with_args(argc, argv); + redisplay(); + } + + return ret; + } + + #endif *** lisp/international/mac-im.el.org Wed Mar 3 11:19:52 2004 --- lisp/international/mac-im.el Wed Mar 3 10:27:11 2004 *************** *** 0 **** --- 1,93 ---- + ;;; mac-im.el --- Input Method for Mac OS X + + ;; Licensed to the Free Software Foundation. + ;; Copyright (C) 2004 Free Software Foundation, Inc. + + ;; Keywords: input method, Mac OS X + + ;; This file is part of GNU Emacs. + + ;; GNU Emacs is free software; you can redistribute it and/or modify + ;; it under the terms of the GNU General Public License as published by + ;; the Free Software Foundation; either version 2, or (at your option) + ;; any later version. + + ;; GNU Emacs is distributed in the hope that it will be useful, + ;; but WITHOUT ANY WARRANTY; without even the implied warranty of + ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ;; GNU General Public License for more details. + + ;; You should have received a copy of the GNU General Public License + ;; along with GNU Emacs; see the file COPYING. If not, write to the + ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, + ;; Boston, MA 02111-1307, USA. + + (defvar mac-im-on nil) + (defvar mac-im-insert-text-length 0) + + (make-face 'mac-im-face) + (set-face-underline-p 'mac-im-face t) + + (make-face 'mac-im-selection-face) + (set-face-foreground 'mac-im-selection-face "black") + (set-face-background 'mac-im-selection-face "light sky blue") + (set-face-underline-p 'mac-im-selection-face t) + + (add-hook 'mac-im-hook + (lambda (type &rest rest) + (cond ((eq type 'update-active-input-text) + (let ((str (car rest)) + (fix (cadr rest)) + (text-properties (cddr rest))) + (mac-im-clear) + (if (< 0 fix) + (mac-im-insert-and-reset str) + (progn + (mac-im-set-faces text-properties str) + (mac-im-insert str)))))))) + + (defun mac-im-clear () + (setq mac-im-on t) + (delete-backward-char mac-im-insert-text-length)) + + (defun mac-im-insert (str) + (while (string-match(char-to-string 2213) str) + (setq str (replace-match (char-to-string 92) t t str))) + (insert str) + (setq mac-im-insert-text-length (length str))) + + (defun mac-im-insert-and-reset (str) + (mac-im-insert str) + (setq mac-im-on nil) + (setq mac-im-insert-text-length 0)) + + (defun mac-im-set-face (type beg end object) + (cond ((eq type 'caret-position) + object) + ((eq type 'raw-text) + (put 'mac-im-face 'face 'mac-im-face) + (put-text-property beg end 'category 'mac-im-face object) + object) + ((eq type 'selected-raw-text) + (put 'mac-im-face 'face 'mac-im-face) + (put-text-property beg end 'category 'mac-im-face object) + object) + ((eq type 'converted-text) + (put 'mac-im-face 'face 'mac-im-face) + (put-text-property beg end 'category 'mac-im-face object) + object) + ((eq type 'selected-converted-text) + (put 'mac-im-selection-face 'face 'mac-im-selection-face) + (put-text-property beg end 'category 'mac-im-selection-face object) + object) + (t + object))) + + (defun mac-im-set-faces (properties object) + (if (null properties) + object + (mac-im-set-faces (cdr properties) + (mac-im-set-face (car (car properties)) + (car (cdr (car properties))) + (car (cddr (car properties))) + object))))