home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / emacs-15.0.3 / lisp / sun-cursors.el < prev    next >
Lisp/Scheme  |  1990-07-19  |  7KB  |  209 lines

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