Changeset 3998

Show
Ignore:
Timestamp:
12/14/05 00:17:42 (2 years ago)
Author:
horiguti
Message:

Change around IME control.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/ChangeLog.Meadow

    r3990 r3998  
     12005-12-13  Kyotaro HORIGUCHI  <horiguti@meadowy.org> 
     2 
     3        * international/meadow.el (mw32-ime-cont-on): New variable. 
     4        (mw32-input-method-noconv-regexp): New variable. 
     5        (mw32-set-ime-if-available): Initialize MW32-IME. 
     6        (mw32-ime-sync-state): Changed. 
     7        (mw32-ime-mode-line-update): Remove redundant parameter. 
     8        (mw32-ime-initialize): Ressurected. Change doc string. Add 
     9        treatment for isearch. 
     10        (mw32-ime-uninitialize): Add treatment for isearch. 
     11        (mw32-isearch-mode-hook-function): New hook function. 
     12        (mw32-ime-state-switch): Move IME initialization into 
     13        mw32-ime-initialize. 
     14        (): Change registration of MW32-IME. 
     15        (mw32-input-method): New function to be used for 
     16        input-method-function. 
     17 
    1182005-11-26  MIYOSHI Masanori  <miyoshi@meadowy.org> 
    219 
  • trunk/lisp/international/meadow.el

    r3945 r3998  
    1 ;;;;; meadow.el ---- For Meadow. 
    21;; 
    32;;   Author H.Miyashita 
     
    155154(defvar mw32-ime-mode-line-format-original nil 
    156155  "Original mode line format.") 
     156(defvar mw32-ime-cont-on t 
     157  "It not nil, IME is always on during current-input-method is MW32-IME.") 
     158(defvar mw32-input-method-noconv-regexp nil 
     159  "Regexp represents printable-chars that does not activate IME.") 
    157160 
    158161(setq search-highlight t) 
     
    267270    (when (and ime (mw32-ime-available)) 
    268271        (setq default-input-method (cdr ime)) 
     272        (mw32-ime-initialize) 
    269273        (define-key global-map [kanji] 'toggle-input-method)))) 
    270274 
     
    327331  (when mw32-ime-buffer-switch-p 
    328332    (with-current-buffer (window-buffer window) 
    329       (let* ((frame (window-frame window)) 
    330              (ime-state (fep-get-mode))) 
    331         (cond 
    332          ((and (not ime-state) 
    333                (equal current-input-method "MW32-IME")) 
    334           (fep-force-on nil) 
    335           (run-hooks 'mw32-ime-on-hook)) 
    336          ((and ime-state 
    337                (not (equal current-input-method "MW32-IME"))) 
    338           (when (= (w32-ime-undetermined-string-length) 0) 
    339             (fep-force-off nil) 
    340             (run-hooks 'mw32-ime-off-hook)))))))) 
     333      (if (window-minibuffer-p) 
     334          (fep-force-off) 
     335        (let* ((frame (window-frame window))) 
     336          (if (string= current-input-method "MW32-IME") 
     337              (run-hooks 'mw32-ime-on-hook) 
     338            (run-hooks 'mw32-ime-off-hook)) 
     339          (if mw32-ime-cont-on 
     340              (if (string= current-input-method "MW32-IME") 
     341                  (if (eq input-method-function 'mw32-input-method) 
     342                      (fep-force-on)) 
     343                (fep-force-off)))))))) 
    341344 
    342345(defun mw32-ime-set-selected-window-buffer-hook (oldbuf newwin newbuf) 
     
    349352  (cond 
    350353   (mw32-ime-show-mode-line 
    351     (unless (window-minibuffer-p (selected-window)
     354    (unless (window-minibuffer-p
    352355      (setq mw32-ime-mode-line-state-indicator 
    353356            (nth (if (fep-get-mode) 1 2) 
     
    384387 
    385388(defun mw32-ime-initialize () 
    386   "This is obsoleted function. It is unnecessary to call this 
    387 function to initialize MW32-IME." 
     389  "Initialize MW32-IME. It is unnecessary to call this function explicitly." 
    388390  (cond 
    389391   ((and (eq system-type 'windows-nt) 
     
    397399      (mw32-ime-init-mode-line-display) 
    398400      (mw32-ime-mode-line-update) 
    399       (add-hook 'select-window-functions 
    400                 'mw32-ime-select-window-hook) 
     401      (add-hook 'select-window-functions 'mw32-ime-select-window-hook) 
    401402      (add-hook 'set-selected-window-buffer-functions 
    402403                'mw32-ime-set-selected-window-buffer-hook) 
    403       (if coding-system 
    404           (set-keyboard-coding-system (cdr coding-system))) 
    405       (define-key global-map [kanji] 'toggle-input-method))))) 
    406  
     404       
     405      (add-hook 'isearch-mode-hook 'mw32-isearch-mode-hook-function) 
     406      (defadvice isearch-toggle-input-method (after mw32-fep-off activate) 
     407        "Deactivate fep when mw32-ime-cont-on is not nil." 
     408        (if mw32-ime-cont-on (fep-force-off))) 
     409      (defadvice isearch-done (after mw32-fep-on activate) 
     410        "Deactivate fep when mw32-ime-cont-on is not nil." 
     411        (if (and mw32-ime-cont-on 
     412                 (string= current-input-method "MW32-IME")) 
     413            (fep-force-on))))))) 
     414 
     415(defun mw32-isearch-mode-hook-function () 
     416  (if mw32-ime-cont-on 
     417      (fep-force-off)) 
     418  (define-key isearch-mode-map [kanji] 'isearch-toggle-input-method) 
     419  (define-key isearch-mode-map [compend] 'ignore)) 
     420       
     421     
    407422(defun mw32-ime-uninitialize () 
    408423  (cond ((and (eq system-type 'windows-nt) 
     
    415430                      'mw32-ime-select-window-hook) 
    416431         (remove-hook 'set-selected-window-buffer-functions 
    417                       'mw32-ime-set-selected-window-buffer-hook)))) 
    418  
     432                      'mw32-ime-set-selected-window-buffer-hook) 
     433         (remove-hook 'isearch-mode-hook 'mw32-isearch-mode-hook-function) 
     434         (defadvice isearch-toggle-input-method (after mw32-fep-off disable)) 
     435         (defadvice isearch-done (after mw32-fep-on disable))))) 
     436          
    419437(defun mw32-ime-exit-from-minibuffer () 
    420438  (inactivate-input-method) 
     
    423441 
    424442(defun mw32-ime-state-switch (&optional arg) 
     443  (kill-local-variable 'input-method-function) 
     444  (if (fep-get-mode) 
     445      (fep-force-off)) 
    425446  (if arg 
    426447      (progn 
    427448        (when (null (memq 'mw32-ime-select-window-hook 
    428449                          select-window-functions)) 
    429           (add-hook 'select-window-functions 'mw32-ime-select-window-hook) 
    430           (add-hook 'set-selected-window-buffer-functions 
    431                     'mw32-ime-set-selected-window-buffer-hook) 
    432           (mw32-ime-init-mode-line-display)) 
    433  
     450          (mw32-ime-initialize)) 
    434451        (setq inactivate-current-input-method-function 
    435452              'mw32-ime-state-switch) 
     
    437454        (run-hooks 'mw32-ime-on-hook) 
    438455        (setq describe-current-input-method-function nil) 
    439         (when (eq (selected-window) (minibuffer-window)
     456        (when (window-minibuffer-p
    440457          (add-hook 'minibuffer-exit-hook 'mw32-ime-exit-from-minibuffer)) 
    441         (fep-force-on)) 
     458        (make-local-variable 'input-method-function) 
     459        (setq input-method-function 'mw32-input-method) 
     460        (if (and mw32-ime-cont-on 
     461                 (not (window-minibuffer-p))) 
     462            (fep-force-on))) 
    442463    (setq current-input-method nil) 
    443464    (run-hooks 'input-method-inactivate-hook) 
    444465    (run-hooks 'mw32-ime-off-hook) 
    445     (setq describe-current-input-method-function nil) 
    446     (fep-force-off)) 
     466    (setq describe-current-input-method-function nil)) 
    447467  (mw32-ime-mode-line-update)) 
    448468 
    449 (register-input-method "MW32-IME" "Japanese" 'mw32-ime-state-switch "
     469(register-input-method "MW32-IME" "Japanese" 'mw32-ime-state-switch "A‚ 
    450470                       "MW32 System IME") 
    451471 
     
    493513          (t 'static-color)))) 
    494514 
     515(defun mw32-input-method (key) 
     516  "Input method function for IME." 
     517  (if (or 
     518       (let ((case-fold-search nil)) 
     519         (and key 
     520              mw32-input-method-noconv-regexp 
     521              (string-match mw32-input-method-noconv-regexp 
     522                            (char-to-string key)))) 
     523       (fep-get-mode)) 
     524      (list key) 
     525    (sit-for 0) 
     526    (fep-force-on) 
     527        (let* ((pos (point)) 
     528               (ov (make-overlay (point) (1+ (point)))) 
     529               (ret (mw32-ime-input-method-function (char-to-string key))) 
     530               (result (append (car ret) nil))) 
     531      ;;; Continue to conversion if composition string cannot be 
     532      ;;; convert into single ascii character. 
     533          (unwind-protect 
     534              (while (or 
     535                      (> (length (cadr ret)) 1) 
     536                      (and 
     537                       (cadr ret) 
     538                       (not (eq (string-to-char (japanese-hankaku (cadr ret))) 
     539                                (caddr ret))))) 
     540                (insert (car ret)) 
     541                (move-overlay ov pos (point)) 
     542                (if input-method-highlight-flag 
     543                    (overlay-put ov 'face 'underline)) 
     544                (sit-for 0) 
     545                (setq ret (mw32-ime-input-method-function)) 
     546                (setq result (append result (append (car ret) nil)))) 
     547            (if (and (cadr ret) 
     548                     (eq (length (cadr ret)) 1) 
     549                     (eq (string-to-char (japanese-hankaku (cadr ret))) 
     550                         (caddr ret))) 
     551                (setq unread-input-method-events 
     552                      (cons (caddr ret) unread-input-method-events))) 
     553            (fep-force-off) 
     554            (delete-region pos (point)) 
     555            (delete-overlay ov)) 
     556          result))) 
     557 
    495558;; dummy vals. 
    496559(defun x-server-max-request-size (&optional display) 65535) 
  • trunk/src/ChangeLog.Meadow

    r3997 r3998  
     12005-12-13  Kyotaro HORIGUCHI  <horiguti@meadowy.org> 
     2 
     3        * mw32ime.c (IMMGETVIRTUALKEYPROC): New typedef. 
     4        (ImmGetVirtualKeyProc): New function pointer. 
     5        (input_method_function_event): New event object. 
     6        (waiting_on_main_thread): New variable. 
     7        (input_method_function_string): New variable. 
     8        (last_ime_keycode): New variable. 
     9        (last_ime_keymod): New variable. 
     10        (mw32_ime_get_virtual_key): New function. 
     11        (mw32_ime_record_keycode): New function. 
     12        (mw32_ime_set_composition_string): New function. 
     13        (mw32_get_ime_composition_string): Renamed to 
     14        mw32_get_ime_result_string. Add process for 
     15        mw32-ime-input-method-function. 
     16        (mw32_ime_get_composition_string): New function. 
     17        (mw32_ime_control_init): Initialize ImmGetVirtualKeyProc and 
     18        input_method_function_event. 
     19        (conversion_agent_wndproc<WM_MULE_IMM_GET_COMPOSISION_STRING>): 
     20        Message renamed to WM_MULE_IMM_GET_RESULT_STRING and ditto about 
     21        the calling function. 
     22        (mw32_ime_cancel_input_function): New function. 
     23        (mw32-ime-input-method-function): New lisp function. 
     24        (fep-force-on): Detail doc string. 
     25        (fep-force-off): Ditto. 
     26        (cmode_list): New static data for imm-get-conversion-status. 
     27        (imm-get-conversion-status): New lisp function. 
     28        (w32-set-ime-mode): Changed. 
     29 
     30        * mw32term.c (mw32_message_loop<WM_KEYDOWN>): Record virtual 
     31        keycode of VK_PROCESSKEY. 
     32        (mw32_message_loop<WM_MULE_IME_REPORT>): Don't enter the loop when 
     33        lpStr is null. 
     34 
     35        * mw32term.h (WM_MULE_IMM_GET_RESULT_STRING): New symbol. 
     36        (WM_MULE_IMM_GET_SET_MODE): Numerical ID is shifted. 
     37 
     38        * mw32fns.c (mw32_WndProc<WM_IME_COMPOSITION>): 
     39        mw32_get_ime_composition_string() is renamed to 
     40        mw32_get_ime_result_string(). Cancel input method function when no 
     41        composition string is left. 
     42        (mw32_WndProc<WM_WM_MULE_IMM_SET_COMPOSITION_STRING>): New message 
     43        handler. 
     44        (mw32_WndProc<WM_WM_MULE_IMM_GET_COMPOSITION_STRING>): New message 
     45        handler. 
     46 
    1472005-12-13  Kyotaro HORIGUCHI  <horiguti@meadowy.org> 
    248 
     
    73119        (set-window-configuration): Ditto. 
    74120 
     121        * eval.c (signal): Remove W32_UNBLOCK_INPUT. 
     122         
    751232005-12-01  MIYOSHI Masanori  <miyoshi@meadowy.org> 
    76124 
  • trunk/src/mw32fns.c

    r3997 r3998  
    24482448      if (lParam & GCS_RESULTSTR) 
    24492449        { 
    2450           extern BOOL mw32_get_ime_composion_string (HWND); 
    2451           if (mw32_get_ime_composition_string (hwnd)) 
     2450          extern BOOL mw32_get_ime_result_string (HWND); 
     2451          if (mw32_get_ime_result_string (hwnd)) 
    24522452            return 0; 
    24532453          else 
    24542454            break; 
    24552455        } 
     2456       
     2457      if (mw32_get_ime_undetermined_string_length (hwnd) == 0) 
     2458        { /* Cancelling composition string */ 
     2459          mw32_ime_cancel_input_function (); 
     2460        }        
     2461       
    24562462      goto dflt; 
    24572463    } 
     
    25032509    mw32_set_ime_conv_window (hwnd, (struct window *) wParam); 
    25042510    break; 
     2511 
     2512  case WM_MULE_IMM_SET_COMPOSITION_STRING: 
     2513    mw32_ime_set_composition_string (hwnd, (char*) wParam); 
     2514    break; 
     2515 
     2516  case WM_MULE_IMM_GET_COMPOSITION_STRING: 
     2517    mw32_ime_get_composition_string (hwnd); 
     2518    break; 
     2519 
    25052520#endif /* not MEADOW and IME_CONTROL */ 
    25062521 
  • trunk/src/mw32ime.c

    r3996 r3998  
    144144typedef BOOL (WINAPI *IMMISIMEPROC)(HKL); 
    145145IMMISIMEPROC ImmIsIMEProc; 
     146typedef UINT (WINAPI *IMMGETVIRTUALKEYPROC)(HWND); 
     147IMMGETVIRTUALKEYPROC ImmGetVirtualKeyProc; 
    146148 
    147149extern Lisp_Object Vime_control; 
    148150 
    149151static WPARAM wIMEOpen; 
     152 
     153static HANDLE input_method_function_event = INVALID_HANDLE_VALUE; 
     154static int waiting_on_main_thread = FALSE; 
     155static HANDLE input_method_function_string = INVALID_HANDLE_VALUE; 
    150156 
    151157Lisp_Object Vime_control; 
     
    153159Lisp_Object Qim_info; 
    154160 
    155  
    156161int IME_event_off_count; 
     162static int last_ime_vkeycode; 
     163static int last_ime_vkeymod; 
     164 
     165int 
     166mw32_ime_get_virtual_key (HWND hwnd) 
     167{ 
     168  return (ImmGetVirtualKeyProc)(hwnd); 
     169} 
     170 
     171void 
     172mw32_ime_record_keycode (int keycode, int keymod) 
     173{ 
     174  last_ime_vkeycode = keycode; 
     175  last_ime_vkeymod  = keymod; 
     176} 
    157177 
    158178void 
     
    185205 
    186206void 
     207mw32_ime_set_composition_string (HWND hwnd, char* str) 
     208{ 
     209  HIMC himc; 
     210 
     211  himc = (ImmGetContextProc) (hwnd); 
     212  (ImmSetCompositionStringProc) (himc, SCS_SETSTR, str, strlen (str), NULL, 0); 
     213  (ImmReleaseContextProc) (hwnd, himc); 
     214} 
     215 
     216void 
    187217mw32_set_ime_status (HWND hwnd, int openp) 
    188218{ 
     
    240270 
    241271BOOL 
    242 mw32_get_ime_composition_string (HWND hwnd) 
     272mw32_get_ime_result_string (HWND hwnd) 
    243273{ 
    244274  HIMC hIMC; 
     
    254284  size = (ImmGetCompositionStringProc) (hIMC, GCS_RESULTSTR, NULL, 0); 
    255285  size += sizeof (TCHAR); 
    256   himestr = GlobalAlloc (GHND, size); 
     286 
     287  input_method_function_string = himestr = GlobalAlloc (GHND, size); 
    257288  if (!himestr) abort (); 
    258289  lpstr = GlobalLock (himestr); 
     
    260291  (ImmGetCompositionStringProc) (hIMC, GCS_RESULTSTR, lpstr, size); 
    261292  (ImmReleaseContextProc) (hwnd, hIMC); 
     293  lpstr [size-1] = 0; 
    262294  GlobalUnlock (himestr); 
    263   f = mw32_window_to_frame (dpyinfo, hwnd); 
    264   PostMessage (NULL, WM_MULE_IME_REPORT, 
    265                (WPARAM) himestr, (LPARAM) f); 
     295 
     296  if (waiting_on_main_thread) 
     297    SetEvent (input_method_function_event); 
     298  else 
     299    { 
     300      f = mw32_window_to_frame (dpyinfo, hwnd); 
     301      PostMessage (NULL, WM_MULE_IME_REPORT, 
     302                   (WPARAM) himestr, (LPARAM) f); 
     303    }    
    266304  return TRUE; 
    267305} 
    268306 
     307BOOL 
     308mw32_ime_get_composition_string (HWND hwnd) 
     309{ 
     310  HIMC hIMC; 
     311  int size; 
     312  HANDLE himestr; 
     313  LPSTR lpstr; 
     314  struct frame *f; 
     315  struct mw32_display_info *dpyinfo = GET_MW32_DISPLAY_INFO (hwnd); 
     316 
     317  hIMC = (ImmGetContextProc) (hwnd); 
     318  if (!hIMC) return FALSE; 
     319 
     320  size = (ImmGetCompositionStringProc) (hIMC, GCS_COMPSTR, NULL, 0); 
     321  size += sizeof (TCHAR); 
     322 
     323  input_method_function_string = himestr = GlobalAlloc (GHND, size); 
     324  if (!himestr) abort (); 
     325  lpstr = GlobalLock (himestr); 
     326  if (!lpstr) abort (); 
     327  (ImmGetCompositionStringProc) (hIMC, GCS_COMPSTR, lpstr, size); 
     328  (ImmReleaseContextProc) (hwnd, hIMC); 
     329  lpstr [size-1] = 0; 
     330  GlobalUnlock (himestr); 
     331 
     332  if (waiting_on_main_thread) 
     333    SetEvent (input_method_function_event); 
     334  else 
     335    { 
     336      f = mw32_window_to_frame (dpyinfo, hwnd); 
     337      PostMessage (NULL, WM_MULE_IME_REPORT, 
     338                   (WPARAM) himestr, (LPARAM) f); 
     339    }    
     340  return TRUE; 
     341} 
     342 
    269343#ifdef IME_RECONVERSION 
    270  
     344/* TODO: This is dangerous because manipulating buffer contnet in 
     345   message-thread without synchronizing. This must be fixed. */ 
    271346int 
    272347mw32_get_ime_reconversion_string (HWND hwnd, WPARAM wParam, 
     
    474549        GetProcAddress (hImm32, 
    475550                        "ImmGetHotKey"); 
    476  
    477551      ImmIsIMEProc = 
    478552        (IMMISIMEPROC) 
    479553        GetProcAddress (hImm32, 
    480554                        "ImmIsIME"); 
    481  
     555      ImmGetVirtualKeyProc = 
     556        (IMMGETVIRTUALKEYPROC) 
     557        GetProcAddress (hImm32, 
     558                        "ImmGetVirtualKey"); 
    482559      if (ImmGetOpenStatusProc && 
    483560          ImmSetOpenStatusProc && 
     
    499576          ImmGetCandidateListCountProc && 
    500577          ImmGetHotKeyProc && 
    501           ImmIsIMEProc) 
     578          ImmIsIMEProc && 
     579          ImmGetVirtualKeyProc) 
    502580        { 
    503581          fIME = TRUE; 
    504582          Vime_control = Qt; 
     583          input_method_function_event = CreateEvent (NULL, FALSE, FALSE, NULL); 
    505584        } 
    506585    } 
     
    592671#endif 
    593672 
    594     case WM_MULE_IMM_GET_COMPOSITION_STRING: 
    595       return mw32_get_ime_composition_string (hwnd); 
     673    case WM_MULE_IMM_GET_RESULT_STRING: 
     674      return mw32_get_ime_result_string (hwnd); 
    596675 
    597676    case WM_MULE_IMM_NOTIFY: 
     
    709788} 
    710789 
     790void 
     791mw32_ime_cancel_input_function (void) 
     792 { 
     793   waiting_on_main_thread = FALSE; 
     794    
     795  if (input_method_function_string != INVALID_HANDLE_VALUE) 
     796      GlobalFree (input_method_function_string); 
     797 
     798  input_method_function_string = INVALID_HANDLE_VALUE; 
     799   
     800  SetEvent (input_method_function_event); 
     801}        
     802 
     803Lisp_Object mw32_ime_input_method_function_unwind (arg) 
     804  Lisp_Object arg; 
     805{ 
     806  mw32_ime_cancel_input_function (); 
     807 
     808  if (NILP (arg)) 
     809    Ffep_force_off (); 
     810 
     811  return Qnil; 
     812} 
    711813  
    712814 
     
    714816  Emacs Lisp function entries 
    715817*/ 
     818 
     819 
     820DEFUN ("mw32-ime-input-method-function", 
     821       Fmw32_ime_input_method_function, Smw32_ime_input_method_function, 
     822       0, 1, 0, doc: /* Low level input method function for IME. 
     823STR is initial composition string. 
     824Returns (RESULTSTR COMPSTR LASTCHAR) where RESULTSTR is the conversion result 
     825string, COMPSTR is the composition string left behind in conversion, and 
     826LASTCHAR is the keycode of the last input during conversion. */) 
     827  (str) 
     828{ 
     829  HWND hwnd; 
     830  int count = SPECPDL_INDEX (); 
     831  Lisp_Object resultstr, compstr, result; 
     832  struct frame *f; 
     833  struct mw32_display_info *dpyinfo; 
     834  HANDLE hstr; 
     835 
     836  hwnd = FRAME_MW32_WINDOW (XFRAME (selected_frame)); 
     837  dpyinfo = GET_MW32_DISPLAY_INFO (hwnd); 
     838  f = mw32_window_to_frame (dpyinfo, hwnd); 
     839 
     840  record_unwind_protect (mw32_ime_input_method_function_unwind, 
     841                         Ffep_get_mode ()); 
     842  waiting_on_main_thread = TRUE; 
     843  ResetEvent (input_method_function_event); 
     844 
     845  result = Qnil; 
     846  Ffep_force_on (); 
     847 
     848  /* If new ascii (expected..) key event comes after this function 
     849     invoked, get it and add to composition string. */ 
     850  if (kbd_buffer_events_waiting (0)) 
     851    { 
     852      Lisp_Object kseq, args[2]; 
     853 
     854      kseq = call5 (intern ("read-key-sequence"), Qnil, Qnil, Qnil, Qnil, Qnil); 
     855      if (STRINGP (kseq)) 
     856        { 
     857          args[0] = str; 
     858          args[1] = kseq; 
     859          str = Fconcat (2, args); 
     860        } 
     861    } 
     862  fflush (stdout); 
     863  if (STRINGP (str)) 
     864    { 
     865      str = ENCODE_SYSTEM (str); 
     866      SendMessage (hwnd, WM_MULE_IMM_SET_COMPOSITION_STRING, 
     867                   (WPARAM)(SDATA (str)), 0); 
     868    } 
     869 
     870  mw32_set_ime_conv_window (hwnd, 
     871                            cursor_in_echo_area ? 
     872                            XWINDOW (f->minibuffer_window): 
     873                            XWINDOW (f->selected_window)); 
     874 
     875  /* Rescue from dead block. This may not happen. */ 
     876  while (WaitForSingleObject (input_method_function_event, 500L) 
     877         == WAIT_TIMEOUT) 
     878    QUIT; 
     879 
     880  hstr = input_method_function_string; 
     881  input_method_function_string = INVALID_HANDLE_VALUE; 
     882  resultstr = compstr = result = Qnil; 
     883   
     884  if (hstr != INVALID_HANDLE_VALUE) 
     885    { 
     886      char* str = GlobalLock (hstr); 
     887      if (str) 
     888        { 
     889          resultstr = make_string (str, strlen (str)); 
     890          resultstr = DECODE_SYSTEM (resultstr); 
     891        }        
     892       
     893      GlobalUnlock (hstr); 
     894      GlobalFree (hstr); 
     895    } 
     896 
     897  waiting_on_main_thread = TRUE; 
     898  ResetEvent (input_method_function_event); 
     899 
     900  SendMessage (hwnd, WM_MULE_IMM_GET_COMPOSITION_STRING, 0, 0); 
     901  while (WaitForSingleObject (input_method_function_event, 500L) 
     902         == WAIT_TIMEOUT) 
     903    QUIT; 
     904 
     905  if (hstr != INVALID_HANDLE_VALUE) 
     906    { 
     907      char* str = GlobalLock (hstr); 
     908      if (str) 
     909        { 
     910          compstr = make_string (str, strlen (str)); 
     911          compstr = DECODE_SYSTEM (compstr); 
     912        }        
     913       
     914      GlobalUnlock (hstr); 
     915      GlobalFree (hstr); 
     916    } 
     917 
     918  result = Fcons (resultstr, 
     919                  Fcons (compstr, 
     920                         Fcons (make_number (last_ime_vkeymod ? 0 
     921                                             : last_ime_vkeycode), 
     922                                Qnil))); 
     923 
     924  return unbind_to (count, result); 
     925} 
    716926 
    717927DEFUN ("mw32-ime-available", Fmw32_ime_available, Smw32_ime_available, 
     
    735945 
    736946DEFUN ("fep-force-on", Ffep_force_on, Sfep_force_on, 0, 1, 0, 
    737        doc: /* Force status of IME open.  */) 
     947       doc: /* Force status of IME open. 
     948If EVENPT is not nil, this function also creates [kanji] key event. */) 
    738949  (eventp) 
    739950     Lisp_Object eventp; 
     
    741952  if (fIME && !NILP (Vime_control)) 
    742953    { 
    743       HIMC himc; 
    744954      HWND hwnd; 
    745955 
     
    759969 
    760970DEFUN ("fep-force-off", Ffep_force_off, Sfep_force_off, 0, 1, 0, 
    761        doc: /* Force status of IME close.  */) 
     971       doc: /* Force status of IME close. 
     972If EVENTP is not nil, this function also creates [kanji] key event. */) 
    762973  (eventp) 
    763974     Lisp_Object eventp; 
     
    765976  if (fIME && !NILP (Vime_control)) 
    766977    { 
    767       HIMC himc; 
    768978      HWND hwnd; 
    769979 
     
    8311041} 
    8321042 
     1043  static struct { 
     1044    DWORD mask; 
     1045    char* posi_symbol; 
     1046    char* nega_symbol; 
     1047  } cmode_list[] = { 
     1048    {IME_CMODE_SYMBOL,          "symbol",       "nosymbol"}, 
     1049    {IME_CMODE_SOFTKBD,         "softkbd",      "nosoftkbd"}, 
     1050    {IME_CMODE_ROMAN,           "roman",        "noroman"}, 
     1051    {IME_CMODE_NOCONVERSION,    "noconversion", "conversion"}, 
     1052    {IME_CMODE_NATIVE   ,       "native",       "nonative"}, 
     1053    {IME_CMODE_KATAKANA,        "katakana",     "nokatakana"}, 
     1054    {IME_CMODE_HANJACONVERT,    "hanja",        "nohanja"}, 
     1055    {IME_CMODE_FULLSHAPE,       "fullshape",    "halfshape"}, 
     1056    {IME_CMODE_FIXED,           "fixed",        "nofixed"}, 
     1057    {IME_CMODE_EUDC,            "eudc",         "noeudc"}, 
     1058    {IME_CMODE_CHARCODE,        "charcode",     "nocharcode"}, 
     1059    /* compatibility */ 
     1060    {IME_CMODE_CHARCODE,        "code",         "nocode"}, 
     1061    {IME_CMODE_HANJACONVERT,    "kanji",        "nokanji"}, 
     1062    {IME_CMODE_KATAKANA,        "katakana",     "hiragana"}, 
     1063    {0,                         NULL} 
     1064  }; 
     1065   
     1066 
     1067DEFUN ("imm-get-conversion-status", 
     1068        Fimm_get_conversion_status, Simm_get_conversion_status,  
     1069       0, 0, 0, doc: /* not documented */) 
     1070  () 
     1071{ 
     1072  DWORD dwConversion, dwSentence; 
     1073  HIMC himc; 
     1074  HWND hwnd; 
     1075  Lisp_Object ret; 
     1076  int i, used; 
     1077 
     1078  if (! fIME ||  NILP (Vime_control)) 
     1079    return Qnil; 
     1080 
     1081  hwnd = FRAME_MW32_WINDOW (SELECTED_FRAME ()); 
     1082  himc = (ImmGetContextProc) (hwnd); 
     1083  ret = Qnil; 
     1084  used = 0; 
     1085     
     1086  if (ImmGetConversionStatusProc 
     1087      && ImmGetConversionStatusProc (himc, &dwConversion, &dwSentence)) 
     1088    { 
     1089      for (i = 0 ; cmode_list[i].mask ; i++) 
     1090        { 
     1091          if (! (used & cmode_list[i].mask)) 
     1092            { 
     1093              used |= cmode_list[i].mask; 
     1094               
     1095              if (dwConversion & cmode_list[i].mask) 
     1096                ret = Fcons (intern (cmode_list[i].posi_symbol), ret); 
     1097              else 
     1098                ret = Fcons (intern (cmode_list[i].nega_symbol), ret); 
     1099            } 
     1100        } 
     1101    }    
     1102   
     1103  (ImmReleaseContextProc) (hwnd, himc); 
     1104  return ret; 
     1105} 
     1106 
     1107 
    8331108DEFUN ("w32-set-ime-mode", 
    8341109       Fw32_set_ime_mode, 
     
    8521127    { 
    8531128      HWND hwnd; 
    854       int ret; 
     1129      int i, done, ret; 
    8551130      int newmode, mask; 
    8561131 
    8571132      newmode = 0; 
    8581133      mask = 0; 
     1134      done = 0; 
     1135 
     1136      for (i = 0 ; cmode_list[i].mask ; i++) 
     1137        { 
     1138          if (EQ (mode, intern (cmode_list[i].posi_symbol))) 
     1139            { 
     1140              newmode |= cmode_list[i].mask; 
     1141              mask |= cmode_list[i].mask; 
     1142              done = 1; 
     1143            } 
     1144          else if (EQ (mode, intern (cmode_list[i].nega_symbol))) 
     1145            { 
     1146              newmode &= ~cmode_list[i].mask; 
     1147              mask |= cmode_list[i].mask; 
     1148              done = 1; 
     1149            } 
     1150        } 
     1151 
     1152      if (! done) 
     1153        error ("unknown mode!!"); 
    8591154 
    8601155      hwnd = FRAME_MW32_WINDOW (f); 
    861  
    862       if (EQ (mode, intern ("katakana"))) 
    863         { 
    864           newmode |= IME_CMODE_KATAKANA; 
    865           mask |= IME_CMODE_KATAKANA; 
    866         } 
    867       else if (EQ (mode, intern ("hiragana"))) 
    868         { 
    869           newmode &= ~IME_CMODE_KATAKANA; 
    870           mask |= IME_CMODE_KATAKANA; 
    871         } 
    872       else if (EQ (mode, intern ("kanji"))) 
    873         { 
    874           newmode |= IME_CMODE_HANJACONVERT; 
    875           mask |= IME_CMODE_HANJACONVERT; 
    876         } 
    877       else if (EQ (mode, intern ("nokanji"))) 
    878         { 
    879           newmode &= ~IME_CMODE_HANJACONVERT; 
    880           mask |= IME_CMODE_HANJACONVERT; 
    881         } 
    882       else if (EQ (mode, intern ("code"))) 
    883         { 
    884           newmode |= IME_CMODE_CHARCODE; 
    885           mask |= IME_CMODE_CHARCODE; 
    886         } 
    887       else if (EQ (mode, intern ("nocode"))) 
    888         { 
    889           newmode &= ~IME_CMODE_CHARCODE; 
    890           mask |= IME_CMODE_CHARCODE; 
    891         } 
    892       else if (EQ (mode, intern ("noconvert"))) 
    893         { 
    894           newmode |= IME_CMODE_NOCONVERSION; 
    895           mask |= IME_CMODE_NOCONVERSION; 
    896         } 
    897       else if (EQ (mode, intern ("convert"))) 
    898         { 
    899           newmode &= ~IME_CMODE_NOCONVERSION; 
    900           mask |= IME_CMODE_NOCONVERSION; 
    901         } 
    902       else 
    903         error ("unknown mode!!"); 
    904  
    9051156      ret = SendMessage (hwnd, WM_MULE_IMM_SET_MODE, 
    9061157                         (WPARAM) newmode, (LPARAM) mask); 
     
    15821833  DEFVAR_LISP ("ime-control", &Vime_control, doc: /* IME control flag  */); 
    15831834 
     1835  defsubr (&Simm_get_conversion_status); 
     1836  defsubr (&Smw32_ime_input_method_function); 
    15841837  defsubr (&Smw32_ime_available); 
    15851838  defsubr (&Smw32_input_language_code); 
  • trunk/src/mw32term.c

    r3997 r3998  
    45744574              int ocount = count; 
    45754575 
     4576              if (msg.wParam == VK_PROCESSKEY) 
     4577                { 
     4578                  int vkey = mw32_ime_get_virtual_key (msg.hwnd); 
     4579                  keyflag = 
     4580                    mw32_emacs_translate_message (dpyinfo, 1, vkey, 
     4581                                                  &keycode, &keymod); 
     4582                  mw32_ime_record_keycode (keycode, keymod); 
     4583                } 
    45764584              keyflag = mw32_emacs_translate_message (dpyinfo, 1, msg.wParam, 
    45774585                                                      &keycode, &keymod); 
     
    46614669              { 
    46624670                lpStr = GlobalLock (hw32_ime_string); 
    4663                 while (1
     4671                while (lpStr
    46644672                  { 
    46654673                    EVENT_INIT (buf); 
  • trunk/src/mw32term.h

    r3997 r3998  
    10001000#define WM_MULE_IMM_SET_COMPOSITION_STRING      (WM_USER+2303) 
    10011001#define WM_MULE_IMM_GET_COMPOSITION_STRING      (WM_USER+2304) 
    1002 #define WM_MULE_IMM_SET_MODE                    (WM_USER+2305) 
     1002#define WM_MULE_IMM_GET_RESULT_STRING           (WM_USER+2305) 
     1003#define WM_MULE_IMM_SET_MODE                    (WM_USER+2306) 
    10031004#define WM_MULE_IMM_NOTIFY                      (WM_USER+2310) 
    10041005#define WM_MULE_IMM_GET_UNDETERMINED_STRING_LENGTH      (WM_USER+2320)