comparison lisp/term/mac-win.el @ 83408:39bb10ce301a

Merged in changes from CVS trunk. Patches applied: * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-667 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-668 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-669 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-670 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-157 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-158 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-159 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-160 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-161 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-162 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-163 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-164 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-165 Update from CVS: texi/message.texi: Fix default values. * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-166 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-167 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-168 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-448
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 11 Dec 2005 22:42:40 +0000
parents 1955a4462bf9 44fba69e3c47
children b64b7e867d0a
comparison
equal deleted inserted replaced
83407:37d0562504bf 83408:39bb10ce301a
74 (require 'faces) 74 (require 'faces)
75 (require 'select) 75 (require 'select)
76 (require 'menu-bar) 76 (require 'menu-bar)
77 (require 'fontset) 77 (require 'fontset)
78 (require 'dnd) 78 (require 'dnd)
79 (eval-when-compile (require 'url))
79 80
80 (defvar mac-charset-info-alist) 81 (defvar mac-charset-info-alist)
81 (defvar mac-services-selection) 82 (defvar mac-services-selection)
82 (defvar mac-system-script-code) 83 (defvar mac-system-script-code)
84 (defvar mac-apple-event-map)
83 (defvar x-invocation-args) 85 (defvar x-invocation-args)
84 86
85 (defvar x-command-line-resources nil) 87 (defvar x-command-line-resources nil)
86 88
87 ;; Handler for switches of the form "-switch value" or "-switch". 89 ;; Handler for switches of the form "-switch value" or "-switch".
1146 (if (eq coding-system 'japanese-shift-jis) 1148 (if (eq coding-system 'japanese-shift-jis)
1147 (define-key key-translation-map [?\x80] "\\")))) 1149 (define-key key-translation-map [?\x80] "\\"))))
1148 1150
1149 (define-key special-event-map [language-change] 'mac-handle-language-change) 1151 (define-key special-event-map [language-change] 'mac-handle-language-change)
1150 1152
1151 ;;;; Selections and Services menu 1153 ;;;; Selections
1152 1154
1153 ;; Setup to use the Mac clipboard. 1155 ;; Setup to use the Mac clipboard.
1154 (set-selection-coding-system mac-system-coding-system) 1156 (set-selection-coding-system mac-system-coding-system)
1155 1157
1156 ;;; We keep track of the last text selected here, so we can check the 1158 ;;; We keep track of the last text selected here, so we can check the
1384 ;; menu makes Emacs crash or hang for unknown reasons. 1386 ;; menu makes Emacs crash or hang for unknown reasons.
1385 ;; (public.tiff . nil) 1387 ;; (public.tiff . nil)
1386 (public.file-url . mac-select-convert-to-file-url) 1388 (public.file-url . mac-select-convert-to-file-url)
1387 ) 1389 )
1388 selection-converter-alist)) 1390 selection-converter-alist))
1391
1392 ;;;; Apple events, HICommand events, and Services menu
1393
1394 ;;; Event classes
1395 (put 'core-event 'mac-apple-event-class "aevt") ; kCoreEventClass
1396 (put 'internet-event 'mac-apple-event-class "GURL") ; kAEInternetEventClass
1397
1398 ;;; Event IDs
1399 ;; kCoreEventClass
1400 (put 'open-application 'mac-apple-event-id "oapp") ; kAEOpenApplication
1401 (put 'reopen-application 'mac-apple-event-id "rapp") ; kAEReopenApplication
1402 (put 'open-documents 'mac-apple-event-id "odoc") ; kAEOpenDocuments
1403 (put 'print-documents 'mac-apple-event-id "pdoc") ; kAEPrintDocuments
1404 (put 'open-contents 'mac-apple-event-id "ocon") ; kAEOpenContents
1405 (put 'quit-application 'mac-apple-event-id "quit") ; kAEQuitApplication
1406 (put 'application-died 'mac-apple-event-id "obit") ; kAEApplicationDied
1407 (put 'show-preferences 'mac-apple-event-id "pref") ; kAEShowPreferences
1408 (put 'autosave-now 'mac-apple-event-id "asav") ; kAEAutosaveNow
1409 ;; kAEInternetEventClass
1410 (put 'get-url 'mac-apple-event-id "GURL") ; kAEGetURL
1411 ;; Converted HICommand events
1412 (put 'about 'mac-apple-event-id "abou") ; kHICommandAbout
1413
1414 (defmacro mac-event-spec (event)
1415 `(nth 1 ,event))
1416
1417 (defmacro mac-event-ae (event)
1418 `(nth 2 ,event))
1419
1420 (defun mac-ae-parameter (ae &optional keyword type)
1421 (or keyword (setq keyword "----")) ;; Direct object.
1422 (if (not (and (consp ae) (equal (car ae) "aevt")))
1423 (error "Not an Apple event: %S" ae)
1424 (let ((type-data (cdr (assoc keyword (cdr ae))))
1425 data)
1426 (when (and type type-data)
1427 (setq data (mac-coerce-ae-data (car type-data) (cdr type-data) type))
1428 (setq type-data (if data (cons type data) nil)))
1429 type-data)))
1430
1431 (defun mac-ae-list (ae &optional keyword type)
1432 (or keyword (setq keyword "----")) ;; Direct object.
1433 (let ((desc (mac-ae-parameter ae keyword)))
1434 (cond ((null desc)
1435 nil)
1436 ((not (equal (car desc) "list"))
1437 (error "Parameter for \"%s\" is not a list" keyword))
1438 (t
1439 (if (null type)
1440 (cdr desc)
1441 (mapcar
1442 (lambda (type-data)
1443 (mac-coerce-ae-data (car type-data) (cdr type-data) type))
1444 (cdr desc)))))))
1445
1446 (defun mac-bytes-to-integer (bytes &optional from to)
1447 (or from (setq from 0))
1448 (or to (setq to (length bytes)))
1449 (let* ((len (- to from))
1450 (extended-sign-len (- (1+ (ceiling (log most-positive-fixnum 2)))
1451 (* 8 len)))
1452 (result 0))
1453 (dotimes (i len)
1454 (setq result (logior (lsh result 8)
1455 (aref bytes (+ from (if (eq (byteorder) ?B) i
1456 (- len i 1)))))))
1457 (if (> extended-sign-len 0)
1458 (ash (lsh result extended-sign-len) (- extended-sign-len))
1459 result)))
1460
1461 (defun mac-ae-selection-range (ae)
1462 ;; #pragma options align=mac68k
1463 ;; typedef struct SelectionRange {
1464 ;; short unused1; // 0 (not used)
1465 ;; short lineNum; // line to select (<0 to specify range)
1466 ;; long startRange; // start of selection range (if line < 0)
1467 ;; long endRange; // end of selection range (if line < 0)
1468 ;; long unused2; // 0 (not used)
1469 ;; long theDate; // modification date/time
1470 ;; } SelectionRange;
1471 ;; #pragma options align=reset
1472 (let ((range-bytes (cdr (mac-ae-parameter ae "kpos" "TEXT"))))
1473 (and range-bytes
1474 (list (mac-bytes-to-integer range-bytes 2 4)
1475 (mac-bytes-to-integer range-bytes 4 8)
1476 (mac-bytes-to-integer range-bytes 8 12)
1477 (mac-bytes-to-integer range-bytes 16 20)))))
1478
1479 ;; On Mac OS X 10.4 and later, the `open-document' event contains an
1480 ;; optional parameter keyAESearchText from the Spotlight search.
1481 (defun mac-ae-text-for-search (ae)
1482 (let ((utf8-text (cdr (mac-ae-parameter ae "stxt" "utf8"))))
1483 (and utf8-text
1484 (decode-coding-string utf8-text 'utf-8))))
1485
1486 (defun mac-ae-open-documents (event)
1487 (interactive "e")
1488 (let ((ae (mac-event-ae event)))
1489 (dolist (file-name (mac-ae-list ae nil 'undecoded-file-name))
1490 (if file-name
1491 (dnd-open-local-file (concat "file:" file-name) nil)))
1492 (let ((selection-range (mac-ae-selection-range ae))
1493 (search-text (mac-ae-text-for-search ae)))
1494 (cond (selection-range
1495 (let ((line (car selection-range))
1496 (start (cadr selection-range))
1497 (end (nth 2 selection-range)))
1498 (if (> line 0)
1499 (goto-line line)
1500 (if (and (> start 0) (> end 0))
1501 (progn (set-mark start)
1502 (goto-char end))))))
1503 ((stringp search-text)
1504 (re-search-forward
1505 (mapconcat 'regexp-quote (split-string search-text) "\\|")
1506 nil t)))))
1507 (raise-frame))
1508
1509 (defun mac-ae-text (ae)
1510 (or (cdr (mac-ae-parameter ae nil "TEXT"))
1511 (error "No text in Apple event.")))
1512
1513 (defun mac-ae-get-url (event)
1514 (interactive "e")
1515 (let* ((ae (mac-event-ae event))
1516 (parsed-url (url-generic-parse-url (mac-ae-text ae))))
1517 (if (string= (url-type parsed-url) "mailto")
1518 (url-mailto parsed-url)
1519 (error "Unsupported URL scheme: %s" (url-type parsed-url)))))
1520
1521 (setq mac-apple-event-map (make-sparse-keymap))
1522
1523 ;; Received when Emacs is launched without associated documents.
1524 ;; Accept it as an Apple event, but no Emacs event is generated so as
1525 ;; not to erase the splash screen.
1526 (define-key mac-apple-event-map [core-event open-application] 0)
1527
1528 ;; Received when a dock or application icon is clicked and Emacs is
1529 ;; already running. Simply ignored. Another idea is to make a new
1530 ;; frame if all frames are invisible.
1531 (define-key mac-apple-event-map [core-event reopen-application] 'ignore)
1532
1533 (define-key mac-apple-event-map [core-event open-documents]
1534 'mac-ae-open-documents)
1535 (define-key mac-apple-event-map [core-event show-preferences] 'customize)
1536 (define-key mac-apple-event-map [core-event quit-application]
1537 'save-buffers-kill-emacs)
1538
1539 (define-key mac-apple-event-map [internet-event get-url] 'mac-ae-get-url)
1540
1541 (define-key mac-apple-event-map [hicommand about] 'display-splash-screen)
1389 1542
1390 (defun mac-services-open-file () 1543 (defun mac-services-open-file ()
1391 (interactive) 1544 (interactive)
1392 (find-file-existing (x-selection-value mac-services-selection))) 1545 (find-file-existing (x-selection-value mac-services-selection)))
1393 1546
1418 (kill-new text) 1571 (kill-new text)
1419 (message 1572 (message
1420 (substitute-command-keys 1573 (substitute-command-keys
1421 "The text from the Services menu can be accessed with \\[yank]"))))) 1574 "The text from the Services menu can be accessed with \\[yank]")))))
1422 1575
1423 (defvar mac-application-menu-map (make-sparse-keymap)) 1576 (define-key mac-apple-event-map [services paste] 'mac-services-insert-text)
1424 (define-key mac-application-menu-map [quit] 'save-buffers-kill-emacs) 1577 (define-key mac-apple-event-map [services perform open-file]
1425 (define-key mac-application-menu-map [services perform open-file]
1426 'mac-services-open-file) 1578 'mac-services-open-file)
1427 (define-key mac-application-menu-map [services perform open-selection] 1579 (define-key mac-apple-event-map [services perform open-selection]
1428 'mac-services-open-selection) 1580 'mac-services-open-selection)
1429 (define-key mac-application-menu-map [services perform mail-selection] 1581 (define-key mac-apple-event-map [services perform mail-selection]
1430 'mac-services-mail-selection) 1582 'mac-services-mail-selection)
1431 (define-key mac-application-menu-map [services perform mail-to] 1583 (define-key mac-apple-event-map [services perform mail-to]
1432 'mac-services-mail-to) 1584 'mac-services-mail-to)
1433 (define-key mac-application-menu-map [services paste] 1585
1434 'mac-services-insert-text) 1586 (defun mac-dispatch-apple-event (event)
1435 (define-key mac-application-menu-map [preferences] 'customize) 1587 (interactive "e")
1436 (define-key mac-application-menu-map [about] 'display-splash-screen) 1588 (let* ((binding (lookup-key mac-apple-event-map (mac-event-spec event)))
1437 (global-set-key [menu-bar application] mac-application-menu-map) 1589 (service-message
1590 (and (keymapp binding)
1591 (cdr (mac-ae-parameter (mac-event-ae event) "svmg")))))
1592 (when service-message
1593 (setq service-message
1594 (intern (decode-coding-string service-message 'utf-8)))
1595 (setq binding (lookup-key binding (vector service-message))))
1596 (call-interactively binding)))
1597
1598 (global-set-key [mac-apple-event] 'mac-dispatch-apple-event)
1599
1600 ;; Processing of Apple events are deferred at the startup time. For
1601 ;; example, files dropped onto the Emacs application icon can only be
1602 ;; processed when the initial frame has been created: this is where
1603 ;; the files should be opened.
1604 (add-hook 'after-init-hook 'mac-process-deferred-apple-events)
1438 1605
1439 ;;; Do the actual Windows setup here; the above code just defines 1606 ;;; Do the actual Windows setup here; the above code just defines
1440 ;;; functions and variables that we use now. 1607 ;;; functions and variables that we use now.
1441 1608
1442 (setq command-line-args (x-handle-args command-line-args)) 1609 (setq command-line-args (x-handle-args command-line-args))
1853 (coords (posn-x-y (event-start event))) 2020 (coords (posn-x-y (event-start event)))
1854 (x (car coords)) 2021 (x (car coords))
1855 (y (cdr coords))) 2022 (y (cdr coords)))
1856 (if (and (> x 0) (> y 0)) 2023 (if (and (> x 0) (> y 0))
1857 (set-frame-selected-window nil window)) 2024 (set-frame-selected-window nil window))
1858 (mapcar (lambda (file-name) 2025 (dolist (file-name (nth 2 event))
1859 (if (listp file-name) 2026 (dnd-handle-one-url window 'private
1860 (let ((line (car file-name)) 2027 (concat "file:" file-name))))
1861 (start (car (cdr file-name)))
1862 (end (car (cdr (cdr file-name)))))
1863 (if (> line 0)
1864 (goto-line line)
1865 (if (and (> start 0) (> end 0))
1866 (progn (set-mark start)
1867 (goto-char end)))))
1868 (dnd-handle-one-url window 'private
1869 (concat "file:" file-name))))
1870 (car (cdr (cdr event)))))
1871 (raise-frame)) 2028 (raise-frame))
1872 2029
1873 (global-set-key [drag-n-drop] 'mac-drag-n-drop) 2030 (global-set-key [drag-n-drop] 'mac-drag-n-drop)
1874
1875 ;; By checking whether the variable mac-ready-for-drag-n-drop has been
1876 ;; defined, the event loop in macterm.c can be informed that it can
1877 ;; now receive Finder drag and drop events. Files dropped onto the
1878 ;; Emacs application icon can only be processed when the initial frame
1879 ;; has been created: this is where the files should be opened.
1880 (add-hook 'after-init-hook
1881 '(lambda ()
1882 (defvar mac-ready-for-drag-n-drop t)))
1883 2031
1884 ;;;; Non-toolkit Scroll bars 2032 ;;;; Non-toolkit Scroll bars
1885 2033
1886 (unless x-toolkit-scroll-bars 2034 (unless x-toolkit-scroll-bars
1887 2035