Add `===shuowen-jiguge-A30' characters.
[chise/xemacs-chise.git] / lisp / gtk-init.el
1 ;;; gtk-init.el --- initialization code for mswindows
2 ;; Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
3 ;; Copyright (C) 1995 Board of Trustees, University of Illinois.
4 ;; Copyright (C) 1995, 1996 Ben Wing.
5
6 ;; Author: various
7 ;; Rewritten for Gtk by: William Perry
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 (defvar gtk-win-initted nil)
27 (defvar gtk-pre-win-initted nil)
28 (defvar gtk-post-win-initted nil)
29
30 (defvar gtk-command-switch-alist
31   '(
32     ;; GNOME Options
33     ("--disable-sound" . nil)
34     ("--enable-sound"  . nil)
35     ("--espeaker"      . t)
36
37     ;; GTK Options
38     ("--gdk-debug"    . t)
39     ("--gdk-no-debug" . t)
40     ("--display"      . t)
41     ("--sync"         . nil)
42     ("--no-xshm"      . nil)
43     ("--name"         . t)
44     ("--class"        . t)
45     ("--gxid_host"    . t)
46     ("--gxid_port"    . t)
47     ("--xim-preedit"  . t)
48     ("--xim-status"   . t)
49     ("--gtk-debug"    . t)
50     ("--gtk-no-debug" . t)
51     ("--gtk-module"   . t)
52
53     ;; Glib options
54     ("--g-fatal-warnings" . nil)
55
56     ;; Session management options
57     ("--sm-client-id"     . t)
58     ("--sm-config-prefix" . t)
59     ("--sm-disable"       . t)
60     )
61
62   "An assoc list of command line arguments that should in gtk-initial-argv-list.
63 This is necessary because GTK and GNOME consider it a fatal error if they receive
64 unknown command line arguments (perfectly reasonable).  But this means that if
65 the user specifies a file name on the command line they will be unable to start.
66 So we filter the command line and allow only items in this list in.
67
68 The CDR of the assoc list is whether it accepts an argument.  All options are in
69 GNU long form though.")
70
71 (defun init-pre-gtk-win ()
72   "Initialize Gtk GUI at startup (pre).  Don't call this."
73   (when (not gtk-pre-win-initted)
74     (setq initial-frame-plist (if initial-frame-unmapped-p
75                                   '(initially-unmapped t)
76                                 nil)
77           gtk-pre-win-initted t)))
78
79 (defun gtk-init-handle-geometry (arg)
80   "Set up initial geometry info for GTK devices."
81   (setq gtk-initial-geometry (pop command-line-args-left)))
82
83 (defun gtk-filter-arguments ()
84   (let ((accepted nil)
85         (rejected nil)
86         (todo nil))
87     (setq todo (mapcar (lambda (argdesc)
88                          (if (cdr argdesc)
89                              ;; Need to look for --foo=bar
90                              (concat "^" (car argdesc) "=")
91                            ;; Just a simple arg
92                            (concat "^" (regexp-quote (car argdesc)) "$")))
93                        gtk-command-switch-alist))
94
95     (while command-line-args-left
96       (if (catch 'found
97             (mapc (lambda (r)
98                     (if (string-match r (car command-line-args-left))
99                         (throw 'found t))) todo)
100             (mapc (lambda (argdesc)
101                     (if (cdr argdesc)
102                         ;; This time we only care about argument items
103                         ;; that take an argument.  We'll check to see if
104                         ;; someone used --foo bar instead of --foo=bar
105                         (if (string-match (concat "^" (car argdesc) "$") (car command-line-args-left))
106                             ;; Yup!  Need to push
107                             (progn
108                               (push (pop command-line-args-left) accepted)
109                               (throw 'found t)))))
110                   gtk-command-switch-alist)
111             nil)
112           (push (pop command-line-args-left) accepted)
113         (push (pop command-line-args-left) rejected)))
114     (setq command-line-args-left (nreverse rejected))
115     (nreverse accepted)))
116
117 (defun init-gtk-win ()
118   "Initialize Gtk GUI at startup.  Don't call this."
119   (unless gtk-win-initted
120     (init-pre-gtk-win)
121     (setq gtk-initial-argv-list (cons (car command-line-args) (gtk-filter-arguments))
122           gtk-initial-geometry (nth 1 (member "-geometry" command-line-args-left)))
123     (make-gtk-device)
124     (init-post-gtk-win)
125     (setq gtk-win-initted t)))
126
127 (defun init-post-gtk-win ()
128   (unless gtk-post-win-initted
129     (if (and (not (featurep 'infodock)) (featurep 'toolbar))
130         (init-x-toolbar))
131     (if (and (featurep 'infodock) (featurep 'toolbar))
132         (require 'id-x-toolbar))
133
134     (when (featurep 'mule)
135       (define-specifier-tag 'mule-fonts
136         (lambda (device) (eq 'gtk (device-type device))))
137       (set-face-font
138        'default
139        '("-*-fixed-medium-r-*--16-*-iso8859-1"
140          "-*-fixed-medium-r-*--*-iso8859-1"
141          "-*-fixed-medium-r-*--*-iso8859-2"
142          "-*-fixed-medium-r-*--*-iso8859-3"
143          "-*-fixed-medium-r-*--*-iso8859-4"
144          "-*-fixed-medium-r-*--*-iso8859-7"
145          "-*-fixed-medium-r-*--*-iso8859-8"
146          "-*-fixed-medium-r-*--*-iso8859-5"
147          "-*-fixed-medium-r-*--*-iso8859-9"
148
149          ;; Following 3 fonts proposed by Teruhiko.Kurosaka@Japan.eng.sun
150          "-sun-gothic-medium-r-normal--14-120-75-75-c-60-jisx0201.1976-0"
151          "-sun-gothic-medium-r-normal--14-120-75-75-c-120-jisx0208.1983-0"
152          "-wadalab-gothic-medium-r-normal--14-120-75-75-c-120-jisx0212.1990-0"
153          ;; Other Japanese fonts
154          "-*-fixed-medium-r-*--*-jisx0201.1976-*"
155          "-*-fixed-medium-r-*--*-jisx0208.1983-*"
156          "-*-fixed-medium-r-*--*-jisx0212*-*"
157
158          ;; Chinese fonts
159          "-*-*-medium-r-*--*-gb2312.1980-*"
160        
161          ;; Use One font specification for CNS chinese
162          ;; Too many variations in font naming
163          "-*-fixed-medium-r-*--*-cns11643*-*"
164          ;; "-*-fixed-medium-r-*--*-cns11643*2"
165          ;; "-*-fixed-medium-r-*--*-cns11643*3"
166          ;; "-*-fixed-medium-r-*--*-cns11643*4"
167          ;; "-*-fixed-medium-r-*--*-cns11643.5-0"
168          ;; "-*-fixed-medium-r-*--*-cns11643.6-0"
169          ;; "-*-fixed-medium-r-*--*-cns11643.7-0"
170        
171          "-*-fixed-medium-r-*--*-big5*-*"
172          "-*-fixed-medium-r-*--*-sisheng_cwnn-0"
173
174          ;; Other fonts
175        
176          ;; "-*-fixed-medium-r-*--*-viscii1.1-1"
177        
178          ;; "-*-fixed-medium-r-*--*-mulearabic-0"
179          ;; "-*-fixed-medium-r-*--*-mulearabic-1"
180          ;; "-*-fixed-medium-r-*--*-mulearabic-2"
181
182          ;; "-*-fixed-medium-r-*--*-muleipa-1"
183          ;; "-*-fixed-medium-r-*--*-ethio-*"
184
185          "-*-mincho-medium-r-*--*-ksc5601.1987-*" ; Korean
186          "-*-fixed-medium-r-*--*-tis620.2529-1" ; Thai
187          )
188        'global '(mule-fonts) 'append))
189     
190     (add-hook 'zmacs-deactivate-region-hook
191               (lambda ()
192                 (if (console-on-window-system-p)
193                     (disown-selection))))
194     (add-hook 'zmacs-activate-region-hook
195               (lambda ()
196                 (if (console-on-window-system-p)
197                     (activate-region-as-selection))))
198     (add-hook 'zmacs-update-region-hook
199               (lambda ()
200                 (if (console-on-window-system-p)
201                     (activate-region-as-selection))))
202
203     (define-key global-map 'menu 'popup-mode-menu)
204     (setq gtk-post-win-initted t)))
205     
206 (push '("-geometry" . gtk-init-handle-geometry) command-switch-alist)
207
208 ;;; Stuff to get compose keys working on GTK
209 (eval-when-compile
210   (defmacro gtk-define-dead-key (key map)
211     `(when (gtk-keysym-on-keyboard-p ',key)
212        (define-key function-key-map [,key] ',map))))
213
214 (defun gtk-initialize-compose ()
215   "Enable compose processing"
216   (autoload 'compose-map            "gtk-compose" nil t 'keymap)
217   (autoload 'compose-acute-map      "gtk-compose" nil t 'keymap)
218   (autoload 'compose-grave-map      "gtk-compose" nil t 'keymap)
219   (autoload 'compose-cedilla-map    "gtk-compose" nil t 'keymap)
220   (autoload 'compose-diaeresis-map  "gtk-compose" nil t 'keymap)
221   (autoload 'compose-circumflex-map "gtk-compose" nil t 'keymap)
222   (autoload 'compose-tilde-map      "gtk-compose" nil t 'keymap)
223
224   (when (gtk-keysym-on-keyboard-p 'multi-key)
225     (define-key function-key-map [multi-key] 'compose-map))
226
227   ;; The dead keys might really be called just about anything, depending
228   ;; on the vendor.  MIT thinks that the prefixes are "SunFA_", "D", and
229   ;; "hpmute_" for Sun, DEC, and HP respectively.  However, OpenWindows 3
230   ;; thinks that the prefixes are "SunXK_FA_", "DXK_", and "hpXK_mute_".
231   ;; And HP (who don't mention Sun and DEC at all) use "XK_mute_".
232   ;; Go figure.
233
234   ;; Presumably if someone is running OpenWindows, they won't be using
235   ;; the DEC or HP keysyms, but if they are defined then that is possible,
236   ;; so in that case we accept them all.
237
238   ;; If things seem not to be working, you might want to check your
239   ;; /usr/lib/X11/XKeysymDB file to see if your vendor has an equally
240   ;; mixed up view of what these keys should be called.
241
242   ;; Canonical names:
243   (gtk-define-dead-key acute                    compose-acute-map)
244   (gtk-define-dead-key grave                    compose-grave-map)
245   (gtk-define-dead-key cedilla                  compose-cedilla-map)
246   (gtk-define-dead-key diaeresis                compose-diaeresis-map)
247   (gtk-define-dead-key circumflex               compose-circumflex-map)
248   (gtk-define-dead-key tilde                    compose-tilde-map)
249   (gtk-define-dead-key degree                   compose-ring-map)
250
251   ;; Sun according to MIT:
252   (gtk-define-dead-key SunFA_Acute              compose-acute-map)
253   (gtk-define-dead-key SunFA_Grave              compose-grave-map)
254   (gtk-define-dead-key SunFA_Cedilla            compose-cedilla-map)
255   (gtk-define-dead-key SunFA_Diaeresis          compose-diaeresis-map)
256   (gtk-define-dead-key SunFA_Circum             compose-circumflex-map)
257   (gtk-define-dead-key SunFA_Tilde              compose-tilde-map)
258
259   ;; Sun according to OpenWindows 2:
260   (gtk-define-dead-key Dead_Grave               compose-grave-map)
261   (gtk-define-dead-key Dead_Circum              compose-circumflex-map)
262   (gtk-define-dead-key Dead_Tilde               compose-tilde-map)
263
264   ;; Sun according to OpenWindows 3:
265   (gtk-define-dead-key SunXK_FA_Acute           compose-acute-map)
266   (gtk-define-dead-key SunXK_FA_Grave           compose-grave-map)
267   (gtk-define-dead-key SunXK_FA_Cedilla         compose-cedilla-map)
268   (gtk-define-dead-key SunXK_FA_Diaeresis       compose-diaeresis-map)
269   (gtk-define-dead-key SunXK_FA_Circum          compose-circumflex-map)
270   (gtk-define-dead-key SunXK_FA_Tilde           compose-tilde-map)
271
272   ;; DEC according to MIT:
273   (gtk-define-dead-key Dacute_accent            compose-acute-map)
274   (gtk-define-dead-key Dgrave_accent            compose-grave-map)
275   (gtk-define-dead-key Dcedilla_accent          compose-cedilla-map)
276   (gtk-define-dead-key Dcircumflex_accent       compose-circumflex-map)
277   (gtk-define-dead-key Dtilde                   compose-tilde-map)
278   (gtk-define-dead-key Dring_accent             compose-ring-map)
279
280   ;; DEC according to OpenWindows 3:
281   (gtk-define-dead-key DXK_acute_accent         compose-acute-map)
282   (gtk-define-dead-key DXK_grave_accent         compose-grave-map)
283   (gtk-define-dead-key DXK_cedilla_accent       compose-cedilla-map)
284   (gtk-define-dead-key DXK_circumflex_accent    compose-circumflex-map)
285   (gtk-define-dead-key DXK_tilde                compose-tilde-map)
286   (gtk-define-dead-key DXK_ring_accent          compose-ring-map)
287
288   ;; HP according to MIT:
289   (gtk-define-dead-key hpmute_acute             compose-acute-map)
290   (gtk-define-dead-key hpmute_grave             compose-grave-map)
291   (gtk-define-dead-key hpmute_diaeresis         compose-diaeresis-map)
292   (gtk-define-dead-key hpmute_asciicircum       compose-circumflex-map)
293   (gtk-define-dead-key hpmute_asciitilde        compose-tilde-map)
294
295   ;; Empirically discovered on Linux XFree86 MetroX:
296   (gtk-define-dead-key usldead_acute            compose-acute-map)
297   (gtk-define-dead-key usldead_grave            compose-grave-map)
298   (gtk-define-dead-key usldead_diaeresis        compose-diaeresis-map)
299   (gtk-define-dead-key usldead_asciicircum      compose-circumflex-map)
300   (gtk-define-dead-key usldead_asciitilde       compose-tilde-map)
301
302   ;; HP according to OpenWindows 3:
303   (gtk-define-dead-key hpXK_mute_acute          compose-acute-map)
304   (gtk-define-dead-key hpXK_mute_grave          compose-grave-map)
305   (gtk-define-dead-key hpXK_mute_diaeresis      compose-diaeresis-map)
306   (gtk-define-dead-key hpXK_mute_asciicircum    compose-circumflex-map)
307   (gtk-define-dead-key hpXK_mute_asciitilde     compose-tilde-map)
308
309   ;; HP according to HP-UX 8.0:
310   (gtk-define-dead-key XK_mute_acute            compose-acute-map)
311   (gtk-define-dead-key XK_mute_grave            compose-grave-map)
312   (gtk-define-dead-key XK_mute_diaeresis        compose-diaeresis-map)
313   (gtk-define-dead-key XK_mute_asciicircum      compose-circumflex-map)
314   (gtk-define-dead-key XK_mute_asciitilde       compose-tilde-map)
315
316   ;; Xfree86 seems to use lower case and a hyphen
317   (gtk-define-dead-key dead-acute               compose-acute-map)
318   (gtk-define-dead-key dead-grave               compose-grave-map)
319   (gtk-define-dead-key dead-cedilla             compose-cedilla-map)
320   (gtk-define-dead-key dead-diaeresis           compose-diaeresis-map)
321   (gtk-define-dead-key dead-circum              compose-circumflex-map)
322   (gtk-define-dead-key dead-circumflex          compose-circumflex-map)
323   (gtk-define-dead-key dead-tilde               compose-tilde-map)
324   )
325
326 (when (featurep 'gtk)
327   (add-hook
328    'create-console-hook
329    (lambda (console)
330      (letf (((selected-console) console))
331        (when (eq 'gtk (console-type console))
332          (gtk-initialize-compose))))))