annotate lisp/custom/wid-edit.el @ 163:0132846995bd r20-3b8

Import from CVS: tag r20-3b8
author cvs
date Mon, 13 Aug 2007 09:43:35 +0200
parents 28f395d8dc7a
children 5a88923fcbfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1 ;;; wid-edit.el --- Functions for creating and using widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
4 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
6 ;; Keywords: extensions
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
7 ;; Version: 1.9931
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
9
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
10 ;; This file is part of GNU Emacs.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
11
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
15 ;; any later version.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
16
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
20 ;; GNU General Public License for more details.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
21
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
22 ;; You should have received a copy of the GNU General Public License
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
25 ;; Boston, MA 02111-1307, USA.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
26
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
27 ;;; Commentary:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
28 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
29 ;; See `widget.el'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
30
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
31 ;;; Code:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
32
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
33 (require 'widget)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
34 (eval-when-compile (require 'cl))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
35
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
36 ;;; Compatibility.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
37
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
38 (eval-and-compile
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
39 (autoload 'pp-to-string "pp")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
40 (autoload 'Info-goto-node "info")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
41
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
42 (when (string-match "XEmacs" emacs-version)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
43 (condition-case nil
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
44 (require 'overlay)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
45 (error (load-library "x-overlay"))))
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
46
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
47 (if (string-match "XEmacs" emacs-version)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
48 (defun widget-event-point (event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
49 "Character position of the end of event if that exists, or nil."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
50 (if (mouse-event-p event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
51 (event-point event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
52 nil))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
53 (defun widget-event-point (event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
54 "Character position of the end of event if that exists, or nil."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
55 (posn-point (event-end event))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
56
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
57 (defalias 'widget-read-event (if (string-match "XEmacs" emacs-version)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
58 'next-event
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
59 'read-event))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
60
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
61 ;; The following should go away when bundled with Emacs.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
62 (condition-case ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
63 (require 'custom)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
64 (error nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
65
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
66 (unless (and (featurep 'custom) (fboundp 'custom-declare-variable))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
67 ;; We have the old custom-library, hack around it!
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
68 (defmacro defgroup (&rest args) nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
69 (defmacro defcustom (var value doc &rest args)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
70 (` (defvar (, var) (, value) (, doc))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
71 (defmacro defface (&rest args) nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
72 (define-widget-keywords :prefix :tag :load :link :options :type :group)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
73 (when (fboundp 'copy-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
74 (copy-face 'default 'widget-documentation-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
75 (copy-face 'bold 'widget-button-face)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
76 (copy-face 'italic 'widget-field-face)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
77
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
78 (unless (fboundp 'button-release-event-p)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
79 ;; XEmacs function missing from Emacs.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
80 (defun button-release-event-p (event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
81 "Non-nil if EVENT is a mouse-button-release event object."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
82 (and (eventp event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
83 (memq (event-basic-type event) '(mouse-1 mouse-2 mouse-3))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
84 (or (memq 'click (event-modifiers event))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
85 (memq 'drag (event-modifiers event))))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
86
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
87 (unless (fboundp 'error-message-string)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
88 ;; Emacs function missing in XEmacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
89 (defun error-message-string (obj)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
90 "Convert an error value to an error message."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
91 (let ((buf (get-buffer-create " *error-message*")))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
92 (erase-buffer buf)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
93 (display-error obj buf)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
94 (buffer-string buf)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
95
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
96 (when (let ((a "foo"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
97 (put-text-property 1 2 'foo 1 a)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
98 (put-text-property 1 2 'bar 2 a)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
99 (set-text-properties 1 2 nil a)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
100 (text-properties-at 1 a))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
101 ;; XEmacs 20.2 and earlier had a buggy set-text-properties.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
102 (defun set-text-properties (start end props &optional buffer-or-string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
103 "Completely replace properties of text from START to END.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
104 The third argument PROPS is the new property list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
105 The optional fourth argument, BUFFER-OR-STRING,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
106 is the string or buffer containing the text."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
107 (map-extents #'(lambda (extent ignored)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
108 (remove-text-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
109 start end
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
110 (list (extent-property extent 'text-prop)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
111 nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
112 buffer-or-string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
113 nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
114 buffer-or-string start end nil nil 'text-prop)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
115 (add-text-properties start end props buffer-or-string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
116
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
117 ;;; Customization.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
118
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
119 (defgroup widgets nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
120 "Customization support for the Widget Library."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
121 :link '(custom-manual "(widget)Top")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
122 :link '(url-link :tag "Development Page"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
123 "http://www.dina.kvl.dk/~abraham/custom/")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
124 :prefix "widget-"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
125 :group 'extensions
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
126 :group 'hypermedia)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
127
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
128 (defgroup widget-documentation nil
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
129 "Options controling the display of documentation strings."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
130 :group 'widgets)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
131
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
132 (defgroup widget-faces nil
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
133 "Faces used by the widget library."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
134 :group 'widgets
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
135 :group 'faces)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
136
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
137 (defface widget-documentation-face '((((class color)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
138 (background dark))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
139 (:foreground "lime green"))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
140 (((class color)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
141 (background light))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
142 (:foreground "dark green"))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
143 (t nil))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
144 "Face used for documentation text."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
145 :group 'widget-documentation
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
146 :group 'widget-faces)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
147
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
148 (defface widget-button-face '((t (:bold t)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
149 "Face used for widget buttons."
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
150 :group 'widget-faces)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
151
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
152 (defcustom widget-mouse-face 'highlight
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
153 "Face used for widget buttons when the mouse is above them."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
154 :type 'face
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
155 :group 'widget-faces)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
156
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
157 (defface widget-field-face '((((class grayscale color)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
158 (background light))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
159 (:background "gray85"))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
160 (((class grayscale color)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
161 (background dark))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
162 (:background "dim gray"))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
163 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
164 (:italic t)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
165 "Face used for editable fields."
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
166 :group 'widget-faces)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
167
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
168 ;;; Utility functions.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
169 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
170 ;; These are not really widget specific.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
171
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
172 (defsubst widget-plist-member (plist prop)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
173 ;; Return non-nil if PLIST has the property PROP.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
174 ;; PLIST is a property list, which is a list of the form
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
175 ;; (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
176 ;; Unlike `plist-get', this allows you to distinguish between a missing
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
177 ;; property and a property with the value nil.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
178 ;; The value is actually the tail of PLIST whose car is PROP.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
179 (while (and plist (not (eq (car plist) prop)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
180 (setq plist (cdr (cdr plist))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
181 plist)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
182
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
183 (defun widget-princ-to-string (object)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
184 ;; Return string representation of OBJECT, any Lisp object.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
185 ;; No quoting characters are used; no delimiters are printed around
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
186 ;; the contents of strings.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
187 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
188 (set-buffer (get-buffer-create " *widget-tmp*"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
189 (erase-buffer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
190 (let ((standard-output (current-buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
191 (princ object))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
192 (buffer-string)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
193
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
194 (defun widget-clear-undo ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
195 "Clear all undo information."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
196 (buffer-disable-undo (current-buffer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
197 (buffer-enable-undo))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
198
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
199 (defcustom widget-menu-max-size 40
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
200 "Largest number of items allowed in a popup-menu.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
201 Larger menus are read through the minibuffer."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
202 :group 'widgets
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
203 :type 'integer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
204
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
205 (defun widget-choose (title items &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
206 "Choose an item from a list.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
207
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
208 First argument TITLE is the name of the list.
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
209 Second argument ITEMS is an list whose members are either
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
210 (NAME . VALUE), to indicate selectable items, or just strings to
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
211 indicate unselectable items.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
212 Optional third argument EVENT is an input event.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
213
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
214 The user is asked to choose between each NAME from the items alist,
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
215 and the VALUE of the chosen element will be returned. If EVENT is a
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
216 mouse event, and the number of elements in items is less than
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
217 `widget-menu-max-size', a popup menu will be used, otherwise the
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
218 minibuffer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
219 (cond ((and (< (length items) widget-menu-max-size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
220 event (fboundp 'x-popup-menu) window-system)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
221 ;; We are in Emacs-19, pressed by the mouse
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
222 (x-popup-menu event
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
223 (list title (cons "" items))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
224 ((and (< (length items) widget-menu-max-size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
225 event (fboundp 'popup-menu) window-system)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
226 ;; We are in XEmacs, pressed by the mouse
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
227 (let ((val (get-popup-menu-response
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
228 (cons title
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
229 (mapcar
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
230 (function
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
231 (lambda (x)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
232 (if (stringp x)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
233 (vector x nil nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
234 (vector (car x) (list (car x)) t))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
235 items)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
236 (setq val (and val
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
237 (listp (event-object val))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
238 (stringp (car-safe (event-object val)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
239 (car (event-object val))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
240 (cdr (assoc val items))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
241 (t
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
242 (setq items (widget-remove-if 'stringp items))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
243 (let ((val (completing-read (concat title ": ") items nil t)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
244 (if (stringp val)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
245 (let ((try (try-completion val items)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
246 (when (stringp try)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
247 (setq val try))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
248 (cdr (assoc val items)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
249 nil)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
250
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
251 (defun widget-remove-if (predictate list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
252 (let (result (tail list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
253 (while tail
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
254 (or (funcall predictate (car tail))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
255 (setq result (cons (car tail) result)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
256 (setq tail (cdr tail)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
257 (nreverse result)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
258
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
259 ;;; Widget text specifications.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
260 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
261 ;; These functions are for specifying text properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
262
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
263 (defun widget-specify-none (from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
264 ;; Clear all text properties between FROM and TO.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
265 (set-text-properties from to nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
266
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
267 (defun widget-specify-text (from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
268 ;; Default properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
269 (add-text-properties from to (list 'read-only t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
270 'front-sticky t
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
271 'rear-nonsticky nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
272 'start-open nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
273 'end-open nil)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
274
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
275 (defcustom widget-field-add-space
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
276 (or (< emacs-major-version 20)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
277 (and (eq emacs-major-version 20)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
278 (< emacs-minor-version 3))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
279 (not (string-match "XEmacs" emacs-version)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
280 "Non-nil means add extra space at the end of editable text fields.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
281
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
282 This is needed on all versions of Emacs, and on XEmacs before 20.3.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
283 If you don't add the space, it will become impossible to edit a zero
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
284 size field."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
285 :type 'boolean
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
286 :group 'widgets)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
287
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
288 (defun widget-specify-field (widget from to)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
289 "Specify editable button for WIDGET between FROM and TO."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
290 (put-text-property from to 'read-only nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
291 ;; Terminating space is not part of the field, but necessary in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
292 ;; order for local-map to work. Remove next sexp if local-map works
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
293 ;; at the end of the overlay.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
294 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
295 (goto-char to)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
296 (when widget-field-add-space
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
297 (insert-and-inherit " "))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
298 (setq to (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
299 (if widget-field-add-space
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
300 (add-text-properties (1- to) to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
301 '(front-sticky nil start-open t read-only to))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
302 (add-text-properties to (1+ to)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
303 '(front-sticky nil start-open t read-only to)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
304 (add-text-properties (1- from) from
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
305 '(rear-nonsticky t end-open t read-only from))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
306 (let ((map (widget-get widget :keymap))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
307 (face (or (widget-get widget :value-face) 'widget-field-face))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
308 (help-echo (widget-get widget :help-echo))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
309 (overlay (make-overlay from to nil nil t)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
310 (unless (or (stringp help-echo) (null help-echo))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
311 (setq help-echo 'widget-mouse-help))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
312 (widget-put widget :field-overlay overlay)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
313 (overlay-put overlay 'detachable nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
314 (overlay-put overlay 'field widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
315 (overlay-put overlay 'local-map map)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
316 (overlay-put overlay 'keymap map)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
317 (overlay-put overlay 'face face)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
318 (overlay-put overlay 'balloon-help help-echo)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
319 (overlay-put overlay 'help-echo help-echo)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
320
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
321 (defun widget-specify-button (widget from to)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
322 "Specify button for WIDGET between FROM and TO."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
323 (let ((face (widget-apply widget :button-face-get))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
324 (help-echo (widget-get widget :help-echo))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
325 (overlay (make-overlay from to nil t nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
326 (widget-put widget :button-overlay overlay)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
327 (unless (or (null help-echo) (stringp help-echo))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
328 (setq help-echo 'widget-mouse-help))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
329 (overlay-put overlay 'button widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
330 (overlay-put overlay 'mouse-face widget-mouse-face)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
331 (overlay-put overlay 'balloon-help help-echo)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
332 (overlay-put overlay 'help-echo help-echo)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
333 (overlay-put overlay 'face face)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
334
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
335 (defun widget-mouse-help (extent)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
336 "Find mouse help string for button in extent."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
337 (let* ((widget (widget-at (extent-start-position extent)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
338 (help-echo (and widget (widget-get widget :help-echo))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
339 (cond ((stringp help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
340 help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
341 ((and (symbolp help-echo) (fboundp help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
342 (stringp (setq help-echo (funcall help-echo widget))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
343 help-echo)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
344 (t
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
345 (format "(widget %S :help-echo %S)" widget help-echo)))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
346
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
347 (defun widget-specify-sample (widget from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
348 ;; Specify sample for WIDGET between FROM and TO.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
349 (let ((face (widget-apply widget :sample-face-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
350 (when face
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
351 (add-text-properties from to (list 'start-open t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
352 'end-open t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
353 'face face)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
354 (defun widget-specify-doc (widget from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
355 ;; Specify documentation for WIDGET between FROM and TO.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
356 (add-text-properties from to (list 'widget-doc widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
357 'face 'widget-documentation-face)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
358
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
359 (defmacro widget-specify-insert (&rest form)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
360 ;; Execute FORM without inheriting any text properties.
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
361 (`
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
362 (save-restriction
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
363 (let ((inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
364 result
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
365 before-change-functions
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
366 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
367 (insert "<>")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
368 (narrow-to-region (- (point) 2) (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
369 (widget-specify-none (point-min) (point-max))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
370 (goto-char (1+ (point-min)))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
371 (setq result (progn (,@ form)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
372 (delete-region (point-min) (1+ (point-min)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
373 (delete-region (1- (point-max)) (point-max))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
374 (goto-char (point-max))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
375 result))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
376
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
377 (defface widget-inactive-face '((((class grayscale color)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
378 (background dark))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
379 (:foreground "light gray"))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
380 (((class grayscale color)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
381 (background light))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
382 (:foreground "dim gray"))
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
383 (t
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
384 (:italic t)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
385 "Face used for inactive widgets."
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
386 :group 'widget-faces)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
387
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
388 (defun widget-specify-inactive (widget from to)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
389 "Make WIDGET inactive for user modifications."
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
390 (unless (widget-get widget :inactive)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
391 (let ((overlay (make-overlay from to nil t nil)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
392 (overlay-put overlay 'face 'widget-inactive-face)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
393 ;; This is disabled, as it makes the mouse cursor change shape.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
394 ;; (overlay-put overlay 'mouse-face 'widget-inactive-face)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
395 (overlay-put overlay 'evaporate t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
396 (overlay-put overlay 'priority 100)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
397 (overlay-put overlay (if (string-match "XEmacs" emacs-version)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
398 'read-only
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
399 'modification-hooks) '(widget-overlay-inactive))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
400 (widget-put widget :inactive overlay))))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
401
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
402 (defun widget-overlay-inactive (&rest junk)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
403 "Ignoring the arguments, signal an error."
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
404 (unless inhibit-read-only
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
405 (error "Attempt to modify inactive widget")))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
406
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
407
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
408 (defun widget-specify-active (widget)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
409 "Make WIDGET active for user modifications."
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
410 (let ((inactive (widget-get widget :inactive)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
411 (when inactive
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
412 (delete-overlay inactive)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
413 (widget-put widget :inactive nil))))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
414
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
415 ;;; Widget Properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
416
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
417 (defsubst widget-type (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
418 "Return the type of WIDGET, a symbol."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
419 (car widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
420
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
421 (defun widget-put (widget property value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
422 "In WIDGET set PROPERTY to VALUE.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
423 The value can later be retrived with `widget-get'."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
424 (setcdr widget (plist-put (cdr widget) property value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
425
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
426 (defun widget-get (widget property)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
427 "In WIDGET, get the value of PROPERTY.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
428 The value could either be specified when the widget was created, or
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
429 later with `widget-put'."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
430 (let ((missing t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
431 value tmp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
432 (while missing
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
433 (cond ((setq tmp (widget-plist-member (cdr widget) property))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
434 (setq value (car (cdr tmp))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
435 missing nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
436 ((setq tmp (car widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
437 (setq widget (get tmp 'widget-type)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
438 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
439 (setq missing nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
440 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
441
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
442 (defun widget-get-indirect (widget property)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
443 "In WIDGET, get the value of PROPERTY.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
444 If the value is a symbol, return its binding.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
445 Otherwise, just return the value."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
446 (let ((value (widget-get widget property)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
447 (if (symbolp value)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
448 (symbol-value value)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
449 value)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
450
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
451 (defun widget-member (widget property)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
452 "Non-nil iff there is a definition in WIDGET for PROPERTY."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
453 (cond ((widget-plist-member (cdr widget) property)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
454 t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
455 ((car widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
456 (widget-member (get (car widget) 'widget-type) property))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
457 (t nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
458
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
459 ;;;###autoload
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
460 (defun widget-apply (widget property &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
461 "Apply the value of WIDGET's PROPERTY to the widget itself.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
462 ARGS are passed as extra arguments to the function."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
463 (apply (widget-get widget property) widget args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
464
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
465 (defun widget-value (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
466 "Extract the current value of WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
467 (widget-apply widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
468 :value-to-external (widget-apply widget :value-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
469
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
470 (defun widget-value-set (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
471 "Set the current value of WIDGET to VALUE."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
472 (widget-apply widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
473 :value-set (widget-apply widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
474 :value-to-internal value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
475
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
476 (defun widget-match-inline (widget vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
477 ;; In WIDGET, match the start of VALS.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
478 (cond ((widget-get widget :inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
479 (widget-apply widget :match-inline vals))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
480 ((and vals
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
481 (widget-apply widget :match (car vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
482 (cons (list (car vals)) (cdr vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
483 (t nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
484
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
485 (defun widget-apply-action (widget &optional event)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
486 "Apply :action in WIDGET in response to EVENT."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
487 (if (widget-apply widget :active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
488 (widget-apply widget :action event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
489 (error "Attempt to perform action on inactive widget")))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
490
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
491 ;;; Helper functions.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
492 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
493 ;; These are widget specific.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
494
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
495 ;;;###autoload
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
496 (defun widget-prompt-value (widget prompt &optional value unbound)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
497 "Prompt for a value matching WIDGET, using PROMPT.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
498 The current value is assumed to be VALUE, unless UNBOUND is non-nil."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
499 (unless (listp widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
500 (setq widget (list widget)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
501 (setq prompt (format "[%s] %s" (widget-type widget) prompt))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
502 (setq widget (widget-convert widget))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
503 (let ((answer (widget-apply widget :prompt-value prompt value unbound)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
504 (unless (widget-apply widget :match answer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
505 (error "Value does not match %S type." (car widget)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
506 answer))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
507
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
508 (defun widget-get-sibling (widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
509 "Get the item WIDGET is assumed to toggle.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
510 This is only meaningful for radio buttons or checkboxes in a list."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
511 (let* ((parent (widget-get widget :parent))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
512 (children (widget-get parent :children))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
513 child)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
514 (catch 'child
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
515 (while children
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
516 (setq child (car children)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
517 children (cdr children))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
518 (when (eq (widget-get child :button) widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
519 (throw 'child child)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
520 nil)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
521
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
522 (defun widget-map-buttons (function &optional buffer maparg)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
523 "Map FUNCTION over the buttons in BUFFER.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
524 FUNCTION is called with the arguments WIDGET and MAPARG.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
525
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
526 If FUNCTION returns non-nil, the walk is cancelled.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
527
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
528 The arguments MAPARG, and BUFFER default to nil and (current-buffer),
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
529 respectively."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
530 (let ((cur (point-min))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
531 (widget nil)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
532 (parent nil)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
533 (overlays (if buffer
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
534 (save-excursion (set-buffer buffer) (overlay-lists))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
535 (overlay-lists))))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
536 (setq overlays (append (car overlays) (cdr overlays)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
537 (while (setq cur (pop overlays))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
538 (setq widget (overlay-get cur 'button))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
539 (if (and widget (funcall function widget maparg))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
540 (setq overlays nil)))))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
541
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
542 ;;; Glyphs.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
543
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
544 (defcustom widget-glyph-directory (concat data-directory "custom/")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
545 "Where widget glyphs are located.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
546 If this variable is nil, widget will try to locate the directory
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
547 automatically."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
548 :group 'widgets
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
549 :type 'directory)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
550
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
551 (defcustom widget-glyph-enable t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
552 "If non nil, use glyphs in images when available."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
553 :group 'widgets
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
554 :type 'boolean)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
555
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
556 (defcustom widget-image-conversion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
557 '((xpm ".xpm") (gif ".gif") (png ".png") (jpeg ".jpg" ".jpeg")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
558 (xbm ".xbm"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
559 "Conversion alist from image formats to file name suffixes."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
560 :group 'widgets
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
561 :type '(repeat (cons :format "%v"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
562 (symbol :tag "Image Format" unknown)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
563 (repeat :tag "Suffixes"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
564 (string :format "%v")))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
565
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
566 (defun widget-glyph-find (image tag)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
567 "Create a glyph corresponding to IMAGE with string TAG as fallback.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
568 IMAGE should either already be a glyph, or be a file name sans
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
569 extension (xpm, xbm, gif, jpg, or png) located in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
570 `widget-glyph-directory'."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
571 (cond ((not (and image
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
572 (string-match "XEmacs" emacs-version)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
573 widget-glyph-enable
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
574 (fboundp 'make-glyph)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
575 (fboundp 'locate-file)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
576 image))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
577 ;; We don't want or can't use glyphs.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
578 nil)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
579 ((and (fboundp 'glyphp)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
580 (glyphp image))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
581 ;; Already a glyph. Use it.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
582 image)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
583 ((stringp image)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
584 ;; A string. Look it up in relevant directories.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
585 (let* ((dirlist (list (or widget-glyph-directory
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
586 (concat data-directory
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
587 "custom/"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
588 data-directory))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
589 (formats widget-image-conversion)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
590 file)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
591 (while (and formats (not file))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
592 (when (valid-image-instantiator-format-p (car (car formats)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
593 (setq file (locate-file image dirlist
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
594 (mapconcat 'identity
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
595 (cdr (car formats))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
596 ":"))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
597 (unless file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
598 (setq formats (cdr formats))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
599 (and file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
600 ;; We create a glyph with the file as the default image
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
601 ;; instantiator, and the TAG fallback
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
602 (make-glyph (list (vector (car (car formats)) ':file file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
603 (vector 'string ':data tag))))))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
604 ((valid-instantiator-p image 'image)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
605 ;; A valid image instantiator (e.g. [gif :file "somefile"] etc.)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
606 (make-glyph (list image
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
607 (vector 'string ':data tag))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
608 ((consp image)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
609 ;; This could be virtually anything. Let `make-glyph' sort it out.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
610 (make-glyph image))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
611 (t
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
612 ;; Oh well.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
613 nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
614
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
615 (defun widget-glyph-insert (widget tag image &optional down inactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
616 "In WIDGET, insert the text TAG or, if supported, IMAGE.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
617 IMAGE should either be a glyph, an image instantiator, or an image file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
618 name sans extension (xpm, xbm, gif, jpg, or png) located in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
619 `widget-glyph-directory'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
620
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
621 Optional arguments DOWN and INACTIVE is used instead of IMAGE when the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
622 glyph is pressed or inactive, respectively.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
623
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
624 WARNING: If you call this with a glyph, and you want the user to be
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
625 able to invoke the glyph, make sure it is unique. If you use the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
626 same glyph for multiple widgets, invoking any of the glyphs will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
627 cause the last created widget to be invoked.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
628
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
629 Instead of an instantiator, you can also use a list of instantiators,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
630 or whatever `make-glyph' will accept. However, in that case you must
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
631 provide the fallback TAG as a part of the instantiator yourself."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
632 (let ((glyph (widget-glyph-find image tag)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
633 (if glyph
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
634 (widget-glyph-insert-glyph widget
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
635 glyph
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
636 (widget-glyph-find down tag)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
637 (widget-glyph-find inactive tag))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
638 (insert tag))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
639
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
640 (defun widget-glyph-insert-glyph (widget glyph &optional down inactive)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
641 "In WIDGET, insert GLYPH.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
642 If optional arguments DOWN and INACTIVE are given, they should be
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
643 glyphs used when the widget is pushed and inactive, respectively."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
644 (when widget
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
645 (set-glyph-property glyph 'widget widget)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
646 (when down
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
647 (set-glyph-property down 'widget widget))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
648 (when inactive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
649 (set-glyph-property inactive 'widget widget)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
650 (insert "*")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
651 (let ((ext (make-extent (point) (1- (point))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
652 (help-echo (and widget (widget-get widget :help-echo))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
653 (set-extent-property ext 'invisible t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
654 (set-extent-property ext 'start-open t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
655 (set-extent-property ext 'end-open t)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
656 (set-extent-end-glyph ext glyph)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
657 (when help-echo
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
658 (set-extent-property ext 'balloon-help help-echo)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
659 (set-extent-property ext 'help-echo help-echo)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
660 (when widget
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
661 (widget-put widget :glyph-up glyph)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
662 (when down (widget-put widget :glyph-down down))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
663 (when inactive (widget-put widget :glyph-inactive inactive))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
664
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
665 ;;; Buttons.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
666
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
667 (defgroup widget-button nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
668 "The look of various kinds of buttons."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
669 :group 'widgets)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
670
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
671 (defcustom widget-button-prefix ""
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
672 "String used as prefix for buttons."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
673 :type 'string
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
674 :group 'widget-button)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
675
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
676 (defcustom widget-button-suffix ""
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
677 "String used as suffix for buttons."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
678 :type 'string
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
679 :group 'widget-button)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
680
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
681 ;;; Creating Widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
682
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
683 ;;;###autoload
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
684 (defun widget-create (type &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
685 "Create widget of TYPE.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
686 The optional ARGS are additional keyword arguments."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
687 (let ((widget (apply 'widget-convert type args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
688 (widget-apply widget :create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
689 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
690
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
691 (defun widget-create-child-and-convert (parent type &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
692 "As part of the widget PARENT, create a child widget TYPE.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
693 The child is converted, using the keyword arguments ARGS."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
694 (let ((widget (apply 'widget-convert type args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
695 (widget-put widget :parent parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
696 (unless (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
697 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
698 (or (widget-get widget :extra-offset) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
699 (widget-get parent :offset))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
700 (widget-apply widget :create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
701 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
702
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
703 (defun widget-create-child (parent type)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
704 "Create widget of TYPE."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
705 (let ((widget (copy-sequence type)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
706 (widget-put widget :parent parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
707 (unless (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
708 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
709 (or (widget-get widget :extra-offset) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
710 (widget-get parent :offset))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
711 (widget-apply widget :create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
712 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
713
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
714 (defun widget-create-child-value (parent type value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
715 "Create widget of TYPE with value VALUE."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
716 (let ((widget (copy-sequence type)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
717 (widget-put widget :value (widget-apply widget :value-to-internal value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
718 (widget-put widget :parent parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
719 (unless (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
720 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
721 (or (widget-get widget :extra-offset) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
722 (widget-get parent :offset))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
723 (widget-apply widget :create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
724 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
725
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
726 ;;;###autoload
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
727 (defun widget-delete (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
728 "Delete WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
729 (widget-apply widget :delete))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
730
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
731 (defun widget-convert (type &rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
732 "Convert TYPE to a widget without inserting it in the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
733 The optional ARGS are additional keyword arguments."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
734 ;; Don't touch the type.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
735 (let* ((widget (if (symbolp type)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
736 (list type)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
737 (copy-sequence type)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
738 (current widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
739 (keys args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
740 ;; First set the :args keyword.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
741 (while (cdr current) ;Look in the type.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
742 (let ((next (car (cdr current))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
743 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
744 (setq current (cdr (cdr current)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
745 (setcdr current (list :args (cdr current)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
746 (setq current nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
747 (while args ;Look in the args.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
748 (let ((next (nth 0 args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
749 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
750 (setq args (nthcdr 2 args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
751 (widget-put widget :args args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
752 (setq args nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
753 ;; Then Convert the widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
754 (setq type widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
755 (while type
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
756 (let ((convert-widget (plist-get (cdr type) :convert-widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
757 (if convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
758 (setq widget (funcall convert-widget widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
759 (setq type (get (car type) 'widget-type)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
760 ;; Finally set the keyword args.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
761 (while keys
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
762 (let ((next (nth 0 keys)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
763 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
764 (progn
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
765 (widget-put widget next (nth 1 keys))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
766 (setq keys (nthcdr 2 keys)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
767 (setq keys nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
768 ;; Convert the :value to internal format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
769 (if (widget-member widget :value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
770 (let ((value (widget-get widget :value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
771 (widget-put widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
772 :value (widget-apply widget :value-to-internal value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
773 ;; Return the newly create widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
774 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
775
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
776 (defun widget-insert (&rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
777 "Call `insert' with ARGS and make the text read only."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
778 (let ((inhibit-read-only t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
779 before-change-functions
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
780 after-change-functions
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
781 (from (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
782 (apply 'insert args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
783 (widget-specify-text from (point))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
784
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
785 (defun widget-convert-text (type from to
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
786 &optional button-from button-to
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
787 &rest args)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
788 "Return a widget of type TYPE with endpoint FROM TO.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
789 Optional ARGS are extra keyword arguments for TYPE.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
790 and TO will be used as the widgets end points. If optional arguments
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
791 BUTTON-FROM and BUTTON-TO are given, these will be used as the widgets
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
792 button end points.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
793 Optional ARGS are extra keyword arguments for TYPE."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
794 (let ((widget (apply 'widget-convert type :delete 'widget-leave-text args))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
795 (from (copy-marker from))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
796 (to (copy-marker to)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
797 (widget-specify-text from to)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
798 (set-marker-insertion-type from t)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
799 (set-marker-insertion-type to nil)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
800 (widget-put widget :from from)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
801 (widget-put widget :to to)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
802 (when button-from
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
803 (widget-specify-button widget button-from button-to))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
804 widget))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
805
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
806 (defun widget-convert-button (type from to &rest args)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
807 "Return a widget of type TYPE with endpoint FROM TO.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
808 Optional ARGS are extra keyword arguments for TYPE.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
809 No text will be inserted to the buffer, instead the text between FROM
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
810 and TO will be used as the widgets end points, as well as the widgets
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
811 button end points."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
812 (apply 'widget-convert-text type from to from to args))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
813
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
814 (defun widget-leave-text (widget)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
815 "Remove markers and overlays from WIDGET and its children."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
816 (let ((from (widget-get widget :from))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
817 (to (widget-get widget :to))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
818 (button (widget-get widget :button-overlay))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
819 (field (widget-get widget :field-overlay))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
820 (children (widget-get widget :children)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
821 (set-marker from nil)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
822 (set-marker to nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
823 (when button
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
824 (delete-overlay button))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
825 (when field
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
826 (delete-overlay field))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
827 (mapcar 'widget-leave-text children)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
828
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
829 ;;; Keymap and Commands.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
830
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
831 (defvar widget-keymap nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
832 "Keymap containing useful binding for buffers containing widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
833 Recommended as a parent keymap for modes using widgets.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
834
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
835 (unless widget-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
836 (setq widget-keymap (make-sparse-keymap))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
837 (define-key widget-keymap "\t" 'widget-forward)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
838 (define-key widget-keymap [(shift tab)] 'widget-backward)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
839 (define-key widget-keymap [backtab] 'widget-backward)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
840 (if (string-match "XEmacs" emacs-version)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
841 (progn
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
842 ;;Glyph support.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
843 (define-key widget-keymap [button1] 'widget-button1-click)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
844 (define-key widget-keymap [button2] 'widget-button-click))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
845 (define-key widget-keymap [down-mouse-2] 'widget-button-click))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
846 (define-key widget-keymap "\C-m" 'widget-button-press))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
847
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
848 (defvar widget-global-map global-map
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
849 "Keymap used for events the widget does not handle themselves.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
850 (make-variable-buffer-local 'widget-global-map)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
851
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
852 (defvar widget-field-keymap nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
853 "Keymap used inside an editable field.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
854
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
855 (unless widget-field-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
856 (setq widget-field-keymap (copy-keymap widget-keymap))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
857 (unless (string-match "XEmacs" (emacs-version))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
858 (define-key widget-field-keymap [menu-bar] 'nil))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
859 (define-key widget-field-keymap "\C-k" 'widget-kill-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
860 (define-key widget-field-keymap "\M-\t" 'widget-complete)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
861 (define-key widget-field-keymap "\C-m" 'widget-field-activate)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
862 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
863 (define-key widget-field-keymap "\C-e" 'widget-end-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
864 (set-keymap-parent widget-field-keymap global-map))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
865
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
866 (defvar widget-text-keymap nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
867 "Keymap used inside a text field.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
868
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
869 (unless widget-text-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
870 (setq widget-text-keymap (copy-keymap widget-keymap))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
871 (unless (string-match "XEmacs" (emacs-version))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
872 (define-key widget-text-keymap [menu-bar] 'nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
873 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
874 (define-key widget-text-keymap "\C-e" 'widget-end-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
875 (set-keymap-parent widget-text-keymap global-map))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
876
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
877 (defun widget-field-activate (pos &optional event)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
878 "Invoke the ediable field at point."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
879 (interactive "@d")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
880 (let ((field (get-char-property pos 'field)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
881 (if field
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
882 (widget-apply-action field event)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
883 (call-interactively
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
884 (lookup-key widget-global-map (this-command-keys))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
885
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
886 (defface widget-button-pressed-face
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
887 '((((class color))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
888 (:foreground "red"))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
889 (t
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
890 (:bold t :underline t)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
891 "Face used for pressed buttons."
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
892 :group 'widget-faces)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
893
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
894 (defun widget-button-click (event)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
895 "Invoke button below mouse pointer."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
896 (interactive "@e")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
897 (cond ((and (fboundp 'event-glyph)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
898 (event-glyph event))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
899 (widget-glyph-click event))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
900 ((widget-event-point event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
901 (let* ((pos (widget-event-point event))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
902 (button (get-char-property pos 'button)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
903 (if button
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
904 (let* ((overlay (widget-get button :button-overlay))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
905 (face (overlay-get overlay 'face))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
906 (mouse-face (overlay-get overlay 'mouse-face)))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
907 (unwind-protect
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
908 (let ((track-mouse t))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
909 (overlay-put overlay
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
910 'face 'widget-button-pressed-face)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
911 (overlay-put overlay
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
912 'mouse-face 'widget-button-pressed-face)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
913 (unless (widget-apply button :mouse-down-action event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
914 (while (not (button-release-event-p event))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
915 (setq event (widget-read-event)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
916 pos (widget-event-point event))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
917 (if (and pos
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
918 (eq (get-char-property pos 'button)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
919 button))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
920 (progn
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
921 (overlay-put overlay
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
922 'face
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
923 'widget-button-pressed-face)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
924 (overlay-put overlay
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
925 'mouse-face
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
926 'widget-button-pressed-face))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
927 (overlay-put overlay 'face face)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
928 (overlay-put overlay 'mouse-face mouse-face))))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
929 (when (and pos
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
930 (eq (get-char-property pos 'button) button))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
931 (widget-apply-action button event)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
932 (overlay-put overlay 'face face)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
933 (overlay-put overlay 'mouse-face mouse-face)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
934 (let (command up)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
935 ;; Find the global command to run, and check whether it
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
936 ;; is bound to an up event.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
937 (cond ((setq command ;down event
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
938 (lookup-key widget-global-map [ button2 ])))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
939 ((setq command ;down event
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
940 (lookup-key widget-global-map [ down-mouse-2 ])))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
941 ((setq command ;up event
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
942 (lookup-key widget-global-map [ button2up ]))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
943 (setq up t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
944 ((setq command ;up event
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
945 (lookup-key widget-global-map [ mouse-2]))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
946 (setq up t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
947 (when command
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
948 ;; Don't execute up events twice.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
949 (when up
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
950 (while (not (button-release-event-p event))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
951 (setq event (widget-read-event))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
952 (call-interactively command))))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
953 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
954 (message "You clicked somewhere weird."))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
955
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
956 (defun widget-button1-click (event)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
957 "Invoke glyph below mouse pointer."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
958 (interactive "@e")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
959 (if (and (fboundp 'event-glyph)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
960 (event-glyph event))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
961 (widget-glyph-click event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
962 (call-interactively (lookup-key widget-global-map (this-command-keys)))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
963
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
964 (defun widget-glyph-click (event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
965 "Handle click on a glyph."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
966 (let* ((glyph (event-glyph event))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
967 (widget (glyph-property glyph 'widget))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
968 (extent (event-glyph-extent event))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
969 (down-glyph (or (and widget (widget-get widget :glyph-down)) glyph))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
970 (up-glyph (or (and widget (widget-get widget :glyph-up)) glyph))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
971 (last event))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
972 ;; Wait for the release.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
973 (while (not (button-release-event-p last))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
974 (if (eq extent (event-glyph-extent last))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
975 (set-extent-property extent 'end-glyph down-glyph)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
976 (set-extent-property extent 'end-glyph up-glyph))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
977 (setq last (next-event event)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
978 ;; Release glyph.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
979 (when down-glyph
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
980 (set-extent-property extent 'end-glyph up-glyph))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
981 ;; Apply widget action.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
982 (when (eq extent (event-glyph-extent last))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
983 (let ((widget (glyph-property (event-glyph event) 'widget)))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
984 (cond ((null widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
985 (message "You clicked on a glyph."))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
986 ((not (widget-apply widget :active))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
987 (message "This glyph is inactive."))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
988 (t
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
989 (widget-apply-action widget event)))))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
990
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
991 (defun widget-button-press (pos &optional event)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
992 "Invoke button at POS."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
993 (interactive "@d")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
994 (let ((button (get-char-property pos 'button)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
995 (if button
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
996 (widget-apply-action button event)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
997 (let ((command (lookup-key widget-global-map (this-command-keys))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
998 (when (commandp command)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
999 (call-interactively command))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1000
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1001 (defun widget-tabable-at (&optional pos)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1002 "Return the tabable widget at POS, or nil.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1003 POS defaults to the value of (point)."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1004 (unless pos
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1005 (setq pos (point)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1006 (let ((widget (or (get-char-property (point) 'button)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1007 (get-char-property (point) 'field))))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1008 (if widget
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1009 (let ((order (widget-get widget :tab-order)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1010 (if order
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1011 (if (>= order 0)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1012 widget
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1013 nil)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1014 widget))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1015 nil)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1016
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1017 (defun widget-move (arg)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1018 "Move point to the ARG next field or button.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1019 ARG may be negative to move backward."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1020 (or (bobp) (> arg 0) (backward-char))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1021 (let ((pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1022 (number arg)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1023 (old (widget-tabable-at))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1024 new)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1025 ;; Forward.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1026 (while (> arg 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1027 (if (eobp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1028 (goto-char (point-min))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1029 (forward-char 1))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1030 (and (eq pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1031 (eq arg number)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1032 (error "No buttons or fields found"))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1033 (let ((new (widget-tabable-at)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1034 (when new
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1035 (unless (eq new old)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1036 (setq arg (1- arg))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1037 (setq old new)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1038 ;; Backward.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1039 (while (< arg 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1040 (if (bobp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1041 (goto-char (point-max))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1042 (backward-char 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1043 (and (eq pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1044 (eq arg number)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1045 (error "No buttons or fields found"))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1046 (let ((new (widget-tabable-at)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1047 (when new
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1048 (unless (eq new old)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1049 (setq arg (1+ arg))))))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1050 (let ((new (widget-tabable-at)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1051 (while (eq (widget-tabable-at) new)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1052 (backward-char)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1053 (forward-char))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1054 (widget-echo-help (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1055 (run-hooks 'widget-move-hook))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1056
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1057 (defun widget-forward (arg)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1058 "Move point to the next field or button.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1059 With optional ARG, move across that many fields."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1060 (interactive "p")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1061 (run-hooks 'widget-forward-hook)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1062 (widget-move arg))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1063
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1064 (defun widget-backward (arg)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1065 "Move point to the previous field or button.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1066 With optional ARG, move across that many fields."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1067 (interactive "p")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1068 (run-hooks 'widget-backward-hook)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1069 (widget-move (- arg)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1070
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1071 (defun widget-beginning-of-line ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1072 "Go to beginning of field or beginning of line, whichever is first."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1073 (interactive)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1074 (let* ((field (widget-field-find (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1075 (start (and field (widget-field-start field))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1076 (if (and start (not (eq start (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1077 (goto-char start)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1078 (call-interactively 'beginning-of-line))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1079
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1080 (defun widget-end-of-line ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1081 "Go to end of field or end of line, whichever is first."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1082 (interactive)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1083 (let* ((field (widget-field-find (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1084 (end (and field (widget-field-end field))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1085 (if (and end (not (eq end (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1086 (goto-char end)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1087 (call-interactively 'end-of-line))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1088
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1089 (defun widget-kill-line ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1090 "Kill to end of field or end of line, whichever is first."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1091 (interactive)
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1092 (let* ((field (widget-field-find (point)))
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1093 (newline (save-excursion (forward-line 1) (point)))
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1094 (end (and field (widget-field-end field))))
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1095 (if (and field (> newline end))
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1096 (kill-region (point) end)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1097 (call-interactively 'kill-line))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1098
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1099 (defcustom widget-complete-field (lookup-key global-map "\M-\t")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1100 "Default function to call for completion inside fields."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1101 :options '(ispell-complete-word complete-tag lisp-complete-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1102 :type 'function
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1103 :group 'widgets)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1104
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1105 (defun widget-complete ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1106 "Complete content of editable field from point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1107 When not inside a field, move to the previous button or field."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1108 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1109 (let ((field (widget-field-find (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1110 (if field
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1111 (widget-apply field :complete)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1112 (error "Not in an editable field"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1113
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1114 ;;; Setting up the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1115
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1116 (defvar widget-field-new nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1117 ;; List of all newly created editable fields in the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1118 (make-variable-buffer-local 'widget-field-new)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1119
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1120 (defvar widget-field-list nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1121 ;; List of all editable fields in the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1122 (make-variable-buffer-local 'widget-field-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1123
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1124 (defun widget-setup ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1125 "Setup current buffer so editing string widgets works."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1126 (let ((inhibit-read-only t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1127 (after-change-functions nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1128 before-change-functions
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1129 field)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1130 (while widget-field-new
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1131 (setq field (car widget-field-new)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1132 widget-field-new (cdr widget-field-new)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1133 widget-field-list (cons field widget-field-list))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1134 (let ((from (car (widget-get field :field-overlay)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1135 (to (cdr (widget-get field :field-overlay))))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1136 (widget-specify-field field
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1137 (marker-position from) (marker-position to))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1138 (set-marker from nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1139 (set-marker to nil))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1140 (widget-clear-undo)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1141 ;; We need to maintain text properties and size of the editing fields.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1142 (make-local-variable 'after-change-functions)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1143 (make-local-variable 'before-change-functions)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1144 (setq after-change-functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1145 (if widget-field-list '(widget-after-change) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1146 (setq before-change-functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1147 (if widget-field-list '(widget-before-change) nil)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1148
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1149 (defvar widget-field-last nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1150 ;; Last field containing point.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1151 (make-variable-buffer-local 'widget-field-last)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1152
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1153 (defvar widget-field-was nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1154 ;; The widget data before the change.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1155 (make-variable-buffer-local 'widget-field-was)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1156
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1157 (defun widget-field-buffer (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1158 "Return the start of WIDGET's editing field."
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1159 (let ((overlay (widget-get widget :field-overlay)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1160 (and overlay (overlay-buffer overlay))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1161
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1162 (defun widget-field-start (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1163 "Return the start of WIDGET's editing field."
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1164 (let ((overlay (widget-get widget :field-overlay)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1165 (and overlay (overlay-start overlay))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1166
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1167 (defun widget-field-end (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1168 "Return the end of WIDGET's editing field."
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1169 (let ((overlay (widget-get widget :field-overlay)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1170 ;; Don't subtract one if local-map works at the end of the overlay.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1171 (and overlay (if widget-field-add-space
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1172 (1- (overlay-end overlay))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1173 (overlay-end overlay)))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1174
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1175 (defun widget-field-find (pos)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1176 "Return the field at POS.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1177 Unlike (get-char-property POS 'field) this, works with empty fields too."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1178 (let ((fields widget-field-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1179 field found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1180 (while fields
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1181 (setq field (car fields)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1182 fields (cdr fields))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1183 (let ((start (widget-field-start field))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1184 (end (widget-field-end field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1185 (when (and (<= start pos) (<= pos end))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1186 (when found
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1187 (debug "Overlapping fields"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1188 (setq found field))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1189 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1190
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1191 (defun widget-before-change (from &rest ignore)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1192 ;; This is how, for example, a variable changes its state to `modified'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1193 ;; when it is being edited.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1194 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1195 (let ((field (widget-field-find from)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1196 (widget-apply field :notify field))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1197 (error (debug "Before Change"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1198
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1199 (defun widget-after-change (from to old)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1200 ;; Adjust field size and text properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1201 (condition-case nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1202 (let ((field (widget-field-find from))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1203 (other (widget-field-find to)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1204 (when field
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1205 (unless (eq field other)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1206 (debug "Change in different fields"))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1207 (let ((size (widget-get field :size))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1208 (secret (widget-get field :secret)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1209 (when size
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1210 (let ((begin (widget-field-start field))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1211 (end (widget-field-end field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1212 (cond ((< (- end begin) size)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1213 ;; Field too small.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1214 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1215 (goto-char end)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1216 (insert-char ?\ (- (+ begin size) end))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1217 ((> (- end begin) size)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1218 ;; Field too large and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1219 (if (or (< (point) (+ begin size))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1220 (> (point) end))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1221 ;; Point is outside extra space.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1222 (setq begin (+ begin size))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1223 ;; Point is within the extra space.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1224 (setq begin (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1225 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1226 (goto-char end)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1227 (while (and (eq (preceding-char) ?\ )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1228 (> (point) begin))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1229 (delete-backward-char 1)))))))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1230 (when secret
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1231 (let ((begin (widget-field-start field))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1232 (end (widget-field-end field)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1233 (when size
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1234 (while (and (> end begin)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1235 (eq (char-after (1- end)) ?\ ))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1236 (setq end (1- end))))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1237 (while (< begin end)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1238 (let ((old (char-after begin)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1239 (unless (eq old secret)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1240 (subst-char-in-region begin (1+ begin) old secret)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1241 (put-text-property begin (1+ begin) 'secret old))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1242 (setq begin (1+ begin)))))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1243 (widget-apply field :notify field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1244 (error (debug "After Change"))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1245
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1246 ;;; Widget Functions
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1247 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1248 ;; These functions are used in the definition of multiple widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1249
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1250 (defun widget-parent-action (widget &optional event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1251 "Tell :parent of WIDGET to handle the :action.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1252 Optional EVENT is the event that triggered the action."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1253 (widget-apply (widget-get widget :parent) :action event))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1254
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1255 (defun widget-children-value-delete (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1256 "Delete all :children and :buttons in WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1257 (mapcar 'widget-delete (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1258 (widget-put widget :children nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1259 (mapcar 'widget-delete (widget-get widget :buttons))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1260 (widget-put widget :buttons nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1261
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1262 (defun widget-children-validate (widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1263 "All the :children must be valid."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1264 (let ((children (widget-get widget :children))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1265 child found)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1266 (while (and children (not found))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1267 (setq child (car children)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1268 children (cdr children)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1269 found (widget-apply child :validate)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1270 found))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1271
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1272 (defun widget-types-convert-widget (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1273 "Convert :args as widget types in WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1274 (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1275 widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1276
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1277 (defun widget-value-convert-widget (widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1278 "Initialize :value from :args in WIDGET."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1279 (let ((args (widget-get widget :args)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1280 (when args
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1281 (widget-put widget :value (car args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1282 ;; Don't convert :value here, as this is done in `widget-convert'.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1283 ;; (widget-put widget :value (widget-apply widget
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1284 ;; :value-to-internal (car args)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1285 (widget-put widget :args nil)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1286 widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1287
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1288 (defun widget-value-value-get (widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1289 "Return the :value property of WIDGET."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1290 (widget-get widget :value))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1291
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1292 ;;; The `default' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1293
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1294 (define-widget 'default nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1295 "Basic widget other widgets are derived from."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1296 :value-to-internal (lambda (widget value) value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1297 :value-to-external (lambda (widget value) value)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1298 :button-prefix 'widget-button-prefix
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1299 :button-suffix 'widget-button-suffix
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1300 :complete 'widget-default-complete
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1301 :create 'widget-default-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1302 :indent nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1303 :offset 0
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1304 :format-handler 'widget-default-format-handler
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1305 :button-face-get 'widget-default-button-face-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1306 :sample-face-get 'widget-default-sample-face-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1307 :delete 'widget-default-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1308 :value-set 'widget-default-value-set
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1309 :value-inline 'widget-default-value-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1310 :menu-tag-get 'widget-default-menu-tag-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1311 :validate (lambda (widget) nil)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1312 :active 'widget-default-active
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1313 :activate 'widget-specify-active
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1314 :deactivate 'widget-default-deactivate
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1315 :mouse-down-action (lambda (widget event) nil)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1316 :action 'widget-default-action
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1317 :notify 'widget-default-notify
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1318 :prompt-value 'widget-default-prompt-value)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1319
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1320 (defun widget-default-complete (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1321 "Call the value of the :complete-function property of WIDGET.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1322 If that does not exists, call the value of `widget-complete-field'."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1323 (let ((fun (widget-get widget :complete-function)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1324 (call-interactively (or fun widget-complete-field))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1325
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1326 (defun widget-default-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1327 "Create WIDGET at point in the current buffer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1328 (widget-specify-insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1329 (let ((from (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1330 button-begin button-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1331 sample-begin sample-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1332 doc-begin doc-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1333 value-pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1334 (insert (widget-get widget :format))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1335 (goto-char from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1336 ;; Parse escapes in format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1337 (while (re-search-forward "%\\(.\\)" nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1338 (let ((escape (aref (match-string 1) 0)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1339 (replace-match "" t t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1340 (cond ((eq escape ?%)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1341 (insert "%"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1342 ((eq escape ?\[)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1343 (setq button-begin (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1344 (insert (widget-get-indirect widget :button-prefix)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1345 ((eq escape ?\])
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1346 (insert (widget-get-indirect widget :button-suffix))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1347 (setq button-end (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1348 ((eq escape ?\{)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1349 (setq sample-begin (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1350 ((eq escape ?\})
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1351 (setq sample-end (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1352 ((eq escape ?n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1353 (when (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1354 (insert "\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1355 (insert-char ? (widget-get widget :indent))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1356 ((eq escape ?t)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1357 (let ((glyph (widget-get widget :tag-glyph))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1358 (tag (widget-get widget :tag)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1359 (cond (glyph
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1360 (widget-glyph-insert widget (or tag "image") glyph))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1361 (tag
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1362 (insert tag))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1363 (t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1364 (let ((standard-output (current-buffer)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1365 (princ (widget-get widget :value)))))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1366 ((eq escape ?d)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1367 (let ((doc (widget-get widget :doc)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1368 (when doc
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1369 (setq doc-begin (point))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1370 (insert doc)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1371 (while (eq (preceding-char) ?\n)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1372 (delete-backward-char 1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1373 (insert "\n")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1374 (setq doc-end (point)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1375 ((eq escape ?v)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1376 (if (and button-begin (not button-end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1377 (widget-apply widget :value-create)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1378 (setq value-pos (point))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1379 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1380 (widget-apply widget :format-handler escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1381 ;; Specify button, sample, and doc, and insert value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1382 (and button-begin button-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1383 (widget-specify-button widget button-begin button-end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1384 (and sample-begin sample-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1385 (widget-specify-sample widget sample-begin sample-end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1386 (and doc-begin doc-end
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1387 (widget-specify-doc widget doc-begin doc-end))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1388 (when value-pos
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1389 (goto-char value-pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1390 (widget-apply widget :value-create)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1391 (let ((from (copy-marker (point-min)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1392 (to (copy-marker (point-max))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1393 (widget-specify-text from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1394 (set-marker-insertion-type from t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1395 (set-marker-insertion-type to nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1396 (widget-put widget :from from)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1397 (widget-put widget :to to)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1398 (widget-clear-undo))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1399
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1400 (defun widget-default-format-handler (widget escape)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1401 ;; We recognize the %h escape by default.
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1402 (let* ((buttons (widget-get widget :buttons)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1403 (cond ((eq escape ?h)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1404 (let* ((doc-property (widget-get widget :documentation-property))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1405 (doc-try (cond ((widget-get widget :doc))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1406 ((symbolp doc-property)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1407 (documentation-property
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1408 (widget-get widget :value)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1409 doc-property))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1410 (t
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1411 (funcall doc-property
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1412 (widget-get widget :value)))))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1413 (doc-text (and (stringp doc-try)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1414 (> (length doc-try) 1)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1415 doc-try))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1416 (doc-indent (widget-get widget :documentation-indent)))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1417 (when doc-text
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1418 (and (eq (preceding-char) ?\n)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1419 (widget-get widget :indent)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1420 (insert-char ? (widget-get widget :indent)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1421 ;; The `*' in the beginning is redundant.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1422 (when (eq (aref doc-text 0) ?*)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1423 (setq doc-text (substring doc-text 1)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1424 ;; Get rid of trailing newlines.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1425 (when (string-match "\n+\\'" doc-text)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1426 (setq doc-text (substring doc-text 0 (match-beginning 0))))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1427 (push (widget-create-child-and-convert
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1428 widget 'documentation-string
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1429 :indent (cond ((numberp doc-indent )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1430 doc-indent)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1431 ((null doc-indent)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1432 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1433 (t 0))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1434 doc-text)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1435 buttons))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1436 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1437 (error "Unknown escape `%c'" escape)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1438 (widget-put widget :buttons buttons)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1439
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1440 (defun widget-default-button-face-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1441 ;; Use :button-face or widget-button-face
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1442 (or (widget-get widget :button-face) 'widget-button-face))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1443
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1444 (defun widget-default-sample-face-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1445 ;; Use :sample-face.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1446 (widget-get widget :sample-face))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1447
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1448 (defun widget-default-delete (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1449 ;; Remove widget from the buffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1450 (let ((from (widget-get widget :from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1451 (to (widget-get widget :to))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1452 (inactive-overlay (widget-get widget :inactive))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1453 (button-overlay (widget-get widget :button-overlay))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1454 before-change-functions
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1455 after-change-functions
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1456 (inhibit-read-only t))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1457 (widget-apply widget :value-delete)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1458 (when inactive-overlay
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1459 (delete-overlay inactive-overlay))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1460 (when button-overlay
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1461 (delete-overlay button-overlay))
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1462 (when (< from to)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1463 ;; Kludge: this doesn't need to be true for empty formats.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1464 (delete-region from to))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1465 (set-marker from nil)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1466 (set-marker to nil))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1467 (widget-clear-undo))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1468
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1469 (defun widget-default-value-set (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1470 ;; Recreate widget with new value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1471 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1472 (goto-char (widget-get widget :from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1473 (widget-apply widget :delete)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1474 (widget-put widget :value value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1475 (widget-apply widget :create)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1476
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1477 (defun widget-default-value-inline (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1478 ;; Wrap value in a list unless it is inline.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1479 (if (widget-get widget :inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1480 (widget-value widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1481 (list (widget-value widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1482
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1483 (defun widget-default-menu-tag-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1484 ;; Use tag or value for menus.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1485 (or (widget-get widget :menu-tag)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1486 (widget-get widget :tag)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1487 (widget-princ-to-string (widget-get widget :value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1488
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1489 (defun widget-default-active (widget)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1490 "Return t iff this widget active (user modifiable)."
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1491 (and (not (widget-get widget :inactive))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1492 (let ((parent (widget-get widget :parent)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1493 (or (null parent)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1494 (widget-apply parent :active)))))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1495
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1496 (defun widget-default-deactivate (widget)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1497 "Make WIDGET inactive for user modifications."
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1498 (widget-specify-inactive widget
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1499 (widget-get widget :from)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1500 (widget-get widget :to)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1501
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1502 (defun widget-default-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1503 ;; Notify the parent when a widget change
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1504 (let ((parent (widget-get widget :parent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1505 (when parent
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1506 (widget-apply parent :notify widget event))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1507
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1508 (defun widget-default-notify (widget child &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1509 ;; Pass notification to parent.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1510 (widget-default-action widget event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1511
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1512 (defun widget-default-prompt-value (widget prompt value unbound)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1513 ;; Read an arbitrary value. Stolen from `set-variable'.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1514 ;; (let ((initial (if unbound
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1515 ;; nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1516 ;; ;; It would be nice if we could do a `(cons val 1)' here.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1517 ;; (prin1-to-string (custom-quote value))))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1518 (eval-minibuffer prompt ))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1519
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1520 ;;; The `item' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1521
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1522 (define-widget 'item 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1523 "Constant items for inclusion in other widgets."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1524 :convert-widget 'widget-value-convert-widget
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1525 :value-create 'widget-item-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1526 :value-delete 'ignore
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1527 :value-get 'widget-value-value-get
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1528 :match 'widget-item-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1529 :match-inline 'widget-item-match-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1530 :action 'widget-item-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1531 :format "%t\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1532
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1533 (defun widget-item-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1534 ;; Insert the printed representation of the value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1535 (let ((standard-output (current-buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1536 (princ (widget-get widget :value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1537
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1538 (defun widget-item-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1539 ;; Match if the value is the same.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1540 (equal (widget-get widget :value) value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1541
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1542 (defun widget-item-match-inline (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1543 ;; Match if the value is the same.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1544 (let ((value (widget-get widget :value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1545 (and (listp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1546 (<= (length value) (length values))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1547 (let ((head (widget-sublist values 0 (length value))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1548 (and (equal head value)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1549 (cons head (widget-sublist values (length value))))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1550
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1551 (defun widget-sublist (list start &optional end)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1552 "Return the sublist of LIST from START to END.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1553 If END is omitted, it defaults to the length of LIST."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1554 (if (> start 0) (setq list (nthcdr start list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1555 (if end
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1556 (if (<= end start)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1557 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1558 (setq list (copy-sequence list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1559 (setcdr (nthcdr (- end start 1) list) nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1560 list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1561 (copy-sequence list)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1562
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1563 (defun widget-item-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1564 ;; Just notify itself.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1565 (widget-apply widget :notify widget event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1566
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1567 ;;; The `push-button' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1568
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1569 (defcustom widget-push-button-gui t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1570 "If non nil, use GUI push buttons when available."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1571 :group 'widgets
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1572 :type 'boolean)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1573
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1574 ;; Cache already created GUI objects.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1575 (defvar widget-push-button-cache nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1576
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1577 (defcustom widget-push-button-prefix "["
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1578 "String used as prefix for buttons."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1579 :type 'string
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1580 :group 'widget-button)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1581
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1582 (defcustom widget-push-button-suffix "]"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1583 "String used as suffix for buttons."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1584 :type 'string
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1585 :group 'widget-button)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1586
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1587 (define-widget 'push-button 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1588 "A pushable button."
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1589 :button-prefix ""
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1590 :button-suffix ""
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1591 :value-create 'widget-push-button-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1592 :format "%[%v%]")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1593
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1594 (defun widget-push-button-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1595 ;; Insert text representing the `on' and `off' states.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1596 (let* ((tag (or (widget-get widget :tag)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1597 (widget-get widget :value)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1598 (tag-glyph (widget-get widget :tag-glyph))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1599 (text (concat widget-push-button-prefix
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1600 tag widget-push-button-suffix))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1601 (gui (cdr (assoc tag widget-push-button-cache))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1602 (cond (tag-glyph
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1603 (widget-glyph-insert widget text tag-glyph))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1604 ((and (fboundp 'make-gui-button)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1605 (fboundp 'make-glyph)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1606 widget-push-button-gui
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1607 (fboundp 'device-on-window-system-p)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1608 (device-on-window-system-p)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1609 (string-match "XEmacs" emacs-version))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1610 (unless gui
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1611 (setq gui (make-gui-button tag 'widget-gui-action widget))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1612 (push (cons tag gui) widget-push-button-cache))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1613 (widget-glyph-insert-glyph widget
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1614 (make-glyph
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1615 (list (nth 0 (aref gui 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1616 (vector 'string ':data text)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1617 (make-glyph
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1618 (list (nth 1 (aref gui 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1619 (vector 'string ':data text)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1620 (make-glyph
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1621 (list (nth 2 (aref gui 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1622 (vector 'string ':data text)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1623 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
1624 (insert text)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1625
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1626 (defun widget-gui-action (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1627 "Apply :action for WIDGET."
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1628 (widget-apply-action widget (this-command-keys)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1629
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1630 ;;; The `link' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1631
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1632 (defcustom widget-link-prefix "["
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1633 "String used as prefix for links."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1634 :type 'string
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1635 :group 'widget-button)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1636
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1637 (defcustom widget-link-suffix "]"
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1638 "String used as suffix for links."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1639 :type 'string
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1640 :group 'widget-button)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1641
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1642 (define-widget 'link 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1643 "An embedded link."
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1644 :button-prefix 'widget-link-prefix
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1645 :button-suffix 'widget-link-suffix
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
1646 :help-echo "Follow the link."
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1647 :format "%[%t%]")
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1648
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1649 ;;; The `info-link' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1650
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1651 (define-widget 'info-link 'link
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1652 "A link to an info file."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1653 :action 'widget-info-link-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1654
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1655 (defun widget-info-link-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1656 "Open the info node specified by WIDGET."
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
1657 (Info-goto-node (widget-value widget)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1658
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1659 ;;; The `url-link' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1660
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1661 (define-widget 'url-link 'link
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1662 "A link to an www page."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1663 :action 'widget-url-link-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1664
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1665 (defun widget-url-link-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1666 "Open the url specified by WIDGET."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1667 (require 'browse-url)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1668 (funcall browse-url-browser-function (widget-value widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1669
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1670 ;;; The `editable-field' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1671
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1672 (define-widget 'editable-field 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1673 "An editable text field."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1674 :convert-widget 'widget-value-convert-widget
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1675 :keymap widget-field-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1676 :format "%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1677 :value ""
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1678 :prompt-internal 'widget-field-prompt-internal
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1679 :prompt-history 'widget-field-history
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1680 :prompt-value 'widget-field-prompt-value
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1681 :action 'widget-field-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1682 :validate 'widget-field-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1683 :valid-regexp ""
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1684 :error "No match"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1685 :value-create 'widget-field-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1686 :value-delete 'widget-field-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1687 :value-get 'widget-field-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1688 :match 'widget-field-match)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1689
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1690 (defvar widget-field-history nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1691 "History of field minibuffer edits.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1692
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1693 (defun widget-field-prompt-internal (widget prompt initial history)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1694 ;; Read string for WIDGET promptinhg with PROMPT.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1695 ;; INITIAL is the initial input and HISTORY is a symbol containing
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1696 ;; the earlier input.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1697 (read-string prompt initial history))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1698
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1699 (defun widget-field-prompt-value (widget prompt value unbound)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1700 ;; Prompt for a string.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1701 (let ((initial (if unbound
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1702 nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1703 (cons (widget-apply widget :value-to-internal
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1704 value) 0)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1705 (history (widget-get widget :prompt-history)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1706 (let ((answer (widget-apply widget
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1707 :prompt-internal prompt initial history)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1708 (widget-apply widget :value-to-external answer))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1709
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1710 (defun widget-field-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1711 ;; Edit the value in the minibuffer.
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1712 (let ((invalid (widget-apply widget :validate)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1713 (let ((prompt (concat (widget-apply widget :menu-tag-get) ": "))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1714 (value (unless invalid
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1715 (widget-value widget))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1716 (let ((answer (widget-apply widget :prompt-value prompt value invalid) ))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1717 (widget-value-set widget answer)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1718 (widget-setup)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1719 (widget-apply widget :notify widget event)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1720
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1721 (defun widget-field-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1722 ;; Valid if the content matches `:valid-regexp'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1723 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1724 (let ((value (widget-apply widget :value-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1725 (regexp (widget-get widget :valid-regexp)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1726 (if (string-match regexp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1727 nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1728 widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1729
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1730 (defun widget-field-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1731 ;; Create an editable text field.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1732 (let ((size (widget-get widget :size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1733 (value (widget-get widget :value))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1734 (from (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1735 (overlay (cons (make-marker) (make-marker))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1736 (widget-put widget :field-overlay overlay)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1737 (insert value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1738 (and size
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1739 (< (length value) size)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1740 (insert-char ?\ (- size (length value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1741 (unless (memq widget widget-field-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1742 (setq widget-field-new (cons widget widget-field-new)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1743 (move-marker (cdr overlay) (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1744 (set-marker-insertion-type (cdr overlay) nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1745 (when (null size)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1746 (insert ?\n))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1747 (move-marker (car overlay) from)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1748 (set-marker-insertion-type (car overlay) t)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1749
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1750 (defun widget-field-value-delete (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1751 ;; Remove the widget from the list of active editing fields.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1752 (setq widget-field-list (delq widget widget-field-list))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1753 ;; These are nil if the :format string doesn't contain `%v'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1754 (let ((overlay (widget-get widget :field-overlay)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1755 (when overlay
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1756 (delete-overlay overlay))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1757
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1758 (defun widget-field-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1759 ;; Return current text in editing field.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1760 (let ((from (widget-field-start widget))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1761 (to (widget-field-end widget))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1762 (buffer (widget-field-buffer widget))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1763 (size (widget-get widget :size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1764 (secret (widget-get widget :secret))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1765 (old (current-buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1766 (if (and from to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1767 (progn
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1768 (set-buffer buffer)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1769 (while (and size
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1770 (not (zerop size))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1771 (> to from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1772 (eq (char-after (1- to)) ?\ ))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1773 (setq to (1- to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1774 (let ((result (buffer-substring-no-properties from to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1775 (when secret
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1776 (let ((index 0))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1777 (while (< (+ from index) to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1778 (aset result index
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1779 (get-char-property (+ from index) 'secret))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1780 (setq index (1+ index)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1781 (set-buffer old)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1782 result))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1783 (widget-get widget :value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1784
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1785 (defun widget-field-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1786 ;; Match any string.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1787 (stringp value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1788
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1789 ;;; The `text' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1790
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1791 (define-widget 'text 'editable-field
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1792 :keymap widget-text-keymap
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1793 "A multiline text area.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1794
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1795 ;;; The `menu-choice' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1796
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1797 (define-widget 'menu-choice 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1798 "A menu of options."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1799 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1800 :format "%[%t%]: %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1801 :case-fold t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1802 :tag "choice"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1803 :void '(item :format "invalid (%t)\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1804 :value-create 'widget-choice-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1805 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1806 :value-get 'widget-choice-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1807 :value-inline 'widget-choice-value-inline
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1808 :mouse-down-action 'widget-choice-mouse-down-action
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1809 :action 'widget-choice-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1810 :error "Make a choice"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1811 :validate 'widget-choice-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1812 :match 'widget-choice-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1813 :match-inline 'widget-choice-match-inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1814
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1815 (defun widget-choice-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1816 ;; Insert the first choice that matches the value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1817 (let ((value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1818 (args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1819 current)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1820 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1821 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1822 args (cdr args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1823 (when (widget-apply current :match value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1824 (widget-put widget :children (list (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1825 widget current value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1826 (widget-put widget :choice current)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1827 (setq args nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1828 current nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1829 (when current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1830 (let ((void (widget-get widget :void)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1831 (widget-put widget :children (list (widget-create-child-and-convert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1832 widget void :value value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1833 (widget-put widget :choice void)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1834
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1835 (defun widget-choice-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1836 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1837 (widget-value (car (widget-get widget :children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1838
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1839 (defun widget-choice-value-inline (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1840 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1841 (widget-apply (car (widget-get widget :children)) :value-inline))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1842
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1843 (defcustom widget-choice-toggle nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1844 "If non-nil, a binary choice will just toggle between the values.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1845 Otherwise, the user will explicitly have to choose between the values
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1846 when he invoked the menu."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1847 :type 'boolean
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1848 :group 'widgets)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1849
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1850 (defun widget-choice-mouse-down-action (widget &optional event)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1851 ;; Return non-nil if we need a menu.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1852 (let ((args (widget-get widget :args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1853 (old (widget-get widget :choice)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1854 (cond ((not window-system)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1855 ;; No place to pop up a menu.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1856 nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1857 ((not (or (fboundp 'x-popup-menu) (fboundp 'popup-menu)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1858 ;; No way to pop up a menu.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1859 nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1860 ((< (length args) 2)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1861 ;; Empty or singleton list, just return the value.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1862 nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1863 ((> (length args) widget-menu-max-size)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1864 ;; Too long, prompt.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1865 nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1866 ((> (length args) 2)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1867 ;; Reasonable sized list, use menu.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1868 t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1869 ((and widget-choice-toggle (memq old args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1870 ;; We toggle.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1871 nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1872 (t
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1873 ;; Ask which of the two.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1874 t))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1875
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1876 (defun widget-choice-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1877 ;; Make a choice.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1878 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1879 (old (widget-get widget :choice))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1880 (tag (widget-apply widget :menu-tag-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1881 (completion-ignore-case (widget-get widget :case-fold))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1882 current choices)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1883 ;; Remember old value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1884 (if (and old (not (widget-apply widget :validate)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1885 (let* ((external (widget-value widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1886 (internal (widget-apply old :value-to-internal external)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1887 (widget-put old :value internal)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1888 ;; Find new choice.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1889 (setq current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1890 (cond ((= (length args) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1891 nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1892 ((= (length args) 1)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1893 (nth 0 args))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1894 ((and widget-choice-toggle
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1895 (= (length args) 2)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1896 (memq old args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1897 (if (eq old (nth 0 args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1898 (nth 1 args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1899 (nth 0 args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1900 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1901 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1902 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1903 args (cdr args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1904 (setq choices
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1905 (cons (cons (widget-apply current :menu-tag-get)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1906 current)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1907 choices)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1908 (widget-choose tag (reverse choices) event))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1909 (when current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1910 (widget-value-set widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1911 (widget-apply current :value-to-external
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1912 (widget-get current :value)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1913 (widget-setup)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1914 (widget-apply widget :notify widget event))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1915
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1916 (defun widget-choice-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1917 ;; Valid if we have made a valid choice.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1918 (let ((void (widget-get widget :void))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1919 (choice (widget-get widget :choice))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1920 (child (car (widget-get widget :children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1921 (if (eq void choice)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1922 widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1923 (widget-apply child :validate))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1924
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1925 (defun widget-choice-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1926 ;; Matches if one of the choices matches.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1927 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1928 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1929 (while (and args (not found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1930 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1931 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1932 found (widget-apply current :match value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1933 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1934
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1935 (defun widget-choice-match-inline (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1936 ;; Matches if one of the choices matches.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1937 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1938 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1939 (while (and args (null found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1940 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1941 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1942 found (widget-match-inline current values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1943 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1944
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1945 ;;; The `toggle' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1946
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1947 (define-widget 'toggle 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1948 "Toggle between two states."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1949 :format "%[%v%]\n"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1950 :value-create 'widget-toggle-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1951 :action 'widget-toggle-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1952 :match (lambda (widget value) t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1953 :on "on"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1954 :off "off")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1955
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1956 (defun widget-toggle-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1957 ;; Insert text representing the `on' and `off' states.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1958 (if (widget-value widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1959 (widget-glyph-insert widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1960 (widget-get widget :on)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1961 (widget-get widget :on-glyph))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1962 (widget-glyph-insert widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1963 (widget-get widget :off)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1964 (widget-get widget :off-glyph))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1965
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1966 (defun widget-toggle-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1967 ;; Toggle value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1968 (widget-value-set widget (not (widget-value widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1969 (widget-apply widget :notify widget event))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
1970
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1971 ;;; The `checkbox' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1972
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1973 (define-widget 'checkbox 'toggle
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1974 "A checkbox toggle."
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1975 :button-suffix ""
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1976 :button-prefix ""
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1977 :format "%[%v%]"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1978 :on "[X]"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1979 :on-glyph "check1"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1980 :off "[ ]"
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1981 :off-glyph "check0"
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1982 :action 'widget-checkbox-action)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1983
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1984 (defun widget-checkbox-action (widget &optional event)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1985 "Toggle checkbox, notify parent, and set active state of sibling."
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1986 (widget-toggle-action widget event)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1987 (let ((sibling (widget-get-sibling widget)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1988 (when sibling
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1989 (if (widget-value widget)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1990 (widget-apply sibling :activate)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
1991 (widget-apply sibling :deactivate)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1992
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1993 ;;; The `checklist' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1994
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1995 (define-widget 'checklist 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1996 "A multiple choice widget."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1997 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1998 :format "%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1999 :offset 4
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2000 :entry-format "%b %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2001 :menu-tag "checklist"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2002 :greedy nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2003 :value-create 'widget-checklist-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2004 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2005 :value-get 'widget-checklist-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2006 :validate 'widget-checklist-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2007 :match 'widget-checklist-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2008 :match-inline 'widget-checklist-match-inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2009
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2010 (defun widget-checklist-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2011 ;; Insert all values
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2012 (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2013 (args (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2014 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2015 (widget-checklist-add-item widget (car args) (assq (car args) alist))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2016 (setq args (cdr args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2017 (widget-put widget :children (nreverse (widget-get widget :children)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2018
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2019 (defun widget-checklist-add-item (widget type chosen)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2020 ;; Create checklist item in WIDGET of type TYPE.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2021 ;; If the item is checked, CHOSEN is a cons whose cdr is the value.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2022 (and (eq (preceding-char) ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2023 (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2024 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2025 (widget-specify-insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2026 (let* ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2027 (buttons (widget-get widget :buttons))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2028 (button-args (or (widget-get type :sibling-args)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2029 (widget-get widget :button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2030 (from (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2031 child button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2032 (insert (widget-get widget :entry-format))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2033 (goto-char from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2034 ;; Parse % escapes in format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2035 (while (re-search-forward "%\\([bv%]\\)" nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2036 (let ((escape (aref (match-string 1) 0)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2037 (replace-match "" t t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2038 (cond ((eq escape ?%)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2039 (insert "%"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2040 ((eq escape ?b)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2041 (setq button (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2042 widget 'checkbox
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2043 :value (not (null chosen))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2044 button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2045 ((eq escape ?v)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2046 (setq child
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2047 (cond ((not chosen)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2048 (let ((child (widget-create-child widget type)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2049 (widget-apply child :deactivate)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2050 child))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2051 ((widget-get type :inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2052 (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2053 widget type (cdr chosen)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2054 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2055 (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2056 widget type (car (cdr chosen)))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2057 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2058 (error "Unknown escape `%c'" escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2059 ;; Update properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2060 (and button child (widget-put child :button button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2061 (and button (widget-put widget :buttons (cons button buttons)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2062 (and child (widget-put widget :children (cons child children))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2063
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2064 (defun widget-checklist-match (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2065 ;; All values must match a type in the checklist.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2066 (and (listp values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2067 (null (cdr (widget-checklist-match-inline widget values)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2068
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2069 (defun widget-checklist-match-inline (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2070 ;; Find the values which match a type in the checklist.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2071 (let ((greedy (widget-get widget :greedy))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2072 (args (copy-sequence (widget-get widget :args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2073 found rest)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2074 (while values
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2075 (let ((answer (widget-checklist-match-up args values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2076 (cond (answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2077 (let ((vals (widget-match-inline answer values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2078 (setq found (append found (car vals))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2079 values (cdr vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2080 args (delq answer args))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2081 (greedy
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2082 (setq rest (append rest (list (car values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2083 values (cdr values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2084 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2085 (setq rest (append rest values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2086 values nil)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2087 (cons found rest)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2088
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2089 (defun widget-checklist-match-find (widget vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2090 ;; Find the vals which match a type in the checklist.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2091 ;; Return an alist of (TYPE MATCH).
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2092 (let ((greedy (widget-get widget :greedy))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2093 (args (copy-sequence (widget-get widget :args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2094 found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2095 (while vals
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2096 (let ((answer (widget-checklist-match-up args vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2097 (cond (answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2098 (let ((match (widget-match-inline answer vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2099 (setq found (cons (cons answer (car match)) found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2100 vals (cdr match)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2101 args (delq answer args))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2102 (greedy
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2103 (setq vals (cdr vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2104 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2105 (setq vals nil)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2106 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2107
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2108 (defun widget-checklist-match-up (args vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2109 ;; Rerturn the first type from ARGS that matches VALS.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2110 (let (current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2111 (while (and args (null found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2112 (setq current (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2113 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2114 found (widget-match-inline current vals)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2115 (if found
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2116 current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2117 nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2118
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2119 (defun widget-checklist-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2120 ;; The values of all selected items.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2121 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2122 child result)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2123 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2124 (setq child (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2125 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2126 (if (widget-value (widget-get child :button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2127 (setq result (append result (widget-apply child :value-inline)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2128 result))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2129
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2130 (defun widget-checklist-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2131 ;; Ticked chilren must be valid.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2132 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2133 child button found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2134 (while (and children (not found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2135 (setq child (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2136 children (cdr children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2137 button (widget-get child :button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2138 found (and (widget-value button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2139 (widget-apply child :validate))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2140 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2141
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2142 ;;; The `option' Widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2143
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2144 (define-widget 'option 'checklist
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2145 "An widget with an optional item."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2146 :inline t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2147
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2148 ;;; The `choice-item' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2149
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2150 (define-widget 'choice-item 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2151 "Button items that delegate action events to their parents."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2152 :action 'widget-parent-action
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2153 :format "%[%t%] \n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2154
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2155 ;;; The `radio-button' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2156
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2157 (define-widget 'radio-button 'toggle
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2158 "A radio button for use in the `radio' widget."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2159 :notify 'widget-radio-button-notify
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2160 :format "%[%v%]"
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
2161 :button-suffix ""
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
2162 :button-prefix ""
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2163 :on "(*)"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2164 :on-glyph "radio1"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2165 :off "( )"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2166 :off-glyph "radio0")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2167
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2168 (defun widget-radio-button-notify (widget child &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2169 ;; Tell daddy.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2170 (widget-apply (widget-get widget :parent) :action widget event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2171
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2172 ;;; The `radio-button-choice' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2173
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2174 (define-widget 'radio-button-choice 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2175 "Select one of multiple options."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2176 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2177 :offset 4
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2178 :format "%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2179 :entry-format "%b %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2180 :menu-tag "radio"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2181 :value-create 'widget-radio-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2182 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2183 :value-get 'widget-radio-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2184 :value-inline 'widget-radio-value-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2185 :value-set 'widget-radio-value-set
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2186 :error "You must push one of the buttons"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2187 :validate 'widget-radio-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2188 :match 'widget-choice-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2189 :match-inline 'widget-choice-match-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2190 :action 'widget-radio-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2191
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2192 (defun widget-radio-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2193 ;; Insert all values
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2194 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2195 arg)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2196 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2197 (setq arg (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2198 args (cdr args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2199 (widget-radio-add-item widget arg))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2200
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2201 (defun widget-radio-add-item (widget type)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2202 "Add to radio widget WIDGET a new radio button item of type TYPE."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2203 ;; (setq type (widget-convert type))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2204 (and (eq (preceding-char) ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2205 (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2206 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2207 (widget-specify-insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2208 (let* ((value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2209 (children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2210 (buttons (widget-get widget :buttons))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2211 (button-args (or (widget-get type :sibling-args)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2212 (widget-get widget :button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2213 (from (point))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2214 (chosen (and (null (widget-get widget :choice))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2215 (widget-apply type :match value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2216 child button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2217 (insert (widget-get widget :entry-format))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2218 (goto-char from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2219 ;; Parse % escapes in format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2220 (while (re-search-forward "%\\([bv%]\\)" nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2221 (let ((escape (aref (match-string 1) 0)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2222 (replace-match "" t t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2223 (cond ((eq escape ?%)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2224 (insert "%"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2225 ((eq escape ?b)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2226 (setq button (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2227 widget 'radio-button
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2228 :value (not (null chosen))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2229 button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2230 ((eq escape ?v)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2231 (setq child (if chosen
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2232 (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2233 widget type value)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2234 (widget-create-child widget type)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2235 (unless chosen
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2236 (widget-apply child :deactivate)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2237 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2238 (error "Unknown escape `%c'" escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2239 ;; Update properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2240 (when chosen
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2241 (widget-put widget :choice type))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2242 (when button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2243 (widget-put child :button button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2244 (widget-put widget :buttons (nconc buttons (list button))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2245 (when child
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2246 (widget-put widget :children (nconc children (list child))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2247 child)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2248
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2249 (defun widget-radio-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2250 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2251 (let ((chosen (widget-radio-chosen widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2252 (and chosen (widget-value chosen))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2253
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2254 (defun widget-radio-chosen (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2255 "Return the widget representing the chosen radio button."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2256 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2257 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2258 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2259 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2260 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2261 (let* ((button (widget-get current :button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2262 (value (widget-apply button :value-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2263 (when value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2264 (setq found current
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2265 children nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2266 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2267
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2268 (defun widget-radio-value-inline (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2269 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2270 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2271 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2272 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2273 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2274 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2275 (let* ((button (widget-get current :button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2276 (value (widget-apply button :value-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2277 (when value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2278 (setq found (widget-apply current :value-inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2279 children nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2280 found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2281
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2282 (defun widget-radio-value-set (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2283 ;; We can't just delete and recreate a radio widget, since children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2284 ;; can be added after the original creation and won't be recreated
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2285 ;; by `:create'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2286 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2287 current found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2288 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2289 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2290 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2291 (let* ((button (widget-get current :button))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2292 (match (and (not found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2293 (widget-apply current :match value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2294 (widget-value-set button match)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2295 (if match
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2296 (progn
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2297 (widget-value-set current value)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2298 (widget-apply current :activate))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2299 (widget-apply current :deactivate))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2300 (setq found (or found match))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2301
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2302 (defun widget-radio-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2303 ;; Valid if we have made a valid choice.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2304 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2305 current found button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2306 (while (and children (not found))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2307 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2308 children (cdr children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2309 button (widget-get current :button)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2310 found (widget-apply button :value-get)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2311 (if found
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2312 (widget-apply current :validate)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2313 widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2314
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2315 (defun widget-radio-action (widget child event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2316 ;; Check if a radio button was pressed.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2317 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2318 (buttons (widget-get widget :buttons))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2319 current)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2320 (when (memq child buttons)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2321 (while children
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2322 (setq current (car children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2323 children (cdr children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2324 (let* ((button (widget-get current :button)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2325 (cond ((eq child button)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2326 (widget-value-set button t)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2327 (widget-apply current :activate))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2328 ((widget-value button)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2329 (widget-value-set button nil)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 36
diff changeset
2330 (widget-apply current :deactivate)))))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2331 ;; Pass notification to parent.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2332 (widget-apply widget :notify child event))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2333
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2334 ;;; The `insert-button' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2335
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2336 (define-widget 'insert-button 'push-button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2337 "An insert button for the `editable-list' widget."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2338 :tag "INS"
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2339 :help-echo "Insert a new item into the list at this position."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2340 :action 'widget-insert-button-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2341
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2342 (defun widget-insert-button-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2343 ;; Ask the parent to insert a new item.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2344 (widget-apply (widget-get widget :parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2345 :insert-before (widget-get widget :widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2346
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2347 ;;; The `delete-button' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2348
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2349 (define-widget 'delete-button 'push-button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2350 "A delete button for the `editable-list' widget."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2351 :tag "DEL"
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2352 :help-echo "Delete this item from the list."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2353 :action 'widget-delete-button-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2354
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2355 (defun widget-delete-button-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2356 ;; Ask the parent to insert a new item.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2357 (widget-apply (widget-get widget :parent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2358 :delete-at (widget-get widget :widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2359
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2360 ;;; The `editable-list' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2361
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2362 (defcustom widget-editable-list-gui nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2363 "If non nil, use GUI push-buttons in editable list when available."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2364 :type 'boolean
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2365 :group 'widgets)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2366
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2367 (define-widget 'editable-list 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2368 "A variable list of widgets of the same type."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2369 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2370 :offset 12
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2371 :format "%v%i\n"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2372 :format-handler 'widget-editable-list-format-handler
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2373 :entry-format "%i %d %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2374 :menu-tag "editable-list"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2375 :value-create 'widget-editable-list-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2376 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2377 :value-get 'widget-editable-list-value-get
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2378 :validate 'widget-children-validate
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2379 :match 'widget-editable-list-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2380 :match-inline 'widget-editable-list-match-inline
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2381 :insert-before 'widget-editable-list-insert-before
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2382 :delete-at 'widget-editable-list-delete-at)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2383
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2384 (defun widget-editable-list-format-handler (widget escape)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2385 ;; We recognize the insert button.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2386 (let ((widget-push-button-gui widget-editable-list-gui))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2387 (cond ((eq escape ?i)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2388 (and (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2389 (insert-char ? (widget-get widget :indent)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2390 (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2391 widget 'insert-button
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2392 (widget-get widget :append-button-args)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2393 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2394 (widget-default-format-handler widget escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2395
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2396 (defun widget-editable-list-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2397 ;; Insert all values
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2398 (let* ((value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2399 (type (nth 0 (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2400 (inlinep (widget-get type :inline))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2401 children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2402 (widget-put widget :value-pos (copy-marker (point)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2403 (set-marker-insertion-type (widget-get widget :value-pos) t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2404 (while value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2405 (let ((answer (widget-match-inline type value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2406 (if answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2407 (setq children (cons (widget-editable-list-entry-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2408 widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2409 (if inlinep
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2410 (car answer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2411 (car (car answer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2412 t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2413 children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2414 value (cdr answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2415 (setq value nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2416 (widget-put widget :children (nreverse children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2417
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2418 (defun widget-editable-list-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2419 ;; Get value of the child widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2420 (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2421 (widget-get widget :children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2422
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2423 (defun widget-editable-list-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2424 ;; Value must be a list and all the members must match the type.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2425 (and (listp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2426 (null (cdr (widget-editable-list-match-inline widget value)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2427
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2428 (defun widget-editable-list-match-inline (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2429 (let ((type (nth 0 (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2430 (ok t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2431 found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2432 (while (and value ok)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2433 (let ((answer (widget-match-inline type value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2434 (if answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2435 (setq found (append found (car answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2436 value (cdr answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2437 (setq ok nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2438 (cons found value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2439
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2440 (defun widget-editable-list-insert-before (widget before)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2441 ;; Insert a new child in the list of children.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2442 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2443 (let ((children (widget-get widget :children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2444 (inhibit-read-only t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2445 before-change-functions
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2446 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2447 (cond (before
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2448 (goto-char (widget-get before :entry-from)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2449 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2450 (goto-char (widget-get widget :value-pos))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2451 (let ((child (widget-editable-list-entry-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2452 widget nil nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2453 (when (< (widget-get child :entry-from) (widget-get widget :from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2454 (set-marker (widget-get widget :from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2455 (widget-get child :entry-from)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2456 (widget-specify-text (widget-get child :entry-from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2457 (widget-get child :entry-to))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2458 (if (eq (car children) before)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2459 (widget-put widget :children (cons child children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2460 (while (not (eq (car (cdr children)) before))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2461 (setq children (cdr children)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2462 (setcdr children (cons child (cdr children)))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2463 (widget-setup)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2464 (widget-apply widget :notify widget))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2465
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2466 (defun widget-editable-list-delete-at (widget child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2467 ;; Delete child from list of children.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2468 (save-excursion
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2469 (let ((buttons (copy-sequence (widget-get widget :buttons)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2470 button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2471 (inhibit-read-only t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2472 before-change-functions
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2473 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2474 (while buttons
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2475 (setq button (car buttons)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2476 buttons (cdr buttons))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2477 (when (eq (widget-get button :widget) child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2478 (widget-put widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2479 :buttons (delq button (widget-get widget :buttons)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2480 (widget-delete button))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2481 (let ((entry-from (widget-get child :entry-from))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2482 (entry-to (widget-get child :entry-to))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2483 (inhibit-read-only t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2484 before-change-functions
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2485 after-change-functions)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2486 (widget-delete child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2487 (delete-region entry-from entry-to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2488 (set-marker entry-from nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2489 (set-marker entry-to nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2490 (widget-put widget :children (delq child (widget-get widget :children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2491 (widget-setup)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2492 (widget-apply widget :notify widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2493
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2494 (defun widget-editable-list-entry-create (widget value conv)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2495 ;; Create a new entry to the list.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2496 (let ((type (nth 0 (widget-get widget :args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2497 (widget-push-button-gui widget-editable-list-gui)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2498 child delete insert)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2499 (widget-specify-insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2500 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2501 (and (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2502 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2503 (insert (widget-get widget :entry-format)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2504 ;; Parse % escapes in format.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2505 (while (re-search-forward "%\\(.\\)" nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2506 (let ((escape (aref (match-string 1) 0)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2507 (replace-match "" t t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2508 (cond ((eq escape ?%)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2509 (insert "%"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2510 ((eq escape ?i)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2511 (setq insert (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2512 widget 'insert-button
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2513 (widget-get widget :insert-button-args))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2514 ((eq escape ?d)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2515 (setq delete (apply 'widget-create-child-and-convert
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2516 widget 'delete-button
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2517 (widget-get widget :delete-button-args))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2518 ((eq escape ?v)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2519 (if conv
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2520 (setq child (widget-create-child-value
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2521 widget type value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2522 (setq child (widget-create-child widget type))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2523 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2524 (error "Unknown escape `%c'" escape)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2525 (widget-put widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2526 :buttons (cons delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2527 (cons insert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2528 (widget-get widget :buttons))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2529 (let ((entry-from (copy-marker (point-min)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2530 (entry-to (copy-marker (point-max))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2531 (widget-specify-text entry-from entry-to)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2532 (set-marker-insertion-type entry-from t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2533 (set-marker-insertion-type entry-to nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2534 (widget-put child :entry-from entry-from)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2535 (widget-put child :entry-to entry-to)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2536 (widget-put insert :widget child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2537 (widget-put delete :widget child)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2538 child))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2539
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2540 ;;; The `group' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2541
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2542 (define-widget 'group 'default
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2543 "A widget which group other widgets inside."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2544 :convert-widget 'widget-types-convert-widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2545 :format "%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2546 :value-create 'widget-group-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2547 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2548 :value-get 'widget-editable-list-value-get
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2549 :validate 'widget-children-validate
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2550 :match 'widget-group-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2551 :match-inline 'widget-group-match-inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2552
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2553 (defun widget-group-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2554 ;; Create each component.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2555 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2556 (value (widget-get widget :value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2557 arg answer children)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2558 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2559 (setq arg (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2560 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2561 answer (widget-match-inline arg value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2562 value (cdr answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2563 (and (eq (preceding-char) ?\n)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2564 (widget-get widget :indent)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2565 (insert-char ? (widget-get widget :indent)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2566 (push (cond ((null answer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2567 (widget-create-child widget arg))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2568 ((widget-get arg :inline)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2569 (widget-create-child-value widget arg (car answer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2570 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2571 (widget-create-child-value widget arg (car (car answer)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2572 children))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2573 (widget-put widget :children (nreverse children))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2574
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2575 (defun widget-group-match (widget values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2576 ;; Match if the components match.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2577 (and (listp values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2578 (let ((match (widget-group-match-inline widget values)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2579 (and match (null (cdr match))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2580
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2581 (defun widget-group-match-inline (widget vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2582 ;; Match if the components match.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2583 (let ((args (widget-get widget :args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2584 argument answer found)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2585 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2586 (setq argument (car args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2587 args (cdr args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2588 answer (widget-match-inline argument vals))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2589 (if answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2590 (setq vals (cdr answer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2591 found (append found (car answer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2592 (setq vals nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2593 args nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2594 (if answer
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2595 (cons found vals)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2596 nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2597
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2598 ;;; The `visibility' Widget.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2599
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2600 (define-widget 'visibility 'item
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2601 "An indicator and manipulator for hidden items."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2602 :format "%[%v%]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2603 :button-prefix ""
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2604 :button-suffix ""
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2605 :on "Hide"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2606 :off "Show"
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2607 :value-create 'widget-visibility-value-create
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2608 :action 'widget-toggle-action
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2609 :match (lambda (widget value) t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2610
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2611 (defun widget-visibility-value-create (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2612 ;; Insert text representing the `on' and `off' states.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2613 (let ((on (widget-get widget :on))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2614 (off (widget-get widget :off)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2615 (if on
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2616 (setq on (concat widget-push-button-prefix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2617 on
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2618 widget-push-button-suffix))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2619 (setq on ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2620 (if off
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2621 (setq off (concat widget-push-button-prefix
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2622 off
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2623 widget-push-button-suffix))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2624 (setq off ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2625 (if (widget-value widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2626 (widget-glyph-insert widget on "down" "down-pushed")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2627 (widget-glyph-insert widget off "right" "right-pushed"))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2628
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2629 ;;; The `documentation-link' Widget.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2630 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2631 ;; This is a helper widget for `documentation-string'.
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2632
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2633 (define-widget 'documentation-link 'link
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2634 "Link type used in documentation strings."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2635 :tab-order -1
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2636 :help-echo 'widget-documentation-link-echo-help
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2637 :action 'widget-documentation-link-action)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2638
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2639 (defun widget-documentation-link-echo-help (widget)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2640 "Tell what this link will describe."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2641 (concat "Describe the `" (widget-get widget :value) "' symbol."))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2642
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2643 (defun widget-documentation-link-action (widget &optional event)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2644 "Run apropos on WIDGET's value. Ignore optional argument EVENT."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2645 (apropos (concat "\\`" (regexp-quote (widget-get widget :value)) "\\'")))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2646
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2647 (defcustom widget-documentation-links t
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2648 "Add hyperlinks to documentation strings when non-nil."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2649 :type 'boolean
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2650 :group 'widget-documentation)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2651
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2652 (defcustom widget-documentation-link-regexp "`\\([^\n`' ]+\\)'"
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2653 "Regexp for matching potential links in documentation strings.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2654 The first group should be the link itself."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2655 :type 'regexp
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2656 :group 'widget-documentation)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2657
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2658 (defcustom widget-documentation-link-p 'intern-soft
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2659 "Predicate used to test if a string is useful as a link.
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2660 The value should be a function. The function will be called one
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2661 argument, a string, and should return non-nil if there should be a
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2662 link for that string."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2663 :type 'function
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2664 :options '(widget-documentation-link-p)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2665 :group 'widget-documentation)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2666
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2667 (defcustom widget-documentation-link-type 'documentation-link
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2668 "Widget type used for links in documentation strings."
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2669 :type 'symbol
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2670 :group 'widget-documentation)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2671
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2672 (defun widget-documentation-link-add (widget from to)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2673 (widget-specify-doc widget from to)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2674 (when widget-documentation-links
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2675 (let ((regexp widget-documentation-link-regexp)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2676 (predicate widget-documentation-link-p)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2677 (type widget-documentation-link-type)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2678 (buttons (widget-get widget :buttons)))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2679 (save-excursion
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2680 (goto-char from)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2681 (while (re-search-forward regexp to t)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2682 (let ((name (match-string 1))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2683 (begin (match-beginning 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2684 (end (match-end 1)))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2685 (when (funcall predicate name)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2686 (push (widget-convert-button type begin end :value name)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2687 buttons)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2688 (widget-put widget :buttons buttons)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2689 (let ((indent (widget-get widget :indent)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2690 (when (and indent (not (zerop indent)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2691 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2692 (save-restriction
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2693 (narrow-to-region from to)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2694 (goto-char (point-min))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2695 (while (search-forward "\n" nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2696 (insert-char ?\ indent)))))))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2697
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2698 ;;; The `documentation-string' Widget.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2699
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2700 (define-widget 'documentation-string 'item
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2701 "A documentation string."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2702 :format "%v"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2703 :action 'widget-documentation-string-action
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2704 :value-delete 'widget-children-value-delete
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2705 :value-create 'widget-documentation-string-value-create)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2706
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2707 (defun widget-documentation-string-value-create (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2708 ;; Insert documentation string.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2709 (let ((doc (widget-value widget))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2710 (indent (widget-get widget :indent))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2711 (shown (widget-get (widget-get widget :parent) :documentation-shown))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2712 (start (point)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2713 (if (string-match "\n" doc)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2714 (let ((before (substring doc 0 (match-beginning 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2715 (after (substring doc (match-beginning 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2716 buttons)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2717 (insert before " ")
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2718 (widget-documentation-link-add widget start (point))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2719 (push (widget-create-child-and-convert
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2720 widget 'visibility
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2721 :help-echo "Show or hide rest of the documentation."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2722 :off "More"
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2723 :action 'widget-parent-action
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2724 shown)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2725 buttons)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2726 (when shown
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2727 (setq start (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2728 (when (and indent (not (zerop indent)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
2729 (insert-char ?\ indent))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2730 (insert after)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2731 (widget-documentation-link-add widget start (point)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2732 (widget-put widget :buttons buttons))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2733 (insert doc)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2734 (widget-documentation-link-add widget start (point))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2735 (insert "\n"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2736
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2737 (defun widget-documentation-string-action (widget &rest ignore)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2738 ;; Toggle documentation.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2739 (let ((parent (widget-get widget :parent)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2740 (widget-put parent :documentation-shown
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2741 (not (widget-get parent :documentation-shown))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2742 ;; Redraw.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2743 (widget-value-set widget (widget-value widget)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2744
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2745 ;;; The Sexp Widgets.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2746
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2747 (define-widget 'const 'item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2748 "An immutable sexp."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2749 :prompt-value 'widget-const-prompt-value
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2750 :format "%t\n%d")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2751
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2752 (defun widget-const-prompt-value (widget prompt value unbound)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2753 ;; Return the value of the const.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2754 (widget-value widget))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2755
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2756 (define-widget 'function-item 'const
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2757 "An immutable function name."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2758 :format "%v\n%h"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2759 :documentation-property (lambda (symbol)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2760 (condition-case nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2761 (documentation symbol t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2762 (error nil))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2763
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2764 (define-widget 'variable-item 'const
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2765 "An immutable variable name."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2766 :format "%v\n%h"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2767 :documentation-property 'variable-documentation)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2768
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2769 (defvar widget-string-prompt-value-history nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2770 "History of input to `widget-string-prompt-value'.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2771
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2772 (define-widget 'string 'editable-field
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2773 "A string"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2774 :tag "String"
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2775 :format "%{%t%}: %v"
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2776 :complete-function 'ispell-complete-word
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2777 :prompt-history 'widget-string-prompt-value-history)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2778
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2779 (define-widget 'regexp 'string
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2780 "A regular expression."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2781 :match 'widget-regexp-match
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2782 :validate 'widget-regexp-validate
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2783 :tag "Regexp")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2784
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2785 (defun widget-regexp-match (widget value)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2786 ;; Match valid regexps.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2787 (and (stringp value)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2788 (condition-case nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2789 (prog1 t
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2790 (string-match value ""))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2791 (error nil))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2792
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2793 (defun widget-regexp-validate (widget)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2794 "Check that the value of WIDGET is a valid regexp."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2795 (let ((val (widget-value widget)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2796 (condition-case data
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2797 (prog1 nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2798 (string-match val ""))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2799 (error (widget-put widget :error (error-message-string data))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2800 widget))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2801
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2802 (define-widget 'file 'string
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2803 "A file widget.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2804 It will read a file name from the minibuffer when invoked."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2805 :prompt-value 'widget-file-prompt-value
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2806 :format "%{%t%}: %v"
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2807 :tag "File"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2808 :action 'widget-file-action)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2809
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2810 (defun widget-file-prompt-value (widget prompt value unbound)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2811 ;; Read file from minibuffer.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2812 (abbreviate-file-name
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2813 (if unbound
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2814 (read-file-name prompt)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2815 (let ((prompt2 (format "%s (default %s) " prompt value))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2816 (dir (file-name-directory value))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2817 (file (file-name-nondirectory value))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2818 (must-match (widget-get widget :must-match)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2819 (read-file-name prompt2 dir nil must-match file)))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2820
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2821 (defun widget-file-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2822 ;; Read a file name from the minibuffer.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2823 (let* ((value (widget-value widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2824 (dir (file-name-directory value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2825 (file (file-name-nondirectory value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2826 (menu-tag (widget-apply widget :menu-tag-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2827 (must-match (widget-get widget :must-match))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 34
diff changeset
2828 (answer (read-file-name (concat menu-tag ": (default `" value "') ")
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2829 dir nil must-match file)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2830 (widget-value-set widget (abbreviate-file-name answer))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2831 (widget-setup)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2832 (widget-apply widget :notify widget event)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2833
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2834 (define-widget 'directory 'file
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2835 "A directory widget.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2836 It will read a directory name from the minibuffer when invoked."
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2837 :tag "Directory")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2838
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2839 (defvar widget-symbol-prompt-value-history nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2840 "History of input to `widget-symbol-prompt-value'.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2841
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2842 (define-widget 'symbol 'editable-field
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2843 "A lisp symbol."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2844 :value nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2845 :tag "Symbol"
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2846 :format "%{%t%}: %v"
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2847 :match (lambda (widget value) (symbolp value))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2848 :prompt-internal 'widget-symbol-prompt-internal
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2849 :prompt-match 'symbolp
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2850 :prompt-history 'widget-symbol-prompt-value-history
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2851 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2852 (if (symbolp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2853 (symbol-name value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2854 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2855 :value-to-external (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2856 (if (stringp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2857 (intern value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2858 value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2859
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2860 (defun widget-symbol-prompt-internal (widget prompt initial history)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2861 ;; Read file from minibuffer.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2862 (let ((answer (completing-read prompt obarray
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2863 (widget-get widget :prompt-match)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2864 nil initial history)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2865 (if (and (stringp answer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2866 (not (zerop (length answer))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2867 answer
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2868 (error "No value"))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2869
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2870 (defvar widget-function-prompt-value-history nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2871 "History of input to `widget-function-prompt-value'.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2872
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2873 (define-widget 'function 'sexp
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2874 "A lisp function."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2875 :complete-function 'lisp-complete-symbol
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2876 :prompt-value 'widget-field-prompt-value
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2877 :prompt-internal 'widget-symbol-prompt-internal
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2878 :prompt-match 'fboundp
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2879 :prompt-history 'widget-function-prompt-value-history
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2880 :action 'widget-field-action
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2881 :tag "Function")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2882
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2883 (defvar widget-variable-prompt-value-history nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2884 "History of input to `widget-variable-prompt-value'.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2885
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2886 (define-widget 'variable 'symbol
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2887 ;; Should complete on variables.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2888 "A lisp variable."
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2889 :prompt-match 'boundp
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2890 :prompt-history 'widget-variable-prompt-value-history
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2891 :tag "Variable")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2892
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2893 (when (featurep 'mule)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2894 (defvar widget-coding-system-prompt-value-history nil
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2895 "History of input to `widget-coding-system-prompt-value'.")
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2896
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2897 (define-widget 'coding-system 'symbol
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2898 "A MULE coding-system."
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2899 :format "%{%t%}: %v"
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2900 :tag "Coding system"
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2901 :prompt-history 'widget-coding-system-prompt-value-history
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2902 :prompt-value 'widget-coding-system-prompt-value
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2903 :action 'widget-coding-system-action)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2904
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2905 (defun widget-coding-system-prompt-value (widget prompt value unbound)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2906 ;; Read coding-system from minibuffer.
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2907 (intern
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2908 (completing-read (format "%s (default %s) " prompt value)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2909 (mapcar (function
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2910 (lambda (sym)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2911 (list (symbol-name sym))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2912 ))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2913 (coding-system-list)))))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2914
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2915 (defun widget-coding-system-action (widget &optional event)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2916 ;; Read a file name from the minibuffer.
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2917 (let ((answer
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2918 (widget-coding-system-prompt-value
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2919 widget
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2920 (widget-apply widget :menu-tag-get)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2921 (widget-value widget)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2922 t)))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2923 (widget-value-set widget answer)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2924 (widget-apply widget :notify widget event)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2925 (widget-setup)))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2926 )
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 157
diff changeset
2927
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2928 (define-widget 'sexp 'editable-field
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2929 "An arbitrary lisp expression."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2930 :tag "Lisp expression"
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2931 :format "%{%t%}: %v"
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2932 :value nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2933 :validate 'widget-sexp-validate
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2934 :match (lambda (widget value) t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2935 :value-to-internal 'widget-sexp-value-to-internal
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2936 :value-to-external (lambda (widget value) (read value))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2937 :prompt-history 'widget-sexp-prompt-value-history
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2938 :prompt-value 'widget-sexp-prompt-value)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2939
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2940 (defun widget-sexp-value-to-internal (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2941 ;; Use pp for printer representation.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2942 (let ((pp (if (symbolp value)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2943 (prin1-to-string value)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2944 (pp-to-string value))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2945 (while (string-match "\n\\'" pp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2946 (setq pp (substring pp 0 -1)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2947 (if (or (string-match "\n\\'" pp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2948 (> (length pp) 40))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2949 (concat "\n" pp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2950 pp)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2951
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2952 (defun widget-sexp-validate (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2953 ;; Valid if we can read the string and there is no junk left after it.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2954 (save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2955 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2956 (erase-buffer)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2957 (insert (widget-apply widget :value-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2958 (goto-char (point-min))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2959 (condition-case data
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2960 (let ((value (read buffer)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2961 (if (eobp)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2962 (if (widget-apply widget :match value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2963 nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2964 (widget-put widget :error (widget-get widget :type-error))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2965 widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2966 (widget-put widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2967 :error (format "Junk at end of expression: %s"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2968 (buffer-substring (point)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2969 (point-max))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2970 widget))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2971 (error (widget-put widget :error (error-message-string data))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2972 widget)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2973
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2974 (defvar widget-sexp-prompt-value-history nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2975 "History of input to `widget-sexp-prompt-value'.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2976
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2977 (defun widget-sexp-prompt-value (widget prompt value unbound)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2978 ;; Read an arbitrary sexp.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2979 (let ((found (read-string prompt
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2980 (if unbound nil (cons (prin1-to-string value) 0))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2981 (widget-get widget :prompt-history))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2982 (save-excursion
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2983 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2984 (erase-buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2985 (insert found)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2986 (goto-char (point-min))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2987 (let ((answer (read buffer)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2988 (unless (eobp)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2989 (error "Junk at end of expression: %s"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2990 (buffer-substring (point) (point-max))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2991 answer)))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
2992
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2993 (define-widget 'integer 'sexp
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2994 "An integer."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2995 :tag "Integer"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2996 :value 0
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2997 :type-error "This field should contain an integer"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2998 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2999 (if (integerp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3000 (prin1-to-string value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3001 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3002 :match (lambda (widget value) (integerp value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3003
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3004 (define-widget 'character 'editable-field
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3005 "An character."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3006 :tag "Character"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3007 :value 0
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3008 :size 1
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3009 :format "%{%t%}: %v\n"
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3010 :valid-regexp "\\`.\\'"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3011 :error "This field should contain a single character"
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3012 :value-to-internal (lambda (widget value)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3013 (if (stringp value)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3014 value
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3015 (char-to-string value)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3016 :value-to-external (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3017 (if (stringp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3018 (aref value 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3019 value))
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3020 :match (lambda (widget value)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3021 (if (fboundp 'characterp)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3022 (characterp value)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3023 (integerp value))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3024
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3025 (define-widget 'number 'sexp
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3026 "A floating point number."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3027 :tag "Number"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3028 :value 0.0
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3029 :type-error "This field should contain a number"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3030 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3031 (if (numberp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3032 (prin1-to-string value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3033 value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3034 :match (lambda (widget value) (numberp value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3035
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3036 (define-widget 'list 'group
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3037 "A lisp list."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3038 :tag "List"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3039 :format "%{%t%}:\n%v")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3040
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3041 (define-widget 'vector 'group
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3042 "A lisp vector."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3043 :tag "Vector"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3044 :format "%{%t%}:\n%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3045 :match 'widget-vector-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3046 :value-to-internal (lambda (widget value) (append value nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3047 :value-to-external (lambda (widget value) (apply 'vector value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3048
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3049 (defun widget-vector-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3050 (and (vectorp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3051 (widget-group-match widget
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
3052 (widget-apply widget :value-to-internal value))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3053
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3054 (define-widget 'cons 'group
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3055 "A cons-cell."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3056 :tag "Cons-cell"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3057 :format "%{%t%}:\n%v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3058 :match 'widget-cons-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3059 :value-to-internal (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3060 (list (car value) (cdr value)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3061 :value-to-external (lambda (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3062 (cons (nth 0 value) (nth 1 value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3063
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3064 (defun widget-cons-match (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3065 (and (consp value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3066 (widget-group-match widget
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3067 (widget-apply widget :value-to-internal value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3068
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3069 (define-widget 'choice 'menu-choice
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3070 "A union of several sexp types."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3071 :tag "Choice"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
3072 :format "%{%t%}: %[Value Menu%] %v"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
3073 :button-prefix 'widget-push-button-prefix
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
3074 :button-suffix 'widget-push-button-suffix
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3075 :prompt-value 'widget-choice-prompt-value)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3076
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3077 (defun widget-choice-prompt-value (widget prompt value unbound)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3078 "Make a choice."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3079 (let ((args (widget-get widget :args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3080 (completion-ignore-case (widget-get widget :case-fold))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3081 current choices old)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3082 ;; Find the first arg that match VALUE.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3083 (let ((look args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3084 (while look
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3085 (if (widget-apply (car look) :match value)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3086 (setq old (car look)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3087 look nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3088 (setq look (cdr look)))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3089 ;; Find new choice.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3090 (setq current
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3091 (cond ((= (length args) 0)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3092 nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3093 ((= (length args) 1)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3094 (nth 0 args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3095 ((and (= (length args) 2)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3096 (memq old args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3097 (if (eq old (nth 0 args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3098 (nth 1 args)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3099 (nth 0 args)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3100 (t
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3101 (while args
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3102 (setq current (car args)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3103 args (cdr args))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3104 (setq choices
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3105 (cons (cons (widget-apply current :menu-tag-get)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3106 current)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3107 choices)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3108 (let ((val (completing-read prompt choices nil t)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3109 (if (stringp val)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3110 (let ((try (try-completion val choices)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3111 (when (stringp try)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3112 (setq val try))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3113 (cdr (assoc val choices)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3114 nil)))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3115 (if current
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3116 (widget-prompt-value current prompt nil t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3117 value)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3118
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3119 (define-widget 'radio 'radio-button-choice
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3120 "A union of several sexp types."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3121 :tag "Choice"
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3122 :format "%{%t%}:\n%v"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3123 :prompt-value 'widget-choice-prompt-value)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3124
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3125 (define-widget 'repeat 'editable-list
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3126 "A variable length homogeneous list."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3127 :tag "Repeat"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3128 :format "%{%t%}:\n%v%i\n")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3129
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3130 (define-widget 'set 'checklist
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3131 "A list of members from a fixed set."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3132 :tag "Set"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3133 :format "%{%t%}:\n%v")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3134
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3135 (define-widget 'boolean 'toggle
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3136 "To be nil or non-nil, that is the question."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3137 :tag "Boolean"
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3138 :prompt-value 'widget-boolean-prompt-value
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
3139 :button-prefix 'widget-push-button-prefix
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
3140 :button-suffix 'widget-push-button-suffix
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
3141 :format "%{%t%}: %[Toggle%] %v\n"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
3142 :on "on (non-nil)"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
3143 :off "off (nil)")
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3144
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3145 (defun widget-boolean-prompt-value (widget prompt value unbound)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3146 ;; Toggle a boolean.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3147 (y-or-n-p prompt))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3148
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3149 ;;; The `color' Widget.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3150
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3151 (define-widget 'color-item 'choice-item
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3152 "A color name (with sample)."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
3153 :format "%v (%{sample%})\n"
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
3154 :sample-face-get 'widget-color-item-button-face-get)
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3155
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3156 (defun widget-color-item-button-face-get (widget)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3157 (let ((symbol (intern (concat "fg:" (widget-value widget)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3158 (if (string-match "XEmacs" emacs-version)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3159 (prog1 symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3160 (or (find-face symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3161 (set-face-foreground (make-face symbol) (widget-value widget))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3162 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3163 (facemenu-get-face symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3164 (error 'default)))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3165
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3166 (define-widget 'color 'push-button
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3167 "Choose a color name (with sample)."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3168 :format "%[%t%]: %v"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3169 :tag "Color"
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
3170 :value "black"
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3171 :value-create 'widget-color-value-create
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3172 :value-delete 'widget-children-value-delete
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3173 :value-get 'widget-color-value-get
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3174 :value-set 'widget-color-value-set
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3175 :action 'widget-color-action
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3176 :match 'widget-field-match
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3177 :tag "Color")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3178
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3179 (defvar widget-color-choice-list nil)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3180 ;; Variable holding the possible colors.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3181
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3182 (defun widget-color-choice-list ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3183 (unless widget-color-choice-list
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3184 (setq widget-color-choice-list
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3185 (mapcar '(lambda (color) (list color))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3186 (x-defined-colors))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3187 widget-color-choice-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3188
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3189 (defun widget-color-value-create (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3190 (let ((child (widget-create-child-and-convert
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3191 widget 'color-item (widget-get widget :value))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3192 (widget-put widget :children (list child))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3193
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3194 (defun widget-color-value-get (widget)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3195 ;; Pass command to first child.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3196 (widget-apply (car (widget-get widget :children)) :value-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3197
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3198 (defun widget-color-value-set (widget value)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3199 ;; Pass command to first child.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3200 (widget-apply (car (widget-get widget :children)) :value-set value))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3201
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3202 (defvar widget-color-history nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3203 "History of entered colors")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3204
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3205 (defun widget-color-action (widget &optional event)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3206 ;; Prompt for a color.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3207 (let* ((tag (widget-apply widget :menu-tag-get))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3208 (prompt (concat tag ": "))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3209 (answer (cond ((string-match "XEmacs" emacs-version)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3210 (read-color prompt))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3211 ((fboundp 'x-defined-colors)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3212 (completing-read (concat tag ": ")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3213 (widget-color-choice-list)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3214 nil nil nil 'widget-color-history))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3215 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3216 (read-string prompt (widget-value widget))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3217 (unless (zerop (length answer))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3218 (widget-value-set widget answer)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3219 (widget-setup)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3220 (widget-apply widget :notify widget event))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3221
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3222 ;;; The Help Echo
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3223
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3224 (defun widget-echo-help-mouse ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3225 "Display the help message for the widget under the mouse.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3226 Enable with (run-with-idle-timer 1 t 'widget-echo-help-mouse)"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3227 (let* ((pos (mouse-position))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3228 (frame (car pos))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3229 (x (car (cdr pos)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3230 (y (cdr (cdr pos)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3231 (win (window-at x y frame))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3232 (where (coordinates-in-window-p (cons x y) win)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3233 (when (consp where)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3234 (save-window-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3235 (progn ; save-excursion
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3236 (select-window win)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3237 (let* ((result (compute-motion (window-start win)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3238 '(0 . 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3239 (window-end win)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3240 where
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3241 (window-width win)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3242 (cons (window-hscroll) 0)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3243 win)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3244 (when (and (eq (nth 1 result) x)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3245 (eq (nth 2 result) y))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3246 (widget-echo-help (nth 0 result))))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3247 (unless track-mouse
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3248 (setq track-mouse t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3249 (add-hook 'post-command-hook 'widget-stop-mouse-tracking)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3250
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3251 (defun widget-stop-mouse-tracking (&rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3252 "Stop the mouse tracking done while idle."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3253 (remove-hook 'post-command-hook 'widget-stop-mouse-tracking)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3254 (setq track-mouse nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3255
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3256 (defun widget-at (pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3257 "The button or field at POS."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3258 (or (get-char-property pos 'button)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3259 (get-char-property pos 'field)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3260
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3261 (defun widget-echo-help (pos)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3262 "Display the help echo for widget at POS."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3263 (let* ((widget (widget-at pos))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3264 (help-echo (and widget (widget-get widget :help-echo))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3265 (cond ((stringp help-echo)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3266 (message "%s" help-echo))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3267 ((and (symbolp help-echo) (fboundp help-echo)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3268 (stringp (setq help-echo (funcall help-echo widget))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3269 (message "%s" help-echo)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3270
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3271 ;;; The End:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3272
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3273 (provide 'wid-edit)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3274
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3275 ;; wid-edit.el ends here