annotate lisp/wid-edit.el @ 724:76d5a3dd827a

[xemacs-hg @ 2002-01-05 07:33:11 by stephent] Pre-21.5.4 commit of stuff on notebook -- updated CHANGES-beta -- fix some slow startups - default with_ipv6_cname=no -- Stephen Turnbull -- Cygwin nox-xpm detection -- Charles Wilson -- eliminate bogus check for Athena widgets -- Alexey Mahotkin
author stephent
date Sat, 05 Jan 2002 07:33:24 +0000
parents 2cf5d151eeb9
children 79940b592197
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; wid-edit.el --- Functions for creating and using widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 ;;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
3 ;; Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: extensions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; Version: 1.9960-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; See `widget.el'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 (require 'widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 (autoload 'finder-commentary "finder" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;;; Customization.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 (defgroup widgets nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 "Customization support for the Widget Library."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 :link '(custom-manual "(widget)Top")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 :link '(url-link :tag "Development Page"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 "http://www.dina.kvl.dk/~abraham/custom/")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 :link '(emacs-library-link :tag "Lisp File" "widget.el")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 :prefix "widget-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 :group 'extensions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 :group 'hypermedia)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 (defgroup widget-documentation nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 "Options controlling the display of documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 (defgroup widget-faces nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 "Faces used by the widget library."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 :group 'faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 (defvar widget-documentation-face 'widget-documentation-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 "Face used for documentation strings in widges.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 This exists as a variable so it can be set locally in certain buffers.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 (defface widget-documentation-face '((((class color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 (:foreground "lime green"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (((class color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (:foreground "dark green"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 "Face used for documentation text."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 :group 'widget-documentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (defvar widget-button-face 'widget-button-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 "Face used for buttons in widges.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 This exists as a variable so it can be set locally in certain buffers.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (defface widget-button-face '((t (:bold t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 "Face used for widget buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (defcustom widget-mouse-face 'highlight
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 "Face used for widget buttons when the mouse is above them."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 :type 'face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (defface widget-field-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (:background "gray85"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (:background "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 "Face used for editable fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 ;; Currently unused
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ;(defface widget-single-line-field-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ; (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 ; (:background "gray85"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 ; (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 ; (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ; (:background "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 ; (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 ; (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ; "Face used for editable fields spanning only a single line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ; :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ;(defvar widget-single-line-display-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ; (let ((table (make-display-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ; (aset table 9 "^I")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ; (aset table 10 "^J")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ; table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ; "Display table used for single-line editable fields.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ;(set-face-display-table 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ; widget-single-line-display-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ;; Some functions from this file have been ported to C for speed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ;; Setting this to t (*before* loading wid-edit.el) will make them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ;; shadow the subrs. It should be used only for debugging purposes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (defvar widget-shadow-subrs nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 ;;; Utility functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 ;; These are not really widget specific.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 (when (or (not (fboundp 'widget-plist-member))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 ;; Recoded in C, for efficiency. It used to be a defsubst, but old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 ;; compiled code won't fail -- it will just be slower.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (defun widget-plist-member (plist prop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ;; Return non-nil if PLIST has the property PROP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ;; PLIST is a property list, which is a list of the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 ;; (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 ;; Unlike `plist-get', this allows you to distinguish between a missing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 ;; property and a property with the value nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 ;; The value is actually the tail of PLIST whose car is PROP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (while (and plist (not (eq (car plist) prop)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (setq plist (cddr plist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 (defun widget-princ-to-string (object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 ;; Return string representation of OBJECT, any Lisp object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 ;; No quoting characters are used; no delimiters are printed around
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 ;; the contents of strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (with-current-buffer (get-buffer-create " *widget-tmp*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (princ object (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (buffer-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (defun widget-prettyprint-to-string (object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ;; Like pp-to-string, but uses `cl-prettyprint'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (with-current-buffer (get-buffer-create " *widget-tmp*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (cl-prettyprint object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 ;; `cl-prettyprint' always surrounds the text with newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (when (eq (char-after (point-min)) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (delete-region (point-min) (1+ (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (when (eq (char-before (point-max)) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (delete-region (1- (point-max)) (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (buffer-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (defun widget-clear-undo ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 "Clear all undo information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (buffer-disable-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (buffer-enable-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (defcustom widget-menu-max-size 40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 "Largest number of items allowed in a popup-menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 Larger menus are read through the minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 :type 'integer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (defcustom widget-menu-minibuffer-flag nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 "*Control how to ask for a choice from the keyboard.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 Non-nil means use the minibuffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 nil means read a single character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (defun widget-choose (title items &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 "Choose an item from a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 First argument TITLE is the name of the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 Second argument ITEMS is an list whose members are either
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (NAME . VALUE), to indicate selectable items, or just strings to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 indicate unselectable items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 Optional third argument EVENT is an input event.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 The user is asked to choose between each NAME from the items alist,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 and the VALUE of the chosen element will be returned. If EVENT is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 mouse event, and the number of elements in items is less than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 `widget-menu-max-size', a popup menu will be used, otherwise the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (cond ((and (< (length items) widget-menu-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 ;; Pressed by the mouse.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (let ((val (get-popup-menu-response
724
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
205 (let ((menu-thingee
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (cons title
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (mapcar (lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (if (stringp x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (vector x nil nil)
724
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
210 (vector (car x)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
211 (list (car x)) ; 'eval 'quote
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
212 t)))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
213 items))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
214 ))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
215 (message "%s" menu-thingee)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
216 menu-thingee)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
217 )))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (setq val (and val
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (listp (event-object val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (stringp (car-safe (event-object val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (car (event-object val))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (cdr (assoc val items))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 ((and (not widget-menu-minibuffer-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 ;; Can't handle more than 10 items (as many digits)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (<= (length items) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 ;; Construct a menu of the choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ;; and then use it for prompting for a single character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (let* ((overriding-terminal-local-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (map (make-sparse-keymap title))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (next-digit ?0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 some-choice-enabled value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 ;; Define SPC as a prefix char to get to this menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (define-key overriding-terminal-local-map " " map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (with-current-buffer (get-buffer-create " widget-choose")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (insert "Available choices:\n\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (dolist (choice items)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (when (consp choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (let* ((name (car choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (function (cdr choice)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (insert (format "%c = %s\n" next-digit name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (define-key map (vector next-digit) function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (setq some-choice-enabled t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 ;; Allocate digits to disabled alternatives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 ;; so that the digit of a given alternative never varies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (incf next-digit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (insert "\nC-g = Quit"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (or some-choice-enabled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (error "None of the choices is currently meaningful"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (define-key map [?\C-g] 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (define-key map [t] 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 ;(setcdr map (nreverse (cdr map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ;; Unread a SPC to lead to our new menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (push (character-to-event ?\ ) unread-command-events)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 ;; Read a char with the menu, and return the result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 ;; that corresponds to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (save-window-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (display-buffer (get-buffer " widget-choose"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (let ((cursor-in-echo-area t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (setq value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (lookup-key overriding-terminal-local-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (read-key-sequence (concat title ": ") t)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (message "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (when (or (eq value 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (null value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (error "Canceled"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 ;; Read the choice of name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (setq items (remove-if 'stringp items))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (let ((val (completing-read (concat title ": ") items nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (if (stringp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (let ((try (try-completion val items)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (when (stringp try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (setq val try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (cdr (assoc val items)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 ;;; Widget text specifications.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 ;; These functions are for specifying text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (defcustom widget-field-add-space t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 ;; Setting this to nil might be available, once some problems are resolved.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 "Non-nil means add extra space at the end of editable text fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 This is needed on all versions of Emacs. If you don't add the space,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 it will become impossible to edit a zero size field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (defcustom widget-field-use-before-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (and (or (> emacs-minor-version 34)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (> emacs-major-version 19))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (not (string-match "XEmacs" emacs-version)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 "Non-nil means use `before-change-functions' to track editable fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 This enables the use of undo, but doesn't work on Emacs 19.34 and earlier.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 Using before hooks also means that the :notify function can't know the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 new value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (defun widget-echo-this-extent (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (let* ((widget (or (extent-property extent 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (extent-property extent 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (extent-property extent 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (setq help-echo (funcall help-echo widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (when (stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (setq help-echo-owns-message t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (display-message 'help-echo help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (defsubst widget-handle-help-echo (extent help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (set-extent-property extent 'balloon-help help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (set-extent-property extent 'help-echo help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (when (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (set-extent-property extent 'balloon-help 'widget-echo-this-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (set-extent-property extent 'help-echo 'widget-echo-this-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (defun widget-specify-field (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 "Specify editable button for WIDGET between FROM and TO."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (goto-char to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (cond ((null (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 ;; Terminating space is not part of the field, but necessary in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 ;; order for local-map to work. Remove next sexp if local-map works
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 ;; at the end of the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (widget-field-add-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (insert-and-inherit " ")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (setq to (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (let ((map (widget-get widget :keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (face (or (widget-get widget :value-face) 'widget-field-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (help-echo (widget-get widget :help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (unless (or (stringp help-echo) (null help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (widget-put widget :field-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (and (or (not widget-field-add-space)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (set-extent-property extent 'end-closed nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (set-extent-property extent 'detachable nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (set-extent-property extent 'field widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (set-extent-property extent 'button-or-field t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (set-extent-property extent 'keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (widget-handle-help-echo extent help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (widget-specify-secret widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (defun widget-specify-secret (field)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
353 "Replace text in FIELD with value of `:secret', if non-nil.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
354
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
355 It is an error to use this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
356 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (let ((secret (widget-get field :secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (size (widget-get field :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (when secret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (let ((begin (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (end (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (when size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (while (and (> end begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (eq (char-after (1- end)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (setq end (1- end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (while (< begin end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (let ((old (char-after begin)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (unless (eq old secret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (subst-char-in-region begin (1+ begin) old secret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (put-text-property begin (1+ begin) 'secret old))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (setq begin (1+ begin))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (defun widget-specify-button (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 "Specify button for WIDGET between FROM and TO."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (let ((face (widget-apply widget :button-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (help-echo (widget-get widget :help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (extent (make-extent from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (map (widget-get widget :button-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (widget-put widget :button-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (unless (or (null help-echo) (stringp help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (set-extent-property extent 'button widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (set-extent-property extent 'button-or-field t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (set-extent-property extent 'mouse-face widget-mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 (widget-handle-help-echo extent help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (set-extent-property extent 'keymap map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (defun widget-mouse-help (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 "Find mouse help string for button in extent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (let* ((widget (widget-at (extent-start-position extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 (cond ((stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 ((and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (stringp (setq help-echo (funcall help-echo widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (format "(widget %S :help-echo %S)" widget help-echo)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (defun widget-specify-sample (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 ;; Specify sample for WIDGET between FROM and TO.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (let ((face (widget-apply widget :sample-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (extent (make-extent from to nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (widget-put widget :sample-extent extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (defun widget-specify-doc (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 ;; Specify documentation for WIDGET between FROM and TO.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (let ((extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (set-extent-property extent 'widget-doc widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (set-extent-property extent 'face widget-documentation-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (widget-put widget :doc-extent extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (defmacro widget-specify-insert (&rest form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 ;; Execute FORM without inheriting any text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 `(save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (insert "<>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (narrow-to-region (- (point) 2) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (goto-char (1+ (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 ;; We use `prog1' instead of a `result' variable, as the latter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 ;; confuses the byte-compiler in some cases (a warning).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (prog1 (progn ,@form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (delete-region (point-min) (1+ (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (delete-region (1- (point-max)) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (goto-char (point-max))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (put 'widget-specify-insert 'edebug-form-spec '(&rest form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 ;;; Inactive Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (defface widget-inactive-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (:foreground "light gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (:foreground "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 "Face used for inactive widgets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 ;; For inactiveness to work on complex structures, it is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 ;; sufficient to keep track of whether a button/field/glyph is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 ;; inactive or not -- we must know how many time it was deactivated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 ;; (inactiveness level). Successive deactivations of the same button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 ;; increment its inactive-count, and activations decrement it. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 ;; inactive-count reaches 0, the button/field/glyph is reactivated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (defun widget-activation-widget-mapper (extent action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 "Activate or deactivate EXTENT's widget (button or field).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 Suitable for use with `map-extents'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (ecase action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (:activate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 (decf (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 (when (zerop (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 extent (extent-property extent :inactive-plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (set-extent-property extent :inactive-plist nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 (:deactivate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (incf (extent-property extent :inactive-count 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 ;; Store a plist of old properties, which will be fed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 ;; `set-extent-properties'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (unless (extent-property extent :inactive-plist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (set-extent-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 extent :inactive-plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (list 'mouse-face (extent-property extent 'mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 'help-echo (extent-property extent 'help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 'keymap (extent-property extent 'keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 extent '(mouse-face nil help-echo nil keymap nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 (defun widget-activation-glyph-mapper (extent action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (let ((activate-p (if (eq action :activate) t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (if activate-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (decf (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (incf (extent-property extent :inactive-count 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (when (or (and activate-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (zerop (extent-property extent :inactive-count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (and (not activate-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 (not (zerop (extent-property extent :inactive-count)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (let* ((glyph-widget (extent-property extent 'glyph-widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (up-glyph (widget-get glyph-widget :glyph-up))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (inactive-glyph (widget-get glyph-widget :glyph-inactive))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
493 (instantiator (widget-get glyph-widget :glyph-instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (new-glyph (if activate-p up-glyph inactive-glyph)))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
495 (cond
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
496 ;; Assume that an instantiator means a native widget.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
497 (instantiator
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
498 (setq instantiator
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
499 (set-instantiator-property instantiator :active activate-p))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
500 (widget-put glyph-widget :glyph-instantiator instantiator)
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
501 (set-glyph-image up-glyph instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 ;; Check that the new glyph exists, and differs from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 ;; default one.
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
504 ((and up-glyph inactive-glyph (not (eq up-glyph inactive-glyph))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
505 ;; Check if the glyph is already installed.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
506 (not (eq (extent-end-glyph extent) new-glyph)))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
507 ;; Change it.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
508 (set-extent-end-glyph extent new-glyph))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (defun widget-specify-inactive (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 "Make WIDGET inactive for user modifications."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (unless (widget-get widget :inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (let ((extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 ;; It is no longer necessary for the extent to be read-only, as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 ;; the inactive editable fields now lose their keymaps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 extent '(start-open t face widget-inactive-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 detachable t priority 2001 widget-inactive t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 (widget-put widget :inactive extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 ;; Deactivate the buttons and fields within the range. In some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 ;; cases, the fields are not yet setup at the time this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 ;; is called. Those fields are deactivated explicitly by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 ;; `widget-setup'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (map-extents 'widget-activation-widget-mapper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 nil from to :deactivate nil 'button-or-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 ;; Deactivate glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (map-extents 'widget-activation-glyph-mapper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 nil from to :deactivate nil 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (defun widget-specify-active (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 "Make WIDGET active for user modifications."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
533 (let ((inactive (widget-get widget :inactive))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
534 (from (widget-get widget :from))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
535 (to (widget-get widget :to)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (when (and inactive (not (extent-detached-p inactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 ;; Reactivate the buttons and fields covered by the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (map-extents 'widget-activation-widget-mapper
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
539 nil from to :activate nil 'button-or-field)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 ;; Reactivate the glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (map-extents 'widget-activation-glyph-mapper
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
542 nil from to :activate nil 'end-glyph)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (delete-extent inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (widget-put widget :inactive nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 ;;; Widget Properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (defsubst widget-type (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 "Return the type of WIDGET, a symbol."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (car widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (when (or (not (fboundp 'widget-put))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 (defun widget-put (widget property value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 "In WIDGET set PROPERTY to VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 The value can later be retrieved with `widget-get'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (setcdr widget (plist-put (cdr widget) property value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 ;; Recoded in C, for efficiency:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 (when (or (not (fboundp 'widget-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 (defun widget-get (widget property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 "In WIDGET, get the value of PROPERTY.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
565 The value may have been specified when the widget was created, or
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 later with `widget-put'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (let ((missing t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 value tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 (while missing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 (cond ((setq tmp (widget-plist-member (cdr widget) property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 (setq value (car (cdr tmp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 missing nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 ((setq tmp (car widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (setq widget (get tmp 'widget-type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (setq missing nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 (defun widget-get-indirect (widget property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 "In WIDGET, get the value of PROPERTY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 If the value is a symbol, return its binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 Otherwise, just return the value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (let ((value (widget-get widget property)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (symbol-value value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (defun widget-member (widget property)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
589 "Return t if there is a definition in WIDGET for PROPERTY."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 (cond ((widget-plist-member (cdr widget) property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 ((car widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 (widget-member (get (car widget) 'widget-type) property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 (t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (when (or (not (fboundp 'widget-apply))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 ;;This is in C, so don't ###utoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (defun widget-apply (widget property &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 "Apply the value of WIDGET's PROPERTY to the widget itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 ARGS are passed as extra arguments to the function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (apply (widget-get widget property) widget args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (defun widget-value (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 "Extract the current value of WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 :value-to-external (widget-apply widget :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (defun widget-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 "Set the current value of WIDGET to VALUE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 :value-set (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 :value-to-internal value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (defun widget-default-get (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
616 "Extract the default value of WIDGET."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (or (widget-get widget :value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 (widget-apply widget :default-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 (defun widget-match-inline (widget vals)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
621 "In WIDGET, match the start of VALS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 (cond ((widget-get widget :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (widget-apply widget :match-inline vals))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
624 ((and (listp vals)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (widget-apply widget :match (car vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (cons (list (car vals)) (cdr vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 (t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 (defun widget-apply-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 "Apply :action in WIDGET in response to EVENT."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 (if (widget-apply widget :active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 (widget-apply widget :action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 (error "Attempt to perform action on inactive widget")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 ;;; Helper functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 ;; These are widget specific.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (defun widget-prompt-value (widget prompt &optional value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 "Prompt for a value matching WIDGET, using PROMPT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 The current value is assumed to be VALUE, unless UNBOUND is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (unless (listp widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 (setq widget (list widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (setq prompt (format "[%s] %s" (widget-type widget) prompt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (setq widget (widget-convert widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 (let ((answer (widget-apply widget :prompt-value prompt value unbound)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 (while (not (widget-apply widget :match answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 (setq answer (signal 'error (list "Answer does not match type"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 answer (widget-type widget)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 (defun widget-get-sibling (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 "Get the item WIDGET is assumed to toggle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 This is only meaningful for radio buttons or checkboxes in a list."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (let* ((parent (widget-get widget :parent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (children (widget-get parent :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 (catch 'child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 (when (eq (widget-get child :button) widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (throw 'child child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 (defun widget-map-buttons (function &optional buffer maparg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 "Map FUNCTION over the buttons in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 FUNCTION is called with the arguments WIDGET and MAPARG.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 If FUNCTION returns non-nil, the walk is cancelled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 The arguments MAPARG, and BUFFER default to nil and (current-buffer),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 respectively."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 (map-extents (lambda (extent ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 ;; If FUNCTION returns non-nil, we bail out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 (funcall function (extent-property extent 'button) maparg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 nil nil nil nil nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 'button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 ;;; Glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 (defcustom widget-glyph-directory (locate-data-directory "custom")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 "Where widget glyphs are located.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 If this variable is nil, widget will try to locate the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 automatically."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 :type 'directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (defcustom widget-glyph-enable t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 "If non nil, use glyphs in images when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 (defcustom widget-image-file-name-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 '((xpm ".xpm") (gif ".gif") (png ".png") (jpeg ".jpg" ".jpeg")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 (xbm ".xbm"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 "Conversion alist from image formats to file name suffixes."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 :type '(repeat (cons :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 (symbol :tag "Image Format" unknown)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 (repeat :tag "Suffixes"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 (string :format "%v")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 ;; Don't use this, because we cannot yet distinguish between widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 ;; glyphs associated with user action, and actionless ones.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 ;(defvar widget-glyph-pointer-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 ; (make-pointer-glyph [cursor-font :data "hand2"])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 ; "Glyph to be used as the mouse pointer shape over glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 ;Use `set-glyph-image' to change this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 (defvar widget-glyph-cache nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 "Cache of glyphs associated with strings (files).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 (defun widget-glyph-find (image tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 "Create a glyph corresponding to IMAGE with string TAG as fallback.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 IMAGE can already be a glyph, or a file name sans extension (xpm,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 xbm, gif, jpg, or png) located in `widget-glyph-directory', or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 in one of the data directories.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 It can also be a valid image instantiator, in which case it will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 used to make the glyph, with an additional TAG string fallback."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 (cond ((not (and image widget-glyph-enable))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 ;; We don't want to use glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 ((and (not (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 ;; We don't use glyphs on TTY consoles, although we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 ;; could. However, glyph faces aren't yet working
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 ;; properly, and movement through glyphs is unintuitive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 ;; As an exception, when TAG is nil, we assume that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 ;; caller knows what he is doing, and that the tag is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 ;; encoded within the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 (not (glyphp image)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 ((glyphp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 ;; Already a glyph. Use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 ((stringp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 ;; A string. Look it up in the cache first...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (or (lax-plist-get widget-glyph-cache image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 ;; ...and then in the relevant directories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 (let* ((dirlist (cons (or widget-glyph-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 (locate-data-directory "custom"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 data-directory-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 (all-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 (apply #'append
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 (lambda (el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 (and (valid-image-instantiator-format-p (car el))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 (cdr el)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 widget-image-file-name-suffixes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (file (locate-file image dirlist all-suffixes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (when file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 (let* ((extension (concat "." (file-name-extension file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (format (car (rassoc* extension
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 widget-image-file-name-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 :test #'member))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 ;; We create a glyph with the file as the default image
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 ;; instantiator, and the TAG fallback
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 (let ((glyph (make-glyph `([,format :file ,file]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 [string :data ,tag]))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 ;; Cache the glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 (laxputf widget-glyph-cache image glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 ;; ...and return it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 glyph))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 ((valid-instantiator-p image 'image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 ;; A valid image instantiator (e.g. [gif :file "somefile"] etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 (make-glyph `(,image [string :data ,tag])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 ;; Oh well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 (defun widget-glyph-insert (widget tag image &optional down inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 "In WIDGET, insert the text TAG or, if supported, IMAGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 IMAGE should either be a glyph, an image instantiator, an image file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 name sans extension (xpm, xbm, gif, jpg, or png) located in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 `widget-glyph-directory', or anything else allowed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 `widget-glyph-find'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 If IMAGE is a list, it will be taken as a list of (UP DOWN INACTIVE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 glyphs. The down and inactive glyphs are shown when glyph is pressed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 or inactive, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 The optional DOWN and INACTIVE arguments are deprecated, and exist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 only because of compatibility."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 ;; Convert between IMAGE being a list, etc. Must use `psetq',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 ;; because otherwise change to `image' screws up the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 (psetq image (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 (car image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 down (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 (nth 1 image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 inactive (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 (nth 2 image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 (let ((glyph (widget-glyph-find image tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 (if glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 (widget-glyph-insert-glyph widget glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 (widget-glyph-find down tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 (widget-glyph-find inactive tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 (insert tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
806 (defun widget-glyph-insert-glyph (widget glyph &optional down inactive
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
807 instantiator)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 "In WIDGET, insert GLYPH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 If optional arguments DOWN and INACTIVE are given, they should be
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
810 glyphs used when the widget is pushed and inactive, respectively.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
811 INSTANTIATOR is the vector used to create the glyph."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 (insert "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 (let ((extent (make-extent (point) (1- (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 (help-echo (and widget (widget-get widget :help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 (map (and widget (widget-get widget :button-keymap))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 (set-extent-property extent 'glyph-widget widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 ;; It would be fun if we could make this extent atomic, so it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 ;; doesn't mess with cursor motion. But atomic-extents library is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 ;; currently a mess, so I'd rather not use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 (set-extent-property extent 'invisible t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 (set-extent-property extent 'end-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 (set-extent-property extent 'keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 ;;(set-extent-property extent 'pointer widget-glyph-pointer-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 (set-extent-end-glyph extent glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (unless (or (stringp help-echo) (null help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 (when help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 (widget-handle-help-echo extent help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 (when widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 (widget-put widget :glyph-up glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 (when down (widget-put widget :glyph-down down))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
833 (when instantiator (widget-put widget :glyph-instantiator instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 (when inactive (widget-put widget :glyph-inactive inactive))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 ;;; Buttons.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 (defgroup widget-button nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 "The look of various kinds of buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (defcustom widget-button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 "String used as prefix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 (defcustom widget-button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 "String used as suffix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 ;;; Creating Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (defun widget-create (type &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
858 "Create a widget of type TYPE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 The optional ARGS are additional keyword arguments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 (let ((widget (apply 'widget-convert type args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (defun widget-create-child-and-convert (parent type &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
865 "As a child of widget PARENT, create a widget of type TYPE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 The child is converted, using the keyword arguments ARGS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 (let ((widget (apply 'widget-convert type args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (defun widget-create-child (parent type)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
877 "As a child of widget PARENT, create a widget of type TYPE.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
878 The child is not converted."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 (let ((widget (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 (defun widget-create-child-value (parent type value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 "Create widget of TYPE with value VALUE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 (let ((widget (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 (widget-put widget :value (widget-apply widget :value-to-internal value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 (defun widget-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 "Delete WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (widget-apply widget :delete))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (defun widget-convert (type &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 "Convert TYPE to a widget without inserting it in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 The optional ARGS are additional keyword arguments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 ;; Don't touch the type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 (let* ((widget (if (symbolp type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 (list type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 (current widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 (keys args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 ;; First set the :args keyword.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (while (cdr current) ;Look in the type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (let ((next (car (cdr current))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (setq current (cdr (cdr current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (setcdr current (list :args (cdr current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 (setq current nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (while args ;Look in the args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 (let ((next (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (setq args (nthcdr 2 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (widget-put widget :args args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 (setq args nil))))
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
927 ;; Then convert the widget.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (setq type widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (while type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (let ((convert-widget (plist-get (cdr type) :convert-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (if convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (setq widget (funcall convert-widget widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (setq type (get (car type) 'widget-type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 ;; Finally set the keyword args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (while keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 (let ((next (nth 0 keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 (widget-put widget next (nth 1 keys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 (setq keys (nthcdr 2 keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (setq keys nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 ;; Convert the :value to internal format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 (if (widget-member widget :value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 (let ((value (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 :value (widget-apply widget :value-to-internal value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 ;; Return the newly created widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (defun widget-insert (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 "Call `insert' with ARGS and make the text read only."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 (apply 'insert args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (defun widget-convert-text (type from to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 &optional button-from button-to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
960 "Return a widget of type TYPE with endpoints FROM and TO.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
961 No text will be inserted in the buffer. Instead the positions FROM and TO
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
962 will be used as the widget's end points. The widget is ``wrapped around''
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
963 the text between them.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
964 If optional arguments BUTTON-FROM and BUTTON-TO are given, these will be
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
965 used as the widget's button end points.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 Optional ARGS are extra keyword arguments for TYPE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 (let ((widget (apply 'widget-convert type :delete 'widget-leave-text args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 (from (copy-marker from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 (to (copy-marker to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 (set-marker-insertion-type from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 (set-marker-insertion-type to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (widget-put widget :from from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (widget-put widget :to to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 (when button-from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (widget-specify-button widget button-from button-to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (defun widget-convert-button (type from to &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
979 "Return a widget of type TYPE with endpoints FROM and TO.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 Optional ARGS are extra keyword arguments for TYPE.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
981 No text will be inserted in the buffer. Instead the positions FROM and TO
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
982 will be used as the widget's end points, as well as the widget's button's
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
983 end points. The widget is ``wrapped around'' the text between them."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (apply 'widget-convert-text type from to from to args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (defun widget-leave-text (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 "Remove markers and extents from WIDGET and its children."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 (let ((from (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 (to (widget-get widget :to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 (button (widget-get widget :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 (sample (widget-get widget :sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 (doc (widget-get widget :doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 (field (widget-get widget :field-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 (children (widget-get widget :children)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 (set-marker to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 ;; Maybe we should delete the extents here? As this code doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 ;; remove them from widget structures, maybe it's safer to just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 ;; detach them. That's what `delete-overlay' did.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 (when button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 (detach-extent button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 (when sample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 (detach-extent sample))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 (when doc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 (detach-extent doc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 (when field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 (detach-extent field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 (mapc 'widget-leave-text children)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 ;;; Keymap and Commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (defvar widget-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 "Keymap containing useful binding for buffers containing widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 Recommended as a parent keymap for modes using widgets.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 (unless widget-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 (setq widget-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 (define-key widget-keymap [tab] 'widget-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (define-key widget-keymap [(shift tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 (define-key widget-keymap [(meta tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 (define-key widget-keymap [backtab] 'widget-backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 (defvar widget-global-map global-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 "Keymap used for events the widget does not handle themselves.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (make-variable-buffer-local 'widget-global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 (defvar widget-field-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 "Keymap used inside an editable field.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (unless widget-field-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (setq widget-field-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 (set-keymap-parents widget-field-keymap global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (define-key widget-field-keymap "\C-k" 'widget-kill-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 (define-key widget-field-keymap [(meta tab)] 'widget-complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (define-key widget-field-keymap [tab] 'widget-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (define-key widget-field-keymap [(shift tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 (define-key widget-field-keymap "\C-m" 'widget-field-activate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (define-key widget-field-keymap "\C-e" 'widget-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (define-key widget-field-keymap "\C-t" 'widget-transpose-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (defvar widget-text-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 "Keymap used inside a text field.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (unless widget-text-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (setq widget-text-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (set-keymap-parents widget-field-keymap global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (define-key widget-text-keymap "\C-e" 'widget-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (define-key widget-text-keymap "\C-t" 'widget-transpose-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (defvar widget-button-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 "Keymap used inside a button.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (unless widget-button-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (setq widget-button-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 (set-keymap-parents widget-button-keymap widget-keymap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 (define-key widget-button-keymap "\C-m" 'widget-button-press)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 (define-key widget-button-keymap [button2] 'widget-button-click)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 ;; Ideally, button3 within a button should invoke a button-specific
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 ;; menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 (define-key widget-button-keymap [button3] 'widget-button-click)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 ;;Glyph support.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 (define-key widget-button-keymap [button1] 'widget-button1-click))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (defun widget-field-activate (pos &optional event)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1069 "Invoke the editable field at point."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 (interactive "@d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 (let ((field (widget-field-find pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (if field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 (widget-apply-action field event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (call-interactively
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 (lookup-key widget-global-map (this-command-keys))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 (defface widget-button-pressed-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 '((((class color))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 (:foreground "red"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 (:bold t :underline t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 "Face used for pressed buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 (defun widget-event-point (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 "Character position of the mouse event, or nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 (and (mouse-event-p event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (event-point event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 (defun widget-button-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 "Invoke button below mouse pointer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (interactive "e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 (with-current-buffer (event-buffer event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (cond ((event-glyph event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 (widget-glyph-click event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 ((widget-event-point event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (let* ((pos (widget-event-point event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (button (get-char-property pos 'button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 (if button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (let* ((extent (widget-get button :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 (face (extent-property extent 'face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 (mouse-face (extent-property extent 'mouse-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 (help-echo (extent-property extent 'help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 ;; Merge relevant faces, and make the result mouse-face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 (let ((merge `(widget-button-pressed-face ,mouse-face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 (nconc merge (if (listp face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 face (list face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 (setq merge (delete-if-not 'find-face merge))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 (set-extent-property extent 'mouse-face merge))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 (unless (widget-apply button :mouse-down-action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 ;; Wait for button release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 (while (not (button-release-event-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 (setq event (next-event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 (dispatch-event event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 ;; Disallow mouse-face and help-echo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 (set-extent-property extent 'mouse-face nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 (set-extent-property extent 'help-echo nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 (setq pos (widget-event-point event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 (unless (eq (current-buffer) (extent-object extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 ;; Barf if dispatch-event tripped us by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 ;; changing buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 (error "Buffer changed during mouse motion"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 ;; Do the associated action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (when (and pos (extent-in-region-p extent pos pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 (widget-apply-action button event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 ;; Unwinding: fully release the button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 (set-extent-property extent 'mouse-face mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 (set-extent-property extent 'help-echo help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 ;; This should not happen!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 (error "`widget-button-click' called outside button"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 (message "You clicked somewhere weird")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 (defun widget-button1-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 "Invoke glyph below mouse pointer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 (interactive "@e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 (if (event-glyph event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 (widget-glyph-click event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 ;; Should somehow avoid this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 (let ((command (lookup-key widget-global-map (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 (and (commandp command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (call-interactively command)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 (defun widget-glyph-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 "Handle click on a glyph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 (let* ((glyph (event-glyph event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (extent (event-glyph-extent event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (widget (extent-property extent 'glyph-widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 (down-glyph (or (and widget (widget-get widget :glyph-down)) glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (up-glyph (or (and widget (widget-get widget :glyph-up)) glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 (last event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 (unless (widget-apply widget :active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 (error "This widget is inactive"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 (let ((current-glyph 'down))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 ;; We always know what glyph is drawn currently, to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 ;; unnecessary extent changes. Is this any noticeable gain?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 ;; Press the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 (set-extent-end-glyph extent down-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 ;; Redisplay (shouldn't be needed, but...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 (sit-for 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 (unless (widget-apply widget :mouse-down-action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 ;; Wait for the release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 (while (not (button-release-event-p last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (unless (button-press-event-p last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 (dispatch-event last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 (when (motion-event-p last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 ;; Update glyphs on mouse motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 (if (eq extent (event-glyph-extent last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (unless (eq current-glyph 'down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 (set-extent-end-glyph extent down-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 (setq current-glyph 'down))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 (unless (eq current-glyph 'up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (set-extent-end-glyph extent up-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 (setq current-glyph 'up))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 (setq last (next-event event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 (unless (eq (current-buffer) (extent-object extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 ;; Barf if dispatch-event tripped us by changing buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 (error "Buffer changed during mouse motion"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 ;; Apply widget action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 (when (eq extent (event-glyph-extent last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 (let ((widget (extent-property (event-glyph-extent event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (cond ((null widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (message "You clicked on a glyph"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 ((not (widget-apply widget :active))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 (error "This glyph is inactive"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 (widget-apply-action widget event))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 ;; Release the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 (and (eq current-glyph 'down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 ;; The extent might have been detached or deleted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 (extent-live-p extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 (not (extent-detached-p extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 (set-extent-end-glyph extent up-glyph))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 (defun widget-button-press (pos &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 "Invoke button at POS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 (interactive "@d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 (let ((button (get-char-property pos 'button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 (if button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 (widget-apply-action button event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 (let ((command (lookup-key widget-global-map (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 (when (commandp command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 (call-interactively command))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 (defun widget-tabable-at (&optional pos last-tab backwardp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 "Return the tabable widget at POS, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 POS defaults to the value of (point)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 (unless pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 (setq pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 (let ((widget (widget-at pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 (if widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 (let ((order (widget-get widget :tab-order)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 (if order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 (if last-tab (and (= order (if backwardp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 (1- last-tab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 (1+ last-tab)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (and (> order 0) widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 ;; Return the button or field extent at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 (defun widget-button-or-field-extent (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 (or (and (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 (widget-get (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 (and (get-char-property pos 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 (widget-get (get-char-property pos 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 :field-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 (defun widget-next-button-or-field (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 "Find the next button, or field, and return its start position, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 Internal function, don't use it outside `wid-edit'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 (let* ((at-point (widget-button-or-field-extent pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 (extent (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 (lambda (ext ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 nil (if at-point (extent-end-position at-point) pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 nil nil 'start-open 'button-or-field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 (and extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 (extent-start-position extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 ;; This is too slow in buffers with many buttons (W3).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 (defun widget-previous-button-or-field (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 "Find the previous button, or field, and return its start position, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 Internal function, don't use it outside `wid-edit'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 (let* ((at-point (widget-button-or-field-extent pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 previous-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 (lambda (ext ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 (if (eq ext at-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 ;; We reached the extent we were on originally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (if (= pos (extent-start-position at-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 previous-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 (setq previous-extent at-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 (setq previous-extent ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 nil nil pos nil 'start-open 'button-or-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (and previous-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 (extent-start-position previous-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 (defun widget-move (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 "Move point to the ARG next field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 ARG may be negative to move backward."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 (let ((opoint (point)) (wrapped 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 (last-tab (widget-get (widget-at (point)) :tab-order))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 nextpos found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 ;; Movement backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (while (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 (setq nextpos (widget-previous-button-or-field (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 (if nextpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 (goto-char nextpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 (when (and (not (get-char-property nextpos 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 (widget-tabable-at nil last-tab t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 (incf arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 (setq found t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 last-tab (widget-get (widget-at (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 :tab-order))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 (if (and (not found) (> wrapped 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 (setq arg 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 (incf wrapped))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 ;; Movement forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 (setq nextpos (widget-next-button-or-field (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 (if nextpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 (goto-char nextpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 (when (and (not (get-char-property nextpos 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 (widget-tabable-at nil last-tab))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 (decf arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 (setq found t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 last-tab (widget-get (widget-at (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 :tab-order))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 (if (and (not found) (> wrapped 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 (setq arg 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 (incf wrapped))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 (if (not found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 (widget-echo-help (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 (run-hooks 'widget-move-hook))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 (defun widget-forward (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 "Move point to the next field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 With optional ARG, move across that many fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 (run-hooks 'widget-forward-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 (widget-move arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 (defun widget-backward (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 "Move point to the previous field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 With optional ARG, move across that many fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 (run-hooks 'widget-backward-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 (widget-move (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 (defun widget-beginning-of-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1327 "Go to beginning of field or beginning of line, whichever is first.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1328
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1329 It is an error to use this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1330 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 (start (and field (widget-field-start field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 (if (and start (not (eq start (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 (call-interactively 'beginning-of-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 (defun widget-end-of-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1339 "Go to end of field or end of line, whichever is first.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1340
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1341 It is an error to use this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1342 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 (end (and field (widget-field-end field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 (if (and end (not (eq end (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 (call-interactively 'end-of-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (defun widget-kill-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1351 "Kill to end of field or end of line, whichever is first.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1352
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1353 It is an error to use this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1354 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 (newline (save-excursion (forward-line 1) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (end (and field (widget-field-end field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 (if (and field (> newline end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (kill-region (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 (call-interactively 'kill-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 (defun widget-transpose-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 "Like `transpose-chars', but works correctly at end of widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (start (and field (widget-field-start field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 (end (and field (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 (last-non-space (and start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 (skip-chars-backward " \t\n" start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 (cond ((and last-non-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 (or (= last-non-space start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 (= last-non-space (1+ start))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 ;; empty or one-character field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 ((= (point) start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 ;; at the beginning of the field -- we would get an error here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 (error "Cannot transpose at beginning of field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 (when (and (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 (= last-non-space (point)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1385 (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 (transpose-chars arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 (defcustom widget-complete-field (lookup-key global-map "\M-\t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 "Default function to call for completion inside fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 :options '(ispell-complete-word complete-tag lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 (defun widget-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 "Complete content of editable field from point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 When not inside a field, move to the previous button or field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 ;; Somehow, this should make pressing M-TAB twice scroll the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 ;; completions window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 (let ((field (widget-field-find (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 (if field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 (widget-apply field :complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 (error "Not in an editable field"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 ;;; Setting up the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 (defvar widget-field-new nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 ;; List of all newly created editable fields in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 (make-variable-buffer-local 'widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 (defvar widget-field-list nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 ;; List of all editable fields in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 (make-variable-buffer-local 'widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 (defun widget-setup ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 "Setup current buffer so editing string widgets works."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 (after-change-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 (while widget-field-new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 (setq field (car widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 widget-field-new (cdr widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 widget-field-list (cons field widget-field-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 (let ((from (car (widget-get field :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 (to (cdr (widget-get field :field-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 (widget-specify-field field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 (marker-position from) (marker-position to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 (set-marker to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 ;; If the field is placed within the inactive zone, deactivate it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 (let ((extent (widget-get field :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 (when (get-char-property (extent-start-position extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 'widget-inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 (widget-activation-widget-mapper extent :deactivate)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 (widget-clear-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 (widget-add-change))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 (defvar widget-field-last nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 ;; Last field containing point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 (make-variable-buffer-local 'widget-field-last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 (defvar widget-field-was nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 ;; The widget data before the change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 (make-variable-buffer-local 'widget-field-was)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 (defun widget-field-buffer (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1449 "Return the buffer containing WIDGET.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1450
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1451 It is an error to use this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1452 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 (and extent (extent-object extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 (defun widget-field-start (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1457 "Return the start of WIDGET's editing field.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1458
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1459 It is an error to use this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1460 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 (and extent (extent-start-position extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 (defun widget-field-end (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1465 "Return the end of WIDGET's editing field.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1466
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1467 It is an error to use this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1468 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 ;; Don't subtract one if local-map works at the end of the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 (and extent (if (or widget-field-add-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 (null (widget-get widget :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 (1- (extent-end-position extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 (extent-end-position extent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 (defun widget-field-find (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 "Return the field at POS.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1478 Unlike (get-char-property POS 'field) this, works with empty fields too.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1479
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1480 Warning: using this function after creating the widget but before invoking
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1481 `widget-setup' will always fail."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 (let ((field-extent (map-extents (lambda (extent ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 nil pos pos nil nil 'field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (and field-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 (extent-property field-extent 'field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 ;; Old version, without `map-extents'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 ;(defun widget-field-find (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 ; (let ((fields widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 ; field found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 ; (while fields
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 ; (setq field (car fields)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 ; fields (cdr fields))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 ; (let ((start (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 ; (end (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 ; (when (and (<= start pos) (<= pos end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 ; (when found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 ; (debug "Overlapping fields"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 ; (setq found field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 ; found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1503 ;; Warning: using this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1504 ;; invoking `widget-setup' will always fail.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 (defun widget-before-change (from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 ;; Barf if the text changed is outside the editable fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 (unless inhibit-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 (let ((from-field (widget-field-find from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 (to-field (widget-field-find to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 (cond ((or (null from-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 (null to-field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 ;; Either end of change is not within a field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 (error "Attempt to change text outside editable field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 ((not (eq from-field to-field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 ;; The change begins in one fields, and ends in another one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 (error "Change should be restricted to a single field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 ((or (and from-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 (get-char-property from 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 (and to-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 (get-char-property to 'widget-inactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 ;; Trying to change an inactive editable field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 (error "Attempt to change an inactive field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 (widget-field-use-before-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 ;; #### Bletch! This loses because XEmacs get confused
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 ;; if before-change-functions change the contents of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 ;; buffer before from/to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 (widget-apply from-field :notify from-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 (error (debug "Before Change"))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 (defun widget-add-change ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 (make-local-hook 'post-command-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 (remove-hook 'post-command-hook 'widget-add-change t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 (make-local-hook 'before-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 (add-hook 'before-change-functions 'widget-before-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 (make-local-hook 'after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 (add-hook 'after-change-functions 'widget-after-change nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 (defun widget-after-change (from to old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 ;; Adjust field size and text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 ;; Also, notify the widgets (so, for example, a variable changes its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 ;; state to `modified'. when it is being edited.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 (let ((field (widget-field-find from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 (other (widget-field-find to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 (when field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 (unless (eq field other)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 (debug "Change in different fields"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 (let ((size (widget-get field :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 (when size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 (let ((begin (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 (end (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 (cond ((< (- end begin) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 ;; Field too small.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 (insert-char ?\ (- (+ begin size) end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 ((> (- end begin) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 ;; Field too large and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 (if (or (< (point) (+ begin size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 (> (point) end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 ;; Point is outside extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 (setq begin (+ begin size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 ;; Point is within the extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 (setq begin (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 (while (and (eq (preceding-char) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 (> (point) begin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 (delete-backward-char 1)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 (widget-specify-secret field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 (widget-apply field :notify field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 (error (debug "After Change"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 ;;; Widget Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 ;; These functions are used in the definition of multiple widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 (defun widget-parent-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 "Tell :parent of WIDGET to handle the :action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 Optional EVENT is the event that triggered the action."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 (widget-apply (widget-get widget :parent) :action event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 (defun widget-children-value-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 "Delete all :children and :buttons in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 (mapc 'widget-delete (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 (widget-put widget :children nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 (mapc 'widget-delete (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 (widget-put widget :buttons nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 (defun widget-children-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 "All the :children must be valid."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 child found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 found (widget-apply child :validate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 (defun widget-types-convert-widget (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 "Convert :args as widget types in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 (defun widget-value-convert-widget (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 "Initialize :value from :args in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 (let ((args (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 (when args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 (widget-put widget :value (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 ;; Don't convert :value here, as this is done in `widget-convert'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 ;; (widget-put widget :value (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 ;; :value-to-internal (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 (widget-put widget :args nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 (defun widget-value-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 "Return the :value property of WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 ;;; The `default' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 (define-widget 'default nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 "Basic widget other widgets are derived from."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 :value-to-internal (lambda (widget value) value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 :value-to-external (lambda (widget value) value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 :button-prefix 'widget-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 :button-suffix 'widget-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 :complete 'widget-default-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 :create 'widget-default-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 :indent nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 :offset 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 :format-handler 'widget-default-format-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 :button-face-get 'widget-default-button-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 :sample-face-get 'widget-default-sample-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 :button-keymap widget-button-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 :delete 'widget-default-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 :value-set 'widget-default-value-set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 :value-inline 'widget-default-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 :default-get 'widget-default-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 :menu-tag-get 'widget-default-menu-tag-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 :validate (lambda (widget) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 :active 'widget-default-active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 :activate 'widget-specify-active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 :deactivate 'widget-default-deactivate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 :mouse-down-action (lambda (widget event) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 :action 'widget-default-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 :notify 'widget-default-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 :prompt-value 'widget-default-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 (defun widget-default-complete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 "Call the value of the :complete-function property of WIDGET.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 If that does not exists, call the value of `widget-complete-field'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 (let ((fun (widget-get widget :complete-function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 (call-interactively (or fun widget-complete-field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 (defun widget-default-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 "Create WIDGET at point in the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 (let ((from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 button-begin button-end button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 sample-begin sample-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 doc-begin doc-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 value-pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 (insert (widget-get widget :format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 ;; Parse escapes in format. Coding this in C would speed up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 ;; things *a lot*.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 (while (re-search-forward "%\\(.\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 (cond ((eq escape ?%)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 (insert "%"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 ((eq escape ?\[)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 (setq button-begin (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 (set-marker-insertion-type button-begin nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 ((eq escape ?\])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 (setq button-end (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 (set-marker-insertion-type button-end nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 ((eq escape ?\{)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 (setq sample-begin (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 ((eq escape ?\})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 (setq sample-end (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 ((eq escape ?n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 (when (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 (insert "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 (insert-char ?\ (widget-get widget :indent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 ((eq escape ?t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 (let* ((tag (widget-get widget :tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 (glyph (widget-get widget :tag-glyph)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 (cond (glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 (setq button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 (widget-glyph-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 widget (or tag "Image") glyph)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 (tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 (insert tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 (let ((standard-output (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 (princ (widget-get widget :value)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 ((eq escape ?d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 (let ((doc (widget-get widget :doc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 (when doc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 (setq doc-begin (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 (insert doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 (while (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 (delete-backward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 (insert "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 (setq doc-end (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 (if (and button-begin (not button-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 (widget-apply widget :value-create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 (setq value-pos (point-marker))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 (widget-apply widget :format-handler escape)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 ;; Specify button, sample, and doc, and insert value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 (when (and button-begin button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 (unless button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 (goto-char button-begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 (insert (widget-get-indirect widget :button-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 (goto-char button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 (set-marker-insertion-type button-end t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 (insert (widget-get-indirect widget :button-suffix)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 (widget-specify-button widget button-begin button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 ;; Is this necessary?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 (set-marker button-begin nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 (set-marker button-end nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 (and sample-begin sample-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 (widget-specify-sample widget sample-begin sample-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 (and doc-begin doc-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 (widget-specify-doc widget doc-begin doc-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 (when value-pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 (goto-char value-pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 (widget-apply widget :value-create)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 (let ((from (point-min-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 (to (point-max-marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 (set-marker-insertion-type from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 (set-marker-insertion-type to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 (widget-put widget :from from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 (widget-put widget :to to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 (widget-clear-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 (defun widget-default-format-handler (widget escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 ;; We recognize the %h escape by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 (let* ((buttons (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 (cond ((eq escape ?h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 (let* ((doc-property (widget-get widget :documentation-property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 (doc-try (cond ((widget-get widget :doc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 ((symbolp doc-property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 (documentation-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 (widget-get widget :value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 doc-property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 (funcall doc-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 (widget-get widget :value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 (doc-text (and (stringp doc-try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 (> (length doc-try) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 doc-try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 (doc-indent (widget-get widget :documentation-indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 (when doc-text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 ;; The `*' in the beginning is redundant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 (when (eq (aref doc-text 0) ?*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 (setq doc-text (substring doc-text 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 ;; Get rid of trailing newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 (when (string-match "\n+\\'" doc-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 (setq doc-text (substring doc-text 0 (match-beginning 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 (push (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 widget 'documentation-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 :indent (cond ((numberp doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 ((null doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 (t 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 doc-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 buttons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 (signal 'error (list "Unknown escape" escape))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 (widget-put widget :buttons buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 (defun widget-default-button-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 ;; Use :button-face or widget-button-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 (or (widget-get widget :button-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 (if parent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 (widget-apply parent :button-face-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 widget-button-face))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 (defun widget-default-sample-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 ;; Use :sample-face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 (widget-get widget :sample-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 (defun widget-default-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 ;; Remove widget from the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 (let ((from (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 (to (widget-get widget :to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 (inactive-extent (widget-get widget :inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 (button-extent (widget-get widget :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 (sample-extent (widget-get widget :sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 (doc-extent (widget-get widget :doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 after-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 (inhibit-read-only t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 (widget-apply widget :value-delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 (when inactive-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 (detach-extent inactive-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 (when button-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 (detach-extent button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 (when sample-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 (detach-extent sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 (when doc-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 (detach-extent doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 (when (< from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 ;; Kludge: this doesn't need to be true for empty formats.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 (delete-region from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 (set-marker to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 (widget-clear-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 (defun widget-default-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 ;; Recreate widget with new value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 (let* ((old-pos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 (from (copy-marker (widget-get widget :from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 (to (copy-marker (widget-get widget :to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 (offset (if (and (<= from old-pos) (<= old-pos to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 (if (>= old-pos (1- to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 (- old-pos to 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 (- old-pos from)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 ;;??? Bug: this ought to insert the new value before deleting the old one,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 ;; so that markers on either side of the value automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 ;; stay on the same side. -- rms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 (goto-char (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 (widget-apply widget :delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 (widget-put widget :value value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 (widget-apply widget :create))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 (when offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 (if (< offset 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 (goto-char (+ (widget-get widget :to) offset 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 (goto-char (min (+ from offset) (1- (widget-get widget :to))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 (defun widget-default-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 ;; Wrap value in a list unless it is inline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 (if (widget-get widget :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 (list (widget-value widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 (defun widget-default-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 ;; Get `:value'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 (defun widget-default-menu-tag-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 ;; Use tag or value for menus.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 (or (widget-get widget :menu-tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 (widget-get widget :tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 (widget-princ-to-string (widget-get widget :value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 (defun widget-default-active (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 "Return t iff this widget active (user modifiable)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 (and (not (widget-get widget :inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 (or (null parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 (widget-apply parent :active)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 (defun widget-default-deactivate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 "Make WIDGET inactive for user modifications."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 (widget-specify-inactive widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 (widget-get widget :from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 (widget-get widget :to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 (defun widget-default-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 ;; Notify the parent when a widget change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 (when parent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 (widget-apply parent :notify widget event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 (defun widget-default-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 ;; Pass notification to parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 (widget-default-action widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 (defun widget-default-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 ;; Read an arbitrary value. Stolen from `set-variable'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 ;; (let ((initial (if unbound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 ;; nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 ;; ;; It would be nice if we could do a `(cons val 1)' here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 ;; (prin1-to-string (custom-quote value))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 (eval-minibuffer prompt ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 ;;; The `item' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 (define-widget 'item 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 "Constant items for inclusion in other widgets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 :convert-widget 'widget-value-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 :value-create 'widget-item-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 :value-delete 'ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 :value-get 'widget-value-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 :match 'widget-item-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 :match-inline 'widget-item-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 :action 'widget-item-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 :format "%t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 (defun widget-item-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 ;; Insert the printed representation of the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 (let ((standard-output (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 (princ (widget-get widget :value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 (defun widget-item-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 ;; Match if the value is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 (equal (widget-get widget :value) value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 (defun widget-item-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 ;; Match if the value is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 (let ((value (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 (and (listp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 (<= (length value) (length values))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 (let ((head (widget-sublist values 0 (length value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 (and (equal head value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (cons head (widget-sublist values (length value))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 (defun widget-sublist (list start &optional end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 "Return the sublist of LIST from START to END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 If END is omitted, it defaults to the length of LIST."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 (if (> start 0) (setq list (nthcdr start list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 (if end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 (if (<= end start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 (setq list (copy-sequence list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 (setcdr (nthcdr (- end start 1) list) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 (copy-sequence list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 (defun widget-item-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 ;; Just notify itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 (widget-apply widget :notify widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 ;;; The `push-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 (defcustom widget-push-button-gui widget-glyph-enable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 "If non nil, use GUI push buttons when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 (defcustom widget-push-button-prefix "["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 "String used as prefix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 (defcustom widget-push-button-suffix "]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 "String used as suffix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 (define-widget 'push-button 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 "A pushable button."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 :value-create 'widget-push-button-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 :format "%[%v%]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 (defun widget-push-button-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 ;; Insert text representing the `on' and `off' states.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 (let* ((tag (or (widget-get widget :tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 (tag-glyph (widget-get widget :tag-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 (text (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 tag widget-push-button-suffix))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
1973 gui inst)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 (cond (tag-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 (widget-glyph-insert widget text tag-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 ;; We must check for console-on-window-system-p here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 ;; because GUI will not work otherwise (it needs RGB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 ;; components for colors, and they are not known on TTYs).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 ((and widget-push-button-gui
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 (console-on-window-system-p))
436
080151679be2 Import from CVS: tag r21-2-26
cvs
parents: 428
diff changeset
1981 (let* ((gui-button-shadow-thickness 1))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
1982 (setq inst (make-gui-button tag 'widget-gui-action widget))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
1983 (setq gui (make-glyph inst)))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
1984 (widget-glyph-insert-glyph widget gui nil nil inst))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 (insert text)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 (defun widget-gui-action (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 "Apply :action for WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 (widget-apply-action widget (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 ;;; The `link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 (defcustom widget-link-prefix "["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 "String used as prefix for links."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 (defcustom widget-link-suffix "]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 "String used as suffix for links."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 (define-widget 'link 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 "An embedded link."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 :button-prefix 'widget-link-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 :button-suffix 'widget-link-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 :help-echo "Follow the link"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 :format "%[%t%]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 ;;; The `info-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 (define-widget 'info-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 "A link to an info file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 :help-echo 'widget-info-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 :action 'widget-info-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 (defun widget-info-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 (concat "Read the manual entry `" (widget-value widget) "'"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 (defun widget-info-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 "Open the info node specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 (Info-goto-node (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 ;;; The `url-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 (define-widget 'url-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 "A link to an www page."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 :help-echo 'widget-url-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 :action 'widget-url-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 (defun widget-url-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 (concat "Visit <URL:" (widget-value widget) ">"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 (defun widget-url-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 "Open the url specified by WIDGET."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2037 (if (fboundp 'browse-url)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2038 (browse-url (widget-value widget))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 (error "Cannot follow URLs in this XEmacs")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 ;;; The `function-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 (define-widget 'function-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 "A link to an Emacs function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 :action 'widget-function-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 (defun widget-function-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 "Show the function specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 (describe-function (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 ;;; The `variable-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 (define-widget 'variable-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 "A link to an Emacs variable."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 :action 'widget-variable-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 (defun widget-variable-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 "Show the variable specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 (describe-variable (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 ;;; The `file-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 (define-widget 'file-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 "A link to a file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 :action 'widget-file-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 (defun widget-file-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 "Find the file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 (find-file (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 ;;; The `emacs-library-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 (define-widget 'emacs-library-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 "A link to an Emacs Lisp library file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 :help-echo 'widget-emacs-library-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 :action 'widget-emacs-library-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 (defun widget-emacs-library-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 (concat "Visit " (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 (defun widget-emacs-library-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 "Find the Emacs Library file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 (find-file (locate-library (widget-value widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 ;;; The `emacs-commentary-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 (define-widget 'emacs-commentary-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 "A link to Commentary in an Emacs Lisp library file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 :action 'widget-emacs-commentary-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 (defun widget-emacs-commentary-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 "Find the Commentary section of the Emacs file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 (finder-commentary (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 ;;; The `editable-field' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 (define-widget 'editable-field 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 "An editable text field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 :convert-widget 'widget-value-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 :keymap widget-field-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 :value ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 :prompt-internal 'widget-field-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 :prompt-history 'widget-field-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 :prompt-value 'widget-field-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 :action 'widget-field-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107 :validate 'widget-field-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 :valid-regexp ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 :error "No match"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 :value-create 'widget-field-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 :value-delete 'widget-field-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 :value-get 'widget-field-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 :match 'widget-field-match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 (defvar widget-field-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 "History of field minibuffer edits.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118 (defun widget-field-prompt-internal (widget prompt initial history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 ;; Read string for WIDGET prompting with PROMPT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 ;; INITIAL is the initial input and HISTORY is a symbol containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 ;; the earlier input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 (read-string prompt initial history))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 (defun widget-field-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 ;; Prompt for a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 (let ((initial (if unbound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 (cons (widget-apply widget :value-to-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 value) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130 (history (widget-get widget :prompt-history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 (let ((answer (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 :prompt-internal prompt initial history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 (widget-apply widget :value-to-external answer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 (defvar widget-edit-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137 (defun widget-field-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 ;; Edit the value in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 (let* ((invalid (widget-apply widget :validate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 (prompt (concat (widget-apply widget :menu-tag-get) ": "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 (value (unless invalid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 (answer (widget-apply widget :prompt-value prompt value invalid)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 (unless (equal value answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 ;; This is a hack. We can't properly validate the widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 ;; because validation requires the new value to be in the field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 ;; However, widget-field-value-create will not function unless
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 ;; the new value matches. So, we check whether the thing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 ;; matches, and if it does, use either the real or a dummy error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 ;; message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 (unless (widget-apply widget :match answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 (let ((error-message (or (widget-get widget :type-error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 "Invalid field contents")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 (widget-put widget :error error-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 (error error-message)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 (widget-setup))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 (run-hook-with-args 'widget-edit-functions widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 ;(defun widget-field-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 ; ;; Move to next field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 ; (widget-forward 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 ; (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 (defun widget-field-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 ;; Valid if the content matches `:valid-regexp'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 (let ((value (widget-apply widget :value-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 (regexp (widget-get widget :valid-regexp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 (if (string-match regexp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 (defun widget-field-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 ;; Create an editable text field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 (let ((size (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 (value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 ;; This is changed to a real extent in `widget-setup'. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 ;; need the end points to behave differently until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 ;; `widget-setup' is called. Should probably be replaced with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 ;; a genuine extent, but some things break, then.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 (extent (cons (make-marker) (make-marker))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 (widget-put widget :field-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 (insert value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 (and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 (< (length value) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 (insert-char ?\ (- size (length value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 (unless (memq widget widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 (push widget widget-field-new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 (move-marker (cdr extent) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 (set-marker-insertion-type (cdr extent) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 (when (null size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 (insert ?\n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 (move-marker (car extent) from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 (set-marker-insertion-type (car extent) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 (defun widget-field-value-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 ;; Remove the widget from the list of active editing fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 (setq widget-field-list (delq widget widget-field-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 ;; These are nil if the :format string doesn't contain `%v'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 (when extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 (detach-extent extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 (defun widget-field-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 ;; Return current text in editing field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 (let ((from (widget-field-start widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 (to (widget-field-end widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 (buffer (widget-field-buffer widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 (size (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 (secret (widget-get widget :secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 (old (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 ((and from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 (while (and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 (not (zerop size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 (> to from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 (eq (char-after (1- to)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 (setq to (1- to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 (let ((result (buffer-substring-no-properties from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 (when secret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 (let ((index 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 (while (< (+ from index) to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 (aset result index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 (get-char-property (+ from index) 'secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 (incf index))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 (set-buffer old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 (widget-get widget :value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 (defun widget-field-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 ;; Match any string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 (stringp value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 ;;; The `text' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 (define-widget 'text 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 :keymap widget-text-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 "A multiline text area.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 ;;; The `menu-choice' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 (define-widget 'menu-choice 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 "A menu of options."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 :format "%[%t%]: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 :case-fold t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 :tag "choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 :void '(item :format "invalid (%t)\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 :value-create 'widget-choice-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 :value-get 'widget-choice-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 :value-inline 'widget-choice-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 :default-get 'widget-choice-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 :mouse-down-action 'widget-choice-mouse-down-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 :action 'widget-choice-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 :error "Make a choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 :validate 'widget-choice-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 :match 'widget-choice-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 :match-inline 'widget-choice-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 (defun widget-choice-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 ;; Insert the first choice that matches the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 (let ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 (args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 (explicit (widget-get widget :explicit-choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 (if explicit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 (widget-put widget :children (list (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 widget explicit value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 (widget-put widget :choice explicit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 (when (widget-apply current :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 (widget-put widget :children (list (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 widget current value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 (widget-put widget :choice current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 (setq args nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 current nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 (when current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 (let ((void (widget-get widget :void)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 (widget-put widget :children (list (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 widget void :value value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 (widget-put widget :choice void))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 (defun widget-choice-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 (widget-value (car (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 (defun widget-choice-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 (widget-apply (car (widget-get widget :children)) :value-inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 (defun widget-choice-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 ;; Get default for the first choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 (widget-default-get (car (widget-get widget :args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 (defcustom widget-choice-toggle nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 "If non-nil, a binary choice will just toggle between the values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 Otherwise, the user will explicitly have to choose between the values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 when he invoked the menu."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 (defun widget-choice-mouse-down-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 ;; Return non-nil if we need a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 (old (widget-get widget :choice)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 (cond ((not (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 ;; No place to pop up a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 ((< (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 ;; Empty or singleton list, just return the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 ((> (length args) widget-menu-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 ;; Too long, prompt.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 ((> (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 ;; Reasonable sized list, use menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 ((and widget-choice-toggle (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 ;; We toggle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 ;; Ask which of the two.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 (defun widget-choice-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 ;; Make a choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 (old (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 (tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 (completion-ignore-case (widget-get widget :case-fold))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 current choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 ;; Remember old value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 (if (and old (not (widget-apply widget :validate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 (let* ((external (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 (internal (widget-apply old :value-to-internal external)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 (widget-put old :value internal)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 ;; Find new choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 (setq current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 (cond ((= (length args) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 ((= (length args) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 ((and widget-choice-toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 (= (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 (if (eq old (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 (nth 1 args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 (setq choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 (cons (cons (widget-apply current :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 (let ((choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 (widget-choose tag (reverse choices) event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 (widget-put widget :explicit-choice choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 choice))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 (when current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 (let ((value (widget-default-get current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 (widget-value-set widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 (widget-apply current :value-to-external value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 (widget-apply widget :notify widget event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 (defun widget-choice-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 ;; Valid if we have made a valid choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 (let ((void (widget-get widget :void))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 (choice (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 (child (car (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 (if (eq void choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 (widget-apply child :validate))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 (defun widget-choice-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 ;; Matches if one of the choices matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 (while (and args (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 found (widget-apply current :match value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 (defun widget-choice-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 ;; Matches if one of the choices matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 (while (and args (null found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 found (widget-match-inline current values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 ;;; The `toggle' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 (define-widget 'toggle 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 "Toggle between two states."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 :format "%[%v%]\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 :value-create 'widget-toggle-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 :action 'widget-toggle-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 :match (lambda (widget value) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 :on "on"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 :off "off")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 (defun widget-toggle-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 ;; Insert text representing the `on' and `off' states.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 (widget-glyph-insert widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 (widget-get widget :on)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 (widget-get widget :on-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 (widget-glyph-insert widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 (widget-get widget :off)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 (widget-get widget :off-glyph))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 (defun widget-toggle-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 ;; Toggle value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 (widget-value-set widget (not (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 ;;; The `checkbox' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 (define-widget 'checkbox 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 "A checkbox toggle."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 :on "[X]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 :on-glyph "check1"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 :off "[ ]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 :off-glyph "check0"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 :action 'widget-checkbox-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 (defun widget-checkbox-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 "Toggle checkbox, notify parent, and set active state of sibling."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 (widget-toggle-action widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 (let ((sibling (widget-get-sibling widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 (when sibling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 (widget-apply sibling :activate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 (widget-apply sibling :deactivate)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 ;;; The `checklist' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 (define-widget 'checklist 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 "A multiple choice widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 :offset 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 :entry-format "%b %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 :menu-tag "checklist"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 :greedy nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 :value-create 'widget-checklist-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 :value-get 'widget-checklist-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 :validate 'widget-checklist-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 :match 'widget-checklist-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 :match-inline 'widget-checklist-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 (defun widget-checklist-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 (args (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 (widget-checklist-add-item widget (car args) (assq (car args) alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 (widget-put widget :children (nreverse (widget-get widget :children)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 (defun widget-checklist-add-item (widget type chosen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 ;; Create checklist item in WIDGET of type TYPE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 ;; If the item is checked, CHOSEN is a cons whose cdr is the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 (let* ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 (button-args (or (widget-get type :sibling-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 (widget-get widget :button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 (insert (widget-get widget :entry-format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 (while (re-search-forward "%\\([bv%]\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 (cond ((eq escape ?%)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 (insert "%"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 ((eq escape ?b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 (setq button (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 widget 'checkbox
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 :value (not (null chosen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 (setq child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 (cond ((not chosen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 (let ((child (widget-create-child widget type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 (widget-apply child :deactivate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 ((widget-get type :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 widget type (cdr chosen)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 widget type (car (cdr chosen)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 ;; Update properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 (and button child (widget-put child :button button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 (and button (widget-put widget :buttons (cons button buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 (and child (widget-put widget :children (cons child children))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 (defun widget-checklist-match (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 ;; All values must match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 (and (listp values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 (null (cdr (widget-checklist-match-inline widget values)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 (defun widget-checklist-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 ;; Find the values which match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 (let ((greedy (widget-get widget :greedy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 (args (copy-sequence (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 found rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 (while values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 (let ((answer (widget-checklist-match-up args values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 (cond (answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 (let ((vals (widget-match-inline answer values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 (setq found (append found (car vals))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 values (cdr vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 args (delq answer args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 (greedy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 (setq rest (append rest (list (car values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 values (cdr values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 (setq rest (append rest values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 values nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 (cons found rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 (defun widget-checklist-match-find (widget vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 ;; Find the vals which match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 ;; Return an alist of (TYPE MATCH).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 (let ((greedy (widget-get widget :greedy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 (args (copy-sequence (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 (while vals
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 (let ((answer (widget-checklist-match-up args vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 (cond (answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 (let ((match (widget-match-inline answer vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 (setq found (cons (cons answer (car match)) found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 vals (cdr match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 args (delq answer args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 (greedy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 (setq vals (cdr vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 (setq vals nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 (defun widget-checklist-match-up (args vals)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2572 ;; Return the first type from ARGS that matches VALS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 (let (current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 (while (and args (null found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 found (widget-match-inline current vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 (if found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 (defun widget-checklist-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 ;; The values of all selected items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 child result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 (if (widget-value (widget-get child :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 (setq result (append result (widget-apply child :value-inline)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 (defun widget-checklist-validate (widget)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2594 ;; Ticked children must be valid.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 child button found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 button (widget-get child :button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 found (and (widget-value button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 (widget-apply child :validate))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 ;;; The `option' Widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 (define-widget 'option 'checklist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 "An widget with an optional item."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 :inline t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 ;;; The `choice-item' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 (define-widget 'choice-item 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 "Button items that delegate action events to their parents."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 :action 'widget-parent-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 :format "%[%t%] \n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 ;;; The `radio-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 (define-widget 'radio-button 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 "A radio button for use in the `radio' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 :notify 'widget-radio-button-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 :on "(*)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 :on-glyph '("radio1" nil "radio0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 :off "( )"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 :off-glyph "radio0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 (defun widget-radio-button-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 ;; Tell daddy.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 (widget-apply (widget-get widget :parent) :action widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 ;;; The `radio-button-choice' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 (define-widget 'radio-button-choice 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 "Select one of multiple options."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 :offset 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 :entry-format "%b %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 :menu-tag "radio"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 :value-create 'widget-radio-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 :value-get 'widget-radio-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 :value-inline 'widget-radio-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 :value-set 'widget-radio-value-set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 :error "You must push one of the buttons"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 :validate 'widget-radio-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 :match 'widget-choice-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 :match-inline 'widget-choice-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 :action 'widget-radio-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 (defun widget-radio-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 (setq arg (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 (widget-radio-add-item widget arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 (defun widget-radio-add-item (widget type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 "Add to radio widget WIDGET a new radio button item of type TYPE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 ;; (setq type (widget-convert type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 (let* ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 (children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 (button-args (or (widget-get type :sibling-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 (widget-get widget :button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 (chosen (and (null (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 (widget-apply type :match value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 (insert (widget-get widget :entry-format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 (while (re-search-forward "%\\([bv%]\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 (cond ((eq escape ?%)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 (insert "%"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 ((eq escape ?b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 (setq button (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 widget 'radio-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 :value (not (null chosen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 (setq child (if chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 widget type value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 (widget-create-child widget type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 (unless chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 (widget-apply child :deactivate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 ;; Update properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 (when chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 (widget-put widget :choice type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 (when button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 (widget-put child :button button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 (widget-put widget :buttons (nconc buttons (list button))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 (when child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 (widget-put widget :children (nconc children (list child))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 (defun widget-radio-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 (let ((chosen (widget-radio-chosen widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 (and chosen (widget-value chosen))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 (defun widget-radio-chosen (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 "Return the widget representing the chosen radio button."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 (let* ((button (widget-get current :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 (value (widget-apply button :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 (when value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 (setq found current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 children nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 (defun widget-radio-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 (let* ((button (widget-get current :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 (value (widget-apply button :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 (when value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 (setq found (widget-apply current :value-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 children nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 (defun widget-radio-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 ;; We can't just delete and recreate a radio widget, since children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 ;; can be added after the original creation and won't be recreated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 ;; by `:create'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 (let* ((button (widget-get current :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 (match (and (not found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 (widget-apply current :match value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 (widget-value-set button match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 (if match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 (widget-value-set current value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 (widget-apply current :activate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 (widget-apply current :deactivate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 (setq found (or found match))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 (defun widget-radio-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 ;; Valid if we have made a valid choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 current found button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 button (widget-get current :button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 found (widget-apply button :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 (if found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 (widget-apply current :validate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 (defun widget-radio-action (widget child event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 ;; Check if a radio button was pressed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 (when (memq child buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 (let* ((button (widget-get current :button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 (cond ((eq child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 (widget-value-set button t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 (widget-apply current :activate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 ((widget-value button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 (widget-value-set button nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 (widget-apply current :deactivate)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 ;; Pass notification to parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 (widget-apply widget :notify child event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 ;;; The `insert-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 (define-widget 'insert-button 'push-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 "An insert button for the `editable-list' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 :tag "INS"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 :help-echo "Insert a new item into the list at this position"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 :action 'widget-insert-button-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 (defun widget-insert-button-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 ;; Ask the parent to insert a new item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 (widget-apply (widget-get widget :parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 :insert-before (widget-get widget :widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 ;;; The `delete-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 (define-widget 'delete-button 'push-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 "A delete button for the `editable-list' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 :tag "DEL"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 :help-echo "Delete this item from the list"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 :action 'widget-delete-button-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 (defun widget-delete-button-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 ;; Ask the parent to insert a new item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 (widget-apply (widget-get widget :parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 :delete-at (widget-get widget :widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 ;;; The `editable-list' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 (defcustom widget-editable-list-gui nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 "If non nil, use GUI push-buttons in editable list when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 (define-widget 'editable-list 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 "A variable list of widgets of the same type."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 :offset 12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 :format "%v%i\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 :format-handler 'widget-editable-list-format-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 :entry-format "%i %d %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 :menu-tag "editable-list"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 :value-create 'widget-editable-list-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 :value-get 'widget-editable-list-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 :validate 'widget-children-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 :match 'widget-editable-list-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 :match-inline 'widget-editable-list-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 :insert-before 'widget-editable-list-insert-before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 :delete-at 'widget-editable-list-delete-at)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 (defun widget-editable-list-format-handler (widget escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 ;; We recognize the insert button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 (let ((widget-push-button-gui widget-editable-list-gui))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 (cond ((eq escape ?i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 (and (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 widget 'insert-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 (widget-get widget :append-button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 (widget-default-format-handler widget escape)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 (defun widget-editable-list-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 (let* ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 (type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 (inlinep (widget-get type :inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 (widget-put widget :value-pos (copy-marker (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 (set-marker-insertion-type (widget-get widget :value-pos) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 (while value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 (let ((answer (widget-match-inline type value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 (setq children (cons (widget-editable-list-entry-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 (if inlinep
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 (car answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 (car (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 (setq value nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 (widget-put widget :children (nreverse children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 (defun widget-editable-list-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 (defun widget-editable-list-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 ;; Value must be a list and all the members must match the type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 (and (listp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 (null (cdr (widget-editable-list-match-inline widget value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 (defun widget-editable-list-match-inline (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 (let ((type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 (ok t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 (while (and value ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 (let ((answer (widget-match-inline type value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 (setq found (append found (car answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 (setq ok nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 (cons found value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 (defun widget-editable-list-insert-before (widget before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 ;; Insert a new child in the list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 (cond (before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 (goto-char (widget-get before :entry-from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 (goto-char (widget-get widget :value-pos))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 (let ((child (widget-editable-list-entry-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 widget nil nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 (when (< (widget-get child :entry-from) (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 (set-marker (widget-get widget :from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 (widget-get child :entry-from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 (if (eq (car children) before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 (widget-put widget :children (cons child children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 (while (not (eq (car (cdr children)) before))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 (setq children (cdr children)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 (setcdr children (cons child (cdr children)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 (widget-apply widget :notify widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 (defun widget-editable-list-delete-at (widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 ;; Delete child from list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 (let ((buttons (copy-sequence (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 (while buttons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 (setq button (car buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 buttons (cdr buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 (when (eq (widget-get button :widget) child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 :buttons (delq button (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 (widget-delete button))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 (let ((entry-from (widget-get child :entry-from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 (entry-to (widget-get child :entry-to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 (widget-delete child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 (delete-region entry-from entry-to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 (set-marker entry-from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 (set-marker entry-to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 (widget-put widget :children (delq child (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 (widget-apply widget :notify widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 (defun widget-editable-list-entry-create (widget value conv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 ;; Create a new entry to the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 (let ((type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 (widget-push-button-gui widget-editable-list-gui)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 child delete insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 (and (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 (insert (widget-get widget :entry-format)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 (while (re-search-forward "%\\(.\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 (cond ((eq escape ?%)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 (insert "%"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 ((eq escape ?i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 (setq insert (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 widget 'insert-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 (widget-get widget :insert-button-args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 ((eq escape ?d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 (setq delete (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 widget 'delete-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 (widget-get widget :delete-button-args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 (if conv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 (setq child (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 widget type value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 (setq child (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 widget type (widget-default-get type)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 :buttons (cons delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 (cons insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 (widget-get widget :buttons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 (let ((entry-from (copy-marker (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 (entry-to (copy-marker (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 (set-marker-insertion-type entry-from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 (set-marker-insertion-type entry-to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 (widget-put child :entry-from entry-from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 (widget-put child :entry-to entry-to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 (widget-put insert :widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 (widget-put delete :widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 ;;; The `group' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 (define-widget 'group 'default
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3004 "A widget which groups other widgets inside."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 :value-create 'widget-group-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 :value-get 'widget-editable-list-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 :default-get 'widget-group-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 :validate 'widget-children-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 :match 'widget-group-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 :match-inline 'widget-group-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 (defun widget-group-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 ;; Create each component.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 (value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 arg answer children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 (setq arg (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 answer (widget-match-inline arg value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 (push (cond ((null answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 (widget-create-child widget arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 ((widget-get arg :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 (widget-create-child-value widget arg (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 (widget-create-child-value widget arg (car (car answer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 (widget-put widget :children (nreverse children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 (defun widget-group-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 ;; Get the default of the components.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 (mapcar 'widget-default-get (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 (defun widget-group-match (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 ;; Match if the components match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 (and (listp values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 (let ((match (widget-group-match-inline widget values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 (and match (null (cdr match))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 (defun widget-group-match-inline (widget vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 ;; Match if the components match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 argument answer found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 (setq argument (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 answer (widget-match-inline argument vals))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 (setq vals (cdr answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 found (append found (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 (setq vals nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 args nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 (cons found vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 ;;; The `visibility' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 (define-widget 'visibility 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 "An indicator and manipulator for hidden items."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 :on "Hide"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 :off "Show"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 :value-create 'widget-visibility-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 :action 'widget-toggle-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 :match (lambda (widget value) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 (defun widget-visibility-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 ;; Insert text representing the `on' and `off' states.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 (let ((on (widget-get widget :on))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 (off (widget-get widget :off)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 (if on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 (setq on (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 widget-push-button-suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 (setq on ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 (if off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087 (setq off (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 widget-push-button-suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 (setq off ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 (widget-glyph-insert widget on '("down" "down-pushed"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 (widget-glyph-insert widget off '("right" "right-pushed")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 ;;; The `documentation-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 ;; This is a helper widget for `documentation-string'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 (define-widget 'documentation-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 "Link type used in documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 :tab-order -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 :help-echo 'widget-documentation-link-echo-help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 :action 'widget-documentation-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 (defun widget-documentation-link-echo-help (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 "Tell what this link will describe."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 (concat "Describe the `" (widget-get widget :value) "' symbol."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 (defun widget-documentation-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 "Display documentation for WIDGET's value. Ignore optional argument EVENT."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 (let* ((string (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 (symbol (intern string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 (if (and (fboundp symbol) (boundp symbol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 ;; If there are two doc strings, give the user a way to pick one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 (apropos (concat "\\`" (regexp-quote string) "\\'"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 (if (fboundp symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 (describe-function symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 (describe-variable symbol)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 (defcustom widget-documentation-links t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 "Add hyperlinks to documentation strings when non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 (defcustom widget-documentation-link-regexp "`\\([^\n`' ]+\\)'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 "Regexp for matching potential links in documentation strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 The first group should be the link itself."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 :type 'regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 (defcustom widget-documentation-link-p 'intern-soft
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 "Predicate used to test if a string is useful as a link.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 The value should be a function. The function will be called one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 argument, a string, and should return non-nil if there should be a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 link for that string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 :options '(widget-documentation-link-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 (defcustom widget-documentation-link-type 'documentation-link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 "Widget type used for links in documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 :type 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 (defun widget-documentation-link-add (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 (widget-specify-doc widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 (when widget-documentation-links
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 (let ((regexp widget-documentation-link-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 (predicate widget-documentation-link-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 (type widget-documentation-link-type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 (buttons (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 (while (re-search-forward regexp to t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 (let ((name (match-string 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 (begin (match-beginning 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 (end (match-end 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158 (when (funcall predicate name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 (push (widget-convert-button type begin end :value name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160 buttons)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 (widget-put widget :buttons buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 (let ((indent (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 (when (and indent (not (zerop indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 (narrow-to-region from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 (while (search-forward "\n" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 (insert-char ?\ indent)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171 ;;; The `documentation-string' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 (define-widget 'documentation-string 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 "A documentation string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 :action 'widget-documentation-string-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 :value-create 'widget-documentation-string-value-create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180 (defun widget-documentation-string-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 ;; Insert documentation string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 (let ((doc (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 (indent (widget-get widget :indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 (shown (widget-get (widget-get widget :parent) :documentation-shown))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 (start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 (if (string-match "\n" doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 (let ((before (substring doc 0 (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 (after (substring doc (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 (insert before " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 (widget-documentation-link-add widget start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 (push (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 widget 'visibility
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 :help-echo (lambda (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 "Hide" "Show")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 " the rest of the documentation"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 :off "More"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 :action 'widget-parent-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 shown)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 (when shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 (when indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206 (insert-char ?\ indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 (insert after)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 (widget-documentation-link-add widget start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 (widget-put widget :buttons buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 (insert doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 (widget-documentation-link-add widget start (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 (insert "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 (defun widget-documentation-string-action (widget &rest ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 ;; Toggle documentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 (widget-put parent :documentation-shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 (not (widget-get parent :documentation-shown))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 ;; Redraw.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 (widget-value-set widget (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 ;;; The Sexp Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 (define-widget 'const 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 "An immutable sexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 :prompt-value 'widget-const-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 :format "%t\n%d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 (defun widget-const-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 ;; Return the value of the const.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 (define-widget 'function-item 'const
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 "An immutable function name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 :format "%v\n%h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 :documentation-property (lambda (symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 (documentation symbol t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 (define-widget 'variable-item 'const
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 "An immutable variable name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 :format "%v\n%h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 :documentation-property 'variable-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 (defvar widget-string-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 "History of input to `widget-string-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 (define-widget 'string 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 "A string"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 :tag "String"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 :complete-function 'ispell-complete-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 :prompt-history 'widget-string-prompt-value-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 (define-widget 'regexp 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 "A regular expression."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 :match 'widget-regexp-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 :validate 'widget-regexp-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 ;; Doesn't work well with terminating newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 ;; :value-face 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 :tag "Regexp")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 (defun widget-regexp-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 ;; Match valid regexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 (and (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 (prog1 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 (string-match value ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 (defun widget-regexp-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 "Check that the value of WIDGET is a valid regexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 (let ((value (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 (condition-case data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 (prog1 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 (string-match value ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 (error (widget-put widget :error (error-message-string data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 (define-widget 'file 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 "A file widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 It will read a file name from the minibuffer when invoked."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 :complete-function 'widget-file-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 :prompt-value 'widget-file-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 ;; Doesn't work well with terminating newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 ;; :value-face 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 :tag "File")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 (defun widget-file-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 "Perform completion on file name preceding point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 (let* ((end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295 (beg (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 (skip-chars-backward "^ ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 (pattern (buffer-substring beg end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 (name-part (file-name-nondirectory pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 (directory (file-name-directory pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 (completion (file-name-completion name-part directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 (cond ((eq completion t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304 (message "Can't find completion for \"%s\"" pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 (ding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 ((not (string= name-part completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 (delete-region beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 (insert (expand-file-name completion directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 (message "Making completion list...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 (let ((list (file-name-all-completions name-part directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 (setq list (sort list 'string<))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 (with-output-to-temp-buffer "*Completions*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 (display-completion-list list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 (message "Making completion list...%s" "done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 (defun widget-file-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 ;; Read file from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 (abbreviate-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 (if unbound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 (read-file-name prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 (let ((prompt2 (format "%s (default %s) " prompt value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 (dir (file-name-directory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 (file (file-name-nondirectory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 (must-match (widget-get widget :must-match)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 (read-file-name prompt2 dir nil must-match file)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 ;;;(defun widget-file-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 ;;; ;; Read a file name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330 ;;; (let* ((value (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 ;;; (dir (file-name-directory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 ;;; (file (file-name-nondirectory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 ;;; (menu-tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 ;;; (must-match (widget-get widget :must-match))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 ;;; (answer (read-file-name (concat menu-tag ": (default `" value "') ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 ;;; dir nil must-match file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 ;;; (widget-value-set widget (abbreviate-file-name answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 ;;; (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 ;;; (widget-apply widget :notify widget event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 (define-widget 'directory 'file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 "A directory widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 It will read a directory name from the minibuffer when invoked."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 :tag "Directory")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 (defvar widget-symbol-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 "History of input to `widget-symbol-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 (define-widget 'symbol 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 "A lisp symbol."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 :value nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 :tag "Symbol"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 :match (lambda (widget value) (symbolp value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 :complete-function 'lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 :prompt-internal 'widget-symbol-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 :prompt-match 'symbolp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 :prompt-history 'widget-symbol-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 (symbol-name value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 (intern value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 (defun widget-symbol-prompt-internal (widget prompt initial history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 ;; Read file from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 (let ((answer (completing-read prompt obarray
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 (widget-get widget :prompt-match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 nil initial history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 (if (and (stringp answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 (not (zerop (length answer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 (error "No value"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 (defvar widget-function-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 "History of input to `widget-function-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 (define-widget 'function 'sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 "A lisp function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 :complete-function 'lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 :prompt-value 'widget-field-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 :prompt-internal 'widget-symbol-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 :prompt-match 'fboundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 :prompt-history 'widget-function-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 :action 'widget-field-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 :tag "Function")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 (defvar widget-variable-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 "History of input to `widget-variable-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 (define-widget 'variable 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 ;; Should complete on variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 "A lisp variable."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 :prompt-match 'boundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 :prompt-history 'widget-variable-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 :tag "Variable")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 ;; This part issues a warning when compiling without Mule. Is there a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 ;; way of shutting it up?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 ;; OK, I'll simply comment the whole thing out, until someone decides
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 ;; to do something with it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 ;(defvar widget-coding-system-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 ; "History of input to `widget-coding-system-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 ;(define-widget 'coding-system 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 ; "A MULE coding-system."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 ; :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 ; :tag "Coding system"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413 ; :prompt-history 'widget-coding-system-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 ; :prompt-value 'widget-coding-system-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 ; :action 'widget-coding-system-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 ;(defun widget-coding-system-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 ; ;; Read coding-system from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 ; (intern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 ; (completing-read (format "%s (default %s) " prompt value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 ; (mapcar (lambda (sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 ; (list (symbol-name sym)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 ; (coding-system-list)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 ;(defun widget-coding-system-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 ; ;; Read a file name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 ; (let ((answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 ; (widget-coding-system-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 ; widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 ; (widget-apply widget :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 ; (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 ; t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 ; (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 ; (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 ; (widget-setup)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 (define-widget 'sexp 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 "An arbitrary lisp expression."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 :tag "Lisp expression"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 :value nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 :validate 'widget-sexp-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 :match (lambda (widget value) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 :value-to-internal 'widget-sexp-value-to-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 :value-to-external (lambda (widget value) (read value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446 :prompt-history 'widget-sexp-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 :prompt-value 'widget-sexp-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449 (defun widget-sexp-value-to-internal (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 ;; Use cl-prettyprint for printer representation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 (let ((pp (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 (prin1-to-string value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453 (widget-prettyprint-to-string value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 (if (> (length pp) 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 (concat "\n" pp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 pp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 (defun widget-sexp-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459 ;; Valid if we can read the string and there is no junk left after it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 (insert (widget-apply widget :value-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465 (condition-case data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 (let ((value (read buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 (if (widget-apply widget :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 (widget-put widget :error (widget-get widget :type-error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 :error (format "Junk at end of expression: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 (buffer-substring (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475 (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 (error (widget-put widget :error (error-message-string data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 widget)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 (defvar widget-sexp-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 "History of input to `widget-sexp-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 (defun widget-sexp-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 ;; Read an arbitrary sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 (let ((found (read-string prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 (if unbound nil (cons (prin1-to-string value) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 (widget-get widget :prompt-history))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 (insert found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 (let ((answer (read buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 (unless (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 (signal 'error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 (list "Junk at end of expression"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 (buffer-substring (point) (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 answer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 (define-widget 'restricted-sexp 'sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 "A Lisp expression restricted to values that match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 To use this type, you must define :match or :match-alternatives."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 :type-error "The specified value is not valid"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 :match 'widget-restricted-sexp-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 (if (widget-apply widget :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 (prin1-to-string value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 (defun widget-restricted-sexp-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 (let ((alternatives (widget-get widget :match-alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512 matched)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 (while (and alternatives (not matched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 (if (cond ((functionp (car alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 (funcall (car alternatives) value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 ((and (consp (car alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 (eq (car (car alternatives)) 'quote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 (eq value (nth 1 (car alternatives)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 (setq matched t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 (setq alternatives (cdr alternatives)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 matched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 (define-widget 'integer 'restricted-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 "An integer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 :tag "Integer"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 :value 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 :type-error "This field should contain an integer"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 :match-alternatives '(integerp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 (define-widget 'number 'restricted-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 "A floating point number."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 :tag "Number"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 :value 0.0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 :type-error "This field should contain a number"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 :match-alternatives '(numberp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 (define-widget 'character 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 "A character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 :tag "Character"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 :value ?\0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 :valid-regexp "\\`[\0-\377]\\'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 :error "This field should contain a single character"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 (char-to-string value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 (aref value 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552 :match (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 (characterp value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 (define-widget 'list 'group
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3556 "A Lisp list."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 :tag "List"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 :format "%{%t%}:\n%v")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 (define-widget 'vector 'group
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3561 "A Lisp vector."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 :tag "Vector"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 :match 'widget-vector-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 :value-to-internal (lambda (widget value) (append value nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566 :value-to-external (lambda (widget value) (vconcat value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 (defun widget-vector-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 (and (vectorp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 (widget-group-match widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 (widget-apply widget :value-to-internal value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 (define-widget 'cons 'group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 "A cons-cell."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 :tag "Cons-cell"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 :match 'widget-cons-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 (list (car value) (cdr value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 (cons (car value) (cadr value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 (defun widget-cons-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 (and (consp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 (widget-group-match widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 (widget-apply widget :value-to-internal value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 (define-widget 'choice 'menu-choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 "A union of several sexp types."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 :tag "Choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 :format "%{%t%}: %[Value Menu%] %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 :button-prefix 'widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 :button-suffix 'widget-push-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 :prompt-value 'widget-choice-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 (defun widget-choice-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 "Make a choice."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 (completion-ignore-case (widget-get widget :case-fold))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 current choices old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 ;; Find the first arg that match VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 (let ((look args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 (while look
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 (if (widget-apply (car look) :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 (setq old (car look)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 look nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 (setq look (cdr look)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 ;; Find new choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 (setq current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 (cond ((= (length args) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 ((= (length args) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 ((and (= (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 (if (eq old (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 (nth 1 args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 (setq choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 (cons (cons (widget-apply current :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 (let ((val (completing-read prompt choices nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 (if (stringp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 (let ((try (try-completion val choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 (when (stringp try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 (setq val try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 (cdr (assoc val choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 (if current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 (widget-prompt-value current prompt nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3638 (define-widget 'radio 'radio-button-choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 "A union of several sexp types."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 :tag "Choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 :prompt-value 'widget-choice-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 (define-widget 'repeat 'editable-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 "A variable length homogeneous list."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 :tag "Repeat"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647 :format "%{%t%}:\n%v%i\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 (define-widget 'set 'checklist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 "A list of members from a fixed set."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 :tag "Set"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 :format "%{%t%}:\n%v")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654 (define-widget 'boolean 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 "To be nil or non-nil, that is the question."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656 :tag "Boolean"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3657 :prompt-value 'widget-boolean-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658 :button-prefix 'widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 :button-suffix 'widget-push-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3660 :format "%{%t%}: %[Toggle%] %v\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661 :on "on (non-nil)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 :off "off (nil)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3664 (defun widget-boolean-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 ;; Toggle a boolean.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 (y-or-n-p prompt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668 ;;; The `color' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 (define-widget 'color 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 "Choose a color name (with sample)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 :format "%[%t%]: %v (%{sample%})\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673 :size 10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 :tag "Color"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 :value "black"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3676 :complete 'widget-color-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677 :sample-face-get 'widget-color-sample-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 :notify 'widget-color-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 :action 'widget-color-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 (defun widget-color-complete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 "Complete the color in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683 (let* ((prefix (buffer-substring-no-properties (widget-field-start widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685 (list (read-color-completion-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 (completion (try-completion prefix list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 (cond ((eq completion t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 (message "Exact match"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 (error "Can't find completion for \"%s\"" prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 ((not (string-equal prefix completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692 (insert (substring completion (length prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 (message "Making completion list...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3695 (let ((list (all-completions prefix list nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696 (with-output-to-temp-buffer "*Completions*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 (display-completion-list list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 (message "Making completion list...done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700 (defun widget-color-sample-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 (or (widget-get widget :sample-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3702 (let ((color (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 (face (make-face (gensym "sample-face-") nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704 ;; Use the face object, not its name, to prevent lossage if gc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705 ;; happens before applying the face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 (widget-put widget :sample-face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3707 (and color
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708 (not (equal color ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3709 (valid-color-name-p color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 (set-face-foreground face color))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 (defvar widget-color-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 "History of entered colors.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 (defun widget-color-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717 ;; Prompt for a color.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 (let* ((tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 (answer (read-color (concat tag ": "))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 (unless (zerop (length answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 (widget-apply widget :notify widget event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 (defun widget-color-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726 "Update the sample, and notify the parent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 (let* ((face (widget-apply widget :sample-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 (color (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 (if (valid-color-name-p color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730 (set-face-foreground face color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 (remove-face-property face 'foreground)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732 (widget-default-notify widget child event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 ;; Is this a misnomer?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735 (defun widget-at (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 "The button or field at POS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 (or (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738 (get-char-property pos 'field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 (defun widget-echo-help (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741 "Display the help echo for widget at POS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742 (let* ((widget (widget-at pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3744 (and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745 (setq help-echo (funcall help-echo widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746 (when (stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3747 (display-message 'help-echo help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3749 ;;; The End:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3751 (provide 'wid-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3753 ;; wid-edit.el ends here