Commit | Line | Data |
---|---|---|
092af6d8 | 1 | ;;; pc-win.el --- setup support for `PC windows' (whatever that is). |
ef88bd2d | 2 | |
e2f35ede | 3 | ;; Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc. |
ef88bd2d MW |
4 | |
5 | ;; Author: Morten Welinder <terra@diku.dk> | |
9596811a | 6 | ;; Maintainer: FSF |
ef88bd2d MW |
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 | |
2fe590dc EN |
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 | ;;; Code: | |
26 | ||
ef88bd2d MW |
27 | (load "term/internal" nil t) |
28 | ||
c4d64969 | 29 | ;;; This is copied from etc/rgb.txt, except that some values were changed |
f795f633 EZ |
30 | ;;; a bit to make them consistent with DOS console colors, and the RGB |
31 | ;;; values were scaled up to 16 bits, as `tty-define-color' requires. | |
32 | ;;; | |
33 | ;;; The mapping between the 16 standard EGA/VGA colors and X color names | |
34 | ;;; was done by running a Unix version of Emacs inside an X client and a | |
35 | ;;; DJGPP-compiled Emacs on the same PC. The names of X colors used to | |
36 | ;;; define the pixel values are shown as comments to each color below. | |
c4d64969 EZ |
37 | ;;; |
38 | ;;; If you want to change the RGB values, keep in mind that various pieces | |
39 | ;;; of Emacs think that a color whose RGB values add up to less than 0.6 of | |
f795f633 | 40 | ;;; the values for WHITE (i.e. less than 117963) are ``dark'', otherwise the |
c4d64969 EZ |
41 | ;;; color is ``light''; see `frame-set-background-mode' in lisp/faces.el for |
42 | ;;; an example. | |
43 | (defvar msdos-color-values | |
f795f633 EZ |
44 | '(("white" 15 65535 65535 65535) |
45 | ("yellow" 14 65535 65535 0) ; Yellow | |
46 | ("lightmagenta" 13 65535 0 65535) ; Magenta | |
47 | ("lightred" 12 65535 0 0) ; Red | |
48 | ("lightcyan" 11 0 65535 65535) ; Cyan | |
49 | ("lightgreen" 10 0 65535 0) ; Green | |
50 | ("lightblue" 9 0 0 65535) ; Blue | |
51 | ("darkgray" 8 26112 26112 26112) ; Gray40 | |
52 | ("lightgray" 7 48640 48640 48640) ; Gray | |
53 | ("brown" 6 40960 20992 11520) ; Sienna | |
54 | ("magenta" 5 35584 0 35584) ; DarkMagenta | |
55 | ("red" 4 45568 8704 8704) ; FireBrick | |
56 | ("cyan" 3 0 52736 53504) ; DarkTurquoise | |
57 | ("green" 2 8704 35584 8704) ; ForestGreen | |
58 | ("blue" 1 0 0 52480) ; MediumBlue | |
59 | ("black" 0 0 0 0)) | |
60 | "A list of MS-DOS console colors, their indices and 16-bit RGB values.") | |
a13b5fad | 61 | |
ef88bd2d MW |
62 | ;; --------------------------------------------------------------------------- |
63 | ;; We want to delay setting frame parameters until the faces are setup | |
64 | (defvar default-frame-alist nil) | |
9000684d | 65 | (modify-frame-parameters terminal-frame default-frame-alist) |
f795f633 | 66 | (tty-color-clear) |
ef88bd2d MW |
67 | |
68 | (defun msdos-face-setup () | |
9000684d RS |
69 | (set-face-foreground 'bold "yellow" terminal-frame) |
70 | (set-face-foreground 'italic "red" terminal-frame) | |
71 | (set-face-foreground 'bold-italic "lightred" terminal-frame) | |
72 | (set-face-foreground 'underline "white" terminal-frame) | |
ef88bd2d MW |
73 | |
74 | (make-face 'msdos-menu-active-face) | |
75 | (make-face 'msdos-menu-passive-face) | |
76 | (make-face 'msdos-menu-select-face) | |
9000684d RS |
77 | (set-face-foreground 'msdos-menu-active-face "white" terminal-frame) |
78 | (set-face-foreground 'msdos-menu-passive-face "lightgray" terminal-frame) | |
79 | (set-face-background 'msdos-menu-active-face "blue" terminal-frame) | |
80 | (set-face-background 'msdos-menu-passive-face "blue" terminal-frame) | |
c13c88d7 | 81 | (set-face-background 'msdos-menu-select-face "red" terminal-frame)) |
ef88bd2d | 82 | |
ef88bd2d | 83 | (add-hook 'before-init-hook 'msdos-face-setup) |
9000684d | 84 | |
f795f633 EZ |
85 | (defun msdos-handle-reverse-video (frame parameters) |
86 | "Handle the reverse-video frame parameter on MS-DOS frames." | |
87 | (when (cdr (assq 'reverse parameters)) | |
88 | (let* ((params (frame-parameters frame)) | |
89 | (bg (cdr (assq 'foreground-color params))) | |
90 | (fg (cdr (assq 'background-color params)))) | |
91 | (modify-frame-parameters frame '((reverse . nil))) | |
92 | (if (equal bg (cdr (assq 'mouse-color params))) | |
93 | (modify-frame-parameters frame | |
94 | (list (cons 'mouse-color fg)))) | |
95 | (if (equal bg (cdr (assq 'cursor-color params))) | |
96 | (modify-frame-parameters frame | |
97 | (list (cons 'cursor-color fg))))))) | |
98 | ||
99 | ;; This must run after all the default colors are inserted into | |
100 | ;; tty-color-alist, since msdos-handle-reverse-video needs to know the | |
101 | ;; actual frame colors. tty-color-alist is set up by startup.el, but | |
102 | ;; only after it runs before-init-hook and after-init-hook. | |
103 | (defun msdos-setup-initial-frame () | |
104 | (modify-frame-parameters terminal-frame default-frame-alist) | |
105 | ;; This remembers the screen colors after applying default-frame-alist, | |
106 | ;; so that all subsequent frames could begin with those colors. | |
107 | (msdos-remember-default-colors terminal-frame) | |
108 | (modify-frame-parameters terminal-frame initial-frame-alist) | |
109 | (msdos-handle-reverse-video terminal-frame | |
110 | (frame-parameters terminal-frame)) | |
111 | ||
112 | (frame-set-background-mode terminal-frame) | |
113 | (face-set-after-frame-default terminal-frame)) | |
114 | ||
115 | (add-hook 'term-setup-hook 'msdos-setup-initial-frame) | |
116 | ||
9000684d RS |
117 | ;; We create frames as if we were a terminal, but with a twist. |
118 | (defun make-msdos-frame (&optional parameters) | |
f795f633 EZ |
119 | (let ((frame (make-terminal-frame parameters)) |
120 | success) | |
68a89a25 EZ |
121 | (unwind-protect |
122 | (progn | |
f795f633 | 123 | (msdos-handle-reverse-video frame (frame-parameters frame)) |
68a89a25 EZ |
124 | (frame-set-background-mode frame) |
125 | (face-set-after-frame-default frame) | |
126 | (setq success t)) | |
127 | (unless success (delete-frame frame))) | |
e2f35ede | 128 | frame)) |
9000684d RS |
129 | |
130 | (setq frame-creation-function 'make-msdos-frame) | |
131 | ||
ef88bd2d | 132 | ;; --------------------------------------------------------------------------- |
a7acbbe4 | 133 | ;; More or less useful imitations of certain X-functions. A lot of the |
ef88bd2d MW |
134 | ;; values returned are questionable, but usually only the form of the |
135 | ;; returned value matters. Also, by the way, recall that `ignore' is | |
136 | ;; a useful function for returning 'nil regardless of argument. | |
137 | ||
138 | ;; From src/xfns.c | |
cee30b8f | 139 | (defun x-list-fonts (pattern &optional face frame maximum width) |
c0e2e77f EZ |
140 | (if (or (null width) (and (numberp width) (= width 1))) |
141 | (list "ms-dos") | |
cee30b8f | 142 | (list "no-such-font"))) |
a259d337 RS |
143 | (defun x-display-pixel-width (&optional frame) (frame-width frame)) |
144 | (defun x-display-pixel-height (&optional frame) (frame-height frame)) | |
c0e2e77f EZ |
145 | (defun x-display-planes (&optional frame) 4) ;bg switched to 16 colors as well |
146 | (defun x-display-color-cells (&optional frame) 16) | |
ef88bd2d MW |
147 | (defun x-server-max-request-size (&optional frame) 1000000) ; ??? |
148 | (defun x-server-vendor (&optional frame) t "GNU") | |
149 | (defun x-server-version (&optional frame) '(1 0 0)) | |
150 | (defun x-display-screens (&optional frame) 1) | |
c0e2e77f EZ |
151 | (defun x-display-mm-height (&optional frame) 245) ; Guess the size of my |
152 | (defun x-display-mm-width (&optional frame) 322) ; monitor, EZ... | |
ef88bd2d MW |
153 | (defun x-display-backing-store (&optional frame) 'not-useful) |
154 | (defun x-display-visual-class (&optional frame) 'static-color) | |
155 | (fset 'x-display-save-under 'ignore) | |
156 | (fset 'x-get-resource 'ignore) | |
a0c712ae | 157 | |
ef88bd2d | 158 | ;; From lisp/term/x-win.el |
f795f633 EZ |
159 | (defvar x-display-name "pc" |
160 | "The display name specifying the MS-DOS display and frame type.") | |
ef88bd2d | 161 | (setq split-window-keep-point t) |
c0e2e77f | 162 | (defvar x-colors (mapcar 'car msdos-color-values) |
bb3a4574 | 163 | "The list of colors available on a PC display under MS-DOS.") |
c4d64969 | 164 | |
8254b6b4 | 165 | ;; From lisp/term/w32-win.el |
c432c362 EZ |
166 | ; |
167 | ;;;; Selections and cut buffers | |
bb3a4574 | 168 | ; |
c432c362 EZ |
169 | ;;; We keep track of the last text selected here, so we can check the |
170 | ;;; current selection against it, and avoid passing back our own text | |
171 | ;;; from x-cut-buffer-or-selection-value. | |
172 | (defvar x-last-selected-text nil) | |
173 | ||
174 | (defvar x-select-enable-clipboard t | |
c0e2e77f | 175 | "Non-nil means cutting and pasting uses the clipboard.") |
c432c362 EZ |
176 | |
177 | (defun x-select-text (text &optional push) | |
178 | (if x-select-enable-clipboard | |
8254b6b4 | 179 | (w16-set-clipboard-data text)) |
c432c362 EZ |
180 | (setq x-last-selected-text text)) |
181 | ||
182 | ;;; Return the value of the current selection. | |
183 | ;;; Consult the selection, then the cut buffer. Treat empty strings | |
184 | ;;; as if they were unset. | |
185 | (defun x-get-selection-value () | |
186 | (if x-select-enable-clipboard | |
187 | (let (text) | |
188 | ;; Don't die if x-get-selection signals an error. | |
189 | (condition-case c | |
8254b6b4 EZ |
190 | (setq text (w16-get-clipboard-data)) |
191 | (error (message "w16-get-clipboard-data:%s" c))) | |
c432c362 EZ |
192 | (if (string= text "") (setq text nil)) |
193 | (cond | |
194 | ((not text) nil) | |
195 | ((eq text x-last-selected-text) nil) | |
196 | ((string= text x-last-selected-text) | |
197 | ;; Record the newer string, so subsequent calls can use the 'eq' test. | |
198 | (setq x-last-selected-text text) | |
199 | nil) | |
200 | (t | |
201 | (setq x-last-selected-text text)))))) | |
202 | ||
203 | ;;; Arrange for the kill and yank functions to set and check the clipboard. | |
204 | (setq interprogram-cut-function 'x-select-text) | |
205 | (setq interprogram-paste-function 'x-get-selection-value) | |
ef88bd2d | 206 | |
ea6401d7 RS |
207 | ;; From lisp/faces.el: we only have one font, so always return |
208 | ;; it, no matter which variety they've asked for. | |
209 | (defun x-frob-font-slant (font which) | |
210 | font) | |
c0e2e77f EZ |
211 | (defun x-frob-font-weight (font which) |
212 | font) | |
213 | (defun x-font-family-list () | |
214 | "Return a list of available font families on FRAME.\n\ | |
215 | If FRAME is omitted or nil, use the selected frame.\n\ | |
216 | Value is a list of conses (FAMILY . FIXED-P) where FAMILY\n\ | |
217 | is a font family, and FIXED-P is non-nil if fonts of that family\n\ | |
218 | are fixed-pitch." | |
219 | '(("default" . t))) | |
ea6401d7 | 220 | |
cee30b8f RS |
221 | ;; From src/fontset.c: |
222 | (fset 'query-fontset 'ignore) | |
223 | ||
e1ddc4b4 RS |
224 | ;; From lisp/term/x-win.el: make iconify-or-deiconify-frame a no-op. |
225 | (fset 'iconify-or-deiconify-frame 'ignore) | |
226 | ||
ef88bd2d MW |
227 | ;; From lisp/frame.el |
228 | (fset 'set-default-font 'ignore) | |
229 | (fset 'set-mouse-color 'ignore) ; We cannot, I think. | |
230 | (fset 'set-cursor-color 'ignore) ; Hardware determined by char under. | |
231 | (fset 'set-border-color 'ignore) ; Not useful. | |
c8a6e3b9 EZ |
232 | |
233 | ;; From lisp/term/x-win.el: | |
234 | (defconst x-long-option-alist | |
235 | '(("--name" . "-name") | |
236 | ("--title" . "-T") | |
237 | ("--reverse-video" . "-reverse") | |
238 | ("--foreground-color" . "-fg") | |
239 | ("--background-color" . "-bg"))) | |
ef88bd2d | 240 | ;; --------------------------------------------------------------------------- |
c8a6e3b9 | 241 | ;; Handle the X-like command line parameters "-fg", "-bg", "-name", etc. |
ef88bd2d MW |
242 | (defun msdos-handle-args (args) |
243 | (let ((rest nil)) | |
c8a6e3b9 | 244 | (message "%s" args) |
ef88bd2d | 245 | (while args |
c8a6e3b9 EZ |
246 | (let* ((this (car args)) |
247 | (orig-this this) | |
248 | completion argval) | |
ef88bd2d | 249 | (setq args (cdr args)) |
c8a6e3b9 EZ |
250 | ;; Check for long options with attached arguments |
251 | ;; and separate out the attached option argument into argval. | |
252 | (if (string-match "^--[^=]*=" this) | |
253 | (setq argval (substring this (match-end 0)) | |
254 | this (substring this 0 (1- (match-end 0))))) | |
255 | (setq completion (try-completion this x-long-option-alist)) | |
256 | (if (eq completion t) | |
257 | ;; Exact match for long option. | |
258 | (setq this (cdr (assoc this x-long-option-alist))) | |
259 | (if (stringp completion) | |
260 | (let ((elt (assoc completion x-long-option-alist))) | |
261 | ;; Check for abbreviated long option. | |
262 | (or elt | |
263 | (error "Option `%s' is ambiguous" this)) | |
264 | (setq this (cdr elt))) | |
265 | ;; Check for a short option. | |
266 | (setq argval nil this orig-this))) | |
ef88bd2d | 267 | (cond ((or (string= this "-fg") (string= this "-foreground")) |
c8a6e3b9 EZ |
268 | (or argval (setq argval (car args) args (cdr args))) |
269 | (setq default-frame-alist | |
270 | (cons (cons 'foreground-color argval) | |
271 | default-frame-alist))) | |
ef88bd2d | 272 | ((or (string= this "-bg") (string= this "-background")) |
c8a6e3b9 EZ |
273 | (or argval (setq argval (car args) args (cdr args))) |
274 | (setq default-frame-alist | |
275 | (cons (cons 'background-color argval) | |
276 | default-frame-alist))) | |
277 | ((or (string= this "-T") (string= this "-name")) | |
278 | (or argval (setq argval (car args) args (cdr args))) | |
279 | (setq default-frame-alist | |
280 | (cons | |
281 | (cons 'title | |
282 | (if (stringp argval) | |
283 | argval | |
284 | (let ((case-fold-search t) | |
285 | i) | |
286 | (setq argval (invocation-name)) | |
287 | ||
288 | ;; Change any . or * characters in name to | |
289 | ;; hyphens, so as to emulate behavior on X. | |
290 | (while | |
291 | (setq i (string-match "[.*]" argval)) | |
292 | (aset argval i ?-)) | |
293 | argval))) | |
294 | default-frame-alist))) | |
295 | ((or (string= this "-r") | |
296 | (string= this "-rv") | |
297 | (string= this "-reverse")) | |
298 | (setq default-frame-alist | |
299 | (cons '(reverse . t) | |
300 | default-frame-alist))) | |
ef88bd2d | 301 | (t (setq rest (cons this rest)))))) |
c8a6e3b9 | 302 | (nreverse rest))) |
ef88bd2d MW |
303 | |
304 | (setq command-line-args (msdos-handle-args command-line-args)) | |
305 | ;; --------------------------------------------------------------------------- | |
092af6d8 RS |
306 | |
307 | ;;; pc-win.el ends here |