| 1 | ;;; w32-win.el --- parse switches controlling interface with W32 window system. |
| 2 | |
| 3 | ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
| 4 | |
| 5 | ;; Author: Kevin Gallo |
| 6 | ;; Keywords: terminals |
| 7 | |
| 8 | ;; This file is part of GNU Emacs. |
| 9 | |
| 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 2, or (at your option) |
| 13 | ;; any later version. |
| 14 | |
| 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. |
| 19 | |
| 20 | ;; You should have received a copy of the GNU General Public License |
| 21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | ;; Boston, MA 02111-1307, USA. |
| 24 | |
| 25 | ;;; Commentary: |
| 26 | |
| 27 | ;; w32-win.el: this file is loaded from ../lisp/startup.el when it recognizes |
| 28 | ;; that W32 windows are to be used. Command line switches are parsed and those |
| 29 | ;; pertaining to W32 are processed and removed from the command line. The |
| 30 | ;; W32 display is opened and hooks are set for popping up the initial window. |
| 31 | |
| 32 | ;; startup.el will then examine startup files, and eventually call the hooks |
| 33 | ;; which create the first window (s). |
| 34 | |
| 35 | ;;; Code: |
| 36 | \f |
| 37 | |
| 38 | ;; These are the standard X switches from the Xt Initialize.c file of |
| 39 | ;; Release 4. |
| 40 | |
| 41 | ;; Command line Resource Manager string |
| 42 | |
| 43 | ;; +rv *reverseVideo |
| 44 | ;; +synchronous *synchronous |
| 45 | ;; -background *background |
| 46 | ;; -bd *borderColor |
| 47 | ;; -bg *background |
| 48 | ;; -bordercolor *borderColor |
| 49 | ;; -borderwidth .borderWidth |
| 50 | ;; -bw .borderWidth |
| 51 | ;; -display .display |
| 52 | ;; -fg *foreground |
| 53 | ;; -fn *font |
| 54 | ;; -font *font |
| 55 | ;; -foreground *foreground |
| 56 | ;; -geometry .geometry |
| 57 | ;; -i .iconType |
| 58 | ;; -itype .iconType |
| 59 | ;; -iconic .iconic |
| 60 | ;; -name .name |
| 61 | ;; -reverse *reverseVideo |
| 62 | ;; -rv *reverseVideo |
| 63 | ;; -selectionTimeout .selectionTimeout |
| 64 | ;; -synchronous *synchronous |
| 65 | ;; -xrm |
| 66 | |
| 67 | ;; An alist of X options and the function which handles them. See |
| 68 | ;; ../startup.el. |
| 69 | |
| 70 | (if (not (eq window-system 'w32)) |
| 71 | (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name))) |
| 72 | |
| 73 | (require 'frame) |
| 74 | (require 'mouse) |
| 75 | (require 'scroll-bar) |
| 76 | (require 'faces) |
| 77 | (require 'select) |
| 78 | (require 'menu-bar) |
| 79 | (if (fboundp 'new-fontset) |
| 80 | (require 'fontset)) |
| 81 | |
| 82 | ;; Because Windows scrollbars look and act quite differently compared |
| 83 | ;; with the standard X scroll-bars, we don't try to use the normal |
| 84 | ;; scroll bar routines. |
| 85 | |
| 86 | (defun w32-handle-scroll-bar-event (event) |
| 87 | "Handle W32 scroll bar events to do normal Window style scrolling." |
| 88 | (interactive "e") |
| 89 | (let ((old-window (selected-window))) |
| 90 | (unwind-protect |
| 91 | (let* ((position (event-start event)) |
| 92 | (window (nth 0 position)) |
| 93 | (portion-whole (nth 2 position)) |
| 94 | (bar-part (nth 4 position))) |
| 95 | (save-excursion |
| 96 | (select-window window) |
| 97 | (cond |
| 98 | ((eq bar-part 'up) |
| 99 | (goto-char (window-start window)) |
| 100 | (scroll-down 1)) |
| 101 | ((eq bar-part 'above-handle) |
| 102 | (scroll-down)) |
| 103 | ((eq bar-part 'handle) |
| 104 | (scroll-bar-maybe-set-window-start event)) |
| 105 | ((eq bar-part 'below-handle) |
| 106 | (scroll-up)) |
| 107 | ((eq bar-part 'down) |
| 108 | (goto-char (window-start window)) |
| 109 | (scroll-up 1)) |
| 110 | ))) |
| 111 | (select-window old-window)))) |
| 112 | |
| 113 | ;; The following definition is used for debugging. |
| 114 | ;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event)) |
| 115 | |
| 116 | (global-set-key [vertical-scroll-bar mouse-1] 'w32-handle-scroll-bar-event) |
| 117 | |
| 118 | ;; (scroll-bar-mode nil) |
| 119 | |
| 120 | (defvar mouse-wheel-scroll-amount 4 |
| 121 | "*Number of lines to scroll per click of the mouse wheel.") |
| 122 | |
| 123 | (defun mouse-wheel-scroll-line (event) |
| 124 | "Scroll the current buffer by `mouse-wheel-scroll-amount'." |
| 125 | (interactive "e") |
| 126 | (condition-case nil |
| 127 | (if (< (car (cdr (cdr event))) 0) |
| 128 | (scroll-up mouse-wheel-scroll-amount) |
| 129 | (scroll-down mouse-wheel-scroll-amount)) |
| 130 | (error nil))) |
| 131 | |
| 132 | ;; for scroll-in-place.el, this way the -scroll-line and -scroll-screen |
| 133 | ;; commands won't interact |
| 134 | (setq scroll-command-groups (list '(mouse-wheel-scroll-line))) |
| 135 | |
| 136 | (defun mouse-wheel-scroll-screen (event) |
| 137 | "Scroll the current buffer by `mouse-wheel-scroll-amount'." |
| 138 | (interactive "e") |
| 139 | (condition-case nil |
| 140 | (if (< (car (cdr (cdr event))) 0) |
| 141 | (scroll-up) |
| 142 | (scroll-down)) |
| 143 | (error nil))) |
| 144 | |
| 145 | ;; Bind the mouse-wheel event: |
| 146 | (global-set-key [mouse-wheel] 'mouse-wheel-scroll-line) |
| 147 | (global-set-key [C-mouse-wheel] 'mouse-wheel-scroll-screen) |
| 148 | |
| 149 | (defun w32-drag-n-drop-debug (event) |
| 150 | "Print the drag-n-drop event in a readable form." |
| 151 | (interactive "e") |
| 152 | (princ event)) |
| 153 | |
| 154 | (defun w32-drag-n-drop (event) |
| 155 | "Edit the files listed in the drag-n-drop event. |
| 156 | Switch to a buffer editing the last file dropped." |
| 157 | (interactive "e") |
| 158 | (save-excursion |
| 159 | (set-frame-selected-window nil (posn-window (event-start event))) |
| 160 | (mapcar 'find-file (car (cdr (cdr event))))) |
| 161 | (raise-frame)) |
| 162 | |
| 163 | (defun w32-drag-n-drop-other-frame (event) |
| 164 | "Edit the files listed in the drag-n-drop event, in other frames. |
| 165 | May create new frames, or reuse existing ones. The frame editing |
| 166 | the last file dropped is selected." |
| 167 | (interactive "e") |
| 168 | (mapcar 'find-file-other-frame (car (cdr (cdr event))))) |
| 169 | |
| 170 | ;; Bind the drag-n-drop event. |
| 171 | (global-set-key [drag-n-drop] 'w32-drag-n-drop) |
| 172 | (global-set-key [C-drag-n-drop] 'w32-drag-n-drop-other-frame) |
| 173 | |
| 174 | ;; Keyboard layout/language change events |
| 175 | ;; For now ignore language-change events; in the future |
| 176 | ;; we should switch the Emacs Input Method to match the |
| 177 | ;; new layout/language selected by the user. |
| 178 | (global-set-key [language-change] 'ignore) |
| 179 | |
| 180 | (defvar x-invocation-args) |
| 181 | |
| 182 | (defvar x-command-line-resources nil) |
| 183 | |
| 184 | (defconst x-option-alist |
| 185 | '(("-bw" . x-handle-numeric-switch) |
| 186 | ("-d" . x-handle-display) |
| 187 | ("-display" . x-handle-display) |
| 188 | ("-name" . x-handle-name-rn-switch) |
| 189 | ("-rn" . x-handle-name-rn-switch) |
| 190 | ("-T" . x-handle-switch) |
| 191 | ("-r" . x-handle-switch) |
| 192 | ("-rv" . x-handle-switch) |
| 193 | ("-reverse" . x-handle-switch) |
| 194 | ("-fn" . x-handle-switch) |
| 195 | ("-font" . x-handle-switch) |
| 196 | ("-ib" . x-handle-numeric-switch) |
| 197 | ("-g" . x-handle-geometry) |
| 198 | ("-geometry" . x-handle-geometry) |
| 199 | ("-fg" . x-handle-switch) |
| 200 | ("-foreground". x-handle-switch) |
| 201 | ("-bg" . x-handle-switch) |
| 202 | ("-background". x-handle-switch) |
| 203 | ("-ms" . x-handle-switch) |
| 204 | ("-itype" . x-handle-switch) |
| 205 | ("-i" . x-handle-switch) |
| 206 | ("-iconic" . x-handle-iconic) |
| 207 | ("-xrm" . x-handle-xrm-switch) |
| 208 | ("-cr" . x-handle-switch) |
| 209 | ("-vb" . x-handle-switch) |
| 210 | ("-hb" . x-handle-switch) |
| 211 | ("-bd" . x-handle-switch))) |
| 212 | |
| 213 | (defconst x-long-option-alist |
| 214 | '(("--border-width" . "-bw") |
| 215 | ("--display" . "-d") |
| 216 | ("--name" . "-name") |
| 217 | ("--title" . "-T") |
| 218 | ("--reverse-video" . "-reverse") |
| 219 | ("--font" . "-font") |
| 220 | ("--internal-border" . "-ib") |
| 221 | ("--geometry" . "-geometry") |
| 222 | ("--foreground-color" . "-fg") |
| 223 | ("--background-color" . "-bg") |
| 224 | ("--mouse-color" . "-ms") |
| 225 | ("--icon-type" . "-itype") |
| 226 | ("--iconic" . "-iconic") |
| 227 | ("--xrm" . "-xrm") |
| 228 | ("--cursor-color" . "-cr") |
| 229 | ("--vertical-scroll-bars" . "-vb") |
| 230 | ("--border-color" . "-bd"))) |
| 231 | |
| 232 | (defconst x-switch-definitions |
| 233 | '(("-name" name) |
| 234 | ("-T" name) |
| 235 | ("-r" reverse t) |
| 236 | ("-rv" reverse t) |
| 237 | ("-reverse" reverse t) |
| 238 | ("-fn" font) |
| 239 | ("-font" font) |
| 240 | ("-ib" internal-border-width) |
| 241 | ("-fg" foreground-color) |
| 242 | ("-foreground" foreground-color) |
| 243 | ("-bg" background-color) |
| 244 | ("-background" background-color) |
| 245 | ("-ms" mouse-color) |
| 246 | ("-cr" cursor-color) |
| 247 | ("-itype" icon-type t) |
| 248 | ("-i" icon-type t) |
| 249 | ("-vb" vertical-scroll-bars t) |
| 250 | ("-hb" horizontal-scroll-bars t) |
| 251 | ("-bd" border-color) |
| 252 | ("-bw" border-width))) |
| 253 | |
| 254 | ;; Handler for switches of the form "-switch value" or "-switch". |
| 255 | (defun x-handle-switch (switch) |
| 256 | (let ((aelt (assoc switch x-switch-definitions))) |
| 257 | (if aelt |
| 258 | (if (nth 2 aelt) |
| 259 | (setq default-frame-alist |
| 260 | (cons (cons (nth 1 aelt) (nth 2 aelt)) |
| 261 | default-frame-alist)) |
| 262 | (setq default-frame-alist |
| 263 | (cons (cons (nth 1 aelt) |
| 264 | (car x-invocation-args)) |
| 265 | default-frame-alist) |
| 266 | x-invocation-args (cdr x-invocation-args)))))) |
| 267 | |
| 268 | ;; Make -iconic apply only to the initial frame! |
| 269 | (defun x-handle-iconic (switch) |
| 270 | (setq initial-frame-alist |
| 271 | (cons '(visibility . icon) initial-frame-alist))) |
| 272 | |
| 273 | ;; Handler for switches of the form "-switch n" |
| 274 | (defun x-handle-numeric-switch (switch) |
| 275 | (let ((aelt (assoc switch x-switch-definitions))) |
| 276 | (if aelt |
| 277 | (setq default-frame-alist |
| 278 | (cons (cons (nth 1 aelt) |
| 279 | (string-to-int (car x-invocation-args))) |
| 280 | default-frame-alist) |
| 281 | x-invocation-args |
| 282 | (cdr x-invocation-args))))) |
| 283 | |
| 284 | ;; Handle the -xrm option. |
| 285 | (defun x-handle-xrm-switch (switch) |
| 286 | (or (consp x-invocation-args) |
| 287 | (error "%s: missing argument to `%s' option" (invocation-name) switch)) |
| 288 | (setq x-command-line-resources (car x-invocation-args)) |
| 289 | (setq x-invocation-args (cdr x-invocation-args))) |
| 290 | |
| 291 | ;; Handle the geometry option |
| 292 | (defun x-handle-geometry (switch) |
| 293 | (let ((geo (x-parse-geometry (car x-invocation-args)))) |
| 294 | (setq initial-frame-alist |
| 295 | (append initial-frame-alist |
| 296 | (if (or (assq 'left geo) (assq 'top geo)) |
| 297 | '((user-position . t))) |
| 298 | (if (or (assq 'height geo) (assq 'width geo)) |
| 299 | '((user-size . t))) |
| 300 | geo) |
| 301 | x-invocation-args (cdr x-invocation-args)))) |
| 302 | |
| 303 | ;; Handle the -name and -rn options. Set the variable x-resource-name |
| 304 | ;; to the option's operand; if the switch was `-name', set the name of |
| 305 | ;; the initial frame, too. |
| 306 | (defun x-handle-name-rn-switch (switch) |
| 307 | (or (consp x-invocation-args) |
| 308 | (error "%s: missing argument to `%s' option" (invocation-name) switch)) |
| 309 | (setq x-resource-name (car x-invocation-args) |
| 310 | x-invocation-args (cdr x-invocation-args)) |
| 311 | (if (string= switch "-name") |
| 312 | (setq initial-frame-alist (cons (cons 'name x-resource-name) |
| 313 | initial-frame-alist)))) |
| 314 | |
| 315 | (defvar x-display-name nil |
| 316 | "The display name specifying server and frame.") |
| 317 | |
| 318 | (defun x-handle-display (switch) |
| 319 | (setq x-display-name (car x-invocation-args) |
| 320 | x-invocation-args (cdr x-invocation-args))) |
| 321 | |
| 322 | (defvar x-invocation-args nil) |
| 323 | |
| 324 | (defun x-handle-args (args) |
| 325 | "Process the X-related command line options in ARGS. |
| 326 | This is done before the user's startup file is loaded. They are copied to |
| 327 | x-invocation args from which the X-related things are extracted, first |
| 328 | the switch (e.g., \"-fg\") in the following code, and possible values |
| 329 | \(e.g., \"black\") in the option handler code (e.g., x-handle-switch). |
| 330 | This returns ARGS with the arguments that have been processed removed." |
| 331 | (message "%s" args) |
| 332 | (setq x-invocation-args args |
| 333 | args nil) |
| 334 | (while x-invocation-args |
| 335 | (let* ((this-switch (car x-invocation-args)) |
| 336 | (orig-this-switch this-switch) |
| 337 | completion argval aelt) |
| 338 | (setq x-invocation-args (cdr x-invocation-args)) |
| 339 | ;; Check for long options with attached arguments |
| 340 | ;; and separate out the attached option argument into argval. |
| 341 | (if (string-match "^--[^=]*=" this-switch) |
| 342 | (setq argval (substring this-switch (match-end 0)) |
| 343 | this-switch (substring this-switch 0 (1- (match-end 0))))) |
| 344 | (setq completion (try-completion this-switch x-long-option-alist)) |
| 345 | (if (eq completion t) |
| 346 | ;; Exact match for long option. |
| 347 | (setq this-switch (cdr (assoc this-switch x-long-option-alist))) |
| 348 | (if (stringp completion) |
| 349 | (let ((elt (assoc completion x-long-option-alist))) |
| 350 | ;; Check for abbreviated long option. |
| 351 | (or elt |
| 352 | (error "Option `%s' is ambiguous" this-switch)) |
| 353 | (setq this-switch (cdr elt))) |
| 354 | ;; Check for a short option. |
| 355 | (setq argval nil this-switch orig-this-switch))) |
| 356 | (setq aelt (assoc this-switch x-option-alist)) |
| 357 | (if aelt |
| 358 | (if argval |
| 359 | (let ((x-invocation-args |
| 360 | (cons argval x-invocation-args))) |
| 361 | (funcall (cdr aelt) this-switch)) |
| 362 | (funcall (cdr aelt) this-switch)) |
| 363 | (setq args (cons this-switch args))))) |
| 364 | (setq args (nreverse args))) |
| 365 | |
| 366 | |
| 367 | \f |
| 368 | ;; |
| 369 | ;; Available colors |
| 370 | ;; |
| 371 | |
| 372 | (defvar x-colors '("aquamarine" |
| 373 | "Aquamarine" |
| 374 | "medium aquamarine" |
| 375 | "MediumAquamarine" |
| 376 | "black" |
| 377 | "Black" |
| 378 | "blue" |
| 379 | "Blue" |
| 380 | "cadet blue" |
| 381 | "CadetBlue" |
| 382 | "cornflower blue" |
| 383 | "CornflowerBlue" |
| 384 | "dark slate blue" |
| 385 | "DarkSlateBlue" |
| 386 | "light blue" |
| 387 | "LightBlue" |
| 388 | "light steel blue" |
| 389 | "LightSteelBlue" |
| 390 | "medium blue" |
| 391 | "MediumBlue" |
| 392 | "medium slate blue" |
| 393 | "MediumSlateBlue" |
| 394 | "midnight blue" |
| 395 | "MidnightBlue" |
| 396 | "navy blue" |
| 397 | "NavyBlue" |
| 398 | "navy" |
| 399 | "Navy" |
| 400 | "sky blue" |
| 401 | "SkyBlue" |
| 402 | "slate blue" |
| 403 | "SlateBlue" |
| 404 | "steel blue" |
| 405 | "SteelBlue" |
| 406 | "coral" |
| 407 | "Coral" |
| 408 | "cyan" |
| 409 | "Cyan" |
| 410 | "firebrick" |
| 411 | "Firebrick" |
| 412 | "brown" |
| 413 | "Brown" |
| 414 | "gold" |
| 415 | "Gold" |
| 416 | "goldenrod" |
| 417 | "Goldenrod" |
| 418 | "green" |
| 419 | "Green" |
| 420 | "dark green" |
| 421 | "DarkGreen" |
| 422 | "dark olive green" |
| 423 | "DarkOliveGreen" |
| 424 | "forest green" |
| 425 | "ForestGreen" |
| 426 | "lime green" |
| 427 | "LimeGreen" |
| 428 | "medium sea green" |
| 429 | "MediumSeaGreen" |
| 430 | "medium spring green" |
| 431 | "MediumSpringGreen" |
| 432 | "pale green" |
| 433 | "PaleGreen" |
| 434 | "sea green" |
| 435 | "SeaGreen" |
| 436 | "spring green" |
| 437 | "SpringGreen" |
| 438 | "yellow green" |
| 439 | "YellowGreen" |
| 440 | "dark slate grey" |
| 441 | "DarkSlateGrey" |
| 442 | "dark slate gray" |
| 443 | "DarkSlateGray" |
| 444 | "dim grey" |
| 445 | "DimGrey" |
| 446 | "dim gray" |
| 447 | "DimGray" |
| 448 | "light grey" |
| 449 | "LightGrey" |
| 450 | "light gray" |
| 451 | "LightGray" |
| 452 | "gray" |
| 453 | "grey" |
| 454 | "Gray" |
| 455 | "Grey" |
| 456 | "khaki" |
| 457 | "Khaki" |
| 458 | "magenta" |
| 459 | "Magenta" |
| 460 | "maroon" |
| 461 | "Maroon" |
| 462 | "orange" |
| 463 | "Orange" |
| 464 | "orchid" |
| 465 | "Orchid" |
| 466 | "dark orchid" |
| 467 | "DarkOrchid" |
| 468 | "medium orchid" |
| 469 | "MediumOrchid" |
| 470 | "pink" |
| 471 | "Pink" |
| 472 | "plum" |
| 473 | "Plum" |
| 474 | "red" |
| 475 | "Red" |
| 476 | "indian red" |
| 477 | "IndianRed" |
| 478 | "medium violet red" |
| 479 | "MediumVioletRed" |
| 480 | "orange red" |
| 481 | "OrangeRed" |
| 482 | "violet red" |
| 483 | "VioletRed" |
| 484 | "salmon" |
| 485 | "Salmon" |
| 486 | "sienna" |
| 487 | "Sienna" |
| 488 | "tan" |
| 489 | "Tan" |
| 490 | "thistle" |
| 491 | "Thistle" |
| 492 | "turquoise" |
| 493 | "Turquoise" |
| 494 | "dark turquoise" |
| 495 | "DarkTurquoise" |
| 496 | "medium turquoise" |
| 497 | "MediumTurquoise" |
| 498 | "violet" |
| 499 | "Violet" |
| 500 | "blue violet" |
| 501 | "BlueViolet" |
| 502 | "wheat" |
| 503 | "Wheat" |
| 504 | "white" |
| 505 | "White" |
| 506 | "yellow" |
| 507 | "Yellow" |
| 508 | "green yellow" |
| 509 | "GreenYellow") |
| 510 | "The full list of X colors from the `rgb.text' file.") |
| 511 | |
| 512 | (defun x-defined-colors (&optional frame) |
| 513 | "Return a list of colors supported for a particular frame. |
| 514 | The argument FRAME specifies which frame to try. |
| 515 | The value may be different for frames on different X displays." |
| 516 | (or frame (setq frame (selected-frame))) |
| 517 | (let* ((color-map-colors (mapcar (lambda (clr) (car clr)) w32-color-map)) |
| 518 | (all-colors (or color-map-colors x-colors)) |
| 519 | (this-color nil) |
| 520 | (defined-colors nil)) |
| 521 | (message "Defining colors...") |
| 522 | (while all-colors |
| 523 | (setq this-color (car all-colors) |
| 524 | all-colors (cdr all-colors)) |
| 525 | (and (face-color-supported-p frame this-color t) |
| 526 | (setq defined-colors (cons this-color defined-colors)))) |
| 527 | defined-colors)) |
| 528 | \f |
| 529 | \f |
| 530 | ;;;; Function keys |
| 531 | |
| 532 | ;;; make f10 activate the real menubar rather than the mini-buffer menu |
| 533 | ;;; navigation feature. |
| 534 | (global-set-key [f10] (lambda () |
| 535 | (interactive) (w32-send-sys-command ?\xf100))) |
| 536 | |
| 537 | (defun iconify-or-deiconify-frame () |
| 538 | "Iconify the selected frame, or deiconify if it's currently an icon." |
| 539 | (interactive) |
| 540 | (if (eq (cdr (assq 'visibility (frame-parameters))) t) |
| 541 | (iconify-frame) |
| 542 | (make-frame-visible))) |
| 543 | |
| 544 | (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame |
| 545 | global-map) |
| 546 | |
| 547 | \f |
| 548 | ;;;; Selections and cut buffers |
| 549 | |
| 550 | ;;; We keep track of the last text selected here, so we can check the |
| 551 | ;;; current selection against it, and avoid passing back our own text |
| 552 | ;;; from x-cut-buffer-or-selection-value. |
| 553 | (defvar x-last-selected-text nil) |
| 554 | |
| 555 | ;;; It is said that overlarge strings are slow to put into the cut buffer. |
| 556 | ;;; Note this value is overridden below. |
| 557 | (defvar x-cut-buffer-max 20000 |
| 558 | "Max number of characters to put in the cut buffer.") |
| 559 | |
| 560 | (defvar x-select-enable-clipboard t |
| 561 | "Non-nil means cutting and pasting uses the clipboard. |
| 562 | This is in addition to the primary selection.") |
| 563 | |
| 564 | (defun x-select-text (text &optional push) |
| 565 | (if x-select-enable-clipboard |
| 566 | (w32-set-clipboard-data text)) |
| 567 | (setq x-last-selected-text text)) |
| 568 | |
| 569 | ;;; Return the value of the current selection. |
| 570 | ;;; Consult the selection, then the cut buffer. Treat empty strings |
| 571 | ;;; as if they were unset. |
| 572 | (defun x-get-selection-value () |
| 573 | (if x-select-enable-clipboard |
| 574 | (let (text) |
| 575 | ;; Don't die if x-get-selection signals an error. |
| 576 | (condition-case c |
| 577 | (setq text (w32-get-clipboard-data)) |
| 578 | (error (message "w32-get-clipboard-data:%s" c))) |
| 579 | (if (string= text "") (setq text nil)) |
| 580 | (cond |
| 581 | ((not text) nil) |
| 582 | ((eq text x-last-selected-text) nil) |
| 583 | ((string= text x-last-selected-text) |
| 584 | ;; Record the newer string, so subsequent calls can use the 'eq' test. |
| 585 | (setq x-last-selected-text text) |
| 586 | nil) |
| 587 | (t |
| 588 | (setq x-last-selected-text text)))))) |
| 589 | \f |
| 590 | (defalias 'x-cut-buffer-or-selection-value 'x-get-selection-value) |
| 591 | |
| 592 | \f |
| 593 | ;;; Do the actual Windows setup here; the above code just defines |
| 594 | ;;; functions and variables that we use now. |
| 595 | |
| 596 | (setq command-line-args (x-handle-args command-line-args)) |
| 597 | |
| 598 | ;;; Make sure we have a valid resource name. |
| 599 | (or (stringp x-resource-name) |
| 600 | (let (i) |
| 601 | (setq x-resource-name (invocation-name)) |
| 602 | |
| 603 | ;; Change any . or * characters in x-resource-name to hyphens, |
| 604 | ;; so as not to choke when we use it in X resource queries. |
| 605 | (while (setq i (string-match "[.*]" x-resource-name)) |
| 606 | (aset x-resource-name i ?-)))) |
| 607 | |
| 608 | ;; For the benefit of older Emacses (19.27 and earlier) that are sharing |
| 609 | ;; the same lisp directory, don't pass the third argument unless we seem |
| 610 | ;; to have the multi-display support. |
| 611 | (if (fboundp 'x-close-connection) |
| 612 | (x-open-connection "" |
| 613 | x-command-line-resources |
| 614 | ;; Exit Emacs with fatal error if this fails. |
| 615 | t) |
| 616 | (x-open-connection "" |
| 617 | x-command-line-resources)) |
| 618 | |
| 619 | (setq frame-creation-function 'x-create-frame-with-faces) |
| 620 | |
| 621 | (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100) |
| 622 | x-cut-buffer-max)) |
| 623 | |
| 624 | ;; W32 expects the menu bar cut and paste commands to use the clipboard. |
| 625 | ;; This has ,? to match both on Sunos and on Solaris. |
| 626 | (menu-bar-enable-clipboard) |
| 627 | |
| 628 | ;; W32 systems have different fonts than commonly found on X, so |
| 629 | ;; we define our own standard fontset here. |
| 630 | (defvar w32-standard-fontset-spec |
| 631 | "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard" |
| 632 | "String of fontset spec of the standard fontset. This defines a |
| 633 | fontset consisting of the Courier New variations for European |
| 634 | languages which are distributed with Windows as \"Multilanguage Support\". |
| 635 | |
| 636 | See the documentation of `create-fontset-from-fontset-spec for the format.") |
| 637 | |
| 638 | (if (fboundp 'new-fontset) |
| 639 | (progn |
| 640 | (defun w32-create-initial-fontsets () |
| 641 | "Create fontset-startup, fontset-standard and any fontsets |
| 642 | specified in X resources." |
| 643 | ;; Create the standard fontset. |
| 644 | (create-fontset-from-fontset-spec w32-standard-fontset-spec t) |
| 645 | |
| 646 | ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...). |
| 647 | (create-fontset-from-x-resource) |
| 648 | |
| 649 | ;; Try to create a fontset from a font specification which comes |
| 650 | ;; from initial-frame-alist, default-frame-alist, or X resource. |
| 651 | ;; A font specification in command line argument (i.e. -fn XXXX) |
| 652 | ;; should be already in default-frame-alist as a `font' |
| 653 | ;; parameter. However, any font specifications in site-start |
| 654 | ;; library, user's init file (.emacs), and default.el are not |
| 655 | ;; yet handled here. |
| 656 | |
| 657 | (let ((font (or (cdr (assq 'font initial-frame-alist)) |
| 658 | (cdr (assq 'font default-frame-alist)) |
| 659 | (x-get-resource "font" "Font"))) |
| 660 | xlfd-fields resolved-name) |
| 661 | (if (and font |
| 662 | (not (query-fontset font)) |
| 663 | (setq resolved-name (x-resolve-font-name font)) |
| 664 | (setq xlfd-fields (x-decompose-font-name font))) |
| 665 | (if (string= "fontset" |
| 666 | (aref xlfd-fields xlfd-regexp-registry-subnum)) |
| 667 | (new-fontset font |
| 668 | (x-complement-fontset-spec xlfd-fields nil)) |
| 669 | ;; Create a fontset from FONT. The fontset name is |
| 670 | ;; generated from FONT. Create style variants of the |
| 671 | ;; fontset too. Font names in the variants are |
| 672 | ;; generated automatially unless X resources |
| 673 | ;; XXX.attribyteFont explicitly specify them. |
| 674 | (let ((styles (mapcar 'car x-style-funcs-alist)) |
| 675 | (faces '(bold italic bold-italic)) |
| 676 | face face-font fontset fontset-spec) |
| 677 | (while faces |
| 678 | (setq face (car faces)) |
| 679 | (setq face-font (x-get-resource (concat (symbol-name face) |
| 680 | ".attributeFont") |
| 681 | "Face.AttributeFont")) |
| 682 | (if face-font |
| 683 | (setq styles (cons (cons face face-font) |
| 684 | (delq face styles)))) |
| 685 | (setq faces (cdr faces))) |
| 686 | (aset xlfd-fields xlfd-regexp-foundry-subnum nil) |
| 687 | (aset xlfd-fields xlfd-regexp-family-subnum nil) |
| 688 | (aset xlfd-fields xlfd-regexp-registry-subnum "fontset") |
| 689 | (aset xlfd-fields xlfd-regexp-encoding-subnum "startup") |
| 690 | ;; The fontset name should have concrete values in |
| 691 | ;; weight and slant field. |
| 692 | (let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum)) |
| 693 | (slant (aref xlfd-fields xlfd-regexp-slant-subnum)) |
| 694 | xlfd-temp) |
| 695 | (if (or (not weight) (string-match "[*?]*" weight)) |
| 696 | (progn |
| 697 | (setq xlfd-temp |
| 698 | (x-decompose-font-name resolved-name)) |
| 699 | (aset xlfd-fields xlfd-regexp-weight-subnum |
| 700 | (aref xlfd-temp xlfd-regexp-weight-subnum)))) |
| 701 | (if (or (not slant) (string-match "[*?]*" slant)) |
| 702 | (progn |
| 703 | (or xlfd-temp |
| 704 | (setq xlfd-temp |
| 705 | (x-decompose-font-name resolved-name))) |
| 706 | (aset xlfd-fields xlfd-regexp-slant-subnum |
| 707 | (aref xlfd-temp xlfd-regexp-slant-subnum))))) |
| 708 | (setq fontset (x-compose-font-name xlfd-fields)) |
| 709 | (create-fontset-from-fontset-spec |
| 710 | (concat fontset ", ascii:" font) styles) |
| 711 | ))))) |
| 712 | ;; This cannot be run yet, as creating fontsets requires a |
| 713 | ;; Window to be initialised so the fonts can be listed. |
| 714 | ;; Add it to a hook so it gets run later. |
| 715 | (add-hook 'before-init-hook 'w32-create-initial-fontsets) |
| 716 | )) |
| 717 | |
| 718 | ;; Apply a geometry resource to the initial frame. Put it at the end |
| 719 | ;; of the alist, so that anything specified on the command line takes |
| 720 | ;; precedence. |
| 721 | (let* ((res-geometry (x-get-resource "geometry" "Geometry")) |
| 722 | parsed) |
| 723 | (if res-geometry |
| 724 | (progn |
| 725 | (setq parsed (x-parse-geometry res-geometry)) |
| 726 | ;; If the resource specifies a position, |
| 727 | ;; call the position and size "user-specified". |
| 728 | (if (or (assq 'top parsed) (assq 'left parsed)) |
| 729 | (setq parsed (cons '(user-position . t) |
| 730 | (cons '(user-size . t) parsed)))) |
| 731 | ;; All geometry parms apply to the initial frame. |
| 732 | (setq initial-frame-alist (append initial-frame-alist parsed)) |
| 733 | ;; The size parms apply to all frames. |
| 734 | (if (assq 'height parsed) |
| 735 | (setq default-frame-alist |
| 736 | (cons (cons 'height (cdr (assq 'height parsed))) |
| 737 | default-frame-alist))) |
| 738 | (if (assq 'width parsed) |
| 739 | (setq default-frame-alist |
| 740 | (cons (cons 'width (cdr (assq 'width parsed))) |
| 741 | default-frame-alist)))))) |
| 742 | |
| 743 | ;; Check the reverseVideo resource. |
| 744 | (let ((case-fold-search t)) |
| 745 | (let ((rv (x-get-resource "reverseVideo" "ReverseVideo"))) |
| 746 | (if (and rv |
| 747 | (string-match "^\\(true\\|yes\\|on\\)$" rv)) |
| 748 | (setq default-frame-alist |
| 749 | (cons '(reverse . t) default-frame-alist))))) |
| 750 | |
| 751 | ;; Set x-selection-timeout, measured in milliseconds. |
| 752 | (let ((res-selection-timeout |
| 753 | (x-get-resource "selectionTimeout" "SelectionTimeout"))) |
| 754 | (setq x-selection-timeout 20000) |
| 755 | (if res-selection-timeout |
| 756 | (setq x-selection-timeout (string-to-number res-selection-timeout)))) |
| 757 | |
| 758 | (defun x-win-suspend-error () |
| 759 | (error "Suspending an emacs running under W32 makes no sense")) |
| 760 | (add-hook 'suspend-hook 'x-win-suspend-error) |
| 761 | |
| 762 | ;;; Arrange for the kill and yank functions to set and check the clipboard. |
| 763 | (setq interprogram-cut-function 'x-select-text) |
| 764 | (setq interprogram-paste-function 'x-get-selection-value) |
| 765 | |
| 766 | ;;; Turn off window-splitting optimization; w32 is usually fast enough |
| 767 | ;;; that this is only annoying. |
| 768 | (setq split-window-keep-point t) |
| 769 | |
| 770 | ;; Don't show the frame name; that's redundant. |
| 771 | (setq-default mode-line-frame-identification " ") |
| 772 | |
| 773 | ;;; Set to a system sound if you want a fancy bell. |
| 774 | (set-message-beep 'ok) |
| 775 | |
| 776 | ;; Remap some functions to call w32 common dialogs |
| 777 | |
| 778 | (defun internal-face-interactive (what &optional bool) |
| 779 | (let* ((fn (intern (concat "face-" what))) |
| 780 | (prompt (concat "Set " what " of face")) |
| 781 | (face (read-face-name (concat prompt ": "))) |
| 782 | (default (if (fboundp fn) |
| 783 | (or (funcall fn face (selected-frame)) |
| 784 | (funcall fn 'default (selected-frame))))) |
| 785 | (fn-win (intern (concat (symbol-name window-system) "-select-" what))) |
| 786 | value) |
| 787 | (setq value |
| 788 | (cond ((fboundp fn-win) |
| 789 | (funcall fn-win)) |
| 790 | ((eq bool 'color) |
| 791 | (completing-read (concat prompt " " (symbol-name face) " to: ") |
| 792 | (mapcar (function (lambda (color) |
| 793 | (cons color color))) |
| 794 | x-colors) |
| 795 | nil nil nil nil default)) |
| 796 | (bool |
| 797 | (y-or-n-p (concat "Should face " (symbol-name face) |
| 798 | " be " bool "? "))) |
| 799 | (t |
| 800 | (read-string (concat prompt " " (symbol-name face) " to: ") |
| 801 | nil nil default)))) |
| 802 | (list face (if (equal value "") nil value)))) |
| 803 | |
| 804 | ;; Redefine the font selection to use the standard W32 dialog |
| 805 | (defvar w32-use-w32-font-dialog t |
| 806 | "*Use the standard font dialog if 't' - otherwise pop up a menu of |
| 807 | some standard fonts like X does - including fontsets") |
| 808 | |
| 809 | (defvar w32-fixed-font-alist |
| 810 | '("Font menu" |
| 811 | ("Misc" |
| 812 | ;; For these, we specify the pixel height and width. |
| 813 | ("fixed" "Fixedsys") |
| 814 | ("") |
| 815 | ("Terminal 5x4" |
| 816 | "-*-Terminal-normal-r-*-*-*-45-*-*-c-40-*-oem") |
| 817 | ("Terminal 6x8" |
| 818 | "-*-Terminal-normal-r-*-*-*-60-*-*-c-80-*-oem") |
| 819 | ("Terminal 9x5" |
| 820 | "-*-Terminal-normal-r-*-*-*-90-*-*-c-50-*-oem") |
| 821 | ("Terminal 9x7" |
| 822 | "-*-Terminal-normal-r-*-*-*-90-*-*-c-70-*-oem") |
| 823 | ("Terminal 9x8" |
| 824 | "-*-Terminal-normal-r-*-*-*-90-*-*-c-80-*-oem") |
| 825 | ("Terminal 12x12" |
| 826 | "-*-Terminal-normal-r-*-*-*-120-*-*-c-120-*-oem") |
| 827 | ("Terminal 14x10" |
| 828 | "-*-Terminal-normal-r-*-*-*-135-*-*-c-100-*-oem") |
| 829 | ("Terminal 6x6 Bold" |
| 830 | "-*-Terminal-bold-r-*-*-*-60-*-*-c-60-*-oem") |
| 831 | ("") |
| 832 | ("Lucida Sans Typewriter.8" |
| 833 | "-*-Lucida Sans Typewriter-normal-r-*-*-11-*-*-*-c-*-iso8859-1") |
| 834 | ("Lucida Sans Typewriter.9" |
| 835 | "-*-Lucida Sans Typewriter-normal-r-*-*-12-*-*-*-c-*-iso8859-1") |
| 836 | ("Lucida Sans Typewriter.10" |
| 837 | "-*-Lucida Sans Typewriter-normal-r-*-*-13-*-*-*-c-*-iso8859-1") |
| 838 | ("Lucida Sans Typewriter.11" |
| 839 | "-*-Lucida Sans Typewriter-normal-r-*-*-15-*-*-*-c-*-iso8859-1") |
| 840 | ("Lucida Sans Typewriter.12" |
| 841 | "-*-Lucida Sans Typewriter-normal-r-*-*-16-*-*-*-c-*-iso8859-1") |
| 842 | ("Lucida Sans Typewriter.8 Bold" |
| 843 | "-*-Lucida Sans Typewriter-semibold-r-*-*-11-*-*-*-c-*-iso8859-1") |
| 844 | ("Lucida Sans Typewriter.9 Bold" |
| 845 | "-*-Lucida Sans Typewriter-semibold-r-*-*-12-*-*-*-c-*-iso8859-1") |
| 846 | ("Lucida Sans Typewriter.10 Bold" |
| 847 | "-*-Lucida Sans Typewriter-semibold-r-*-*-13-*-*-*-c-*-iso8859-1") |
| 848 | ("Lucida Sans Typewriter.11 Bold" |
| 849 | "-*-Lucida Sans Typewriter-semibold-r-*-*-15-*-*-*-c-*-iso8859-1") |
| 850 | ("Lucida Sans Typewriter.12 Bold" |
| 851 | "-*-Lucida Sans Typewriter-semibold-r-*-*-16-*-*-*-c-*-iso8859-1")) |
| 852 | ("Courier" |
| 853 | ("Courier 10x8" |
| 854 | "-*-Courier-*normal-r-*-*-*-97-*-*-c-80-iso8859-1") |
| 855 | ("Courier 12x9" |
| 856 | "-*-Courier-*normal-r-*-*-*-120-*-*-c-90-iso8859-1") |
| 857 | ("Courier 15x12" |
| 858 | "-*-Courier-*normal-r-*-*-*-150-*-*-c-120-iso8859-1") |
| 859 | ;; For these, we specify the point height. |
| 860 | ("") |
| 861 | ("8" "-*-Courier New-normal-r-*-*-11-*-*-*-c-*-iso8859-1") |
| 862 | ("9" "-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-1") |
| 863 | ("10" "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-iso8859-1") |
| 864 | ("11" "-*-Courier New-normal-r-*-*-15-*-*-*-c-*-iso8859-1") |
| 865 | ("12" "-*-Courier New-normal-r-*-*-16-*-*-*-c-*-iso8859-1") |
| 866 | ("8 bold" "-*-Courier New-bold-r-*-*-11-*-*-*-c-*-iso8859-1") |
| 867 | ("9 bold" "-*-Courier New-bold-r-*-*-12-*-*-*-c-*-iso8859-1") |
| 868 | ("10 bold" "-*-Courier New-bold-r-*-*-13-*-*-*-c-*-iso8859-1") |
| 869 | ("11 bold" "-*-Courier New-bold-r-*-*-15-*-*-*-c-*-iso8859-1") |
| 870 | ("12 bold" "-*-Courier New-bold-r-*-*-16-*-*-*-c-*-iso8859-1") |
| 871 | ("8 italic" "-*-Courier New-normal-i-*-*-11-*-*-*-c-*-iso8859-1") |
| 872 | ("9 italic" "-*-Courier New-normal-i-*-*-12-*-*-*-c-*-iso8859-1") |
| 873 | ("10 italic" "-*-Courier New-normal-i-*-*-13-*-*-*-c-*-iso8859-1") |
| 874 | ("11 italic" "-*-Courier New-normal-i-*-*-15-*-*-*-c-*-iso8859-1") |
| 875 | ("12 italic" "-*-Courier New-normal-i-*-*-16-*-*-*-c-*-iso8859-1") |
| 876 | ("8 bold italic" "-*-Courier New-bold-i-*-*-11-*-*-*-c-*-iso8859-1") |
| 877 | ("9 bold italic" "-*-Courier New-bold-i-*-*-12-*-*-*-c-*-iso8859-1") |
| 878 | ("10 bold italic" "-*-Courier New-bold-i-*-*-13-*-*-*-c-*-iso8859-1") |
| 879 | ("11 bold italic" "-*-Courier New-bold-i-*-*-15-*-*-*-c-*-iso8859-1") |
| 880 | ("12 bold italic" "-*-Courier New-bold-i-*-*-16-*-*-*-c-*-iso8859-1") |
| 881 | )) |
| 882 | "Fonts suitable for use in Emacs. Initially this is a list of some |
| 883 | fixed width fonts that most people will have like Terminal and |
| 884 | Courier. These fonts are used in the font menu if the variable |
| 885 | `w32-use-w32-font-dialog' is nil.") |
| 886 | |
| 887 | ;;; Enable Japanese fonts on Windows to be used by default. |
| 888 | (put-charset-property 'katakana-jisx0201 'x-charset-registry "JISX0208-SJIS") |
| 889 | (put-charset-property 'latin-jisx0201 'x-charset-registry "JISX0208-SJIS") |
| 890 | (put-charset-property 'japanese-jisx0208 'x-charset-registry "JISX0208-SJIS") |
| 891 | (put-charset-property 'japanese-jisx0208-1978 'x-charset-registry |
| 892 | "JISX0208-SJIS") |
| 893 | |
| 894 | (defun mouse-set-font (&rest fonts) |
| 895 | "Select a font. If `w32-use-w32-font-dialog' is non-nil (the default), |
| 896 | use the Windows font dialog. Otherwise use a pop-up menu (like Emacs |
| 897 | on other platforms) initialized with the fonts in |
| 898 | `w32-fixed-font-alist'. Emacs will attempt to create a fontset from |
| 899 | the font chosen, covering all the charsets that can be fully represented |
| 900 | with the font." |
| 901 | (interactive |
| 902 | (if w32-use-w32-font-dialog |
| 903 | (list (w32-select-font)) |
| 904 | (x-popup-menu |
| 905 | last-nonmenu-event |
| 906 | ;; Append list of fontsets currently defined. |
| 907 | (if (fboundp 'new-fontset) |
| 908 | (append w32-fixed-font-alist (list (generate-fontset-menu))))))) |
| 909 | (if fonts |
| 910 | (let (font fontset xlfd resolved-font) |
| 911 | (while fonts |
| 912 | (condition-case nil |
| 913 | (progn |
| 914 | (setq font (car fonts)) |
| 915 | (if (fontset-name-p font) |
| 916 | (setq fontset font) |
| 917 | (condition-case nil |
| 918 | (setq resolved-font (x-resolve-font-name font) |
| 919 | xlfd (x-decompose-font-name resolved-font) |
| 920 | fontset |
| 921 | (create-fontset-from-ascii-font |
| 922 | font resolved-font |
| 923 | (format "%s_%s_%s_%s" |
| 924 | (aref xlfd xlfd-regexp-family-subnum) |
| 925 | (aref xlfd xlfd-regexp-registry-subnum) |
| 926 | (aref xlfd xlfd-regexp-encoding-subnum) |
| 927 | (aref xlfd |
| 928 | xlfd-regexp-pixelsize-subnum)))) |
| 929 | (error nil))) |
| 930 | (if fontset |
| 931 | (set-default-font fontset) |
| 932 | (set-default-font font)) |
| 933 | (setq fonts nil)) |
| 934 | (error (setq fonts (cdr fonts))))) |
| 935 | (if (null font) |
| 936 | (error "Font not found"))))) |
| 937 | |
| 938 | ;;; w32-win.el ends here |