annotate lisp/w3/widget-edit.el @ 82:6a378aca36af r20-0b91

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