(with-vc-file, edit-vc-file): New macros.
[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")
158 (mapcar 'find-file (car (cdr (cdr event))))
159 (raise-frame))
160
161(defun w32-drag-n-drop-other-frame (event)
162 "Edit the files listed in the drag-n-drop event, in other frames.
163May create new frames, or reuse existing ones. The frame editing
164the last file dropped is selected."
165 (interactive "e")
166 (mapcar 'find-file-other-frame (car (cdr (cdr event)))))
167
168;; Bind the drag-n-drop event.
169(global-set-key [drag-n-drop] 'w32-drag-n-drop)
170(global-set-key [C-drag-n-drop] 'w32-drag-n-drop-other-frame)
171
ee78dc32
GV
172(defvar x-invocation-args)
173
174(defvar x-command-line-resources nil)
175
176(defconst x-option-alist
177 '(("-bw" . x-handle-numeric-switch)
178 ("-d" . x-handle-display)
179 ("-display" . x-handle-display)
180 ("-name" . x-handle-name-rn-switch)
181 ("-rn" . x-handle-name-rn-switch)
182 ("-T" . x-handle-switch)
183 ("-r" . x-handle-switch)
184 ("-rv" . x-handle-switch)
185 ("-reverse" . x-handle-switch)
186 ("-fn" . x-handle-switch)
187 ("-font" . x-handle-switch)
188 ("-ib" . x-handle-numeric-switch)
189 ("-g" . x-handle-geometry)
190 ("-geometry" . x-handle-geometry)
191 ("-fg" . x-handle-switch)
192 ("-foreground". x-handle-switch)
193 ("-bg" . x-handle-switch)
194 ("-background". x-handle-switch)
195 ("-ms" . x-handle-switch)
196 ("-itype" . x-handle-switch)
197 ("-i" . x-handle-switch)
198 ("-iconic" . x-handle-iconic)
199 ("-xrm" . x-handle-xrm-switch)
200 ("-cr" . x-handle-switch)
201 ("-vb" . x-handle-switch)
202 ("-hb" . x-handle-switch)
203 ("-bd" . x-handle-switch)))
204
205(defconst x-long-option-alist
206 '(("--border-width" . "-bw")
207 ("--display" . "-d")
208 ("--name" . "-name")
209 ("--title" . "-T")
210 ("--reverse-video" . "-reverse")
211 ("--font" . "-font")
212 ("--internal-border" . "-ib")
213 ("--geometry" . "-geometry")
214 ("--foreground-color" . "-fg")
215 ("--background-color" . "-bg")
216 ("--mouse-color" . "-ms")
217 ("--icon-type" . "-itype")
218 ("--iconic" . "-iconic")
219 ("--xrm" . "-xrm")
220 ("--cursor-color" . "-cr")
221 ("--vertical-scroll-bars" . "-vb")
222 ("--border-color" . "-bd")))
223
224(defconst x-switch-definitions
225 '(("-name" name)
226 ("-T" name)
227 ("-r" reverse t)
228 ("-rv" reverse t)
229 ("-reverse" reverse t)
230 ("-fn" font)
231 ("-font" font)
232 ("-ib" internal-border-width)
233 ("-fg" foreground-color)
234 ("-foreground" foreground-color)
235 ("-bg" background-color)
236 ("-background" background-color)
237 ("-ms" mouse-color)
238 ("-cr" cursor-color)
239 ("-itype" icon-type t)
240 ("-i" icon-type t)
241 ("-vb" vertical-scroll-bars t)
242 ("-hb" horizontal-scroll-bars t)
243 ("-bd" border-color)
244 ("-bw" border-width)))
245
246;; Handler for switches of the form "-switch value" or "-switch".
247(defun x-handle-switch (switch)
248 (let ((aelt (assoc switch x-switch-definitions)))
249 (if aelt
250 (if (nth 2 aelt)
251 (setq default-frame-alist
252 (cons (cons (nth 1 aelt) (nth 2 aelt))
253 default-frame-alist))
254 (setq default-frame-alist
255 (cons (cons (nth 1 aelt)
256 (car x-invocation-args))
257 default-frame-alist)
258 x-invocation-args (cdr x-invocation-args))))))
259
260;; Make -iconic apply only to the initial frame!
261(defun x-handle-iconic (switch)
262 (setq initial-frame-alist
263 (cons '(visibility . icon) initial-frame-alist)))
264
265;; Handler for switches of the form "-switch n"
266(defun x-handle-numeric-switch (switch)
267 (let ((aelt (assoc switch x-switch-definitions)))
268 (if aelt
269 (setq default-frame-alist
270 (cons (cons (nth 1 aelt)
271 (string-to-int (car x-invocation-args)))
272 default-frame-alist)
273 x-invocation-args
274 (cdr x-invocation-args)))))
275
276;; Handle the -xrm option.
277(defun x-handle-xrm-switch (switch)
278 (or (consp x-invocation-args)
279 (error "%s: missing argument to `%s' option" (invocation-name) switch))
280 (setq x-command-line-resources (car x-invocation-args))
281 (setq x-invocation-args (cdr x-invocation-args)))
282
283;; Handle the geometry option
284(defun x-handle-geometry (switch)
285 (let ((geo (x-parse-geometry (car x-invocation-args))))
286 (setq initial-frame-alist
287 (append initial-frame-alist
288 (if (or (assq 'left geo) (assq 'top geo))
289 '((user-position . t)))
290 (if (or (assq 'height geo) (assq 'width geo))
291 '((user-size . t)))
292 geo)
293 x-invocation-args (cdr x-invocation-args))))
294
295;; Handle the -name and -rn options. Set the variable x-resource-name
296;; to the option's operand; if the switch was `-name', set the name of
297;; the initial frame, too.
298(defun x-handle-name-rn-switch (switch)
299 (or (consp x-invocation-args)
300 (error "%s: missing argument to `%s' option" (invocation-name) switch))
301 (setq x-resource-name (car x-invocation-args)
302 x-invocation-args (cdr x-invocation-args))
303 (if (string= switch "-name")
304 (setq initial-frame-alist (cons (cons 'name x-resource-name)
305 initial-frame-alist))))
306
307(defvar x-display-name nil
308 "The display name specifying server and frame.")
309
310(defun x-handle-display (switch)
311 (setq x-display-name (car x-invocation-args)
312 x-invocation-args (cdr x-invocation-args)))
313
314(defvar x-invocation-args nil)
315
316(defun x-handle-args (args)
317 "Process the X-related command line options in ARGS.
318This is done before the user's startup file is loaded. They are copied to
319x-invocation args from which the X-related things are extracted, first
320the switch (e.g., \"-fg\") in the following code, and possible values
321\(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
322This returns ARGS with the arguments that have been processed removed."
323 (message "%s" args)
324 (setq x-invocation-args args
325 args nil)
326 (while x-invocation-args
327 (let* ((this-switch (car x-invocation-args))
328 (orig-this-switch this-switch)
329 completion argval aelt)
330 (setq x-invocation-args (cdr x-invocation-args))
331 ;; Check for long options with attached arguments
332 ;; and separate out the attached option argument into argval.
333 (if (string-match "^--[^=]*=" this-switch)
334 (setq argval (substring this-switch (match-end 0))
335 this-switch (substring this-switch 0 (1- (match-end 0)))))
336 (setq completion (try-completion this-switch x-long-option-alist))
337 (if (eq completion t)
338 ;; Exact match for long option.
339 (setq this-switch (cdr (assoc this-switch x-long-option-alist)))
340 (if (stringp completion)
341 (let ((elt (assoc completion x-long-option-alist)))
342 ;; Check for abbreviated long option.
343 (or elt
344 (error "Option `%s' is ambiguous" this-switch))
345 (setq this-switch (cdr elt)))
346 ;; Check for a short option.
347 (setq argval nil this-switch orig-this-switch)))
348 (setq aelt (assoc this-switch x-option-alist))
349 (if aelt
350 (if argval
351 (let ((x-invocation-args
352 (cons argval x-invocation-args)))
353 (funcall (cdr aelt) this-switch))
354 (funcall (cdr aelt) this-switch))
355 (setq args (cons this-switch args)))))
356 (setq args (nreverse args)))
357
358
359\f
360;;
361;; Available colors
362;;
363
364(defvar x-colors '("aquamarine"
365 "Aquamarine"
366 "medium aquamarine"
367 "MediumAquamarine"
368 "black"
369 "Black"
370 "blue"
371 "Blue"
372 "cadet blue"
373 "CadetBlue"
374 "cornflower blue"
375 "CornflowerBlue"
376 "dark slate blue"
377 "DarkSlateBlue"
378 "light blue"
379 "LightBlue"
380 "light steel blue"
381 "LightSteelBlue"
382 "medium blue"
383 "MediumBlue"
384 "medium slate blue"
385 "MediumSlateBlue"
386 "midnight blue"
387 "MidnightBlue"
388 "navy blue"
389 "NavyBlue"
390 "navy"
391 "Navy"
392 "sky blue"
393 "SkyBlue"
394 "slate blue"
395 "SlateBlue"
396 "steel blue"
397 "SteelBlue"
398 "coral"
399 "Coral"
400 "cyan"
401 "Cyan"
402 "firebrick"
403 "Firebrick"
404 "brown"
405 "Brown"
406 "gold"
407 "Gold"
408 "goldenrod"
409 "Goldenrod"
410 "green"
411 "Green"
412 "dark green"
413 "DarkGreen"
414 "dark olive green"
415 "DarkOliveGreen"
416 "forest green"
417 "ForestGreen"
418 "lime green"
419 "LimeGreen"
420 "medium sea green"
421 "MediumSeaGreen"
422 "medium spring green"
423 "MediumSpringGreen"
424 "pale green"
425 "PaleGreen"
426 "sea green"
427 "SeaGreen"
428 "spring green"
429 "SpringGreen"
430 "yellow green"
431 "YellowGreen"
432 "dark slate grey"
433 "DarkSlateGrey"
434 "dark slate gray"
435 "DarkSlateGray"
436 "dim grey"
437 "DimGrey"
438 "dim gray"
439 "DimGray"
440 "light grey"
441 "LightGrey"
442 "light gray"
443 "LightGray"
444 "gray"
445 "grey"
446 "Gray"
447 "Grey"
448 "khaki"
449 "Khaki"
450 "magenta"
451 "Magenta"
452 "maroon"
453 "Maroon"
454 "orange"
455 "Orange"
456 "orchid"
457 "Orchid"
458 "dark orchid"
459 "DarkOrchid"
460 "medium orchid"
461 "MediumOrchid"
462 "pink"
463 "Pink"
464 "plum"
465 "Plum"
466 "red"
467 "Red"
468 "indian red"
469 "IndianRed"
470 "medium violet red"
471 "MediumVioletRed"
472 "orange red"
473 "OrangeRed"
474 "violet red"
475 "VioletRed"
476 "salmon"
477 "Salmon"
478 "sienna"
479 "Sienna"
480 "tan"
481 "Tan"
482 "thistle"
483 "Thistle"
484 "turquoise"
485 "Turquoise"
486 "dark turquoise"
487 "DarkTurquoise"
488 "medium turquoise"
489 "MediumTurquoise"
490 "violet"
491 "Violet"
492 "blue violet"
493 "BlueViolet"
494 "wheat"
495 "Wheat"
496 "white"
497 "White"
498 "yellow"
499 "Yellow"
500 "green yellow"
501 "GreenYellow")
502 "The full list of X colors from the `rgb.text' file.")
503
504(defun x-defined-colors (&optional frame)
505 "Return a list of colors supported for a particular frame.
506The argument FRAME specifies which frame to try.
507The value may be different for frames on different X displays."
508 (or frame (setq frame (selected-frame)))
e5e0a3c9
GV
509 (let* ((color-map-colors (mapcar (lambda (clr) (car clr)) w32-color-map))
510 (all-colors (or color-map-colors x-colors))
511 (this-color nil)
512 (defined-colors nil))
513 (message "Defining colors...")
ee78dc32
GV
514 (while all-colors
515 (setq this-color (car all-colors)
516 all-colors (cdr all-colors))
517 (and (face-color-supported-p frame this-color t)
518 (setq defined-colors (cons this-color defined-colors))))
519 defined-colors))
520\f
d66be571 521\f
ee78dc32
GV
522;;;; Function keys
523
d66be571
GV
524;;; make f10 activate the real menubar rather than the mini-buffer menu
525;;; navigation feature.
526(global-set-key [f10] (lambda ()
527 (interactive) (w32-send-sys-command ?\xf100)))
528
ee78dc32
GV
529(defun iconify-or-deiconify-frame ()
530 "Iconify the selected frame, or deiconify if it's currently an icon."
531 (interactive)
532 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
533 (iconify-frame)
534 (make-frame-visible)))
535
536(substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
537 global-map)
538
ee78dc32
GV
539\f
540;;;; Selections and cut buffers
541
542;;; We keep track of the last text selected here, so we can check the
543;;; current selection against it, and avoid passing back our own text
544;;; from x-cut-buffer-or-selection-value.
545(defvar x-last-selected-text nil)
546
547;;; It is said that overlarge strings are slow to put into the cut buffer.
548;;; Note this value is overridden below.
549(defvar x-cut-buffer-max 20000
550 "Max number of characters to put in the cut buffer.")
551
552(defvar x-select-enable-clipboard t
553 "Non-nil means cutting and pasting uses the clipboard.
554This is in addition to the primary selection.")
555
556(defun x-select-text (text &optional push)
557 (if x-select-enable-clipboard
fbd6baed 558 (w32-set-clipboard-data text))
b2b9ff5e 559 (setq x-last-selected-text text))
ee78dc32
GV
560
561;;; Return the value of the current selection.
562;;; Consult the selection, then the cut buffer. Treat empty strings
563;;; as if they were unset.
564(defun x-get-selection-value ()
565 (if x-select-enable-clipboard
566 (let (text)
567 ;; Don't die if x-get-selection signals an error.
568 (condition-case c
fbd6baed
GV
569 (setq text (w32-get-clipboard-data))
570 (error (message "w32-get-clipboard-data:%s" c)))
ee78dc32 571 (if (string= text "") (setq text nil))
b2b9ff5e
RS
572 (cond
573 ((not text) nil)
574 ((eq text x-last-selected-text) nil)
575 ((string= text x-last-selected-text)
576 ;; Record the newer string, so subsequent calls can use the 'eq' test.
577 (setq x-last-selected-text text)
578 nil)
579 (t
580 (setq x-last-selected-text text))))))
ee78dc32
GV
581\f
582;;; Do the actual Windows setup here; the above code just defines
583;;; functions and variables that we use now.
584
585(setq command-line-args (x-handle-args command-line-args))
586
587;;; Make sure we have a valid resource name.
588(or (stringp x-resource-name)
589 (let (i)
590 (setq x-resource-name (invocation-name))
591
592 ;; Change any . or * characters in x-resource-name to hyphens,
593 ;; so as not to choke when we use it in X resource queries.
594 (while (setq i (string-match "[.*]" x-resource-name))
595 (aset x-resource-name i ?-))))
596
597;; For the benefit of older Emacses (19.27 and earlier) that are sharing
598;; the same lisp directory, don't pass the third argument unless we seem
599;; to have the multi-display support.
600(if (fboundp 'x-close-connection)
601 (x-open-connection ""
602 x-command-line-resources
603 ;; Exit Emacs with fatal error if this fails.
604 t)
605 (x-open-connection ""
606 x-command-line-resources))
607
608(setq frame-creation-function 'x-create-frame-with-faces)
609
610(setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
611 x-cut-buffer-max))
612
fbd6baed 613;; W32 expects the menu bar cut and paste commands to use the clipboard.
ee78dc32
GV
614;; This has ,? to match both on Sunos and on Solaris.
615(menu-bar-enable-clipboard)
616
617;; Apply a geometry resource to the initial frame. Put it at the end
618;; of the alist, so that anything specified on the command line takes
619;; precedence.
620(let* ((res-geometry (x-get-resource "geometry" "Geometry"))
621 parsed)
622 (if res-geometry
623 (progn
624 (setq parsed (x-parse-geometry res-geometry))
625 ;; If the resource specifies a position,
626 ;; call the position and size "user-specified".
627 (if (or (assq 'top parsed) (assq 'left parsed))
628 (setq parsed (cons '(user-position . t)
629 (cons '(user-size . t) parsed))))
630 ;; All geometry parms apply to the initial frame.
631 (setq initial-frame-alist (append initial-frame-alist parsed))
632 ;; The size parms apply to all frames.
633 (if (assq 'height parsed)
634 (setq default-frame-alist
635 (cons (cons 'height (cdr (assq 'height parsed)))
636 default-frame-alist)))
637 (if (assq 'width parsed)
638 (setq default-frame-alist
639 (cons (cons 'width (cdr (assq 'width parsed)))
640 default-frame-alist))))))
641
642;; Check the reverseVideo resource.
643(let ((case-fold-search t))
644 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
645 (if (and rv
646 (string-match "^\\(true\\|yes\\|on\\)$" rv))
647 (setq default-frame-alist
648 (cons '(reverse . t) default-frame-alist)))))
649
650;; Set x-selection-timeout, measured in milliseconds.
651(let ((res-selection-timeout
652 (x-get-resource "selectionTimeout" "SelectionTimeout")))
653 (setq x-selection-timeout 20000)
654 (if res-selection-timeout
655 (setq x-selection-timeout (string-to-number res-selection-timeout))))
656
657(defun x-win-suspend-error ()
b63f9ba1 658 (error "Suspending an emacs running under W32 makes no sense"))
ee78dc32
GV
659(add-hook 'suspend-hook 'x-win-suspend-error)
660
661;;; Arrange for the kill and yank functions to set and check the clipboard.
662(setq interprogram-cut-function 'x-select-text)
663(setq interprogram-paste-function 'x-get-selection-value)
664
fbd6baed 665;;; Turn off window-splitting optimization; w32 is usually fast enough
ee78dc32
GV
666;;; that this is only annoying.
667(setq split-window-keep-point t)
668
669;; Don't show the frame name; that's redundant.
f182c531 670(setq-default mode-line-frame-identification " ")
ee78dc32
GV
671
672;;; Set to a system sound if you want a fancy bell.
673(set-message-beep 'ok)
674
fbd6baed 675;; Remap some functions to call w32 common dialogs
ee78dc32
GV
676
677(defun internal-face-interactive (what &optional bool)
678 (let* ((fn (intern (concat "face-" what)))
679 (prompt (concat "Set " what " of face"))
680 (face (read-face-name (concat prompt ": ")))
681 (default (if (fboundp fn)
682 (or (funcall fn face (selected-frame))
683 (funcall fn 'default (selected-frame)))))
684 (fn-win (intern (concat (symbol-name window-system) "-select-" what)))
3ce36200
AI
685 value)
686 (setq value
687 (cond ((fboundp fn-win)
688 (funcall fn-win))
689 ((eq bool 'color)
690 (completing-read (concat prompt " " (symbol-name face) " to: ")
691 (mapcar (function (lambda (color)
692 (cons color color)))
693 x-colors)
694 nil nil nil nil default))
695 (bool
696 (y-or-n-p (concat "Should face " (symbol-name face)
697 " be " bool "? ")))
698 (t
699 (read-string (concat prompt " " (symbol-name face) " to: ")
700 nil nil default))))
701 (list face (if (equal value "") nil value))))
ee78dc32 702
b63f9ba1 703;; Redefine the font selection to use the standard W32 dialog
cf14c2b4
GV
704(defvar w32-use-w32-font-dialog t
705 "Use the standard font dialog if 't' - otherwise pop up a menu of
706some standard fonts like X does - including fontsets")
707
708(defvar w32-fixed-font-alist
709 '("Font menu"
710 ("Misc"
711 ;; For these, we specify the pixel height and width.
712 ("fixed" "Fixedsys")
713 ("")
714 ("Terminal 5x4"
715 "-*-Terminal-normal-r-*-*-*-45-*-*-c-40-*-oem")
716 ("Terminal 6x8"
717 "-*-Terminal-normal-r-*-*-*-60-*-*-c-80-*-oem")
718 ("Terminal 9x5"
719 "-*-Terminal-normal-r-*-*-*-90-*-*-c-50-*-oem")
720 ("Terminal 9x7"
721 "-*-Terminal-normal-r-*-*-*-90-*-*-c-70-*-oem")
722 ("Terminal 9x8"
723 "-*-Terminal-normal-r-*-*-*-90-*-*-c-80-*-oem")
724 ("Terminal 12x12"
725 "-*-Terminal-normal-r-*-*-*-120-*-*-c-120-*-oem")
726 ("Terminal 14x10"
727 "-*-Terminal-normal-r-*-*-*-135-*-*-c-100-*-oem")
728 ("Terminal 6x6 Bold"
729 "-*-Terminal-bold-r-*-*-*-60-*-*-c-60-*-oem")
730 ("")
731 ("Lucida Sans Typewriter.8"
732 "-*-Lucida Sans Typewriter-normal-r-*-*-11-*-*-*-c-*-iso8859-1")
733 ("Lucida Sans Typewriter.9"
734 "-*-Lucida Sans Typewriter-normal-r-*-*-12-*-*-*-c-*-iso8859-1")
735 ("Lucida Sans Typewriter.10"
736 "-*-Lucida Sans Typewriter-normal-r-*-*-13-*-*-*-c-*-iso8859-1")
737 ("Lucida Sans Typewriter.11"
738 "-*-Lucida Sans Typewriter-normal-r-*-*-15-*-*-*-c-*-iso8859-1")
739 ("Lucida Sans Typewriter.12"
740 "-*-Lucida Sans Typewriter-normal-r-*-*-16-*-*-*-c-*-iso8859-1")
741 ("Lucida Sans Typewriter.8 Bold"
742 "-*-Lucida Sans Typewriter-semibold-r-*-*-11-*-*-*-c-*-iso8859-1")
743 ("Lucida Sans Typewriter.9 Bold"
744 "-*-Lucida Sans Typewriter-semibold-r-*-*-12-*-*-*-c-*-iso8859-1")
745 ("Lucida Sans Typewriter.10 Bold"
746 "-*-Lucida Sans Typewriter-semibold-r-*-*-13-*-*-*-c-*-iso8859-1")
747 ("Lucida Sans Typewriter.11 Bold"
748 "-*-Lucida Sans Typewriter-semibold-r-*-*-15-*-*-*-c-*-iso8859-1")
749 ("Lucida Sans Typewriter.12 Bold"
750 "-*-Lucida Sans Typewriter-semibold-r-*-*-16-*-*-*-c-*-iso8859-1"))
751 ("Courier"
752 ("Courier 10x8"
753 "-*-Courier-*normal-r-*-*-*-97-*-*-c-80-iso8859-1")
754 ("Courier 12x9"
755 "-*-Courier-*normal-r-*-*-*-120-*-*-c-90-iso8859-1")
756 ("Courier 15x12"
757 "-*-Courier-*normal-r-*-*-*-150-*-*-c-120-iso8859-1")
758 ;; For these, we specify the point height.
759 ("")
760 ("8" "-*-Courier New-normal-r-*-*-11-*-*-*-c-*-iso8859-1")
761 ("9" "-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-1")
762 ("10" "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-iso8859-1")
763 ("11" "-*-Courier New-normal-r-*-*-15-*-*-*-c-*-iso8859-1")
764 ("12" "-*-Courier New-normal-r-*-*-16-*-*-*-c-*-iso8859-1")
765 ("8 bold" "-*-Courier New-bold-r-*-*-11-*-*-*-c-*-iso8859-1")
766 ("9 bold" "-*-Courier New-bold-r-*-*-12-*-*-*-c-*-iso8859-1")
767 ("10 bold" "-*-Courier New-bold-r-*-*-13-*-*-*-c-*-iso8859-1")
768 ("11 bold" "-*-Courier New-bold-r-*-*-15-*-*-*-c-*-iso8859-1")
769 ("12 bold" "-*-Courier New-bold-r-*-*-16-*-*-*-c-*-iso8859-1")
770 ("8 italic" "-*-Courier New-normal-i-*-*-11-*-*-*-c-*-iso8859-1")
771 ("9 italic" "-*-Courier New-normal-i-*-*-12-*-*-*-c-*-iso8859-1")
772 ("10 italic" "-*-Courier New-normal-i-*-*-13-*-*-*-c-*-iso8859-1")
773 ("11 italic" "-*-Courier New-normal-i-*-*-15-*-*-*-c-*-iso8859-1")
774 ("12 italic" "-*-Courier New-normal-i-*-*-16-*-*-*-c-*-iso8859-1")
775 ("8 bold italic" "-*-Courier New-bold-i-*-*-11-*-*-*-c-*-iso8859-1")
776 ("9 bold italic" "-*-Courier New-bold-i-*-*-12-*-*-*-c-*-iso8859-1")
777 ("10 bold italic" "-*-Courier New-bold-i-*-*-13-*-*-*-c-*-iso8859-1")
778 ("11 bold italic" "-*-Courier New-bold-i-*-*-15-*-*-*-c-*-iso8859-1")
779 ("12 bold italic" "-*-Courier New-bold-i-*-*-16-*-*-*-c-*-iso8859-1")
780 ))
781 "Fonts suitable for use in Emacs. Initially this is a list of some
782fixed width fonts that most people will have like Terminal and
783Courier. These fonts are used in the font menu if the variable
784`w32-use-w32-font-dialog' is nil.")
ee78dc32
GV
785
786(defun mouse-set-font (&rest fonts)
cf14c2b4
GV
787 (interactive
788 (if w32-use-w32-font-dialog
789 (list (w32-select-font))
790 (x-popup-menu
791 last-nonmenu-event
792 ;; Append list of fontsets currently defined.
793 (append w32-fixed-font-alist (list (generate-fontset-menu))))))
794 (if fonts
795 (let (font)
796 (while fonts
797 (condition-case nil
798 (progn
799 (set-default-font (car fonts))
800 (setq font (car fonts))
801 (setq fonts nil))
802 (error
803 (setq fonts (cdr fonts)))))
804 (if (null font)
805 (error "Font not found")))))
ee78dc32 806
b63f9ba1 807;;; w32-win.el ends here
cf14c2b4
GV
808;;; The code in w32-init-fontsets requires a w32 frame to have been created,
809;;; which is not the case when this file is loaded during startup.
810(add-hook 'before-init-hook 'w32-init-fontsets)
811
812(defun w32-init-fontsets ()
813 "Initialize standard fontsets for w32."
814 (if (fboundp 'new-fontset)
815 (progn
816 ;; Create the standard fontset.
817 (create-fontset-from-fontset-spec standard-fontset-spec t)
818
819 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
820 (create-fontset-from-x-resource)
821
822 ;; Try to create a fontset from a font specification which comes
823 ;; from initial-frame-alist, default-frame-alist, or X resource.
824 ;; A font specification in command line argument (i.e. -fn XXXX)
825 ;; should be already in default-frame-alist as a `font'
826 ;; parameter. However, any font specifications in site-start
827 ;; library, user's init file (.emacs), and default.el are not
828 ;; yet handled here.
829
830 (let ((font (or (cdr (assq 'font initial-frame-alist))
831 (cdr (assq 'font default-frame-alist))
832 (x-get-resource "font" "Font")))
833 xlfd-fields resolved-name)
834 (if (and font
835 (not (query-fontset font))
836 (setq resolved-name (x-resolve-font-name font))
837 (setq xlfd-fields (x-decompose-font-name font)))
838 (if (string= "fontset"
839 (aref xlfd-fields xlfd-regexp-registry-subnum))
840 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
841 ;; Create a fontset from FONT. The fontset name is
842 ;; generated from FONT. Create style variants of the
843 ;; fontset too. Font names in the variants are
844 ;; generated automatially unless X resources
845 ;; XXX.attribyteFont explicitly specify them.
846 (let ((styles (mapcar 'car x-style-funcs-alist))
847 (faces '(bold italic bold-italic))
848 face face-font fontset fontset-spec)
849 (while faces
850 (setq face (car faces))
851 (setq face-font (x-get-resource (concat (symbol-name face)
852 ".attributeFont")
853 "Face.AttributeFont"))
854 (if face-font
855 (setq styles (cons (cons face face-font)
856 (delq face styles))))
857 (setq faces (cdr faces)))
858 (aset xlfd-fields xlfd-regexp-foundry-subnum nil)
859 (aset xlfd-fields xlfd-regexp-family-subnum nil)
860 (aset xlfd-fields xlfd-regexp-registry-subnum "fontset")
861 (aset xlfd-fields xlfd-regexp-encoding-subnum "startup")
862 ;; The fontset name should have concrete values in
863 ;; weight and slant field.
864 (let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum))
865 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
866 xlfd-temp)
867 (if (or (not weight) (string-match "[*?]*" weight))
868 (progn
869 (setq xlfd-temp (x-decompose-font-name resolved-name))
870 (aset xlfd-fields xlfd-regexp-weight-subnum
871 (aref xlfd-temp xlfd-regexp-weight-subnum))))
872 (if (or (not slant) (string-match "[*?]*" slant))
873 (progn
874 (or xlfd-temp
875 (setq xlfd-temp
876 (x-decompose-font-name resolved-name)))
877 (aset xlfd-fields xlfd-regexp-slant-subnum
878 (aref xlfd-temp xlfd-regexp-slant-subnum)))))
879 (setq fontset (x-compose-font-name xlfd-fields))
880 (create-fontset-from-fontset-spec
881 (concat fontset ", ascii:" font) styles)
882 )))))))
883