-
Notifications
You must be signed in to change notification settings - Fork 3
/
emacs-26.3-windows-ime-20191231.patch
2123 lines (2061 loc) · 62.2 KB
/
emacs-26.3-windows-ime-20191231.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -urN emacs-26.3.orig/configure.ac emacs-26.3/configure.ac
--- emacs-26.3.orig/configure.ac 2019-09-05 02:17:58.363369200 +0900
+++ emacs-26.3/configure.ac 2019-09-05 02:18:30.880905400 +0900
@@ -368,6 +368,10 @@
On by default on macOS.])],[],[with_ns=maybe])
OPTION_DEFAULT_OFF([w32], [use native MS Windows GUI in a Cygwin build])
+OPTION_DEFAULT_ON([w32-ime], [don't compile with W32-IME support])
+OPTION_DEFAULT_ON([reconversion], [don't compile with RECONVERSION support])
+OPTION_DEFAULT_ON([documentfeed], [don't compile with DOCUMENTFEED support])
+
OPTION_DEFAULT_ON([gpm],[don't use -lgpm for mouse support on a GNU/Linux console])
OPTION_DEFAULT_ON([dbus],[don't compile with D-Bus support])
AC_ARG_WITH([gconf],[AS_HELP_STRING([--with-gconf],
@@ -5351,6 +5355,42 @@
ACL_SUMMARY=no
fi
+USE_W32_IME=no
+if test "${HAVE_W32}" = "yes"; then
+ if test "${with_w32_ime}" != "no"; then
+ USE_W32_IME=yes
+ AC_DEFINE(USE_W32_IME, 1, [Define to support W32-IME.])
+
+ RECONVERSION=no
+ if test "${with_reconversion}" != "no"; then
+ AC_CACHE_CHECK([whether RECONVERTSTRING is declared],
+ emacs_cv_have_reconvertstring,
+ [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#include <windows.h>
+#include <imm.h>]], [[RECONVERTSTRING]])],
+ emacs_cv_have_reconvertstring=yes, emacs_cv_have_reconvertstring=no)])
+ if test "$emacs_cv_have_reconvertstring" = "yes"; then
+ RECONVERSION=yes
+ AC_DEFINE(RECONVERSION, 1, [Define to support RECONVERSION.])
+ AC_DEFINE(HAVE_RECONVERTSTRING, 1, [Define to 1 if you have RECONVERTSTRING.])
+
+ DOCUMENTFEED=no
+ if test "${with_documentfeed}" != "no"; then
+ AC_CHECK_DECL(IMR_DOCUMENTFEED, HAVE_IMR_DOCUMENTFEED=yes,
+ HAVE_IMR_DOCUMENTFEED=no,[[
+#include <windows.h>
+#include <imm.h>]])
+ if test "$ac_cv_have_decl_IMR_DOCUMENTFEED" = "yes"; then
+ DOCUMENTFEED=yes
+ AC_DEFINE(DOCUMENTFEED, 1, [Define to support DOCUMENTFEED.])
+ AC_DEFINE(HAVE_IMR_DOCUMENTFEED, 1, [Define to 1 if you have IMR_DOCUMENTFEED.])
+ fi
+ fi
+ fi
+ fi
+ fi
+fi
+
emacs_standard_dirs='Standard dirs'
AS_ECHO(["
Configured for '${canonical}'.
@@ -5394,6 +5434,10 @@
AS_VAR_APPEND([emacs_config_features], ["$optsep$opt"])
optsep=' '
done
+if test "${USE_W32_IME}" = "yes"; then
+ opt=W32_IME
+ AS_VAR_APPEND([emacs_config_features], ["$optsep$opt"])
+fi
AC_DEFINE_UNQUOTED(EMACS_CONFIG_FEATURES, "${emacs_config_features}",
[Summary of some of the main features enabled by configure.])
@@ -5429,6 +5473,16 @@
Does Emacs have threading support in lisp? ${threads_enabled}
"])
+if test "${HAVE_W32}" = "yes"; then
+ AS_ECHO([" Does Emacs support W32-IME? ${USE_W32_IME}"])
+ if test "${USE_W32_IME}" = "yes"; then
+ AS_ECHO([" Does Emacs support RECONVERSION? ${RECONVERSION}"])
+ if test "${RECONVERSION}" = "yes"; then
+ AS_ECHO([" Does Emacs support DOCUMENTFEED? ${DOCUMENTFEED}"])
+ fi
+ fi
+fi
+
if test -n "${EMACSDATA}"; then
AS_ECHO([" Environment variable EMACSDATA set to: $EMACSDATA"])
fi
diff -urN emacs-26.3.orig/lisp/international/w32-ime.el emacs-26.3/lisp/international/w32-ime.el
--- emacs-26.3.orig/lisp/international/w32-ime.el 1970-01-01 09:00:00.000000000 +0900
+++ emacs-26.3/lisp/international/w32-ime.el 2019-09-05 02:18:30.888288300 +0900
@@ -0,0 +1,201 @@
+;;;;; w32-ime.el ---- Meadow features for NTEmacs.
+;;
+;; Author H.Miyashita
+;;
+;;;;;
+
+(defgroup W32-IME nil
+ "w32-ime"
+ :group 'emacs)
+
+(defvar w32-last-selection nil
+ "It is stored the last data from Emacs.")
+
+;----------
+
+(defvar w32-ime-on-hook nil
+ "Functions to eval when IME is turned on at least.
+Even if IME state is not changed, these functiona are maybe called.")
+(defvar w32-ime-off-hook nil
+ "Functions to eval when IME is turned off at least.
+Even if IME state is not changed, these functiona are maybe called.")
+(defvar w32-ime-buffer-switch-p t
+ "If this variable is nil, IME control when buffer is switched is disabled.")
+(defvar w32-ime-show-mode-line t
+ "When t, mode line indicates IME state.")
+(defvar w32-ime-mode-line-state-indicator "[O]"
+ "This is shown at the mode line. It is regarded as state of ime.")
+(make-variable-buffer-local 'w32-ime-mode-line-state-indicator)
+(put 'w32-ime-mode-line-state-indicator 'permanent-local t)
+(defvar w32-ime-mode-line-state-indicator-list '("-" "[|]" "[O]")
+ "List of IME state indicator string.")
+(defvar w32-ime-mode-line-format-original nil
+ "Original mode line format.")
+
+;;
+;; Section: IME
+;;
+
+;; ;; This is temporal solution. In the future, we will prepare
+;; ;; dynamic configuration.
+;; (defvar w32-ime-coding-system-language-environment-alist
+;; '(("Japanese" . japanese-shift-jis)
+;; ("Chinese-GB" . chinese-iso-8bit)
+;; ("Chinese-BIG5" . chinese-big5)
+;; ("Korean" . korean-iso-8bit)))
+
+;;
+;; IME state indicator
+;;
+(global-set-key [kanji] 'ignore)
+(global-set-key [compend] 'ignore)
+
+(defun wrap-function-to-control-ime
+ (function interactive-p interactive-arg &optional suffix)
+ "Wrap FUNCTION, and IME control is enabled when FUNCTION is called.
+An original function is saved to FUNCTION-SUFFIX when suffix is string.
+If SUFFIX is nil, \"-original\" is added. "
+ (let ((original-function
+ (intern (concat (symbol-name function)
+ (if suffix suffix "-original")))))
+ (cond
+ ((not (fboundp original-function))
+ (fset original-function
+ (symbol-function function))
+ (fset function
+ (list
+ 'lambda '(&rest arguments)
+ (when interactive-p
+ (list 'interactive interactive-arg))
+ `(cond
+ ((and (ime-get-mode)
+ (equal current-input-method "W32-IME"))
+ (ime-force-off)
+ (unwind-protect
+ (apply ',original-function arguments)
+ (when (and (not (ime-get-mode))
+ (equal current-input-method "W32-IME"))
+ (ime-force-on))))
+ (t
+ (apply ',original-function arguments)))))))))
+
+(defvar w32-ime-toroku-region-yomigana nil
+ "* if this variable is string, toroku-region regard this value as yomigana.")
+
+(defun w32-ime-toroku-region (begin end)
+ (interactive "r")
+ (let ((string (buffer-substring begin end))
+ (w32-ime-buffer-switch-p nil)
+ (reading w32-ime-toroku-region-yomigana))
+ (unless (stringp reading)
+ (w32-set-ime-mode 'hiragana)
+ (setq reading
+ (read-multilingual-string
+ (format "Input reading of \"%s\": " string) nil "W32-IME")))
+ (w32-ime-register-word-dialog reading string)))
+
+;; for IME management system.
+
+(defun w32-ime-sync-state (window)
+ (when w32-ime-buffer-switch-p
+ (with-current-buffer (window-buffer window)
+ (let* ((frame (window-frame window))
+ (ime-state (ime-get-mode)))
+ (cond
+ ((and (not ime-state)
+ (equal current-input-method "W32-IME"))
+ (ime-force-on nil)
+ (run-hooks 'w32-ime-on-hook))
+ ((and ime-state
+ (not (equal current-input-method "W32-IME")))
+;;; (when (= (w32-ime-undetermined-string-length) 0)
+ (ime-force-off nil)
+ (run-hooks 'w32-ime-off-hook)))))))
+
+(defun w32-ime-set-selected-window-buffer-hook (oldbuf newwin newbuf)
+ (w32-ime-sync-state newwin))
+
+(defun w32-ime-select-window-hook (old new)
+ (w32-ime-sync-state new))
+
+(defun w32-ime-mode-line-update ()
+ (cond
+ (w32-ime-show-mode-line
+ (unless (window-minibuffer-p (selected-window))
+ (setq w32-ime-mode-line-state-indicator
+ (nth (if (ime-get-mode) 1 2)
+ w32-ime-mode-line-state-indicator-list))))
+ (t
+ (setq w32-ime-mode-line-state-indicator
+ (nth 0 w32-ime-mode-line-state-indicator-list))))
+ (force-mode-line-update))
+
+(defun w32-ime-init-mode-line-display ()
+ (unless (member 'w32-ime-mode-line-state-indicator mode-line-format)
+ (setq w32-ime-mode-line-format-original
+ (default-value 'mode-line-format))
+ (if (and (stringp (car mode-line-format))
+ (string= (car mode-line-format) "-"))
+ (setq-default mode-line-format
+ (cons ""
+ (cons 'w32-ime-mode-line-state-indicator
+ (cdr mode-line-format))))
+ (setq-default mode-line-format
+ (cons ""
+ (cons 'w32-ime-mode-line-state-indicator
+ mode-line-format))))
+ (force-mode-line-update t)))
+
+(defun w32-ime-initialize ()
+ (when (and (or (eq system-type 'windows-nt) (eq system-type 'cygwin))
+ (eq window-system 'w32)
+ (featurep 'w32-ime))
+ (w32-ime-init-mode-line-display)
+ (w32-ime-mode-line-update)
+ (add-hook 'select-window-functions
+ 'w32-ime-select-window-hook)
+ (add-hook 'set-selected-window-buffer-functions
+ 'w32-ime-set-selected-window-buffer-hook)
+ (define-key global-map [kanji] 'toggle-input-method)))
+;; (set-keyboard-coding-system 'utf-8)))
+
+(defun w32-ime-uninitialize ()
+ (when (and (or (eq system-type 'windows-nt) (eq system-type 'cygwin))
+ (eq window-system 'w32)
+ (featurep 'w32-ime))
+ (setq-default mode-line-format
+ w32-ime-mode-line-format-original)
+ (force-mode-line-update t)
+ (remove-hook 'select-window-functions
+ 'w32-ime-select-window-hook)
+ (remove-hook 'set-selected-window-buffer-functions
+ 'w32-ime-set-selected-window-buffer-hook)
+ (define-key global-map [kanji] 'ignore)))
+
+(defun w32-ime-exit-from-minibuffer ()
+ (deactivate-input-method)
+ (when (<= (minibuffer-depth) 1)
+ (remove-hook 'minibuffer-exit-hook 'w32-ime-exit-from-minibuffer)))
+
+(defun w32-ime-state-switch (&optional arg)
+ (if arg
+ (progn
+ (setq deactivate-current-input-method-function
+ 'w32-ime-state-switch)
+ (run-hooks 'input-method-activate-hook)
+ (run-hooks 'w32-ime-on-hook)
+ (setq describe-current-input-method-function nil)
+ (when (eq (selected-window) (minibuffer-window))
+ (add-hook 'minibuffer-exit-hook 'w32-ime-exit-from-minibuffer))
+ (ime-force-on))
+ (setq current-input-method nil)
+ (run-hooks 'input-method-deactivate-hook)
+ (run-hooks 'w32-ime-off-hook)
+ (setq describe-current-input-method-function nil)
+ (ime-force-off))
+ (w32-ime-mode-line-update))
+
+(register-input-method "W32-IME" "Japanese" 'w32-ime-state-switch ""
+ "W32 System IME")
+
+(provide 'w32-ime)
diff -urN emacs-26.3.orig/lisp/language/japan-util.el emacs-26.3/lisp/language/japan-util.el
--- emacs-26.3.orig/lisp/language/japan-util.el 2019-09-05 02:18:02.853391800 +0900
+++ emacs-26.3/lisp/language/japan-util.el 2019-09-05 02:18:30.893387000 +0900
@@ -31,9 +31,11 @@
(defun setup-japanese-environment-internal ()
;; By default, we use 'japanese-iso-8bit for file names. But, the
;; following prefer-coding-system will override it.
- (if (memq system-type '(windows-nt ms-dos cygwin))
+ (if (memq system-type '(windows-nt ms-dos))
(prefer-coding-system 'japanese-shift-jis)
- (prefer-coding-system 'japanese-iso-8bit))
+ (if (eq system-type 'cygwin)
+ (prefer-coding-system 'utf-8)
+ (prefer-coding-system 'japanese-iso-8bit)))
(use-cjk-char-width-table 'ja_JP))
(defconst japanese-kana-table
diff -urN emacs-26.3.orig/lisp/loadup.el emacs-26.3/lisp/loadup.el
--- emacs-26.3.orig/lisp/loadup.el 2019-09-05 02:18:03.048664200 +0900
+++ emacs-26.3/lisp/loadup.el 2019-09-05 02:18:30.897731500 +0900
@@ -283,6 +283,7 @@
(load "w32-vars")
(load "term/w32-win")
(load "disp-table")
+ (load "international/w32-ime")
(when (eq system-type 'windows-nt)
(load "w32-fns")
(load "ls-lisp")
diff -urN emacs-26.3.orig/lisp/startup.el emacs-26.3/lisp/startup.el
--- emacs-26.3.orig/lisp/startup.el 2019-09-05 02:17:59.296148900 +0900
+++ emacs-26.3/lisp/startup.el 2019-09-05 02:18:30.901330800 +0900
@@ -604,6 +604,8 @@
;; `user-full-name' is now known; reset its standard-value here.
(put 'user-full-name 'standard-value
(list (default-value 'user-full-name)))
+ ;; Set language environment for using "Japanese".
+ (set-language-environment "Japanese")
;; If the PWD environment variable isn't accurate, delete it.
(let ((pwd (getenv "PWD")))
(and (stringp pwd)
diff -urN emacs-26.3.orig/src/frame.c emacs-26.3/src/frame.c
--- emacs-26.3.orig/src/frame.c 2019-09-05 02:17:58.545219500 +0900
+++ emacs-26.3/src/frame.c 2019-09-05 02:18:30.908742100 +0900
@@ -3586,6 +3586,9 @@
{"ns-appearance", SYMBOL_INDEX (Qns_appearance)},
{"ns-transparent-titlebar", SYMBOL_INDEX (Qns_transparent_titlebar)},
#endif
+#ifdef USE_W32_IME
+ {"ime-font", SYMBOL_INDEX (Qime_font)},
+#endif /* USE_W32_IME */
};
#ifdef HAVE_WINDOW_SYSTEM
@@ -5769,6 +5772,9 @@
DEFSYM (Qtop_only, "top-only");
DEFSYM (Qiconify_top_level, "iconify-top-level");
DEFSYM (Qmake_invisible, "make-invisible");
+#ifdef USE_W32_IME
+ DEFSYM (Qime_font, "ime-font");
+#endif /* USE_W32_IME */
{
int i;
diff -urN emacs-26.3.orig/src/keyboard.c emacs-26.3/src/keyboard.c
--- emacs-26.3.orig/src/keyboard.c 2019-09-05 02:17:58.719640200 +0900
+++ emacs-26.3/src/keyboard.c 2019-09-05 02:18:30.917066700 +0900
@@ -4730,7 +4730,11 @@
"junja", /* VK_JUNJA 0x17 */
"final", /* VK_FINAL 0x18 */
"kanji", /* VK_KANJI/VK_HANJA 0x19 */
+#ifdef USE_W32_IME
+ "compend", /* VK_COMPEND 0x1A */
+#else
0, /* 0x1A */
+#endif /* USE_W32_IME */
"escape", /* VK_ESCAPE 0x1B */
"convert", /* VK_CONVERT 0x1C */
"non-convert", /* VK_NONCONVERT 0x1D */
@@ -8917,6 +8921,12 @@
{
ptrdiff_t count = SPECPDL_INDEX ();
+ /* To control IME */
+#ifdef USE_W32_IME
+ Lisp_Object VIME_command_off_flag = Qnil;
+ Lisp_Object IME_command_loop_flag = Qnil;
+#endif /* USE_W32_IME */
+
/* How many keys there are in the current key sequence. */
int t;
@@ -9034,6 +9044,12 @@
keybuf[0..mock_input] holds the sequence we should reread. */
replay_sequence:
+#ifdef USE_W32_IME
+/* If key sequences are to replay, IME_loop_flag should not be set.
+ Because event has never been occured. */
+ IME_command_loop_flag = Qnil;
+#endif /* USE_W32_IME */
+
starting_buffer = current_buffer;
first_unbound = bufsize + 1;
@@ -9113,6 +9129,16 @@
goto replay_sequence;
}
+#ifdef USE_W32_IME
+ if (!NILP (IME_command_loop_flag) && NILP (VIME_command_off_flag))
+ {
+ VIME_command_off_flag = Fime_get_mode ();
+ if (!NILP (VIME_command_off_flag))
+ Fime_force_off (Qnil);
+ }
+ IME_command_loop_flag = Qt;
+#endif /* USE_W32_IME */
+
if (t >= bufsize)
error ("Key sequence too long");
@@ -9785,6 +9811,12 @@
? Fcommand_remapping (read_key_sequence_cmd, Qnil, Qnil)
: Qnil;
+ /* to control IME */
+#ifdef USE_W32_IME
+ if (!NILP (VIME_command_off_flag))
+ Fime_force_on (Qnil);
+#endif /* USE_W32_IME */
+
unread_switch_frame = delayed_switch_frame;
unbind_to (count, Qnil);
diff -urN emacs-26.3.orig/src/w32fns.c emacs-26.3/src/w32fns.c
--- emacs-26.3.orig/src/w32fns.c 2019-09-05 02:17:58.590448300 +0900
+++ emacs-26.3/src/w32fns.c 2019-09-05 02:18:30.929500200 +0900
@@ -56,6 +56,11 @@
#include "w32.h"
#endif
+#ifdef USE_W32_IME
+#include "fontset.h"
+#include "w32font.h"
+#endif
+
#include <basetyps.h>
#include <unknwn.h>
#include <commctrl.h>
@@ -83,6 +88,44 @@
#define IDC_HAND MAKEINTRESOURCE(32649)
#endif
+#ifdef USE_W32_IME
+#ifdef RECONVERSION
+#define CHRSZ sizeof(short)
+#define RECONV_LENG 100
+#define DOCFEED_LENG 100
+static LRESULT w32_get_ime_reconversion_string (HWND, RECONVERTSTRING*);
+static BOOL w32_perform_reconversion (HWND, RECONVERTSTRING*);
+#ifdef DOCUMENTFEED
+#define DOCFEED_CSTR_LENG 64
+static LRESULT w32_get_ime_documentfeed_string (HWND, RECONVERTSTRING*);
+#endif
+#endif
+static int set_ime_font = 0;
+static LOGFONT ime_logfont = {0};
+static int IME_event_off_count;
+const char * const ImmGetOpenStatus_Name = "ImmGetOpenStatus";
+const char * const ImmSetOpenStatus_Name = "ImmSetOpenStatus";
+const char * const ImmSetCompositionWindow_Name = "ImmSetCompositionWindow";
+const char * const ImmGetContext_Name = "ImmGetContext";
+const char * const ImmGetConversionStatus_Name = "ImmGetConversionStatus";
+const char * const ImmSetConversionStatus_Name = "ImmSetConversionStatus";
+const char * const ImmNotifyIME_Name = "ImmNotifyIME";
+
+const char * const ImmReleaseContext_Name = "ImmReleaseContext";
+const char * const ImmCreateContext_Name = "ImmCreateContext";
+const char * const ImmDestroyContext_Name = "ImmDestroyContext";
+const char * const ImmAssociateContext_Name = "ImmAssociateContext";
+const char * const ImmGetHotKey_Name = "ImmGetHotKey";
+const char * const ImmGetProperty_Name = "ImmGetProperty";
+const char * const ImmGetCompositionString_Name = "ImmGetCompositionStringW";
+const char * const ImmSetCompositionString_Name = "ImmSetCompositionStringW";
+const char * const ImmSetCompositionFont_Name = "ImmSetCompositionFontA"; /* LOGFONTA */
+const char * const ImmGetConversionList_Name = "ImmGetConversionListW";
+const char * const ImmConfigureIME_Name = "ImmConfigureIMEW";
+const char * const ImmGetCandidateList_Name = "ImmGetCandidateListW";
+const char * const ImmGetCandidateListCount_Name = "ImmGetCandidateListCountW";
+#endif
+
/* Prefix for system colors. */
#define SYSTEM_COLOR_PREFIX "System"
#define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
@@ -157,12 +200,14 @@
typedef BOOL (WINAPI * TrackMouseEvent_Proc)
(IN OUT LPTRACKMOUSEEVENT lpEventTrack);
+#ifndef USE_W32_IME
typedef LONG (WINAPI * ImmGetCompositionString_Proc)
(IN HIMC context, IN DWORD index, OUT LPVOID buffer, IN DWORD bufLen);
typedef HIMC (WINAPI * ImmGetContext_Proc) (IN HWND window);
typedef BOOL (WINAPI * ImmReleaseContext_Proc) (IN HWND wnd, IN HIMC context);
typedef BOOL (WINAPI * ImmSetCompositionWindow_Proc) (IN HIMC context,
IN COMPOSITIONFORM *form);
+#endif /* !USE_W32_IME */
typedef HMONITOR (WINAPI * MonitorFromPoint_Proc) (IN POINT pt, IN DWORD flags);
typedef BOOL (WINAPI * GetMonitorInfo_Proc)
(IN HMONITOR monitor, OUT struct MONITOR_INFO* info);
@@ -176,10 +221,12 @@
(IN HWND hwnd, OUT TITLEBAR_INFO* info);
TrackMouseEvent_Proc track_mouse_event_fn = NULL;
+#ifndef USE_W32_IME
ImmGetCompositionString_Proc get_composition_string_fn = NULL;
ImmGetContext_Proc get_ime_context_fn = NULL;
ImmReleaseContext_Proc release_ime_context_fn = NULL;
ImmSetCompositionWindow_Proc set_ime_composition_window_fn = NULL;
+#endif /* !USE_W32_IME */
MonitorFromPoint_Proc monitor_from_point_fn = NULL;
GetMonitorInfo_Proc get_monitor_info_fn = NULL;
MonitorFromWindow_Proc monitor_from_window_fn = NULL;
@@ -188,8 +235,13 @@
extern AppendMenuW_Proc unicode_append_menu;
+#ifdef USE_W32_IME
+/* Flag for indicating in conversion in IME. */
+int ime_in_conversion = 0;
+#else
/* Flag to selectively ignore WM_IME_CHAR messages. */
static int ignore_ime_char = 0;
+#endif
/* W95 mousewheel handler */
unsigned int msh_mousewheel = 0;
@@ -793,6 +845,15 @@
return ret;
}
+#ifdef USE_W32_IME
+static void w32_set_ime_conv_window (HWND, struct frame *);
+static void w32_set_ime_status (HWND, int);
+static int w32_get_ime_status (HWND);
+static int w32_set_ime_mode (HWND, int, int);
+static void w32_set_ime_font (HWND);
+static BOOL w32_get_ime_composition_string (HWND);
+static LRESULT CALLBACK conversion_agent_wndproc (HWND, UINT, WPARAM, LPARAM);
+#endif /* USE_W32_IME */
static void
add_system_logical_colors_to_map (Lisp_Object *system_colors)
@@ -2387,6 +2448,8 @@
if (hwnd)
{
+ static int initialized = 0;
+
if (FRAME_SKIP_TASKBAR (f))
SetWindowLong (hwnd, GWL_EXSTYLE,
GetWindowLong (hwnd, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
@@ -2398,6 +2461,12 @@
SetWindowLong (hwnd, WND_HSCROLLBAR_INDEX, FRAME_SCROLL_BAR_AREA_HEIGHT (f));
SetWindowLong (hwnd, WND_BACKGROUND_INDEX, FRAME_BACKGROUND_PIXEL (f));
+ if (!initialized && (w32_major_version > 6 || (w32_major_version == 6 && w32_minor_version >= 2)))
+ {
+ ShowWindow (hwnd, SW_MINIMIZE); ShowWindow (hwnd, SW_RESTORE);
+ initialized = 1;
+ }
+
/* Enable drag-n-drop. */
DragAcceptFiles (hwnd, TRUE);
@@ -4418,6 +4487,24 @@
TranslateMessage (&windows_msg);
goto dflt;
}
+#ifdef USE_W32_IME
+ else
+ {
+ MSG ime_undo_test_msg;
+
+ if (wParam == VK_BACK
+ && ctrl_modifier == w32_get_key_modifiers (wParam, lParam)
+ && w32_get_ime_status (hwnd) != 0
+ && PeekMessage (&ime_undo_test_msg, hwnd, WM_KEYDOWN, WM_KEYDOWN, PM_NOYIELD | PM_NOREMOVE) != 0
+ && ime_undo_test_msg.wParam == VK_BACK
+ && ime_undo_test_msg.lParam == 0x40000001
+ )
+ {
+ post_character_message (hwnd, msg, wParam, lParam, 0);
+ break;
+ }
+ }
+#endif
/* Fall through */
FALLTHROUGH;
@@ -4437,6 +4524,7 @@
w32_get_key_modifiers (wParam, lParam));
break;
+#ifndef USE_W32_IME
case WM_UNICHAR:
/* WM_UNICHAR looks promising from the docs, but the exact
circumstances in which TranslateMessage sends it is one of those
@@ -4561,6 +4649,7 @@
case WM_IME_ENDCOMPOSITION:
ignore_ime_char = 0;
goto dflt;
+#endif /* USE_W32_IME */
/* Simulate middle mouse button events when left and right buttons
are used together, but only if user has two button mouse. */
@@ -5379,8 +5468,89 @@
case WM_EMACS_FILENOTIFY:
my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
return 1;
+#ifdef USE_W32_IME
+ case WM_IME_NOTIFY:
+ if (wParam == IMN_SETOPENSTATUS)
+ {
+ if (w32_get_ime_status(hwnd)){
+ struct frame *f = x_window_to_frame (dpyinfo, hwnd);
+ if (f) {
+ set_ime_font = 0;
+ w32_set_ime_conv_window (hwnd, f);
+ }
+ }
+ if (!IME_event_off_count)
+ my_post_msg (&wmsg, hwnd, WM_MULE_IME_STATUS, 0, 0);
+ else
+ IME_event_off_count--;
+ }
+ goto dflt;
+
+ case WM_IME_STARTCOMPOSITION:
+ {
+ struct frame *f = x_window_to_frame (dpyinfo, hwnd);
+ if (f && !set_ime_font)
+ {
+ my_post_msg (&wmsg, hwnd, WM_MULE_IME_SET_FONT, (WPARAM) f, 0);
+ set_ime_font = 1;
+ }
+ }
+ ime_in_conversion = 1;
+ goto dflt;
+
+ case WM_IME_ENDCOMPOSITION:
+ ime_in_conversion = 0;
+ goto dflt;
+
+ case WM_IME_SETCONTEXT:
+ set_ime_font = 0;
+ goto dflt;
+
+ case WM_IME_COMPOSITION:
+ if (lParam & GCS_RESULTSTR)
+ {
+ if (w32_get_ime_composition_string (hwnd))
+ return 0;
+ else
+ break;
+ }
+ goto dflt;
+
+#ifdef RECONVERSION
+ case WM_IME_REQUEST:
+ if (wParam == IMR_RECONVERTSTRING)
+ {
+ if (!ime_enable_reconversion || !w32_get_ime_status (hwnd))
+ return 0;
+ if (lParam)
+ return w32_get_ime_reconversion_string (hwnd,
+ (RECONVERTSTRING*) lParam);
+ else
+ return sizeof (RECONVERTSTRING) + (RECONV_LENG * 2 + 1) * CHRSZ;
+ }
+#ifdef DOCUMENTFEED
+ else if (wParam == IMR_DOCUMENTFEED)
+ {
+ if (!ime_enable_document_feed)
+ return 0;
+ if (lParam)
+ return w32_get_ime_documentfeed_string (hwnd,
+ (RECONVERTSTRING*) lParam);
+ else
+ return sizeof (RECONVERTSTRING) + (DOCFEED_LENG * 2 + DOCFEED_CSTR_LENG + 1) * CHRSZ;
+ }
+#endif
+ goto dflt;
+#endif
+#endif /* USE_W32_IME */
default:
+
+#ifdef USE_W32_IME
+ if (MESSAGE_IMM_COM_P(msg))
+ return conversion_agent_wndproc (hwnd, msg, wParam, lParam);
+#endif /* USE_W32_IME */
+
/* Check for messages registered at runtime. */
if (msg == msh_mousewheel)
{
@@ -5671,6 +5841,10 @@
Qnil));
}
x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
+#ifdef USE_W32_IME
+ x_default_parameter (f, parms, Qime_font, Qnil,
+ "ime-font", "IME-Font", RES_TYPE_STRING);
+#endif
}
DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
@@ -8171,6 +8345,992 @@
/***********************************************************************
+ Input Method Editor
+ ***********************************************************************/
+#ifdef USE_W32_IME
+BOOL fIME = FALSE;
+
+typedef BOOL (WINAPI *IMMGETOPENSTATUSPROC)(HIMC);
+IMMGETOPENSTATUSPROC ImmGetOpenStatusProc;
+
+typedef BOOL (WINAPI *IMMSETOPENSTATUSPROC)(HIMC, BOOL);
+IMMSETOPENSTATUSPROC ImmSetOpenStatusProc;
+
+typedef BOOL (WINAPI *IMMSETCOMPOSITIONWINDOWPROC)(HIMC, LPCOMPOSITIONFORM);
+IMMSETCOMPOSITIONWINDOWPROC ImmSetCompositionWindowProc;
+
+typedef LONG (WINAPI *IMMGETCOMPOSITIONSTRINGPROC)
+ (HIMC, DWORD, LPVOID, DWORD);
+IMMGETCOMPOSITIONSTRINGPROC ImmGetCompositionStringProc;
+
+typedef LONG (WINAPI *IMMSETCOMPOSITIONSTRINGPROC)
+ (HIMC, DWORD, LPCVOID, DWORD, LPCVOID, DWORD);
+IMMSETCOMPOSITIONSTRINGPROC ImmSetCompositionStringProc;
+
+typedef BOOL (WINAPI *IMMSETCOMPOSITIONFONTPROC) (HIMC, LPLOGFONTA);
+IMMSETCOMPOSITIONFONTPROC ImmSetCompositionFontProc;
+
+typedef HIMC (WINAPI *IMMGETCONTEXTPROC)(HWND);
+IMMGETCONTEXTPROC ImmGetContextProc;
+
+typedef BOOL (WINAPI *IMMGETCONVERSIONSTATUSPROC)(HIMC, LPDWORD, LPDWORD);
+IMMGETCONVERSIONSTATUSPROC ImmGetConversionStatusProc;
+
+typedef BOOL (WINAPI *IMMSETCONVERSIONSTATUSPROC)(HIMC, DWORD, DWORD);
+IMMSETCONVERSIONSTATUSPROC ImmSetConversionStatusProc;
+
+typedef BOOL (WINAPI *IMMGETCONVERSIONLISTPROC)
+ (HKL, HIMC, LPCTSTR, LPCANDIDATELIST, DWORD, UINT);
+IMMGETCONVERSIONLISTPROC ImmGetConversionListProc;
+
+typedef BOOL (WINAPI *IMMCONFIGUREIMEPROC)(HKL, HWND, DWORD, LPVOID);
+IMMCONFIGUREIMEPROC ImmConfigureIMEProc;
+
+typedef BOOL (WINAPI *IMMNOTIFYIMEPROC)(HIMC, DWORD, DWORD, DWORD);
+IMMNOTIFYIMEPROC ImmNotifyIMEProc;
+
+typedef BOOL (WINAPI *IMMRELEASECONTEXTPROC)(HWND, HIMC);
+IMMRELEASECONTEXTPROC ImmReleaseContextProc;
+
+typedef HIMC (WINAPI *IMMCREATECONTEXTPROC)(void);
+IMMCREATECONTEXTPROC ImmCreateContextProc;
+
+typedef BOOL (WINAPI *IMMDESTROYCONTEXTPROC)(HIMC);
+IMMDESTROYCONTEXTPROC ImmDestroyContextProc;
+
+typedef HIMC (WINAPI *IMMASSOCIATECONTEXTPROC) (HWND, HIMC);
+IMMASSOCIATECONTEXTPROC ImmAssociateContextProc;
+
+typedef BOOL (WINAPI *IMMGETCANDIDATELISTPROC)
+ (HIMC, DWORD, LPCANDIDATELIST, DWORD);
+IMMGETCANDIDATELISTPROC ImmGetCandidateListProc;
+
+typedef BOOL (WINAPI *IMMGETCANDIDATELISTCOUNTPROC) (HIMC, LPDWORD);
+IMMGETCANDIDATELISTCOUNTPROC ImmGetCandidateListCountProc;
+
+typedef BOOL (WINAPI *IMMGETHOTKEYPROC)(DWORD, LPUINT, LPUINT, LPHKL);
+IMMGETHOTKEYPROC ImmGetHotKeyProc;
+
+typedef BOOL (WINAPI *IMMGETPROPERTYPROC)(HKL, DWORD);
+IMMGETPROPERTYPROC ImmGetPropertyProc;
+
+// Lisp_Object Vime_control;
+
+static void
+w32_set_ime_conv_window (HWND hwnd, struct frame *f)
+{
+ if (fIME && !NILP (Vime_control))
+ {
+ HIMC himc;
+ COMPOSITIONFORM compform;
+ struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
+
+ /* If Vw32_ime_composition_window is set, try it. */
+ if (!NILP (Vw32_ime_composition_window)
+ && WINDOWP (Vw32_ime_composition_window)
+ && EQ (WINDOW_FRAME (XWINDOW (Vw32_ime_composition_window)),
+ WINDOW_FRAME (w)))
+ w = XWINDOW (Vw32_ime_composition_window);
+
+ himc = (ImmGetContextProc) (hwnd);
+ compform.dwStyle = CFS_RECT;
+
+ compform.ptCurrentPos.x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
+
+ compform.ptCurrentPos.y = WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y);
+#if 0
+ if (FRAME_FONT (f)->vertical_centering == 1)
+ compform.ptCurrentPos.y += FRAME_FONT (f)->baseline_offset;
+#endif
+
+ compform.rcArea.left = (WINDOW_BOX_LEFT_EDGE_X (w)
+ + WINDOW_LEFT_MARGIN_WIDTH (w)
+ + WINDOW_LEFT_FRINGE_WIDTH (w));
+
+ compform.rcArea.top = (WINDOW_TOP_EDGE_Y (w)
+ + WINDOW_HEADER_LINE_HEIGHT (w));
+
+ compform.rcArea.right = (WINDOW_BOX_RIGHT_EDGE_X (w)
+ - WINDOW_RIGHT_MARGIN_WIDTH (w)
+ - WINDOW_RIGHT_FRINGE_WIDTH (w)) + 1;
+
+ compform.rcArea.bottom = (WINDOW_BOTTOM_EDGE_Y (w)
+ - WINDOW_MODE_LINE_HEIGHT (w));
+
+ (ImmSetCompositionWindowProc) (himc, &compform);
+ (ImmReleaseContextProc) (hwnd, himc);
+ }
+}
+
+static void
+w32_set_ime_status (HWND hwnd, int openp)
+{
+ HIMC himc;
+
+ himc = (ImmGetContextProc) (hwnd);
+ (ImmSetOpenStatusProc) (himc, openp);
+ (ImmReleaseContextProc) (hwnd, himc);
+}
+
+static int
+w32_get_ime_status (HWND hwnd)
+{
+ HIMC himc;
+ int ret;
+
+ himc = (ImmGetContextProc) (hwnd);
+ ret = (ImmGetOpenStatusProc) (himc);
+ (ImmReleaseContextProc) (hwnd, himc);
+
+ return ret;
+}
+
+static int
+w32_set_ime_mode (HWND hwnd, int mode, int mask)
+{
+ HIMC himc;
+ DWORD cmode, smode;
+
+ himc = (ImmGetContextProc) (hwnd);
+ if (!(ImmGetConversionStatusProc) (himc, &cmode, &smode))
+ return 0;
+
+ cmode = (cmode & (~mask)) | (mode & mask);
+
+ (ImmSetConversionStatusProc) (himc, cmode, smode);
+ (ImmReleaseContextProc) (hwnd, himc);
+
+ return 1;
+}
+
+static BOOL
+w32_get_ime_composition_string (HWND hwnd)
+{
+ HIMC hIMC;
+ int size;
+ HANDLE himestr;
+
+ struct frame *f;
+
+ hIMC = (ImmGetContextProc) (hwnd);
+ if (!hIMC)
+ return FALSE;
+
+ size = (ImmGetCompositionStringProc) (hIMC, GCS_RESULTSTR, NULL, 0);
+ size += sizeof (WCHAR);
+ himestr = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, size);
+ if (!himestr)
+ abort ();
+
+ (ImmGetCompositionStringProc) (hIMC, GCS_RESULTSTR, himestr, size);
+ (ImmReleaseContextProc) (hwnd, hIMC);
+ {
+ W32Msg wmsg;
+ f = SELECTED_FRAME ();
+ my_post_msg (&wmsg, hwnd, WM_MULE_IME_REPORT,
+ (WPARAM) himestr, (LPARAM) f);
+ }
+ return TRUE;
+}
+
+#ifdef RECONVERSION
+
+static EMACS_INT compstr_beginning_pos(int max_char)
+{
+ EMACS_INT bol, point = PT, pt;
+ for (bol = XFASTINT(Fline_beginning_position(Qnil)), pt = PT;
+ PT >= bol && PT > point - max_char; ) {
+ pt = PT;
+ if (NILP(Fforward_word (make_number (-1))))
+ break;
+ }
+ Fgoto_char (make_number(point));
+ return pt;
+}
+
+static EMACS_INT compstr_end_pos(int max_char)
+{
+ EMACS_INT eol, point = PT, pt;
+
+ for (eol = XFASTINT(Fline_end_position(Qnil)), pt = PT;
+ PT <= eol && PT < point + max_char;) {
+ pt = PT;
+ if (NILP(Fforward_word (make_number (1))))
+ break;
+ }
+ Fgoto_char (make_number(point));
+ return pt;
+}
+
+static LRESULT
+get_reconversion_string (HWND hwnd,
+ RECONVERTSTRING *reconv,
+ unsigned short *compstr)
+{
+ EMACS_INT pt, pt_byte, start, end, len, t_start, t_end, compstr_len;
+ W32Msg wmsg;
+
+ if (!NILP (BVAR (current_buffer, read_only)))
+ return 0;
+
+ pt = PT;
+ pt_byte = PT_BYTE;
+
+ if (compstr)
+ {
+ t_start = t_end = PT;
+ start = compstr_beginning_pos (DOCFEED_LENG);
+ end = compstr_end_pos (DOCFEED_LENG);
+ }
+ else if (!NILP (BVAR (current_buffer, mark_active))
+ && !NILP (Vtransient_mark_mode))
+ {
+ if (marker_position (BVAR (current_buffer, mark)) < PT)
+ {
+ t_start = marker_position (BVAR (current_buffer, mark));
+ t_end = PT;
+ }
+ else
+ {
+ t_start = PT;
+ t_end = marker_position (BVAR (current_buffer, mark));
+ }
+ Fgoto_char (make_number (t_end));
+ while (!NILP (Fbolp ()) && t_start < PT)
+ Fforward_char (make_number (-1));
+ if (t_start >= PT)
+ return 0;
+ t_end = PT;
+ }
+ else
+ {
+ if (NILP (Feobp ()))
+ Fforward_char (make_number (1));
+ if (!NILP (Fforward_word (make_number (-1))))
+ t_start = PT;
+ else
+ {
+ SET_PT_BOTH (pt, pt_byte);
+ return 0;
+ }
+ Fforward_word (make_number (1));
+ t_end = PT;
+ SET_PT_BOTH (pt, pt_byte);
+ if (t_end < PT)
+ return 0;
+ }
+
+ if (!compstr)
+ {
+ if (t_start == t_end)
+ return 0;
+
+ Fgoto_char (make_number (t_start));
+ start = compstr_beginning_pos (RECONV_LENG);
+ Fgoto_char (make_number (t_end));
+ end = compstr_end_pos (RECONV_LENG);
+ }
+
+ len = end - start;
+ if (reconv)
+ {
+ int pos;