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