Add declarations for builds without X.
[bpt/emacs.git] / lisp / term / w32-win.el
CommitLineData
6a05d05f 1;;; w32-win.el --- parse switches controlling interface with W32 window system
2fe590dc 2
f2e3589a 3;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
12dc447f 4;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
ee78dc32
GV
5
6;; Author: Kevin Gallo
7;; Keywords: terminals
8
2fe590dc
EN
9;; This file is part of GNU Emacs.
10
1fecc8fe 11;; GNU Emacs is free software: you can redistribute it and/or modify
2fe590dc 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.
2fe590dc
EN
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/>.
ee78dc32
GV
23
24;;; Commentary:
25
b63f9ba1
GV
26;; w32-win.el: this file is loaded from ../lisp/startup.el when it recognizes
27;; that W32 windows are to be used. Command line switches are parsed and those
28;; pertaining to W32 are processed and removed from the command line. The
29;; W32 display is opened and hooks are set for popping up the initial window.
ee78dc32
GV
30
31;; startup.el will then examine startup files, and eventually call the hooks
32;; which create the first window (s).
33
34;;; Code:
35\f
36
37;; These are the standard X switches from the Xt Initialize.c file of
38;; Release 4.
39
40;; Command line Resource Manager string
41
42;; +rv *reverseVideo
43;; +synchronous *synchronous
44;; -background *background
45;; -bd *borderColor
46;; -bg *background
47;; -bordercolor *borderColor
48;; -borderwidth .borderWidth
49;; -bw .borderWidth
50;; -display .display
51;; -fg *foreground
52;; -fn *font
53;; -font *font
54;; -foreground *foreground
55;; -geometry .geometry
56;; -i .iconType
57;; -itype .iconType
58;; -iconic .iconic
59;; -name .name
60;; -reverse *reverseVideo
61;; -rv *reverseVideo
62;; -selectionTimeout .selectionTimeout
63;; -synchronous *synchronous
64;; -xrm
65
66;; An alist of X options and the function which handles them. See
67;; ../startup.el.
68
c60b74b4
JR
69;; (if (not (eq window-system 'w32))
70;; (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name)))
db95369b 71
ee78dc32
GV
72(require 'frame)
73(require 'mouse)
74(require 'scroll-bar)
75(require 'faces)
76(require 'select)
77(require 'menu-bar)
6bc52abc 78(require 'dnd)
729f1525 79(require 'w32-vars)
b0efcd2e 80
c6524989
JR
81;; Keep an obsolete alias for w32-focus-frame and w32-select-font in case
82;; they are used by code outside Emacs.
44fe0f65 83(define-obsolete-function-alias 'w32-focus-frame 'x-focus-frame "23.1")
c6524989 84(define-obsolete-function-alias 'w32-select-font 'x-select-font "23.1")
44fe0f65 85
b01f27a3 86(defvar xlfd-regexp-registry-subnum)
729f1525 87(defvar w32-color-map) ;; defined in w32fns.c
b01f27a3 88
73e6adaa 89(declare-function w32-send-sys-command "w32fns.c")
73e6adaa
DN
90(declare-function set-message-beep "w32console.c")
91
b05f815e 92;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
64f41d64
JR
93(if (fboundp 'new-fontset)
94 (require 'fontset))
ee78dc32 95
15f18b89 96;; The following definition is used for debugging scroll bar events.
fbd6baed 97;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
af99aa46 98
de0c7b5d
JR
99(defun w32-drag-n-drop-debug (event)
100 "Print the drag-n-drop EVENT in a readable form."
101 (interactive "e")
33b307f8
RS
102 (princ event))
103
104(defun w32-drag-n-drop (event)
de0c7b5d 105 "Edit the files listed in the drag-n-drop EVENT.
33b307f8
RS
106Switch to a buffer editing the last file dropped."
107 (interactive "e")
c8316112 108 (save-excursion
35a8911d
GM
109 ;; Make sure the drop target has positive co-ords
110 ;; before setting the selected frame - otherwise it
111 ;; won't work. <skx@tardis.ed.ac.uk>
112 (let* ((window (posn-window (event-start event)))
113 (coords (posn-x-y (event-start event)))
114 (x (car coords))
115 (y (cdr coords)))
116 (if (and (> x 0) (> y 0))
117 (set-frame-selected-window nil window))
f7ba2ff4 118 (mapc (lambda (file-name)
0cd80dfa
YM
119 (let ((f (subst-char-in-string ?\\ ?/ file-name))
120 (coding (or file-name-coding-system
121 default-file-name-coding-system)))
122 (setq file-name
123 (mapconcat 'url-hexify-string
124 (split-string (encode-coding-string f coding)
125 "/")
126 "/")))
5fd6d89f 127 (dnd-handle-one-url window 'private
6bc52abc 128 (concat "file:" file-name)))
1e8b532f 129 (car (cdr (cdr event)))))
35a8911d 130 (raise-frame)))
33b307f8
RS
131
132(defun w32-drag-n-drop-other-frame (event)
de0c7b5d 133 "Edit the files listed in the drag-n-drop EVENT, in other frames.
33b307f8
RS
134May create new frames, or reuse existing ones. The frame editing
135the last file dropped is selected."
136 (interactive "e")
137 (mapcar 'find-file-other-frame (car (cdr (cdr event)))))
138
139;; Bind the drag-n-drop event.
140(global-set-key [drag-n-drop] 'w32-drag-n-drop)
141(global-set-key [C-drag-n-drop] 'w32-drag-n-drop-other-frame)
142
a73c80a3
GV
143;; Keyboard layout/language change events
144;; For now ignore language-change events; in the future
145;; we should switch the Emacs Input Method to match the
146;; new layout/language selected by the user.
147(global-set-key [language-change] 'ignore)
148
aa360da1 149(defvar x-resource-name)
f2d9c15f 150(defvar x-colors)
aa360da1 151
ee78dc32 152\f
f795f633
EZ
153(defun xw-defined-colors (&optional frame)
154 "Internal function called by `defined-colors', which see."
ee78dc32 155 (or frame (setq frame (selected-frame)))
bd6a8278
SM
156 (let ((defined-colors nil))
157 (dolist (this-color (or (mapcar 'car w32-color-map) x-colors))
79b24da3 158 (and (color-supported-p this-color frame t)
aaa5e420 159 (setq defined-colors (cons this-color defined-colors))))
ee78dc32
GV
160 defined-colors))
161\f
162;;;; Function keys
163
7eb1e453
MB
164 ;;; make f10 activate the real menubar rather than the mini-buffer menu
165 ;;; navigation feature.
14f3467e 166 (defun w32-menu-bar-open (&optional frame)
7eb1e453
MB
167 "Start key navigation of the menu bar in FRAME.
168
14f3467e
JR
169This initially activates the first menu-bar item, and you can then navigate
170with the arrow keys, select a menu entry with the Return key or cancel with
171the Escape key. If FRAME has no menu bar, this function does nothing.
7eb1e453 172
14f3467e
JR
173If FRAME is nil or not given, use the selected frame.
174If FRAME does not have the menu bar enabled, display a text menu using
175`tmm-menubar'."
7eb1e453 176 (interactive "i")
14f3467e
JR
177 (if menu-bar-mode
178 (w32-send-sys-command ?\xf100 frame)
179 (with-selected-frame (or frame (selected-frame))
180 (tmm-menubar))))
ee78dc32 181\f
ee78dc32 182
4664455c
GV
183;; W32 systems have different fonts than commonly found on X, so
184;; we define our own standard fontset here.
185(defvar w32-standard-fontset-spec
e7a8ad1f 186 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
de0c7b5d
JR
187 "String of fontset spec of the standard fontset.
188This defines a fontset consisting of the Courier New variations for
189European languages which are distributed with Windows as
190\"Multilanguage Support\".
4664455c 191
885a56fe 192See the documentation of `create-fontset-from-fontset-spec' for the format.")
4664455c 193
ee78dc32 194(defun x-win-suspend-error ()
de0c7b5d
JR
195 "Report an error when a suspend is attempted."
196 (error "Suspending an Emacs running under W32 makes no sense"))
ee78dc32 197
aa360da1
GM
198(defvar image-library-alist)
199
fe347034
JB
200;;; Set default known names for image libraries
201(setq image-library-alist
72000816 202 '((xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll")
299db7f8
JB
203 (png "libpng12d.dll" "libpng12.dll" "libpng.dll"
204 ;; these are libpng 1.2.8 from GTK+
205 "libpng13d.dll" "libpng13.dll")
fe347034
JB
206 (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
207 (tiff "libtiff3.dll" "libtiff.dll")
44fe0f65
JR
208 (gif "giflib4.dll" "libungif4.dll" "libungif.dll")
209 (svg "librsvg-2-2.dll")
210 (gdk-pixbuf "libgdk_pixbuf-2.0-0.dll")
211 (glib "libglib-2.0-0.dll")))
fe347034 212
eacf409f
JR
213;;; multi-tty support
214(defvar w32-initialized nil
215 "Non-nil if the w32 window system has been initialized.")
216
aa360da1
GM
217(declare-function x-open-connection "w32fns.c"
218 (display &optional xrm-string must-succeed))
219
220(declare-function setup-default-fontset "fontset" ())
221(declare-function set-fontset-font "fontset.c"
222 (name target font-spec &optional frame add))
223(declare-function setup-default-fontset "fontset" ())
224(declare-function create-fontset-from-fontset-spec "fontset"
225 (fontset-spec &optional style-variant noerror))
226(declare-function create-fontset-from-x-resource "fontset" ())
227(declare-function x-get-resource "frame.c"
228 (attribute class &optional component subclass))
f2d9c15f
GM
229(declare-function x-handle-args "common-win" (args))
230(declare-function x-parse-geometry "frame.c" (string))
231(defvar x-command-line-resources)
aa360da1 232
c60b74b4
JR
233(defun w32-initialize-window-system ()
234 "Initialize Emacs for W32 GUI frames."
00954c67
JR
235
236 ;; Do the actual Windows setup here; the above code just defines
237 ;; functions and variables that we use now.
238
239 (setq command-line-args (x-handle-args command-line-args))
240
241 ;; Make sure we have a valid resource name.
242 (or (stringp x-resource-name)
243 (setq x-resource-name
244 ;; Change any . or * characters in x-resource-name to hyphens,
245 ;; so as not to choke when we use it in X resource queries.
246 (replace-regexp-in-string "[.*]" "-" (invocation-name))))
247
eacf409f
JR
248 (x-open-connection "" x-command-line-resources
249 ;; Exit with a fatal error if this fails and we
250 ;; are the initial display
251 (eq initial-window-system 'w32))
00954c67
JR
252
253 ;; Setup the default fontset.
254 (setup-default-fontset)
1adf362d
JR
255
256 ;; Enable Japanese fonts on Windows to be used by default.
70628e53 257 (set-fontset-font t (make-char 'katakana-jisx0201)
1adf362d 258 '("*" . "JISX0208-SJIS"))
70628e53 259 (set-fontset-font t (make-char 'latin-jisx0201)
1adf362d 260 '("*" . "JISX0208-SJIS"))
70628e53 261 (set-fontset-font t (make-char 'japanese-jisx0208)
1adf362d 262 '("*" . "JISX0208-SJIS"))
70628e53 263 (set-fontset-font t (make-char 'japanese-jisx0208-1978)
1adf362d
JR
264 '("*" . "JISX0208-SJIS"))
265
00954c67
JR
266 ;; Create the standard fontset.
267 (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
268 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
269 (create-fontset-from-x-resource)
00954c67
JR
270
271 ;; Apply a geometry resource to the initial frame. Put it at the end
272 ;; of the alist, so that anything specified on the command line takes
273 ;; precedence.
274 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
275 parsed)
276 (if res-geometry
277 (progn
278 (setq parsed (x-parse-geometry res-geometry))
279 ;; If the resource specifies a position,
280 ;; call the position and size "user-specified".
281 (if (or (assq 'top parsed) (assq 'left parsed))
282 (setq parsed (cons '(user-position . t)
283 (cons '(user-size . t) parsed))))
284 ;; All geometry parms apply to the initial frame.
285 (setq initial-frame-alist (append initial-frame-alist parsed))
286 ;; The size parms apply to all frames.
aaa5e420
JR
287 (if (and (assq 'height parsed)
288 (not (assq 'height default-frame-alist)))
289 (setq default-frame-alist
290 (cons (cons 'height (cdr (assq 'height parsed)))
291 default-frame-alist))
292 (if (and (assq 'width parsed)
293 (not (assq 'width default-frame-alist)))
294 (setq default-frame-alist
295 (cons (cons 'width (cdr (assq 'width parsed)))
296 default-frame-alist)))))))
00954c67 297
eacf409f
JR
298 ;; Check the reverseVideo resource.
299 (let ((case-fold-search t))
300 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
301 (if (and rv (string-match "^\\(true\\|yes\\|on\\)$" rv))
aaa5e420
JR
302 (setq default-frame-alist
303 (cons '(reverse . t) default-frame-alist)))))
eacf409f
JR
304
305 ;; Don't let Emacs suspend under w32 gui
00954c67
JR
306 (add-hook 'suspend-hook 'x-win-suspend-error)
307
308 ;; Turn off window-splitting optimization; w32 is usually fast enough
309 ;; that this is only annoying.
310 (setq split-window-keep-point t)
311
eacf409f
JR
312 ;; Turn on support for mouse wheels
313 (mouse-wheel-mode 1)
314
315 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
316 (menu-bar-enable-clipboard)
317
00954c67
JR
318 ;; Don't show the frame name; that's redundant.
319 (setq-default mode-line-frame-identification " ")
320
321 ;; Set to a system sound if you want a fancy bell.
322 (set-message-beep 'ok)
eacf409f 323 (setq w32-initialized t))
c60b74b4
JR
324
325(add-to-list 'handle-args-function-alist '(w32 . x-handle-args))
326(add-to-list 'frame-creation-function-alist '(w32 . x-create-frame-with-faces))
327(add-to-list 'window-system-initialization-alist '(w32 . w32-initialize-window-system))
328
329(provide 'w32-win)
fe347034 330
bd6a8278 331;; arch-tag: 69fb1701-28c2-4890-b351-3d1fe4b4f166
b63f9ba1 332;;; w32-win.el ends here