1 ;;; mac-win.el --- support for "Macintosh windows"
3 ;; Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
5 ;; Author: Andrew Choi <akochoi@mac.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 ;; ---------------------------------------------------------------------------
29 ;; We want to delay setting frame parameters until the faces are setup
31 ;; Mac can't handle ~ prefix in file names
32 ;(setq auto-save-list-file-prefix ".saves-")
34 (setq frame-creation-function 'x-create-frame-with-faces)
37 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event))
39 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event)
42 [vertical-scroll-bar down-mouse-1]
43 'mac-handle-scroll-bar-event)
45 (global-unset-key [vertical-scroll-bar drag-mouse-1])
46 (global-unset-key [vertical-scroll-bar mouse-1])
50 (defun mac-handle-scroll-bar-event (event)
51 "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling."
53 (let* ((position (event-start event))
54 (window (nth 0 position))
55 (bar-part (nth 4 position)))
56 (select-window window)
59 (goto-char (window-start window))
60 (mac-scroll-down-line))
61 ((eq bar-part 'above-handle)
63 ((eq bar-part 'handle)
64 (scroll-bar-drag event))
65 ((eq bar-part 'below-handle)
68 (goto-char (window-start window))
69 (mac-scroll-up-line)))))
71 (defun mac-scroll-down ()
73 (while (not (eq (car-safe (read-event)) 'mouse-1)) nil)
76 (defun mac-scroll-down-line ()
78 (while (not (eq (car-safe (read-event)) 'mouse-1)) nil)
81 (defun mac-scroll-up ()
83 (while (not (eq (car-safe (read-event)) 'mouse-1)) nil)
86 (defun mac-scroll-up-line ()
88 (while (not (eq (car-safe (read-event)) 'mouse-1)) nil)
91 (defun xw-defined-colors (&optional frame)
92 "Internal function called by `defined-colors', which see."
93 (or frame (setq frame (selected-frame)))
94 (let ((all-colors x-colors)
98 (setq this-color (car all-colors)
99 all-colors (cdr all-colors))
100 (and (color-supported-p this-color frame t)
101 (setq defined-colors (cons this-color defined-colors))))
104 ;; Don't have this yet.
105 (fset 'x-get-resource 'ignore)
107 (unless (eq system-type 'darwin)
108 ;; This variable specifies the Unix program to call (as a process) to
109 ;; deteremine the amount of free space on a file system (defaults to
110 ;; df). If it is not set to nil, ls-lisp will not work correctly
111 ;; unless an external application df is implemented on the Mac.
112 (setq directory-free-space-program nil)
114 ;; Set this so that Emacs calls subprocesses with "sh" as shell to
115 ;; expand filenames Note no subprocess for the shell is actually
116 ;; started (see run_mac_command in sysdep.c).
117 (setq shell-file-name "sh"))
119 ;; X Window emulation in macterm.c is not complete enough to start a
120 ;; frame without a minibuffer properly. Call this to tell ediff
121 ;; library to use a single frame.
122 ; (ediff-toggle-multiframe)
124 ;; Setup to use the Mac clipboard. The functions mac-cut-function and
125 ;; mac-paste-function are defined in mac.c.
126 (set-selection-coding-system 'compound-text-mac)
128 (setq interprogram-cut-function
131 (encode-coding-string str selection-coding-system t) push)))
133 (setq interprogram-paste-function
135 (decode-coding-string
136 (mac-paste-function) selection-coding-system t)))
138 (defun mac-drag-n-drop (event)
139 "Edit the files listed in the drag-n-drop event.\n\
140 Switch to a buffer editing the last file dropped."
143 ;; Make sure the drop target has positive co-ords
144 ;; before setting the selected frame - otherwise it
145 ;; won't work. <skx@tardis.ed.ac.uk>
146 (let* ((window (posn-window (event-start event)))
147 (coords (posn-x-y (event-start event)))
150 (if (and (> x 0) (> y 0))
151 (set-frame-selected-window nil window))
155 (decode-coding-string
157 (or file-name-coding-system
158 default-file-name-coding-system))))
159 (car (cdr (cdr event)))))
163 (global-set-key [drag-n-drop] 'mac-drag-n-drop)
165 ;; By checking whether the variable mac-ready-for-drag-n-drop has been
166 ;; defined, the event loop in macterm.c can be informed that it can
167 ;; now receive Finder drag and drop events. Files dropped onto the
168 ;; Emacs application icon can only be processed when the initial frame
169 ;; has been created: this is where the files should be opened.
170 (add-hook 'after-init-hook
172 (defvar mac-ready-for-drag-n-drop t)))
174 ; Define constant values to be set to mac-keyboard-text-encoding
175 (defconst kTextEncodingMacRoman 0)
176 (defconst kTextEncodingISOLatin1 513 "0x201")
177 (defconst kTextEncodingISOLatin2 514 "0x202")
180 (define-ccl-program ccl-encode-mac-roman-font
182 (if (r0 != ,(charset-id 'ascii))
183 (if (r0 == ,(charset-id 'latin-iso8859-1))
184 (translate-character mac-roman-encoder r0 r1)
187 (translate-character mac-roman-encoder r0 r1)))))
188 "CCL program for Mac Roman font")
190 (setq font-ccl-encoder-alist
191 (cons '("mac-roman" . ccl-encode-mac-roman-font)
192 font-ccl-encoder-alist))
194 ;; Create a fontset that uses mac-roman font. With this fontset,
195 ;; characters decoded from mac-roman encoding (ascii, latin-iso8859-1,
196 ;; and mule-unicode-xxxx-yyyy) are displayed by a mac-roman font.
198 (if (fboundp 'new-fontset)
200 (create-fontset-from-fontset-spec
201 "-etl-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-mac,
202 ascii:-*-Monaco-*-*-*-*-12-*-*-*-*-*-mac-roman")
203 (let ((monaco-font '("monaco" . "mac-roman")))
207 (or (generic-char-p key)
208 (memq (char-charset key)
209 '(ascii eight-bit-control eight-bit-graphic))
210 (set-fontset-font "fontset-mac" key monaco-font))))
211 (get 'mac-roman-encoder 'translation-table)))))
213 (if (eq system-type 'darwin)
214 ;; On Darwin filenames are encoded in UTF-8
215 (setq file-name-coding-system 'utf-8)
216 ;; To display filenames in Chinese or Japanese, replace mac-roman with
218 (setq file-name-coding-system 'mac-roman))
220 ;; If Emacs is started from the Finder, change the default directory
221 ;; to the user's home directory.
222 (if (string= default-directory "/")
225 (unless (eq system-type 'darwin)
226 ;; Tell Emacs to use pipes instead of pty's for processes because the
227 ;; latter sometimes lose characters. Pty support is compiled in since
228 ;; ange-ftp will not work without it.
229 (setq process-connection-type nil))
231 ;; Assume that fonts are always scalable on the Mac. This sometimes
232 ;; results in characters with jagged edges. However, without it,
233 ;; fonts with both truetype and bitmap representations but no italic
234 ;; or bold bitmap versions will not display these variants correctly.
235 (setq scalable-fonts-allowed t)
237 ;; (prefer-coding-system 'mac-roman)
243 (defvar x-colors '("LightGreen"
842 "LightGoldenrodYellow"
843 "light goldenrod yellow"
860 "medium spring green"
995 "The list of X colors from the `rgb.txt' file.
996 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
998 ;;; mac-win.el ends here