Add missing :version tags to new defgroups and defcustoms
[bpt/emacs.git] / lisp / term / pc-win.el
CommitLineData
55535639 1;;; pc-win.el --- setup support for `PC windows' (whatever that is)
ef88bd2d 2
acaf905b 3;; Copyright (C) 1994, 1996-1997, 1999, 2001-2012
95df8112 4;; 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
1fecc8fe 11;; GNU Emacs is free software: you can redistribute it and/or modify
ef88bd2d 12;; it under the terms of the GNU General Public License as published by
1fecc8fe
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
ef88bd2d
MW
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
1fecc8fe 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
2fe590dc 23
55535639
PJ
24;;; Commentary:
25
cbcc5ad4
EZ
26;; This file is preloaded into Emacs by loadup.el. The functions in
27;; this file are then called during startup from startup.el. This
28;; means that just loading this file should not have any side effects
29;; besides defining functions and variables, and in particular should
30;; NOT initialize any window systems.
31
32;; The main entry points to this file's features are msdos-handle-args,
33;; msdos-create-frame-with-faces, msdos-initialize-window-system,
34;; terminal-init-internal. The last one is not supposed to be called,
35;; so it just errors out.
36
2fe590dc
EN
37;;; Code:
38
cbcc5ad4
EZ
39(if (not (fboundp 'msdos-remember-default-colors))
40 (error "%s: Loading pc-win.el but not compiled for MS-DOS"
41 (invocation-name)))
42
ef88bd2d
MW
43(load "term/internal" nil t)
44
73e6adaa
DN
45(declare-function msdos-remember-default-colors "msdos.c")
46(declare-function w16-set-clipboard-data "w16select.c")
47(declare-function w16-get-clipboard-data "w16select.c")
92f9269e 48(declare-function msdos-setup-keyboard "internal" (frame))
73e6adaa 49
cbcc5ad4 50;;; This was copied from etc/rgb.txt, except that some values were changed
f795f633
EZ
51;;; a bit to make them consistent with DOS console colors, and the RGB
52;;; values were scaled up to 16 bits, as `tty-define-color' requires.
53;;;
54;;; The mapping between the 16 standard EGA/VGA colors and X color names
55;;; was done by running a Unix version of Emacs inside an X client and a
56;;; DJGPP-compiled Emacs on the same PC. The names of X colors used to
57;;; define the pixel values are shown as comments to each color below.
c4d64969
EZ
58;;;
59;;; If you want to change the RGB values, keep in mind that various pieces
60;;; of Emacs think that a color whose RGB values add up to less than 0.6 of
f795f633 61;;; the values for WHITE (i.e. less than 117963) are ``dark'', otherwise the
c4d64969
EZ
62;;; color is ``light''; see `frame-set-background-mode' in lisp/faces.el for
63;;; an example.
64(defvar msdos-color-values
1400df92 65 '(("black" 0 0 0 0)
f795f633 66 ("blue" 1 0 0 52480) ; MediumBlue
1400df92
EZ
67 ("green" 2 8704 35584 8704) ; ForestGreen
68 ("cyan" 3 0 52736 53504) ; DarkTurquoise
69 ("red" 4 45568 8704 8704) ; FireBrick
70 ("magenta" 5 35584 0 35584) ; DarkMagenta
71 ("brown" 6 40960 20992 11520) ; Sienna
72 ("lightgray" 7 48640 48640 48640) ; Gray
73 ("darkgray" 8 26112 26112 26112) ; Gray40
74 ("lightblue" 9 0 0 65535) ; Blue
75 ("lightgreen" 10 0 65535 0) ; Green
76 ("lightcyan" 11 0 65535 65535) ; Cyan
77 ("lightred" 12 65535 0 0) ; Red
78 ("lightmagenta" 13 65535 0 65535) ; Magenta
79 ("yellow" 14 65535 65535 0) ; Yellow
80 ("white" 15 65535 65535 65535))
f795f633 81 "A list of MS-DOS console colors, their indices and 16-bit RGB values.")
a13b5fad 82
ef88bd2d
MW
83;; ---------------------------------------------------------------------------
84;; We want to delay setting frame parameters until the faces are setup
85(defvar default-frame-alist nil)
cbcc5ad4 86;(modify-frame-parameters terminal-frame default-frame-alist)
ef88bd2d
MW
87
88(defun msdos-face-setup ()
7ced34de
EZ
89 "Initial setup of faces for the MS-DOS display."
90 (set-face-foreground 'bold "yellow")
91 (set-face-foreground 'italic "red")
92 (set-face-foreground 'bold-italic "lightred")
93 (set-face-foreground 'underline "white")
ef88bd2d
MW
94
95 (make-face 'msdos-menu-active-face)
96 (make-face 'msdos-menu-passive-face)
97 (make-face 'msdos-menu-select-face)
7ced34de
EZ
98 (set-face-foreground 'msdos-menu-active-face "white")
99 (set-face-foreground 'msdos-menu-passive-face "lightgray")
100 (set-face-background 'msdos-menu-active-face "blue")
101 (set-face-background 'msdos-menu-passive-face "blue")
102 (set-face-background 'msdos-menu-select-face "red"))
ef88bd2d 103
f795f633
EZ
104(defun msdos-handle-reverse-video (frame parameters)
105 "Handle the reverse-video frame parameter on MS-DOS frames."
c88c89a0
EZ
106 (when (cdr (or (assq 'reverse parameters)
107 (assq 'reverse default-frame-alist)))
f795f633 108 (let* ((params (frame-parameters frame))
8fcacf13
EZ
109 (fg (cdr (assq 'foreground-color params)))
110 (bg (cdr (assq 'background-color params))))
111 (if (equal fg (cdr (assq 'mouse-color params)))
f795f633 112 (modify-frame-parameters frame
8fcacf13
EZ
113 (list (cons 'mouse-color bg))))
114 (if (equal fg (cdr (assq 'cursor-color params)))
f795f633 115 (modify-frame-parameters frame
8fcacf13 116 (list (cons 'cursor-color bg)))))))
f795f633
EZ
117
118;; This must run after all the default colors are inserted into
119;; tty-color-alist, since msdos-handle-reverse-video needs to know the
cbcc5ad4 120;; actual frame colors.
f795f633
EZ
121(defun msdos-setup-initial-frame ()
122 (modify-frame-parameters terminal-frame default-frame-alist)
123 ;; This remembers the screen colors after applying default-frame-alist,
124 ;; so that all subsequent frames could begin with those colors.
125 (msdos-remember-default-colors terminal-frame)
126 (modify-frame-parameters terminal-frame initial-frame-alist)
127 (msdos-handle-reverse-video terminal-frame
128 (frame-parameters terminal-frame))
129
130 (frame-set-background-mode terminal-frame)
131 (face-set-after-frame-default terminal-frame))
132
cbcc5ad4
EZ
133;; We create frames as if we were a terminal, but without invoking the
134;; terminal-initialization function. Also, our handling of reverse
135;; video is slightly different.
136(defun msdos-create-frame-with-faces (&optional parameters)
58179cce 137 "Create a frame on MS-DOS display.
cbcc5ad4
EZ
138Optional frame parameters PARAMETERS specify the frame parameters.
139Parameters not specified by PARAMETERS are taken from
140`default-frame-alist'. If either PARAMETERS or `default-frame-alist'
141contains a `reverse' parameter, handle that. Value is the new frame
142created."
f795f633
EZ
143 (let ((frame (make-terminal-frame parameters))
144 success)
68a89a25 145 (unwind-protect
cbcc5ad4 146 (with-selected-frame frame
f795f633 147 (msdos-handle-reverse-video frame (frame-parameters frame))
cbcc5ad4
EZ
148 (unless (terminal-parameter frame 'terminal-initted)
149 (set-terminal-parameter frame 'terminal-initted t))
68a89a25
EZ
150 (frame-set-background-mode frame)
151 (face-set-after-frame-default frame)
152 (setq success t))
153 (unless success (delete-frame frame)))
e2f35ede 154 frame))
9000684d 155
ef88bd2d 156;; ---------------------------------------------------------------------------
a7acbbe4 157;; More or less useful imitations of certain X-functions. A lot of the
ef88bd2d
MW
158;; values returned are questionable, but usually only the form of the
159;; returned value matters. Also, by the way, recall that `ignore' is
160;; a useful function for returning 'nil regardless of argument.
161
162;; From src/xfns.c
cee30b8f 163(defun x-list-fonts (pattern &optional face frame maximum width)
c0e2e77f
EZ
164 (if (or (null width) (and (numberp width) (= width 1)))
165 (list "ms-dos")
cee30b8f 166 (list "no-such-font")))
a259d337
RS
167(defun x-display-pixel-width (&optional frame) (frame-width frame))
168(defun x-display-pixel-height (&optional frame) (frame-height frame))
c0e2e77f
EZ
169(defun x-display-planes (&optional frame) 4) ;bg switched to 16 colors as well
170(defun x-display-color-cells (&optional frame) 16)
ef88bd2d
MW
171(defun x-server-max-request-size (&optional frame) 1000000) ; ???
172(defun x-server-vendor (&optional frame) t "GNU")
173(defun x-server-version (&optional frame) '(1 0 0))
174(defun x-display-screens (&optional frame) 1)
c0e2e77f
EZ
175(defun x-display-mm-height (&optional frame) 245) ; Guess the size of my
176(defun x-display-mm-width (&optional frame) 322) ; monitor, EZ...
ef88bd2d
MW
177(defun x-display-backing-store (&optional frame) 'not-useful)
178(defun x-display-visual-class (&optional frame) 'static-color)
179(fset 'x-display-save-under 'ignore)
180(fset 'x-get-resource 'ignore)
a0c712ae 181
ef88bd2d 182;; From lisp/term/x-win.el
f795f633 183(defvar x-display-name "pc"
3077d1f6
EZ
184 "The name of the window display on which Emacs was started.
185On X, the display name of individual X frames is recorded in the
186`display' frame parameter.")
c0e2e77f 187(defvar x-colors (mapcar 'car msdos-color-values)
3077d1f6
EZ
188 "List of basic colors available on color displays.
189For X, the list comes from the `rgb.txt' file,v 10.41 94/02/20.
190For Nextstep, this is a list of non-PANTONE colors returned by
191the operating system.")
c4d64969 192
8254b6b4 193;; From lisp/term/w32-win.el
c432c362 194;
45240125 195;;;; Selections
bb3a4574 196;
c432c362
EZ
197;;; We keep track of the last text selected here, so we can check the
198;;; current selection against it, and avoid passing back our own text
6d7cc563 199;;; from x-selection-value.
c432c362
EZ
200(defvar x-last-selected-text nil)
201
8c717810
EZ
202(defcustom x-select-enable-clipboard t
203 "Non-nil means cutting and pasting uses the clipboard.
3077d1f6
EZ
204This is in addition to, but in preference to, the primary selection.
205
6f748f70 206Note that MS-Windows does not support selection types other than the
725513b7
GM
207clipboard. (The primary selection that is set by Emacs is not
208accessible to other programs on MS-Windows.)
209
210This variable is not used by the Nextstep port."
8c717810
EZ
211 :type 'boolean
212 :group 'killing)
c432c362 213
6d7cc563 214(defun x-select-text (text)
3077d1f6
EZ
215 "Select TEXT, a string, according to the window system.
216
6d7cc563
JD
217On X, if `x-select-enable-clipboard' is non-nil, copy TEXT to the
218clipboard. If `x-select-enable-primary' is non-nil, put TEXT in
219the primary selection.
3077d1f6 220
90b671e2 221On MS-Windows, make TEXT the current selection. If
3077d1f6 222`x-select-enable-clipboard' is non-nil, copy the text to the
6d7cc563 223clipboard as well.
3077d1f6 224
90b671e2
EZ
225On Nextstep, put TEXT in the pasteboard (`x-select-enable-clipboard'
226is not used)."
db95369b 227 (if x-select-enable-clipboard
8254b6b4 228 (w16-set-clipboard-data text))
c432c362 229 (setq x-last-selected-text text))
db95369b 230
c432c362 231;;; Return the value of the current selection.
45240125 232;;; Consult the selection. Treat empty strings as if they were unset.
c432c362 233(defun x-get-selection-value ()
db95369b 234 (if x-select-enable-clipboard
c432c362
EZ
235 (let (text)
236 ;; Don't die if x-get-selection signals an error.
237 (condition-case c
8254b6b4
EZ
238 (setq text (w16-get-clipboard-data))
239 (error (message "w16-get-clipboard-data:%s" c)))
c432c362
EZ
240 (if (string= text "") (setq text nil))
241 (cond
242 ((not text) nil)
243 ((eq text x-last-selected-text) nil)
244 ((string= text x-last-selected-text)
245 ;; Record the newer string, so subsequent calls can use the 'eq' test.
246 (setq x-last-selected-text text)
247 nil)
248 (t
249 (setq x-last-selected-text text))))))
250
f22693fc 251;; x-selection-owner-p is used in simple.el.
90b671e2 252(defun x-selection-owner-p (&optional selection terminal)
f22693fc
EZ
253 "Whether the current Emacs process owns the given X Selection.
254The arg should be the name of the selection in question, typically one of
255the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
256\(Those are literal upper-case symbol names, since that's what X expects.)
257For convenience, the symbol nil is the same as `PRIMARY',
90b671e2
EZ
258and t is the same as `SECONDARY'.
259
260TERMINAL should be a terminal object or a frame specifying the X
261server to query. If omitted or nil, that stands for the selected
262frame's display, or the first available X display."
f22693fc
EZ
263 (if x-select-enable-clipboard
264 (let (text)
265 ;; Don't die if w16-get-clipboard-data signals an error.
266 (ignore-errors
267 (setq text (w16-get-clipboard-data)))
268 ;; We consider ourselves the owner of the selection if it does
269 ;; not exist, or exists and compares equal with the last text
270 ;; we've put into the Windows clipboard.
271 (cond
272 ((not text) t)
273 ((or (eq text x-last-selected-text)
274 (string= text x-last-selected-text))
275 text)
276 (t nil)))))
277
278;; x-own-selection-internal and x-disown-selection-internal are used
279;; in select.el:x-set-selection.
90b671e2
EZ
280(defun x-own-selection-internal (selection value &optional frame)
281 "Assert an X selection of the type SELECTION with and value VALUE.
282SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
f22693fc
EZ
283\(Those are literal upper-case symbol names, since that's what X expects.)
284VALUE is typically a string, or a cons of two markers, but may be
90b671e2
EZ
285anything that the functions on `selection-converter-alist' know about.
286
287FRAME should be a frame that should own the selection. If omitted or
288nil, it defaults to the selected frame."
f22693fc
EZ
289 (ignore-errors
290 (x-select-text value))
291 value)
292
90b671e2 293(defun x-disown-selection-internal (selection &optional time-object terminal)
f22693fc 294 "If we own the selection SELECTION, disown it.
90b671e2
EZ
295Disowning it means there is no such selection.
296
297TERMINAL should be a terminal object or a frame specifying the X
298server to query. If omitted or nil, that stands for the selected
299frame's display, or the first available X display."
f22693fc
EZ
300 (if (x-selection-owner-p selection)
301 t))
302
a2249e66 303;; x-get-selection-internal is used in select.el
90b671e2 304(defun x-get-selection-internal (selection-symbol target-type &optional time_stamp terminal)
a2249e66
EZ
305 "Return text selected from some X window.
306SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
307\(Those are literal upper-case symbol names, since that's what X expects.)
308TYPE is the type of data desired, typically `STRING'.
309TIME_STAMP is the time to use in the XConvertSelection call for foreign
90b671e2
EZ
310selections. If omitted, defaults to the time for the last event.
311
312TERMINAL should be a terminal object or a frame specifying the X
313server to query. If omitted or nil, that stands for the selected
314frame's display, or the first available X display."
a2249e66
EZ
315 (x-get-selection-value))
316
cee30b8f
RS
317;; From src/fontset.c:
318(fset 'query-fontset 'ignore)
319
e1ddc4b4
RS
320;; From lisp/term/x-win.el: make iconify-or-deiconify-frame a no-op.
321(fset 'iconify-or-deiconify-frame 'ignore)
322
ef88bd2d
MW
323;; From lisp/frame.el
324(fset 'set-default-font 'ignore)
325(fset 'set-mouse-color 'ignore) ; We cannot, I think.
326(fset 'set-cursor-color 'ignore) ; Hardware determined by char under.
327(fset 'set-border-color 'ignore) ; Not useful.
c8a6e3b9 328
9993f59a
EZ
329(defvar msdos-last-help-message nil
330 "The last help message received via `show-help-function'.
331This is used by `msdos-show-help'.")
332
23608640
EZ
333(defvar msdos-previous-message nil
334 "The content of the echo area before help echo was displayed.")
335
336(defun msdos-show-help (help)
8fc29035 337 "Function installed as `show-help-function' on MS-DOS frames."
23608640 338 (when (and (not (window-minibuffer-p)) ;Don't overwrite minibuffer contents.
23608640
EZ
339 (not cursor-in-echo-area)) ;Don't overwrite a prompt.
340 (cond
341 ((stringp help)
9993f59a
EZ
342 (setq help (replace-regexp-in-string "\n" ", " help))
343 (unless (or msdos-previous-message
344 (string-equal help (current-message))
345 (and (stringp msdos-last-help-message)
346 (string-equal msdos-last-help-message
347 (current-message))))
23608640 348 (setq msdos-previous-message (current-message)))
9993f59a 349 (setq msdos-last-help-message help)
08792c11 350 (let ((message-truncate-lines nil)
23608640 351 (message-log-max nil))
9993f59a 352 (message "%s" help)))
23608640
EZ
353 ((stringp msdos-previous-message)
354 (let ((message-log-max nil))
355 (message "%s" msdos-previous-message)
356 (setq msdos-previous-message nil)))
357 (t
358 (message nil)))))
359
360
cbcc5ad4 361;; Initialization.
ef88bd2d 362;; ---------------------------------------------------------------------------
cbcc5ad4
EZ
363;; This function is run, by faces.el:tty-create-frame-with-faces, only
364;; for the initial frame (on each terminal, but we have only one).
365;; This works by setting the `terminal-initted' terminal parameter to
366;; this function, the first time `tty-create-frame-with-faces' is
367;; called on that terminal. `tty-create-frame-with-faces' is called
368;; directly from startup.el and also by `make-frame' through
369;; `frame-creation-function-alist'. `make-frame' will call this
370;; function if `msdos-create-frame-with-faces' (see below) is not
371;; found in `frame-creation-function-alist', which means something is
372;; _very_ wrong, because "internal" terminal emulator should not be
373;; turned on if our window-system is not `pc'. Therefore, the only
374;; Right Thing for us to do here is scream bloody murder.
375(defun terminal-init-internal ()
376 "Terminal initialization function for the MS-DOS \"internal\" terminal.
377Errors out because it is not supposed to be called, ever."
378 (error "terminal-init-internal called for window-system `%s'"
379 (window-system)))
380
381(defun msdos-initialize-window-system ()
382 "Initialization function for the `pc' \"window system\"."
383 (or (eq (window-system) 'pc)
384 (error
385 "`msdos-initialize-window-system' called, but window-system is `%s'"
386 (window-system)))
387 ;; First, the keyboard.
388 (msdos-setup-keyboard terminal-frame) ; see internal.el
389 ;; Next, register the default colors.
390 (let* ((colors msdos-color-values)
391 (color (car colors)))
392 (tty-color-clear)
393 (while colors
394 (tty-color-define (car color) (cadr color) (cddr color))
395 (setq colors (cdr colors) color (car colors))))
396 ;; Modifying color mappings means realized faces don't
397 ;; use the right colors, so clear them.
398 (clear-face-cache)
399 ;; Now set up some additional faces.
400 (msdos-face-setup)
401 ;; Set up the initial frame.
402 (msdos-setup-initial-frame)
23608640
EZ
403 ;; Help echo is displayed in the echo area.
404 (setq show-help-function 'msdos-show-help)
cbcc5ad4
EZ
405 ;; We want to delay the codepage-related setup until after user's
406 ;; .emacs is processed, because people might define their
407 ;; `dos-codepage-setup-hook' there.
408 (add-hook 'after-init-hook 'dos-codepage-setup)
409 ;; In multibyte mode, we want unibyte buffers to be displayed
410 ;; using the terminal coding system, so that they display
411 ;; correctly on the DOS terminal; in unibyte mode we want to see
412 ;; all 8-bit characters verbatim. In both cases, we want the
413 ;; entire range of 8-bit characters to arrive at our display code
414 ;; verbatim.
415 (standard-display-8bit 127 255)
416 ;; We are fast enough to make this optimization unnecessary.
417 (setq split-window-keep-point t)
418 ;; Arrange for the kill and yank functions to set and check the
419 ;; clipboard.
420 (setq interprogram-cut-function 'x-select-text)
421 (setq interprogram-paste-function 'x-get-selection-value)
422 (menu-bar-enable-clipboard)
423 (run-hooks 'terminal-init-msdos-hook))
424
425;; frame-creation-function-alist is examined by frame.el:make-frame.
426(add-to-list 'frame-creation-function-alist
427 '(pc . msdos-create-frame-with-faces))
428;; window-system-initialization-alist is examined by startup.el:command-line.
429(add-to-list 'window-system-initialization-alist
430 '(pc . msdos-initialize-window-system))
431;; We don't need anything beyond tty-handle-args for handling
432;; command-line argument; see startup.el.
433(add-to-list 'handle-args-function-alist '(pc . tty-handle-args))
434
435;; ---------------------------------------------------------------------------
436
437(provide 'pc-win)
092af6d8
RS
438
439;;; pc-win.el ends here