* term.c: Include stdarg.h.
[bpt/emacs.git] / lisp / term / pc-win.el
CommitLineData
55535639 1;;; pc-win.el --- setup support for `PC windows' (whatever that is)
ef88bd2d 2
5fd6d89f 3;; Copyright (C) 1994, 1996, 1997, 1999, 2001, 2002, 2003, 2004,
d7a0267c 4;; 2005, 2006, 2007 Free Software Foundation, Inc.
ef88bd2d
MW
5
6;; Author: Morten Welinder <terra@diku.dk>
9596811a 7;; Maintainer: FSF
ef88bd2d
MW
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
5a9dffec 13;; the Free Software Foundation; either version 3, or (at your option)
ef88bd2d
MW
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
2fe590dc 22;; along with GNU Emacs; see the file COPYING. If not, write to the
4fc5845f
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
2fe590dc 25
55535639
PJ
26;;; Commentary:
27
2fe590dc
EN
28;;; Code:
29
ef88bd2d
MW
30(load "term/internal" nil t)
31
c4d64969 32;;; This is copied from etc/rgb.txt, except that some values were changed
f795f633
EZ
33;;; a bit to make them consistent with DOS console colors, and the RGB
34;;; values were scaled up to 16 bits, as `tty-define-color' requires.
35;;;
36;;; The mapping between the 16 standard EGA/VGA colors and X color names
37;;; was done by running a Unix version of Emacs inside an X client and a
38;;; DJGPP-compiled Emacs on the same PC. The names of X colors used to
39;;; define the pixel values are shown as comments to each color below.
c4d64969
EZ
40;;;
41;;; If you want to change the RGB values, keep in mind that various pieces
42;;; of Emacs think that a color whose RGB values add up to less than 0.6 of
f795f633 43;;; the values for WHITE (i.e. less than 117963) are ``dark'', otherwise the
c4d64969
EZ
44;;; color is ``light''; see `frame-set-background-mode' in lisp/faces.el for
45;;; an example.
46(defvar msdos-color-values
1400df92 47 '(("black" 0 0 0 0)
f795f633 48 ("blue" 1 0 0 52480) ; MediumBlue
1400df92
EZ
49 ("green" 2 8704 35584 8704) ; ForestGreen
50 ("cyan" 3 0 52736 53504) ; DarkTurquoise
51 ("red" 4 45568 8704 8704) ; FireBrick
52 ("magenta" 5 35584 0 35584) ; DarkMagenta
53 ("brown" 6 40960 20992 11520) ; Sienna
54 ("lightgray" 7 48640 48640 48640) ; Gray
55 ("darkgray" 8 26112 26112 26112) ; Gray40
56 ("lightblue" 9 0 0 65535) ; Blue
57 ("lightgreen" 10 0 65535 0) ; Green
58 ("lightcyan" 11 0 65535 65535) ; Cyan
59 ("lightred" 12 65535 0 0) ; Red
60 ("lightmagenta" 13 65535 0 65535) ; Magenta
61 ("yellow" 14 65535 65535 0) ; Yellow
62 ("white" 15 65535 65535 65535))
f795f633 63 "A list of MS-DOS console colors, their indices and 16-bit RGB values.")
a13b5fad 64
ef88bd2d
MW
65;; ---------------------------------------------------------------------------
66;; We want to delay setting frame parameters until the faces are setup
67(defvar default-frame-alist nil)
9000684d 68(modify-frame-parameters terminal-frame default-frame-alist)
f795f633 69(tty-color-clear)
ef88bd2d
MW
70
71(defun msdos-face-setup ()
9000684d
RS
72 (set-face-foreground 'bold "yellow" terminal-frame)
73 (set-face-foreground 'italic "red" terminal-frame)
74 (set-face-foreground 'bold-italic "lightred" terminal-frame)
75 (set-face-foreground 'underline "white" terminal-frame)
ef88bd2d
MW
76
77 (make-face 'msdos-menu-active-face)
78 (make-face 'msdos-menu-passive-face)
79 (make-face 'msdos-menu-select-face)
9000684d
RS
80 (set-face-foreground 'msdos-menu-active-face "white" terminal-frame)
81 (set-face-foreground 'msdos-menu-passive-face "lightgray" terminal-frame)
82 (set-face-background 'msdos-menu-active-face "blue" terminal-frame)
83 (set-face-background 'msdos-menu-passive-face "blue" terminal-frame)
c13c88d7 84 (set-face-background 'msdos-menu-select-face "red" terminal-frame))
ef88bd2d 85
ef88bd2d 86(add-hook 'before-init-hook 'msdos-face-setup)
9000684d 87
f795f633
EZ
88(defun msdos-handle-reverse-video (frame parameters)
89 "Handle the reverse-video frame parameter on MS-DOS frames."
c88c89a0
EZ
90 (when (cdr (or (assq 'reverse parameters)
91 (assq 'reverse default-frame-alist)))
f795f633 92 (let* ((params (frame-parameters frame))
8fcacf13
EZ
93 (fg (cdr (assq 'foreground-color params)))
94 (bg (cdr (assq 'background-color params))))
95 (if (equal fg (cdr (assq 'mouse-color params)))
f795f633 96 (modify-frame-parameters frame
8fcacf13
EZ
97 (list (cons 'mouse-color bg))))
98 (if (equal fg (cdr (assq 'cursor-color params)))
f795f633 99 (modify-frame-parameters frame
8fcacf13 100 (list (cons 'cursor-color bg)))))))
f795f633
EZ
101
102;; This must run after all the default colors are inserted into
103;; tty-color-alist, since msdos-handle-reverse-video needs to know the
104;; actual frame colors. tty-color-alist is set up by startup.el, but
105;; only after it runs before-init-hook and after-init-hook.
106(defun msdos-setup-initial-frame ()
107 (modify-frame-parameters terminal-frame default-frame-alist)
108 ;; This remembers the screen colors after applying default-frame-alist,
109 ;; so that all subsequent frames could begin with those colors.
110 (msdos-remember-default-colors terminal-frame)
111 (modify-frame-parameters terminal-frame initial-frame-alist)
112 (msdos-handle-reverse-video terminal-frame
113 (frame-parameters terminal-frame))
114
115 (frame-set-background-mode terminal-frame)
116 (face-set-after-frame-default terminal-frame))
117
118(add-hook 'term-setup-hook 'msdos-setup-initial-frame)
119
9000684d
RS
120;; We create frames as if we were a terminal, but with a twist.
121(defun make-msdos-frame (&optional parameters)
f795f633
EZ
122 (let ((frame (make-terminal-frame parameters))
123 success)
68a89a25
EZ
124 (unwind-protect
125 (progn
f795f633 126 (msdos-handle-reverse-video frame (frame-parameters frame))
68a89a25
EZ
127 (frame-set-background-mode frame)
128 (face-set-after-frame-default frame)
129 (setq success t))
130 (unless success (delete-frame frame)))
e2f35ede 131 frame))
9000684d 132
729f1525 133(add-to-list 'frame-creation-function-alist '(pc . make-msdos-frame))
9000684d 134
ef88bd2d 135;; ---------------------------------------------------------------------------
a7acbbe4 136;; More or less useful imitations of certain X-functions. A lot of the
ef88bd2d
MW
137;; values returned are questionable, but usually only the form of the
138;; returned value matters. Also, by the way, recall that `ignore' is
139;; a useful function for returning 'nil regardless of argument.
140
141;; From src/xfns.c
cee30b8f 142(defun x-list-fonts (pattern &optional face frame maximum width)
c0e2e77f
EZ
143 (if (or (null width) (and (numberp width) (= width 1)))
144 (list "ms-dos")
cee30b8f 145 (list "no-such-font")))
a259d337
RS
146(defun x-display-pixel-width (&optional frame) (frame-width frame))
147(defun x-display-pixel-height (&optional frame) (frame-height frame))
c0e2e77f
EZ
148(defun x-display-planes (&optional frame) 4) ;bg switched to 16 colors as well
149(defun x-display-color-cells (&optional frame) 16)
ef88bd2d
MW
150(defun x-server-max-request-size (&optional frame) 1000000) ; ???
151(defun x-server-vendor (&optional frame) t "GNU")
152(defun x-server-version (&optional frame) '(1 0 0))
153(defun x-display-screens (&optional frame) 1)
c0e2e77f
EZ
154(defun x-display-mm-height (&optional frame) 245) ; Guess the size of my
155(defun x-display-mm-width (&optional frame) 322) ; monitor, EZ...
ef88bd2d
MW
156(defun x-display-backing-store (&optional frame) 'not-useful)
157(defun x-display-visual-class (&optional frame) 'static-color)
158(fset 'x-display-save-under 'ignore)
159(fset 'x-get-resource 'ignore)
a0c712ae 160
ef88bd2d 161;; From lisp/term/x-win.el
f795f633
EZ
162(defvar x-display-name "pc"
163 "The display name specifying the MS-DOS display and frame type.")
ef88bd2d 164(setq split-window-keep-point t)
c0e2e77f 165(defvar x-colors (mapcar 'car msdos-color-values)
bb3a4574 166 "The list of colors available on a PC display under MS-DOS.")
c4d64969 167
8254b6b4 168;; From lisp/term/w32-win.el
c432c362
EZ
169;
170;;;; Selections and cut buffers
bb3a4574 171;
c432c362
EZ
172;;; We keep track of the last text selected here, so we can check the
173;;; current selection against it, and avoid passing back our own text
174;;; from x-cut-buffer-or-selection-value.
175(defvar x-last-selected-text nil)
176
8c717810
EZ
177(defcustom x-select-enable-clipboard t
178 "Non-nil means cutting and pasting uses the clipboard.
179This is the default on this system, since MS-Windows does not
180support other types of selections."
181 :type 'boolean
182 :group 'killing)
c432c362
EZ
183
184(defun x-select-text (text &optional push)
db95369b 185 (if x-select-enable-clipboard
8254b6b4 186 (w16-set-clipboard-data text))
c432c362 187 (setq x-last-selected-text text))
db95369b 188
c432c362
EZ
189;;; Return the value of the current selection.
190;;; Consult the selection, then the cut buffer. Treat empty strings
191;;; as if they were unset.
192(defun x-get-selection-value ()
db95369b 193 (if x-select-enable-clipboard
c432c362
EZ
194 (let (text)
195 ;; Don't die if x-get-selection signals an error.
196 (condition-case c
8254b6b4
EZ
197 (setq text (w16-get-clipboard-data))
198 (error (message "w16-get-clipboard-data:%s" c)))
c432c362
EZ
199 (if (string= text "") (setq text nil))
200 (cond
201 ((not text) nil)
202 ((eq text x-last-selected-text) nil)
203 ((string= text x-last-selected-text)
204 ;; Record the newer string, so subsequent calls can use the 'eq' test.
205 (setq x-last-selected-text text)
206 nil)
207 (t
208 (setq x-last-selected-text text))))))
209
210;;; Arrange for the kill and yank functions to set and check the clipboard.
211(setq interprogram-cut-function 'x-select-text)
212(setq interprogram-paste-function 'x-get-selection-value)
ef88bd2d 213
ea6401d7
RS
214;; From lisp/faces.el: we only have one font, so always return
215;; it, no matter which variety they've asked for.
216(defun x-frob-font-slant (font which)
217 font)
aa32689c 218(make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
c0e2e77f
EZ
219(defun x-frob-font-weight (font which)
220 font)
aa32689c 221(make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
c0e2e77f
EZ
222(defun x-font-family-list ()
223 "Return a list of available font families on FRAME.\n\
224If FRAME is omitted or nil, use the selected frame.\n\
225Value is a list of conses (FAMILY . FIXED-P) where FAMILY\n\
226is a font family, and FIXED-P is non-nil if fonts of that family\n\
227are fixed-pitch."
228 '(("default" . t)))
ea6401d7 229
cee30b8f
RS
230;; From src/fontset.c:
231(fset 'query-fontset 'ignore)
232
e1ddc4b4
RS
233;; From lisp/term/x-win.el: make iconify-or-deiconify-frame a no-op.
234(fset 'iconify-or-deiconify-frame 'ignore)
235
ef88bd2d
MW
236;; From lisp/frame.el
237(fset 'set-default-font 'ignore)
238(fset 'set-mouse-color 'ignore) ; We cannot, I think.
239(fset 'set-cursor-color 'ignore) ; Hardware determined by char under.
240(fset 'set-border-color 'ignore) ; Not useful.
c8a6e3b9 241
ef88bd2d 242;; ---------------------------------------------------------------------------
092af6d8 243
ab5796a9 244;;; arch-tag: 5cbdb455-b495-427b-95d0-e417d77d00b4
092af6d8 245;;; pc-win.el ends here