Contents in 1999-06-04-13 of release-21-2.
[chise/xemacs-chise.git.1] / lisp / device.el
1 ;;; device.el --- miscellaneous device functions not written in C
2
3 ;; Copyright (C) 1994-5, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996 Ben Wing
5
6 ;; Maintainer: XEmacs Development Team
7 ;; Keywords: internal, dumped
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING.  If not, write to the 
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Synched up with: Not in FSF.
27
28 ;;; Commentary:
29
30 ;; This file is dumped with XEmacs.
31
32 ;;; Code:
33
34 (defun device-list ()
35   "Return a list of all devices."
36   (apply 'nconc (mapcar 'console-device-list (console-list))))
37
38 (defun device-type (&optional device)
39   "Return the type of the specified device (e.g. `x' or `tty').
40 This is equivalent to the type of the device's console.
41 Value is `tty' for a tty device (a character-only terminal),
42 `x' for a device that is a screen on an X display,
43 `ns' for a device that is a NeXTstep connection (not yet implemented),
44 `mswindows' for a device that is a Windows or Windows NT connection,
45 `pc' for a device that is a direct-write MS-DOS screen (not yet implemented),
46 `stream' for a stream device (which acts like a stdio stream), and
47 `dead' for a deleted device."
48   (or device (setq device (selected-device)))
49   (if (not (device-live-p device)) 'dead
50     (console-type (device-console device))))
51
52 (defun make-tty-device (&optional tty terminal-type controlling-process)
53   "Create a new device on TTY.
54   TTY should be the name of a tty device file (e.g. \"/dev/ttyp3\" under
55 SunOS et al.), as returned by the `tty' command.  A value of nil means
56 use the stdin and stdout as passed to XEmacs from the shell.
57   If TERMINAL-TYPE is non-nil, it should be a string specifying the
58 type of the terminal attached to the specified tty.  If it is nil,
59 the terminal type will be inferred from the TERM environment variable.
60   If CONTROLLING-PROCESS is non-nil, it should be an integer
61 specifying the process id of the process in control of the specified tty.  If
62 it is nil, it is assumes to be the value returned by emacs-pid."
63   (make-device 'tty tty (list 'terminal-type terminal-type 
64                               'controlling-process controlling-process)))
65
66 (defun device-pixel-width (&optional device)
67   "Return the width in pixels of DEVICE, or nil if unknown."
68   (let ((ds (device-system-metric device 'size-device)))
69     (and ds (car ds))))
70
71 (defun device-pixel-height (&optional device)
72   "Return the height in pixels of DEVICE, or nil if unknown."
73   (let ((ds (device-system-metric device 'size-device)))
74     (and ds (cdr ds))))
75
76 (defun device-mm-width (&optional device)
77   "Return the width in millimeters of DEVICE, or nil if unknown."
78   (let ((ds (device-system-metric device 'size-device-mm)))
79     (and ds (car ds))))
80
81 (defun device-mm-height (&optional device)
82   "Return the height in millimeters of DEVICE, or nil if unknown."
83   (let ((ds (device-system-metric device 'size-device-mm)))
84     (and ds (cdr ds))))
85
86 (defun device-bitplanes (&optional device)
87   "Return the number of bitplanes of DEVICE, or nil if unknown."
88   (device-system-metric device 'num-bit-planes))
89
90 (defun device-color-cells (&optional device)
91   "Return the number of color cells of DEVICE, or nil if unknown."
92   (device-system-metric device 'num-color-cells))
93
94 (defun make-x-device (&optional display)
95   "Create a new device connected to DISPLAY."
96   (make-device 'x display))
97
98 (defun make-mswindows-device ()
99   "Create a new mswindows device."
100   (make-device 'mswindows nil))
101
102 (defun device-on-window-system-p (&optional device)
103   "Return non-nil if DEVICE is on a window system.
104 This generally means that there is support for the mouse, the menubar,
105 the toolbar, glyphs, etc."
106   (or device (setq device (selected-device)))
107   (console-on-window-system-p (device-console device)))
108
109 (defun call-device-method (name device &rest args)
110   "Call a DEVICE-specific function with the generic name NAME.
111 If DEVICE is not provide the selected device is used."
112   (or device (setq device (selected-device)))
113   (or (symbolp name) (error "function name must be a symbol"))
114   (let ((devmeth (intern (concat (symbol-name 
115                                   (device-type device)) "-" (symbol-name name)))))
116     (if (functionp devmeth)
117         (if args
118             (apply devmeth args)
119           (funcall devmeth))
120       nil)))
121
122 (defmacro define-device-method (name &optional docstring)
123   "Define NAME to be a device method."
124   `(defun ,name (&rest arglist) ,docstring
125      (apply 'call-device-method (quote ,name) nil arglist)))
126
127 (defmacro define-device-method* (name &optional docstring)
128   "Define NAME to be a device method."
129   `(defun* ,name (&rest arglist) ,docstring
130      (apply 'call-device-method (quote ,name) nil arglist)))
131
132 (defalias 'valid-device-type-p 'valid-console-type-p)
133 (defalias 'device-type-list 'console-type-list)
134 (defalias 'device-pixel-depth 'device-bitplanes)
135
136 ;;; device.el ends here