Add a bunch of prototypes.
[bpt/emacs.git] / lisp / term / w32-win.el
CommitLineData
b63f9ba1 1;;; w32-win.el --- parse switches controlling interface with W32 window system.
2fe590dc 2
ee78dc32
GV
3;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4
5;; Author: Kevin Gallo
6;; Keywords: terminals
7
2fe590dc
EN
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
ee78dc32
GV
24
25;;; Commentary:
26
b63f9ba1
GV
27;; w32-win.el: this file is loaded from ../lisp/startup.el when it recognizes
28;; that W32 windows are to be used. Command line switches are parsed and those
29;; pertaining to W32 are processed and removed from the command line. The
30;; W32 display is opened and hooks are set for popping up the initial window.
ee78dc32
GV
31
32;; startup.el will then examine startup files, and eventually call the hooks
33;; which create the first window (s).
34
35;;; Code:
36\f
37
38;; These are the standard X switches from the Xt Initialize.c file of
39;; Release 4.
40
41;; Command line Resource Manager string
42
43;; +rv *reverseVideo
44;; +synchronous *synchronous
45;; -background *background
46;; -bd *borderColor
47;; -bg *background
48;; -bordercolor *borderColor
49;; -borderwidth .borderWidth
50;; -bw .borderWidth
51;; -display .display
52;; -fg *foreground
53;; -fn *font
54;; -font *font
55;; -foreground *foreground
56;; -geometry .geometry
57;; -i .iconType
58;; -itype .iconType
59;; -iconic .iconic
60;; -name .name
61;; -reverse *reverseVideo
62;; -rv *reverseVideo
63;; -selectionTimeout .selectionTimeout
64;; -synchronous *synchronous
65;; -xrm
66
67;; An alist of X options and the function which handles them. See
68;; ../startup.el.
69
b63f9ba1
GV
70(if (not (eq window-system 'w32))
71 (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name)))
ee78dc32
GV
72
73(require 'frame)
74(require 'mouse)
75(require 'scroll-bar)
76(require 'faces)
77(require 'select)
78(require 'menu-bar)
51099b45
GV
79(if (fboundp 'new-fontset)
80 (require 'fontset))
ee78dc32 81
af99aa46
GV
82;; Because Windows scrollbars look and act quite differently compared
83;; with the standard X scroll-bars, we don't try to use the normal
84;; scroll bar routines.
85
fbd6baed 86(defun w32-handle-scroll-bar-event (event)
b63f9ba1 87 "Handle W32 scroll bar events to do normal Window style scrolling."
af99aa46 88 (interactive "e")
caf9b328
KH
89 (let ((old-window (selected-window)))
90 (unwind-protect
91 (let* ((position (event-start event))
92 (window (nth 0 position))
93 (portion-whole (nth 2 position))
94 (bar-part (nth 4 position)))
95 (save-excursion
96 (select-window window)
97 (cond
98 ((eq bar-part 'up)
d66be571 99 (goto-char (window-start window))
caf9b328
KH
100 (scroll-down 1))
101 ((eq bar-part 'above-handle)
102 (scroll-down))
103 ((eq bar-part 'handle)
104 (scroll-bar-maybe-set-window-start event))
105 ((eq bar-part 'below-handle)
106 (scroll-up))
107 ((eq bar-part 'down)
d66be571 108 (goto-char (window-start window))
caf9b328
KH
109 (scroll-up 1))
110 )))
111 (select-window old-window))))
af99aa46
GV
112
113;; The following definition is used for debugging.
fbd6baed 114;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
af99aa46 115
fbd6baed 116(global-set-key [vertical-scroll-bar mouse-1] 'w32-handle-scroll-bar-event)
af99aa46
GV
117
118;; (scroll-bar-mode nil)
fe07d75e 119
d66be571
GV
120(defvar mouse-wheel-scroll-amount 4
121 "*Number of lines to scroll per click of the mouse wheel.")
122
123(defun mouse-wheel-scroll-line (event)
124 "Scroll the current buffer by `mouse-wheel-scroll-amount'."
125 (interactive "e")
126 (condition-case nil
127 (if (< (car (cdr (cdr event))) 0)
128 (scroll-up mouse-wheel-scroll-amount)
129 (scroll-down mouse-wheel-scroll-amount))
130 (error nil)))
131
132;; for scroll-in-place.el, this way the -scroll-line and -scroll-screen
133;; commands won't interact
134(setq scroll-command-groups (list '(mouse-wheel-scroll-line)))
135
136(defun mouse-wheel-scroll-screen (event)
137 "Scroll the current buffer by `mouse-wheel-scroll-amount'."
138 (interactive "e")
139 (condition-case nil
140 (if (< (car (cdr (cdr event))) 0)
141 (scroll-up)
142 (scroll-down))
143 (error nil)))
144
145;; Bind the mouse-wheel event:
146(global-set-key [mouse-wheel] 'mouse-wheel-scroll-line)
147(global-set-key [C-mouse-wheel] 'mouse-wheel-scroll-screen)
148
33b307f8
RS
149(defun w32-drag-n-drop-debug (event)
150 "Print the drag-n-drop event in a readable form."
151 (interactive "e")
152 (princ event))
153
154(defun w32-drag-n-drop (event)
155 "Edit the files listed in the drag-n-drop event.
156Switch to a buffer editing the last file dropped."
157 (interactive "e")
c8316112 158 (save-excursion
35a8911d
GM
159 ;; Make sure the drop target has positive co-ords
160 ;; before setting the selected frame - otherwise it
161 ;; won't work. <skx@tardis.ed.ac.uk>
162 (let* ((window (posn-window (event-start event)))
163 (coords (posn-x-y (event-start event)))
164 (x (car coords))
165 (y (cdr coords)))
166 (if (and (> x 0) (> y 0))
167 (set-frame-selected-window nil window))
7ed4e9a7 168 (mapcar 'find-file (car (cdr (cdr event)))))
35a8911d 169 (raise-frame)))
33b307f8
RS
170
171(defun w32-drag-n-drop-other-frame (event)
172 "Edit the files listed in the drag-n-drop event, in other frames.
173May create new frames, or reuse existing ones. The frame editing
174the last file dropped is selected."
175 (interactive "e")
176 (mapcar 'find-file-other-frame (car (cdr (cdr event)))))
177
178;; Bind the drag-n-drop event.
179(global-set-key [drag-n-drop] 'w32-drag-n-drop)
180(global-set-key [C-drag-n-drop] 'w32-drag-n-drop-other-frame)
181
a73c80a3
GV
182;; Keyboard layout/language change events
183;; For now ignore language-change events; in the future
184;; we should switch the Emacs Input Method to match the
185;; new layout/language selected by the user.
186(global-set-key [language-change] 'ignore)
187
ee78dc32
GV
188(defvar x-invocation-args)
189
190(defvar x-command-line-resources nil)
191
192(defconst x-option-alist
193 '(("-bw" . x-handle-numeric-switch)
194 ("-d" . x-handle-display)
195 ("-display" . x-handle-display)
196 ("-name" . x-handle-name-rn-switch)
197 ("-rn" . x-handle-name-rn-switch)
198 ("-T" . x-handle-switch)
199 ("-r" . x-handle-switch)
200 ("-rv" . x-handle-switch)
201 ("-reverse" . x-handle-switch)
202 ("-fn" . x-handle-switch)
203 ("-font" . x-handle-switch)
204 ("-ib" . x-handle-numeric-switch)
205 ("-g" . x-handle-geometry)
206 ("-geometry" . x-handle-geometry)
207 ("-fg" . x-handle-switch)
208 ("-foreground". x-handle-switch)
209 ("-bg" . x-handle-switch)
210 ("-background". x-handle-switch)
211 ("-ms" . x-handle-switch)
212 ("-itype" . x-handle-switch)
213 ("-i" . x-handle-switch)
214 ("-iconic" . x-handle-iconic)
215 ("-xrm" . x-handle-xrm-switch)
216 ("-cr" . x-handle-switch)
217 ("-vb" . x-handle-switch)
218 ("-hb" . x-handle-switch)
219 ("-bd" . x-handle-switch)))
220
221(defconst x-long-option-alist
222 '(("--border-width" . "-bw")
223 ("--display" . "-d")
224 ("--name" . "-name")
225 ("--title" . "-T")
226 ("--reverse-video" . "-reverse")
227 ("--font" . "-font")
228 ("--internal-border" . "-ib")
229 ("--geometry" . "-geometry")
230 ("--foreground-color" . "-fg")
231 ("--background-color" . "-bg")
232 ("--mouse-color" . "-ms")
233 ("--icon-type" . "-itype")
234 ("--iconic" . "-iconic")
235 ("--xrm" . "-xrm")
236 ("--cursor-color" . "-cr")
237 ("--vertical-scroll-bars" . "-vb")
238 ("--border-color" . "-bd")))
239
240(defconst x-switch-definitions
241 '(("-name" name)
242 ("-T" name)
243 ("-r" reverse t)
244 ("-rv" reverse t)
245 ("-reverse" reverse t)
246 ("-fn" font)
247 ("-font" font)
248 ("-ib" internal-border-width)
249 ("-fg" foreground-color)
250 ("-foreground" foreground-color)
251 ("-bg" background-color)
252 ("-background" background-color)
253 ("-ms" mouse-color)
254 ("-cr" cursor-color)
255 ("-itype" icon-type t)
256 ("-i" icon-type t)
257 ("-vb" vertical-scroll-bars t)
258 ("-hb" horizontal-scroll-bars t)
259 ("-bd" border-color)
260 ("-bw" border-width)))
261
262;; Handler for switches of the form "-switch value" or "-switch".
263(defun x-handle-switch (switch)
264 (let ((aelt (assoc switch x-switch-definitions)))
265 (if aelt
266 (if (nth 2 aelt)
267 (setq default-frame-alist
268 (cons (cons (nth 1 aelt) (nth 2 aelt))
269 default-frame-alist))
270 (setq default-frame-alist
271 (cons (cons (nth 1 aelt)
272 (car x-invocation-args))
273 default-frame-alist)
274 x-invocation-args (cdr x-invocation-args))))))
275
276;; Make -iconic apply only to the initial frame!
277(defun x-handle-iconic (switch)
278 (setq initial-frame-alist
279 (cons '(visibility . icon) initial-frame-alist)))
280
281;; Handler for switches of the form "-switch n"
282(defun x-handle-numeric-switch (switch)
283 (let ((aelt (assoc switch x-switch-definitions)))
284 (if aelt
285 (setq default-frame-alist
286 (cons (cons (nth 1 aelt)
287 (string-to-int (car x-invocation-args)))
288 default-frame-alist)
289 x-invocation-args
290 (cdr x-invocation-args)))))
291
292;; Handle the -xrm option.
293(defun x-handle-xrm-switch (switch)
294 (or (consp x-invocation-args)
295 (error "%s: missing argument to `%s' option" (invocation-name) switch))
296 (setq x-command-line-resources (car x-invocation-args))
297 (setq x-invocation-args (cdr x-invocation-args)))
298
299;; Handle the geometry option
300(defun x-handle-geometry (switch)
301 (let ((geo (x-parse-geometry (car x-invocation-args))))
302 (setq initial-frame-alist
303 (append initial-frame-alist
304 (if (or (assq 'left geo) (assq 'top geo))
305 '((user-position . t)))
306 (if (or (assq 'height geo) (assq 'width geo))
307 '((user-size . t)))
308 geo)
309 x-invocation-args (cdr x-invocation-args))))
310
311;; Handle the -name and -rn options. Set the variable x-resource-name
312;; to the option's operand; if the switch was `-name', set the name of
313;; the initial frame, too.
314(defun x-handle-name-rn-switch (switch)
315 (or (consp x-invocation-args)
316 (error "%s: missing argument to `%s' option" (invocation-name) switch))
317 (setq x-resource-name (car x-invocation-args)
318 x-invocation-args (cdr x-invocation-args))
319 (if (string= switch "-name")
320 (setq initial-frame-alist (cons (cons 'name x-resource-name)
321 initial-frame-alist))))
322
323(defvar x-display-name nil
324 "The display name specifying server and frame.")
325
326(defun x-handle-display (switch)
327 (setq x-display-name (car x-invocation-args)
328 x-invocation-args (cdr x-invocation-args)))
329
330(defvar x-invocation-args nil)
331
332(defun x-handle-args (args)
333 "Process the X-related command line options in ARGS.
334This is done before the user's startup file is loaded. They are copied to
335x-invocation args from which the X-related things are extracted, first
336the switch (e.g., \"-fg\") in the following code, and possible values
337\(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
338This returns ARGS with the arguments that have been processed removed."
90abecd3 339 ;;(message "%s" args)
ee78dc32
GV
340 (setq x-invocation-args args
341 args nil)
342 (while x-invocation-args
343 (let* ((this-switch (car x-invocation-args))
344 (orig-this-switch this-switch)
345 completion argval aelt)
346 (setq x-invocation-args (cdr x-invocation-args))
347 ;; Check for long options with attached arguments
348 ;; and separate out the attached option argument into argval.
349 (if (string-match "^--[^=]*=" this-switch)
350 (setq argval (substring this-switch (match-end 0))
351 this-switch (substring this-switch 0 (1- (match-end 0)))))
352 (setq completion (try-completion this-switch x-long-option-alist))
353 (if (eq completion t)
354 ;; Exact match for long option.
355 (setq this-switch (cdr (assoc this-switch x-long-option-alist)))
356 (if (stringp completion)
357 (let ((elt (assoc completion x-long-option-alist)))
358 ;; Check for abbreviated long option.
359 (or elt
360 (error "Option `%s' is ambiguous" this-switch))
361 (setq this-switch (cdr elt)))
362 ;; Check for a short option.
363 (setq argval nil this-switch orig-this-switch)))
364 (setq aelt (assoc this-switch x-option-alist))
365 (if aelt
366 (if argval
367 (let ((x-invocation-args
368 (cons argval x-invocation-args)))
369 (funcall (cdr aelt) this-switch))
370 (funcall (cdr aelt) this-switch))
371 (setq args (cons this-switch args)))))
372 (setq args (nreverse args)))
373
374
375\f
376;;
377;; Available colors
378;;
379
380(defvar x-colors '("aquamarine"
381 "Aquamarine"
382 "medium aquamarine"
383 "MediumAquamarine"
384 "black"
385 "Black"
386 "blue"
387 "Blue"
388 "cadet blue"
389 "CadetBlue"
390 "cornflower blue"
391 "CornflowerBlue"
392 "dark slate blue"
393 "DarkSlateBlue"
394 "light blue"
395 "LightBlue"
396 "light steel blue"
397 "LightSteelBlue"
398 "medium blue"
399 "MediumBlue"
400 "medium slate blue"
401 "MediumSlateBlue"
402 "midnight blue"
403 "MidnightBlue"
404 "navy blue"
405 "NavyBlue"
406 "navy"
407 "Navy"
408 "sky blue"
409 "SkyBlue"
410 "slate blue"
411 "SlateBlue"
412 "steel blue"
413 "SteelBlue"
414 "coral"
415 "Coral"
416 "cyan"
417 "Cyan"
418 "firebrick"
419 "Firebrick"
420 "brown"
421 "Brown"
422 "gold"
423 "Gold"
424 "goldenrod"
425 "Goldenrod"
426 "green"
427 "Green"
428 "dark green"
429 "DarkGreen"
430 "dark olive green"
431 "DarkOliveGreen"
432 "forest green"
433 "ForestGreen"
434 "lime green"
435 "LimeGreen"
436 "medium sea green"
437 "MediumSeaGreen"
438 "medium spring green"
439 "MediumSpringGreen"
440 "pale green"
441 "PaleGreen"
442 "sea green"
443 "SeaGreen"
444 "spring green"
445 "SpringGreen"
446 "yellow green"
447 "YellowGreen"
448 "dark slate grey"
449 "DarkSlateGrey"
450 "dark slate gray"
451 "DarkSlateGray"
452 "dim grey"
453 "DimGrey"
454 "dim gray"
455 "DimGray"
456 "light grey"
457 "LightGrey"
458 "light gray"
459 "LightGray"
460 "gray"
461 "grey"
462 "Gray"
463 "Grey"
464 "khaki"
465 "Khaki"
466 "magenta"
467 "Magenta"
468 "maroon"
469 "Maroon"
470 "orange"
471 "Orange"
472 "orchid"
473 "Orchid"
474 "dark orchid"
475 "DarkOrchid"
476 "medium orchid"
477 "MediumOrchid"
478 "pink"
479 "Pink"
480 "plum"
481 "Plum"
482 "red"
483 "Red"
484 "indian red"
485 "IndianRed"
486 "medium violet red"
487 "MediumVioletRed"
488 "orange red"
489 "OrangeRed"
490 "violet red"
491 "VioletRed"
492 "salmon"
493 "Salmon"
494 "sienna"
495 "Sienna"
496 "tan"
497 "Tan"
498 "thistle"
499 "Thistle"
500 "turquoise"
501 "Turquoise"
502 "dark turquoise"
503 "DarkTurquoise"
504 "medium turquoise"
505 "MediumTurquoise"
506 "violet"
507 "Violet"
508 "blue violet"
509 "BlueViolet"
510 "wheat"
511 "Wheat"
512 "white"
513 "White"
514 "yellow"
515 "Yellow"
516 "green yellow"
517 "GreenYellow")
518 "The full list of X colors from the `rgb.text' file.")
519
f795f633
EZ
520(defun xw-defined-colors (&optional frame)
521 "Internal function called by `defined-colors', which see."
ee78dc32 522 (or frame (setq frame (selected-frame)))
e5e0a3c9
GV
523 (let* ((color-map-colors (mapcar (lambda (clr) (car clr)) w32-color-map))
524 (all-colors (or color-map-colors x-colors))
525 (this-color nil)
526 (defined-colors nil))
527 (message "Defining colors...")
ee78dc32
GV
528 (while all-colors
529 (setq this-color (car all-colors)
530 all-colors (cdr all-colors))
79b24da3 531 (and (color-supported-p this-color frame t)
ee78dc32
GV
532 (setq defined-colors (cons this-color defined-colors))))
533 defined-colors))
534\f
d66be571 535\f
ee78dc32
GV
536;;;; Function keys
537
d66be571
GV
538;;; make f10 activate the real menubar rather than the mini-buffer menu
539;;; navigation feature.
540(global-set-key [f10] (lambda ()
541 (interactive) (w32-send-sys-command ?\xf100)))
542
ee78dc32
GV
543(defun iconify-or-deiconify-frame ()
544 "Iconify the selected frame, or deiconify if it's currently an icon."
545 (interactive)
546 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
547 (iconify-frame)
548 (make-frame-visible)))
549
550(substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
551 global-map)
552
ee78dc32
GV
553\f
554;;;; Selections and cut buffers
555
556;;; We keep track of the last text selected here, so we can check the
557;;; current selection against it, and avoid passing back our own text
558;;; from x-cut-buffer-or-selection-value.
559(defvar x-last-selected-text nil)
560
561;;; It is said that overlarge strings are slow to put into the cut buffer.
562;;; Note this value is overridden below.
563(defvar x-cut-buffer-max 20000
564 "Max number of characters to put in the cut buffer.")
565
566(defvar x-select-enable-clipboard t
567 "Non-nil means cutting and pasting uses the clipboard.
568This is in addition to the primary selection.")
569
570(defun x-select-text (text &optional push)
571 (if x-select-enable-clipboard
fbd6baed 572 (w32-set-clipboard-data text))
b2b9ff5e 573 (setq x-last-selected-text text))
ee78dc32
GV
574
575;;; Return the value of the current selection.
576;;; Consult the selection, then the cut buffer. Treat empty strings
577;;; as if they were unset.
578(defun x-get-selection-value ()
579 (if x-select-enable-clipboard
580 (let (text)
581 ;; Don't die if x-get-selection signals an error.
582 (condition-case c
fbd6baed
GV
583 (setq text (w32-get-clipboard-data))
584 (error (message "w32-get-clipboard-data:%s" c)))
ee78dc32 585 (if (string= text "") (setq text nil))
b2b9ff5e
RS
586 (cond
587 ((not text) nil)
588 ((eq text x-last-selected-text) nil)
589 ((string= text x-last-selected-text)
590 ;; Record the newer string, so subsequent calls can use the 'eq' test.
591 (setq x-last-selected-text text)
592 nil)
593 (t
594 (setq x-last-selected-text text))))))
ee78dc32 595\f
4664455c
GV
596(defalias 'x-cut-buffer-or-selection-value 'x-get-selection-value)
597
598\f
ee78dc32
GV
599;;; Do the actual Windows setup here; the above code just defines
600;;; functions and variables that we use now.
601
602(setq command-line-args (x-handle-args command-line-args))
603
604;;; Make sure we have a valid resource name.
605(or (stringp x-resource-name)
606 (let (i)
607 (setq x-resource-name (invocation-name))
608
609 ;; Change any . or * characters in x-resource-name to hyphens,
610 ;; so as not to choke when we use it in X resource queries.
611 (while (setq i (string-match "[.*]" x-resource-name))
612 (aset x-resource-name i ?-))))
613
614;; For the benefit of older Emacses (19.27 and earlier) that are sharing
615;; the same lisp directory, don't pass the third argument unless we seem
616;; to have the multi-display support.
617(if (fboundp 'x-close-connection)
618 (x-open-connection ""
619 x-command-line-resources
620 ;; Exit Emacs with fatal error if this fails.
621 t)
622 (x-open-connection ""
623 x-command-line-resources))
624
625(setq frame-creation-function 'x-create-frame-with-faces)
626
627(setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
628 x-cut-buffer-max))
629
fbd6baed 630;; W32 expects the menu bar cut and paste commands to use the clipboard.
ee78dc32
GV
631;; This has ,? to match both on Sunos and on Solaris.
632(menu-bar-enable-clipboard)
633
4664455c
GV
634;; W32 systems have different fonts than commonly found on X, so
635;; we define our own standard fontset here.
636(defvar w32-standard-fontset-spec
e7a8ad1f 637 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
4664455c
GV
638 "String of fontset spec of the standard fontset. This defines a
639fontset consisting of the Courier New variations for European
640languages which are distributed with Windows as \"Multilanguage Support\".
641
642See the documentation of `create-fontset-from-fontset-spec for the format.")
643
7ed4e9a7
JR
644; (if (fboundp 'new-fontset)
645; (progn
646; (defun w32-create-initial-fontsets ()
647; "Create fontset-startup, fontset-standard and any fontsets
648; specified in X resources."
649; ;; Create the standard fontset.
650; (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
651
652; ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
653; (create-fontset-from-x-resource)
654
655; ;; Try to create a fontset from a font specification which comes
656; ;; from initial-frame-alist, default-frame-alist, or X resource.
657; ;; A font specification in command line argument (i.e. -fn XXXX)
658; ;; should be already in default-frame-alist as a `font'
659; ;; parameter. However, any font specifications in site-start
660; ;; library, user's init file (.emacs), and default.el are not
661; ;; yet handled here.
662
663; (let ((font (or (cdr (assq 'font initial-frame-alist))
664; (cdr (assq 'font default-frame-alist))
665; (x-get-resource "font" "Font")))
666; xlfd-fields resolved-name)
667; (if (and font
668; (not (query-fontset font))
669; (setq resolved-name (x-resolve-font-name font))
670; (setq xlfd-fields (x-decompose-font-name font)))
671; (if (string= "fontset"
672; (aref xlfd-fields xlfd-regexp-registry-subnum))
673; (new-fontset font
674; (x-complement-fontset-spec xlfd-fields nil))
675; ;; Create a fontset from FONT. The fontset name is
676; ;; generated from FONT. Create style variants of the
677; ;; fontset too. Font names in the variants are
678; ;; generated automatially unless X resources
679; ;; XXX.attribyteFont explicitly specify them.
680; (let ((styles (mapcar 'car x-style-funcs-alist))
681; (faces '(bold italic bold-italic))
682; face face-font fontset fontset-spec)
683; (while faces
684; (setq face (car faces))
685; (setq face-font (x-get-resource (concat (symbol-name face)
686; ".attributeFont")
687; "Face.AttributeFont"))
688; (if face-font
689; (setq styles (cons (cons face face-font)
690; (delq face styles))))
691; (setq faces (cdr faces)))
692; (aset xlfd-fields xlfd-regexp-foundry-subnum nil)
693; (aset xlfd-fields xlfd-regexp-family-subnum nil)
694; (aset xlfd-fields xlfd-regexp-registry-subnum "fontset")
695; (aset xlfd-fields xlfd-regexp-encoding-subnum "startup")
696; ;; The fontset name should have concrete values in
697; ;; weight and slant field.
698; (let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum))
699; (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
700; xlfd-temp)
701; (if (or (not weight) (string-match "[*?]*" weight))
702; (progn
703; (setq xlfd-temp
704; (x-decompose-font-name resolved-name))
705; (aset xlfd-fields xlfd-regexp-weight-subnum
706; (aref xlfd-temp xlfd-regexp-weight-subnum))))
707; (if (or (not slant) (string-match "[*?]*" slant))
708; (progn
709; (or xlfd-temp
710; (setq xlfd-temp
711; (x-decompose-font-name resolved-name)))
712; (aset xlfd-fields xlfd-regexp-slant-subnum
713; (aref xlfd-temp xlfd-regexp-slant-subnum)))))
714; (setq fontset (x-compose-font-name xlfd-fields))
715; (create-fontset-from-fontset-spec
716; (concat fontset ", ascii:" font) styles)
717; )))))
718; ;; This cannot be run yet, as creating fontsets requires a
719; ;; Window to be initialised so the fonts can be listed.
720; ;; Add it to a hook so it gets run later.
721; (add-hook 'before-init-hook 'w32-create-initial-fontsets)
722; ))
4664455c 723
ee78dc32
GV
724;; Apply a geometry resource to the initial frame. Put it at the end
725;; of the alist, so that anything specified on the command line takes
726;; precedence.
727(let* ((res-geometry (x-get-resource "geometry" "Geometry"))
728 parsed)
729 (if res-geometry
730 (progn
731 (setq parsed (x-parse-geometry res-geometry))
732 ;; If the resource specifies a position,
733 ;; call the position and size "user-specified".
734 (if (or (assq 'top parsed) (assq 'left parsed))
735 (setq parsed (cons '(user-position . t)
736 (cons '(user-size . t) parsed))))
737 ;; All geometry parms apply to the initial frame.
738 (setq initial-frame-alist (append initial-frame-alist parsed))
739 ;; The size parms apply to all frames.
740 (if (assq 'height parsed)
741 (setq default-frame-alist
742 (cons (cons 'height (cdr (assq 'height parsed)))
743 default-frame-alist)))
744 (if (assq 'width parsed)
745 (setq default-frame-alist
746 (cons (cons 'width (cdr (assq 'width parsed)))
747 default-frame-alist))))))
748
749;; Check the reverseVideo resource.
750(let ((case-fold-search t))
751 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
752 (if (and rv
753 (string-match "^\\(true\\|yes\\|on\\)$" rv))
754 (setq default-frame-alist
755 (cons '(reverse . t) default-frame-alist)))))
756
757;; Set x-selection-timeout, measured in milliseconds.
758(let ((res-selection-timeout
759 (x-get-resource "selectionTimeout" "SelectionTimeout")))
760 (setq x-selection-timeout 20000)
761 (if res-selection-timeout
762 (setq x-selection-timeout (string-to-number res-selection-timeout))))
763
764(defun x-win-suspend-error ()
b63f9ba1 765 (error "Suspending an emacs running under W32 makes no sense"))
ee78dc32
GV
766(add-hook 'suspend-hook 'x-win-suspend-error)
767
768;;; Arrange for the kill and yank functions to set and check the clipboard.
769(setq interprogram-cut-function 'x-select-text)
770(setq interprogram-paste-function 'x-get-selection-value)
771
fbd6baed 772;;; Turn off window-splitting optimization; w32 is usually fast enough
ee78dc32
GV
773;;; that this is only annoying.
774(setq split-window-keep-point t)
775
776;; Don't show the frame name; that's redundant.
f182c531 777(setq-default mode-line-frame-identification " ")
ee78dc32
GV
778
779;;; Set to a system sound if you want a fancy bell.
780(set-message-beep 'ok)
781
fbd6baed 782;; Remap some functions to call w32 common dialogs
ee78dc32
GV
783
784(defun internal-face-interactive (what &optional bool)
785 (let* ((fn (intern (concat "face-" what)))
3247de96
DL
786 (prompt (concat "Set " what " of face "))
787 (face (read-face-name prompt))
ee78dc32
GV
788 (default (if (fboundp fn)
789 (or (funcall fn face (selected-frame))
790 (funcall fn 'default (selected-frame)))))
791 (fn-win (intern (concat (symbol-name window-system) "-select-" what)))
3ce36200
AI
792 value)
793 (setq value
794 (cond ((fboundp fn-win)
795 (funcall fn-win))
796 ((eq bool 'color)
797 (completing-read (concat prompt " " (symbol-name face) " to: ")
798 (mapcar (function (lambda (color)
799 (cons color color)))
800 x-colors)
801 nil nil nil nil default))
802 (bool
803 (y-or-n-p (concat "Should face " (symbol-name face)
804 " be " bool "? ")))
805 (t
806 (read-string (concat prompt " " (symbol-name face) " to: ")
807 nil nil default))))
808 (list face (if (equal value "") nil value))))
ee78dc32 809
b63f9ba1 810;; Redefine the font selection to use the standard W32 dialog
cf14c2b4 811(defvar w32-use-w32-font-dialog t
4664455c 812 "*Use the standard font dialog if 't' - otherwise pop up a menu of
cf14c2b4
GV
813some standard fonts like X does - including fontsets")
814
815(defvar w32-fixed-font-alist
816 '("Font menu"
817 ("Misc"
818 ;; For these, we specify the pixel height and width.
819 ("fixed" "Fixedsys")
820 ("")
821 ("Terminal 5x4"
822 "-*-Terminal-normal-r-*-*-*-45-*-*-c-40-*-oem")
823 ("Terminal 6x8"
824 "-*-Terminal-normal-r-*-*-*-60-*-*-c-80-*-oem")
825 ("Terminal 9x5"
826 "-*-Terminal-normal-r-*-*-*-90-*-*-c-50-*-oem")
827 ("Terminal 9x7"
828 "-*-Terminal-normal-r-*-*-*-90-*-*-c-70-*-oem")
829 ("Terminal 9x8"
830 "-*-Terminal-normal-r-*-*-*-90-*-*-c-80-*-oem")
831 ("Terminal 12x12"
832 "-*-Terminal-normal-r-*-*-*-120-*-*-c-120-*-oem")
833 ("Terminal 14x10"
834 "-*-Terminal-normal-r-*-*-*-135-*-*-c-100-*-oem")
835 ("Terminal 6x6 Bold"
836 "-*-Terminal-bold-r-*-*-*-60-*-*-c-60-*-oem")
837 ("")
838 ("Lucida Sans Typewriter.8"
839 "-*-Lucida Sans Typewriter-normal-r-*-*-11-*-*-*-c-*-iso8859-1")
840 ("Lucida Sans Typewriter.9"
841 "-*-Lucida Sans Typewriter-normal-r-*-*-12-*-*-*-c-*-iso8859-1")
842 ("Lucida Sans Typewriter.10"
843 "-*-Lucida Sans Typewriter-normal-r-*-*-13-*-*-*-c-*-iso8859-1")
844 ("Lucida Sans Typewriter.11"
845 "-*-Lucida Sans Typewriter-normal-r-*-*-15-*-*-*-c-*-iso8859-1")
846 ("Lucida Sans Typewriter.12"
847 "-*-Lucida Sans Typewriter-normal-r-*-*-16-*-*-*-c-*-iso8859-1")
848 ("Lucida Sans Typewriter.8 Bold"
849 "-*-Lucida Sans Typewriter-semibold-r-*-*-11-*-*-*-c-*-iso8859-1")
850 ("Lucida Sans Typewriter.9 Bold"
851 "-*-Lucida Sans Typewriter-semibold-r-*-*-12-*-*-*-c-*-iso8859-1")
852 ("Lucida Sans Typewriter.10 Bold"
853 "-*-Lucida Sans Typewriter-semibold-r-*-*-13-*-*-*-c-*-iso8859-1")
854 ("Lucida Sans Typewriter.11 Bold"
855 "-*-Lucida Sans Typewriter-semibold-r-*-*-15-*-*-*-c-*-iso8859-1")
856 ("Lucida Sans Typewriter.12 Bold"
857 "-*-Lucida Sans Typewriter-semibold-r-*-*-16-*-*-*-c-*-iso8859-1"))
858 ("Courier"
859 ("Courier 10x8"
860 "-*-Courier-*normal-r-*-*-*-97-*-*-c-80-iso8859-1")
861 ("Courier 12x9"
862 "-*-Courier-*normal-r-*-*-*-120-*-*-c-90-iso8859-1")
863 ("Courier 15x12"
864 "-*-Courier-*normal-r-*-*-*-150-*-*-c-120-iso8859-1")
865 ;; For these, we specify the point height.
866 ("")
867 ("8" "-*-Courier New-normal-r-*-*-11-*-*-*-c-*-iso8859-1")
868 ("9" "-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-1")
869 ("10" "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-iso8859-1")
870 ("11" "-*-Courier New-normal-r-*-*-15-*-*-*-c-*-iso8859-1")
871 ("12" "-*-Courier New-normal-r-*-*-16-*-*-*-c-*-iso8859-1")
872 ("8 bold" "-*-Courier New-bold-r-*-*-11-*-*-*-c-*-iso8859-1")
873 ("9 bold" "-*-Courier New-bold-r-*-*-12-*-*-*-c-*-iso8859-1")
874 ("10 bold" "-*-Courier New-bold-r-*-*-13-*-*-*-c-*-iso8859-1")
875 ("11 bold" "-*-Courier New-bold-r-*-*-15-*-*-*-c-*-iso8859-1")
876 ("12 bold" "-*-Courier New-bold-r-*-*-16-*-*-*-c-*-iso8859-1")
877 ("8 italic" "-*-Courier New-normal-i-*-*-11-*-*-*-c-*-iso8859-1")
878 ("9 italic" "-*-Courier New-normal-i-*-*-12-*-*-*-c-*-iso8859-1")
879 ("10 italic" "-*-Courier New-normal-i-*-*-13-*-*-*-c-*-iso8859-1")
880 ("11 italic" "-*-Courier New-normal-i-*-*-15-*-*-*-c-*-iso8859-1")
881 ("12 italic" "-*-Courier New-normal-i-*-*-16-*-*-*-c-*-iso8859-1")
882 ("8 bold italic" "-*-Courier New-bold-i-*-*-11-*-*-*-c-*-iso8859-1")
883 ("9 bold italic" "-*-Courier New-bold-i-*-*-12-*-*-*-c-*-iso8859-1")
884 ("10 bold italic" "-*-Courier New-bold-i-*-*-13-*-*-*-c-*-iso8859-1")
885 ("11 bold italic" "-*-Courier New-bold-i-*-*-15-*-*-*-c-*-iso8859-1")
886 ("12 bold italic" "-*-Courier New-bold-i-*-*-16-*-*-*-c-*-iso8859-1")
887 ))
888 "Fonts suitable for use in Emacs. Initially this is a list of some
889fixed width fonts that most people will have like Terminal and
890Courier. These fonts are used in the font menu if the variable
891`w32-use-w32-font-dialog' is nil.")
ee78dc32 892
d76d2456
AI
893;;; Enable Japanese fonts on Windows to be used by default.
894(put-charset-property 'katakana-jisx0201 'x-charset-registry "JISX0208-SJIS")
895(put-charset-property 'latin-jisx0201 'x-charset-registry "JISX0208-SJIS")
896(put-charset-property 'japanese-jisx0208 'x-charset-registry "JISX0208-SJIS")
897(put-charset-property 'japanese-jisx0208-1978 'x-charset-registry
898 "JISX0208-SJIS")
899
ee78dc32 900(defun mouse-set-font (&rest fonts)
e7a8ad1f
GV
901 "Select a font. If `w32-use-w32-font-dialog' is non-nil (the default),
902use the Windows font dialog. Otherwise use a pop-up menu (like Emacs
903on other platforms) initialized with the fonts in
904`w32-fixed-font-alist'. Emacs will attempt to create a fontset from
905the font chosen, covering all the charsets that can be fully represented
906with the font."
cf14c2b4
GV
907 (interactive
908 (if w32-use-w32-font-dialog
efaec94e
KH
909 (let ((chosen-font (w32-select-font)))
910 (and chosen-font (list chosen-font)))
cf14c2b4
GV
911 (x-popup-menu
912 last-nonmenu-event
913 ;; Append list of fontsets currently defined.
4664455c
GV
914 (if (fboundp 'new-fontset)
915 (append w32-fixed-font-alist (list (generate-fontset-menu)))))))
cf14c2b4 916 (if fonts
81af6e72 917 (let (font fontset xlfd resolved-font)
cf14c2b4
GV
918 (while fonts
919 (condition-case nil
920 (progn
e7a8ad1f
GV
921 (setq font (car fonts))
922 (if (fontset-name-p font)
923 (setq fontset font)
924 (condition-case nil
81af6e72
AI
925 (setq resolved-font (x-resolve-font-name font)
926 xlfd (x-decompose-font-name resolved-font)
927 fontset
928 (create-fontset-from-ascii-font
929 font resolved-font
930 (format "%s_%s_%s_%s"
931 (aref xlfd xlfd-regexp-family-subnum)
932 (aref xlfd xlfd-regexp-registry-subnum)
933 (aref xlfd xlfd-regexp-encoding-subnum)
934 (aref xlfd
935 xlfd-regexp-pixelsize-subnum))))
e7a8ad1f
GV
936 (error nil)))
937 (if fontset
938 (set-default-font fontset)
939 (set-default-font font))
940 (setq fonts nil))
941 (error (setq fonts (cdr fonts)))))
cf14c2b4
GV
942 (if (null font)
943 (error "Font not found")))))
ee78dc32 944
b63f9ba1 945;;; w32-win.el ends here