*** empty log message ***
[emacs.git] / lisp / sun-curs.el
blob36df2de60a4c4888653f9b3b76eeb2bcdb1136b6
1 ;;; sun-cursors.el --- cursor definitions for Sun windows
3 ;; Copyright (C) 1987 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
10 ;; any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
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>
27 (defvar sc::cursors nil "List of known cursors")
29 (defmacro defcursor (name x y string)
30 (if (not (memq name sc::cursors))
31 (setq sc::cursors (cons name sc::cursors)))
32 (list 'defconst name (list 'vector x y string)))
34 ;;; push should be defined in common lisp, but if not use this:
35 ;(defmacro push (v l)
36 ; "The ITEM is evaluated and consed onto LIST, a list-valued atom"
37 ; (list 'setq l (list 'cons v l)))
39 ;;;
40 ;;; The standard default cursor
41 ;;;
42 (defcursor sc:right-arrow 15 0
43 (concat '(0 1 0 3 0 7 0 15 0 31 0 63 0 127 0 15
44 0 27 0 25 0 48 0 48 0 96 0 96 0 192 0 192)))
46 ;;(sc:set-cursor sc:right-arrow)
48 (defcursor sc:fat-left-arrow 0 8
49 (concat '(1 0 3 0 7 0 15 0 31 0 63 255 127 255 255 255
50 255 255 127 255 63 255 31 0 15 0 7 0 3 0 1 0)))
52 (defcursor sc:box 8 8
53 (concat '(15 252 8 4 8 4 8 4 8 4 8 4 8 4 8 4
54 8 132 8 4 8 4 8 4 8 4 8 4 8 4 15 252)))
56 (defcursor sc:hourglass 8 8
57 (concat "\177\376\100\002\040\014\032\070"
58 "\017\360\007\340\003\300\001\200"
59 "\001\200\002\100\005\040\010\020"
60 "\021\210\043\304\107\342\177\376"))
62 (defun sc:set-cursor (icon)
63 "Change the Sun mouse cursor to ICON.
64 If ICON is nil, switch to the system default cursor,
65 Otherwise, ICON should be a vector or the name of a vector of [x y 32-chars]"
66 (interactive "XIcon Name: ")
67 (if (symbolp icon) (setq icon (symbol-value icon)))
68 (sun-change-cursor-icon icon))
70 (make-local-variable '*edit-icon*)
71 (make-variable-buffer-local 'icon-edit)
72 (setq-default icon-edit nil)
73 (or (assq 'icon-edit minor-mode-alist)
74 (push '(icon-edit " IconEdit") minor-mode-alist))
76 (defun sc:edit-cursor (icon)
77 "convert icon to rectangle, edit, and repack"
78 (interactive "XIcon Name: ")
79 (if (not icon) (setq icon (sc::menu-choose-cursor (selected-window) 1 1)))
80 (if (symbolp icon) (setq icon (symbol-value icon)))
81 (if (get-buffer "icon-edit") (kill-buffer "icon-edit"))
82 (switch-to-buffer "icon-edit")
83 (local-set-mouse '(text right) 'sc::menu-function)
84 (local-set-mouse '(text left) '(sc::pic-ins-at-mouse 32))
85 (local-set-mouse '(text middle) '(sc::pic-ins-at-mouse 64))
86 (local-set-mouse '(text left middle) 'sc::hotspot)
87 (sc::display-icon icon)
88 (picture-mode)
89 (setq icon-edit t) ; for mode line display
92 (defun sc::pic-ins-at-mouse (char)
93 "Picture insert char at mouse location"
94 (mouse-move-point *mouse-window* (min 15 *mouse-x*) (min 15 *mouse-y*))
95 (move-to-column-force (1+ (min 15 (current-column))))
96 (delete-char -1)
97 (insert char)
98 (sc::goto-hotspot))
100 (defun sc::menu-function (window x y)
101 (sun-menu-evaluate window (1+ x) y sc::menu))
103 (defmenu sc::menu
104 ("Cursor Menu")
105 ("Pack & Use" sc::pack-buffer-to-cursor)
106 ("Pack to Icon" sc::pack-buffer-to-icon
107 (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
108 ("New Icon" call-interactively 'sc::make-cursor)
109 ("Edit Icon" sc:edit-cursor
110 (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
111 ("Set Cursor" sc:set-cursor
112 (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
113 ("Reset Cursor" sc:set-cursor nil)
114 ("Help". sc::edit-icon-help-menu)
115 ("Quit" sc::quit-edit)
118 (defun sc::quit-edit ()
119 (interactive)
120 (bury-buffer (current-buffer))
121 (switch-to-buffer (other-buffer) 'no-record))
123 (defun sc::make-cursor (symbol)
124 (interactive "SIcon Name: ")
125 (eval (list 'defcursor symbol 0 0 ""))
126 (sc::pack-buffer-to-icon (symbol-value symbol)))
128 (defmenu sc::edit-icon-help-menu
129 ("Simple Icon Editor")
130 ("Left => CLEAR")
131 ("Middle => SET")
132 ("L & M => HOTSPOT")
133 ("Right => MENU"))
135 (defun sc::edit-icon-help ()
136 (message "Left=> CLEAR Middle=> SET Left+Middle=> HOTSPOT Right=> MENU"))
138 (defun sc::pack-buffer-to-cursor ()
139 (sc::pack-buffer-to-icon *edit-icon*)
140 (sc:set-cursor *edit-icon*))
142 (defun sc::menu-choose-cursor (window x y)
143 "Presents a menu of cursor names, and returns one or nil"
144 (let ((curs sc::cursors)
145 (items))
146 (while curs
147 (push (sc::menu-item-for-cursor (car curs)) items)
148 (setq curs (cdr curs)))
149 (push (list "Choose Cursor") items)
150 (setq menu (menu-create items))
151 (sun-menu-evaluate window x y menu)))
153 (defun sc::menu-item-for-cursor (cursor)
154 "apply function to selected cursor"
155 (list (symbol-name cursor) 'quote cursor))
157 (defun sc::hotspot (window x y)
158 (aset *edit-icon* 0 x)
159 (aset *edit-icon* 1 y)
160 (sc::goto-hotspot))
162 (defun sc::goto-hotspot ()
163 (goto-line (1+ (aref *edit-icon* 1)))
164 (move-to-column (aref *edit-icon* 0)))
166 (defun sc::display-icon (icon)
167 (setq *edit-icon* (copy-sequence icon))
168 (let ((string (aref *edit-icon* 2))
169 (index 0))
170 (while (< index 32)
171 (let ((char (aref string index))
172 (bit 128))
173 (while (> bit 0)
174 (insert (sc::char-at-bit char bit))
175 (setq bit (lsh bit -1))))
176 (if (eq 1 (% index 2)) (newline))
177 (setq index (1+ index))))
178 (sc::goto-hotspot))
180 (defun sc::char-at-bit (char bit)
181 (if (> (logand char bit) 0) "@" " "))
183 (defun sc::pack-buffer-to-icon (icon)
184 "Pack 16 x 16 field into icon string"
185 (goto-char (point-min))
186 (aset icon 0 (aref *edit-icon* 0))
187 (aset icon 1 (aref *edit-icon* 1))
188 (aset icon 2 (mapconcat 'sc::pack-one-line "1234567890123456" ""))
189 (sc::goto-hotspot)
192 (defun sc::pack-one-line (dummy)
193 (let* (char chr1 chr2)
194 (setq char 0 chr1 (mapconcat 'sc::pack-one-char "12345678" "") chr1 char)
195 (setq char 0 chr2 (mapconcat 'sc::pack-one-char "12345678" "") chr2 char)
196 (forward-line 1)
197 (concat (char-to-string chr1) (char-to-string chr2))
200 (defun sc::pack-one-char (dummy)
201 "pack following char into char, unless eolp"
202 (if (or (eolp) (char-equal (following-char) 32))
203 (setq char (lsh char 1))
204 (setq char (1+ (lsh char 1))))
205 (if (not (eolp))(forward-char)))
207 (provide 'sm-cursors)
209 ;;; sun-cursors.el ends here