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