annotate lisp/custom/wid-edit.el @ 44:8d2a9b52c682 r19-15prefinal

Import from CVS: tag r19-15prefinal
author cvs
date Mon, 13 Aug 2007 08:55:10 +0200
parents c53a95d3c46d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1 ;;; wid-edit.el --- Functions for creating and using widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
4 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
6 ;; Keywords: extensions
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
7 ;; Version: 1.67
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
9
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
10 ;;; Commentary:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
11 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
12 ;; See `widget.el'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
13
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
14 ;;; Code:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
15
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
16 (require 'widget)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
17
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
18 (eval-and-compile
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
19 (require 'cl))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
20
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
21 ;;; Compatibility.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
22
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
23 (eval-and-compile
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
24 (autoload 'pp-to-string "pp")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
25 (autoload 'Info-goto-node "info")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
26
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
27 (if (string-match "XEmacs" emacs-version)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
28 ;; XEmacs spell `intangible' as `atomic'.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
29 (defun widget-make-intangible (from to side)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
30 "Make text between FROM and TO atomic with regard to movement.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
31 Third argument should be `start-open' if it should be sticky to the rear,
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
32 and `end-open' if it should sticky to the front."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
33 (require 'atomic-extents)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
34 (let ((ext (make-extent from to)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
35 ;; XEmacs doesn't understant different kinds of read-only, so
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
36 ;; we have to use extents instead.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
37 (put-text-property from to 'read-only nil)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
38 (set-extent-property ext 'read-only t)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
39 (set-extent-property ext 'start-open nil)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
40 (set-extent-property ext 'end-open nil)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
41 (set-extent-property ext side t)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
42 (set-extent-property ext 'atomic t)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
43 (defun widget-make-intangible (from to size)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
44 "Make text between FROM and TO intangible."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
45 (put-text-property from to 'intangible 'front)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
46
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
47 ;; The following should go away when bundled with Emacs.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
48 (condition-case ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
49 (require 'custom)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
50 (error nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
51
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
52 (unless (and (featurep 'custom) (fboundp 'custom-declare-variable))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
53 ;; We have the old custom-library, hack around it!
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
54 (defmacro defgroup (&rest args) nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
55 (defmacro defcustom (var value doc &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
56 `(defvar ,var ,value ,doc))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
57 (defmacro defface (&rest args) nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
58 (define-widget-keywords :prefix :tag :load :link :options :type :group)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
59 (when (fboundp 'copy-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
60 (copy-face 'default 'widget-documentation-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
61 (copy-face 'bold 'widget-button-face)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
62 (copy-face 'italic 'widget-field-face)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
63
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
64 (unless (fboundp 'event-point)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
65 ;; XEmacs function missing in Emacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
66 (defun event-point (event)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
67 "Return the character position of the given mouse-motion, button-press,
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
68 or button-release event. If the event did not occur over a window, or did
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
69 not occur over text, then this returns nil. Otherwise, it returns an index
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
70 into the buffer visible in the event's window."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
71 (posn-point (event-start event))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
72
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
73 (unless (fboundp 'error-message-string)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
74 ;; Emacs function missing in XEmacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
75 (defun error-message-string (obj)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
76 "Convert an error value to an error message."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
77 (let ((buf (get-buffer-create " *error-message*")))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
78 (erase-buffer buf)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
79 (display-error obj buf)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
80 (buffer-string buf)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
81
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
82 ;;; Customization.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
83
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
84 (defgroup widgets nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
85 "Customization support for the Widget Library."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
86 :link '(custom-manual "(widget)Top")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
87 :link '(url-link :tag "Development Page"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
88 "http://www.dina.kvl.dk/~abraham/custom/")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
89 :prefix "widget-"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
90 :group 'extensions
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
91 :group 'faces
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
92 :group 'hypermedia)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
93
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
94 (defface widget-documentation-face '((((class color)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
95 (background dark))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
96 (:foreground "lime green"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
97 (((class color)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
98 (background light))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
99 (:foreground "dark green"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
100 (t nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
101 "Face used for documentation text."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
102 :group 'widgets)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
103
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
104 (defface widget-button-face '((t (:bold t)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
105 "Face used for widget buttons."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
106 :group 'widgets)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
107
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
108 (defcustom widget-mouse-face 'highlight
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
109 "Face used for widget buttons when the mouse is above them."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
110 :type 'face
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
111 :group 'widgets)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
112
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
113 (defface widget-field-face '((((class grayscale color)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
114 (background light))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
115 (:background "light gray"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
116 (((class grayscale color)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
117 (background dark))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
118 (:background "dark gray"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
119 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
120 (:italic t)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
121 "Face used for editable fields."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
122 :group 'widgets)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
123
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
124 (defcustom widget-menu-max-size 40
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
125 "Largest number of items allowed in a popup-menu.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
126 Larger menus are read through the minibuffer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
127 :group 'widgets
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
128 :type 'integer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
129
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
130 ;;; Utility functions.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
131 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
132 ;; These are not really widget specific.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
133
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
134 (defsubst widget-plist-member (plist prop)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
135 ;; Return non-nil if PLIST has the property PROP.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
136 ;; PLIST is a property list, which is a list of the form
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
137 ;; (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
138 ;; Unlike `plist-get', this allows you to distinguish between a missing
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
139 ;; property and a property with the value nil.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
140 ;; The value is actually the tail of PLIST whose car is PROP.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
141 (while (and plist (not (eq (car plist) prop)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
142 (setq plist (cdr (cdr plist))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
143 plist)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
144
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
145 (defun widget-princ-to-string (object)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
146 ;; Return string representation of OBJECT, any Lisp object.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
147 ;; No quoting characters are used; no delimiters are printed around
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
148 ;; the contents of strings.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
149 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
150 (set-buffer (get-buffer-create " *widget-tmp*"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
151 (erase-buffer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
152 (let ((standard-output (current-buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
153 (princ object))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
154 (buffer-string)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
155
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
156 (defun widget-clear-undo ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
157 "Clear all undo information."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
158 (buffer-disable-undo (current-buffer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
159 (buffer-enable-undo))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
160
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
161 (defun widget-choose (title items &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
162 "Choose an item from a list.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
163
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
164 First argument TITLE is the name of the list.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
165 Second argument ITEMS is an alist (NAME . VALUE).
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
166 Optional third argument EVENT is an input event.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
167
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
168 The user is asked to choose between each NAME from the items alist,
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
169 and the VALUE of the chosen element will be returned. If EVENT is a
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
170 mouse event, and the number of elements in items is less than
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
171 `widget-menu-max-size', a popup menu will be used, otherwise the
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
172 minibuffer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
173 (cond ((and (< (length items) widget-menu-max-size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
174 event (fboundp 'x-popup-menu) window-system)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
175 ;; We are in Emacs-19, pressed by the mouse
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
176 (x-popup-menu event
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
177 (list title (cons "" items))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
178 ((and (< (length items) widget-menu-max-size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
179 event (fboundp 'popup-menu) window-system)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
180 ;; We are in XEmacs, pressed by the mouse
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
181 (let ((val (get-popup-menu-response
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
182 (cons title
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
183 (mapcar
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
184 (function
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
185 (lambda (x)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
186 (vector (car x) (list (car x)) t)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
187 items)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
188 (setq val (and val
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
189 (listp (event-object val))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
190 (stringp (car-safe (event-object val)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
191 (car (event-object val))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
192 (cdr (assoc val items))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
193 (t
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
194 (let ((val (completing-read (concat title ": ") items nil t)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
195 (if (stringp val)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
196 (let ((try (try-completion val items)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
197 (when (stringp try)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
198 (setq val try))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
199 (cdr (assoc val items)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
200 nil)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
201
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
202 (defun widget-get-sibling (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
203 "Get the item WIDGET is assumed to toggle.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
204 This is only meaningful for radio buttons or checkboxes in a list."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
205 (let* ((parent (widget-get widget :parent))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
206 (children (widget-get parent :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
207 child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
208 (catch 'child
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
209 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
210 (setq child (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
211 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
212 (when (eq (widget-get child :button) widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
213 (throw 'child child)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
214 nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
215
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
216 ;;; Widget text specifications.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
217 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
218 ;; These functions are for specifying text properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
219
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
220 (defun widget-specify-none (from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
221 ;; Clear all text properties between FROM and TO.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
222 (set-text-properties from to nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
223
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
224 (defun widget-specify-text (from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
225 ;; Default properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
226 (add-text-properties from to (list 'read-only t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
227 'front-sticky t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
228 'start-open t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
229 'end-open t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
230 'rear-nonsticky nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
231
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
232 (defun widget-specify-field (widget from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
233 ;; Specify editable button for WIDGET between FROM and TO.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
234 (widget-specify-field-update widget from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
235
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
236 ;; Make it possible to edit the front end of the field.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
237 (add-text-properties (1- from) from (list 'rear-nonsticky t
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
238 'end-open t
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
239 'invisible t))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
240 (when (or (string-match "\\(.\\|\n\\)%v" (widget-get widget :format))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
241 (widget-get widget :hide-front-space))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
242 ;; WARNING: This is going to lose horrible if the character just
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
243 ;; before the field can be modified (e.g. if it belongs to a
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
244 ;; choice widget). We try to compensate by checking the format
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
245 ;; string, and hope the user hasn't changed the :create method.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
246 (widget-make-intangible (- from 2) from 'end-open))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
247
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
248 ;; Make it possible to edit back end of the field.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
249 (add-text-properties to (1+ to) (list 'front-sticky nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
250 'read-only t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
251 'start-open t))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
252
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
253 (cond ((widget-get widget :size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
254 (put-text-property to (1+ to) 'invisible t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
255 (when (or (string-match "%v\\(.\\|\n\\)" (widget-get widget :format))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
256 (widget-get widget :hide-rear-space))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
257 ;; WARNING: This is going to lose horrible if the character just
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
258 ;; after the field can be modified (e.g. if it belongs to a
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
259 ;; choice widget). We try to compensate by checking the format
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
260 ;; string, and hope the user hasn't changed the :create method.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
261 (widget-make-intangible to (+ to 2) 'start-open)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
262 ((string-match "XEmacs" emacs-version)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
263 ;; XEmacs does not allow you to insert before a read-only
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
264 ;; character, even if it is start.open.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
265 ;; XEmacs does allow you to delete an read-only extent, so
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
266 ;; making the terminating newline read only doesn't help.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
267 ;; I tried putting an invisible intangible read-only space
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
268 ;; before the newline, which gave really weird effects.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
269 ;; So for now, we just have trust the user not to delete the
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
270 ;; newline.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
271 (put-text-property to (1+ to) 'read-only nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
272
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
273 (defun widget-specify-field-update (widget from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
274 ;; Specify editable button for WIDGET between FROM and TO.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
275 (let ((map (widget-get widget :keymap))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
276 (secret (widget-get widget :secret))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
277 (secret-to to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
278 (size (widget-get widget :size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
279 (face (or (widget-get widget :value-face)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
280 'widget-field-face))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
281 (help-echo (widget-get widget :help-echo))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
282 (help-property (if (featurep 'balloon-help)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
283 'balloon-help
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
284 'help-echo)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
285 (unless (or (stringp help-echo) (null help-echo))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
286 (setq help-echo 'widget-mouse-help))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
287
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
288 (when secret
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
289 (while (and size
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
290 (not (zerop size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
291 (> secret-to from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
292 (eq (char-after (1- secret-to)) ?\ ))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
293 (setq secret-to (1- secret-to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
294
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
295 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
296 (goto-char from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
297 (while (< (point) secret-to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
298 (let ((old (get-text-property (point) 'secret)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
299 (when old
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
300 (subst-char-in-region (point) (1+ (point)) secret old)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
301 (forward-char))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
302
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
303 (set-text-properties from to (list 'field widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
304 'read-only nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
305 'keymap map
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
306 'local-map map
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
307 help-property help-echo
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
308 'face face))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
309
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
310 (when secret
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
311 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
312 (goto-char from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
313 (while (< (point) secret-to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
314 (let ((old (following-char)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
315 (subst-char-in-region (point) (1+ (point)) old secret)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
316 (put-text-property (point) (1+ (point)) 'secret old))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
317 (forward-char))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
318
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
319 (unless (widget-get widget :size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
320 (add-text-properties to (1+ to) (list 'field widget
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
321 help-property help-echo
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
322 'face face)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
323 (add-text-properties to (1+ to) (list 'local-map map
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
324 'keymap map))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
325
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
326 (defun widget-specify-button (widget from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
327 ;; Specify button for WIDGET between FROM and TO.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
328 (let ((face (widget-apply widget :button-face-get))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
329 (help-echo (widget-get widget :help-echo))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
330 (help-property (if (featurep 'balloon-help)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
331 'balloon-help
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
332 'help-echo)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
333 (unless (or (null help-echo) (stringp help-echo))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
334 (setq help-echo 'widget-mouse-help))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
335 (add-text-properties from to (list 'button widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
336 'mouse-face widget-mouse-face
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
337 'start-open t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
338 'end-open t
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
339 help-property help-echo
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
340 'face face))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
341
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
342 (defun widget-mouse-help (extent)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
343 "Find mouse help string for button in extent."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
344 (let* ((widget (widget-at (extent-start-position extent)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
345 (help-echo (and widget (widget-get widget :help-echo))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
346 (cond ((stringp help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
347 help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
348 ((and (symbolp help-echo) (fboundp help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
349 (stringp (setq help-echo (funcall help-echo widget))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
350 help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
351 (t
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
352 (format "(widget %S :help-echo %S)" widget help-echo)))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
353
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
354 (defun widget-specify-sample (widget from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
355 ;; Specify sample for WIDGET between FROM and TO.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
356 (let ((face (widget-apply widget :sample-face-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
357 (when face
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
358 (add-text-properties from to (list 'start-open t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
359 'end-open t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
360 'face face)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
361
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
362 (defun widget-specify-doc (widget from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
363 ;; Specify documentation for WIDGET between FROM and TO.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
364 (add-text-properties from to (list 'widget-doc widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
365 'face 'widget-documentation-face)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
366
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
367 (defmacro widget-specify-insert (&rest form)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
368 ;; Execute FORM without inheriting any text properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
369 `(save-restriction
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
370 (let ((inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
371 result
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
372 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
373 (insert "<>")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
374 (narrow-to-region (- (point) 2) (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
375 (widget-specify-none (point-min) (point-max))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
376 (goto-char (1+ (point-min)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
377 (setq result (progn ,@form))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
378 (delete-region (point-min) (1+ (point-min)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
379 (delete-region (1- (point-max)) (point-max))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
380 (goto-char (point-max))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
381 result)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
382
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
383 ;;; Widget Properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
384
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
385 (defsubst widget-type (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
386 "Return the type of WIDGET, a symbol."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
387 (car widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
388
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
389 (defun widget-put (widget property value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
390 "In WIDGET set PROPERTY to VALUE.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
391 The value can later be retrived with `widget-get'."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
392 (setcdr widget (plist-put (cdr widget) property value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
393
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
394 (defun widget-get (widget property)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
395 "In WIDGET, get the value of PROPERTY.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
396 The value could either be specified when the widget was created, or
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
397 later with `widget-put'."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
398 (let ((missing t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
399 value tmp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
400 (while missing
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
401 (cond ((setq tmp (widget-plist-member (cdr widget) property))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
402 (setq value (car (cdr tmp))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
403 missing nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
404 ((setq tmp (car widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
405 (setq widget (get tmp 'widget-type)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
406 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
407 (setq missing nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
408 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
409
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
410 (defun widget-member (widget property)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
411 "Non-nil iff there is a definition in WIDGET for PROPERTY."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
412 (cond ((widget-plist-member (cdr widget) property)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
413 t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
414 ((car widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
415 (widget-member (get (car widget) 'widget-type) property))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
416 (t nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
417
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
418 (defun widget-apply (widget property &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
419 "Apply the value of WIDGET's PROPERTY to the widget itself.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
420 ARGS are passed as extra arguments to the function."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
421 (apply (widget-get widget property) widget args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
422
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
423 (defun widget-value (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
424 "Extract the current value of WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
425 (widget-apply widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
426 :value-to-external (widget-apply widget :value-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
427
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
428 (defun widget-value-set (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
429 "Set the current value of WIDGET to VALUE."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
430 (widget-apply widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
431 :value-set (widget-apply widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
432 :value-to-internal value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
433
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
434 (defun widget-match-inline (widget vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
435 ;; In WIDGET, match the start of VALS.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
436 (cond ((widget-get widget :inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
437 (widget-apply widget :match-inline vals))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
438 ((and vals
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
439 (widget-apply widget :match (car vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
440 (cons (list (car vals)) (cdr vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
441 (t nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
442
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
443 ;;; Glyphs.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
444
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
445 (defcustom widget-glyph-directory (concat data-directory "custom/")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
446 "Where widget glyphs are located.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
447 If this variable is nil, widget will try to locate the directory
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
448 automatically. This does not work yet."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
449 :group 'widgets
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
450 :type 'directory)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
451
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
452 (defcustom widget-glyph-enable t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
453 "If non nil, use glyphs in images when available."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
454 :group 'widgets
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
455 :type 'boolean)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
456
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
457 (defun widget-glyph-insert (widget tag image)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
458 "In WIDGET, insert the text TAG or, if supported, IMAGE.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
459 IMAGE should either be a glyph, or a name sans extension of an xpm or
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
460 xbm file located in `widget-glyph-directory'.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
461
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
462 WARNING: If you call this with a glyph, and you want theuser to be
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
463 able to activate the glyph, make sure it is unique. If you use the
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
464 same glyph for multiple widgets, "
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
465 (cond ((not (and (string-match "XEmacs" emacs-version)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
466 widget-glyph-enable
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
467 (fboundp 'make-glyph)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
468 image))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
469 ;; We don't want or can't use glyphs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
470 (insert tag))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
471 ((and (fboundp 'glyphp)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
472 (glyphp image))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
473 ;; Already a glyph. Insert it.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
474 (widget-glyph-insert-glyph widget tag image))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
475 (t
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
476 ;; A string. Look it up in.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
477 (let ((file (concat widget-glyph-directory
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
478 (if (string-match "/\\'" widget-glyph-directory)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
479 ""
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
480 "/")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
481 image
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
482 (if (featurep 'xpm) ".xpm" ".xbm"))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
483 (if (file-readable-p file)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
484 (widget-glyph-insert-glyph widget tag (make-glyph file))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
485 ;; File not readable, give up.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
486 (insert tag))))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
487
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
488 (defun widget-glyph-insert-glyph (widget tag glyph)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
489 "In WIDGET, with alternative text TAG, insert GLYPH."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
490 (set-glyph-image glyph (cons 'tty tag))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
491 (set-glyph-property glyph 'widget widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
492 (insert "*")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
493 (add-text-properties (1- (point)) (point)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
494 (list 'invisible t
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
495 'end-glyph glyph))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
496 (let ((help-echo (widget-get widget :help-echo)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
497 (when help-echo
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
498 (let ((extent (extent-at (1- (point)) nil 'end-glyph))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
499 (help-property (if (featurep 'balloon-help)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
500 'balloon-help
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
501 'help-echo)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
502 (set-extent-property extent help-property (if (stringp help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
503 help-echo
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
504 'widget-mouse-help))))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
505
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
506 ;;; Creating Widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
507
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
508 ;;;###autoload
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
509 (defun widget-create (type &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
510 "Create widget of TYPE.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
511 The optional ARGS are additional keyword arguments."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
512 (let ((widget (apply 'widget-convert type args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
513 (widget-apply widget :create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
514 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
515
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
516 (defun widget-create-child-and-convert (parent type &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
517 "As part of the widget PARENT, create a child widget TYPE.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
518 The child is converted, using the keyword arguments ARGS."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
519 (let ((widget (apply 'widget-convert type args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
520 (widget-put widget :parent parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
521 (unless (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
522 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
523 (or (widget-get widget :extra-offset) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
524 (widget-get parent :offset))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
525 (widget-apply widget :create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
526 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
527
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
528 (defun widget-create-child (parent type)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
529 "Create widget of TYPE."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
530 (let ((widget (copy-list type)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
531 (widget-put widget :parent parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
532 (unless (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
533 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
534 (or (widget-get widget :extra-offset) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
535 (widget-get parent :offset))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
536 (widget-apply widget :create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
537 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
538
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
539 (defun widget-create-child-value (parent type value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
540 "Create widget of TYPE with value VALUE."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
541 (let ((widget (copy-list type)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
542 (widget-put widget :value (widget-apply widget :value-to-internal value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
543 (widget-put widget :parent parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
544 (unless (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
545 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
546 (or (widget-get widget :extra-offset) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
547 (widget-get parent :offset))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
548 (widget-apply widget :create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
549 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
550
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
551 ;;;###autoload
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
552 (defun widget-delete (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
553 "Delete WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
554 (widget-apply widget :delete))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
555
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
556 (defun widget-convert (type &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
557 "Convert TYPE to a widget without inserting it in the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
558 The optional ARGS are additional keyword arguments."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
559 ;; Don't touch the type.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
560 (let* ((widget (if (symbolp type)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
561 (list type)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
562 (copy-list type)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
563 (current widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
564 (keys args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
565 ;; First set the :args keyword.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
566 (while (cdr current) ;Look in the type.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
567 (let ((next (car (cdr current))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
568 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
569 (setq current (cdr (cdr current)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
570 (setcdr current (list :args (cdr current)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
571 (setq current nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
572 (while args ;Look in the args.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
573 (let ((next (nth 0 args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
574 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
575 (setq args (nthcdr 2 args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
576 (widget-put widget :args args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
577 (setq args nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
578 ;; Then Convert the widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
579 (setq type widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
580 (while type
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
581 (let ((convert-widget (plist-get (cdr type) :convert-widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
582 (if convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
583 (setq widget (funcall convert-widget widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
584 (setq type (get (car type) 'widget-type)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
585 ;; Finally set the keyword args.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
586 (while keys
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
587 (let ((next (nth 0 keys)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
588 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
589 (progn
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
590 (widget-put widget next (nth 1 keys))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
591 (setq keys (nthcdr 2 keys)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
592 (setq keys nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
593 ;; Convert the :value to internal format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
594 (if (widget-member widget :value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
595 (let ((value (widget-get widget :value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
596 (widget-put widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
597 :value (widget-apply widget :value-to-internal value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
598 ;; Return the newly create widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
599 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
600
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
601 (defun widget-insert (&rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
602 "Call `insert' with ARGS and make the text read only."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
603 (let ((inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
604 after-change-functions
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
605 (from (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
606 (apply 'insert args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
607 (widget-specify-text from (point))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
608
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
609 ;;; Keymap and Commands.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
610
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
611 (defvar widget-keymap nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
612 "Keymap containing useful binding for buffers containing widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
613 Recommended as a parent keymap for modes using widgets.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
614
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
615 (unless widget-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
616 (setq widget-keymap (make-sparse-keymap))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
617 (define-key widget-keymap "\C-k" 'widget-kill-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
618 (define-key widget-keymap "\t" 'widget-forward)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
619 (define-key widget-keymap "\M-\t" 'widget-backward)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
620 (define-key widget-keymap [(shift tab)] 'widget-backward)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
621 (define-key widget-keymap [backtab] 'widget-backward)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
622 (if (string-match "XEmacs" (emacs-version))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
623 (progn
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
624 (define-key widget-keymap [button2] 'widget-button-click)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
625 (define-key widget-keymap [button1] 'widget-button1-click))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
626 (define-key widget-keymap [mouse-2] 'ignore)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
627 (define-key widget-keymap [down-mouse-2] 'widget-button-click))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
628 (define-key widget-keymap "\C-m" 'widget-button-press))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
629
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
630 (defvar widget-global-map global-map
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
631 "Keymap used for events the widget does not handle themselves.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
632 (make-variable-buffer-local 'widget-global-map)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
633
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
634 (defvar widget-field-keymap nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
635 "Keymap used inside an editable field.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
636
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
637 (unless widget-field-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
638 (setq widget-field-keymap (copy-keymap widget-keymap))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
639 (unless (string-match "XEmacs" (emacs-version))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
640 (define-key widget-field-keymap [menu-bar] 'nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
641 (define-key widget-field-keymap "\C-m" 'widget-field-activate)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
642 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
643 (define-key widget-field-keymap "\C-e" 'widget-end-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
644 (set-keymap-parent widget-field-keymap global-map))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
645
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
646 (defvar widget-text-keymap nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
647 "Keymap used inside a text field.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
648
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
649 (unless widget-text-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
650 (setq widget-text-keymap (copy-keymap widget-keymap))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
651 (unless (string-match "XEmacs" (emacs-version))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
652 (define-key widget-text-keymap [menu-bar] 'nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
653 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
654 (define-key widget-text-keymap "\C-e" 'widget-end-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
655 (set-keymap-parent widget-text-keymap global-map))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
656
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
657 (defun widget-field-activate (pos &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
658 "Activate the ediable field at point."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
659 (interactive "@d")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
660 (let ((field (get-text-property pos 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
661 (if field
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
662 (widget-apply field :action event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
663 (call-interactively
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
664 (lookup-key widget-global-map (this-command-keys))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
665
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
666 (defun widget-button-click (event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
667 "Activate button below mouse pointer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
668 (interactive "@e")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
669 (cond ((and (fboundp 'event-glyph)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
670 (event-glyph event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
671 (let ((widget (glyph-property (event-glyph event) 'widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
672 (if widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
673 (widget-apply widget :action event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
674 (message "You clicked on a glyph."))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
675 ((event-point event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
676 (let ((button (get-text-property (event-point event) 'button)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
677 (if button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
678 (widget-apply button :action event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
679 (call-interactively
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
680 (or (lookup-key widget-global-map [ button2 ])
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
681 (lookup-key widget-global-map [ down-mouse-2 ])
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
682 (lookup-key widget-global-map [ mouse-2]))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
683 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
684 (message "You clicked somewhere weird."))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
685
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
686 (defun widget-button1-click (event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
687 "Activate glyph below mouse pointer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
688 (interactive "@e")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
689 (if (and (fboundp 'event-glyph)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
690 (event-glyph event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
691 (let ((widget (glyph-property (event-glyph event) 'widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
692 (if widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
693 (widget-apply widget :action event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
694 (message "You clicked on a glyph.")))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
695 (call-interactively (lookup-key widget-global-map (this-command-keys)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
696
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
697 (defun widget-button-press (pos &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
698 "Activate button at POS."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
699 (interactive "@d")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
700 (let ((button (get-text-property pos 'button)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
701 (if button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
702 (widget-apply button :action event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
703 (let ((command (lookup-key widget-global-map (this-command-keys))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
704 (when (commandp command)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
705 (call-interactively command))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
706
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
707 (defun widget-move (arg)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
708 "Move point to the ARG next field or button.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
709 ARG may be negative to move backward."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
710 (while (> arg 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
711 (setq arg (1- arg))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
712 (let ((next (cond ((get-text-property (point) 'button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
713 (next-single-property-change (point) 'button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
714 ((get-text-property (point) 'field)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
715 (next-single-property-change (point) 'field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
716 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
717 (point)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
718 (if (null next) ; Widget extends to end. of buffer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
719 (setq next (point-min)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
720 (let ((button (next-single-property-change next 'button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
721 (field (next-single-property-change next 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
722 (cond ((or (get-text-property next 'button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
723 (get-text-property next 'field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
724 (goto-char next))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
725 ((and button field)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
726 (goto-char (min button field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
727 (button (goto-char button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
728 (field (goto-char field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
729 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
730 (let ((button (next-single-property-change (point-min) 'button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
731 (field (next-single-property-change (point-min) 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
732 (cond ((and button field) (goto-char (min button field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
733 (button (goto-char button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
734 (field (goto-char field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
735 (t
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
736 (error "No buttons or fields found"))))))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
737 (setq button (widget-at (point)))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
738 (if (and button (widget-get button :tab-order)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
739 (< (widget-get button :tab-order) 0))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
740 (setq arg (1+ arg))))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
741 (while (< arg 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
742 (if (= (point-min) (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
743 (forward-char 1))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
744 (setq arg (1+ arg))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
745 (let ((previous (cond ((get-text-property (1- (point)) 'button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
746 (previous-single-property-change (point) 'button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
747 ((get-text-property (1- (point)) 'field)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
748 (previous-single-property-change (point) 'field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
749 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
750 (point)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
751 (if (null previous) ; Widget extends to beg. of buffer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
752 (setq previous (point-max)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
753 (let ((button (previous-single-property-change previous 'button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
754 (field (previous-single-property-change previous 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
755 (cond ((and button field)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
756 (goto-char (max button field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
757 (button (goto-char button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
758 (field (goto-char field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
759 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
760 (let ((button (previous-single-property-change
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
761 (point-max) 'button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
762 (field (previous-single-property-change
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
763 (point-max) 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
764 (cond ((and button field) (goto-char (max button field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
765 (button (goto-char button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
766 (field (goto-char field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
767 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
768 (error "No buttons or fields found"))))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
769 (let ((button (previous-single-property-change (point) 'button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
770 (field (previous-single-property-change (point) 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
771 (cond ((and button field)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
772 (goto-char (max button field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
773 (button (goto-char button))
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
774 (field (goto-char field)))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
775 (setq button (widget-at (point)))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
776 (if (and button (widget-get button :tab-order)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
777 (< (widget-get button :tab-order) 0))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
778 (setq arg (1- arg)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
779 (widget-echo-help (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
780 (run-hooks 'widget-move-hook))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
781
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
782 (defun widget-forward (arg)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
783 "Move point to the next field or button.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
784 With optional ARG, move across that many fields."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
785 (interactive "p")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
786 (run-hooks 'widget-forward-hook)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
787 (widget-move arg))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
788
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
789 (defun widget-backward (arg)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
790 "Move point to the previous field or button.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
791 With optional ARG, move across that many fields."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
792 (interactive "p")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
793 (run-hooks 'widget-backward-hook)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
794 (widget-move (- arg)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
795
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
796 (defun widget-beginning-of-line ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
797 "Go to beginning of field or beginning of line, whichever is first."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
798 (interactive)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
799 (let ((bol (save-excursion (beginning-of-line) (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
800 (prev (previous-single-property-change (point) 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
801 (goto-char (max bol (or prev bol)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
802
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
803 (defun widget-end-of-line ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
804 "Go to end of field or end of line, whichever is first."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
805 (interactive)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
806 (let ((bol (save-excursion (end-of-line) (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
807 (prev (next-single-property-change (point) 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
808 (goto-char (min bol (or prev bol)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
809
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
810 (defun widget-kill-line ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
811 "Kill to end of field or end of line, whichever is first."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
812 (interactive)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
813 (let ((field (get-text-property (point) 'field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
814 (newline (save-excursion (search-forward "\n")))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
815 (next (next-single-property-change (point) 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
816 (if (and field (> newline next))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
817 (kill-region (point) next)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
818 (call-interactively 'kill-line))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
819
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
820 ;;; Setting up the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
821
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
822 (defvar widget-field-new nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
823 ;; List of all newly created editable fields in the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
824 (make-variable-buffer-local 'widget-field-new)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
825
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
826 (defvar widget-field-list nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
827 ;; List of all editable fields in the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
828 (make-variable-buffer-local 'widget-field-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
829
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
830 (defun widget-setup ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
831 "Setup current buffer so editing string widgets works."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
832 (let ((inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
833 (after-change-functions nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
834 field)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
835 (while widget-field-new
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
836 (setq field (car widget-field-new)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
837 widget-field-new (cdr widget-field-new)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
838 widget-field-list (cons field widget-field-list))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
839 (let ((from (widget-get field :value-from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
840 (to (widget-get field :value-to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
841 (widget-specify-field field from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
842 (move-marker from (1- from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
843 (move-marker to (1+ to)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
844 (widget-clear-undo)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
845 ;; We need to maintain text properties and size of the editing fields.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
846 (make-local-variable 'after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
847 (if widget-field-list
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
848 (setq after-change-functions '(widget-after-change))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
849 (setq after-change-functions nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
850
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
851 (defvar widget-field-last nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
852 ;; Last field containing point.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
853 (make-variable-buffer-local 'widget-field-last)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
854
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
855 (defvar widget-field-was nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
856 ;; The widget data before the change.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
857 (make-variable-buffer-local 'widget-field-was)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
858
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
859 (defun widget-field-find (pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
860 ;; Find widget whose editing field is located at POS.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
861 ;; Return nil if POS is not inside and editing field.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
862 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
863 ;; This is only used in `widget-field-modified', since ordinarily
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
864 ;; you would just test the field property.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
865 (let ((fields widget-field-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
866 field found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
867 (while fields
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
868 (setq field (car fields)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
869 fields (cdr fields))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
870 (let ((from (widget-get field :value-from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
871 (to (widget-get field :value-to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
872 (if (and from to (< from pos) (> to pos))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
873 (setq fields nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
874 found field))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
875 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
876
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
877 (defun widget-after-change (from to old)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
878 ;; Adjust field size and text properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
879 (condition-case nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
880 (let ((field (widget-field-find from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
881 (inhibit-read-only t))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
882 (cond ((null field))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
883 ((not (eq field (widget-field-find to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
884 (debug)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
885 (message "Error: `widget-after-change' called on two fields"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
886 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
887 (let ((size (widget-get field :size)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
888 (if size
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
889 (let ((begin (1+ (widget-get field :value-from)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
890 (end (1- (widget-get field :value-to))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
891 (widget-specify-field-update field begin end)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
892 (cond ((< (- end begin) size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
893 ;; Field too small.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
894 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
895 (goto-char end)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
896 (insert-char ?\ (- (+ begin size) end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
897 (widget-specify-field-update field
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
898 begin
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
899 (+ begin size))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
900 ((> (- end begin) size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
901 ;; Field too large and
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
902 (if (or (< (point) (+ begin size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
903 (> (point) end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
904 ;; Point is outside extra space.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
905 (setq begin (+ begin size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
906 ;; Point is within the extra space.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
907 (setq begin (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
908 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
909 (goto-char end)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
910 (while (and (eq (preceding-char) ?\ )
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
911 (> (point) begin))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
912 (delete-backward-char 1))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
913 (widget-specify-field-update field from to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
914 (widget-apply field :notify field))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
915 (error (debug))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
916
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
917 ;;; Widget Functions
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
918 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
919 ;; These functions are used in the definition of multiple widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
920
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
921 (defun widget-children-value-delete (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
922 "Delete all :children and :buttons in WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
923 (mapcar 'widget-delete (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
924 (widget-put widget :children nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
925 (mapcar 'widget-delete (widget-get widget :buttons))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
926 (widget-put widget :buttons nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
927
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
928 (defun widget-types-convert-widget (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
929 "Convert :args as widget types in WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
930 (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
931 widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
932
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
933 ;;; The `default' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
934
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
935 (define-widget 'default nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
936 "Basic widget other widgets are derived from."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
937 :value-to-internal (lambda (widget value) value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
938 :value-to-external (lambda (widget value) value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
939 :create 'widget-default-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
940 :indent nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
941 :offset 0
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
942 :format-handler 'widget-default-format-handler
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
943 :button-face-get 'widget-default-button-face-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
944 :sample-face-get 'widget-default-sample-face-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
945 :delete 'widget-default-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
946 :value-set 'widget-default-value-set
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
947 :value-inline 'widget-default-value-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
948 :menu-tag-get 'widget-default-menu-tag-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
949 :validate (lambda (widget) nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
950 :action 'widget-default-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
951 :notify 'widget-default-notify)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
952
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
953 (defun widget-default-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
954 "Create WIDGET at point in the current buffer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
955 (widget-specify-insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
956 (let ((from (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
957 (tag (widget-get widget :tag))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
958 (glyph (widget-get widget :tag-glyph))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
959 (doc (widget-get widget :doc))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
960 button-begin button-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
961 sample-begin sample-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
962 doc-begin doc-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
963 value-pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
964 (insert (widget-get widget :format))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
965 (goto-char from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
966 ;; Parse escapes in format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
967 (while (re-search-forward "%\\(.\\)" nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
968 (let ((escape (aref (match-string 1) 0)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
969 (replace-match "" t t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
970 (cond ((eq escape ?%)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
971 (insert "%"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
972 ((eq escape ?\[)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
973 (setq button-begin (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
974 ((eq escape ?\])
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
975 (setq button-end (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
976 ((eq escape ?\{)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
977 (setq sample-begin (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
978 ((eq escape ?\})
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
979 (setq sample-end (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
980 ((eq escape ?n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
981 (when (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
982 (insert "\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
983 (insert-char ? (widget-get widget :indent))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
984 ((eq escape ?t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
985 (cond (glyph
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
986 (widget-glyph-insert widget (or tag "image") glyph))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
987 (tag
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
988 (insert tag))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
989 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
990 (let ((standard-output (current-buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
991 (princ (widget-get widget :value))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
992 ((eq escape ?d)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
993 (when doc
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
994 (setq doc-begin (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
995 (insert doc)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
996 (while (eq (preceding-char) ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
997 (delete-backward-char 1))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
998 (insert "\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
999 (setq doc-end (point))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1000 ((eq escape ?v)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1001 (if (and button-begin (not button-end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1002 (widget-apply widget :value-create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1003 (setq value-pos (point))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1004 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1005 (widget-apply widget :format-handler escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1006 ;; Specify button, sample, and doc, and insert value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1007 (and button-begin button-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1008 (widget-specify-button widget button-begin button-end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1009 (and sample-begin sample-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1010 (widget-specify-sample widget sample-begin sample-end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1011 (and doc-begin doc-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1012 (widget-specify-doc widget doc-begin doc-end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1013 (when value-pos
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1014 (goto-char value-pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1015 (widget-apply widget :value-create)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1016 (let ((from (copy-marker (point-min)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1017 (to (copy-marker (point-max))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1018 (widget-specify-text from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1019 (set-marker-insertion-type from t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1020 (set-marker-insertion-type to nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1021 (widget-put widget :from from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1022 (widget-put widget :to to))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1023
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1024 (defun widget-default-format-handler (widget escape)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1025 ;; We recognize the %h escape by default.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1026 (let* ((buttons (widget-get widget :buttons))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1027 (doc-property (widget-get widget :documentation-property))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1028 (doc-try (cond ((widget-get widget :doc))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1029 ((symbolp doc-property)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1030 (documentation-property (widget-get widget :value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1031 doc-property))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1032 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1033 (funcall doc-property (widget-get widget :value)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1034 (doc-text (and (stringp doc-try)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1035 (> (length doc-try) 1)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1036 doc-try)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1037 (cond ((eq escape ?h)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1038 (when doc-text
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1039 (and (eq (preceding-char) ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1040 (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1041 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1042 ;; The `*' in the beginning is redundant.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1043 (when (eq (aref doc-text 0) ?*)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1044 (setq doc-text (substring doc-text 1)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1045 ;; Get rid of trailing newlines.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1046 (when (string-match "\n+\\'" doc-text)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1047 (setq doc-text (substring doc-text 0 (match-beginning 0))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1048 (push (if (string-match "\n." doc-text)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1049 ;; Allow multiline doc to be hiden.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1050 (widget-create-child-and-convert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1051 widget 'widget-help
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1052 :doc (progn
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1053 (string-match "\\`.*" doc-text)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1054 (match-string 0 doc-text))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1055 :widget-doc doc-text
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1056 "?")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1057 ;; A single line is just inserted.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1058 (widget-create-child-and-convert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1059 widget 'item :format "%d" :doc doc-text nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1060 buttons)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1061 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1062 (error "Unknown escape `%c'" escape)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1063 (widget-put widget :buttons buttons)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1064
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1065 (defun widget-default-button-face-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1066 ;; Use :button-face or widget-button-face
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1067 (or (widget-get widget :button-face) 'widget-button-face))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1068
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1069 (defun widget-default-sample-face-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1070 ;; Use :sample-face.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1071 (widget-get widget :sample-face))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1072
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1073 (defun widget-default-delete (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1074 ;; Remove widget from the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1075 (let ((from (widget-get widget :from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1076 (to (widget-get widget :to))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1077 (inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1078 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1079 (widget-apply widget :value-delete)
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
1080 (when (< from to)
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
1081 ;; Kludge: this doesn't need to be true for empty formats.
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
1082 (delete-region from to))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1083 (set-marker from nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1084 (set-marker to nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1085
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1086 (defun widget-default-value-set (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1087 ;; Recreate widget with new value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1088 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1089 (goto-char (widget-get widget :from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1090 (widget-apply widget :delete)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1091 (widget-put widget :value value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1092 (widget-apply widget :create)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1093
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1094 (defun widget-default-value-inline (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1095 ;; Wrap value in a list unless it is inline.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1096 (if (widget-get widget :inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1097 (widget-value widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1098 (list (widget-value widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1099
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1100 (defun widget-default-menu-tag-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1101 ;; Use tag or value for menus.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1102 (or (widget-get widget :menu-tag)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1103 (widget-get widget :tag)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1104 (widget-princ-to-string (widget-get widget :value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1105
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1106 (defun widget-default-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1107 ;; Notify the parent when a widget change
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1108 (let ((parent (widget-get widget :parent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1109 (when parent
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1110 (widget-apply parent :notify widget event))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1111
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1112 (defun widget-default-notify (widget child &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1113 ;; Pass notification to parent.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1114 (widget-default-action widget event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1115
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1116 ;;; The `item' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1117
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1118 (define-widget 'item 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1119 "Constant items for inclusion in other widgets."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1120 :convert-widget 'widget-item-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1121 :value-create 'widget-item-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1122 :value-delete 'ignore
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1123 :value-get 'widget-item-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1124 :match 'widget-item-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1125 :match-inline 'widget-item-match-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1126 :action 'widget-item-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1127 :format "%t\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1128
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1129 (defun widget-item-convert-widget (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1130 ;; Initialize :value from :args in WIDGET.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1131 (let ((args (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1132 (when args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1133 (widget-put widget :value (widget-apply widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1134 :value-to-internal (car args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1135 (widget-put widget :args nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1136 widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1137
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1138 (defun widget-item-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1139 ;; Insert the printed representation of the value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1140 (let ((standard-output (current-buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1141 (princ (widget-get widget :value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1142
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1143 (defun widget-item-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1144 ;; Match if the value is the same.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1145 (equal (widget-get widget :value) value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1146
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1147 (defun widget-item-match-inline (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1148 ;; Match if the value is the same.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1149 (let ((value (widget-get widget :value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1150 (and (listp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1151 (<= (length value) (length values))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1152 (let ((head (subseq values 0 (length value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1153 (and (equal head value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1154 (cons head (subseq values (length value))))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1155
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1156 (defun widget-item-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1157 ;; Just notify itself.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1158 (widget-apply widget :notify widget event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1159
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1160 (defun widget-item-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1161 ;; Items are simple.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1162 (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1163
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1164 ;;; The `push-button' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1165
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1166 (defcustom widget-push-button-gui t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1167 "If non nil, use GUI push buttons when available."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1168 :group 'widgets
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1169 :type 'boolean)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1170
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1171 ;; Cache already created GUI objects.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1172 (defvar widget-push-button-cache nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1173
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1174 (define-widget 'push-button 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1175 "A pushable button."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1176 :value-create 'widget-push-button-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1177 :format "%[%v%]")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1178
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1179 (defun widget-push-button-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1180 ;; Insert text representing the `on' and `off' states.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1181 (let* ((tag (or (widget-get widget :tag)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1182 (widget-get widget :value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1183 (text (concat "[" tag "]"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1184 (gui (cdr (assoc tag widget-push-button-cache))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1185 (if (and (fboundp 'make-gui-button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1186 (fboundp 'make-glyph)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1187 widget-push-button-gui
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1188 (fboundp 'device-on-window-system-p)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1189 (device-on-window-system-p)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1190 (string-match "XEmacs" emacs-version))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1191 (progn
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1192 (unless gui
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1193 (setq gui (make-gui-button tag 'widget-gui-action widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1194 (push (cons tag gui) widget-push-button-cache))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1195 (widget-glyph-insert-glyph widget text
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1196 (make-glyph (car (aref gui 1)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1197 (insert text))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1198
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1199 (defun widget-gui-action (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1200 "Apply :action for WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1201 (widget-apply widget :action (this-command-keys)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1202
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1203 ;;; The `link' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1204
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1205 (define-widget 'link 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1206 "An embedded link."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1207 :help-echo "Follow the link."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1208 :format "%[_%t_%]")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1209
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1210 ;;; The `info-link' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1211
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1212 (define-widget 'info-link 'link
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1213 "A link to an info file."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1214 :action 'widget-info-link-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1215
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1216 (defun widget-info-link-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1217 "Open the info node specified by WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1218 (Info-goto-node (widget-value widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1219
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1220 ;;; The `url-link' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1221
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1222 (define-widget 'url-link 'link
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1223 "A link to an www page."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1224 :action 'widget-url-link-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1225
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1226 (defun widget-url-link-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1227 "Open the url specified by WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1228 (require 'browse-url)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1229 (funcall browse-url-browser-function (widget-value widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1230
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1231 ;;; The `editable-field' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1232
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1233 (define-widget 'editable-field 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1234 "An editable text field."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1235 :convert-widget 'widget-item-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1236 :keymap widget-field-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1237 :format "%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1238 :value ""
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1239 :action 'widget-field-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1240 :validate 'widget-field-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1241 :valid-regexp ""
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1242 :error "No match"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1243 :value-create 'widget-field-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1244 :value-delete 'widget-field-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1245 :value-get 'widget-field-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1246 :match 'widget-field-match)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1247
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1248 ;; History of field minibuffer edits.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1249 (defvar widget-field-history nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1250
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1251 (defun widget-field-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1252 ;; Edit the value in the minibuffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1253 (let ((tag (widget-apply widget :menu-tag-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1254 (invalid (widget-apply widget :validate)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1255 (when invalid
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1256 (error (widget-get invalid :error)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1257 (widget-value-set widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1258 (widget-apply widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1259 :value-to-external
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1260 (read-string (concat tag ": ")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1261 (widget-apply
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1262 widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1263 :value-to-internal
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1264 (widget-value widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1265 'widget-field-history)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1266 (widget-apply widget :notify widget event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1267 (widget-setup)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1268
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1269 (defun widget-field-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1270 ;; Valid if the content matches `:valid-regexp'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1271 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1272 (let ((value (widget-apply widget :value-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1273 (regexp (widget-get widget :valid-regexp)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1274 (if (string-match regexp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1275 nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1276 widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1277
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1278 (defun widget-field-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1279 ;; Create an editable text field.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1280 (insert " ")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1281 (let ((size (widget-get widget :size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1282 (value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1283 (from (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1284 (insert value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1285 (and size
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1286 (< (length value) size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1287 (insert-char ?\ (- size (length value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1288 (unless (memq widget widget-field-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1289 (setq widget-field-new (cons widget widget-field-new)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1290 (widget-put widget :value-to (copy-marker (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1291 (set-marker-insertion-type (widget-get widget :value-to) nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1292 (if (null size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1293 (insert ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1294 (insert ?\ ))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1295 (widget-put widget :value-from (copy-marker from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1296 (set-marker-insertion-type (widget-get widget :value-from) t)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1297
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1298 (defun widget-field-value-delete (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1299 ;; Remove the widget from the list of active editing fields.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1300 (setq widget-field-list (delq widget widget-field-list))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1301 ;; These are nil if the :format string doesn't contain `%v'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1302 (when (widget-get widget :value-from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1303 (set-marker (widget-get widget :value-from) nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1304 (when (widget-get widget :value-from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1305 (set-marker (widget-get widget :value-to) nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1306
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1307 (defun widget-field-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1308 ;; Return current text in editing field.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1309 (let ((from (widget-get widget :value-from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1310 (to (widget-get widget :value-to))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1311 (size (widget-get widget :size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1312 (secret (widget-get widget :secret))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1313 (old (current-buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1314 (if (and from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1315 (progn
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1316 (set-buffer (marker-buffer from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1317 (setq from (1+ from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1318 to (1- to))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1319 (while (and size
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1320 (not (zerop size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1321 (> to from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1322 (eq (char-after (1- to)) ?\ ))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1323 (setq to (1- to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1324 (let ((result (buffer-substring-no-properties from to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1325 (when secret
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1326 (let ((index 0))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1327 (while (< (+ from index) to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1328 (aset result index
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1329 (get-text-property (+ from index) 'secret))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1330 (setq index (1+ index)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1331 (set-buffer old)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1332 result))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1333 (widget-get widget :value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1334
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1335 (defun widget-field-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1336 ;; Match any string.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1337 (stringp value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1338
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1339 ;;; The `text' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1340
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1341 (define-widget 'text 'editable-field
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1342 :keymap widget-text-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1343 "A multiline text area.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1344
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1345 ;;; The `menu-choice' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1346
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1347 (define-widget 'menu-choice 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1348 "A menu of options."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1349 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1350 :format "%[%t%]: %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1351 :case-fold t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1352 :tag "choice"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1353 :void '(item :format "invalid (%t)\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1354 :value-create 'widget-choice-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1355 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1356 :value-get 'widget-choice-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1357 :value-inline 'widget-choice-value-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1358 :action 'widget-choice-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1359 :error "Make a choice"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1360 :validate 'widget-choice-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1361 :match 'widget-choice-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1362 :match-inline 'widget-choice-match-inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1363
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1364 (defun widget-choice-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1365 ;; Insert the first choice that matches the value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1366 (let ((value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1367 (args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1368 current)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1369 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1370 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1371 args (cdr args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1372 (when (widget-apply current :match value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1373 (widget-put widget :children (list (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1374 widget current value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1375 (widget-put widget :choice current)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1376 (setq args nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1377 current nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1378 (when current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1379 (let ((void (widget-get widget :void)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1380 (widget-put widget :children (list (widget-create-child-and-convert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1381 widget void :value value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1382 (widget-put widget :choice void)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1383
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1384 (defun widget-choice-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1385 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1386 (widget-value (car (widget-get widget :children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1387
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1388 (defun widget-choice-value-inline (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1389 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1390 (widget-apply (car (widget-get widget :children)) :value-inline))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1391
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1392 (defun widget-choice-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1393 ;; Make a choice.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1394 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1395 (old (widget-get widget :choice))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1396 (tag (widget-apply widget :menu-tag-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1397 (completion-ignore-case (widget-get widget :case-fold))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1398 current choices)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1399 ;; Remember old value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1400 (if (and old (not (widget-apply widget :validate)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1401 (let* ((external (widget-value widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1402 (internal (widget-apply old :value-to-internal external)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1403 (widget-put old :value internal)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1404 ;; Find new choice.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1405 (setq current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1406 (cond ((= (length args) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1407 nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1408 ((= (length args) 1)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1409 (nth 0 args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1410 ((and (= (length args) 2)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1411 (memq old args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1412 (if (eq old (nth 0 args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1413 (nth 1 args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1414 (nth 0 args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1415 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1416 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1417 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1418 args (cdr args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1419 (setq choices
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1420 (cons (cons (widget-apply current :menu-tag-get)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1421 current)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1422 choices)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1423 (widget-choose tag (reverse choices) event))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1424 (when current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1425 (widget-value-set widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1426 (widget-apply current :value-to-external
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1427 (widget-get current :value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1428 (widget-apply widget :notify widget event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1429 (widget-setup)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1430 ;; Notify parent.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1431 (widget-apply widget :notify widget event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1432 (widget-clear-undo))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1433
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1434 (defun widget-choice-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1435 ;; Valid if we have made a valid choice.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1436 (let ((void (widget-get widget :void))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1437 (choice (widget-get widget :choice))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1438 (child (car (widget-get widget :children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1439 (if (eq void choice)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1440 widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1441 (widget-apply child :validate))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1442
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1443 (defun widget-choice-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1444 ;; Matches if one of the choices matches.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1445 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1446 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1447 (while (and args (not found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1448 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1449 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1450 found (widget-apply current :match value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1451 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1452
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1453 (defun widget-choice-match-inline (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1454 ;; Matches if one of the choices matches.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1455 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1456 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1457 (while (and args (null found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1458 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1459 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1460 found (widget-match-inline current values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1461 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1462
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1463 ;;; The `toggle' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1464
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1465 (define-widget 'toggle 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1466 "Toggle between two states."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1467 :format "%[%v%]\n"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1468 :value-create 'widget-toggle-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1469 :action 'widget-toggle-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1470 :match (lambda (widget value) t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1471 :on "on"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1472 :off "off")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1473
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1474 (defun widget-toggle-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1475 ;; Insert text representing the `on' and `off' states.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1476 (if (widget-value widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1477 (widget-glyph-insert widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1478 (widget-get widget :on)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1479 (widget-get widget :on-glyph))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1480 (widget-glyph-insert widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1481 (widget-get widget :off)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1482 (widget-get widget :off-glyph))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1483
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1484 (defun widget-toggle-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1485 ;; Toggle value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1486 (widget-value-set widget (not (widget-value widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1487 (widget-apply widget :notify widget event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1488
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1489 ;;; The `checkbox' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1490
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1491 (define-widget 'checkbox 'toggle
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1492 "A checkbox toggle."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1493 :format "%[%v%]"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1494 :on "[X]"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1495 :on-glyph "check1"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1496 :off "[ ]"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1497 :off-glyph "check0")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1498
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1499 ;;; The `checklist' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1500
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1501 (define-widget 'checklist 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1502 "A multiple choice widget."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1503 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1504 :format "%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1505 :offset 4
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1506 :entry-format "%b %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1507 :menu-tag "checklist"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1508 :greedy nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1509 :value-create 'widget-checklist-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1510 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1511 :value-get 'widget-checklist-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1512 :validate 'widget-checklist-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1513 :match 'widget-checklist-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1514 :match-inline 'widget-checklist-match-inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1515
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1516 (defun widget-checklist-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1517 ;; Insert all values
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1518 (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1519 (args (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1520 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1521 (widget-checklist-add-item widget (car args) (assq (car args) alist))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1522 (setq args (cdr args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1523 (widget-put widget :children (nreverse (widget-get widget :children)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1524
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1525 (defun widget-checklist-add-item (widget type chosen)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1526 ;; Create checklist item in WIDGET of type TYPE.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1527 ;; If the item is checked, CHOSEN is a cons whose cdr is the value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1528 (and (eq (preceding-char) ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1529 (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1530 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1531 (widget-specify-insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1532 (let* ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1533 (buttons (widget-get widget :buttons))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1534 (button-args (or (widget-get type :sibling-args)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1535 (widget-get widget :button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1536 (from (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1537 child button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1538 (insert (widget-get widget :entry-format))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1539 (goto-char from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1540 ;; Parse % escapes in format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1541 (while (re-search-forward "%\\([bv%]\\)" nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1542 (let ((escape (aref (match-string 1) 0)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1543 (replace-match "" t t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1544 (cond ((eq escape ?%)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1545 (insert "%"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1546 ((eq escape ?b)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1547 (setq button (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1548 widget 'checkbox
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1549 :value (not (null chosen))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1550 button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1551 ((eq escape ?v)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1552 (setq child
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1553 (cond ((not chosen)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1554 (widget-create-child widget type))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1555 ((widget-get type :inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1556 (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1557 widget type (cdr chosen)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1558 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1559 (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1560 widget type (car (cdr chosen)))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1561 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1562 (error "Unknown escape `%c'" escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1563 ;; Update properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1564 (and button child (widget-put child :button button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1565 (and button (widget-put widget :buttons (cons button buttons)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1566 (and child (widget-put widget :children (cons child children))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1567
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1568 (defun widget-checklist-match (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1569 ;; All values must match a type in the checklist.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1570 (and (listp values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1571 (null (cdr (widget-checklist-match-inline widget values)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1572
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1573 (defun widget-checklist-match-inline (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1574 ;; Find the values which match a type in the checklist.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1575 (let ((greedy (widget-get widget :greedy))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1576 (args (copy-list (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1577 found rest)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1578 (while values
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1579 (let ((answer (widget-checklist-match-up args values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1580 (cond (answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1581 (let ((vals (widget-match-inline answer values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1582 (setq found (append found (car vals))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1583 values (cdr vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1584 args (delq answer args))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1585 (greedy
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1586 (setq rest (append rest (list (car values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1587 values (cdr values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1588 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1589 (setq rest (append rest values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1590 values nil)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1591 (cons found rest)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1592
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1593 (defun widget-checklist-match-find (widget vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1594 ;; Find the vals which match a type in the checklist.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1595 ;; Return an alist of (TYPE MATCH).
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1596 (let ((greedy (widget-get widget :greedy))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1597 (args (copy-list (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1598 found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1599 (while vals
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1600 (let ((answer (widget-checklist-match-up args vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1601 (cond (answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1602 (let ((match (widget-match-inline answer vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1603 (setq found (cons (cons answer (car match)) found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1604 vals (cdr match)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1605 args (delq answer args))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1606 (greedy
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1607 (setq vals (cdr vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1608 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1609 (setq vals nil)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1610 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1611
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1612 (defun widget-checklist-match-up (args vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1613 ;; Rerturn the first type from ARGS that matches VALS.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1614 (let (current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1615 (while (and args (null found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1616 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1617 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1618 found (widget-match-inline current vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1619 (if found
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1620 current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1621 nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1622
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1623 (defun widget-checklist-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1624 ;; The values of all selected items.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1625 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1626 child result)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1627 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1628 (setq child (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1629 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1630 (if (widget-value (widget-get child :button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1631 (setq result (append result (widget-apply child :value-inline)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1632 result))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1633
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1634 (defun widget-checklist-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1635 ;; Ticked chilren must be valid.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1636 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1637 child button found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1638 (while (and children (not found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1639 (setq child (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1640 children (cdr children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1641 button (widget-get child :button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1642 found (and (widget-value button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1643 (widget-apply child :validate))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1644 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1645
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1646 ;;; The `option' Widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1647
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1648 (define-widget 'option 'checklist
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1649 "An widget with an optional item."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1650 :inline t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1651
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1652 ;;; The `choice-item' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1653
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1654 (define-widget 'choice-item 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1655 "Button items that delegate action events to their parents."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1656 :action 'widget-choice-item-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1657 :format "%[%t%] \n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1658
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1659 (defun widget-choice-item-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1660 ;; Tell parent what happened.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1661 (widget-apply (widget-get widget :parent) :action event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1662
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1663 ;;; The `radio-button' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1664
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1665 (define-widget 'radio-button 'toggle
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1666 "A radio button for use in the `radio' widget."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1667 :notify 'widget-radio-button-notify
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1668 :format "%[%v%]"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1669 :on "(*)"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1670 :on-glyph "radio1"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1671 :off "( )"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1672 :off-glyph "radio0")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1673
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1674 (defun widget-radio-button-notify (widget child &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1675 ;; Tell daddy.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1676 (widget-apply (widget-get widget :parent) :action widget event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1677
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1678 ;;; The `radio-button-choice' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1679
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1680 (define-widget 'radio-button-choice 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1681 "Select one of multiple options."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1682 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1683 :offset 4
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1684 :format "%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1685 :entry-format "%b %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1686 :menu-tag "radio"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1687 :value-create 'widget-radio-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1688 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1689 :value-get 'widget-radio-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1690 :value-inline 'widget-radio-value-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1691 :value-set 'widget-radio-value-set
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1692 :error "You must push one of the buttons"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1693 :validate 'widget-radio-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1694 :match 'widget-choice-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1695 :match-inline 'widget-choice-match-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1696 :action 'widget-radio-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1697
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1698 (defun widget-radio-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1699 ;; Insert all values
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1700 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1701 arg)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1702 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1703 (setq arg (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1704 args (cdr args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1705 (widget-radio-add-item widget arg))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1706
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1707 (defun widget-radio-add-item (widget type)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1708 "Add to radio widget WIDGET a new radio button item of type TYPE."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1709 ;; (setq type (widget-convert type))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1710 (and (eq (preceding-char) ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1711 (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1712 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1713 (widget-specify-insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1714 (let* ((value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1715 (children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1716 (buttons (widget-get widget :buttons))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1717 (button-args (or (widget-get type :sibling-args)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1718 (widget-get widget :button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1719 (from (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1720 (chosen (and (null (widget-get widget :choice))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1721 (widget-apply type :match value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1722 child button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1723 (insert (widget-get widget :entry-format))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1724 (goto-char from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1725 ;; Parse % escapes in format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1726 (while (re-search-forward "%\\([bv%]\\)" nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1727 (let ((escape (aref (match-string 1) 0)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1728 (replace-match "" t t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1729 (cond ((eq escape ?%)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1730 (insert "%"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1731 ((eq escape ?b)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1732 (setq button (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1733 widget 'radio-button
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1734 :value (not (null chosen))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1735 button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1736 ((eq escape ?v)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1737 (setq child (if chosen
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1738 (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1739 widget type value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1740 (widget-create-child widget type))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1741 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1742 (error "Unknown escape `%c'" escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1743 ;; Update properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1744 (when chosen
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1745 (widget-put widget :choice type))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1746 (when button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1747 (widget-put child :button button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1748 (widget-put widget :buttons (nconc buttons (list button))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1749 (when child
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1750 (widget-put widget :children (nconc children (list child))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1751 child)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1752
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1753 (defun widget-radio-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1754 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1755 (let ((chosen (widget-radio-chosen widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1756 (and chosen (widget-value chosen))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1757
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1758 (defun widget-radio-chosen (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1759 "Return the widget representing the chosen radio button."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1760 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1761 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1762 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1763 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1764 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1765 (let* ((button (widget-get current :button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1766 (value (widget-apply button :value-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1767 (when value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1768 (setq found current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1769 children nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1770 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1771
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1772 (defun widget-radio-value-inline (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1773 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1774 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1775 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1776 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1777 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1778 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1779 (let* ((button (widget-get current :button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1780 (value (widget-apply button :value-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1781 (when value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1782 (setq found (widget-apply current :value-inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1783 children nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1784 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1785
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1786 (defun widget-radio-value-set (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1787 ;; We can't just delete and recreate a radio widget, since children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1788 ;; can be added after the original creation and won't be recreated
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1789 ;; by `:create'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1790 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1791 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1792 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1793 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1794 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1795 (let* ((button (widget-get current :button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1796 (match (and (not found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1797 (widget-apply current :match value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1798 (widget-value-set button match)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1799 (if match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1800 (widget-value-set current value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1801 (setq found (or found match))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1802
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1803 (defun widget-radio-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1804 ;; Valid if we have made a valid choice.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1805 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1806 current found button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1807 (while (and children (not found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1808 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1809 children (cdr children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1810 button (widget-get current :button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1811 found (widget-apply button :value-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1812 (if found
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1813 (widget-apply current :validate)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1814 widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1815
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1816 (defun widget-radio-action (widget child event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1817 ;; Check if a radio button was pressed.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1818 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1819 (buttons (widget-get widget :buttons))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1820 current)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1821 (when (memq child buttons)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1822 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1823 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1824 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1825 (let* ((button (widget-get current :button)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1826 (cond ((eq child button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1827 (widget-value-set button t))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1828 ((widget-value button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1829 (widget-value-set button nil)))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1830 ;; Pass notification to parent.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1831 (widget-apply widget :notify child event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1832
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1833 ;;; The `insert-button' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1834
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1835 (define-widget 'insert-button 'push-button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1836 "An insert button for the `editable-list' widget."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1837 :tag "INS"
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1838 :help-echo "Insert a new item into the list at this position."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1839 :action 'widget-insert-button-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1840
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1841 (defun widget-insert-button-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1842 ;; Ask the parent to insert a new item.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1843 (widget-apply (widget-get widget :parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1844 :insert-before (widget-get widget :widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1845
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1846 ;;; The `delete-button' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1847
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1848 (define-widget 'delete-button 'push-button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1849 "A delete button for the `editable-list' widget."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1850 :tag "DEL"
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1851 :help-echo "Delete this item from the list."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1852 :action 'widget-delete-button-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1853
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1854 (defun widget-delete-button-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1855 ;; Ask the parent to insert a new item.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1856 (widget-apply (widget-get widget :parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1857 :delete-at (widget-get widget :widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1858
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1859 ;;; The `editable-list' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1860
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1861 (defcustom widget-editable-list-gui nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1862 "If non nil, use GUI push-buttons in editable list when available."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1863 :type 'boolean
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1864 :group 'widgets)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1865
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1866 (define-widget 'editable-list 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1867 "A variable list of widgets of the same type."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1868 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1869 :offset 12
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1870 :format "%v%i\n"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1871 :format-handler 'widget-editable-list-format-handler
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1872 :entry-format "%i %d %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1873 :menu-tag "editable-list"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1874 :value-create 'widget-editable-list-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1875 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1876 :value-get 'widget-editable-list-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1877 :validate 'widget-editable-list-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1878 :match 'widget-editable-list-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1879 :match-inline 'widget-editable-list-match-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1880 :insert-before 'widget-editable-list-insert-before
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1881 :delete-at 'widget-editable-list-delete-at)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1882
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1883 (defun widget-editable-list-format-handler (widget escape)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1884 ;; We recognize the insert button.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1885 (let ((widget-push-button-gui widget-editable-list-gui))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1886 (cond ((eq escape ?i)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1887 (and (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1888 (insert-char ? (widget-get widget :indent)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1889 (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1890 widget 'insert-button
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1891 (widget-get widget :append-button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1892 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1893 (widget-default-format-handler widget escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1894
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1895 (defun widget-editable-list-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1896 ;; Insert all values
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1897 (let* ((value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1898 (type (nth 0 (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1899 (inlinep (widget-get type :inline))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1900 children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1901 (widget-put widget :value-pos (copy-marker (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1902 (set-marker-insertion-type (widget-get widget :value-pos) t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1903 (while value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1904 (let ((answer (widget-match-inline type value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1905 (if answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1906 (setq children (cons (widget-editable-list-entry-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1907 widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1908 (if inlinep
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1909 (car answer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1910 (car (car answer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1911 t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1912 children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1913 value (cdr answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1914 (setq value nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1915 (widget-put widget :children (nreverse children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1916
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1917 (defun widget-editable-list-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1918 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1919 (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1920 (widget-get widget :children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1921
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1922 (defun widget-editable-list-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1923 ;; All the chilren must be valid.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1924 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1925 child found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1926 (while (and children (not found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1927 (setq child (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1928 children (cdr children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1929 found (widget-apply child :validate)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1930 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1931
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1932 (defun widget-editable-list-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1933 ;; Value must be a list and all the members must match the type.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1934 (and (listp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1935 (null (cdr (widget-editable-list-match-inline widget value)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1936
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1937 (defun widget-editable-list-match-inline (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1938 (let ((type (nth 0 (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1939 (ok t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1940 found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1941 (while (and value ok)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1942 (let ((answer (widget-match-inline type value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1943 (if answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1944 (setq found (append found (car answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1945 value (cdr answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1946 (setq ok nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1947 (cons found value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1948
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1949 (defun widget-editable-list-insert-before (widget before)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1950 ;; Insert a new child in the list of children.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1951 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1952 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1953 (inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1954 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1955 (cond (before
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1956 (goto-char (widget-get before :entry-from)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1957 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1958 (goto-char (widget-get widget :value-pos))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1959 (let ((child (widget-editable-list-entry-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1960 widget nil nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1961 (when (< (widget-get child :entry-from) (widget-get widget :from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1962 (set-marker (widget-get widget :from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1963 (widget-get child :entry-from)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1964 (widget-specify-text (widget-get child :entry-from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1965 (widget-get child :entry-to))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1966 (if (eq (car children) before)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1967 (widget-put widget :children (cons child children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1968 (while (not (eq (car (cdr children)) before))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1969 (setq children (cdr children)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1970 (setcdr children (cons child (cdr children)))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1971 (widget-setup)
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
1972 widget (widget-apply widget :notify widget))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1973
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1974 (defun widget-editable-list-delete-at (widget child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1975 ;; Delete child from list of children.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1976 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1977 (let ((buttons (copy-list (widget-get widget :buttons)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1978 button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1979 (inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1980 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1981 (while buttons
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1982 (setq button (car buttons)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1983 buttons (cdr buttons))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1984 (when (eq (widget-get button :widget) child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1985 (widget-put widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1986 :buttons (delq button (widget-get widget :buttons)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1987 (widget-delete button))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1988 (let ((entry-from (widget-get child :entry-from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1989 (entry-to (widget-get child :entry-to))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1990 (inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1991 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1992 (widget-delete child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1993 (delete-region entry-from entry-to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1994 (set-marker entry-from nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1995 (set-marker entry-to nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1996 (widget-put widget :children (delq child (widget-get widget :children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1997 (widget-setup)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1998 (widget-apply widget :notify widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1999
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2000 (defun widget-editable-list-entry-create (widget value conv)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2001 ;; Create a new entry to the list.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2002 (let ((type (nth 0 (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2003 (widget-push-button-gui widget-editable-list-gui)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2004 child delete insert)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2005 (widget-specify-insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2006 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2007 (and (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2008 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2009 (insert (widget-get widget :entry-format)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2010 ;; Parse % escapes in format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2011 (while (re-search-forward "%\\(.\\)" nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2012 (let ((escape (aref (match-string 1) 0)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2013 (replace-match "" t t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2014 (cond ((eq escape ?%)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2015 (insert "%"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2016 ((eq escape ?i)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2017 (setq insert (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2018 widget 'insert-button
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2019 (widget-get widget :insert-button-args))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2020 ((eq escape ?d)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2021 (setq delete (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2022 widget 'delete-button
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2023 (widget-get widget :delete-button-args))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2024 ((eq escape ?v)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2025 (if conv
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2026 (setq child (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2027 widget type value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2028 (setq child (widget-create-child widget type))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2029 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2030 (error "Unknown escape `%c'" escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2031 (widget-put widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2032 :buttons (cons delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2033 (cons insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2034 (widget-get widget :buttons))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2035 (let ((entry-from (copy-marker (point-min)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2036 (entry-to (copy-marker (point-max))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2037 (widget-specify-text entry-from entry-to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2038 (set-marker-insertion-type entry-from t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2039 (set-marker-insertion-type entry-to nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2040 (widget-put child :entry-from entry-from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2041 (widget-put child :entry-to entry-to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2042 (widget-put insert :widget child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2043 (widget-put delete :widget child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2044 child))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2045
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2046 ;;; The `group' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2047
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2048 (define-widget 'group 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2049 "A widget which group other widgets inside."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2050 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2051 :format "%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2052 :value-create 'widget-group-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2053 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2054 :value-get 'widget-editable-list-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2055 :validate 'widget-editable-list-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2056 :match 'widget-group-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2057 :match-inline 'widget-group-match-inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2058
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2059 (defun widget-group-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2060 ;; Create each component.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2061 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2062 (value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2063 arg answer children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2064 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2065 (setq arg (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2066 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2067 answer (widget-match-inline arg value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2068 value (cdr answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2069 (and (eq (preceding-char) ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2070 (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2071 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2072 (push (cond ((null answer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2073 (widget-create-child widget arg))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2074 ((widget-get arg :inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2075 (widget-create-child-value widget arg (car answer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2076 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2077 (widget-create-child-value widget arg (car (car answer)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2078 children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2079 (widget-put widget :children (nreverse children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2080
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2081 (defun widget-group-match (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2082 ;; Match if the components match.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2083 (and (listp values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2084 (let ((match (widget-group-match-inline widget values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2085 (and match (null (cdr match))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2086
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2087 (defun widget-group-match-inline (widget vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2088 ;; Match if the components match.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2089 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2090 argument answer found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2091 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2092 (setq argument (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2093 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2094 answer (widget-match-inline argument vals))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2095 (if answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2096 (setq vals (cdr answer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2097 found (append found (car answer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2098 (setq vals nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2099 args nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2100 (if answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2101 (cons found vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2102 nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2103
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2104 ;;; The `widget-help' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2105
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2106 (define-widget 'widget-help 'push-button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2107 "The widget documentation button."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2108 :format "%[[%t]%] %d"
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2109 :help-echo "Toggle display of documentation."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2110 :action 'widget-help-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2111
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2112 (defun widget-help-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2113 "Toggle documentation for WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2114 (let ((old (widget-get widget :doc))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2115 (new (widget-get widget :widget-doc)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2116 (widget-put widget :doc new)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2117 (widget-put widget :widget-doc old))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2118 (widget-value-set widget (widget-value widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2119
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2120 ;;; The Sexp Widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2121
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2122 (define-widget 'const 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2123 "An immutable sexp."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2124 :format "%t\n%d")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2125
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2126 (define-widget 'function-item 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2127 "An immutable function name."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2128 :format "%v\n%h"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2129 :documentation-property (lambda (symbol)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2130 (condition-case nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2131 (documentation symbol t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2132 (error nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2133
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2134 (define-widget 'variable-item 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2135 "An immutable variable name."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2136 :format "%v\n%h"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2137 :documentation-property 'variable-documentation)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2138
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2139 (define-widget 'string 'editable-field
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2140 "A string"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2141 :tag "String"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2142 :format "%[%t%]: %v")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2143
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2144 (define-widget 'regexp 'string
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2145 "A regular expression."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2146 ;; Should do validation.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2147 :tag "Regexp")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2148
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2149 (define-widget 'file 'string
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2150 "A file widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2151 It will read a file name from the minibuffer when activated."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2152 :format "%[%t%]: %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2153 :tag "File"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2154 :action 'widget-file-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2155
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2156 (defun widget-file-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2157 ;; Read a file name from the minibuffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2158 (let* ((value (widget-value widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2159 (dir (file-name-directory value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2160 (file (file-name-nondirectory value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2161 (menu-tag (widget-apply widget :menu-tag-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2162 (must-match (widget-get widget :must-match))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 34
diff changeset
2163 (answer (read-file-name (concat menu-tag ": (default `" value "') ")
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2164 dir nil must-match file)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2165 (widget-value-set widget (abbreviate-file-name answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2166 (widget-apply widget :notify widget event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2167 (widget-setup)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2168
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2169 (define-widget 'directory 'file
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2170 "A directory widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2171 It will read a directory name from the minibuffer when activated."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2172 :tag "Directory")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2173
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2174 (define-widget 'symbol 'string
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2175 "A lisp symbol."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2176 :value nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2177 :tag "Symbol"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2178 :match (lambda (widget value) (symbolp value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2179 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2180 (if (symbolp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2181 (symbol-name value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2182 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2183 :value-to-external (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2184 (if (stringp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2185 (intern value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2186 value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2187
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2188 (define-widget 'function 'sexp
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2189 ;; Should complete on functions.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2190 "A lisp function."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2191 :tag "Function")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2192
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2193 (define-widget 'variable 'symbol
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2194 ;; Should complete on variables.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2195 "A lisp variable."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2196 :tag "Variable")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2197
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2198 (define-widget 'sexp 'string
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2199 "An arbitrary lisp expression."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2200 :tag "Lisp expression"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2201 :value nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2202 :validate 'widget-sexp-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2203 :match (lambda (widget value) t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2204 :value-to-internal 'widget-sexp-value-to-internal
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2205 :value-to-external (lambda (widget value) (read value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2206
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2207 (defun widget-sexp-value-to-internal (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2208 ;; Use pp for printer representation.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2209 (let ((pp (pp-to-string value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2210 (while (string-match "\n\\'" pp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2211 (setq pp (substring pp 0 -1)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2212 (if (or (string-match "\n\\'" pp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2213 (> (length pp) 40))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2214 (concat "\n" pp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2215 pp)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2216
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2217 (defun widget-sexp-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2218 ;; Valid if we can read the string and there is no junk left after it.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2219 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2220 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2221 (erase-buffer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2222 (insert (widget-apply widget :value-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2223 (goto-char (point-min))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2224 (condition-case data
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2225 (let ((value (read buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2226 (if (eobp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2227 (if (widget-apply widget :match value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2228 nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2229 (widget-put widget :error (widget-get widget :type-error))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2230 widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2231 (widget-put widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2232 :error (format "Junk at end of expression: %s"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2233 (buffer-substring (point)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2234 (point-max))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2235 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2236 (error (widget-put widget :error (error-message-string data))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2237 widget)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2238
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2239 (define-widget 'integer 'sexp
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2240 "An integer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2241 :tag "Integer"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2242 :value 0
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2243 :type-error "This field should contain an integer"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2244 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2245 (if (integerp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2246 (prin1-to-string value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2247 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2248 :match (lambda (widget value) (integerp value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2249
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2250 (define-widget 'character 'string
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2251 "An character."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2252 :tag "Character"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2253 :value 0
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2254 :size 1
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2255 :format "%{%t%}: %v\n"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2256 :type-error "This field should contain a character"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2257 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2258 (if (integerp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2259 (char-to-string value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2260 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2261 :value-to-external (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2262 (if (stringp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2263 (aref value 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2264 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2265 :match (lambda (widget value) (integerp value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2266
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2267 (define-widget 'number 'sexp
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2268 "A floating point number."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2269 :tag "Number"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2270 :value 0.0
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2271 :type-error "This field should contain a number"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2272 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2273 (if (numberp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2274 (prin1-to-string value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2275 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2276 :match (lambda (widget value) (numberp value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2277
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2278 (define-widget 'list 'group
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2279 "A lisp list."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2280 :tag "List"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2281 :format "%{%t%}:\n%v")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2282
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2283 (define-widget 'vector 'group
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2284 "A lisp vector."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2285 :tag "Vector"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2286 :format "%{%t%}:\n%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2287 :match 'widget-vector-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2288 :value-to-internal (lambda (widget value) (append value nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2289 :value-to-external (lambda (widget value) (apply 'vector value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2290
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2291 (defun widget-vector-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2292 (and (vectorp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2293 (widget-group-match widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2294 (widget-apply :value-to-internal widget value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2295
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2296 (define-widget 'cons 'group
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2297 "A cons-cell."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2298 :tag "Cons-cell"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2299 :format "%{%t%}:\n%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2300 :match 'widget-cons-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2301 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2302 (list (car value) (cdr value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2303 :value-to-external (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2304 (cons (nth 0 value) (nth 1 value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2305
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2306 (defun widget-cons-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2307 (and (consp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2308 (widget-group-match widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2309 (widget-apply widget :value-to-internal value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2310
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2311 (define-widget 'choice 'menu-choice
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2312 "A union of several sexp types."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2313 :tag "Choice"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2314 :format "%[%t%]: %v")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2315
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2316 (define-widget 'radio 'radio-button-choice
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2317 "A union of several sexp types."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2318 :tag "Choice"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2319 :format "%{%t%}:\n%v")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2320
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2321 (define-widget 'repeat 'editable-list
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2322 "A variable length homogeneous list."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2323 :tag "Repeat"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2324 :format "%{%t%}:\n%v%i\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2325
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2326 (define-widget 'set 'checklist
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2327 "A list of members from a fixed set."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2328 :tag "Set"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2329 :format "%{%t%}:\n%v")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2330
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2331 (define-widget 'boolean 'toggle
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2332 "To be nil or non-nil, that is the question."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2333 :tag "Boolean"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2334 :format "%{%t%}: %[%v%]\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2335
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2336 ;;; The `color' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2337
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2338 (define-widget 'color-item 'choice-item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2339 "A color name (with sample)."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2340 :format "%v (%{sample%})\n"
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
2341 :sample-face-get 'widget-color-item-button-face-get)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2342
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2343 (defun widget-color-item-button-face-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2344 ;; We create a face from the value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2345 (require 'facemenu)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2346 (condition-case nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2347 (facemenu-get-face (intern (concat "fg:" (widget-value widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2348 (error 'default)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2349
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2350 (define-widget 'color 'push-button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2351 "Choose a color name (with sample)."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2352 :format "%[%t%]: %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2353 :tag "Color"
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
2354 :value "black"
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2355 :value-create 'widget-color-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2356 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2357 :value-get 'widget-color-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2358 :value-set 'widget-color-value-set
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2359 :action 'widget-color-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2360 :match 'widget-field-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2361 :tag "Color")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2362
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2363 (defvar widget-color-choice-list nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2364 ;; Variable holding the possible colors.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2365
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2366 (defun widget-color-choice-list ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2367 (unless widget-color-choice-list
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2368 (setq widget-color-choice-list
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2369 (mapcar '(lambda (color) (list color))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2370 (x-defined-colors))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2371 widget-color-choice-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2372
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2373 (defun widget-color-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2374 (let ((child (widget-create-child-and-convert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2375 widget 'color-item (widget-get widget :value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2376 (widget-put widget :children (list child))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2377
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2378 (defun widget-color-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2379 ;; Pass command to first child.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2380 (widget-apply (car (widget-get widget :children)) :value-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2381
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2382 (defun widget-color-value-set (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2383 ;; Pass command to first child.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2384 (widget-apply (car (widget-get widget :children)) :value-set value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2385
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2386 (defvar widget-color-history nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2387 "History of entered colors")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2388
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2389 (defun widget-color-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2390 ;; Prompt for a color.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2391 (let* ((tag (widget-apply widget :menu-tag-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2392 (prompt (concat tag ": "))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2393 (answer (cond ((string-match "XEmacs" emacs-version)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2394 (read-color prompt))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2395 ((fboundp 'x-defined-colors)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2396 (completing-read (concat tag ": ")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2397 (widget-color-choice-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2398 nil nil nil 'widget-color-history))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2399 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2400 (read-string prompt (widget-value widget))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2401 (unless (zerop (length answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2402 (widget-value-set widget answer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2403 (widget-apply widget :notify widget event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2404 (widget-setup))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2405
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2406 ;;; The Help Echo
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2407
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2408 (defun widget-echo-help-mouse ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2409 "Display the help message for the widget under the mouse.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2410 Enable with (run-with-idle-timer 1 t 'widget-echo-help-mouse)"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2411 (let* ((pos (mouse-position))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2412 (frame (car pos))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2413 (x (car (cdr pos)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2414 (y (cdr (cdr pos)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2415 (win (window-at x y frame))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2416 (where (coordinates-in-window-p (cons x y) win)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2417 (when (consp where)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2418 (save-window-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2419 (progn ; save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2420 (select-window win)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2421 (let* ((result (compute-motion (window-start win)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2422 '(0 . 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2423 (window-end win)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2424 where
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2425 (window-width win)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2426 (cons (window-hscroll) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2427 win)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2428 (when (and (eq (nth 1 result) x)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2429 (eq (nth 2 result) y))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2430 (widget-echo-help (nth 0 result))))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2431 (unless track-mouse
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2432 (setq track-mouse t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2433 (add-hook 'post-command-hook 'widget-stop-mouse-tracking)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2434
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2435 (defun widget-stop-mouse-tracking (&rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2436 "Stop the mouse tracking done while idle."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2437 (remove-hook 'post-command-hook 'widget-stop-mouse-tracking)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2438 (setq track-mouse nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2439
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2440 (defun widget-at (pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2441 "The button or field at POS."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2442 (or (get-text-property pos 'button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2443 (get-text-property pos 'field)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2444
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2445 (defun widget-echo-help (pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2446 "Display the help echo for widget at POS."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2447 (let* ((widget (widget-at pos))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2448 (help-echo (and widget (widget-get widget :help-echo))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2449 (cond ((stringp help-echo)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2450 (message "%s" help-echo))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2451 ((and (symbolp help-echo) (fboundp help-echo)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2452 (stringp (setq help-echo (funcall help-echo widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2453 (message "%s" help-echo)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2454
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2455 ;;; The End:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2456
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2457 (provide 'wid-edit)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2458
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2459 ;; wid-edit.el ends here