w32-win.el 12 KB

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