]> code.delx.au - gnu-emacs/blobdiff - lisp/term/pc-win.el
Fix coding tag.
[gnu-emacs] / lisp / term / pc-win.el
index 57ba7eb15680760411fa656012ccfd8f331199e0..e3bb01eded9887034a5f53f0637d1cb9353a8baa 100644 (file)
@@ -1,6 +1,7 @@
-;; pc-win.el -- setup support for `PC windows' (whatever that is).
+;;; pc-win.el --- setup support for `PC windows' (whatever that is)
 
-;; Copyright (C) 1994, 1996 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1996, 1997, 1999, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: Morten Welinder <terra@diku.dk>
 ;; Maintainer: FSF
@@ -9,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
 
 ;;; Code:
 
 (load "term/internal" nil t)
 
-;; Color translation -- doesn't really need to be fast.
-;; Colors listed here do not include the "light-",
-;; "medium-" and "dark-" prefixes that are accounted for
-;; by `msdos-color-translate', which see below).
-
-(defvar msdos-color-aliases
-  '(("snow"            . "white")
-    ("ghost white"     . "white")
-    ("ghostwhite"      . "white")
-    ("white smoke"     . "white")
-    ("whitesmoke"      . "white")
-    ("gainsboro"       . "white")
-    ("floral white"    . "white")
-    ("floralwhite"     . "white")
-    ("old lace"                . "white")
-    ("oldlace"         . "white")
-    ("linen"           . "white")
-    ("antique white"   . "white")
-    ("antiquewhite"    . "white")
-    ("papaya whip"     . "white")
-    ("papayawhip"      . "white")
-    ("blanched almond" . "white")
-    ("blanchedalmond"  . "white")
-    ("bisque"          . "white")
-    ("peach puff"      . "lightred")
-    ("peachpuff"       . "lightred")
-    ("navajo white"    . "lightred")
-    ("navajowhite"     . "lightred")
-    ("moccasin"                . "lightred")
-    ("cornsilk"                . "white")
-    ("ivory"           . "white")
-    ("lemon chiffon"   . "yellow")
-    ("lemonchiffon"    . "yellow")
-    ("seashell"                . "white")
-    ("honeydew"                . "white")
-    ("mint cream"      . "white")
-    ("mintcream"       . "white")
-    ("azure"           . "lightcyan")
-    ("alice blue"      . "lightcyan")
-    ("aliceblue"       . "lightcyan")
-    ("lavender"                . "lightcyan")
-    ("lavender blush"  . "lightcyan")
-    ("lavenderblush"   . "lightcyan")
-    ("misty rose"      . "lightred")
-    ("mistyrose"       . "lightred")
-    ("aquamarine"      . "blue")
-    ("cadet blue"      . "blue")
-    ("cadetblue"       . "blue")
-    ("cornflower blue" . "lightblue")
-    ("cornflowerblue"  . "lightblue")
-    ("midnight blue"   . "blue")
-    ("midnightblue"    . "blue")
-    ("navy blue"       . "cyan")
-    ("navyblue"                . "cyan")
-    ("navy"            . "cyan")
-    ("sky blue"                . "lightblue")
-    ("skyblue"         . "lightblue")
-    ("dodger blue"     . "blue")
-    ("dodgerblue"      . "blue")
-    ("powder blue"     . "lightblue")
-    ("powderblue"      . "lightblue")
-    ("slate blue"      . "cyan")
-    ("slateblue"       . "cyan")
-    ("steel blue"      . "blue")
-    ("steelblue"       . "blue")
-    ("coral"           . "lightred")
-    ("firebrick"       . "red")
-    ("gold"            . "yellow")
-    ("goldenrod"       . "yellow")
-    ("pale goldenrod"  . "yellow")
-    ("palegoldenrod"   . "yellow")
-    ("olive green"     . "lightgreen")
-    ("olivegreen"      . "lightgreen")
-    ("olive drab"      . "green")
-    ("olivedrab"       . "green")
-    ("forest green"    . "green")
-    ("forestgreen"     . "green")
-    ("lime green"      . "lightgreen")
-    ("limegreen"       . "lightgreen")
-    ("sea green"       . "lightcyan")
-    ("seagreen"                . "lightcyan")
-    ("spring green"    . "green")
-    ("springgreen"     . "green")
-    ("pale green"      . "lightgreen")
-    ("palegreen"       . "lightgreen")
-    ("lawn green"      . "lightgreen")
-    ("lawngreen"       . "lightgreen")
-    ("chartreuse"      . "yellow")
-    ("yellow green"    . "lightgreen")
-    ("yellowgreen"     . "lightgreen")
-    ("green yellow"    . "lightgreen")
-    ("greenyellow"     . "lightgreen")
-    ("slate grey"      . "lightgray")
-    ("slategrey"       . "lightgray")
-    ("slate gray"      . "lightgray")
-    ("slategray"       . "lightgray")
-    ("dim grey"                . "darkgray")
-    ("dimgrey"         . "darkgray")
-    ("dim gray"                . "darkgray")
-    ("dimgray"         . "darkgray")
-    ("light grey"      . "lightgray")
-    ("lightgrey"       . "lightgray")
-    ("light gray"      . "lightgray")
-    ("gray"            . "darkgray")
-    ("grey"            . "darkgray")
-    ("gray80"          . "darkgray")
-    ("gray50"          . "black")
-    ("gray90"          . "darkgray")
-    ("khaki"           . "green")
-    ("maroon"          . "red")
-    ("orange"          . "brown")
-    ("orchid"          . "brown")
-    ("saddle brown"    . "red")
-    ("saddlebrown"     . "red")
-    ("sienna"          . "red")
-    ("peru"            . "red")
-    ("pink"            . "lightred")
-    ("plum"            . "magenta")
-    ("indian red"      . "red")
-    ("indianred"       . "red")
-    ("violet red"      . "magenta")
-    ("violetred"       . "magenta")
-    ("orange red"      . "red")
-    ("orangered"       . "red")
-    ("salmon"          .  "lightred")
-    ("sienna"          . "lightred")
-    ("tan"             . "lightred")
-    ("thistle"         . "magenta")
-    ("turquoise"       . "lightgreen")
-    ("pale turquoise"  . "cyan")
-    ("paleturquoise"   . "cyan")
-    ("violet"          . "magenta")
-    ("blue violet"     . "lightmagenta")
-    ("blueviolet"      . "lightmagenta")
-    ("wheat"           . "white")
-    ("green yellow"    . "yellow")
-    ("greenyellow"     . "yellow")
-    ("purple"          . "magenta")
-    ("royalblue"       . "blue")
-    ("grey40"          . "darkgray")
-    ("rosybrown"       . "brown")
-    ("rosy brown"      . "brown")
-    ("beige"           . "brown"))
-  "List of alternate names for colors.")
-
-(defun msdos-color-translate (name)
-  (setq name (downcase name))
-  (let* ((len (length name))
-        (val (- (length x-colors)
-                (length (member name x-colors))))
-        (try))
-    (if (or (< val 0) (>= val (length x-colors))) (setq val nil))
-    (or val
-       (and (setq try (cdr (assoc name msdos-color-aliases)))
-            (msdos-color-translate try))
-       (and (> len 5)
-            (string= "light" (substring name 0 5))
-            (setq try (msdos-color-translate (substring name 5)))
-            (logior try 8))
-       (and (> len 6)
-            (string= "light " (substring name 0 6))
-            (setq try (msdos-color-translate (substring name 6)))
-            (logior try 8))
-       (and (> len 6)
-            (string= "medium" (substring name 0 6))
-            (msdos-color-translate (substring name 6)))
-       (and (> len 7)
-            (string= "medium " (substring name 0 7))
-            (msdos-color-translate (substring name 7)))
-       (and (> len 4)
-            (string= "dark" (substring name 0 4))
-            (msdos-color-translate (substring name 4)))
-       (and (> len 5)
-            (string= "dark " (substring name 0 5))
-            (msdos-color-translate (substring name 5))))))
+(declare-function msdos-remember-default-colors "msdos.c")
+(declare-function w16-set-clipboard-data "w16select.c")
+(declare-function w16-get-clipboard-data "w16select.c")
+
+;;; This is copied from etc/rgb.txt, except that some values were changed
+;;; a bit to make them consistent with DOS console colors, and the RGB
+;;; values were scaled up to 16 bits, as `tty-define-color' requires.
+;;;
+;;; The mapping between the 16 standard EGA/VGA colors and X color names
+;;; was done by running a Unix version of Emacs inside an X client and a
+;;; DJGPP-compiled Emacs on the same PC.  The names of X colors used to
+;;; define the pixel values are shown as comments to each color below.
+;;;
+;;; If you want to change the RGB values, keep in mind that various pieces
+;;; of Emacs think that a color whose RGB values add up to less than 0.6 of
+;;; the values for WHITE (i.e. less than 117963) are ``dark'', otherwise the
+;;; color is ``light''; see `frame-set-background-mode' in lisp/faces.el for
+;;; an example.
+(defvar msdos-color-values
+  '(("black"          0     0     0     0)
+    ("blue"           1     0     0 52480) ; MediumBlue
+    ("green"          2  8704 35584  8704) ; ForestGreen
+    ("cyan"           3     0 52736 53504) ; DarkTurquoise
+    ("red"            4 45568  8704  8704) ; FireBrick
+    ("magenta"        5 35584     0 35584) ; DarkMagenta
+    ("brown"          6 40960 20992 11520) ; Sienna
+    ("lightgray"      7 48640 48640 48640) ; Gray
+    ("darkgray"       8 26112 26112 26112) ; Gray40
+    ("lightblue"      9     0     0 65535) ; Blue
+    ("lightgreen"    10     0 65535     0) ; Green
+    ("lightcyan"     11     0 65535 65535) ; Cyan
+    ("lightred"      12 65535     0     0) ; Red
+    ("lightmagenta"  13 65535     0 65535) ; Magenta
+    ("yellow"        14 65535 65535     0) ; Yellow
+    ("white"         15 65535 65535 65535))
+  "A list of MS-DOS console colors, their indices and 16-bit RGB values.")
+
 ;; ---------------------------------------------------------------------------
 ;; We want to delay setting frame parameters until the faces are setup
 (defvar default-frame-alist nil)
 (modify-frame-parameters terminal-frame default-frame-alist)
+(tty-color-clear)
 
 (defun msdos-face-setup ()
-  (modify-frame-parameters terminal-frame default-frame-alist)
-
   (set-face-foreground 'bold "yellow" terminal-frame)
   (set-face-foreground 'italic "red" terminal-frame)
   (set-face-foreground 'bold-italic "lightred" terminal-frame)
   (set-face-foreground 'underline "white" terminal-frame)
-  (set-face-background 'region "green" terminal-frame)
 
   (make-face 'msdos-menu-active-face)
   (make-face 'msdos-menu-passive-face)
   (set-face-background 'msdos-menu-passive-face "blue" terminal-frame)
   (set-face-background 'msdos-menu-select-face "red" terminal-frame))
 
-;; We have only one font, so...
 (add-hook 'before-init-hook 'msdos-face-setup)
 
+(defun msdos-handle-reverse-video (frame parameters)
+  "Handle the reverse-video frame parameter on MS-DOS frames."
+  (when (cdr (or (assq 'reverse parameters)
+                (assq 'reverse default-frame-alist)))
+      (let* ((params (frame-parameters frame))
+            (fg (cdr (assq 'foreground-color params)))
+            (bg (cdr (assq 'background-color params))))
+       (if (equal fg (cdr (assq 'mouse-color params)))
+           (modify-frame-parameters frame
+                                    (list (cons 'mouse-color bg))))
+       (if (equal fg (cdr (assq 'cursor-color params)))
+           (modify-frame-parameters frame
+                                    (list (cons 'cursor-color bg)))))))
+
+;; This must run after all the default colors are inserted into
+;; tty-color-alist, since msdos-handle-reverse-video needs to know the
+;; actual frame colors.  tty-color-alist is set up by startup.el, but
+;; only after it runs before-init-hook and after-init-hook.
+(defun msdos-setup-initial-frame ()
+  (modify-frame-parameters terminal-frame default-frame-alist)
+  ;; This remembers the screen colors after applying default-frame-alist,
+  ;; so that all subsequent frames could begin with those colors.
+  (msdos-remember-default-colors terminal-frame)
+  (modify-frame-parameters terminal-frame initial-frame-alist)
+  (msdos-handle-reverse-video terminal-frame
+                             (frame-parameters terminal-frame))
+
+  (frame-set-background-mode terminal-frame)
+  (face-set-after-frame-default terminal-frame))
+
+(add-hook 'term-setup-hook 'msdos-setup-initial-frame)
+
 ;; We create frames as if we were a terminal, but with a twist.
 (defun make-msdos-frame (&optional parameters)
-  (let ((parms
-        (append initial-frame-alist default-frame-alist parameters nil)))
-    (make-terminal-frame parms)))
-
-(setq frame-creation-function 'make-msdos-frame)
+  (let ((frame (make-terminal-frame parameters))
+       success)
+    (unwind-protect
+       (progn
+         (msdos-handle-reverse-video frame (frame-parameters frame))
+         (frame-set-background-mode frame)
+         (face-set-after-frame-default frame)
+         (setq success t))
+      (unless success (delete-frame frame)))
+    frame))
+
+(add-to-list 'frame-creation-function-alist '(pc . make-msdos-frame))
 
 ;; ---------------------------------------------------------------------------
 ;; More or less useful imitations of certain X-functions.  A lot of the
 ;; a useful function for returning 'nil regardless of argument.
 
 ;; From src/xfns.c
-(defun x-display-color-p (&optional display) 't)
-(defun x-list-fonts (pattern &optional face frame) (list "default"))
-(defun x-color-defined-p (color) (numberp (msdos-color-translate color)))
+(defun x-list-fonts (pattern &optional face frame maximum width)
+  (if (or (null width) (and (numberp width) (= width 1)))
+      (list "ms-dos")
+    (list "no-such-font")))
 (defun x-display-pixel-width (&optional frame) (frame-width frame))
 (defun x-display-pixel-height (&optional frame) (frame-height frame))
-(defun x-display-planes (&optional frame) 4) ; 3 for background, actually
-(defun x-display-color-cells (&optional frame) 16) ; ???
+(defun x-display-planes (&optional frame) 4) ;bg switched to 16 colors as well
+(defun x-display-color-cells (&optional frame) 16)
 (defun x-server-max-request-size (&optional frame) 1000000) ; ???
 (defun x-server-vendor (&optional frame) t "GNU")
 (defun x-server-version (&optional frame) '(1 0 0))
 (defun x-display-screens (&optional frame) 1)
-(defun x-display-mm-height (&optional frame) 200) ; Guess the size of my
-(defun x-display-mm-width (&optional frame) 253)  ; monitor, MW...
+(defun x-display-mm-height (&optional frame) 245) ; Guess the size of my
+(defun x-display-mm-width (&optional frame) 322)  ; monitor, EZ...
 (defun x-display-backing-store (&optional frame) 'not-useful)
 (defun x-display-visual-class (&optional frame) 'static-color)
 (fset 'x-display-save-under 'ignore)
 (fset 'x-get-resource 'ignore)
 
 ;; From lisp/term/x-win.el
-(setq x-display-name "pc")
+(defvar x-display-name "pc"
+  "The display name specifying the MS-DOS display and frame type.")
 (setq split-window-keep-point t)
-(defvar x-colors '("black"
-                  "blue"
-                  "green"
-                  "cyan"
-                  "red"
-                  "magenta"
-                  "brown"
-                  "lightgray"
-                  "darkgray"
-                  "lightblue"
-                  "lightgreen"
-                  "lightcyan"
-                  "lightred"
-                  "lightmagenta"
-                  "yellow"
-                  "white")
+(defvar x-colors (mapcar 'car msdos-color-values)
   "The list of colors available on a PC display under MS-DOS.")
-(defun x-defined-colors (&optional frame)
-  "Return a list of colors supported for a particular frame.
-The argument FRAME specifies which frame to try.
-The value may be different for frames on different X displays."
-  x-colors)
+
+;; From lisp/term/w32-win.el
+;
+;;;; Selections and cut buffers
 ;
-;; From lisp/select.el
-(defun x-get-selection (&rest rest) "")
-(fset 'x-set-selection 'ignore)
+;;; We keep track of the last text selected here, so we can check the
+;;; current selection against it, and avoid passing back our own text
+;;; from x-cut-buffer-or-selection-value.
+(defvar x-last-selected-text nil)
+
+(defcustom x-select-enable-clipboard t
+  "Non-nil means cutting and pasting uses the clipboard.
+This is the default on this system, since MS-Windows does not
+support other types of selections."
+  :type 'boolean
+  :group 'killing)
+
+(defun x-select-text (text &optional push)
+  (if x-select-enable-clipboard
+      (w16-set-clipboard-data text))
+  (setq x-last-selected-text text))
+
+;;; Return the value of the current selection.
+;;; Consult the selection, then the cut buffer.  Treat empty strings
+;;; as if they were unset.
+(defun x-get-selection-value ()
+  (if x-select-enable-clipboard
+      (let (text)
+       ;; Don't die if x-get-selection signals an error.
+       (condition-case c
+           (setq text (w16-get-clipboard-data))
+         (error (message "w16-get-clipboard-data:%s" c)))
+       (if (string= text "") (setq text nil))
+       (cond
+        ((not text) nil)
+        ((eq text x-last-selected-text) nil)
+        ((string= text x-last-selected-text)
+         ;; Record the newer string, so subsequent calls can use the 'eq' test.
+         (setq x-last-selected-text text)
+         nil)
+        (t
+         (setq x-last-selected-text text))))))
+
+;;; Arrange for the kill and yank functions to set and check the clipboard.
+(setq interprogram-cut-function 'x-select-text)
+(setq interprogram-paste-function 'x-get-selection-value)
 
 ;; From lisp/faces.el: we only have one font, so always return
 ;; it, no matter which variety they've asked for.
 (defun x-frob-font-slant (font which)
   font)
+(make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
+(defun x-frob-font-weight (font which)
+  font)
+(make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
+(defun x-font-family-list ()
+  "Return a list of available font families on FRAME.\n\
+If FRAME is omitted or nil, use the selected frame.\n\
+Value is a list of conses (FAMILY . FIXED-P) where FAMILY\n\
+is a font family, and FIXED-P is non-nil if fonts of that family\n\
+are fixed-pitch."
+  '(("default" . t)))
+
+;; From src/fontset.c:
+(fset 'query-fontset 'ignore)
+
+;; From lisp/term/x-win.el: make iconify-or-deiconify-frame a no-op.
+(fset 'iconify-or-deiconify-frame 'ignore)
 
 ;; From lisp/frame.el
 (fset 'set-default-font 'ignore)
 (fset 'set-mouse-color 'ignore)                ; We cannot, I think.
 (fset 'set-cursor-color 'ignore)       ; Hardware determined by char under.
 (fset 'set-border-color 'ignore)       ; Not useful.
+
 ;; ---------------------------------------------------------------------------
-;; Handle the X-like command line parameters "-fg" and "-bg"
-(defun msdos-handle-args (args)
-  (let ((rest nil))
-    (while args
-      (let ((this (car args)))
-       (setq args (cdr args))
-       (cond ((or (string= this "-fg") (string= this "-foreground"))
-              (if args
-                  (setq default-frame-alist
-                        (cons (cons 'foreground-color (car args))
-                              default-frame-alist)
-                        args (cdr args))))
-             ((or (string= this "-bg") (string= this "-background"))
-              (if args
-                  (setq default-frame-alist
-                        (cons (cons 'background-color (car args))
-                              default-frame-alist)
-                        args (cdr args))))
-             (t (setq rest (cons this rest))))))
-    (nreverse rest)))
-
-(setq command-line-args (msdos-handle-args command-line-args))
-;; ---------------------------------------------------------------------------
+
+;;; arch-tag: 5cbdb455-b495-427b-95d0-e417d77d00b4
+;;; pc-win.el ends here