Only require fontset when new-fontset is bound.
[bpt/emacs.git] / lisp / term / w32-win.el
1 ;;; w32-win.el --- parse switches controlling interface with W32 window system
2
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4
5 ;; Author: Kevin Gallo
6 ;; Keywords: terminals
7
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.
24
25 ;;; Commentary:
26
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.
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
70 (if (not (eq window-system 'w32))
71 (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name)))
72
73 (require 'frame)
74 (require 'mouse)
75 (require 'scroll-bar)
76 (require 'faces)
77 (require 'select)
78 (require 'menu-bar)
79 (if (fboundp 'new-fontset)
80 (require 'fontset))
81
82 ;; The following definition is used for debugging scroll bar events.
83 ;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
84
85 (defvar mouse-wheel-scroll-amount 4
86 "*Number of lines to scroll per click of the mouse wheel.")
87
88 (defun mouse-wheel-scroll-line (event)
89 "Scroll the window in which EVENT occurred by `mouse-wheel-scroll-amount'."
90 (interactive "e")
91 (condition-case nil
92 (if (< (car (cdr (cdr event))) 0)
93 (scroll-up mouse-wheel-scroll-amount)
94 (scroll-down mouse-wheel-scroll-amount))
95 (error nil)))
96
97 ;; for scroll-in-place.el, this way the -scroll-line and -scroll-screen
98 ;; commands won't interact
99 (setq scroll-command-groups (list '(mouse-wheel-scroll-line)))
100
101 (defun mouse-wheel-scroll-screen (event)
102 "Scroll the window in which EVENT occurred by `mouse-wheel-scroll-amount'."
103 (interactive "e")
104 (condition-case nil
105 (if (< (car (cdr (cdr event))) 0)
106 (scroll-up)
107 (scroll-down))
108 (error nil)))
109
110 ;; Bind the mouse-wheel event:
111 (global-set-key [mouse-wheel] 'mouse-wheel-scroll-line)
112 (global-set-key [C-mouse-wheel] 'mouse-wheel-scroll-screen)
113
114 (defun w32-drag-n-drop-debug (event)
115 "Print the drag-n-drop EVENT in a readable form."
116 (interactive "e")
117 (princ event))
118
119 (defun w32-drag-n-drop (event)
120 "Edit the files listed in the drag-n-drop EVENT.
121 Switch to a buffer editing the last file dropped."
122 (interactive "e")
123 (save-excursion
124 ;; Make sure the drop target has positive co-ords
125 ;; before setting the selected frame - otherwise it
126 ;; won't work. <skx@tardis.ed.ac.uk>
127 (let* ((window (posn-window (event-start event)))
128 (coords (posn-x-y (event-start event)))
129 (x (car coords))
130 (y (cdr coords)))
131 (if (and (> x 0) (> y 0))
132 (set-frame-selected-window nil window))
133 (mapcar 'find-file (car (cdr (cdr event)))))
134 (raise-frame)))
135
136 (defun w32-drag-n-drop-other-frame (event)
137 "Edit the files listed in the drag-n-drop EVENT, in other frames.
138 May create new frames, or reuse existing ones. The frame editing
139 the last file dropped is selected."
140 (interactive "e")
141 (mapcar 'find-file-other-frame (car (cdr (cdr event)))))
142
143 ;; Bind the drag-n-drop event.
144 (global-set-key [drag-n-drop] 'w32-drag-n-drop)
145 (global-set-key [C-drag-n-drop] 'w32-drag-n-drop-other-frame)
146
147 ;; Keyboard layout/language change events
148 ;; For now ignore language-change events; in the future
149 ;; we should switch the Emacs Input Method to match the
150 ;; new layout/language selected by the user.
151 (global-set-key [language-change] 'ignore)
152
153 (defvar x-invocation-args)
154
155 (defvar x-command-line-resources nil)
156
157 (defconst x-option-alist
158 '(("-bw" . x-handle-numeric-switch)
159 ("-d" . x-handle-display)
160 ("-display" . x-handle-display)
161 ("-name" . x-handle-name-rn-switch)
162 ("-rn" . x-handle-name-rn-switch)
163 ("-T" . x-handle-switch)
164 ("-r" . x-handle-switch)
165 ("-rv" . x-handle-switch)
166 ("-reverse" . x-handle-switch)
167 ("-fn" . x-handle-switch)
168 ("-font" . x-handle-switch)
169 ("-ib" . x-handle-numeric-switch)
170 ("-g" . x-handle-geometry)
171 ("-geometry" . x-handle-geometry)
172 ("-fg" . x-handle-switch)
173 ("-foreground". x-handle-switch)
174 ("-bg" . x-handle-switch)
175 ("-background". x-handle-switch)
176 ("-ms" . x-handle-switch)
177 ("-itype" . x-handle-switch)
178 ("-i" . x-handle-switch)
179 ("-iconic" . x-handle-iconic)
180 ("-xrm" . x-handle-xrm-switch)
181 ("-cr" . x-handle-switch)
182 ("-vb" . x-handle-switch)
183 ("-hb" . x-handle-switch)
184 ("-bd" . x-handle-switch)))
185
186 (defconst x-long-option-alist
187 '(("--border-width" . "-bw")
188 ("--display" . "-d")
189 ("--name" . "-name")
190 ("--title" . "-T")
191 ("--reverse-video" . "-reverse")
192 ("--font" . "-font")
193 ("--internal-border" . "-ib")
194 ("--geometry" . "-geometry")
195 ("--foreground-color" . "-fg")
196 ("--background-color" . "-bg")
197 ("--mouse-color" . "-ms")
198 ("--icon-type" . "-itype")
199 ("--iconic" . "-iconic")
200 ("--xrm" . "-xrm")
201 ("--cursor-color" . "-cr")
202 ("--vertical-scroll-bars" . "-vb")
203 ("--border-color" . "-bd")))
204
205 (defconst x-switch-definitions
206 '(("-name" name)
207 ("-T" name)
208 ("-r" reverse t)
209 ("-rv" reverse t)
210 ("-reverse" reverse t)
211 ("-fn" font)
212 ("-font" font)
213 ("-ib" internal-border-width)
214 ("-fg" foreground-color)
215 ("-foreground" foreground-color)
216 ("-bg" background-color)
217 ("-background" background-color)
218 ("-ms" mouse-color)
219 ("-cr" cursor-color)
220 ("-itype" icon-type t)
221 ("-i" icon-type t)
222 ("-vb" vertical-scroll-bars t)
223 ("-hb" horizontal-scroll-bars t)
224 ("-bd" border-color)
225 ("-bw" border-width)))
226
227
228 (defun x-handle-switch (switch)
229 "Handle SWITCH of the form \"-switch value\" or \"-switch\"."
230 (let ((aelt (assoc switch x-switch-definitions)))
231 (if aelt
232 (if (nth 2 aelt)
233 (setq default-frame-alist
234 (cons (cons (nth 1 aelt) (nth 2 aelt))
235 default-frame-alist))
236 (setq default-frame-alist
237 (cons (cons (nth 1 aelt)
238 (car x-invocation-args))
239 default-frame-alist)
240 x-invocation-args (cdr x-invocation-args))))))
241
242 (defun x-handle-iconic (switch)
243 "Make \"-iconic\" SWITCH apply only to the initial frame."
244 (setq initial-frame-alist
245 (cons '(visibility . icon) initial-frame-alist)))
246
247
248 (defun x-handle-numeric-switch (switch)
249 "Handle SWITCH of the form \"-switch n\"."
250 (let ((aelt (assoc switch x-switch-definitions)))
251 (if aelt
252 (setq default-frame-alist
253 (cons (cons (nth 1 aelt)
254 (string-to-int (car x-invocation-args)))
255 default-frame-alist)
256 x-invocation-args
257 (cdr x-invocation-args)))))
258
259 (defun x-handle-xrm-switch (switch)
260 "Handle the \"-xrm\" SWITCH."
261 (or (consp x-invocation-args)
262 (error "%s: missing argument to `%s' option" (invocation-name) switch))
263 (setq x-command-line-resources (car x-invocation-args))
264 (setq x-invocation-args (cdr x-invocation-args)))
265
266 (defun x-handle-geometry (switch)
267 "Handle the \"-geometry\" SWITCH."
268 (let* ((geo (x-parse-geometry (car x-invocation-args)))
269 (left (assq 'left geo))
270 (top (assq 'top geo))
271 (height (assq 'height geo))
272 (width (assq 'width geo)))
273 (if (or height width)
274 (setq default-frame-alist
275 (append default-frame-alist
276 '((user-size . t))
277 (if height (list height))
278 (if width (list width)))))
279 (if (or left top)
280 (setq initial-frame-alist
281 (append initial-frame-alist
282 '((user-position . t))
283 (if left (list left))
284 (if top (list top)))))
285 (setq x-invocation-args (cdr x-invocation-args))))
286
287 (defun x-handle-name-rn-switch (switch)
288 "Handle a \"-name\" or \"-rn\" SWITCH."
289 ;; Handle the -name and -rn options. Set the variable x-resource-name
290 ;; to the option's operand; if the switch was `-name', set the name of
291 ;; the initial frame, too.
292 (or (consp x-invocation-args)
293 (error "%s: missing argument to `%s' option" (invocation-name) switch))
294 (setq x-resource-name (car x-invocation-args)
295 x-invocation-args (cdr x-invocation-args))
296 (if (string= switch "-name")
297 (setq initial-frame-alist (cons (cons 'name x-resource-name)
298 initial-frame-alist))))
299
300 (defvar x-display-name nil
301 "The display name specifying server and frame.")
302
303 (defun x-handle-display (switch)
304 "Handle the \"-display\" SWITCH."
305 (setq x-display-name (car x-invocation-args)
306 x-invocation-args (cdr x-invocation-args)))
307
308 (defvar x-invocation-args nil)
309
310 (defun x-handle-args (args)
311 "Process the X-related command line options in ARGS.
312 This is done before the user's startup file is loaded. They are copied to
313 x-invocation args from which the X-related things are extracted, first
314 the switch (e.g., \"-fg\") in the following code, and possible values
315 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
316 This returns ARGS with the arguments that have been processed removed."
317 (setq x-invocation-args args
318 args nil)
319 (while x-invocation-args
320 (let* ((this-switch (car x-invocation-args))
321 (orig-this-switch this-switch)
322 completion argval aelt)
323 (setq x-invocation-args (cdr x-invocation-args))
324 ;; Check for long options with attached arguments
325 ;; and separate out the attached option argument into argval.
326 (if (string-match "^--[^=]*=" this-switch)
327 (setq argval (substring this-switch (match-end 0))
328 this-switch (substring this-switch 0 (1- (match-end 0)))))
329 (setq completion (try-completion this-switch x-long-option-alist))
330 (if (eq completion t)
331 ;; Exact match for long option.
332 (setq this-switch (cdr (assoc this-switch x-long-option-alist)))
333 (if (stringp completion)
334 (let ((elt (assoc completion x-long-option-alist)))
335 ;; Check for abbreviated long option.
336 (or elt
337 (error "Option `%s' is ambiguous" this-switch))
338 (setq this-switch (cdr elt)))
339 ;; Check for a short option.
340 (setq argval nil this-switch orig-this-switch)))
341 (setq aelt (assoc this-switch x-option-alist))
342 (if aelt
343 (if argval
344 (let ((x-invocation-args
345 (cons argval x-invocation-args)))
346 (funcall (cdr aelt) this-switch))
347 (funcall (cdr aelt) this-switch))
348 (setq args (cons this-switch args)))))
349 (setq args (nreverse args)))
350
351
352 \f
353 ;;
354 ;; Available colors
355 ;;
356
357 (defvar x-colors '("LightGreen"
358 "light green"
359 "DarkRed"
360 "dark red"
361 "DarkMagenta"
362 "dark magenta"
363 "DarkCyan"
364 "dark cyan"
365 "DarkBlue"
366 "dark blue"
367 "DarkGray"
368 "dark gray"
369 "DarkGrey"
370 "dark grey"
371 "grey100"
372 "gray100"
373 "grey99"
374 "gray99"
375 "grey98"
376 "gray98"
377 "grey97"
378 "gray97"
379 "grey96"
380 "gray96"
381 "grey95"
382 "gray95"
383 "grey94"
384 "gray94"
385 "grey93"
386 "gray93"
387 "grey92"
388 "gray92"
389 "grey91"
390 "gray91"
391 "grey90"
392 "gray90"
393 "grey89"
394 "gray89"
395 "grey88"
396 "gray88"
397 "grey87"
398 "gray87"
399 "grey86"
400 "gray86"
401 "grey85"
402 "gray85"
403 "grey84"
404 "gray84"
405 "grey83"
406 "gray83"
407 "grey82"
408 "gray82"
409 "grey81"
410 "gray81"
411 "grey80"
412 "gray80"
413 "grey79"
414 "gray79"
415 "grey78"
416 "gray78"
417 "grey77"
418 "gray77"
419 "grey76"
420 "gray76"
421 "grey75"
422 "gray75"
423 "grey74"
424 "gray74"
425 "grey73"
426 "gray73"
427 "grey72"
428 "gray72"
429 "grey71"
430 "gray71"
431 "grey70"
432 "gray70"
433 "grey69"
434 "gray69"
435 "grey68"
436 "gray68"
437 "grey67"
438 "gray67"
439 "grey66"
440 "gray66"
441 "grey65"
442 "gray65"
443 "grey64"
444 "gray64"
445 "grey63"
446 "gray63"
447 "grey62"
448 "gray62"
449 "grey61"
450 "gray61"
451 "grey60"
452 "gray60"
453 "grey59"
454 "gray59"
455 "grey58"
456 "gray58"
457 "grey57"
458 "gray57"
459 "grey56"
460 "gray56"
461 "grey55"
462 "gray55"
463 "grey54"
464 "gray54"
465 "grey53"
466 "gray53"
467 "grey52"
468 "gray52"
469 "grey51"
470 "gray51"
471 "grey50"
472 "gray50"
473 "grey49"
474 "gray49"
475 "grey48"
476 "gray48"
477 "grey47"
478 "gray47"
479 "grey46"
480 "gray46"
481 "grey45"
482 "gray45"
483 "grey44"
484 "gray44"
485 "grey43"
486 "gray43"
487 "grey42"
488 "gray42"
489 "grey41"
490 "gray41"
491 "grey40"
492 "gray40"
493 "grey39"
494 "gray39"
495 "grey38"
496 "gray38"
497 "grey37"
498 "gray37"
499 "grey36"
500 "gray36"
501 "grey35"
502 "gray35"
503 "grey34"
504 "gray34"
505 "grey33"
506 "gray33"
507 "grey32"
508 "gray32"
509 "grey31"
510 "gray31"
511 "grey30"
512 "gray30"
513 "grey29"
514 "gray29"
515 "grey28"
516 "gray28"
517 "grey27"
518 "gray27"
519 "grey26"
520 "gray26"
521 "grey25"
522 "gray25"
523 "grey24"
524 "gray24"
525 "grey23"
526 "gray23"
527 "grey22"
528 "gray22"
529 "grey21"
530 "gray21"
531 "grey20"
532 "gray20"
533 "grey19"
534 "gray19"
535 "grey18"
536 "gray18"
537 "grey17"
538 "gray17"
539 "grey16"
540 "gray16"
541 "grey15"
542 "gray15"
543 "grey14"
544 "gray14"
545 "grey13"
546 "gray13"
547 "grey12"
548 "gray12"
549 "grey11"
550 "gray11"
551 "grey10"
552 "gray10"
553 "grey9"
554 "gray9"
555 "grey8"
556 "gray8"
557 "grey7"
558 "gray7"
559 "grey6"
560 "gray6"
561 "grey5"
562 "gray5"
563 "grey4"
564 "gray4"
565 "grey3"
566 "gray3"
567 "grey2"
568 "gray2"
569 "grey1"
570 "gray1"
571 "grey0"
572 "gray0"
573 "thistle4"
574 "thistle3"
575 "thistle2"
576 "thistle1"
577 "MediumPurple4"
578 "MediumPurple3"
579 "MediumPurple2"
580 "MediumPurple1"
581 "purple4"
582 "purple3"
583 "purple2"
584 "purple1"
585 "DarkOrchid4"
586 "DarkOrchid3"
587 "DarkOrchid2"
588 "DarkOrchid1"
589 "MediumOrchid4"
590 "MediumOrchid3"
591 "MediumOrchid2"
592 "MediumOrchid1"
593 "plum4"
594 "plum3"
595 "plum2"
596 "plum1"
597 "orchid4"
598 "orchid3"
599 "orchid2"
600 "orchid1"
601 "magenta4"
602 "magenta3"
603 "magenta2"
604 "magenta1"
605 "VioletRed4"
606 "VioletRed3"
607 "VioletRed2"
608 "VioletRed1"
609 "maroon4"
610 "maroon3"
611 "maroon2"
612 "maroon1"
613 "PaleVioletRed4"
614 "PaleVioletRed3"
615 "PaleVioletRed2"
616 "PaleVioletRed1"
617 "LightPink4"
618 "LightPink3"
619 "LightPink2"
620 "LightPink1"
621 "pink4"
622 "pink3"
623 "pink2"
624 "pink1"
625 "HotPink4"
626 "HotPink3"
627 "HotPink2"
628 "HotPink1"
629 "DeepPink4"
630 "DeepPink3"
631 "DeepPink2"
632 "DeepPink1"
633 "red4"
634 "red3"
635 "red2"
636 "red1"
637 "OrangeRed4"
638 "OrangeRed3"
639 "OrangeRed2"
640 "OrangeRed1"
641 "tomato4"
642 "tomato3"
643 "tomato2"
644 "tomato1"
645 "coral4"
646 "coral3"
647 "coral2"
648 "coral1"
649 "DarkOrange4"
650 "DarkOrange3"
651 "DarkOrange2"
652 "DarkOrange1"
653 "orange4"
654 "orange3"
655 "orange2"
656 "orange1"
657 "LightSalmon4"
658 "LightSalmon3"
659 "LightSalmon2"
660 "LightSalmon1"
661 "salmon4"
662 "salmon3"
663 "salmon2"
664 "salmon1"
665 "brown4"
666 "brown3"
667 "brown2"
668 "brown1"
669 "firebrick4"
670 "firebrick3"
671 "firebrick2"
672 "firebrick1"
673 "chocolate4"
674 "chocolate3"
675 "chocolate2"
676 "chocolate1"
677 "tan4"
678 "tan3"
679 "tan2"
680 "tan1"
681 "wheat4"
682 "wheat3"
683 "wheat2"
684 "wheat1"
685 "burlywood4"
686 "burlywood3"
687 "burlywood2"
688 "burlywood1"
689 "sienna4"
690 "sienna3"
691 "sienna2"
692 "sienna1"
693 "IndianRed4"
694 "IndianRed3"
695 "IndianRed2"
696 "IndianRed1"
697 "RosyBrown4"
698 "RosyBrown3"
699 "RosyBrown2"
700 "RosyBrown1"
701 "DarkGoldenrod4"
702 "DarkGoldenrod3"
703 "DarkGoldenrod2"
704 "DarkGoldenrod1"
705 "goldenrod4"
706 "goldenrod3"
707 "goldenrod2"
708 "goldenrod1"
709 "gold4"
710 "gold3"
711 "gold2"
712 "gold1"
713 "yellow4"
714 "yellow3"
715 "yellow2"
716 "yellow1"
717 "LightYellow4"
718 "LightYellow3"
719 "LightYellow2"
720 "LightYellow1"
721 "LightGoldenrod4"
722 "LightGoldenrod3"
723 "LightGoldenrod2"
724 "LightGoldenrod1"
725 "khaki4"
726 "khaki3"
727 "khaki2"
728 "khaki1"
729 "DarkOliveGreen4"
730 "DarkOliveGreen3"
731 "DarkOliveGreen2"
732 "DarkOliveGreen1"
733 "OliveDrab4"
734 "OliveDrab3"
735 "OliveDrab2"
736 "OliveDrab1"
737 "chartreuse4"
738 "chartreuse3"
739 "chartreuse2"
740 "chartreuse1"
741 "green4"
742 "green3"
743 "green2"
744 "green1"
745 "SpringGreen4"
746 "SpringGreen3"
747 "SpringGreen2"
748 "SpringGreen1"
749 "PaleGreen4"
750 "PaleGreen3"
751 "PaleGreen2"
752 "PaleGreen1"
753 "SeaGreen4"
754 "SeaGreen3"
755 "SeaGreen2"
756 "SeaGreen1"
757 "DarkSeaGreen4"
758 "DarkSeaGreen3"
759 "DarkSeaGreen2"
760 "DarkSeaGreen1"
761 "aquamarine4"
762 "aquamarine3"
763 "aquamarine2"
764 "aquamarine1"
765 "DarkSlateGray4"
766 "DarkSlateGray3"
767 "DarkSlateGray2"
768 "DarkSlateGray1"
769 "cyan4"
770 "cyan3"
771 "cyan2"
772 "cyan1"
773 "turquoise4"
774 "turquoise3"
775 "turquoise2"
776 "turquoise1"
777 "CadetBlue4"
778 "CadetBlue3"
779 "CadetBlue2"
780 "CadetBlue1"
781 "PaleTurquoise4"
782 "PaleTurquoise3"
783 "PaleTurquoise2"
784 "PaleTurquoise1"
785 "LightCyan4"
786 "LightCyan3"
787 "LightCyan2"
788 "LightCyan1"
789 "LightBlue4"
790 "LightBlue3"
791 "LightBlue2"
792 "LightBlue1"
793 "LightSteelBlue4"
794 "LightSteelBlue3"
795 "LightSteelBlue2"
796 "LightSteelBlue1"
797 "SlateGray4"
798 "SlateGray3"
799 "SlateGray2"
800 "SlateGray1"
801 "LightSkyBlue4"
802 "LightSkyBlue3"
803 "LightSkyBlue2"
804 "LightSkyBlue1"
805 "SkyBlue4"
806 "SkyBlue3"
807 "SkyBlue2"
808 "SkyBlue1"
809 "DeepSkyBlue4"
810 "DeepSkyBlue3"
811 "DeepSkyBlue2"
812 "DeepSkyBlue1"
813 "SteelBlue4"
814 "SteelBlue3"
815 "SteelBlue2"
816 "SteelBlue1"
817 "DodgerBlue4"
818 "DodgerBlue3"
819 "DodgerBlue2"
820 "DodgerBlue1"
821 "blue4"
822 "blue3"
823 "blue2"
824 "blue1"
825 "RoyalBlue4"
826 "RoyalBlue3"
827 "RoyalBlue2"
828 "RoyalBlue1"
829 "SlateBlue4"
830 "SlateBlue3"
831 "SlateBlue2"
832 "SlateBlue1"
833 "azure4"
834 "azure3"
835 "azure2"
836 "azure1"
837 "MistyRose4"
838 "MistyRose3"
839 "MistyRose2"
840 "MistyRose1"
841 "LavenderBlush4"
842 "LavenderBlush3"
843 "LavenderBlush2"
844 "LavenderBlush1"
845 "honeydew4"
846 "honeydew3"
847 "honeydew2"
848 "honeydew1"
849 "ivory4"
850 "ivory3"
851 "ivory2"
852 "ivory1"
853 "cornsilk4"
854 "cornsilk3"
855 "cornsilk2"
856 "cornsilk1"
857 "LemonChiffon4"
858 "LemonChiffon3"
859 "LemonChiffon2"
860 "LemonChiffon1"
861 "NavajoWhite4"
862 "NavajoWhite3"
863 "NavajoWhite2"
864 "NavajoWhite1"
865 "PeachPuff4"
866 "PeachPuff3"
867 "PeachPuff2"
868 "PeachPuff1"
869 "bisque4"
870 "bisque3"
871 "bisque2"
872 "bisque1"
873 "AntiqueWhite4"
874 "AntiqueWhite3"
875 "AntiqueWhite2"
876 "AntiqueWhite1"
877 "seashell4"
878 "seashell3"
879 "seashell2"
880 "seashell1"
881 "snow4"
882 "snow3"
883 "snow2"
884 "snow1"
885 "thistle"
886 "MediumPurple"
887 "medium purple"
888 "purple"
889 "BlueViolet"
890 "blue violet"
891 "DarkViolet"
892 "dark violet"
893 "DarkOrchid"
894 "dark orchid"
895 "MediumOrchid"
896 "medium orchid"
897 "orchid"
898 "plum"
899 "violet"
900 "magenta"
901 "VioletRed"
902 "violet red"
903 "MediumVioletRed"
904 "medium violet red"
905 "maroon"
906 "PaleVioletRed"
907 "pale violet red"
908 "LightPink"
909 "light pink"
910 "pink"
911 "DeepPink"
912 "deep pink"
913 "HotPink"
914 "hot pink"
915 "red"
916 "OrangeRed"
917 "orange red"
918 "tomato"
919 "LightCoral"
920 "light coral"
921 "coral"
922 "DarkOrange"
923 "dark orange"
924 "orange"
925 "LightSalmon"
926 "light salmon"
927 "salmon"
928 "DarkSalmon"
929 "dark salmon"
930 "brown"
931 "firebrick"
932 "chocolate"
933 "tan"
934 "SandyBrown"
935 "sandy brown"
936 "wheat"
937 "beige"
938 "burlywood"
939 "peru"
940 "sienna"
941 "SaddleBrown"
942 "saddle brown"
943 "IndianRed"
944 "indian red"
945 "RosyBrown"
946 "rosy brown"
947 "DarkGoldenrod"
948 "dark goldenrod"
949 "goldenrod"
950 "LightGoldenrod"
951 "light goldenrod"
952 "gold"
953 "yellow"
954 "LightYellow"
955 "light yellow"
956 "LightGoldenrodYellow"
957 "light goldenrod yellow"
958 "PaleGoldenrod"
959 "pale goldenrod"
960 "khaki"
961 "DarkKhaki"
962 "dark khaki"
963 "OliveDrab"
964 "olive drab"
965 "ForestGreen"
966 "forest green"
967 "YellowGreen"
968 "yellow green"
969 "LimeGreen"
970 "lime green"
971 "GreenYellow"
972 "green yellow"
973 "MediumSpringGreen"
974 "medium spring green"
975 "chartreuse"
976 "green"
977 "LawnGreen"
978 "lawn green"
979 "SpringGreen"
980 "spring green"
981 "PaleGreen"
982 "pale green"
983 "LightSeaGreen"
984 "light sea green"
985 "MediumSeaGreen"
986 "medium sea green"
987 "SeaGreen"
988 "sea green"
989 "DarkSeaGreen"
990 "dark sea green"
991 "DarkOliveGreen"
992 "dark olive green"
993 "DarkGreen"
994 "dark green"
995 "aquamarine"
996 "MediumAquamarine"
997 "medium aquamarine"
998 "CadetBlue"
999 "cadet blue"
1000 "LightCyan"
1001 "light cyan"
1002 "cyan"
1003 "turquoise"
1004 "MediumTurquoise"
1005 "medium turquoise"
1006 "DarkTurquoise"
1007 "dark turquoise"
1008 "PaleTurquoise"
1009 "pale turquoise"
1010 "PowderBlue"
1011 "powder blue"
1012 "LightBlue"
1013 "light blue"
1014 "LightSteelBlue"
1015 "light steel blue"
1016 "SteelBlue"
1017 "steel blue"
1018 "LightSkyBlue"
1019 "light sky blue"
1020 "SkyBlue"
1021 "sky blue"
1022 "DeepSkyBlue"
1023 "deep sky blue"
1024 "DodgerBlue"
1025 "dodger blue"
1026 "blue"
1027 "RoyalBlue"
1028 "royal blue"
1029 "MediumBlue"
1030 "medium blue"
1031 "LightSlateBlue"
1032 "light slate blue"
1033 "MediumSlateBlue"
1034 "medium slate blue"
1035 "SlateBlue"
1036 "slate blue"
1037 "DarkSlateBlue"
1038 "dark slate blue"
1039 "CornflowerBlue"
1040 "cornflower blue"
1041 "NavyBlue"
1042 "navy blue"
1043 "navy"
1044 "MidnightBlue"
1045 "midnight blue"
1046 "LightGray"
1047 "light gray"
1048 "LightGrey"
1049 "light grey"
1050 "grey"
1051 "gray"
1052 "LightSlateGrey"
1053 "light slate grey"
1054 "LightSlateGray"
1055 "light slate gray"
1056 "SlateGrey"
1057 "slate grey"
1058 "SlateGray"
1059 "slate gray"
1060 "DimGrey"
1061 "dim grey"
1062 "DimGray"
1063 "dim gray"
1064 "DarkSlateGrey"
1065 "dark slate grey"
1066 "DarkSlateGray"
1067 "dark slate gray"
1068 "black"
1069 "white"
1070 "MistyRose"
1071 "misty rose"
1072 "LavenderBlush"
1073 "lavender blush"
1074 "lavender"
1075 "AliceBlue"
1076 "alice blue"
1077 "azure"
1078 "MintCream"
1079 "mint cream"
1080 "honeydew"
1081 "seashell"
1082 "LemonChiffon"
1083 "lemon chiffon"
1084 "ivory"
1085 "cornsilk"
1086 "moccasin"
1087 "NavajoWhite"
1088 "navajo white"
1089 "PeachPuff"
1090 "peach puff"
1091 "bisque"
1092 "BlanchedAlmond"
1093 "blanched almond"
1094 "PapayaWhip"
1095 "papaya whip"
1096 "AntiqueWhite"
1097 "antique white"
1098 "linen"
1099 "OldLace"
1100 "old lace"
1101 "FloralWhite"
1102 "floral white"
1103 "gainsboro"
1104 "WhiteSmoke"
1105 "white smoke"
1106 "GhostWhite"
1107 "ghost white"
1108 "snow")
1109 "The list of X colors from the `rgb.txt' file.
1110 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1111
1112 (defun xw-defined-colors (&optional frame)
1113 "Internal function called by `defined-colors', which see."
1114 (or frame (setq frame (selected-frame)))
1115 (let* ((color-map-colors (mapcar (lambda (clr) (car clr)) w32-color-map))
1116 (all-colors (or color-map-colors x-colors))
1117 (this-color nil)
1118 (defined-colors nil))
1119 (message "Defining colors...")
1120 (while all-colors
1121 (setq this-color (car all-colors)
1122 all-colors (cdr all-colors))
1123 (and (color-supported-p this-color frame t)
1124 (setq defined-colors (cons this-color defined-colors))))
1125 defined-colors))
1126 \f
1127 \f
1128 ;;;; Function keys
1129
1130 ;;; make f10 activate the real menubar rather than the mini-buffer menu
1131 ;;; navigation feature.
1132 (global-set-key [f10] (lambda ()
1133 (interactive) (w32-send-sys-command ?\xf100)))
1134
1135 (defun iconify-or-deiconify-frame ()
1136 "Iconify the selected frame, or deiconify if it's currently an icon."
1137 (interactive)
1138 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
1139 (iconify-frame)
1140 (make-frame-visible)))
1141
1142 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1143 global-map)
1144
1145 \f
1146 ;;; Do the actual Windows setup here; the above code just defines
1147 ;;; functions and variables that we use now.
1148
1149 (setq command-line-args (x-handle-args command-line-args))
1150
1151 ;;; Make sure we have a valid resource name.
1152 (or (stringp x-resource-name)
1153 (let (i)
1154 (setq x-resource-name (invocation-name))
1155
1156 ;; Change any . or * characters in x-resource-name to hyphens,
1157 ;; so as not to choke when we use it in X resource queries.
1158 (while (setq i (string-match "[.*]" x-resource-name))
1159 (aset x-resource-name i ?-))))
1160
1161 ;; For the benefit of older Emacses (19.27 and earlier) that are sharing
1162 ;; the same lisp directory, don't pass the third argument unless we seem
1163 ;; to have the multi-display support.
1164 (if (fboundp 'x-close-connection)
1165 (x-open-connection ""
1166 x-command-line-resources
1167 ;; Exit Emacs with fatal error if this fails.
1168 t)
1169 (x-open-connection ""
1170 x-command-line-resources))
1171
1172 (setq frame-creation-function 'x-create-frame-with-faces)
1173
1174 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
1175 x-cut-buffer-max))
1176
1177 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
1178 ;; This has ,? to match both on Sunos and on Solaris.
1179 (menu-bar-enable-clipboard)
1180
1181 ;; W32 systems have different fonts than commonly found on X, so
1182 ;; we define our own standard fontset here.
1183 (defvar w32-standard-fontset-spec
1184 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
1185 "String of fontset spec of the standard fontset.
1186 This defines a fontset consisting of the Courier New variations for
1187 European languages which are distributed with Windows as
1188 \"Multilanguage Support\".
1189
1190 See the documentation of `create-fontset-from-fontset-spec for the format.")
1191
1192 (if (fboundp 'new-fontset)
1193 (progn
1194 ;; Create the standard fontset.
1195 (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
1196 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
1197 (create-fontset-from-x-resource)
1198 ;; Try to create a fontset from a font specification which comes
1199 ;; from initial-frame-alist, default-frame-alist, or X resource.
1200 ;; A font specification in command line argument (i.e. -fn XXXX)
1201 ;; should be already in default-frame-alist as a `font'
1202 ;; parameter. However, any font specifications in site-start
1203 ;; library, user's init file (.emacs), and default.el are not
1204 ;; yet handled here.
1205
1206 (let ((font (or (cdr (assq 'font initial-frame-alist))
1207 (cdr (assq 'font default-frame-alist))
1208 (x-get-resource "font" "Font")))
1209 xlfd-fields resolved-name)
1210 (if (and font
1211 (not (query-fontset font))
1212 (setq resolved-name (x-resolve-font-name font))
1213 (setq xlfd-fields (x-decompose-font-name font)))
1214 (if (string= "fontset"
1215 (aref xlfd-fields xlfd-regexp-registry-subnum))
1216 (new-fontset font
1217 (x-complement-fontset-spec xlfd-fields nil))
1218 ;; Create a fontset from FONT. The fontset name is
1219 ;; generated from FONT.
1220 (create-fontset-from-ascii-font font
1221 resolved-name "startup"))))))
1222
1223 ;; Apply a geometry resource to the initial frame. Put it at the end
1224 ;; of the alist, so that anything specified on the command line takes
1225 ;; precedence.
1226 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1227 parsed)
1228 (if res-geometry
1229 (progn
1230 (setq parsed (x-parse-geometry res-geometry))
1231 ;; If the resource specifies a position,
1232 ;; call the position and size "user-specified".
1233 (if (or (assq 'top parsed) (assq 'left parsed))
1234 (setq parsed (cons '(user-position . t)
1235 (cons '(user-size . t) parsed))))
1236 ;; All geometry parms apply to the initial frame.
1237 (setq initial-frame-alist (append initial-frame-alist parsed))
1238 ;; The size parms apply to all frames.
1239 (if (assq 'height parsed)
1240 (setq default-frame-alist
1241 (cons (cons 'height (cdr (assq 'height parsed)))
1242 default-frame-alist)))
1243 (if (assq 'width parsed)
1244 (setq default-frame-alist
1245 (cons (cons 'width (cdr (assq 'width parsed)))
1246 default-frame-alist))))))
1247
1248 ;; Check the reverseVideo resource.
1249 (let ((case-fold-search t))
1250 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1251 (if (and rv
1252 (string-match "^\\(true\\|yes\\|on\\)$" rv))
1253 (setq default-frame-alist
1254 (cons '(reverse . t) default-frame-alist)))))
1255
1256 (defun x-win-suspend-error ()
1257 "Report an error when a suspend is attempted."
1258 (error "Suspending an Emacs running under W32 makes no sense"))
1259 (add-hook 'suspend-hook 'x-win-suspend-error)
1260
1261 ;;; Turn off window-splitting optimization; w32 is usually fast enough
1262 ;;; that this is only annoying.
1263 (setq split-window-keep-point t)
1264
1265 ;; Don't show the frame name; that's redundant.
1266 (setq-default mode-line-frame-identification " ")
1267
1268 ;;; Set to a system sound if you want a fancy bell.
1269 (set-message-beep 'ok)
1270
1271 ;; Remap some functions to call w32 common dialogs
1272
1273 (defun internal-face-interactive (what &optional bool)
1274 (let* ((fn (intern (concat "face-" what)))
1275 (prompt (concat "Set " what " of face "))
1276 (face (read-face-name prompt))
1277 (default (if (fboundp fn)
1278 (or (funcall fn face (selected-frame))
1279 (funcall fn 'default (selected-frame)))))
1280 (fn-win (intern (concat (symbol-name window-system) "-select-" what)))
1281 value)
1282 (setq value
1283 (cond ((fboundp fn-win)
1284 (funcall fn-win))
1285 ((eq bool 'color)
1286 (completing-read (concat prompt " " (symbol-name face) " to: ")
1287 (mapcar (function (lambda (color)
1288 (cons color color)))
1289 x-colors)
1290 nil nil nil nil default))
1291 (bool
1292 (y-or-n-p (concat "Should face " (symbol-name face)
1293 " be " bool "? ")))
1294 (t
1295 (read-string (concat prompt " " (symbol-name face) " to: ")
1296 nil nil default))))
1297 (list face (if (equal value "") nil value))))
1298
1299 ;; Redefine the font selection to use the standard W32 dialog
1300 (defvar w32-use-w32-font-dialog t
1301 "*Use the standard font dialog if 't'.
1302 Otherwise pop up a menu of some standard fonts like X does - including
1303 fontsets.")
1304
1305 (defvar w32-fixed-font-alist
1306 '("Font menu"
1307 ("Misc"
1308 ;; For these, we specify the pixel height and width.
1309 ("fixed" "Fixedsys")
1310 ("")
1311 ("Terminal 5x4"
1312 "-*-Terminal-normal-r-*-*-*-45-*-*-c-40-*-oem")
1313 ("Terminal 6x8"
1314 "-*-Terminal-normal-r-*-*-*-60-*-*-c-80-*-oem")
1315 ("Terminal 9x5"
1316 "-*-Terminal-normal-r-*-*-*-90-*-*-c-50-*-oem")
1317 ("Terminal 9x7"
1318 "-*-Terminal-normal-r-*-*-*-90-*-*-c-70-*-oem")
1319 ("Terminal 9x8"
1320 "-*-Terminal-normal-r-*-*-*-90-*-*-c-80-*-oem")
1321 ("Terminal 12x12"
1322 "-*-Terminal-normal-r-*-*-*-120-*-*-c-120-*-oem")
1323 ("Terminal 14x10"
1324 "-*-Terminal-normal-r-*-*-*-135-*-*-c-100-*-oem")
1325 ("Terminal 6x6 Bold"
1326 "-*-Terminal-bold-r-*-*-*-60-*-*-c-60-*-oem")
1327 ("")
1328 ("Lucida Sans Typewriter.8"
1329 "-*-Lucida Sans Typewriter-normal-r-*-*-11-*-*-*-c-*-iso8859-1")
1330 ("Lucida Sans Typewriter.9"
1331 "-*-Lucida Sans Typewriter-normal-r-*-*-12-*-*-*-c-*-iso8859-1")
1332 ("Lucida Sans Typewriter.10"
1333 "-*-Lucida Sans Typewriter-normal-r-*-*-13-*-*-*-c-*-iso8859-1")
1334 ("Lucida Sans Typewriter.11"
1335 "-*-Lucida Sans Typewriter-normal-r-*-*-15-*-*-*-c-*-iso8859-1")
1336 ("Lucida Sans Typewriter.12"
1337 "-*-Lucida Sans Typewriter-normal-r-*-*-16-*-*-*-c-*-iso8859-1")
1338 ("Lucida Sans Typewriter.8 Bold"
1339 "-*-Lucida Sans Typewriter-semibold-r-*-*-11-*-*-*-c-*-iso8859-1")
1340 ("Lucida Sans Typewriter.9 Bold"
1341 "-*-Lucida Sans Typewriter-semibold-r-*-*-12-*-*-*-c-*-iso8859-1")
1342 ("Lucida Sans Typewriter.10 Bold"
1343 "-*-Lucida Sans Typewriter-semibold-r-*-*-13-*-*-*-c-*-iso8859-1")
1344 ("Lucida Sans Typewriter.11 Bold"
1345 "-*-Lucida Sans Typewriter-semibold-r-*-*-15-*-*-*-c-*-iso8859-1")
1346 ("Lucida Sans Typewriter.12 Bold"
1347 "-*-Lucida Sans Typewriter-semibold-r-*-*-16-*-*-*-c-*-iso8859-1"))
1348 ("Courier"
1349 ("Courier 10x8"
1350 "-*-Courier-*normal-r-*-*-*-97-*-*-c-80-iso8859-1")
1351 ("Courier 12x9"
1352 "-*-Courier-*normal-r-*-*-*-120-*-*-c-90-iso8859-1")
1353 ("Courier 15x12"
1354 "-*-Courier-*normal-r-*-*-*-150-*-*-c-120-iso8859-1")
1355 ;; For these, we specify the point height.
1356 ("")
1357 ("8" "-*-Courier New-normal-r-*-*-11-*-*-*-c-*-iso8859-1")
1358 ("9" "-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-1")
1359 ("10" "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-iso8859-1")
1360 ("11" "-*-Courier New-normal-r-*-*-15-*-*-*-c-*-iso8859-1")
1361 ("12" "-*-Courier New-normal-r-*-*-16-*-*-*-c-*-iso8859-1")
1362 ("8 bold" "-*-Courier New-bold-r-*-*-11-*-*-*-c-*-iso8859-1")
1363 ("9 bold" "-*-Courier New-bold-r-*-*-12-*-*-*-c-*-iso8859-1")
1364 ("10 bold" "-*-Courier New-bold-r-*-*-13-*-*-*-c-*-iso8859-1")
1365 ("11 bold" "-*-Courier New-bold-r-*-*-15-*-*-*-c-*-iso8859-1")
1366 ("12 bold" "-*-Courier New-bold-r-*-*-16-*-*-*-c-*-iso8859-1")
1367 ("8 italic" "-*-Courier New-normal-i-*-*-11-*-*-*-c-*-iso8859-1")
1368 ("9 italic" "-*-Courier New-normal-i-*-*-12-*-*-*-c-*-iso8859-1")
1369 ("10 italic" "-*-Courier New-normal-i-*-*-13-*-*-*-c-*-iso8859-1")
1370 ("11 italic" "-*-Courier New-normal-i-*-*-15-*-*-*-c-*-iso8859-1")
1371 ("12 italic" "-*-Courier New-normal-i-*-*-16-*-*-*-c-*-iso8859-1")
1372 ("8 bold italic" "-*-Courier New-bold-i-*-*-11-*-*-*-c-*-iso8859-1")
1373 ("9 bold italic" "-*-Courier New-bold-i-*-*-12-*-*-*-c-*-iso8859-1")
1374 ("10 bold italic" "-*-Courier New-bold-i-*-*-13-*-*-*-c-*-iso8859-1")
1375 ("11 bold italic" "-*-Courier New-bold-i-*-*-15-*-*-*-c-*-iso8859-1")
1376 ("12 bold italic" "-*-Courier New-bold-i-*-*-16-*-*-*-c-*-iso8859-1")
1377 ))
1378 "Fonts suitable for use in Emacs.
1379 Initially this is a list of some fixed width fonts that most people
1380 will have like Terminal and Courier. These fonts are used in the font
1381 menu if the variable `w32-use-w32-font-dialog' is nil.")
1382
1383 ;;; Enable Japanese fonts on Windows to be used by default.
1384 (set-fontset-font t (make-char 'katakana-jisx0201) '("*" . "JISX0208-SJIS"))
1385 (set-fontset-font t (make-char 'latin-jisx0201) '("*" . "JISX0208-SJIS"))
1386 (set-fontset-font t (make-char 'japanese-jisx0208) '("*" . "JISX0208-SJIS"))
1387 (set-fontset-font t (make-char 'japanese-jisx0208-1978) '("*" . "JISX0208-SJIS"))
1388
1389 (defun mouse-set-font (&rest fonts)
1390 "Select a font.
1391 If `w32-use-w32-font-dialog' is non-nil (the default), use the Windows
1392 font dialog to get the matching FONTS. Otherwise use a pop-up menu
1393 \(like Emacs on other platforms) initialized with the fonts in
1394 `w32-fixed-font-alist'."
1395 (interactive
1396 (if w32-use-w32-font-dialog
1397 (let ((chosen-font (w32-select-font)))
1398 (and chosen-font (list chosen-font)))
1399 (x-popup-menu
1400 last-nonmenu-event
1401 ;; Append list of fontsets currently defined.
1402 (if (fboundp 'new-fontset)
1403 (append w32-fixed-font-alist (list (generate-fontset-menu)))))))
1404 (if fonts
1405 (let (font)
1406 (while fonts
1407 (condition-case nil
1408 (progn
1409 (setq font (car fonts))
1410 (set-default-font font)
1411 (setq fonts nil))
1412 (error (setq fonts (cdr fonts)))))
1413 (if (null font)
1414 (error "Font not found")))))
1415
1416 ;;; w32-win.el ends here