annotate lisp/custom/wid-edit.el @ 153:25f70ba0133c r20-3b3

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