| 1 | ;;; pc-win.el --- setup support for `PC windows' (whatever that is). |
| 2 | |
| 3 | ;; Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc. |
| 4 | |
| 5 | ;; Author: Morten Welinder <terra@diku.dk> |
| 6 | ;; Maintainer: FSF |
| 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 |
| 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 | |
| 27 | (load "term/internal" nil t) |
| 28 | |
| 29 | ;; Color translation -- doesn't really need to be fast. |
| 30 | ;; Colors listed here do not include the "light-", |
| 31 | ;; "medium-" and "dark-" prefixes that are accounted for |
| 32 | ;; by `msdos-color-translate', which see below). |
| 33 | |
| 34 | (defvar msdos-color-aliases |
| 35 | '(("snow" . "white") |
| 36 | ("ghost white" . "white") |
| 37 | ("ghostwhite" . "white") |
| 38 | ("white smoke" . "white") |
| 39 | ("whitesmoke" . "white") |
| 40 | ("gainsboro" . "white") |
| 41 | ("floral white" . "white") |
| 42 | ("floralwhite" . "white") |
| 43 | ("old lace" . "white") |
| 44 | ("oldlace" . "white") |
| 45 | ("linen" . "white") |
| 46 | ("antique white" . "white") |
| 47 | ("antiquewhite" . "white") |
| 48 | ("papaya whip" . "white") |
| 49 | ("papayawhip" . "white") |
| 50 | ("blanched almond" . "white") |
| 51 | ("blanchedalmond" . "white") |
| 52 | ("bisque" . "white") |
| 53 | ("peach puff" . "lightred") |
| 54 | ("peachpuff" . "lightred") |
| 55 | ("navajo white" . "lightred") |
| 56 | ("navajowhite" . "lightred") |
| 57 | ("moccasin" . "lightred") |
| 58 | ("cornsilk" . "white") |
| 59 | ("ivory" . "white") |
| 60 | ("lemon chiffon" . "yellow") |
| 61 | ("lemonchiffon" . "yellow") |
| 62 | ("seashell" . "white") |
| 63 | ("honeydew" . "white") |
| 64 | ("mint cream" . "white") |
| 65 | ("mintcream" . "white") |
| 66 | ("azure" . "lightcyan") |
| 67 | ("alice blue" . "lightcyan") |
| 68 | ("aliceblue" . "lightcyan") |
| 69 | ("lavender" . "lightcyan") |
| 70 | ("lavender blush" . "lightcyan") |
| 71 | ("lavenderblush" . "lightcyan") |
| 72 | ("misty rose" . "lightred") |
| 73 | ("mistyrose" . "lightred") |
| 74 | ("aquamarine" . "blue") |
| 75 | ("cadet blue" . "blue") |
| 76 | ("cadetblue" . "blue") |
| 77 | ("cornflower blue" . "lightblue") |
| 78 | ("cornflowerblue" . "lightblue") |
| 79 | ("midnight blue" . "blue") |
| 80 | ("midnightblue" . "blue") |
| 81 | ("navy blue" . "cyan") |
| 82 | ("navyblue" . "cyan") |
| 83 | ("navy" . "cyan") |
| 84 | ("royalblue" . "blue") |
| 85 | ("royal blue" . "blue") |
| 86 | ("sky blue" . "lightblue") |
| 87 | ("skyblue" . "lightblue") |
| 88 | ("dodger blue" . "blue") |
| 89 | ("dodgerblue" . "blue") |
| 90 | ("powder blue" . "lightblue") |
| 91 | ("powderblue" . "lightblue") |
| 92 | ("slate blue" . "cyan") |
| 93 | ("slateblue" . "cyan") |
| 94 | ("steel blue" . "blue") |
| 95 | ("steelblue" . "blue") |
| 96 | ("coral" . "lightred") |
| 97 | ("tomato" . "lightred") |
| 98 | ("firebrick" . "red") |
| 99 | ("gold" . "yellow") |
| 100 | ("goldenrod" . "yellow") |
| 101 | ("goldenrod yellow" . "yellow") |
| 102 | ("goldenrodyellow" . "yellow") |
| 103 | ("pale goldenrod" . "yellow") |
| 104 | ("palegoldenrod" . "yellow") |
| 105 | ("olive green" . "lightgreen") |
| 106 | ("olivegreen" . "lightgreen") |
| 107 | ("olive drab" . "green") |
| 108 | ("olivedrab" . "green") |
| 109 | ("forest green" . "green") |
| 110 | ("forestgreen" . "green") |
| 111 | ("lime green" . "lightgreen") |
| 112 | ("limegreen" . "lightgreen") |
| 113 | ("sea green" . "lightcyan") |
| 114 | ("seagreen" . "lightcyan") |
| 115 | ("spring green" . "green") |
| 116 | ("springgreen" . "green") |
| 117 | ("lawn green" . "lightgreen") |
| 118 | ("lawngreen" . "lightgreen") |
| 119 | ("chartreuse" . "yellow") |
| 120 | ("yellow green" . "lightgreen") |
| 121 | ("yellowgreen" . "lightgreen") |
| 122 | ("green yellow" . "lightgreen") |
| 123 | ("greenyellow" . "lightgreen") |
| 124 | ("slate grey" . "lightgray") |
| 125 | ("slategrey" . "lightgray") |
| 126 | ("slate gray" . "lightgray") |
| 127 | ("slategray" . "lightgray") |
| 128 | ("dim grey" . "darkgray") |
| 129 | ("dimgrey" . "darkgray") |
| 130 | ("dim gray" . "darkgray") |
| 131 | ("dimgray" . "darkgray") |
| 132 | ("light grey" . "lightgray") |
| 133 | ("lightgrey" . "lightgray") |
| 134 | ("light gray" . "lightgray") |
| 135 | ("gray" . "darkgray") |
| 136 | ("grey" . "darkgray") |
| 137 | ("khaki" . "green") |
| 138 | ("maroon" . "red") |
| 139 | ("orange" . "brown") |
| 140 | ("orchid" . "brown") |
| 141 | ("saddle brown" . "red") |
| 142 | ("saddlebrown" . "red") |
| 143 | ("peru" . "red") |
| 144 | ("burlywood" . "brown") |
| 145 | ("sandy brown" . "brown") |
| 146 | ("sandybrown" . "brown") |
| 147 | ("pink" . "lightred") |
| 148 | ("hotpink" . "lightred") |
| 149 | ("hot pink" ."lightred") |
| 150 | ("plum" . "magenta") |
| 151 | ("indian red" . "red") |
| 152 | ("indianred" . "red") |
| 153 | ("violet red" . "magenta") |
| 154 | ("violetred" . "magenta") |
| 155 | ("orange red" . "red") |
| 156 | ("orangered" . "red") |
| 157 | ("salmon" . "lightred") |
| 158 | ("sienna" . "lightred") |
| 159 | ("tan" . "lightred") |
| 160 | ("chocolate" . "brown") |
| 161 | ("thistle" . "magenta") |
| 162 | ("turquoise" . "lightgreen") |
| 163 | ("pale turquoise" . "cyan") |
| 164 | ("paleturquoise" . "cyan") |
| 165 | ("violet" . "magenta") |
| 166 | ("blue violet" . "lightmagenta") |
| 167 | ("blueviolet" . "lightmagenta") |
| 168 | ("wheat" . "white") |
| 169 | ("green yellow" . "yellow") |
| 170 | ("greenyellow" . "yellow") |
| 171 | ("purple" . "magenta") |
| 172 | ("rosybrown" . "brown") |
| 173 | ("rosy brown" . "brown") |
| 174 | ("beige" . "brown")) |
| 175 | "List of alternate names for colors.") |
| 176 | |
| 177 | (defun msdos-color-translate (name) |
| 178 | (setq name (downcase name)) |
| 179 | (let* ((len (length name)) |
| 180 | (val (- (length x-colors) |
| 181 | (length (member name x-colors)))) |
| 182 | (try)) |
| 183 | (if (or (< val 0) (>= val (length x-colors))) (setq val nil)) |
| 184 | (or val |
| 185 | (and (setq try (cdr (assoc name msdos-color-aliases))) |
| 186 | (msdos-color-translate try)) |
| 187 | (and (> len 5) |
| 188 | (string= "light" (substring name 0 5)) |
| 189 | (setq try (msdos-color-translate (substring name 5))) |
| 190 | (logior try 8)) |
| 191 | (and (> len 6) |
| 192 | (string= "light " (substring name 0 6)) |
| 193 | (setq try (msdos-color-translate (substring name 6))) |
| 194 | (logior try 8)) |
| 195 | (and (> len 4) |
| 196 | (string= "pale" (substring name 0 4)) |
| 197 | (setq try (msdos-color-translate (substring name 4))) |
| 198 | (logior try 8)) |
| 199 | (and (> len 5) |
| 200 | (string= "pale " (substring name 0 5)) |
| 201 | (setq try (msdos-color-translate (substring name 5))) |
| 202 | (logior try 8)) |
| 203 | (and (> len 6) |
| 204 | (string= "medium" (substring name 0 6)) |
| 205 | (msdos-color-translate (substring name 6))) |
| 206 | (and (> len 7) |
| 207 | (string= "medium " (substring name 0 7)) |
| 208 | (msdos-color-translate (substring name 7))) |
| 209 | (and (> len 4) |
| 210 | (or (string= "dark" (substring name 0 4)) |
| 211 | (string= "deep" (substring name 0 4))) |
| 212 | (msdos-color-translate (substring name 4))) |
| 213 | (and (> len 5) |
| 214 | (or (string= "dark " (substring name 0 5)) |
| 215 | (string= "deep " (substring name 0 5))) |
| 216 | (msdos-color-translate (substring name 5))) |
| 217 | (and (> len 4) ;; gray shades: gray0 to gray100 |
| 218 | (save-match-data |
| 219 | (and |
| 220 | (string-match "gr[ae]y[0-9]" name) |
| 221 | (string-match "[0-9]+\\'" name) |
| 222 | (let ((num (string-to-int |
| 223 | (substring name (match-beginning 0))))) |
| 224 | (msdos-color-translate |
| 225 | (cond |
| 226 | ((> num 90) "white") |
| 227 | ((> num 50) "lightgray") |
| 228 | ((> num 10) "darkgray") |
| 229 | (t "black"))))))) |
| 230 | (and (> len 1) ;; purple1 to purple4 and the like |
| 231 | (save-match-data |
| 232 | (and |
| 233 | (string-match "[1-4]\\'" name) |
| 234 | (msdos-color-translate |
| 235 | (substring name 0 (match-beginning 0))))))))) |
| 236 | ;; --------------------------------------------------------------------------- |
| 237 | ;; We want to delay setting frame parameters until the faces are setup |
| 238 | (defvar default-frame-alist nil) |
| 239 | (modify-frame-parameters terminal-frame default-frame-alist) |
| 240 | |
| 241 | (defun msdos-bg-mode (&optional frame) |
| 242 | (let* ((frame (or frame (selected-frame))) |
| 243 | (params (frame-parameters frame)) |
| 244 | (bg (cdr (assq 'background-color params)))) |
| 245 | (if (member bg '("black" "blue" "darkgray" "green")) |
| 246 | 'dark |
| 247 | 'light))) |
| 248 | |
| 249 | (defun msdos-face-setup () |
| 250 | (modify-frame-parameters terminal-frame default-frame-alist) |
| 251 | |
| 252 | (modify-frame-parameters terminal-frame |
| 253 | (list (cons 'background-mode |
| 254 | (msdos-bg-mode terminal-frame)) |
| 255 | (cons 'display-type 'color))) |
| 256 | (face-set-after-frame-default terminal-frame) |
| 257 | |
| 258 | (set-face-foreground 'bold "yellow" terminal-frame) |
| 259 | (set-face-foreground 'italic "red" terminal-frame) |
| 260 | (set-face-foreground 'bold-italic "lightred" terminal-frame) |
| 261 | (set-face-foreground 'underline "white" terminal-frame) |
| 262 | |
| 263 | (make-face 'msdos-menu-active-face) |
| 264 | (make-face 'msdos-menu-passive-face) |
| 265 | (make-face 'msdos-menu-select-face) |
| 266 | (set-face-foreground 'msdos-menu-active-face "white" terminal-frame) |
| 267 | (set-face-foreground 'msdos-menu-passive-face "lightgray" terminal-frame) |
| 268 | (set-face-background 'msdos-menu-active-face "blue" terminal-frame) |
| 269 | (set-face-background 'msdos-menu-passive-face "blue" terminal-frame) |
| 270 | (set-face-background 'msdos-menu-select-face "red" terminal-frame)) |
| 271 | |
| 272 | ;; We have only one font, so... |
| 273 | (add-hook 'before-init-hook 'msdos-face-setup) |
| 274 | |
| 275 | ;; We create frames as if we were a terminal, but with a twist. |
| 276 | (defun make-msdos-frame (&optional parameters) |
| 277 | (let* ((parms |
| 278 | (append initial-frame-alist default-frame-alist parameters nil)) |
| 279 | (frame (make-terminal-frame parms))) |
| 280 | (modify-frame-parameters frame |
| 281 | (list (cons 'background-mode |
| 282 | (msdos-bg-mode frame)) |
| 283 | (cons 'display-type 'color))) |
| 284 | frame)) |
| 285 | |
| 286 | (setq frame-creation-function 'make-msdos-frame) |
| 287 | |
| 288 | ;; --------------------------------------------------------------------------- |
| 289 | ;; More or less useful imitations of certain X-functions. A lot of the |
| 290 | ;; values returned are questionable, but usually only the form of the |
| 291 | ;; returned value matters. Also, by the way, recall that `ignore' is |
| 292 | ;; a useful function for returning 'nil regardless of argument. |
| 293 | |
| 294 | ;; From src/xfns.c |
| 295 | (defun x-display-color-p (&optional display) 't) |
| 296 | (defun x-list-fonts (pattern &optional face frame maximum width) |
| 297 | (if (and (numberp width) (= width 1)) |
| 298 | (list "default") |
| 299 | (list "no-such-font"))) |
| 300 | (defun x-color-defined-p (color) (numberp (msdos-color-translate color))) |
| 301 | (defun x-display-pixel-width (&optional frame) (frame-width frame)) |
| 302 | (defun x-display-pixel-height (&optional frame) (frame-height frame)) |
| 303 | (defun x-display-planes (&optional frame) 4) ; 3 for background, actually |
| 304 | (defun x-display-color-cells (&optional frame) 16) ; ??? |
| 305 | (defun x-server-max-request-size (&optional frame) 1000000) ; ??? |
| 306 | (defun x-server-vendor (&optional frame) t "GNU") |
| 307 | (defun x-server-version (&optional frame) '(1 0 0)) |
| 308 | (defun x-display-screens (&optional frame) 1) |
| 309 | (defun x-display-mm-height (&optional frame) 200) ; Guess the size of my |
| 310 | (defun x-display-mm-width (&optional frame) 253) ; monitor, MW... |
| 311 | (defun x-display-backing-store (&optional frame) 'not-useful) |
| 312 | (defun x-display-visual-class (&optional frame) 'static-color) |
| 313 | (fset 'x-display-save-under 'ignore) |
| 314 | (fset 'x-get-resource 'ignore) |
| 315 | |
| 316 | ;; From lisp/term/x-win.el |
| 317 | (setq x-display-name "pc") |
| 318 | (setq split-window-keep-point t) |
| 319 | (defvar x-colors '("black" |
| 320 | "blue" |
| 321 | "green" |
| 322 | "cyan" |
| 323 | "red" |
| 324 | "magenta" |
| 325 | "brown" |
| 326 | "lightgray" |
| 327 | "darkgray" |
| 328 | "lightblue" |
| 329 | "lightgreen" |
| 330 | "lightcyan" |
| 331 | "lightred" |
| 332 | "lightmagenta" |
| 333 | "yellow" |
| 334 | "white") |
| 335 | "The list of colors available on a PC display under MS-DOS.") |
| 336 | (defun x-defined-colors (&optional frame) |
| 337 | "Return a list of colors supported for a particular frame. |
| 338 | The argument FRAME specifies which frame to try. |
| 339 | The value may be different for frames on different X displays." |
| 340 | x-colors) |
| 341 | |
| 342 | ;; From lisp/term/w32-win.el |
| 343 | ; |
| 344 | ;;;; Selections and cut buffers |
| 345 | ; |
| 346 | ;;; We keep track of the last text selected here, so we can check the |
| 347 | ;;; current selection against it, and avoid passing back our own text |
| 348 | ;;; from x-cut-buffer-or-selection-value. |
| 349 | (defvar x-last-selected-text nil) |
| 350 | |
| 351 | (defvar x-select-enable-clipboard t |
| 352 | "Non-nil means cutting and pasting uses the clipboard. |
| 353 | This is in addition to the primary selection.") |
| 354 | |
| 355 | (defun x-select-text (text &optional push) |
| 356 | (if x-select-enable-clipboard |
| 357 | (w16-set-clipboard-data text)) |
| 358 | (setq x-last-selected-text text)) |
| 359 | |
| 360 | ;;; Return the value of the current selection. |
| 361 | ;;; Consult the selection, then the cut buffer. Treat empty strings |
| 362 | ;;; as if they were unset. |
| 363 | (defun x-get-selection-value () |
| 364 | (if x-select-enable-clipboard |
| 365 | (let (text) |
| 366 | ;; Don't die if x-get-selection signals an error. |
| 367 | (condition-case c |
| 368 | (setq text (w16-get-clipboard-data)) |
| 369 | (error (message "w16-get-clipboard-data:%s" c))) |
| 370 | (if (string= text "") (setq text nil)) |
| 371 | (cond |
| 372 | ((not text) nil) |
| 373 | ((eq text x-last-selected-text) nil) |
| 374 | ((string= text x-last-selected-text) |
| 375 | ;; Record the newer string, so subsequent calls can use the 'eq' test. |
| 376 | (setq x-last-selected-text text) |
| 377 | nil) |
| 378 | (t |
| 379 | (setq x-last-selected-text text)))))) |
| 380 | |
| 381 | ;;; Arrange for the kill and yank functions to set and check the clipboard. |
| 382 | (setq interprogram-cut-function 'x-select-text) |
| 383 | (setq interprogram-paste-function 'x-get-selection-value) |
| 384 | |
| 385 | ;; From lisp/faces.el: we only have one font, so always return |
| 386 | ;; it, no matter which variety they've asked for. |
| 387 | (defun x-frob-font-slant (font which) |
| 388 | font) |
| 389 | |
| 390 | ;; From src/fontset.c: |
| 391 | (fset 'query-fontset 'ignore) |
| 392 | |
| 393 | ;; From lisp/term/x-win.el: make iconify-or-deiconify-frame a no-op. |
| 394 | (fset 'iconify-or-deiconify-frame 'ignore) |
| 395 | |
| 396 | ;; From lisp/frame.el |
| 397 | (fset 'set-default-font 'ignore) |
| 398 | (fset 'set-mouse-color 'ignore) ; We cannot, I think. |
| 399 | (fset 'set-cursor-color 'ignore) ; Hardware determined by char under. |
| 400 | (fset 'set-border-color 'ignore) ; Not useful. |
| 401 | |
| 402 | ;; From lisp/term/x-win.el: |
| 403 | (defconst x-long-option-alist |
| 404 | '(("--name" . "-name") |
| 405 | ("--title" . "-T") |
| 406 | ("--reverse-video" . "-reverse") |
| 407 | ("--foreground-color" . "-fg") |
| 408 | ("--background-color" . "-bg"))) |
| 409 | ;; --------------------------------------------------------------------------- |
| 410 | ;; Handle the X-like command line parameters "-fg", "-bg", "-name", etc. |
| 411 | (defun msdos-handle-args (args) |
| 412 | (let ((rest nil)) |
| 413 | (message "%s" args) |
| 414 | (while args |
| 415 | (let* ((this (car args)) |
| 416 | (orig-this this) |
| 417 | completion argval) |
| 418 | (setq args (cdr args)) |
| 419 | ;; Check for long options with attached arguments |
| 420 | ;; and separate out the attached option argument into argval. |
| 421 | (if (string-match "^--[^=]*=" this) |
| 422 | (setq argval (substring this (match-end 0)) |
| 423 | this (substring this 0 (1- (match-end 0))))) |
| 424 | (setq completion (try-completion this x-long-option-alist)) |
| 425 | (if (eq completion t) |
| 426 | ;; Exact match for long option. |
| 427 | (setq this (cdr (assoc this x-long-option-alist))) |
| 428 | (if (stringp completion) |
| 429 | (let ((elt (assoc completion x-long-option-alist))) |
| 430 | ;; Check for abbreviated long option. |
| 431 | (or elt |
| 432 | (error "Option `%s' is ambiguous" this)) |
| 433 | (setq this (cdr elt))) |
| 434 | ;; Check for a short option. |
| 435 | (setq argval nil this orig-this))) |
| 436 | (cond ((or (string= this "-fg") (string= this "-foreground")) |
| 437 | (or argval (setq argval (car args) args (cdr args))) |
| 438 | (setq default-frame-alist |
| 439 | (cons (cons 'foreground-color argval) |
| 440 | default-frame-alist))) |
| 441 | ((or (string= this "-bg") (string= this "-background")) |
| 442 | (or argval (setq argval (car args) args (cdr args))) |
| 443 | (setq default-frame-alist |
| 444 | (cons (cons 'background-color argval) |
| 445 | default-frame-alist))) |
| 446 | ((or (string= this "-T") (string= this "-name")) |
| 447 | (or argval (setq argval (car args) args (cdr args))) |
| 448 | (setq default-frame-alist |
| 449 | (cons |
| 450 | (cons 'title |
| 451 | (if (stringp argval) |
| 452 | argval |
| 453 | (let ((case-fold-search t) |
| 454 | i) |
| 455 | (setq argval (invocation-name)) |
| 456 | |
| 457 | ;; Change any . or * characters in name to |
| 458 | ;; hyphens, so as to emulate behavior on X. |
| 459 | (while |
| 460 | (setq i (string-match "[.*]" argval)) |
| 461 | (aset argval i ?-)) |
| 462 | argval))) |
| 463 | default-frame-alist))) |
| 464 | ((or (string= this "-r") |
| 465 | (string= this "-rv") |
| 466 | (string= this "-reverse")) |
| 467 | (setq default-frame-alist |
| 468 | (cons '(reverse . t) |
| 469 | default-frame-alist))) |
| 470 | (t (setq rest (cons this rest)))))) |
| 471 | (nreverse rest))) |
| 472 | |
| 473 | (setq command-line-args (msdos-handle-args command-line-args)) |
| 474 | ;; --------------------------------------------------------------------------- |
| 475 | |
| 476 | ;;; pc-win.el ends here |