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