sun-cursors.el 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. ;; Cursor definitions for Sun windows
  2. ;; Copyright (C) 1987 Free Software Foundation, Inc.
  3. ;; This file is part of GNU Emacs.
  4. ;; GNU Emacs is distributed in the hope that it will be useful,
  5. ;; but WITHOUT ANY WARRANTY. No author or distributor
  6. ;; accepts responsibility to anyone for the consequences of using it
  7. ;; or for whether it serves any particular purpose or works at all,
  8. ;; unless he says so in writing. Refer to the GNU Emacs General Public
  9. ;; License for full details.
  10. ;; Everyone is granted permission to copy, modify and redistribute
  11. ;; GNU Emacs, but only under the conditions described in the
  12. ;; GNU Emacs General Public License. A copy of this license is
  13. ;; supposed to have been given to you along with GNU Emacs so you
  14. ;; can know your rights and responsibilities. It should be in a
  15. ;; file named COPYING. Among other things, the copyright notice
  16. ;; and this notice must be preserved on all copies.
  17. ;;;
  18. ;;; Added some more cursors and moved the hot spots
  19. ;;; Cursor defined by 16 pairs of 16-bit numbers
  20. ;;;
  21. ;;; 9-dec-86 Jeff Peck, Sun Microsystems Inc. <peck@sun.com>
  22. (provide 'sm-cursors)
  23. (defvar sc::cursors nil "List of known cursors")
  24. (defmacro defcursor (name x y string)
  25. (if (not (memq name sc::cursors))
  26. (setq sc::cursors (cons name sc::cursors)))
  27. (list 'defconst name (list 'vector x y string)))
  28. ;;; push should be defined in common lisp, but if not use this:
  29. ;(defmacro push (v l)
  30. ; "The ITEM is evaluated and consed onto LIST, a list-valued atom"
  31. ; (list 'setq l (list 'cons v l)))
  32. ;;;
  33. ;;; The standard default cursor
  34. ;;;
  35. (defcursor sc:right-arrow 15 0
  36. (concat '(0 1 0 3 0 7 0 15 0 31 0 63 0 127 0 15
  37. 0 27 0 25 0 48 0 48 0 96 0 96 0 192 0 192)))
  38. ;;(sc:set-cursor sc:right-arrow)
  39. (defcursor sc:fat-left-arrow 0 8
  40. (concat '(1 0 3 0 7 0 15 0 31 0 63 255 127 255 255 255
  41. 255 255 127 255 63 255 31 0 15 0 7 0 3 0 1 0)))
  42. (defcursor sc:box 8 8
  43. (concat '(15 252 8 4 8 4 8 4 8 4 8 4 8 4 8 4
  44. 8 132 8 4 8 4 8 4 8 4 8 4 8 4 15 252)))
  45. (defcursor sc:hourglass 8 8
  46. (concat "\177\376\100\002\040\014\032\070"
  47. "\017\360\007\340\003\300\001\200"
  48. "\001\200\002\100\005\040\010\020"
  49. "\021\210\043\304\107\342\177\376"))
  50. (defun sc:set-cursor (icon)
  51. "Change the Sun mouse cursor to ICON.
  52. If ICON is nil, switch to the system default cursor,
  53. Otherwise, ICON should be a vector or the name of a vector of [x y 32-chars]"
  54. (interactive "XIcon Name: ")
  55. (if (symbolp icon) (setq icon (symbol-value icon)))
  56. (sun-change-cursor-icon icon))
  57. (make-local-variable '*edit-icon*)
  58. (make-variable-buffer-local 'icon-edit)
  59. (setq-default icon-edit nil)
  60. (or (assq 'icon-edit minor-mode-alist)
  61. (push '(icon-edit " IconEdit") minor-mode-alist))
  62. (defun sc:edit-cursor (icon)
  63. "convert icon to rectangle, edit, and repack"
  64. (interactive "XIcon Name: ")
  65. (if (not icon) (setq icon (sc::menu-choose-cursor (selected-window) 1 1)))
  66. (if (symbolp icon) (setq icon (symbol-value icon)))
  67. (if (get-buffer "icon-edit") (kill-buffer "icon-edit"))
  68. (switch-to-buffer "icon-edit")
  69. (local-set-mouse '(text right) 'sc::menu-function)
  70. (local-set-mouse '(text left) '(sc::pic-ins-at-mouse 32))
  71. (local-set-mouse '(text middle) '(sc::pic-ins-at-mouse 64))
  72. (local-set-mouse '(text left middle) 'sc::hotspot)
  73. (sc::display-icon icon)
  74. (picture-mode)
  75. (setq icon-edit t) ; for mode line display
  76. )
  77. (defun sc::pic-ins-at-mouse (char)
  78. "Picture insert char at mouse location"
  79. (mouse-move-point *mouse-window* (min 15 *mouse-x*) (min 15 *mouse-y*))
  80. (move-to-column-force (1+ (min 15 (current-column))))
  81. (delete-char -1)
  82. (insert char)
  83. (sc::goto-hotspot))
  84. (defun sc::menu-function (window x y)
  85. (sun-menu-evaluate window (1+ x) y sc::menu))
  86. (defmenu sc::menu
  87. ("Cursor Menu")
  88. ("Pack & Use" sc::pack-buffer-to-cursor)
  89. ("Pack to Icon" sc::pack-buffer-to-icon
  90. (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
  91. ("New Icon" call-interactively 'sc::make-cursor)
  92. ("Edit Icon" sc:edit-cursor
  93. (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
  94. ("Set Cursor" sc:set-cursor
  95. (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
  96. ("Reset Cursor" sc:set-cursor nil)
  97. ("Help". sc::edit-icon-help-menu)
  98. ("Quit" sc::quit-edit)
  99. )
  100. (defun sc::quit-edit ()
  101. (interactive)
  102. (bury-buffer (current-buffer))
  103. (switch-to-buffer (other-buffer) 'no-record))
  104. (defun sc::make-cursor (symbol)
  105. (interactive "SIcon Name: ")
  106. (eval (list 'defcursor symbol 0 0 ""))
  107. (sc::pack-buffer-to-icon (symbol-value symbol)))
  108. (defmenu sc::edit-icon-help-menu
  109. ("Simple Icon Editor")
  110. ("Left => CLEAR")
  111. ("Middle => SET")
  112. ("L & M => HOTSPOT")
  113. ("Right => MENU"))
  114. (defun sc::edit-icon-help ()
  115. (message "Left=> CLEAR Middle=> SET Left+Middle=> HOTSPOT Right=> MENU"))
  116. (defun sc::pack-buffer-to-cursor ()
  117. (sc::pack-buffer-to-icon *edit-icon*)
  118. (sc:set-cursor *edit-icon*))
  119. (defun sc::menu-choose-cursor (window x y)
  120. "Presents a menu of cursor names, and returns one or nil"
  121. (let ((curs sc::cursors)
  122. (items))
  123. (while curs
  124. (push (sc::menu-item-for-cursor (car curs)) items)
  125. (setq curs (cdr curs)))
  126. (push (list "Choose Cursor") items)
  127. (setq menu (menu-create items))
  128. (sun-menu-evaluate window x y menu)))
  129. (defun sc::menu-item-for-cursor (cursor)
  130. "apply function to selected cursor"
  131. (list (symbol-name cursor) 'quote cursor))
  132. (defun sc::hotspot (window x y)
  133. (aset *edit-icon* 0 x)
  134. (aset *edit-icon* 1 y)
  135. (sc::goto-hotspot))
  136. (defun sc::goto-hotspot ()
  137. (goto-line (1+ (aref *edit-icon* 1)))
  138. (move-to-column (aref *edit-icon* 0)))
  139. (defun sc::display-icon (icon)
  140. (setq *edit-icon* (copy-sequence icon))
  141. (let ((string (aref *edit-icon* 2))
  142. (index 0))
  143. (while (< index 32)
  144. (let ((char (aref string index))
  145. (bit 128))
  146. (while (> bit 0)
  147. (insert (sc::char-at-bit char bit))
  148. (setq bit (lsh bit -1))))
  149. (if (eq 1 (mod index 2)) (newline))
  150. (setq index (1+ index))))
  151. (sc::goto-hotspot))
  152. (defun sc::char-at-bit (char bit)
  153. (if (> (logand char bit) 0) "@" " "))
  154. (defun sc::pack-buffer-to-icon (icon)
  155. "Pack 16 x 16 field into icon string"
  156. (goto-char (point-min))
  157. (aset icon 0 (aref *edit-icon* 0))
  158. (aset icon 1 (aref *edit-icon* 1))
  159. (aset icon 2 (mapconcat 'sc::pack-one-line "1234567890123456" ""))
  160. (sc::goto-hotspot)
  161. )
  162. (defun sc::pack-one-line (dummy)
  163. (let* (char chr1 chr2)
  164. (setq char 0 chr1 (mapconcat 'sc::pack-one-char "12345678" "") chr1 char)
  165. (setq char 0 chr2 (mapconcat 'sc::pack-one-char "12345678" "") chr2 char)
  166. (forward-line 1)
  167. (concat (char-to-string chr1) (char-to-string chr2))
  168. ))
  169. (defun sc::pack-one-char (dummy)
  170. "pack following char into char, unless eolp"
  171. (if (or (eolp) (char-equal (following-char) 32))
  172. (setq char (lsh char 1))
  173. (setq char (1+ (lsh char 1))))
  174. (if (not (eolp))(forward-char)))