strftime: import from gnulib
[emacs.git] / lisp / term / w32-win.el
blob0ddf7b3e542eb4657effdb156eb00a7df4f4b221
1 ;;; w32-win.el --- parse switches controlling interface with W32 window system
3 ;; Copyright (C) 1993-1994, 2001-2011 Free Software Foundation, Inc.
5 ;; Author: Kevin Gallo
6 ;; Keywords: terminals
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; w32-win.el: this file is loaded from ../lisp/startup.el when it recognizes
26 ;; that W32 windows are to be used. Command line switches are parsed and those
27 ;; pertaining to W32 are processed and removed from the command line. The
28 ;; W32 display is opened and hooks are set for popping up the initial window.
30 ;; startup.el will then examine startup files, and eventually call the hooks
31 ;; which create the first window (s).
33 ;;; Code:
36 ;; These are the standard X switches from the Xt Initialize.c file of
37 ;; Release 4.
39 ;; Command line Resource Manager string
41 ;; +rv *reverseVideo
42 ;; +synchronous *synchronous
43 ;; -background *background
44 ;; -bd *borderColor
45 ;; -bg *background
46 ;; -bordercolor *borderColor
47 ;; -borderwidth .borderWidth
48 ;; -bw .borderWidth
49 ;; -display .display
50 ;; -fg *foreground
51 ;; -fn *font
52 ;; -font *font
53 ;; -foreground *foreground
54 ;; -geometry .geometry
55 ;; -i .iconType
56 ;; -itype .iconType
57 ;; -iconic .iconic
58 ;; -name .name
59 ;; -reverse *reverseVideo
60 ;; -rv *reverseVideo
61 ;; -selectionTimeout .selectionTimeout
62 ;; -synchronous *synchronous
63 ;; -xrm
65 ;; An alist of X options and the function which handles them. See
66 ;; ../startup.el.
68 ;; (if (not (eq window-system 'w32))
69 ;; (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name)))
71 (require 'frame)
72 (require 'mouse)
73 (require 'scroll-bar)
74 (require 'faces)
75 (require 'select)
76 (require 'menu-bar)
77 (require 'dnd)
78 (require 'w32-vars)
80 ;; Keep an obsolete alias for w32-focus-frame and w32-select-font in case
81 ;; they are used by code outside Emacs.
82 (define-obsolete-function-alias 'w32-focus-frame 'x-focus-frame "23.1")
83 (declare-function x-select-font "w32font.c"
84 (&optional frame exclude-proportional))
85 (define-obsolete-function-alias 'w32-select-font 'x-select-font "23.1")
87 (defvar w32-color-map) ;; defined in w32fns.c
89 (declare-function w32-send-sys-command "w32fns.c")
90 (declare-function set-message-beep "w32console.c")
92 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
93 (if (fboundp 'new-fontset)
94 (require 'fontset))
96 ;; The following definition is used for debugging scroll bar events.
97 ;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
99 ;; (defun w32-drag-n-drop-debug (event)
100 ;; "Print the drag-n-drop EVENT in a readable form."
101 ;; (interactive "e")
102 ;; (princ event))
104 (defun w32-drag-n-drop (event)
105 "Edit the files listed in the drag-n-drop EVENT.
106 Switch to a buffer editing the last file dropped."
107 (interactive "e")
108 (save-excursion
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))
118 (mapc (lambda (file-name)
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 "/")))
127 (dnd-handle-one-url window 'private
128 (concat "file:" file-name)))
129 (car (cdr (cdr event)))))
130 (raise-frame)))
132 (defun w32-drag-n-drop-other-frame (event)
133 "Edit the files listed in the drag-n-drop EVENT, in other frames.
134 May create new frames, or reuse existing ones. The frame editing
135 the last file dropped is selected."
136 (interactive "e")
137 (mapcar 'find-file-other-frame (car (cdr (cdr event)))))
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)
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)
149 (defvar x-resource-name)
152 ;;;; Function keys
154 ;;; make f10 activate the real menubar rather than the mini-buffer menu
155 ;;; navigation feature.
156 (defun w32-menu-bar-open (&optional frame)
157 "Start key navigation of the menu bar in FRAME.
159 This initially activates the first menu-bar item, and you can then navigate
160 with the arrow keys, select a menu entry with the Return key or cancel with
161 the Escape key. If FRAME has no menu bar, this function does nothing.
163 If FRAME is nil or not given, use the selected frame.
164 If FRAME does not have the menu bar enabled, display a text menu using
165 `tmm-menubar'."
166 (interactive "i")
167 (if menu-bar-mode
168 (w32-send-sys-command ?\xf100 frame)
169 (with-selected-frame (or frame (selected-frame))
170 (tmm-menubar))))
173 ;; W32 systems have different fonts than commonly found on X, so
174 ;; we define our own standard fontset here.
175 (defvar w32-standard-fontset-spec
176 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
177 "String of fontset spec of the standard fontset.
178 This defines a fontset consisting of the Courier New variations for
179 European languages which are distributed with Windows as
180 \"Multilanguage Support\".
182 See the documentation of `create-fontset-from-fontset-spec' for the format.")
184 (defun x-win-suspend-error ()
185 "Report an error when a suspend is attempted."
186 (error "Suspending an Emacs running under W32 makes no sense"))
188 (defvar dynamic-library-alist)
190 ;;; Set default known names for external libraries
191 (setq dynamic-library-alist
192 (list
193 '(xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll")
194 ;; Versions of libpng 1.4.x and later are incompatible with
195 ;; earlier versions. Set up the list of libraries according to
196 ;; the version we were compiled against. (If we were compiled
197 ;; without PNG support, libpng-version's value is -1.)
198 (if (>= libpng-version 10400)
199 ;; libpng14-14.dll is libpng 1.4.3 from GTK+
200 '(png "libpng14-14.dll" "libpng14.dll")
201 '(png "libpng12d.dll" "libpng12.dll" "libpng3.dll" "libpng.dll"
202 ;; these are libpng 1.2.8 from GTK+
203 "libpng13d.dll" "libpng13.dll"))
204 '(jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
205 '(tiff "libtiff3.dll" "libtiff.dll")
206 '(gif "giflib4.dll" "libungif4.dll" "libungif.dll")
207 '(svg "librsvg-2-2.dll")
208 '(gdk-pixbuf "libgdk_pixbuf-2.0-0.dll")
209 '(glib "libglib-2.0-0.dll")
210 '(gobject "libgobject-2.0-0.dll")))
212 ;;; multi-tty support
213 (defvar w32-initialized nil
214 "Non-nil if the w32 window system has been initialized.")
216 (declare-function x-open-connection "w32fns.c"
217 (display &optional xrm-string must-succeed))
218 (declare-function create-fontset-from-fontset-spec "fontset"
219 (fontset-spec &optional style-variant noerror))
220 (declare-function create-fontset-from-x-resource "fontset" ())
221 (declare-function x-get-resource "frame.c"
222 (attribute class &optional component subclass))
223 (declare-function x-handle-args "common-win" (args))
224 (declare-function x-parse-geometry "frame.c" (string))
225 (defvar x-command-line-resources)
227 (defun w32-initialize-window-system ()
228 "Initialize Emacs for W32 GUI frames."
230 ;; Do the actual Windows setup here; the above code just defines
231 ;; functions and variables that we use now.
233 (setq command-line-args (x-handle-args command-line-args))
235 ;; Make sure we have a valid resource name.
236 (or (stringp x-resource-name)
237 (setq x-resource-name
238 ;; Change any . or * characters in x-resource-name to hyphens,
239 ;; so as not to choke when we use it in X resource queries.
240 (replace-regexp-in-string "[.*]" "-" (invocation-name))))
242 (x-open-connection "" x-command-line-resources
243 ;; Exit with a fatal error if this fails and we
244 ;; are the initial display
245 (eq initial-window-system 'w32))
247 ;; Create the default fontset.
248 (create-default-fontset)
249 ;; Create the standard fontset.
250 (condition-case err
251 (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
252 (error (display-warning
253 'initialization
254 (format "Creation of the standard fontset failed: %s" err)
255 :error)))
256 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
257 (create-fontset-from-x-resource)
259 ;; Apply a geometry resource to the initial frame. Put it at the end
260 ;; of the alist, so that anything specified on the command line takes
261 ;; precedence.
262 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
263 parsed)
264 (if res-geometry
265 (progn
266 (setq parsed (x-parse-geometry res-geometry))
267 ;; If the resource specifies a position,
268 ;; call the position and size "user-specified".
269 (if (or (assq 'top parsed) (assq 'left parsed))
270 (setq parsed (cons '(user-position . t)
271 (cons '(user-size . t) parsed))))
272 ;; All geometry parms apply to the initial frame.
273 (setq initial-frame-alist (append initial-frame-alist parsed))
274 ;; The size parms apply to all frames.
275 (if (and (assq 'height parsed)
276 (not (assq 'height default-frame-alist)))
277 (setq default-frame-alist
278 (cons (cons 'height (cdr (assq 'height parsed)))
279 default-frame-alist))
280 (if (and (assq 'width parsed)
281 (not (assq 'width default-frame-alist)))
282 (setq default-frame-alist
283 (cons (cons 'width (cdr (assq 'width parsed)))
284 default-frame-alist)))))))
286 ;; Check the reverseVideo resource.
287 (let ((case-fold-search t))
288 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
289 (if (and rv (string-match "^\\(true\\|yes\\|on\\)$" rv))
290 (setq default-frame-alist
291 (cons '(reverse . t) default-frame-alist)))))
293 ;; Don't let Emacs suspend under w32 gui
294 (add-hook 'suspend-hook 'x-win-suspend-error)
296 ;; Turn off window-splitting optimization; w32 is usually fast enough
297 ;; that this is only annoying.
298 (setq split-window-keep-point t)
300 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
301 (menu-bar-enable-clipboard)
303 ;; Don't show the frame name; that's redundant.
304 (setq-default mode-line-frame-identification " ")
306 ;; Set to a system sound if you want a fancy bell.
307 (set-message-beep 'ok)
308 (setq w32-initialized t))
310 (add-to-list 'handle-args-function-alist '(w32 . x-handle-args))
311 (add-to-list 'frame-creation-function-alist '(w32 . x-create-frame-with-faces))
312 (add-to-list 'window-system-initialization-alist '(w32 . w32-initialize-window-system))
314 (provide 'w32-win)
316 ;;; w32-win.el ends here