1 ;;; w32-win.el --- parse switches controlling interface with W32 window system
3 ;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
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.
31 ;; startup.el will then examine startup files, and eventually call the hooks
32 ;; which create the first window (s).
37 ;; These are the standard X switches from the Xt Initialize.c file of
40 ;; Command line Resource Manager string
43 ;; +synchronous *synchronous
44 ;; -background *background
47 ;; -bordercolor *borderColor
48 ;; -borderwidth .borderWidth
54 ;; -foreground *foreground
55 ;; -geometry .geometry
60 ;; -reverse *reverseVideo
62 ;; -selectionTimeout .selectionTimeout
63 ;; -synchronous *synchronous
66 ;; An alist of X options and the function which handles them. See
69 ;; (if (not (eq window-system 'w32))
70 ;; (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name)))
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")
88 (defvar w32-color-map
) ;; defined in w32fns.c
90 (declare-function w32-send-sys-command
"w32fns.c")
91 (declare-function set-message-beep
"w32console.c")
93 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
94 (if (fboundp 'new-fontset
)
97 ;; The following definition is used for debugging scroll bar events.
98 ;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
100 ;; (defun w32-drag-n-drop-debug (event)
101 ;; "Print the drag-n-drop EVENT in a readable form."
105 (defun w32-drag-n-drop (event)
106 "Edit the files listed in the drag-n-drop EVENT.
107 Switch to a buffer editing the last file dropped."
110 ;; Make sure the drop target has positive co-ords
111 ;; before setting the selected frame - otherwise it
112 ;; won't work. <skx@tardis.ed.ac.uk>
113 (let* ((window (posn-window (event-start event
)))
114 (coords (posn-x-y (event-start event
)))
117 (if (and (> x
0) (> y
0))
118 (set-frame-selected-window nil window
))
119 (mapc (lambda (file-name)
120 (let ((f (subst-char-in-string ?
\\ ?
/ file-name
))
121 (coding (or file-name-coding-system
122 default-file-name-coding-system
)))
124 (mapconcat 'url-hexify-string
125 (split-string (encode-coding-string f coding
)
128 (dnd-handle-one-url window
'private
129 (concat "file:" file-name
)))
130 (car (cdr (cdr event
)))))
133 (defun w32-drag-n-drop-other-frame (event)
134 "Edit the files listed in the drag-n-drop EVENT, in other frames.
135 May create new frames, or reuse existing ones. The frame editing
136 the last file dropped is selected."
138 (mapcar 'find-file-other-frame
(car (cdr (cdr event
)))))
140 ;; Bind the drag-n-drop event.
141 (global-set-key [drag-n-drop
] 'w32-drag-n-drop
)
142 (global-set-key [C-drag-n-drop
] 'w32-drag-n-drop-other-frame
)
144 ;; Keyboard layout/language change events
145 ;; For now ignore language-change events; in the future
146 ;; we should switch the Emacs Input Method to match the
147 ;; new layout/language selected by the user.
148 (global-set-key [language-change
] 'ignore
)
150 (defvar x-resource-name
)
154 (defun xw-defined-colors (&optional frame
)
155 "Internal function called by `defined-colors', which see."
156 (or frame
(setq frame
(selected-frame)))
157 (let ((defined-colors nil
))
158 (dolist (this-color (or (mapcar 'car w32-color-map
) x-colors
))
159 (and (color-supported-p this-color frame t
)
160 (setq defined-colors
(cons this-color defined-colors
))))
165 ;;; make f10 activate the real menubar rather than the mini-buffer menu
166 ;;; navigation feature.
167 (defun w32-menu-bar-open (&optional frame
)
168 "Start key navigation of the menu bar in FRAME.
170 This initially activates the first menu-bar item, and you can then navigate
171 with the arrow keys, select a menu entry with the Return key or cancel with
172 the Escape key. If FRAME has no menu bar, this function does nothing.
174 If FRAME is nil or not given, use the selected frame.
175 If FRAME does not have the menu bar enabled, display a text menu using
179 (w32-send-sys-command ?
\xf100 frame
)
180 (with-selected-frame (or frame
(selected-frame))
184 ;; W32 systems have different fonts than commonly found on X, so
185 ;; we define our own standard fontset here.
186 (defvar w32-standard-fontset-spec
187 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
188 "String of fontset spec of the standard fontset.
189 This defines a fontset consisting of the Courier New variations for
190 European languages which are distributed with Windows as
191 \"Multilanguage Support\".
193 See the documentation of `create-fontset-from-fontset-spec' for the format.")
195 (defun x-win-suspend-error ()
196 "Report an error when a suspend is attempted."
197 (error "Suspending an Emacs running under W32 makes no sense"))
199 (defvar image-library-alist
)
201 ;;; Set default known names for image libraries
202 (setq image-library-alist
204 '(xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll")
205 ;; Versions of libpng 1.4.x and later are incompatible with
206 ;; earlier versions. Set up the list of libraries according to
207 ;; the version we were compiled against. (If we were compiled
208 ;; without PNG support, libpng-version's value is -1.)
209 (if (>= libpng-version
10400)
210 ;; libpng14-14.dll is libpng 1.4.3 from GTK+
211 '(png "libpng14-14.dll" "libpng14.dll")
212 '(png "libpng12d.dll" "libpng12.dll" "libpng3.dll" "libpng.dll"
213 ;; these are libpng 1.2.8 from GTK+
214 "libpng13d.dll" "libpng13.dll"))
215 '(jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
216 '(tiff "libtiff3.dll" "libtiff.dll")
217 '(gif "giflib4.dll" "libungif4.dll" "libungif.dll")
218 '(svg "librsvg-2-2.dll")
219 '(gdk-pixbuf "libgdk_pixbuf-2.0-0.dll")
220 '(glib "libglib-2.0-0.dll")
221 '(gobject "libgobject-2.0-0.dll")))
223 ;;; multi-tty support
224 (defvar w32-initialized nil
225 "Non-nil if the w32 window system has been initialized.")
227 (declare-function x-open-connection
"w32fns.c"
228 (display &optional xrm-string must-succeed
))
229 (declare-function create-fontset-from-fontset-spec
"fontset"
230 (fontset-spec &optional style-variant noerror
))
231 (declare-function create-fontset-from-x-resource
"fontset" ())
232 (declare-function x-get-resource
"frame.c"
233 (attribute class
&optional component subclass
))
234 (declare-function x-handle-args
"common-win" (args))
235 (declare-function x-parse-geometry
"frame.c" (string))
236 (defvar x-command-line-resources
)
238 (defun w32-initialize-window-system ()
239 "Initialize Emacs for W32 GUI frames."
241 ;; Do the actual Windows setup here; the above code just defines
242 ;; functions and variables that we use now.
244 (setq command-line-args
(x-handle-args command-line-args
))
246 ;; Make sure we have a valid resource name.
247 (or (stringp x-resource-name
)
248 (setq x-resource-name
249 ;; Change any . or * characters in x-resource-name to hyphens,
250 ;; so as not to choke when we use it in X resource queries.
251 (replace-regexp-in-string "[.*]" "-" (invocation-name))))
253 (x-open-connection "" x-command-line-resources
254 ;; Exit with a fatal error if this fails and we
255 ;; are the initial display
256 (eq initial-window-system
'w32
))
258 ;; Create the default fontset.
259 (create-default-fontset)
260 ;; Create the standard fontset.
262 (create-fontset-from-fontset-spec w32-standard-fontset-spec t
)
263 (error (display-warning
265 (format "Creation of the standard fontset failed: %s" err
)
267 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
268 (create-fontset-from-x-resource)
270 ;; Apply a geometry resource to the initial frame. Put it at the end
271 ;; of the alist, so that anything specified on the command line takes
273 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
277 (setq parsed
(x-parse-geometry res-geometry
))
278 ;; If the resource specifies a position,
279 ;; call the position and size "user-specified".
280 (if (or (assq 'top parsed
) (assq 'left parsed
))
281 (setq parsed
(cons '(user-position . t
)
282 (cons '(user-size . t
) parsed
))))
283 ;; All geometry parms apply to the initial frame.
284 (setq initial-frame-alist
(append initial-frame-alist parsed
))
285 ;; The size parms apply to all frames.
286 (if (and (assq 'height parsed
)
287 (not (assq 'height default-frame-alist
)))
288 (setq default-frame-alist
289 (cons (cons 'height
(cdr (assq 'height parsed
)))
290 default-frame-alist
))
291 (if (and (assq 'width parsed
)
292 (not (assq 'width default-frame-alist
)))
293 (setq default-frame-alist
294 (cons (cons 'width
(cdr (assq 'width parsed
)))
295 default-frame-alist
)))))))
297 ;; Check the reverseVideo resource.
298 (let ((case-fold-search t
))
299 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
300 (if (and rv
(string-match "^\\(true\\|yes\\|on\\)$" rv
))
301 (setq default-frame-alist
302 (cons '(reverse . t
) default-frame-alist
)))))
304 ;; Don't let Emacs suspend under w32 gui
305 (add-hook 'suspend-hook
'x-win-suspend-error
)
307 ;; Turn off window-splitting optimization; w32 is usually fast enough
308 ;; that this is only annoying.
309 (setq split-window-keep-point t
)
311 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
312 (menu-bar-enable-clipboard)
314 ;; Don't show the frame name; that's redundant.
315 (setq-default mode-line-frame-identification
" ")
317 ;; Set to a system sound if you want a fancy bell.
318 (set-message-beep 'ok
)
319 (setq w32-initialized t
))
321 (add-to-list 'handle-args-function-alist
'(w32 . x-handle-args
))
322 (add-to-list 'frame-creation-function-alist
'(w32 . x-create-frame-with-faces
))
323 (add-to-list 'window-system-initialization-alist
'(w32 . w32-initialize-window-system
))
327 ;; arch-tag: 69fb1701-28c2-4890-b351-3d1fe4b4f166
328 ;;; w32-win.el ends here