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