new version
[emacs.git] / lisp / sun-curs.el
blob0a31d4d3a2e6ac6047900c53959698fc76def769
1 ;;; sun-curs.el --- cursor definitions for Sun windows
3 ;; Copyright (C) 1987 Free Software Foundation, Inc.
5 ;; Author: Jeff Peck <peck@sun.com>
6 ;; Maintainer: none
7 ;; Keywords: hardware
9 ;; This file is part of GNU Emacs.
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
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
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.
26 ;;; Code:
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>
34 (require 'cl)
36 (defvar sc::cursors nil "List of known cursors")
38 (defmacro defcursor (name x y string)
39 (if (not (memq name sc::cursors))
40 (setq sc::cursors (cons name sc::cursors)))
41 (list 'defconst name (list 'vector x y string)))
43 ;;; push should be defined in common lisp, but if not use this:
44 ;(defmacro push (v l)
45 ; "The ITEM is evaluated and consed onto LIST, a list-valued atom"
46 ; (list 'setq l (list 'cons v l)))
48 ;;;
49 ;;; The standard default cursor
50 ;;;
51 (defcursor sc:right-arrow 15 0
52 (concat '(0 1 0 3 0 7 0 15 0 31 0 63 0 127 0 15
53 0 27 0 25 0 48 0 48 0 96 0 96 0 192 0 192)))
55 ;;(sc:set-cursor sc:right-arrow)
57 (defcursor sc:fat-left-arrow 0 8
58 (concat '(1 0 3 0 7 0 15 0 31 0 63 255 127 255 255 255
59 255 255 127 255 63 255 31 0 15 0 7 0 3 0 1 0)))
61 (defcursor sc:box 8 8
62 (concat '(15 252 8 4 8 4 8 4 8 4 8 4 8 4 8 4
63 8 132 8 4 8 4 8 4 8 4 8 4 8 4 15 252)))
65 (defcursor sc:hourglass 8 8
66 (concat "\177\376\100\002\040\014\032\070"
67 "\017\360\007\340\003\300\001\200"
68 "\001\200\002\100\005\040\010\020"
69 "\021\210\043\304\107\342\177\376"))
71 (defun sc:set-cursor (icon)
72 "Change the Sun mouse cursor to ICON.
73 If ICON is nil, switch to the system default cursor,
74 Otherwise, ICON should be a vector or the name of a vector of [x y 32-chars]"
75 (interactive "XIcon Name: ")
76 (if (symbolp icon) (setq icon (symbol-value icon)))
77 (sun-change-cursor-icon icon))
79 (make-local-variable '*edit-icon*)
80 (make-variable-buffer-local 'icon-edit)
81 (setq-default icon-edit nil)
82 (or (assq 'icon-edit minor-mode-alist)
83 (push '(icon-edit " IconEdit") minor-mode-alist))
85 (defun sc:edit-cursor (icon)
86 "convert icon to rectangle, edit, and repack"
87 (interactive "XIcon Name: ")
88 (if (not icon) (setq icon (sc::menu-choose-cursor (selected-window) 1 1)))
89 (if (symbolp icon) (setq icon (symbol-value icon)))
90 (if (get-buffer "icon-edit") (kill-buffer "icon-edit"))
91 (switch-to-buffer "icon-edit")
92 (local-set-mouse '(text right) 'sc::menu-function)
93 (local-set-mouse '(text left) '(sc::pic-ins-at-mouse 32))
94 (local-set-mouse '(text middle) '(sc::pic-ins-at-mouse 64))
95 (local-set-mouse '(text left middle) 'sc::hotspot)
96 (sc::display-icon icon)
97 (picture-mode)
98 (setq icon-edit t) ; for mode line display
101 (defun sc::pic-ins-at-mouse (char)
102 "Picture insert char at mouse location"
103 (mouse-move-point *mouse-window* (min 15 *mouse-x*) (min 15 *mouse-y*))
104 (move-to-column (1+ (min 15 (current-column))) t)
105 (delete-char -1)
106 (insert char)
107 (sc::goto-hotspot))
109 (defun sc::menu-function (window x y)
110 (sun-menu-evaluate window (1+ x) y sc::menu))
112 (defmenu sc::menu
113 ("Cursor Menu")
114 ("Pack & Use" sc::pack-buffer-to-cursor)
115 ("Pack to Icon" sc::pack-buffer-to-icon
116 (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
117 ("New Icon" call-interactively 'sc::make-cursor)
118 ("Edit Icon" sc:edit-cursor
119 (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
120 ("Set Cursor" sc:set-cursor
121 (sc::menu-choose-cursor *menu-window* *menu-x* *menu-y*))
122 ("Reset Cursor" sc:set-cursor nil)
123 ("Help" sc::edit-icon-help-menu)
124 ("Quit" sc::quit-edit)
127 (defun sc::quit-edit ()
128 (interactive)
129 (bury-buffer (current-buffer))
130 (switch-to-buffer (other-buffer) 'no-record))
132 (defun sc::make-cursor (symbol)
133 (interactive "SIcon Name: ")
134 (eval (list 'defcursor symbol 0 0 ""))
135 (sc::pack-buffer-to-icon (symbol-value symbol)))
137 (defmenu sc::edit-icon-help-menu
138 ("Simple Icon Editor")
139 ("Left => CLEAR")
140 ("Middle => SET")
141 ("L & M => HOTSPOT")
142 ("Right => MENU"))
144 (defun sc::edit-icon-help ()
145 (message "Left=> CLEAR Middle=> SET Left+Middle=> HOTSPOT Right=> MENU"))
147 (defun sc::pack-buffer-to-cursor ()
148 (sc::pack-buffer-to-icon *edit-icon*)
149 (sc:set-cursor *edit-icon*))
151 (defun sc::menu-choose-cursor (window x y)
152 "Presents a menu of cursor names, and returns one or nil"
153 (let ((curs sc::cursors)
154 (items))
155 (while curs
156 (push (sc::menu-item-for-cursor (car curs)) items)
157 (setq curs (cdr curs)))
158 (push (list "Choose Cursor") items)
159 (setq menu (menu-create items))
160 (sun-menu-evaluate window x y menu)))
162 (defun sc::menu-item-for-cursor (cursor)
163 "apply function to selected cursor"
164 (list (symbol-name cursor) 'quote cursor))
166 (defun sc::hotspot (window x y)
167 (aset *edit-icon* 0 x)
168 (aset *edit-icon* 1 y)
169 (sc::goto-hotspot))
171 (defun sc::goto-hotspot ()
172 (goto-line (1+ (aref *edit-icon* 1)))
173 (move-to-column (aref *edit-icon* 0)))
175 (defun sc::display-icon (icon)
176 (setq *edit-icon* (copy-sequence icon))
177 (let ((string (aref *edit-icon* 2))
178 (index 0))
179 (while (< index 32)
180 (let ((char (aref string index))
181 (bit 128))
182 (while (> bit 0)
183 (insert (sc::char-at-bit char bit))
184 (setq bit (lsh bit -1))))
185 (if (eq 1 (% index 2)) (newline))
186 (setq index (1+ index))))
187 (sc::goto-hotspot))
189 (defun sc::char-at-bit (char bit)
190 (if (> (logand char bit) 0) "@" " "))
192 (defun sc::pack-buffer-to-icon (icon)
193 "Pack 16 x 16 field into icon string"
194 (goto-char (point-min))
195 (aset icon 0 (aref *edit-icon* 0))
196 (aset icon 1 (aref *edit-icon* 1))
197 (aset icon 2 (mapconcat 'sc::pack-one-line "1234567890123456" ""))
198 (sc::goto-hotspot)
201 (defun sc::pack-one-line (dummy)
202 (let* (char chr1 chr2)
203 (setq char 0 chr1 (mapconcat 'sc::pack-one-char "12345678" "") chr1 char)
204 (setq char 0 chr2 (mapconcat 'sc::pack-one-char "12345678" "") chr2 char)
205 (forward-line 1)
206 (concat (char-to-string chr1) (char-to-string chr2))
209 (defun sc::pack-one-char (dummy)
210 "pack following char into char, unless eolp"
211 (if (or (eolp) (char-equal (following-char) 32))
212 (setq char (lsh char 1))
213 (setq char (1+ (lsh char 1))))
214 (if (not (eolp))(forward-char)))
216 (provide 'sm-cursors)
218 ;;; sun-curs.el ends here