root/trunk/lisp/term/mac-win.el

Revision 4220, 88.5 kB (checked in by miyoshi, 9 months ago)

Sync up with Emacs22.2.

  • Property svn:eol-style set to LF
Line 
1 ;;; mac-win.el --- parse switches controlling interface with Mac window system -*-coding: iso-2022-7bit;-*-
2
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Author: Andrew Choi <akochoi@mac.com>
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, or (at your option)
14 ;; 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; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; Mac-win.el:  this file is loaded from ../lisp/startup.el when it recognizes
29 ;; that Mac windows are to be used.  Command line switches are parsed and those
30 ;; pertaining to Mac are processed and removed from the command line.  The
31 ;; Mac display is opened and hooks are set for popping up the initial window.
32
33 ;; startup.el will then examine startup files, and eventually call the hooks
34 ;; which create the first window(s).
35
36 ;;; Code:
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 ;; -iconic              .iconic
58 ;; -name                .name
59 ;; -reverse             *reverseVideo
60 ;; -rv                  *reverseVideo
61 ;; -selectionTimeout    .selectionTimeout
62 ;; -synchronous         *synchronous
63 ;; -xrm
64
65 ;; An alist of X options and the function which handles them.  See
66 ;; ../startup.el.
67
68 (if (not (eq window-system 'mac))
69     (error "%s: Loading mac-win.el but not compiled for Mac" (invocation-name)))
70
71 (require 'frame)
72 (require 'mouse)
73 (require 'scroll-bar)
74 (require 'faces)
75 (require 'select)
76 (require 'menu-bar)
77 (require 'fontset)
78 (require 'dnd)
79
80 (defvar mac-charset-info-alist)
81 (defvar mac-service-selection)
82 (defvar mac-system-script-code)
83 (defvar mac-apple-event-map)
84 (defvar mac-font-panel-mode)
85 (defvar mac-ts-active-input-overlay)
86 (defvar x-invocation-args)
87
88 (defvar x-command-line-resources nil)
89
90 ;; Handler for switches of the form "-switch value" or "-switch".
91 (defun x-handle-switch (switch)
92   (let ((aelt (assoc switch command-line-x-option-alist)))
93     (if aelt
94         (let ((param (nth 3 aelt))
95               (value (nth 4 aelt)))
96           (if value
97               (setq default-frame-alist
98                     (cons (cons param value)
99                           default-frame-alist))
100             (setq default-frame-alist
101                   (cons (cons param
102                               (car x-invocation-args))
103                         default-frame-alist)
104                   x-invocation-args (cdr x-invocation-args)))))))
105
106 ;; Handler for switches of the form "-switch n"
107 (defun x-handle-numeric-switch (switch)
108   (let ((aelt (assoc switch command-line-x-option-alist)))
109     (if aelt
110         (let ((param (nth 3 aelt)))
111           (setq default-frame-alist
112                 (cons (cons param
113                             (string-to-number (car x-invocation-args)))
114                       default-frame-alist)
115                 x-invocation-args
116                 (cdr x-invocation-args))))))
117
118 ;; Handle options that apply to initial frame only
119 (defun x-handle-initial-switch (switch)
120   (let ((aelt (assoc switch command-line-x-option-alist)))
121     (if aelt
122         (let ((param (nth 3 aelt))
123               (value (nth 4 aelt)))
124           (if value
125               (setq initial-frame-alist
126                     (cons (cons param value)
127                           initial-frame-alist))
128             (setq initial-frame-alist
129                   (cons (cons param
130                               (car x-invocation-args))
131                         initial-frame-alist)
132                   x-invocation-args (cdr x-invocation-args)))))))
133
134 ;; Make -iconic apply only to the initial frame!
135 (defun x-handle-iconic (switch)
136   (setq initial-frame-alist
137         (cons '(visibility . icon) initial-frame-alist)))
138
139 ;; Handle the -xrm option.
140 (defun x-handle-xrm-switch (switch)
141   (unless (consp x-invocation-args)
142     (error "%s: missing argument to `%s' option" (invocation-name) switch))
143   (setq x-command-line-resources
144         (if (null x-command-line-resources)
145             (car x-invocation-args)
146           (concat x-command-line-resources "\n" (car x-invocation-args))))
147   (setq x-invocation-args (cdr x-invocation-args)))
148
149 ;; Handle the geometry option
150 (defun x-handle-geometry (switch)
151   (let* ((geo (x-parse-geometry (car x-invocation-args)))
152          (left (assq 'left geo))
153          (top (assq 'top geo))
154          (height (assq 'height geo))
155          (width (assq 'width geo)))
156     (if (or height width)
157         (setq default-frame-alist
158               (append default-frame-alist
159                       '((user-size . t))
160                       (if height (list height))
161                       (if width (list width)))
162               initial-frame-alist
163               (append initial-frame-alist
164                       '((user-size . t))
165                       (if height (list height))
166                       (if width (list width)))))
167     (if (or left top)
168         (setq initial-frame-alist
169               (append initial-frame-alist
170                       '((user-position . t))
171                       (if left (list left))
172                       (if top (list top)))))
173     (setq x-invocation-args (cdr x-invocation-args))))
174
175 ;; Handle the -name option.  Set the variable x-resource-name
176 ;; to the option's operand; set the name of
177 ;; the initial frame, too.
178 (defun x-handle-name-switch (switch)
179   (or (consp x-invocation-args)
180       (error "%s: missing argument to `%s' option" (invocation-name) switch))
181   (setq x-resource-name (car x-invocation-args)
182         x-invocation-args (cdr x-invocation-args))
183   (setq initial-frame-alist (cons (cons 'name x-resource-name)
184                                   initial-frame-alist)))
185
186 (defvar x-display-name nil
187   "The display name specifying server and frame.")
188
189 (defun x-handle-display (switch)
190   (setq x-display-name (car x-invocation-args)
191         x-invocation-args (cdr x-invocation-args)))
192
193 (defun x-handle-args (args)
194   "Process the X-related command line options in ARGS.
195 This is done before the user's startup file is loaded.  They are copied to
196 `x-invocation-args', from which the X-related things are extracted, first
197 the switch (e.g., \"-fg\") in the following code, and possible values
198 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
199 This function returns ARGS minus the arguments that have been processed."
200   ;; We use ARGS to accumulate the args that we don't handle here, to return.
201   (setq x-invocation-args args
202         args nil)
203   (while (and x-invocation-args
204               (not (equal (car x-invocation-args) "--")))
205     (let* ((this-switch (car x-invocation-args))
206            (orig-this-switch this-switch)
207            completion argval aelt handler)
208       (setq x-invocation-args (cdr x-invocation-args))
209       ;; Check for long options with attached arguments
210       ;; and separate out the attached option argument into argval.
211       (if (string-match "^--[^=]*=" this-switch)
212           (setq argval (substring this-switch (match-end 0))
213                 this-switch (substring this-switch 0 (1- (match-end 0)))))
214       ;; Complete names of long options.
215       (if (string-match "^--" this-switch)
216           (progn
217             (setq completion (try-completion this-switch command-line-x-option-alist))
218             (if (eq completion t)
219                 ;; Exact match for long option.
220                 nil
221               (if (stringp completion)
222                   (let ((elt (assoc completion command-line-x-option-alist)))
223                     ;; Check for abbreviated long option.
224                     (or elt
225                         (error "Option `%s' is ambiguous" this-switch))
226                     (setq this-switch completion))))))
227       (setq aelt (assoc this-switch command-line-x-option-alist))
228       (if aelt (setq handler (nth 2 aelt)))
229       (if handler
230           (if argval
231               (let ((x-invocation-args
232                      (cons argval x-invocation-args)))
233                 (funcall handler this-switch))
234             (funcall handler this-switch))
235         (setq args (cons orig-this-switch args)))))
236   (nconc (nreverse args) x-invocation-args))
237
238
239 ;;
240 ;; Standard Mac cursor shapes
241 ;;
242
243 (defconst mac-pointer-arrow 0)
244 (defconst mac-pointer-copy-arrow 1)
245 (defconst mac-pointer-alias-arrow 2)
246 (defconst mac-pointer-contextual-menu-arrow 3)
247 (defconst mac-pointer-I-beam 4)
248 (defconst mac-pointer-cross 5)
249 (defconst mac-pointer-plus 6)
250 (defconst mac-pointer-watch 7)
251 (defconst mac-pointer-closed-hand 8)
252 (defconst mac-pointer-open-hand 9)
253 (defconst mac-pointer-pointing-hand 10)
254 (defconst mac-pointer-counting-up-hand 11)
255 (defconst mac-pointer-counting-down-hand 12)
256 (defconst mac-pointer-counting-up-and-down-hand 13)
257 (defconst mac-pointer-spinning 14)
258 (defconst mac-pointer-resize-left 15)
259 (defconst mac-pointer-resize-right 16)
260 (defconst mac-pointer-resize-left-right 17)
261 ;; Mac OS X 10.2 and later
262 (defconst mac-pointer-not-allowed 18)
263 ;; Mac OS X 10.3 and later
264 (defconst mac-pointer-resize-up 19)
265 (defconst mac-pointer-resize-down 20)
266 (defconst mac-pointer-resize-up-down 21)
267 (defconst mac-pointer-poof 22)
268
269 ;;
270 ;; Standard X cursor shapes that have Mac counterparts
271 ;;
272
273 (defconst x-pointer-left-ptr mac-pointer-arrow)
274 (defconst x-pointer-xterm mac-pointer-I-beam)
275 (defconst x-pointer-crosshair mac-pointer-cross)
276 (defconst x-pointer-plus mac-pointer-plus)
277 (defconst x-pointer-watch mac-pointer-watch)
278 (defconst x-pointer-hand2 mac-pointer-pointing-hand)
279 (defconst x-pointer-left-side mac-pointer-resize-left)
280 (defconst x-pointer-right-side mac-pointer-resize-right)
281 (defconst x-pointer-sb-h-double-arrow mac-pointer-resize-left-right)
282 (defconst x-pointer-top-side mac-pointer-resize-up)
283 (defconst x-pointer-bottom-side mac-pointer-resize-down)
284 (defconst x-pointer-sb-v-double-arrow mac-pointer-resize-up-down)
285
286
287 ;;
288 ;; Available colors
289 ;;
290
291 (defvar x-colors '("LightGreen"
292                    "light green"
293                    "DarkRed"
294                    "dark red"
295                    "DarkMagenta"
296                    "dark magenta"
297                    "DarkCyan"
298                    "dark cyan"
299                    "DarkBlue"
300                    "dark blue"
301                    "DarkGray"
302                    "dark gray"
303                    "DarkGrey"
304                    "dark grey"
305                    "grey100"
306                    "gray100"
307                    "grey99"
308                    "gray99"
309                    "grey98"
310                    "gray98"
311                    "grey97"
312                    "gray97"
313                    "grey96"
314                    "gray96"
315                    "grey95"
316                    "gray95"
317                    "grey94"
318                    "gray94"
319                    "grey93"
320                    "gray93"
321                    "grey92"
322                    "gray92"
323                    "grey91"
324                    "gray91"
325                    "grey90"
326                    "gray90"
327                    "grey89"
328                    "gray89"
329                    "grey88"
330                    "gray88"
331                    "grey87"
332                    "gray87"
333                    "grey86"
334                    "gray86"
335                    "grey85"
336                    "gray85"
337                    "grey84"
338                    "gray84"
339                    "grey83"
340                    "gray83"
341                    "grey82"
342                    "gray82"
343                    "grey81"
344                    "gray81"
345                    "grey80"
346                    "gray80"
347                    "grey79"
348                    "gray79"
349                    "grey78"
350                    "gray78"
351                    "grey77"
352                    "gray77"
353                    "grey76"
354                    "gray76"
355                    "grey75"
356                    "gray75"
357                    "grey74"
358                    "gray74"
359                    "grey73"
360                    "gray73"
361                    "grey72"
362                    "gray72"
363                    "grey71"
364                    "gray71"
365                    "grey70"
366                    "gray70"
367                    "grey69"
368                    "gray69"
369                    "grey68"
370                    "gray68"
371                    "grey67"
372                    "gray67"
373                    "grey66"
374                    "gray66"
375                    "grey65"
376                    "gray65"
377                    "grey64"
378                    "gray64"
379                    "grey63"
380                    "gray63"
381                    "grey62"
382                    "gray62"
383                    "grey61"
384                    "gray61"
385                    "grey60"
386                    "gray60"
387                    "grey59"
388                    "gray59"
389                    "grey58"
390                    "gray58"
391                    "grey57"
392                    "gray57"
393                    "grey56"
394                    "gray56"
395                    "grey55"
396                    "gray55"
397                    "grey54"
398                    "gray54"
399                    "grey53"
400                    "gray53"
401                    "grey52"
402                    "gray52"
403                    "grey51"
404                    "gray51"
405                    "grey50"
406                    "gray50"
407                    "grey49"
408                    "gray49"
409                    "grey48"
410                    "gray48"
411                    "grey47"
412                    "gray47"
413                    "grey46"
414                    "gray46"
415                    "grey45"
416                    "gray45"
417                    "grey44"
418                    "gray44"
419                    "grey43"
420                    "gray43"
421                    "grey42"
422                    "gray42"
423                    "grey41"
424                    "gray41"
425                    "grey40"
426                    "gray40"
427                    "grey39"
428                    "gray39"
429                    "grey38"
430                    "gray38"
431                    "grey37"
432                    "gray37"
433                    "grey36"
434                    "gray36"
435                    "grey35"
436                    "gray35"
437                    "grey34"
438                    "gray34"
439                    "grey33"
440                    "gray33"
441                    "grey32"
442                    "gray32"
443                    "grey31"
444                    "gray31"
445                    "grey30"
446                    "gray30"
447                    "grey29"
448                    "gray29"
449                    "grey28"
450                    "gray28"
451                    "grey27"
452                    "gray27"
453                    "grey26"
454                    "gray26"
455                    "grey25"
456                    "gray25"
457                    "grey24"
458                    "gray24"
459                    "grey23"
460                    "gray23"
461                    "grey22"
462                    "gray22"
463                    "grey21"
464                    "gray21"
465                    "grey20"
466                    "gray20"
467                    "grey19"
468                    "gray19"
469                    "grey18"
470                    "gray18"
471                    "grey17"
472                    "gray17"
473                    "grey16"
474                    "gray16"
475                    "grey15"
476                    "gray15"
477                    "grey14"
478                    "gray14"
479                    "grey13"
480                    "gray13"
481                    "grey12"
482                    "gray12"
483                    "grey11"
484                    "gray11"
485                    "grey10"
486                    "gray10"
487                    "grey9"
488                    "gray9"
489                    "grey8"
490                    "gray8"
491                    "grey7"
492                    "gray7"
493                    "grey6"
494                    "gray6"
495                    "grey5"
496                    "gray5"
497                    "grey4"
498                    "gray4"
499                    "grey3"
500                    "gray3"
501                    "grey2"
502                    "gray2"
503                    "grey1"
504                    "gray1"
505                    "grey0"
506                    "gray0"
507                    "thistle4"
508                    "thistle3"
509                    "thistle2"
510                    "thistle1"
511                    "MediumPurple4"
512                    "MediumPurple3"
513                    "MediumPurple2"
514                    "MediumPurple1"
515                    "purple4"
516                    "purple3"
517                    "purple2"
518                    "purple1"
519                    "DarkOrchid4"
520                    "DarkOrchid3"
521                    "DarkOrchid2"
522                    "DarkOrchid1"
523                    "MediumOrchid4"
524                    "MediumOrchid3"
525                    "MediumOrchid2"
526                    "MediumOrchid1"
527                    "plum4"
528                    "plum3"
529                    "plum2"
530                    "plum1"
531                    "orchid4"
532                    "orchid3"
533                    "orchid2"
534                    "orchid1"
535                    "magenta4"
536                    "magenta3"
537                    "magenta2"
538                    "magenta1"
539                    "VioletRed4"
540                    "VioletRed3"
541                    "VioletRed2"
542                    "VioletRed1"
543                    "maroon4"
544                    "maroon3"
545                    "maroon2"
546                    "maroon1"
547                    "PaleVioletRed4"
548                    "PaleVioletRed3"
549                    "PaleVioletRed2"
550                    "PaleVioletRed1"
551                    "LightPink4"
552                    "LightPink3"
553                    "LightPink2"
554                    "LightPink1"
555                    "pink4"
556                    "pink3"
557                    "pink2"
558                    "pink1"
559                    "HotPink4"
560                    "HotPink3"
561                    "HotPink2"
562                    "HotPink1"
563                    "DeepPink4"
564                    "DeepPink3"
565                    "DeepPink2"
566                    "DeepPink1"
567                    "red4"
568                    "red3"
569                    "red2"
570                    "red1"
571                    "OrangeRed4"
572                    "OrangeRed3"
573                    "OrangeRed2"
574                    "OrangeRed1"
575                    "tomato4"
576                    "tomato3"
577                    "tomato2"
578                    "tomato1"
579                    "coral4"
580                    "coral3"
581                    "coral2"
582                    "coral1"
583                    "DarkOrange4"
584                    "DarkOrange3"
585                    "DarkOrange2"
586                    "DarkOrange1"
587                    "orange4"
588                    "orange3"
589                    "orange2"
590                    "orange1"
591                    "LightSalmon4"
592                    "LightSalmon3"
593                    "LightSalmon2"
594                    "LightSalmon1"
595                    "salmon4"
596                    "salmon3"
597                    "salmon2"
598                    "salmon1"
599                    "brown4"
600                    "brown3"
601                    "brown2"
602                    "brown1"
603                    "firebrick4"
604                    "firebrick3"
605                    "firebrick2"
606                    "firebrick1"
607                    "chocolate4"
608                    "chocolate3"
609                    "chocolate2"
610                    "chocolate1"
611                    "tan4"
612                    "tan3"
613                    "tan2"
614                    "tan1"
615                    "wheat4"
616                    "wheat3"
617                    "wheat2"
618                    "wheat1"
619                    "burlywood4"
620                    "burlywood3"
621                    "burlywood2"
622                    "burlywood1"
623                    "sienna4"
624                    "sienna3"
625                    "sienna2"
626                    "sienna1"
627                    "IndianRed4"
628                    "IndianRed3"
629                    "IndianRed2"
630                    "IndianRed1"
631                    "RosyBrown4"
632                    "RosyBrown3"
633                    "RosyBrown2"
634                    "RosyBrown1"
635                    "DarkGoldenrod4"
636                    "DarkGoldenrod3"
637                    "DarkGoldenrod2"
638                    "DarkGoldenrod1"
639                    "goldenrod4"
640                    "goldenrod3"
641                    "goldenrod2"
642                    "goldenrod1"
643                    "gold4"
644                    "gold3"
645                    "gold2"
646                    "gold1"
647                    "yellow4"
648                    "yellow3"
649                    "yellow2"
650                    "yellow1"
651                    "LightYellow4"
652                    "LightYellow3"
653                    "LightYellow2"
654                    "LightYellow1"
655                    "LightGoldenrod4"
656                    "LightGoldenrod3"
657                    "LightGoldenrod2"
658                    "LightGoldenrod1"
659                    "khaki4"
660                    "khaki3"
661                    "khaki2"
662                    "khaki1"
663                    "DarkOliveGreen4"
664                    "DarkOliveGreen3"
665                    "DarkOliveGreen2"
666                    "DarkOliveGreen1"
667                    "OliveDrab4"
668                    "OliveDrab3"
669                    "OliveDrab2"
670                    "OliveDrab1"
671                    "chartreuse4"
672                    "chartreuse3"
673                    "chartreuse2"
674                    "chartreuse1"
675                    "green4"
676                    "green3"
677                    "green2"
678                    "green1"
679                    "SpringGreen4"
680                    "SpringGreen3"
681                    "SpringGreen2"
682                    "SpringGreen1"
683                    "PaleGreen4"
684                    "PaleGreen3"
685                    "PaleGreen2"
686                    "PaleGreen1"
687                    "SeaGreen4"
688                    "SeaGreen3"
689                    "SeaGreen2"
690                    "SeaGreen1"
691                    "DarkSeaGreen4"
692                    "DarkSeaGreen3"
693                    "DarkSeaGreen2"
694                    "DarkSeaGreen1"
695                    "aquamarine4"
696                    "aquamarine3"
697                    "aquamarine2"
698                    "aquamarine1"
699                    "DarkSlateGray4"
700                    "DarkSlateGray3"
701                    "DarkSlateGray2"
702                    "DarkSlateGray1"
703                    "cyan4"
704                    "cyan3"
705                    "cyan2"
706                    "cyan1"
707                    "turquoise4"
708                    "turquoise3"
709                    "turquoise2"
710                    "turquoise1"
711                    "CadetBlue4"
712                    "CadetBlue3"
713                    "CadetBlue2"
714                    "CadetBlue1"
715                    "PaleTurquoise4"
716                    "PaleTurquoise3"
717                    "PaleTurquoise2"
718                    "PaleTurquoise1"
719                    "LightCyan4"
720                    "LightCyan3"
721                    "LightCyan2"
722                    "LightCyan1"
723</