]> code.delx.au - gnu-emacs/blob - lisp/term/mac-win.el
* term/news.el (terminal-init-news):
[gnu-emacs] / lisp / term / mac-win.el
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 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 \f
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 \f
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 \f
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 "LightBlue4"
724 "LightBlue3"
725 "LightBlue2"
726 "LightBlue1"
727 "LightSteelBlue4"
728 "LightSteelBlue3"
729 "LightSteelBlue2"
730 "LightSteelBlue1"
731 "SlateGray4"
732 "SlateGray3"
733 "SlateGray2"
734 "SlateGray1"
735 "LightSkyBlue4"
736 "LightSkyBlue3"
737 "LightSkyBlue2"
738 "LightSkyBlue1"
739 "SkyBlue4"
740 "SkyBlue3"
741 "SkyBlue2"
742 "SkyBlue1"
743 "DeepSkyBlue4"
744 "DeepSkyBlue3"
745 "DeepSkyBlue2"
746 "DeepSkyBlue1"
747 "SteelBlue4"
748 "SteelBlue3"
749 "SteelBlue2"
750 "SteelBlue1"
751 "DodgerBlue4"
752 "DodgerBlue3"
753 "DodgerBlue2"
754 "DodgerBlue1"
755 "blue4"
756 "blue3"
757 "blue2"
758 "blue1"
759 "RoyalBlue4"
760 "RoyalBlue3"
761 "RoyalBlue2"
762 "RoyalBlue1"
763 "SlateBlue4"
764 "SlateBlue3"
765 "SlateBlue2"
766 "SlateBlue1"
767 "azure4"
768 "azure3"
769 "azure2"
770 "azure1"
771 "MistyRose4"
772 "MistyRose3"
773 "MistyRose2"
774 "MistyRose1"
775 "LavenderBlush4"
776 "LavenderBlush3"
777 "LavenderBlush2"
778 "LavenderBlush1"
779 "honeydew4"
780 "honeydew3"
781 "honeydew2"
782 "honeydew1"
783 "ivory4"
784 "ivory3"
785 "ivory2"
786 "ivory1"
787 "cornsilk4"
788 "cornsilk3"
789 "cornsilk2"
790 "cornsilk1"
791 "LemonChiffon4"
792 "LemonChiffon3"
793 "LemonChiffon2"
794 "LemonChiffon1"
795 "NavajoWhite4"
796 "NavajoWhite3"
797 "NavajoWhite2"
798 "NavajoWhite1"
799 "PeachPuff4"
800 "PeachPuff3"
801 "PeachPuff2"
802 "PeachPuff1"
803 "bisque4"
804 "bisque3"
805 "bisque2"
806 "bisque1"
807 "AntiqueWhite4"
808 "AntiqueWhite3"
809 "AntiqueWhite2"
810 "AntiqueWhite1"
811 "seashell4"
812 "seashell3"
813 "seashell2"
814 "seashell1"
815 "snow4"
816 "snow3"
817 "snow2"
818 "snow1"
819 "thistle"
820 "MediumPurple"
821 "medium purple"
822 "purple"
823 "BlueViolet"
824 "blue violet"
825 "DarkViolet"
826 "dark violet"
827 "DarkOrchid"
828 "dark orchid"
829 "MediumOrchid"
830 "medium orchid"
831 "orchid"
832 "plum"
833 "violet"
834 "magenta"
835 "VioletRed"
836 "violet red"
837 "MediumVioletRed"
838 "medium violet red"
839 "maroon"
840 "PaleVioletRed"
841 "pale violet red"
842 "LightPink"
843 "light pink"
844 "pink"
845 "DeepPink"
846 "deep pink"
847 "HotPink"
848 "hot pink"
849 "red"
850 "OrangeRed"
851 "orange red"
852 "tomato"
853 "LightCoral"
854 "light coral"
855 "coral"
856 "DarkOrange"
857 "dark orange"
858 "orange"
859 "LightSalmon"
860 "light salmon"
861 "salmon"
862 "DarkSalmon"
863 "dark salmon"
864 "brown"
865 "firebrick"
866 "chocolate"
867 "tan"
868 "SandyBrown"
869 "sandy brown"
870 "wheat"
871 "beige"
872 "burlywood"
873 "peru"
874 "sienna"
875 "SaddleBrown"
876 "saddle brown"
877 "IndianRed"
878 "indian red"
879 "RosyBrown"
880 "rosy brown"
881 "DarkGoldenrod"
882 "dark goldenrod"
883 "goldenrod"
884 "LightGoldenrod"
885 "light goldenrod"
886 "gold"
887 "yellow"
888 "LightYellow"
889 "light yellow"
890 "LightGoldenrodYellow"
891 "light goldenrod yellow"
892 "PaleGoldenrod"
893 "pale goldenrod"
894 "khaki"
895 "DarkKhaki"
896 "dark khaki"
897 "OliveDrab"
898 "olive drab"
899 "ForestGreen"
900 "forest green"
901 "YellowGreen"
902 "yellow green"
903 "LimeGreen"
904 "lime green"
905 "GreenYellow"
906 "green yellow"
907 "MediumSpringGreen"
908 "medium spring green"
909 "chartreuse"
910 "green"
911 "LawnGreen"
912 "lawn green"
913 "SpringGreen"
914 "spring green"
915 "PaleGreen"
916 "pale green"
917 "LightSeaGreen"
918 "light sea green"
919 "MediumSeaGreen"
920 "medium sea green"
921 "SeaGreen"
922 "sea green"
923 "DarkSeaGreen"
924 "dark sea green"
925 "DarkOliveGreen"
926 "dark olive green"
927 "DarkGreen"
928 "dark green"
929 "aquamarine"
930 "MediumAquamarine"
931 "medium aquamarine"
932 "CadetBlue"
933 "cadet blue"
934 "LightCyan"
935 "light cyan"
936 "cyan"
937 "turquoise"
938 "MediumTurquoise"
939 "medium turquoise"
940 "DarkTurquoise"
941 "dark turquoise"
942 "PaleTurquoise"
943 "pale turquoise"
944 "PowderBlue"
945 "powder blue"
946 "LightBlue"
947 "light blue"
948 "LightSteelBlue"
949 "light steel blue"
950 "SteelBlue"
951 "steel blue"
952 "LightSkyBlue"
953 "light sky blue"
954 "SkyBlue"
955 "sky blue"
956 "DeepSkyBlue"
957 "deep sky blue"
958 "DodgerBlue"
959 "dodger blue"
960 "blue"
961 "RoyalBlue"
962 "royal blue"
963 "MediumBlue"
964 "medium blue"
965 "LightSlateBlue"
966 "light slate blue"
967 "MediumSlateBlue"
968 "medium slate blue"
969 "SlateBlue"
970 "slate blue"
971 "DarkSlateBlue"
972 "dark slate blue"
973 "CornflowerBlue"
974 "cornflower blue"
975 "NavyBlue"
976 "navy blue"
977 "navy"
978 "MidnightBlue"
979 "midnight blue"
980 "LightGray"
981 "light gray"
982 "LightGrey"
983 "light grey"
984 "grey"
985 "gray"
986 "LightSlateGrey"
987 "light slate grey"
988 "LightSlateGray"
989 "light slate gray"
990 "SlateGrey"
991 "slate grey"
992 "SlateGray"
993 "slate gray"
994 "DimGrey"
995 "dim grey"
996 "DimGray"
997 "dim gray"
998 "DarkSlateGrey"
999 "dark slate grey"
1000 "DarkSlateGray"
1001 "dark slate gray"
1002 "black"
1003 "white"
1004 "MistyRose"
1005 "misty rose"
1006 "LavenderBlush"
1007 "lavender blush"
1008 "lavender"
1009 "AliceBlue"
1010 "alice blue"
1011 "azure"
1012 "MintCream"
1013 "mint cream"
1014 "honeydew"
1015 "seashell"
1016 "LemonChiffon"
1017 "lemon chiffon"
1018 "ivory"
1019 "cornsilk"
1020 "moccasin"
1021 "NavajoWhite"
1022 "navajo white"
1023 "PeachPuff"
1024 "peach puff"
1025 "bisque"
1026 "BlanchedAlmond"
1027 "blanched almond"
1028 "PapayaWhip"
1029 "papaya whip"
1030 "AntiqueWhite"
1031 "antique white"
1032 "linen"
1033 "OldLace"
1034 "old lace"
1035 "FloralWhite"
1036 "floral white"
1037 "gainsboro"
1038 "WhiteSmoke"
1039 "white smoke"
1040 "GhostWhite"
1041 "ghost white"
1042 "snow")
1043 "The list of X colors from the `rgb.txt' file.
1044 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1045
1046 (defun xw-defined-colors (&optional frame)
1047 "Internal function called by `defined-colors', which see."
1048 (or frame (setq frame (selected-frame)))
1049 (let ((all-colors x-colors)
1050 (this-color nil)
1051 (defined-colors nil))
1052 (while all-colors
1053 (setq this-color (car all-colors)
1054 all-colors (cdr all-colors))
1055 (and (color-supported-p this-color frame t)
1056 (setq defined-colors (cons this-color defined-colors))))
1057 defined-colors))
1058 \f
1059 ;;;; Function keys
1060
1061 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1062 global-map)
1063
1064 (defun x-setup-function-keys (frame)
1065 "Setup Function Keys for mac."
1066 ;; Map certain keypad keys into ASCII characters
1067 ;; that people usually expect.
1068 (define-key local-function-key-map [backspace] [?\d])
1069 (define-key local-function-key-map [delete] [?\d])
1070 (define-key local-function-key-map [tab] [?\t])
1071 (define-key local-function-key-map [linefeed] [?\n])
1072 (define-key local-function-key-map [clear] [?\C-l])
1073 (define-key local-function-key-map [return] [?\C-m])
1074 (define-key local-function-key-map [escape] [?\e])
1075 (define-key local-function-key-map [M-backspace] [?\M-\d])
1076 (define-key local-function-key-map [M-delete] [?\M-\d])
1077 (define-key local-function-key-map [M-tab] [?\M-\t])
1078 (define-key local-function-key-map [M-linefeed] [?\M-\n])
1079 (define-key local-function-key-map [M-clear] [?\M-\C-l])
1080 (define-key local-function-key-map [M-return] [?\M-\C-m])
1081 (define-key local-function-key-map [M-escape] [?\M-\e])
1082 )
1083
1084 ;; These tell read-char how to convert
1085 ;; these special chars to ASCII.
1086 (put 'backspace 'ascii-character ?\d)
1087 (put 'delete 'ascii-character ?\d)
1088 (put 'tab 'ascii-character ?\t)
1089 (put 'linefeed 'ascii-character ?\n)
1090 (put 'clear 'ascii-character ?\C-l)
1091 (put 'return 'ascii-character ?\C-m)
1092 (put 'escape 'ascii-character ?\e)
1093
1094 ;; Modifier name `ctrl' is an alias of `control'.
1095 (put 'ctrl 'modifier-value (get 'control 'modifier-value))
1096
1097 \f
1098 ;;;; Script codes and coding systems
1099 (defconst mac-script-code-coding-systems
1100 '((0 . mac-roman) ; smRoman
1101 (1 . japanese-shift-jis) ; smJapanese
1102 (2 . chinese-big5) ; smTradChinese
1103 (3 . korean-iso-8bit) ; smKorean
1104 (7 . mac-cyrillic) ; smCyrillic
1105 (25 . chinese-iso-8bit) ; smSimpChinese
1106 (29 . mac-centraleurroman) ; smCentralEuroRoman
1107 )
1108 "Alist of Mac script codes vs Emacs coding systems.")
1109
1110 (defun mac-add-charset-info (xlfd-charset mac-text-encoding)
1111 "Add a character set to display with Mac fonts.
1112 Create an entry in `mac-charset-info-alist'.
1113 XLFD-CHARSET is a string which will appear in the XLFD font name
1114 to identify the character set. MAC-TEXT-ENCODING is the
1115 correspoinding TextEncodingBase value."
1116 (add-to-list 'mac-charset-info-alist
1117 (list xlfd-charset mac-text-encoding
1118 (cdr (assq mac-text-encoding
1119 mac-script-code-coding-systems)))))
1120
1121 (setq mac-charset-info-alist nil)
1122 (mac-add-charset-info "mac-roman" 0)
1123 (mac-add-charset-info "jisx0208.1983-sjis" 1)
1124 (mac-add-charset-info "jisx0201.1976-0" 1)
1125 (mac-add-charset-info "big5-0" 2)
1126 (mac-add-charset-info "ksc5601.1989-0" 3)
1127 (mac-add-charset-info "mac-cyrillic" 7)
1128 (mac-add-charset-info "gb2312.1980-0" 25)
1129 (mac-add-charset-info "mac-centraleurroman" 29)
1130 (mac-add-charset-info "mac-symbol" 33)
1131 (mac-add-charset-info "adobe-fontspecific" 33) ; for X-Symbol
1132 (mac-add-charset-info "mac-dingbats" 34)
1133 (mac-add-charset-info "iso10646-1" 126) ; for ATSUI
1134
1135 (cp-make-coding-system
1136 mac-centraleurroman
1137 [?\\e,AD\e(B ?\\e$,1 \e(B ?\\e$,1 !\e(B ?\\e,AI\e(B ?\\e$,1 $\e(B ?\\e,AV\e(B ?\\e,A\\e(B ?\\e,Aa\e(B ?\\e$,1 %\e(B ?\\e$,1 ,\e(B ?\\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?\\e$,1ry\e(B ?\\e,Aw\e(B ?\\e$,2"*\e(B ?\\e$,1 m\e(B ?\\e$,1 t\e(B ?\\e$,1 u\e(B ?\\e$,1 x\e(B ?\\e$,1s9\e(B ?\\e$,1s:\e(B ?\\e$,1 y\e(B ?\\e$,1 v\e(B
1143 ?\\e$,1 w\e(B ?\\e$,1! \e(B ?\\e$,1rz\e(B ?\\e$,1r~\e(B ?\\e$,1!!\e(B ?\\e$,1 z\e(B ?\\e$,1 {\e(B ?\\e,AA\e(B ?\\e$,1!$\e(B ?\\e$,1!%\e(B ?\\e,AM\e(B ?\\e$,1!=\e(B ?\\e$,1!>\e(B ?\\e$,1!*\e(B ?\\e,AS\e(B ?\\e,AT\e(B
1144 ?\\e$,1!+\e(B ?\\e$,1!.\e(B ?\\e,AZ\e(B ?\\e$,1!/\e(B ?\\e$,1!0\e(B ?\\e$,1!1\e(B ?\\e$,1!2\e(B ?\\e$,1!3\e(B ?\\e,A]\e(B ?\\e,A}\e(B ?\\e$,1 W\e(B ?\\e$,1!;\e(B ?\\e$,1 a\e(B ?\\e$,1!<\e(B ?\\e$,1 B\e(B ?\\e$,1$g\e(B]
1145 "Mac Central European Roman Encoding (MIME:x-mac-centraleurroman).")
1146 (coding-system-put 'mac-centraleurroman 'mime-charset 'x-mac-centraleurroman)
1147
1148 (cp-make-coding-system
1149 mac-cyrillic
1150 [?\\e$,1(0\e(B ?\\e$,1(1\e(B ?\\e$,1(2\e(B ?\\e$,1(3\e(B ?\\e$,1(4\e(B ?\\e$,1(5\e(B ?\\e$,1(6\e(B ?\\e$,1(7\e(B ?\\e$,1(8\e(B ?\\e$,1(9\e(B ?\\e$,1(:\e(B ?\\e$,1(;\e(B ?\\e$,1(<\e(B ?\\e$,1(=\e(B ?\\e$,1(>\e(B ?\\e$,1(?\e(B
1151 ?\\e$,1(@\e(B ?\\e$,1(A\e(B ?\\e$,1(B\e(B ?\\e$,1(C\e(B ?\\e$,1(D\e(B ?\\e$,1(E\e(B ?\\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\e(B
1169 ?\\e$,1' \e(B ?\\e$,1&x\e(B ?\\e$,1'!\e(B ?\\e$,1'#\e(B ?\\e$,1'$\e(B ?\\e$,1'%\e(B ?\\e$,1'B\e(B ?\\e$,1')\e(B ?\\e$,1&~\e(B ?\\e$,1'(\e(B ?\\e$,1&v\e(B ?\[ ?\\e$,1xT\e(B ?\] ?\\e$,1ye\e(B ?\_
1170 ?\\e$,3bE\e(B ?\\e$,1'1\e(B ?\\e$,1'2\e(B ?\\e$,1'G\e(B ?\\e$,1'4\e(B ?\\e$,1'5\e(B ?\\e$,1'F\e(B ?\\e$,1'3\e(B ?\\e$,1'7\e(B ?\\e$,1'9\e(B ?\\e$,1'U\e(B ?\\e$,1':\e(B ?\\e$,1';\e(B ?\\e$,1'<\e(B ?\\e$,1'=\e(B ?\\e$,1'?\e(B
1171 ?\\e$,1'@\e(B ?\\e$,1'8\e(B ?\\e$,1'A\e(B ?\\e$,1'C\e(B ?\\e$,1'D\e(B ?\\e$,1'E\e(B ?\\e$,1'V\e(B ?\\e$,1'I\e(B ?\\e$,1'>\e(B ?\\e$,1'H\e(B ?\\e$,1'6\e(B ?\{ ?\| ?\} ?\\e$,1x\\e(B]
1172 (make-vector (- 160 127) nil)
1173 ;; mac-symbol (160..254) -> emacs-mule mapping
1174 ;; Mapping of the following characters are changed from the
1175 ;; original one:
1176 ;; 0xE2 0x00AE+0xF87F -> 0x00AE # REGISTERED SIGN, alternate: sans serif
1177 ;; 0xE3 0x00A9+0xF87F -> 0x00A9 # COPYRIGHT SIGN, alternate: sans serif
1178 ;; 0xE4 0x2122+0xF87F -> 0x2122 # TRADE MARK SIGN, alternate: sans serif
1179 [?\\e$,1tL\e(B ?\\e$,1'R\e(B ?\\e$,1s2\e(B ?\\e$,1y$\e(B ?\\e$,1sD\e(B ?\\e$,1x>\e(B ?\\e$,1!R\e(B ?\\e$,2#c\e(B ?\\e$,2#f\e(B ?\\e$,2#e\e(B ?\\e$,2#`\e(B ?\\e$,1vt\e(B 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(B ?\\e$,1{!\e(B ?\\e$,1|>\e(B ?\\e$,1|?\e(B ?\\e$,1|@\e(B ?\\e$,1|D\e(B ?\\e$,1|E\e(B ?\\e$,1|F\e(B ?\\e$,1|K\e(B ?\\e$,1|L\e(B ?\\e$,1|M\e(B
1185 nil]))
1186 translation-table)
1187 (setq translation-table
1188 (make-translation-table-from-vector encoding-vector))
1189 ;; (define-translation-table 'mac-symbol-decoder translation-table)
1190 (define-translation-table 'mac-symbol-encoder
1191 (char-table-extra-slot translation-table 0)))
1192
1193 (let
1194 ((encoding-vector
1195 (vconcat
1196 (make-vector 32 nil)
1197 ;; mac-dingbats (32..126) -> emacs-mule mapping
1198 [?\ ?\\e$,2%A\e(B ?\\e$,2%B\e(B ?\\e$,2%C\e(B ?\\e$,2%D\e(B ?\\e$,2"n\e(B ?\\e$,2%F\e(B ?\\e$,2%G\e(B ?\\e$,2%H\e(B ?\\e$,2%I\e(B ?\\e$,2"{\e(B ?\\e$,2"~\e(B ?\\e$,2%L\e(B ?\\e$,2%M\e(B ?\\e$,2%N\e(B ?\\e$,2%O\e(B
1199 ?\\e$,2%P\e(B ?\\e$,2%Q\e(B ?\\e$,2%R\e(B ?\\e$,2%S\e(B ?\\e$,2%T\e(B ?\\e$,2%U\e(B ?\\e$,2%V\e(B ?\\e$,2%W\e(B ?\\e$,2%X\e(B ?\\e$,2%Y\e(B ?\\e$,2%Z\e(B ?\\e$,2%[\e(B ?\\e$,2%\\e(B ?\\e$,2%]\e(B ?\\e$,2%^\e(B ?\\e$,2%_\e(B
1200 ?\\e$,2%`\e(B ?\\e$,2%a\e(B ?\\e$,2%b\e(B ?\\e$,2%c\e(B ?\\e$,2%d\e(B ?\\e$,2%e\e(B ?\\e$,2%f\e(B ?\\e$,2%g\e(B ?\\e$,2"e\e(B ?\\e$,2%i\e(B ?\\e$,2%j\e(B ?\\e$,2%k\e(B ?\\e$,2%l\e(B ?\\e$,2%m\e(B ?\\e$,2%n\e(B ?\\e$,2%o\e(B
1201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-\e(B ?\\e$,2'.\e(B ?\\e$,2'/\e(B
1214 nil
1215 ;; mac-dingbats (241..254) -> emacs-mule mapping
1216 ?\\e$,2'1\e(B ?\\e$,2'2\e(B ?\\e$,2'3\e(B ?\\e$,2'4\e(B ?\\e$,2'5\e(B ?\\e$,2'6\e(B ?\\e$,2'7\e(B ?\\e$,2'8\e(B ?\\e$,2'9\e(B ?\\e$,2':\e(B ?\\e$,2';\e(B ?\\e$,2'<\e(B ?\\e$,2'=\e(B ?\\e$,2'>\e(B
1217 nil]))
1218 translation-table)
1219 (setq translation-table
1220 (make-translation-table-from-vector encoding-vector))
1221 ;; (define-translation-table 'mac-dingbats-decoder translation-table)
1222 (define-translation-table 'mac-dingbats-encoder
1223 (char-table-extra-slot translation-table 0)))
1224
1225 (defconst mac-system-coding-system
1226 (let ((base (or (cdr (assq mac-system-script-code
1227 mac-script-code-coding-systems))
1228 'mac-roman)))
1229 (if (eq system-type 'darwin)
1230 base
1231 (coding-system-change-eol-conversion base 'mac)))
1232 "Coding system derived from the system script code.")
1233
1234 (set-selection-coding-system mac-system-coding-system)
1235
1236 \f
1237 ;;;; Keyboard layout/language change events
1238 (defun mac-handle-language-change (event)
1239 "Set keyboard coding system to what is specified in EVENT."
1240 (interactive "e")
1241 (let ((coding-system
1242 (cdr (assq (car (cadr event)) mac-script-code-coding-systems))))
1243 (set-keyboard-coding-system (or coding-system 'mac-roman))
1244 ;; MacJapanese maps reverse solidus to ?\x80.
1245 (if (eq coding-system 'japanese-shift-jis)
1246 (define-key key-translation-map [?\x80] "\\"))))
1247
1248 (define-key special-event-map [language-change] 'mac-handle-language-change)
1249
1250 \f
1251 ;;;; Conversion between common flavors and Lisp string.
1252
1253 (defconst mac-text-encoding-ascii #x600
1254 "ASCII text encoding.")
1255
1256 (defconst mac-text-encoding-mac-japanese-basic-variant #x20001
1257 "MacJapanese text encoding without Apple double-byte extensions.")
1258
1259 (defun mac-utxt-to-string (data &optional coding-system)
1260 (or coding-system (setq coding-system mac-system-coding-system))
1261 (let* ((encoding
1262 (and (eq system-type 'darwin)
1263 (eq (coding-system-base coding-system) 'japanese-shift-jis)
1264 mac-text-encoding-mac-japanese-basic-variant))
1265 (str (and (fboundp 'mac-code-convert-string)
1266 (mac-code-convert-string data nil
1267 (or encoding coding-system)))))
1268 (when str
1269 (setq str (decode-coding-string str coding-system))
1270 (if (eq encoding mac-text-encoding-mac-japanese-basic-variant)
1271 ;; Does it contain Apple one-byte extensions other than
1272 ;; reverse solidus?
1273 (if (string-match "[\xa0\xfd-\xff]" str)
1274 (setq str nil)
1275 ;; ASCII-only?
1276 (unless (mac-code-convert-string data nil mac-text-encoding-ascii)
1277 (subst-char-in-string ?\x5c ?\\e(J\\e(B str t)
1278 (subst-char-in-string ?\x80 ?\\ str t)))))
1279 (or str
1280 (decode-coding-string data
1281 (if (eq (byteorder) ?B) 'utf-16be 'utf-16le)))))
1282
1283 (defun mac-string-to-utxt (string &optional coding-system)
1284 (or coding-system (setq coding-system mac-system-coding-system))
1285 (let (data encoding)
1286 (when (and (fboundp 'mac-code-convert-string)
1287 (memq (coding-system-base coding-system)
1288 (find-coding-systems-string string)))
1289 (setq coding-system
1290 (coding-system-change-eol-conversion coding-system 'mac))
1291 (let ((str string))
1292 (when (and (eq system-type 'darwin)
1293 (eq coding-system 'japanese-shift-jis-mac))
1294 (setq encoding mac-text-encoding-mac-japanese-basic-variant)
1295 (setq str (subst-char-in-string ?\\ ?\x80 str))
1296 (subst-char-in-string ?\\e(J\\e(B ?\x5c str t)
1297 ;; ASCII-only?
1298 (if (string-match "\\`[\x00-\x7f]*\\'" str)
1299 (setq str nil)))
1300 (and str
1301 (setq data (mac-code-convert-string
1302 (encode-coding-string str coding-system)
1303 (or encoding coding-system) nil)))))
1304 (or data (encode-coding-string string (if (eq (byteorder) ?B)
1305 'utf-16be-mac
1306 'utf-16le-mac)))))
1307
1308 (defun mac-TEXT-to-string (data &optional coding-system)
1309 (or coding-system (setq coding-system mac-system-coding-system))
1310 (prog1 (setq data (decode-coding-string data coding-system))
1311 (when (eq (coding-system-base coding-system) 'japanese-shift-jis)
1312 ;; (subst-char-in-string ?\x5c ?\\e(J\\e(B data t)
1313 (subst-char-in-string ?\x80 ?\\ data t))))
1314
1315 (defun mac-string-to-TEXT (string &optional coding-system)
1316 (or coding-system (setq coding-system mac-system-coding-system))
1317 (let ((encodables (find-coding-systems-string string))
1318 (rest mac-script-code-coding-systems))
1319 (unless (memq (coding-system-base coding-system) encodables)
1320 (while (and rest (not (memq (cdar rest) encodables)))
1321 (setq rest (cdr rest)))
1322 (if rest
1323 (setq coding-system (cdar rest)))))
1324 (setq coding-system
1325 (coding-system-change-eol-conversion coding-system 'mac))
1326 (when (eq coding-system 'japanese-shift-jis-mac)
1327 ;; (setq string (subst-char-in-string ?\\ ?\x80 string))
1328 (setq string (subst-char-in-string ?\\e(J\\e(B ?\x5c string)))
1329 (encode-coding-string string coding-system))
1330
1331 (defun mac-furl-to-string (data)
1332 ;; Remove a trailing nul character.
1333 (let ((len (length data)))
1334 (if (and (> len 0) (= (aref data (1- len)) ?\0))
1335 (substring data 0 (1- len))
1336 data)))
1337
1338 (defun mac-TIFF-to-string (data &optional text)
1339 (prog1 (or text (setq text (copy-sequence " ")))
1340 (put-text-property 0 (length text) 'display (create-image data 'tiff t)
1341 text)))
1342 \f
1343 ;;;; Selections
1344
1345 ;;; We keep track of the last text selected here, so we can check the
1346 ;;; current selection against it, and avoid passing back our own text
1347 ;;; from x-get-selection-value.
1348 (defvar x-last-selected-text-clipboard nil
1349 "The value of the CLIPBOARD selection last time we selected or
1350 pasted text.")
1351 (defvar x-last-selected-text-primary nil
1352 "The value of the PRIMARY X selection last time we selected or
1353 pasted text.")
1354
1355 (defcustom x-select-enable-clipboard t
1356 "*Non-nil means cutting and pasting uses the clipboard.
1357 This is in addition to the primary selection."
1358 :type 'boolean
1359 :group 'killing)
1360
1361 ;;; Make TEXT, a string, the primary X selection.
1362 (defun x-select-text (text &optional push)
1363 (x-set-selection 'PRIMARY text)
1364 (setq x-last-selected-text-primary text)
1365 (if (not x-select-enable-clipboard)
1366 (setq x-last-selected-text-clipboard nil)
1367 (x-set-selection 'CLIPBOARD text)
1368 (setq x-last-selected-text-clipboard text))
1369 )
1370
1371 (defun x-get-selection (&optional type data-type)
1372 "Return the value of a selection.
1373 The argument TYPE (default `PRIMARY') says which selection,
1374 and the argument DATA-TYPE (default `STRING') says
1375 how to convert the data.
1376
1377 TYPE may be any symbol \(but nil stands for `PRIMARY'). However,
1378 only a few symbols are commonly used. They conventionally have
1379 all upper-case names. The most often used ones, in addition to
1380 `PRIMARY', are `SECONDARY' and `CLIPBOARD'.
1381
1382 DATA-TYPE is usually `STRING', but can also be one of the symbols
1383 in `selection-converter-alist', which see."
1384 (let ((data (x-get-selection-internal (or type 'PRIMARY)
1385 (or data-type 'STRING)))
1386 (coding (or next-selection-coding-system
1387 selection-coding-system)))
1388 (when (and (stringp data)
1389 (setq data-type (get-text-property 0 'foreign-selection data)))
1390 (cond ((eq data-type 'public.utf16-plain-text)
1391 (setq data (mac-utxt-to-string data coding)))
1392 ((eq data-type 'com.apple.traditional-mac-plain-text)
1393 (setq data (mac-TEXT-to-string data coding)))
1394 ((eq data-type 'public.file-url)
1395 (setq data (mac-furl-to-string data))))
1396 (put-text-property 0 (length data) 'foreign-selection data-type data))
1397 data))
1398
1399 (defun x-selection-value (type)
1400 (let ((data-types '(public.utf16-plain-text
1401 com.apple.traditional-mac-plain-text
1402 public.file-url))
1403 text tiff-image)
1404 (while (and (null text) data-types)
1405 (setq text (condition-case nil
1406 (x-get-selection type (car data-types))
1407 (error nil)))
1408 (setq data-types (cdr data-types)))
1409 (if text
1410 (remove-text-properties 0 (length text) '(foreign-selection nil) text))
1411 (setq tiff-image (condition-case nil
1412 (x-get-selection type 'public.tiff)
1413 (error nil)))
1414 (when tiff-image
1415 (remove-text-properties 0 (length tiff-image)
1416 '(foreign-selection nil) tiff-image)
1417 (setq text (mac-TIFF-to-string tiff-image text)))
1418 text))
1419
1420 ;;; Return the value of the current selection.
1421 ;;; Treat empty strings as if they were unset.
1422 ;;; If this function is called twice and finds the same text,
1423 ;;; it returns nil the second time. This is so that a single
1424 ;;; selection won't be added to the kill ring over and over.
1425 (defun x-get-selection-value ()
1426 (let (clip-text primary-text)
1427 (if (not x-select-enable-clipboard)
1428 (setq x-last-selected-text-clipboard nil)
1429 (setq clip-text (x-selection-value 'CLIPBOARD))
1430 (if (string= clip-text "") (setq clip-text nil))
1431
1432 ;; Check the CLIPBOARD selection for 'newness', is it different
1433 ;; from what we remebered them to be last time we did a
1434 ;; cut/paste operation.
1435 (setq clip-text
1436 (cond;; check clipboard
1437 ((or (not clip-text) (string= clip-text ""))
1438 (setq x-last-selected-text-clipboard nil))
1439 ((eq clip-text x-last-selected-text-clipboard) nil)
1440 ((string= clip-text x-last-selected-text-clipboard)
1441 ;; Record the newer string,
1442 ;; so subsequent calls can use the `eq' test.
1443 (setq x-last-selected-text-clipboard clip-text)
1444 nil)
1445 (t
1446 (setq x-last-selected-text-clipboard clip-text))))
1447 )
1448
1449 (setq primary-text (x-selection-value 'PRIMARY))
1450 ;; Check the PRIMARY selection for 'newness', is it different
1451 ;; from what we remebered them to be last time we did a
1452 ;; cut/paste operation.
1453 (setq primary-text
1454 (cond;; check primary selection
1455 ((or (not primary-text) (string= primary-text ""))
1456 (setq x-last-selected-text-primary nil))
1457 ((eq primary-text x-last-selected-text-primary) nil)
1458 ((string= primary-text x-last-selected-text-primary)
1459 ;; Record the newer string,
1460 ;; so subsequent calls can use the `eq' test.
1461 (setq x-last-selected-text-primary primary-text)
1462 nil)
1463 (t
1464 (setq x-last-selected-text-primary primary-text))))
1465
1466 ;; As we have done one selection, clear this now.
1467 (setq next-selection-coding-system nil)
1468
1469 ;; At this point we have recorded the current values for the
1470 ;; selection from clipboard (if we are supposed to) and primary,
1471 ;; So return the first one that has changed (which is the first
1472 ;; non-null one).
1473 (or clip-text primary-text)
1474 ))
1475
1476 (put 'CLIPBOARD 'mac-scrap-name "com.apple.scrap.clipboard")
1477 (when (eq system-type 'darwin)
1478 (put 'FIND 'mac-scrap-name "com.apple.scrap.find")
1479 (put 'PRIMARY 'mac-scrap-name
1480 (format "org.gnu.Emacs.%d.selection.PRIMARY" (emacs-pid))))
1481 (put 'com.apple.traditional-mac-plain-text 'mac-ostype "TEXT")
1482 (put 'public.utf16-plain-text 'mac-ostype "utxt")
1483 (put 'public.tiff 'mac-ostype "TIFF")
1484 (put 'public.file-url 'mac-ostype "furl")
1485
1486 (defun mac-select-convert-to-string (selection type value)
1487 (let ((str (cdr (xselect-convert-to-string selection nil value)))
1488 (coding (or next-selection-coding-system selection-coding-system)))
1489 (when str
1490 ;; If TYPE is nil, this is a local request, thus return STR as
1491 ;; is. Otherwise, encode STR.
1492 (if (not type)
1493 str
1494 (let ((inhibit-read-only t))
1495 (remove-text-properties 0 (length str) '(composition nil) str)
1496 (cond
1497 ((eq type 'public.utf16-plain-text)
1498 (setq str (mac-string-to-utxt str coding)))
1499 ((eq type 'com.apple.traditional-mac-plain-text)
1500 (setq str (mac-string-to-TEXT str coding)))
1501 (t
1502 (error "Unknown selection type: %S" type))
1503 )))
1504
1505 (setq next-selection-coding-system nil)
1506 (cons type str))))
1507
1508 (defun mac-select-convert-to-file-url (selection type value)
1509 (let ((filename (xselect-convert-to-filename selection type value))
1510 (coding (or file-name-coding-system default-file-name-coding-system)))
1511 (if (and filename coding)
1512 (setq filename (encode-coding-string filename coding)))
1513 (and filename
1514 (concat "file://localhost"
1515 (mapconcat 'url-hexify-string
1516 (split-string filename "/") "/")))))
1517
1518 (setq selection-converter-alist
1519 (nconc
1520 '((public.utf16-plain-text . mac-select-convert-to-string)
1521 (com.apple.traditional-mac-plain-text . mac-select-convert-to-string)
1522 ;; This is not enabled by default because the `Import Image'
1523 ;; menu makes Emacs crash or hang for unknown reasons.
1524 ;; (public.tiff . nil)
1525 (public.file-url . mac-select-convert-to-file-url)
1526 )
1527 selection-converter-alist))
1528 \f
1529 ;;;; Apple events, HICommand events, and Services menu
1530
1531 ;;; Event classes
1532 (put 'core-event 'mac-apple-event-class "aevt") ; kCoreEventClass
1533 (put 'internet-event 'mac-apple-event-class "GURL") ; kAEInternetEventClass
1534
1535 ;;; Event IDs
1536 ;; kCoreEventClass
1537 (put 'open-application 'mac-apple-event-id "oapp") ; kAEOpenApplication
1538 (put 'reopen-application 'mac-apple-event-id "rapp") ; kAEReopenApplication
1539 (put 'open-documents 'mac-apple-event-id "odoc") ; kAEOpenDocuments
1540 (put 'print-documents 'mac-apple-event-id "pdoc") ; kAEPrintDocuments
1541 (put 'open-contents 'mac-apple-event-id "ocon") ; kAEOpenContents
1542 (put 'quit-application 'mac-apple-event-id "quit") ; kAEQuitApplication
1543 (put 'application-died 'mac-apple-event-id "obit") ; kAEApplicationDied
1544 (put 'show-preferences 'mac-apple-event-id "pref") ; kAEShowPreferences
1545 (put 'autosave-now 'mac-apple-event-id "asav") ; kAEAutosaveNow
1546 ;; kAEInternetEventClass
1547 (put 'get-url 'mac-apple-event-id "GURL") ; kAEGetURL
1548 ;; Converted HI command events
1549 (put 'about 'mac-apple-event-id "abou") ; kHICommandAbout
1550 (put 'show-hide-font-panel 'mac-apple-event-id "shfp") ; kHICommandShowHideFontPanel
1551
1552 (defmacro mac-event-spec (event)
1553 `(nth 1 ,event))
1554
1555 (defmacro mac-event-ae (event)
1556 `(nth 2 ,event))
1557
1558 (defun mac-ae-parameter (ae &optional keyword type)
1559 (or keyword (setq keyword "----")) ;; Direct object.
1560 (if (not (and (consp ae) (equal (car ae) "aevt")))
1561 (error "Not an Apple event: %S" ae)
1562 (let ((type-data (cdr (assoc keyword (cdr ae))))
1563 data)
1564 (when (and type type-data (not (equal type (car type-data))))
1565 (setq data (mac-coerce-ae-data (car type-data) (cdr type-data) type))
1566 (setq type-data (if data (cons type data) nil)))
1567 type-data)))
1568
1569 (defun mac-ae-list (ae &optional keyword type)
1570 (or keyword (setq keyword "----")) ;; Direct object.
1571 (let ((desc (mac-ae-parameter ae keyword "list")))
1572 (cond ((null desc)
1573 nil)
1574 ((not (equal (car desc) "list"))
1575 (error "Parameter for \"%s\" is not a list" keyword))
1576 (t
1577 (if (null type)
1578 (cdr desc)
1579 (mapcar
1580 (lambda (type-data)
1581 (mac-coerce-ae-data (car type-data) (cdr type-data) type))
1582 (cdr desc)))))))
1583
1584 (defun mac-ae-number (ae keyword)
1585 (let ((type-data (mac-ae-parameter ae keyword))
1586 str)
1587 (if (and type-data
1588 (setq str (mac-coerce-ae-data (car type-data)
1589 (cdr type-data) "TEXT")))
1590 (let ((num (string-to-number str)))
1591 ;; Mac OS Classic may return "0e+0" as the coerced value for
1592 ;; the type "magn" and the data "\000\000\000\000".
1593 (if (= num 0.0) 0 num))
1594 nil)))
1595
1596 (defun mac-bytes-to-integer (bytes &optional from to)
1597 (or from (setq from 0))
1598 (or to (setq to (length bytes)))
1599 (let* ((len (- to from))
1600 (extended-sign-len (- (1+ (ceiling (log most-positive-fixnum 2)))
1601 (* 8 len)))
1602 (result 0))
1603 (dotimes (i len)
1604 (setq result (logior (lsh result 8)
1605 (aref bytes (+ from (if (eq (byteorder) ?B) i
1606 (- len i 1)))))))
1607 (if (> extended-sign-len 0)
1608 (ash (lsh result extended-sign-len) (- extended-sign-len))
1609 result)))
1610
1611 (defun mac-ae-selection-range (ae)
1612 ;; #pragma options align=mac68k
1613 ;; typedef struct SelectionRange {
1614 ;; short unused1; // 0 (not used)
1615 ;; short lineNum; // line to select (<0 to specify range)
1616 ;; long startRange; // start of selection range (if line < 0)
1617 ;; long endRange; // end of selection range (if line < 0)
1618 ;; long unused2; // 0 (not used)
1619 ;; long theDate; // modification date/time
1620 ;; } SelectionRange;
1621 ;; #pragma options align=reset
1622 (let ((range-bytes (cdr (mac-ae-parameter ae "kpos" "TEXT"))))
1623 (and range-bytes
1624 (list (mac-bytes-to-integer range-bytes 2 4)
1625 (mac-bytes-to-integer range-bytes 4 8)
1626 (mac-bytes-to-integer range-bytes 8 12)
1627 (mac-bytes-to-integer range-bytes 16 20)))))
1628
1629 ;; On Mac OS X 10.4 and later, the `open-document' event contains an
1630 ;; optional parameter keyAESearchText from the Spotlight search.
1631 (defun mac-ae-text-for-search (ae)
1632 (let ((utf8-text (cdr (mac-ae-parameter ae "stxt" "utf8"))))
1633 (and utf8-text
1634 (decode-coding-string utf8-text 'utf-8))))
1635
1636 (defun mac-ae-text (ae)
1637 (or (cdr (mac-ae-parameter ae nil "TEXT"))
1638 (error "No text in Apple event.")))
1639
1640 (defun mac-ae-frame (ae &optional keyword type)
1641 (let ((bytes (cdr (mac-ae-parameter ae keyword type))))
1642 (if (or (null bytes) (/= (length bytes) 4))
1643 (error "No window reference in Apple event.")
1644 (let ((window-id (mac-coerce-ae-data "long" bytes "TEXT"))
1645 (rest (frame-list))
1646 frame)
1647 (while (and (null frame) rest)
1648 (if (string= (frame-parameter (car rest) 'window-id) window-id)
1649 (setq frame (car rest)))
1650 (setq rest (cdr rest)))
1651 frame))))
1652
1653 (defun mac-ae-script-language (ae keyword)
1654 ;; struct WritingCode {
1655 ;; ScriptCode theScriptCode;
1656 ;; LangCode theLangCode;
1657 ;; };
1658 (let ((bytes (cdr (mac-ae-parameter ae keyword "intl"))))
1659 (and bytes
1660 (cons (mac-bytes-to-integer bytes 0 2)
1661 (mac-bytes-to-integer bytes 2 4)))))
1662
1663 (defun mac-bytes-to-text-range (bytes &optional from to)
1664 ;; struct TextRange {
1665 ;; long fStart;
1666 ;; long fEnd;
1667 ;; short fHiliteStyle;
1668 ;; };
1669 (or from (setq from 0))
1670 (or to (setq to (length bytes)))
1671 (and (= (- to from) (+ 4 4 2))
1672 (list (mac-bytes-to-integer bytes from (+ from 4))
1673 (mac-bytes-to-integer bytes (+ from 4) (+ from 8))
1674 (mac-bytes-to-integer bytes (+ from 8) to))))
1675
1676 (defun mac-ae-text-range-array (ae keyword)
1677 ;; struct TextRangeArray {
1678 ;; short fNumOfRanges;
1679 ;; TextRange fRange[1];
1680 ;; };
1681 (let* ((bytes (cdr (mac-ae-parameter ae keyword "tray")))
1682 (len (length bytes))
1683 nranges result)
1684 (when (and bytes (>= len 2)
1685 (progn
1686 (setq nranges (mac-bytes-to-integer bytes 0 2))
1687 (= len (+ 2 (* nranges 10)))))
1688 (setq result (make-vector nranges nil))
1689 (dotimes (i nranges)
1690 (aset result i
1691 (mac-bytes-to-text-range bytes (+ (* i 10) 2)
1692 (+ (* i 10) 12)))))
1693 result))
1694
1695 (defconst mac-keyboard-modifier-mask-alist
1696 (mapcar
1697 (lambda (modifier-bit)
1698 (cons (car modifier-bit) (lsh 1 (cdr modifier-bit))))
1699 '((command . 8) ; cmdKeyBit
1700 (shift . 9) ; shiftKeyBit
1701 (option . 11) ; optionKeyBit
1702 (control . 12) ; controlKeyBit
1703 (function . 17))) ; kEventKeyModifierFnBit
1704 "Alist of Mac keyboard modifier symbols vs masks.")
1705
1706 (defun mac-ae-keyboard-modifiers (ae)
1707 (let ((modifiers-value (mac-ae-number ae "kmod"))
1708 modifiers)
1709 (if modifiers-value
1710 (dolist (modifier-mask mac-keyboard-modifier-mask-alist)
1711 (if (/= (logand modifiers-value (cdr modifier-mask)) 0)
1712 (setq modifiers (cons (car modifier-mask) modifiers)))))
1713 modifiers))
1714
1715 (defun mac-ae-reopen-application (event)
1716 "Show some frame in response to the Apple event EVENT.
1717 The frame to be shown is chosen from visible or iconified frames
1718 if possible. If there's no such frame, a new frame is created."
1719 (interactive "e")
1720 (unless (frame-visible-p (selected-frame))
1721 (let ((frame (or (car (visible-frame-list))
1722 (car (filtered-frame-list 'frame-visible-p)))))
1723 (if frame
1724 (select-frame frame)
1725 (switch-to-buffer-other-frame "*scratch*"))))
1726 (select-frame-set-input-focus (selected-frame)))
1727
1728 (defun mac-ae-open-documents (event)
1729 "Open the documents specified by the Apple event EVENT."
1730 (interactive "e")
1731 (let ((ae (mac-event-ae event)))
1732 (dolist (file-name (mac-ae-list ae nil 'undecoded-file-name))
1733 (if file-name
1734 (dnd-open-local-file
1735 (concat "file://"
1736 (mapconcat 'url-hexify-string
1737 (split-string file-name "/") "/")) nil)))
1738 (let ((selection-range (mac-ae-selection-range ae))
1739 (search-text (mac-ae-text-for-search ae)))
1740 (cond (selection-range
1741 (let ((line (car selection-range))
1742 (start (cadr selection-range))
1743 (end (nth 2 selection-range)))
1744 (if (> line 0)
1745 (goto-line line)
1746 (if (and (> start 0) (> end 0))
1747 (progn (set-mark start)
1748 (goto-char end))))))
1749 ((stringp search-text)
1750 (re-search-forward
1751 (mapconcat 'regexp-quote (split-string search-text) "\\|")
1752 nil t)))))
1753 (select-frame-set-input-focus (selected-frame)))
1754
1755 (defun mac-ae-quit-application (event)
1756 "Quit the application Emacs with the Apple event EVENT."
1757 (interactive "e")
1758 (let ((ae (mac-event-ae event)))
1759 (unwind-protect
1760 (save-buffers-kill-emacs)
1761 ;; Reaches here if the user has canceled the quit.
1762 (mac-resume-apple-event ae -128)))) ; userCanceledErr
1763
1764 (defun mac-ae-get-url (event)
1765 "Open the URL specified by the Apple event EVENT.
1766 Currently the `mailto' scheme is supported."
1767 (interactive "e")
1768 (let* ((ae (mac-event-ae event))
1769 (parsed-url (url-generic-parse-url (mac-ae-text ae))))
1770 (if (string= (url-type parsed-url) "mailto")
1771 (progn
1772 (url-mailto parsed-url)
1773 (select-frame-set-input-focus (selected-frame)))
1774 (mac-resume-apple-event ae t))))
1775
1776 (setq mac-apple-event-map (make-sparse-keymap))
1777
1778 ;; Received when Emacs is launched without associated documents.
1779 ;; Accept it as an Apple event, but no Emacs event is generated so as
1780 ;; not to erase the splash screen.
1781 (define-key mac-apple-event-map [core-event open-application] 0)
1782
1783 ;; Received when a dock or application icon is clicked and Emacs is
1784 ;; already running.
1785 (define-key mac-apple-event-map [core-event reopen-application]
1786 'mac-ae-reopen-application)
1787
1788 (define-key mac-apple-event-map [core-event open-documents]
1789 'mac-ae-open-documents)
1790 (define-key mac-apple-event-map [core-event show-preferences] 'customize)
1791 (define-key mac-apple-event-map [core-event quit-application]
1792 'mac-ae-quit-application)
1793
1794 (define-key mac-apple-event-map [internet-event get-url] 'mac-ae-get-url)
1795
1796 (define-key mac-apple-event-map [hi-command about] 'about-emacs)
1797
1798 ;;; Converted Carbon Events
1799 (defun mac-handle-toolbar-switch-mode (event)
1800 "Toggle visibility of tool-bars in response to EVENT.
1801 With no keyboard modifiers, it toggles the visibility of the
1802 frame where the tool-bar toggle button was pressed. With some
1803 modifiers, it changes the global tool-bar visibility setting."
1804 (interactive "e")
1805 (let ((ae (mac-event-ae event)))
1806 (if (mac-ae-keyboard-modifiers ae)
1807 ;; Globally toggle tool-bar-mode if some modifier key is pressed.
1808 (tool-bar-mode 'toggle)
1809 (let ((frame (mac-ae-frame ae)))
1810 (set-frame-parameter frame 'tool-bar-lines
1811 (if (= (frame-parameter frame 'tool-bar-lines) 0)
1812 1 0))))))
1813
1814 ;; kEventClassWindow/kEventWindowToolbarSwitchMode
1815 (define-key mac-apple-event-map [window toolbar-switch-mode]
1816 'mac-handle-toolbar-switch-mode)
1817
1818 ;;; Font panel
1819 (when (fboundp 'mac-set-font-panel-visible-p)
1820
1821 (define-minor-mode mac-font-panel-mode
1822 "Toggle use of the font panel.
1823 With numeric ARG, display the font panel if and only if ARG is positive."
1824 :init-value nil
1825 :global t
1826 :group 'mac
1827 (mac-set-font-panel-visible-p mac-font-panel-mode))
1828
1829 (defun mac-handle-font-panel-closed (event)
1830 "Update internal status in response to font panel closed EVENT."
1831 (interactive "e")
1832 ;; Synchronize with the minor mode variable.
1833 (mac-font-panel-mode 0))
1834
1835 (defun mac-handle-font-selection (event)
1836 "Change default face attributes according to font selection EVENT."
1837 (interactive "e")
1838 (let* ((ae (mac-event-ae event))
1839 (fm-font-size (mac-ae-number ae "fmsz"))
1840 (atsu-font-id (mac-ae-number ae "auid"))
1841 (attribute-values (and atsu-font-id
1842 (mac-atsu-font-face-attributes atsu-font-id))))
1843 (if fm-font-size
1844 (setq attribute-values
1845 `(:height ,(* 10 fm-font-size) ,@attribute-values)))
1846 (apply 'set-face-attribute 'default (selected-frame) attribute-values)))
1847
1848 ;; kEventClassFont/kEventFontPanelClosed
1849 (define-key mac-apple-event-map [font panel-closed]
1850 'mac-handle-font-panel-closed)
1851 ;; kEventClassFont/kEventFontSelection
1852 (define-key mac-apple-event-map [font selection] 'mac-handle-font-selection)
1853 (define-key mac-apple-event-map [hi-command show-hide-font-panel]
1854 'mac-font-panel-mode)
1855
1856 (define-key-after menu-bar-showhide-menu [mac-font-panel-mode]
1857 (menu-bar-make-mm-toggle mac-font-panel-mode
1858 "Font Panel"
1859 "Show the font panel as a floating dialog")
1860 'showhide-speedbar)
1861
1862 ) ;; (fboundp 'mac-set-font-panel-visible-p)
1863
1864 ;;; Text Services
1865 (defvar mac-ts-active-input-buf ""
1866 "Byte sequence of the current Mac TSM active input area.")
1867 (defvar mac-ts-update-active-input-area-seqno 0
1868 "Number of processed update-active-input-area events.")
1869 (setq mac-ts-active-input-overlay (make-overlay 0 0))
1870
1871 (defface mac-ts-caret-position
1872 '((t :inverse-video t))
1873 "Face for caret position in Mac TSM active input area.
1874 This is used when the active input area is displayed either in
1875 the echo area or in a buffer where the cursor is not displayed."
1876 :group 'mac)
1877
1878 (defface mac-ts-raw-text
1879 '((t :underline t))
1880 "Face for raw text in Mac TSM active input area."
1881 :group 'mac)
1882
1883 (defface mac-ts-selected-raw-text
1884 '((t :underline t))
1885 "Face for selected raw text in Mac TSM active input area."
1886 :group 'mac)
1887
1888 (defface mac-ts-converted-text
1889 '((((background dark)) :underline "gray20")
1890 (t :underline "gray80"))
1891 "Face for converted text in Mac TSM active input area."
1892 :group 'mac)
1893
1894 (defface mac-ts-selected-converted-text
1895 '((t :underline t))
1896 "Face for selected converted text in Mac TSM active input area."
1897 :group 'mac)
1898
1899 (defface mac-ts-block-fill-text
1900 '((t :underline t))
1901 "Face for block fill text in Mac TSM active input area."
1902 :group 'mac)
1903
1904 (defface mac-ts-outline-text
1905 '((t :underline t))
1906 "Face for outline text in Mac TSM active input area."
1907 :group 'mac)
1908
1909 (defface mac-ts-selected-text
1910 '((t :underline t))
1911 "Face for selected text in Mac TSM active input area."
1912 :group 'mac)
1913
1914 (defface mac-ts-no-hilite
1915 '((t :inherit default))
1916 "Face for no hilite in Mac TSM active input area."
1917 :group 'mac)
1918
1919 (defconst mac-ts-hilite-style-faces
1920 '((2 . mac-ts-raw-text) ; kTSMHiliteRawText
1921 (3 . mac-ts-selected-raw-text) ; kTSMHiliteSelectedRawText
1922 (4 . mac-ts-converted-text) ; kTSMHiliteConvertedText
1923 (5 . mac-ts-selected-converted-text) ; kTSMHiliteSelectedConvertedText
1924 (6 . mac-ts-block-fill-text) ; kTSMHiliteBlockFillText
1925 (7 . mac-ts-outline-text) ; kTSMHiliteOutlineText
1926 (8 . mac-ts-selected-text) ; kTSMHiliteSelectedText
1927 (9 . mac-ts-no-hilite)) ; kTSMHiliteNoHilite
1928 "Alist of Mac TSM hilite style vs Emacs face.")
1929
1930 (defun mac-ts-update-active-input-buf (text fix-len hilite-rng update-rng)
1931 (let ((buf-len (length mac-ts-active-input-buf))
1932 confirmed)
1933 (if (or (null update-rng)
1934 (/= (% (length update-rng) 2) 0))
1935 ;; The parameter is missing (or in a bad format). The
1936 ;; existing inline input session is completely replaced with
1937 ;; the new text.
1938 (setq mac-ts-active-input-buf text)
1939 ;; Otherwise, the current subtext specified by the (2*j)-th
1940 ;; range is replaced with the new subtext specified by the
1941 ;; (2*j+1)-th range.
1942 (let ((tail buf-len)
1943 (i (length update-rng))
1944 segments rng)
1945 (while (> i 0)
1946 (setq i (- i 2))
1947 (setq rng (aref update-rng i))
1948 (if (and (<= 0 (cadr rng)) (< (cadr rng) tail)
1949 (<= tail buf-len))
1950 (setq segments
1951 (cons (substring mac-ts-active-input-buf (cadr rng) tail)
1952 segments)))
1953 (setq tail (car rng))
1954 (setq rng (aref update-rng (1+ i)))
1955 (if (and (<= 0 (car rng)) (< (car rng) (cadr rng))
1956 (<= (cadr rng) (length text)))
1957 (setq segments
1958 (cons (substring text (car rng) (cadr rng))
1959 segments))))
1960 (if (and (< 0 tail) (<= tail buf-len))
1961 (setq segments
1962 (cons (substring mac-ts-active-input-buf 0 tail)
1963 segments)))
1964 (setq mac-ts-active-input-buf (apply 'concat segments))))
1965 (setq buf-len (length mac-ts-active-input-buf))
1966 ;; Confirm (a part of) inline input session.
1967 (cond ((< fix-len 0)
1968 ;; Entire inline session is being confirmed.
1969 (setq confirmed mac-ts-active-input-buf)
1970 (setq mac-ts-active-input-buf ""))
1971 ((= fix-len 0)
1972 ;; None of the text is being confirmed (yet).
1973 (setq confirmed ""))
1974 (t
1975 (if (> fix-len buf-len)
1976 (setq fix-len buf-len))
1977 (setq confirmed (substring mac-ts-active-input-buf 0 fix-len))
1978 (setq mac-ts-active-input-buf
1979 (substring mac-ts-active-input-buf fix-len))))
1980 (setq buf-len (length mac-ts-active-input-buf))
1981 ;; Update highlighting and the caret position in the new inline
1982 ;; input session.
1983 (remove-text-properties 0 buf-len '(cursor nil) mac-ts-active-input-buf)
1984 (mapc (lambda (rng)
1985 (cond ((and (= (nth 2 rng) 1) ; kTSMHiliteCaretPosition
1986 (<= 0 (car rng)) (< (car rng) buf-len))
1987 (put-text-property (car rng) buf-len
1988 'cursor t mac-ts-active-input-buf))
1989 ((and (<= 0 (car rng)) (< (car rng) (cadr rng))
1990 (<= (cadr rng) buf-len))
1991 (put-text-property (car rng) (cadr rng) 'face
1992 (cdr (assq (nth 2 rng)
1993 mac-ts-hilite-style-faces))
1994 mac-ts-active-input-buf))))
1995 hilite-rng)
1996 confirmed))
1997
1998 (defun mac-split-string-by-property-change (string)
1999 (let ((tail (length string))
2000 head result)
2001 (unless (= tail 0)
2002 (while (setq head (previous-property-change tail string)
2003 result (cons (substring string (or head 0) tail) result)
2004 tail head)))
2005 result))
2006
2007 (defun mac-replace-untranslated-utf-8-chars (string &optional to-string)
2008 (or to-string (setq to-string "\e$,3u=\e(B"))
2009 (mapconcat
2010 (lambda (str)
2011 (if (get-text-property 0 'untranslated-utf-8 str) to-string str))
2012 (mac-split-string-by-property-change string)
2013 ""))
2014
2015 (defun mac-keyboard-translate-char (ch)
2016 (if (and (char-valid-p ch)
2017 (or (char-table-p keyboard-translate-table)
2018 (and (or (stringp keyboard-translate-table)
2019 (vectorp keyboard-translate-table))
2020 (> (length keyboard-translate-table) ch))))
2021 (or (aref keyboard-translate-table ch) ch)
2022 ch))
2023
2024 (defun mac-unread-string (string)
2025 ;; Unread characters and insert them in a keyboard macro being
2026 ;; defined.
2027 (apply 'isearch-unread
2028 (mapcar 'mac-keyboard-translate-char
2029 (mac-replace-untranslated-utf-8-chars string))))
2030
2031 (defun mac-ts-update-active-input-area (event)
2032 "Update Mac TSM active input area according to EVENT.
2033 The confirmed text is converted to Emacs input events and pushed
2034 into `unread-command-events'. The unconfirmed text is displayed
2035 either in the current buffer or in the echo area."
2036 (interactive "e")
2037 (let* ((ae (mac-event-ae event))
2038 (type-text (mac-ae-parameter ae "tstx"))
2039 (text (or (cdr type-text) ""))
2040 (decode-fun (if (equal (car type-text) "TEXT")
2041 'mac-TEXT-to-string 'mac-utxt-to-string))
2042 (script-language (mac-ae-script-language ae "tssl"))
2043 (coding (or (cdr (assq (car script-language)
2044 mac-script-code-coding-systems))
2045 'mac-roman))
2046 (fix-len (mac-ae-number ae "tsfx"))
2047 ;; Optional parameters
2048 (hilite-rng (mac-ae-text-range-array ae "tshi"))
2049 (update-rng (mac-ae-text-range-array ae "tsup"))
2050 ;;(pin-rng (mac-bytes-to-text-range (cdr (mac-ae-parameter ae "tspn" "txrn"))))
2051 ;;(clause-offsets (cdr (mac-ae-parameter ae "tscl" "ofay")))
2052 (seqno (mac-ae-number ae "tsSn"))
2053 confirmed)
2054 (unless (= seqno mac-ts-update-active-input-area-seqno)
2055 ;; Reset internal states if sequence number is out of sync.
2056 (setq mac-ts-active-input-buf ""))
2057 (setq confirmed
2058 (mac-ts-update-active-input-buf text fix-len hilite-rng update-rng))
2059 (let ((use-echo-area
2060 (or isearch-mode
2061 (and cursor-in-echo-area (current-message))
2062 ;; Overlay strings are not shown in some cases.
2063 (get-char-property (point) 'invisible)
2064 (and (not (bobp))
2065 (or (and (get-char-property (point) 'display)
2066 (eq (get-char-property (1- (point)) 'display)
2067 (get-char-property (point) 'display)))
2068 (and (get-char-property (point) 'composition)
2069 (eq (get-char-property (1- (point)) 'composition)
2070 (get-char-property (point) 'composition)))))))
2071 active-input-string caret-seen)
2072 ;; Decode the active input area text with inheriting faces and
2073 ;; the caret position.
2074 (setq active-input-string
2075 (mapconcat
2076 (lambda (str)
2077 (let ((decoded (funcall decode-fun str coding)))
2078 (put-text-property 0 (length decoded) 'face
2079 (get-text-property 0 'face str) decoded)
2080 (when (and (not caret-seen)
2081 (get-text-property 0 'cursor str))
2082 (setq caret-seen t)
2083 (if (or use-echo-area (null cursor-type))
2084 (put-text-property 0 1 'face 'mac-ts-caret-position
2085 decoded)
2086 (put-text-property 0 1 'cursor t decoded)))
2087 decoded))
2088 (mac-split-string-by-property-change mac-ts-active-input-buf)
2089 ""))
2090 (put-text-property 0 (length active-input-string)
2091 'mac-ts-active-input-string t active-input-string)
2092 (if use-echo-area
2093 (let ((msg (current-message))
2094 message-log-max)
2095 (if (and msg
2096 ;; Don't get confused by previously displayed
2097 ;; `active-input-string'.
2098 (null (get-text-property 0 'mac-ts-active-input-string
2099 msg)))
2100 (setq msg (propertize msg 'display
2101 (concat msg active-input-string)))
2102 (setq msg active-input-string))
2103 (message "%s" msg)
2104 (overlay-put mac-ts-active-input-overlay 'before-string nil))
2105 (move-overlay mac-ts-active-input-overlay
2106 (point) (point) (current-buffer))
2107 (overlay-put mac-ts-active-input-overlay 'before-string
2108 active-input-string))
2109 (mac-unread-string (funcall decode-fun confirmed coding)))
2110 ;; The event is successfully processed. Sync the sequence number.
2111 (setq mac-ts-update-active-input-area-seqno (1+ seqno))))
2112
2113 (defun mac-ts-unicode-for-key-event (event)
2114 "Convert Unicode key EVENT to Emacs key events and unread them."
2115 (interactive "e")
2116 (let* ((ae (mac-event-ae event))
2117 (text (cdr (mac-ae-parameter ae "tstx" "utxt")))
2118 (script-language (mac-ae-script-language ae "tssl"))
2119 (coding (or (cdr (assq (car script-language)
2120 mac-script-code-coding-systems))
2121 'mac-roman)))
2122 (if text
2123 (mac-unread-string (mac-utxt-to-string text coding)))))
2124
2125 ;; kEventClassTextInput/kEventTextInputUpdateActiveInputArea
2126 (define-key mac-apple-event-map [text-input update-active-input-area]
2127 'mac-ts-update-active-input-area)
2128 ;; kEventClassTextInput/kEventTextInputUnicodeForKeyEvent
2129 (define-key mac-apple-event-map [text-input unicode-for-key-event]
2130 'mac-ts-unicode-for-key-event)
2131
2132 ;;; Services
2133 (defun mac-service-open-file ()
2134 "Open the file specified by the selection value for Services."
2135 (interactive)
2136 (find-file-existing (x-selection-value mac-service-selection)))
2137
2138 (defun mac-service-open-selection ()
2139 "Create a new buffer containing the selection value for Services."
2140 (interactive)
2141 (switch-to-buffer (generate-new-buffer "*untitled*"))
2142 (insert (x-selection-value mac-service-selection))
2143 (sit-for 0)
2144 (save-buffer) ; It pops up the save dialog.
2145 )
2146
2147 (defun mac-service-mail-selection ()
2148 "Prepare a mail buffer containing the selection value for Services."
2149 (interactive)
2150 (compose-mail)
2151 (rfc822-goto-eoh)
2152 (forward-line 1)
2153 (insert (x-selection-value mac-service-selection) "\n"))
2154
2155 (defun mac-service-mail-to ()
2156 "Prepare a mail buffer to be sent to the selection value for Services."
2157 (interactive)
2158 (compose-mail (x-selection-value mac-service-selection)))
2159
2160 (defun mac-service-insert-text ()
2161 "Insert the selection value for Services."
2162 (interactive)
2163 (let ((text (x-selection-value mac-service-selection)))
2164 (if (not buffer-read-only)
2165 (insert text)
2166 (kill-new text)
2167 (message
2168 (substitute-command-keys
2169 "The text from the Services menu can be accessed with \\[yank]")))))
2170
2171 ;; kEventClassService/kEventServicePaste
2172 (define-key mac-apple-event-map [service paste] 'mac-service-insert-text)
2173 ;; kEventClassService/kEventServicePerform
2174 (define-key mac-apple-event-map [service perform open-file]
2175 'mac-service-open-file)
2176 (define-key mac-apple-event-map [service perform open-selection]
2177 'mac-service-open-selection)
2178 (define-key mac-apple-event-map [service perform mail-selection]
2179 'mac-service-mail-selection)
2180 (define-key mac-apple-event-map [service perform mail-to]
2181 'mac-service-mail-to)
2182
2183 (defun mac-dispatch-apple-event (event)
2184 "Dispatch EVENT according to the keymap `mac-apple-event-map'."
2185 (interactive "e")
2186 (let* ((binding (lookup-key mac-apple-event-map (mac-event-spec event)))
2187 (ae (mac-event-ae event))
2188 (service-message (and (keymapp binding)
2189 (cdr (mac-ae-parameter ae "svmg")))))
2190 (when service-message
2191 (setq service-message
2192 (intern (decode-coding-string service-message 'utf-8)))
2193 (setq binding (lookup-key binding (vector service-message))))
2194 ;; Replace (cadr event) with a dummy position so that event-start
2195 ;; returns it.
2196 (setcar (cdr event) (list (selected-window) (point) '(0 . 0) 0))
2197 (if (null (mac-ae-parameter ae 'emacs-suspension-id))
2198 (command-execute binding nil (vector event) t)
2199 (condition-case err
2200 (progn
2201 (command-execute binding nil (vector event) t)
2202 (mac-resume-apple-event ae))
2203 (error
2204 (mac-ae-set-reply-parameter ae "errs"
2205 (cons "TEXT" (error-message-string err)))
2206 (mac-resume-apple-event ae -10000)))))) ; errAEEventFailed
2207
2208 (define-key special-event-map [mac-apple-event] 'mac-dispatch-apple-event)
2209
2210 ;; Processing of Apple events are deferred at the startup time. For
2211 ;; example, files dropped onto the Emacs application icon can only be
2212 ;; processed when the initial frame has been created: this is where
2213 ;; the files should be opened.
2214 (add-hook 'after-init-hook 'mac-process-deferred-apple-events)
2215
2216 (run-with-idle-timer 5 t 'mac-cleanup-expired-apple-events)
2217
2218 \f
2219 ;;;; Drag and drop
2220
2221 (defcustom mac-dnd-types-alist
2222 '(("furl" . mac-dnd-handle-furl)
2223 ("hfs " . mac-dnd-handle-hfs)
2224 ("utxt" . mac-dnd-insert-utxt)
2225 ("TEXT" . mac-dnd-insert-TEXT)
2226 ("TIFF" . mac-dnd-insert-TIFF))
2227 "Which function to call to handle a drop of that type.
2228 The function takes three arguments, WINDOW, ACTION and DATA.
2229 WINDOW is where the drop occurred, ACTION is always `private' on
2230 Mac. DATA is the drop data. Unlike the x-dnd counterpart, the
2231 return value of the function is not significant.
2232
2233 See also `mac-dnd-known-types'."
2234 :version "22.1"
2235 :type 'alist
2236 :group 'mac)
2237
2238 (defun mac-dnd-handle-furl (window action data)
2239 (dnd-handle-one-url window action (mac-furl-to-string data)))
2240
2241 (defun mac-dnd-handle-hfs (window action data)
2242 ;; struct HFSFlavor {
2243 ;; OSType fileType;
2244 ;; OSType fileCreator;
2245 ;; UInt16 fdFlags;
2246 ;; FSSpec fileSpec;
2247 ;; };
2248 (let* ((file-name (mac-coerce-ae-data "fss " (substring data 10)
2249 'undecoded-file-name))
2250 (url (concat "file://"
2251 (mapconcat 'url-hexify-string
2252 (split-string file-name "/") "/"))))
2253 (dnd-handle-one-url window action url)))
2254
2255 (defun mac-dnd-insert-utxt (window action data)
2256 (dnd-insert-text window action (mac-utxt-to-string data)))
2257
2258 (defun mac-dnd-insert-TEXT (window action data)
2259 (dnd-insert-text window action (mac-TEXT-to-string data)))
2260
2261 (defun mac-dnd-insert-TIFF (window action data)
2262 (dnd-insert-text window action (mac-TIFF-to-string data)))
2263
2264 (defun mac-dnd-drop-data (event frame window data type &optional action)
2265 (or action (setq action 'private))
2266 (let* ((type-info (assoc type mac-dnd-types-alist))
2267 (handler (cdr type-info))
2268 (w (posn-window (event-start event))))
2269 (when handler
2270 (if (and (window-live-p w)
2271 (not (window-minibuffer-p w))
2272 (not (window-dedicated-p w)))
2273 ;; If dropping in an ordinary window which we could use,
2274 ;; let dnd-open-file-other-window specify what to do.
2275 (progn
2276 (when (not mouse-yank-at-point)
2277 (goto-char (posn-point (event-start event))))
2278 (funcall handler window action data))
2279 ;; If we can't display the file here,
2280 ;; make a new window for it.
2281 (let ((dnd-open-file-other-window t))
2282 (select-frame frame)
2283 (funcall handler window action data))))))
2284
2285 (defun mac-dnd-handle-drag-n-drop-event (event)
2286 "Receive drag and drop events."
2287 (interactive "e")
2288 (let ((window (posn-window (event-start event)))
2289 (ae (mac-event-ae event))
2290 action)
2291 (when (windowp window) (select-window window))
2292 (if (memq 'option (mac-ae-keyboard-modifiers ae))
2293 (setq action 'copy))
2294 (dolist (item (mac-ae-list ae))
2295 (if (not (equal (car item) "null"))
2296 (mac-dnd-drop-data event (selected-frame) window
2297 (cdr item) (car item) action)))))
2298 \f
2299 (defvar mac-font-encoder-list
2300 '(("mac-roman" mac-roman-encoder
2301 ccl-encode-mac-roman-font "%s")
2302 ("mac-centraleurroman" encode-mac-centraleurroman
2303 ccl-encode-mac-centraleurroman-font "%s ce")
2304 ("mac-cyrillic" encode-mac-cyrillic
2305 ccl-encode-mac-cyrillic-font "%s cy")
2306 ("mac-symbol" mac-symbol-encoder
2307 ccl-encode-mac-symbol-font "symbol")
2308 ("mac-dingbats" mac-dingbats-encoder
2309 ccl-encode-mac-dingbats-font "zapf dingbats")))
2310
2311 (let ((encoder-list
2312 (mapcar (lambda (lst) (nth 1 lst)) mac-font-encoder-list))
2313 (charset-list
2314 '(latin-iso8859-2
2315 latin-iso8859-3 latin-iso8859-4
2316 cyrillic-iso8859-5 greek-iso8859-7 hebrew-iso8859-8
2317 latin-iso8859-9 latin-iso8859-14 latin-iso8859-15)))
2318 (dolist (encoder encoder-list)
2319 (let ((table (get encoder 'translation-table)))
2320 (dolist (charset charset-list)
2321 (dotimes (i 96)
2322 (let* ((c (make-char charset (+ i 32)))
2323 (mu (aref ucs-mule-to-mule-unicode c))
2324 (mac-encoded (and mu (aref table mu))))
2325 (if mac-encoded
2326 (aset table c mac-encoded))))))))
2327
2328 ;; We assume none of official dim2 charsets (0x90..0x99) are encoded
2329 ;; to these fonts.
2330
2331 (define-ccl-program ccl-encode-mac-roman-font
2332 `(0
2333 (if (r0 <= ?\xef)
2334 (translate-character mac-roman-encoder r0 r1)
2335 ((r1 <<= 7)
2336 (r1 |= r2)
2337 (translate-character mac-roman-encoder r0 r1))))
2338 "CCL program for Mac Roman font")
2339
2340 (define-ccl-program ccl-encode-mac-centraleurroman-font
2341 `(0
2342 (if (r0 <= ?\xef)
2343 (translate-character encode-mac-centraleurroman r0 r1)
2344 ((r1 <<= 7)
2345 (r1 |= r2)
2346 (translate-character encode-mac-centraleurroman r0 r1))))
2347 "CCL program for Mac Central European Roman font")
2348
2349 (define-ccl-program ccl-encode-mac-cyrillic-font
2350 `(0
2351 (if (r0 <= ?\xef)
2352 (translate-character encode-mac-cyrillic r0 r1)
2353 ((r1 <<= 7)
2354 (r1 |= r2)
2355 (translate-character encode-mac-cyrillic r0 r1))))
2356 "CCL program for Mac Cyrillic font")
2357
2358 (define-ccl-program ccl-encode-mac-symbol-font
2359 `(0
2360 (if (r0 <= ?\xef)
2361 (translate-character mac-symbol-encoder r0 r1)
2362 ((r1 <<= 7)
2363 (r1 |= r2)
2364 (translate-character mac-symbol-encoder r0 r1))))
2365 "CCL program for Mac Symbol font")
2366
2367 (define-ccl-program ccl-encode-mac-dingbats-font
2368 `(0
2369 (if (r0 <= ?\xef)
2370 (translate-character mac-dingbats-encoder r0 r1)
2371 ((r1 <<= 7)
2372 (r1 |= r2)
2373 (translate-character mac-dingbats-encoder r0 r1))))
2374 "CCL program for Mac Dingbats font")
2375
2376
2377 (setq font-ccl-encoder-alist
2378 (nconc
2379 (mapcar (lambda (lst) (cons (nth 0 lst) (nth 2 lst)))
2380 mac-font-encoder-list)
2381 font-ccl-encoder-alist))
2382
2383 (defconst mac-char-fontspec-list
2384 ;; Directly operate on a char-table instead of a fontset so that it
2385 ;; may not create a dummy fontset.
2386 (let ((template (make-char-table 'fontset)))
2387 (dolist
2388 (font-encoder
2389 (nreverse
2390 (mapcar (lambda (lst)
2391 (cons (cons (nth 3 lst) (nth 0 lst)) (nth 1 lst)))
2392 mac-font-encoder-list)))
2393 (let ((font (car font-encoder))
2394 (encoder (cdr font-encoder)))
2395 (map-char-table
2396 (lambda (key val)
2397 (or (null val)
2398 (generic-char-p key)
2399 (memq (char-charset key)
2400 '(ascii eight-bit-control eight-bit-graphic))
2401 (aset template key font)))
2402 (get encoder 'translation-table))))
2403
2404 ;; Like fontset-info, but extend a range only if its "to" part is
2405 ;; the predecessor of the current char.
2406 (let* ((last '((0 nil)))
2407 (accumulator last)
2408 last-char-or-range last-char last-elt)
2409 (map-char-table
2410 (lambda (char elt)
2411 (when elt
2412 (setq last-char-or-range (car (car last))
2413 last-char (if (consp last-char-or-range)
2414 (cdr last-char-or-range)
2415 last-char-or-range)
2416 last-elt (cdr (car last)))
2417 (if (and (eq elt last-elt)
2418 (= char (1+ last-char))
2419 (eq (char-charset char) (char-charset last-char)))
2420 (if (consp last-char-or-range)
2421 (setcdr last-char-or-range char)
2422 (setcar (car last) (cons last-char char)))
2423 (setcdr last (list (cons char elt)))
2424 (setq last (cdr last)))))
2425 template)
2426 (cdr accumulator))))
2427
2428 (defun fontset-add-mac-fonts (fontset &optional base-family)
2429 "Add font-specs for Mac fonts to FONTSET.
2430 The added font-specs are determined by BASE-FAMILY and the value
2431 of `mac-char-fontspec-list', which is a list
2432 of (CHARACTER-OR-RANGE . (FAMILY-FORMAT . REGISTRY)). If
2433 BASE-FAMILY is nil, the font family in the added font-specs is
2434 also nil. If BASE-FAMILY is a string, `%s' in FAMILY-FORMAT is
2435 replaced with the string. Otherwise, `%s' in FAMILY-FORMAT is
2436 replaced with the ASCII font family name in FONTSET."
2437 (if base-family
2438 (if (stringp base-family)
2439 (setq base-family (downcase base-family))
2440 (let ((ascii-font (fontset-font fontset (charset-id 'ascii))))
2441 (if ascii-font
2442 (setq base-family
2443 (aref (x-decompose-font-name
2444 (downcase (x-resolve-font-name ascii-font)))
2445 xlfd-regexp-family-subnum))))))
2446 (let (fontspec-cache fontspec)
2447 (dolist (char-fontspec mac-char-fontspec-list)
2448 (setq fontspec (cdr (assq (cdr char-fontspec) fontspec-cache)))
2449 (when (null fontspec)
2450 (setq fontspec
2451 (cons (and base-family
2452 (format (car (cdr char-fontspec)) base-family))
2453 (cdr (cdr char-fontspec))))
2454 (setq fontspec-cache (cons (cons (cdr char-fontspec) fontspec)
2455 fontspec-cache)))
2456 (set-fontset-font fontset (car char-fontspec) fontspec))))
2457
2458 (defun create-fontset-from-mac-roman-font (font &optional resolved-font
2459 fontset-name)
2460 "Create a fontset from a Mac roman font FONT.
2461
2462 Optional 1st arg RESOLVED-FONT is a resolved name of FONT. If
2463 omitted, `x-resolve-font-name' is called to get the resolved name. At
2464 this time, if FONT is not available, error is signaled.
2465
2466 Optional 2nd arg FONTSET-NAME is a string to be used in
2467 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
2468 an appropriate name is generated automatically.
2469
2470 It returns a name of the created fontset."
2471 (let ((fontset
2472 (create-fontset-from-ascii-font font resolved-font fontset-name)))
2473 (fontset-add-mac-fonts fontset t)
2474 fontset))
2475
2476 (defun x-win-suspend-error ()
2477 (error "Suspending an Emacs running under Mac makes no sense"))
2478
2479 (defalias 'x-cut-buffer-or-selection-value 'x-get-selection-value)
2480
2481 (defvar mac-initialized nil
2482 "Non-nil if the w32 window system has been initialized.")
2483
2484 (defun mac-initialize-window-system ()
2485 "Initialize Emacs for Mac GUI frames."
2486
2487 ;;; Do the actual Windows setup here; the above code just defines
2488 ;;; functions and variables that we use now.
2489
2490 (setq command-line-args (x-handle-args command-line-args))
2491
2492 ;;; Make sure we have a valid resource name.
2493 (or (stringp x-resource-name)
2494 (let (i)
2495 (setq x-resource-name (invocation-name))
2496
2497 ;; Change any . or * characters in x-resource-name to hyphens,
2498 ;; so as not to choke when we use it in X resource queries.
2499 (while (setq i (string-match "[.*]" x-resource-name))
2500 (aset x-resource-name i ?-))))
2501
2502 (if (x-display-list)
2503 ;; On Mac OS 8/9, Most coding systems used in code conversion for
2504 ;; font names are not ready at the time when the terminal frame is
2505 ;; created. So we reconstruct font name table for the initial
2506 ;; frame.
2507 (mac-clear-font-name-table)
2508 (x-open-connection "Mac"
2509 x-command-line-resources
2510 ;; Exit Emacs with fatal error if this fails.
2511 t))
2512
2513 (add-hook 'suspend-hook 'x-win-suspend-error)
2514
2515 ;;; Arrange for the kill and yank functions to set and check the clipboard.
2516 (setq interprogram-cut-function 'x-select-text)
2517 (setq interprogram-paste-function 'x-get-selection-value)
2518
2519
2520
2521
2522 ;;; Turn off window-splitting optimization; Mac is usually fast enough
2523 ;;; that this is only annoying.
2524 (setq split-window-keep-point t)
2525
2526 ;; Don't show the frame name; that's redundant.
2527 (setq-default mode-line-frame-identification " ")
2528
2529 ;; Turn on support for mouse wheels.
2530 (mouse-wheel-mode 1)
2531
2532
2533 ;; Enable CLIPBOARD copy/paste through menu bar commands.
2534 (menu-bar-enable-clipboard)
2535
2536
2537 ;; Initiate drag and drop
2538
2539 (define-key special-event-map [drag-n-drop] 'mac-dnd-handle-drag-n-drop-event)
2540
2541 \f
2542 ;;;; Non-toolkit Scroll bars
2543
2544 (unless x-toolkit-scroll-bars
2545
2546 ;; for debugging
2547 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event))
2548
2549 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event)
2550
2551 (global-set-key
2552 [vertical-scroll-bar down-mouse-1]
2553 'mac-handle-scroll-bar-event)
2554
2555 (global-unset-key [vertical-scroll-bar drag-mouse-1])
2556 (global-unset-key [vertical-scroll-bar mouse-1])
2557
2558 ;; Adjust Courier font specifications in x-fixed-font-alist.
2559 (let ((courier-fonts (assoc "Courier" x-fixed-font-alist)))
2560 (if courier-fonts
2561 (dolist (label-fonts (cdr courier-fonts))
2562 (setcdr label-fonts
2563 (mapcar
2564 (lambda (font)
2565 (if (string-match "\\`-adobe-courier-\\([^-]*\\)-\\(.\\)-\\(.*\\)-iso8859-1\\'" font)
2566 (replace-match
2567 (if (string= (match-string 2 font) "o")
2568 "-*-courier-\\1-i-\\3-*-*"
2569 "-*-courier-\\1-\\2-\\3-*-*")
2570 t nil font)
2571 font))
2572 (cdr label-fonts))))))
2573
2574 ;; Setup the default fontset.
2575 (setup-default-fontset)
2576 (cond ((x-list-fonts "*-iso10646-1" nil nil 1)
2577 ;; Use ATSUI (if available) for the following charsets.
2578 (dolist
2579 (charset '(latin-iso8859-1
2580 latin-iso8859-2 latin-iso8859-3 latin-iso8859-4
2581 thai-tis620 greek-iso8859-7 arabic-iso8859-6
2582 hebrew-iso8859-8 cyrillic-iso8859-5
2583 latin-iso8859-9 latin-iso8859-15 latin-iso8859-14
2584 japanese-jisx0212 chinese-sisheng ipa
2585 vietnamese-viscii-lower vietnamese-viscii-upper
2586 lao ethiopic tibetan))
2587 (set-fontset-font nil charset '(nil . "iso10646-1"))))
2588 ((null (x-list-fonts "*-iso8859-1" nil nil 1))
2589 ;; Add Mac-encoding fonts unless ETL fonts are installed.
2590 (fontset-add-mac-fonts "fontset-default")))
2591
2592 ;; Create a fontset that uses mac-roman font. With this fontset,
2593 ;; characters decoded from mac-roman encoding (ascii, latin-iso8859-1,
2594 ;; and mule-unicode-xxxx-yyyy) are displayed by a mac-roman font.
2595 (create-fontset-from-fontset-spec
2596 "-etl-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard,
2597 ascii:-*-Monaco-*-*-*-*-12-*-*-*-*-*-mac-roman")
2598 (fontset-add-mac-fonts "fontset-standard" t)
2599
2600 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
2601 (create-fontset-from-x-resource)
2602
2603 ;; Try to create a fontset from a font specification which comes
2604 ;; from initial-frame-alist, default-frame-alist, or X resource.
2605 ;; A font specification in command line argument (i.e. -fn XXXX)
2606 ;; should be already in default-frame-alist as a `font'
2607 ;; parameter. However, any font specifications in site-start
2608 ;; library, user's init file (.emacs), and default.el are not
2609 ;; yet handled here.
2610
2611 (let ((font (or (cdr (assq 'font initial-frame-alist))
2612 (cdr (assq 'font default-frame-alist))
2613 (x-get-resource "font" "Font")))
2614 xlfd-fields resolved-name)
2615 (if (and font
2616 (not (query-fontset font))
2617 (setq resolved-name (x-resolve-font-name font))
2618 (setq xlfd-fields (x-decompose-font-name font)))
2619 (if (string= "fontset" (aref xlfd-fields xlfd-regexp-registry-subnum))
2620 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
2621 ;; Create a fontset from FONT. The fontset name is
2622 ;; generated from FONT.
2623 (if (and (string= "mac" (aref xlfd-fields xlfd-regexp-registry-subnum))
2624 (string= "roman" (aref xlfd-fields xlfd-regexp-encoding-subnum)))
2625 (create-fontset-from-mac-roman-font font resolved-name "startup")
2626 (create-fontset-from-ascii-font font resolved-name "startup")))))
2627
2628 ;; Apply a geometry resource to the initial frame. Put it at the end
2629 ;; of the alist, so that anything specified on the command line takes
2630 ;; precedence.
2631 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
2632 parsed)
2633 (if res-geometry
2634 (progn
2635 (setq parsed (x-parse-geometry res-geometry))
2636 ;; If the resource specifies a position,
2637 ;; call the position and size "user-specified".
2638 (if (or (assq 'top parsed) (assq 'left parsed))
2639 (setq parsed (cons '(user-position . t)
2640 (cons '(user-size . t) parsed))))
2641 ;; All geometry parms apply to the initial frame.
2642 (setq initial-frame-alist (append initial-frame-alist parsed))
2643 ;; The size parms apply to all frames. Don't set it if there are
2644 ;; sizes there already (from command line).
2645 (if (and (assq 'height parsed)
2646 (not (assq 'height default-frame-alist)))
2647 (setq default-frame-alist
2648 (cons (cons 'height (cdr (assq 'height parsed)))
2649 default-frame-alist)))
2650 (if (and (assq 'width parsed)
2651 (not (assq 'width default-frame-alist)))
2652 (setq default-frame-alist
2653 (cons (cons 'width (cdr (assq 'width parsed)))
2654 default-frame-alist))))))
2655
2656 ;; Check the reverseVideo resource.
2657 (let ((case-fold-search t))
2658 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
2659 (if (and rv
2660 (string-match "^\\(true\\|yes\\|on\\)$" rv))
2661 (setq default-frame-alist
2662 (cons '(reverse . t) default-frame-alist)))))
2663
2664 (setq mac-initialized t)))
2665
2666 (defun mac-handle-scroll-bar-event (event)
2667 "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling."
2668 (interactive "e")
2669 (let* ((position (event-start event))
2670 (window (nth 0 position))
2671 (bar-part (nth 4 position)))
2672 (select-window window)
2673 (cond
2674 ((eq bar-part 'up)
2675 (goto-char (window-start window))
2676 (mac-scroll-down-line))
2677 ((eq bar-part 'above-handle)
2678 (mac-scroll-down))
2679 ((eq bar-part 'handle)
2680 (scroll-bar-drag event))
2681 ((eq bar-part 'below-handle)
2682 (mac-scroll-up))
2683 ((eq bar-part 'down)
2684 (goto-char (window-start window))
2685 (mac-scroll-up-line)))))
2686
2687 (defun mac-scroll-ignore-events ()
2688 ;; Ignore confusing non-mouse events
2689 (while (not (memq (car-safe (read-event))
2690 '(mouse-1 double-mouse-1 triple-mouse-1))) nil))
2691
2692 (defun mac-scroll-down ()
2693 (track-mouse
2694 (mac-scroll-ignore-events)
2695 (scroll-down)))
2696
2697 (defun mac-scroll-down-line ()
2698 (track-mouse
2699 (mac-scroll-ignore-events)
2700 (scroll-down 1)))
2701
2702 (defun mac-scroll-up ()
2703 (track-mouse
2704 (mac-scroll-ignore-events)
2705 (scroll-up)))
2706
2707 (defun mac-scroll-up-line ()
2708 (track-mouse
2709 (mac-scroll-ignore-events)
2710 (scroll-up 1)))
2711
2712
2713 \f
2714 ;;;; Others
2715
2716 (unless (eq system-type 'darwin)
2717 ;; This variable specifies the Unix program to call (as a process) to
2718 ;; determine the amount of free space on a file system (defaults to
2719 ;; df). If it is not set to nil, ls-lisp will not work correctly
2720 ;; unless an external application df is implemented on the Mac.
2721 (setq directory-free-space-program nil)
2722
2723 ;; Set this so that Emacs calls subprocesses with "sh" as shell to
2724 ;; expand filenames Note no subprocess for the shell is actually
2725 ;; started (see run_mac_command in sysdep.c).
2726 (setq shell-file-name "sh")
2727
2728 ;; Some system variables are encoded with the system script code.
2729 (dolist (v '(system-name
2730 emacs-build-system ; Mac OS 9 version cannot dump
2731 user-login-name user-real-login-name user-full-name))
2732 (set v (decode-coding-string (symbol-value v) mac-system-coding-system))))
2733
2734 ;; Now the default directory is changed to the user's home directory
2735 ;; in emacs.c if invoked from the WindowServer (with -psn_* option).
2736 ;; (if (string= default-directory "/")
2737 ;; (cd "~"))
2738
2739 ;; Darwin 6- pty breakage is now controlled from the C code so that
2740 ;; it applies to all builds on darwin. See s/darwin.h PTY_ITERATION.
2741 ;; (setq process-connection-type t)
2742
2743 ;; Assume that fonts are always scalable on the Mac. This sometimes
2744 ;; results in characters with jagged edges. However, without it,
2745 ;; fonts with both truetype and bitmap representations but no italic
2746 ;; or bold bitmap versions will not display these variants correctly.
2747 (setq scalable-fonts-allowed t)
2748
2749 (add-to-list 'handle-args-function-alist '(mac . x-handle-args))
2750 (add-to-list 'frame-creation-function-alist '(mac . x-create-frame-with-faces))
2751 (add-to-list 'window-system-initialization-alist '(mac . mac-initialize-window-system))
2752
2753 (provide 'mac-win)
2754
2755 ;; arch-tag: 71dfcd14-cde8-4d66-b05c-85ec94fb23a6
2756 ;;; mac-win.el ends here