annotate lisp/wid-edit.el @ 1313:671b65f2b075

[xemacs-hg @ 2003-02-20 01:12:25 by ben] patch for crashes when deleting frames eval.c: Don't check_quit() unless we're unbinding a real Lisp `unwind-protect' since check_quit() does lots of weird things and not all callers are prepared for it. frame.c: Make absolutely sure there is no quit checking while we are in a "critical section" during frame deletion.
author ben
date Thu, 20 Feb 2003 01:12:26 +0000
parents 00abb1091204
children 1b0339b048ce
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 ;;
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3 ;; Copyright (C) 1996-1997, 1999-2002 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 ;;
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
30 ;; See `widget.el' and the wishlist in `../man/widget.texi'.
428
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
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
61 "Face used for documentation strings in widgets.
428
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
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
76 "Face used for buttons in widgets.
428
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
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
88 ;; #### comment from GNU Emacs 21.3.50, test the first spec.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
89 ;; TTY gets special definitions here and in the next defface, because
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
90 ;; the gray colors defined for other displays cause black text on a black
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
91 ;; background, at least on light-background TTYs.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
92 (defface widget-field-face '((((type tty))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
93 (:background "yellow3")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
94 (:foreground "black"))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
95 (((class grayscale color)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 (:background "gray85"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 (:background "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 "Face used for editable fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 ;; Currently unused
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 ;(defface widget-single-line-field-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ; (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ; (:background "gray85"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ; (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ; (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ; (:background "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ; (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ; (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ; "Face used for editable fields spanning only a single line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ; :group 'widget-faces)
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 ;(defvar widget-single-line-display-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ; (let ((table (make-display-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ; (aset table 9 "^I")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 ; (aset table 10 "^J")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ; table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ; "Display table used for single-line editable fields.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 ;(set-face-display-table 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 ; widget-single-line-display-table)
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 ;; Some functions from this file have been ported to C for speed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 ;; Setting this to t (*before* loading wid-edit.el) will make them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 ;; shadow the subrs. It should be used only for debugging purposes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 (defvar widget-shadow-subrs nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 ;;; Utility functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ;; These are not really widget specific.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (when (or (not (fboundp 'widget-plist-member))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 ;; 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
142 ;; compiled code won't fail -- it will just be slower.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (defun widget-plist-member (plist prop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 ;; Return non-nil if PLIST has the property PROP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 ;; PLIST is a property list, which is a list of the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 ;; (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 ;; Unlike `plist-get', this allows you to distinguish between a missing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 ;; property and a property with the value nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 ;; The value is actually the tail of PLIST whose car is PROP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (while (and plist (not (eq (car plist) prop)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (setq plist (cddr plist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (defun widget-princ-to-string (object)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
155 "Return string representation of OBJECT, any Lisp object.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
156 No quoting characters are used; no delimiters are printed around
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
157 the contents of strings."
428
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 (princ object (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (buffer-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (defun widget-prettyprint-to-string (object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 ;; Like pp-to-string, but uses `cl-prettyprint'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (with-current-buffer (get-buffer-create " *widget-tmp*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (cl-prettyprint object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 ;; `cl-prettyprint' always surrounds the text with newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (when (eq (char-after (point-min)) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (delete-region (point-min) (1+ (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (when (eq (char-before (point-max)) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (delete-region (1- (point-max)) (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (buffer-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (defun widget-clear-undo ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 "Clear all undo information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (buffer-disable-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (buffer-enable-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (defcustom widget-menu-max-size 40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 "Largest number of items allowed in a popup-menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 Larger menus are read through the minibuffer."
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 'integer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
186 (defcustom widget-menu-max-shortcuts 40
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
187 "Largest number of items for which it works to choose one with a character.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
188 For a larger number of items, the minibuffer is used.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
189 #### Not yet implemented in XEmacs."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
190 :group 'widgets
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
191 :type 'integer)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
192
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 (defcustom widget-menu-minibuffer-flag nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 "*Control how to ask for a choice from the keyboard.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 Non-nil means use the minibuffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 nil means read a single character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (defun widget-choose (title items &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 "Choose an item from a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 First argument TITLE is the name of the list.
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
204 Second argument ITEMS is a list whose members are either
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (NAME . VALUE), to indicate selectable items, or just strings to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 indicate unselectable items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 Optional third argument EVENT is an input event.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 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
210 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
211 mouse event, and the number of elements in items is less than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 `widget-menu-max-size', a popup menu will be used, otherwise the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (cond ((and (< (length items) widget-menu-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 ;; Pressed by the mouse.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (let ((val (get-popup-menu-response
724
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
219 (let ((menu-thingee
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (cons title
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (mapcar (lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (if (stringp x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (vector x nil nil)
724
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
224 (vector (car x)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
225 (list (car x)) ; 'eval 'quote
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
226 t)))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
227 items))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
228 ))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
229 (message "%s" menu-thingee)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
230 menu-thingee)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
231 )))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (setq val (and val
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (listp (event-object val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (stringp (car-safe (event-object val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (car (event-object val))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (cdr (assoc val items))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ((and (not widget-menu-minibuffer-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ;; Can't handle more than 10 items (as many digits)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (<= (length items) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 ;; Construct a menu of the choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 ;; and then use it for prompting for a single character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (let* ((overriding-terminal-local-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (map (make-sparse-keymap title))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (next-digit ?0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 some-choice-enabled value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 ;; Define SPC as a prefix char to get to this menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (define-key overriding-terminal-local-map " " map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (with-current-buffer (get-buffer-create " widget-choose")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (insert "Available choices:\n\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (dolist (choice items)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (when (consp choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (let* ((name (car choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (function (cdr choice)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (insert (format "%c = %s\n" next-digit name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (define-key map (vector next-digit) function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (setq some-choice-enabled t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 ;; Allocate digits to disabled alternatives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 ;; so that the digit of a given alternative never varies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (incf next-digit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (insert "\nC-g = Quit"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (or some-choice-enabled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (error "None of the choices is currently meaningful"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (define-key map [?\C-g] 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (define-key map [t] 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 ;(setcdr map (nreverse (cdr map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 ;; Unread a SPC to lead to our new menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (push (character-to-event ?\ ) unread-command-events)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 ;; Read a char with the menu, and return the result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 ;; that corresponds to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (save-window-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (display-buffer (get-buffer " widget-choose"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (let ((cursor-in-echo-area t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (setq value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (lookup-key overriding-terminal-local-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (read-key-sequence (concat title ": ") t)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (message "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (when (or (eq value 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (null value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (error "Canceled"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 ;; Read the choice of name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (setq items (remove-if 'stringp items))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (let ((val (completing-read (concat title ": ") items nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (if (stringp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (let ((try (try-completion val items)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (when (stringp try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (setq val try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (cdr (assoc val items)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
293 ;; GNU Emacs 21.3.50 uses this in `widget-choose'
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
294 (defun widget-remove-if (predicate list)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
295 (let (result (tail list))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
296 (while tail
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
297 (or (funcall predicate (car tail))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
298 (setq result (cons (car tail) result)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
299 (setq tail (cdr tail)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
300 (nreverse result)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
301
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 ;;; Widget text specifications.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 ;; These functions are for specifying text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (defcustom widget-field-add-space t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 ;; Setting this to nil might be available, once some problems are resolved.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 "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
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 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
312 it will become impossible to edit a zero size field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (defcustom widget-field-use-before-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (and (or (> emacs-minor-version 34)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (> emacs-major-version 19))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (not (string-match "XEmacs" emacs-version)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 "Non-nil means use `before-change-functions' to track editable fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 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
322 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
323 new value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (defun widget-echo-this-extent (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (let* ((widget (or (extent-property extent 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (extent-property extent 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (extent-property extent 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (setq help-echo (funcall help-echo widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (when (stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (setq help-echo-owns-message t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (display-message 'help-echo help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (defsubst widget-handle-help-echo (extent help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (set-extent-property extent 'balloon-help help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (set-extent-property extent 'help-echo help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (when (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (set-extent-property extent 'balloon-help 'widget-echo-this-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (set-extent-property extent 'help-echo 'widget-echo-this-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (defun widget-specify-field (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 "Specify editable button for WIDGET between FROM and TO."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (goto-char to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (cond ((null (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (forward-char 1))
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
351 ;; #### This comment goes outside of the save-excursion in GNU
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 ;; Terminating space is not part of the field, but necessary in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 ;; 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
354 ;; at the end of the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (widget-field-add-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (insert-and-inherit " ")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (setq to (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (let ((map (widget-get widget :keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (face (or (widget-get widget :value-face) 'widget-field-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (help-echo (widget-get widget :help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (unless (or (stringp help-echo) (null help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (widget-put widget :field-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (and (or (not widget-field-add-space)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (set-extent-property extent 'end-closed nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (set-extent-property extent 'detachable nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (set-extent-property extent 'field widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (set-extent-property extent 'button-or-field t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (set-extent-property extent 'keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (widget-handle-help-echo extent help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (widget-specify-secret widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (defun widget-specify-secret (field)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
377 "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
378
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
379 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
380 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (let ((secret (widget-get field :secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (size (widget-get field :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (when secret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (let ((begin (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (end (widget-field-end field)))
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
386 (when size
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (while (and (> end begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (eq (char-after (1- end)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 (setq end (1- end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (while (< begin end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (let ((old (char-after begin)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (unless (eq old secret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (subst-char-in-region begin (1+ begin) old secret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 (put-text-property begin (1+ begin) 'secret old))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (setq begin (1+ begin))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (defun widget-specify-button (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 "Specify button for WIDGET between FROM and TO."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (let ((face (widget-apply widget :button-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (help-echo (widget-get widget :help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (extent (make-extent from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (map (widget-get widget :button-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (widget-put widget :button-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (unless (or (null help-echo) (stringp help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (setq help-echo 'widget-mouse-help))
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 'button widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (set-extent-property extent 'button-or-field t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (set-extent-property extent 'mouse-face widget-mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (widget-handle-help-echo extent help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (set-extent-property extent 'keymap map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (defun widget-mouse-help (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 "Find mouse help string for button in extent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (let* ((widget (widget-at (extent-start-position extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (cond ((stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 ((and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (stringp (setq help-echo (funcall help-echo widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (format "(widget %S :help-echo %S)" widget help-echo)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (defun widget-specify-sample (widget from to)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
427 "Specify sample for WIDGET between FROM and TO."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (let ((face (widget-apply widget :sample-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (extent (make-extent from to nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (widget-put widget :sample-extent extent)))
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 (defun widget-specify-doc (widget from to)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
435 "Specify documentation for WIDGET between FROM and TO."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (let ((extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (set-extent-property extent 'widget-doc widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (set-extent-property extent 'face widget-documentation-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (widget-put widget :doc-extent extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (defmacro widget-specify-insert (&rest form)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
443 "Execute FORM without inheriting any text properties."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 `(save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (insert "<>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 (narrow-to-region (- (point) 2) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (goto-char (1+ (point-min)))
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
451 ;; XEmacs: use `prog1' instead of a `result' variable. The latter
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 ;; confuses the byte-compiler in some cases (a warning).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (prog1 (progn ,@form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (delete-region (point-min) (1+ (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (delete-region (1- (point-max)) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (goto-char (point-max))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (put 'widget-specify-insert 'edebug-form-spec '(&rest form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 ;;; Inactive Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 (defface widget-inactive-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 (:foreground "light gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (:foreground "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 "Face used for inactive widgets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 ;; For inactiveness to work on complex structures, it is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 ;; sufficient to keep track of whether a button/field/glyph is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 ;; inactive or not -- we must know how many time it was deactivated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 ;; (inactiveness level). Successive deactivations of the same button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 ;; increment its inactive-count, and activations decrement it. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 ;; inactive-count reaches 0, the button/field/glyph is reactivated.
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-widget-mapper (extent action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 "Activate or deactivate EXTENT's widget (button or field).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 Suitable for use with `map-extents'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (ecase action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (:activate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (decf (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (when (zerop (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 extent (extent-property extent :inactive-plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (set-extent-property extent :inactive-plist nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (:deactivate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (incf (extent-property extent :inactive-count 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 ;; Store a plist of old properties, which will be fed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 ;; `set-extent-properties'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 (unless (extent-property extent :inactive-plist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 (set-extent-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 extent :inactive-plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (list 'mouse-face (extent-property extent 'mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 'help-echo (extent-property extent 'help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 'keymap (extent-property extent 'keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 extent '(mouse-face nil help-echo nil keymap nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (defun widget-activation-glyph-mapper (extent action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (let ((activate-p (if (eq action :activate) t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (if activate-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 (decf (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 (incf (extent-property extent :inactive-count 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (when (or (and activate-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (zerop (extent-property extent :inactive-count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 (and (not activate-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (not (zerop (extent-property extent :inactive-count)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (let* ((glyph-widget (extent-property extent 'glyph-widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 (up-glyph (widget-get glyph-widget :glyph-up))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (inactive-glyph (widget-get glyph-widget :glyph-inactive))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
517 (instantiator (widget-get glyph-widget :glyph-instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (new-glyph (if activate-p up-glyph inactive-glyph)))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
519 (cond
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
520 ;; Assume that an instantiator means a native widget.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
521 (instantiator
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
522 (setq instantiator
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
523 (set-instantiator-property instantiator :active activate-p))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
524 (widget-put glyph-widget :glyph-instantiator instantiator)
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
525 (set-glyph-image up-glyph instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 ;; Check that the new glyph exists, and differs from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 ;; default one.
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
528 ((and up-glyph inactive-glyph (not (eq up-glyph inactive-glyph))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
529 ;; Check if the glyph is already installed.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
530 (not (eq (extent-end-glyph extent) new-glyph)))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
531 ;; Change it.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
532 (set-extent-end-glyph extent new-glyph))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (defun widget-specify-inactive (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 "Make WIDGET inactive for user modifications."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (unless (widget-get widget :inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (let ((extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 ;; 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
540 ;; the inactive editable fields now lose their keymaps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 extent '(start-open t face widget-inactive-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 detachable t priority 2001 widget-inactive t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (widget-put widget :inactive extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 ;; Deactivate the buttons and fields within the range. In some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 ;; cases, the fields are not yet setup at the time this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 ;; is called. Those fields are deactivated explicitly by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 ;; `widget-setup'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (map-extents 'widget-activation-widget-mapper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 nil from to :deactivate nil 'button-or-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 ;; Deactivate glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (map-extents 'widget-activation-glyph-mapper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 nil from to :deactivate nil 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 (defun widget-specify-active (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 "Make WIDGET active for user modifications."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
557 (let ((inactive (widget-get widget :inactive))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
558 (from (widget-get widget :from))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
559 (to (widget-get widget :to)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (when (and inactive (not (extent-detached-p inactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 ;; Reactivate the buttons and fields covered by the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 (map-extents 'widget-activation-widget-mapper
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
563 nil from to :activate nil 'button-or-field)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 ;; Reactivate the glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 (map-extents 'widget-activation-glyph-mapper
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
566 nil from to :activate nil 'end-glyph)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (delete-extent inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (widget-put widget :inactive nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 ;;; Widget Properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (defsubst widget-type (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 "Return the type of WIDGET, a symbol."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 (car widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
577 ;;;###autoload
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
578 (defun widgetp (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
579 "Return non-nil iff WIDGET is a widget."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
580 (if (symbolp widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
581 (get widget 'widget-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
582 (and (consp widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
583 (symbolp (car widget))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
584 (get (car widget) 'widget-type))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
585
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 (when (or (not (fboundp 'widget-put))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (defun widget-put (widget property value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 "In WIDGET set PROPERTY to VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 The value can later be retrieved with `widget-get'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 (setcdr widget (plist-put (cdr widget) property value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 ;; Recoded in C, for efficiency:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 (when (or (not (fboundp 'widget-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (defun widget-get (widget property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 "In WIDGET, get the value of PROPERTY.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
598 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
599 later with `widget-put'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (let ((missing t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 value tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (while missing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (cond ((setq tmp (widget-plist-member (cdr widget) property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (setq value (car (cdr tmp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 missing nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 ((setq tmp (car widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (setq widget (get tmp 'widget-type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (setq missing nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (defun widget-get-indirect (widget property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 "In WIDGET, get the value of PROPERTY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 If the value is a symbol, return its binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 Otherwise, just return the value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (let ((value (widget-get widget property)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 (symbol-value value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 (defun widget-member (widget property)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
622 "Non-nil iff there is a definition in WIDGET for PROPERTY."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (cond ((widget-plist-member (cdr widget) property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 ((car widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (widget-member (get (car widget) 'widget-type) property))
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 (when (or (not (fboundp 'widget-apply))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 ;;This is in C, so don't ###utoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 (defun widget-apply (widget property &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 "Apply the value of WIDGET's PROPERTY to the widget itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 ARGS are passed as extra arguments to the function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 (apply (widget-get widget property) widget args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 (defun widget-value (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 "Extract the current value of WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 :value-to-external (widget-apply widget :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 (defun widget-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 "Set the current value of WIDGET to VALUE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 :value-set (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 :value-to-internal value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 (defun widget-default-get (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
649 "Extract the default value of WIDGET."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 (or (widget-get widget :value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 (widget-apply widget :default-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (defun widget-match-inline (widget vals)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
654 "In WIDGET, match the start of VALS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (cond ((widget-get widget :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 (widget-apply widget :match-inline vals))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
657 ((and (listp vals)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (widget-apply widget :match (car vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 (cons (list (car vals)) (cdr vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 (t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 (defun widget-apply-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 "Apply :action in WIDGET in response to EVENT."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 (if (widget-apply widget :active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (widget-apply widget :action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 (error "Attempt to perform action on inactive widget")))
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 ;;; Helper functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 ;; These are widget specific.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (defun widget-prompt-value (widget prompt &optional value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 "Prompt for a value matching WIDGET, using PROMPT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 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
677 (unless (listp widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 (setq widget (list widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 (setq prompt (format "[%s] %s" (widget-type widget) prompt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 (setq widget (widget-convert widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 (let ((answer (widget-apply widget :prompt-value prompt value unbound)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 (while (not (widget-apply widget :match answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 (setq answer (signal 'error (list "Answer does not match type"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 answer (widget-type widget)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 (defun widget-get-sibling (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 "Get the item WIDGET is assumed to toggle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 This is only meaningful for radio buttons or checkboxes in a list."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
690 (let* ((children (widget-get (widget-get widget :parent) :children))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (catch 'child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (when (eq (widget-get child :button) widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 (throw 'child child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 (defun widget-map-buttons (function &optional buffer maparg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 "Map FUNCTION over the buttons in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 FUNCTION is called with the arguments WIDGET and MAPARG.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 If FUNCTION returns non-nil, the walk is cancelled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 The arguments MAPARG, and BUFFER default to nil and (current-buffer),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 respectively."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 (map-extents (lambda (extent ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 ;; If FUNCTION returns non-nil, we bail out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 (funcall function (extent-property extent 'button) maparg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 nil nil nil nil nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 'button))
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 ;;; Glyphs.
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 (defcustom widget-glyph-directory (locate-data-directory "custom")
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
718 "Where widget button glyphs are located.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 If this variable is nil, widget will try to locate the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 automatically."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 :type 'directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 (defcustom widget-glyph-enable t
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
725 "If non nil, use glyph buttons in widgets when available."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
729 ;; #### What happens if you try to customize this?
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
730 (define-compatible-variable-alias 'widget-image-conversion
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
731 'widget-image-file-name-suffixes)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
732
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 (defcustom widget-image-file-name-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 '((xpm ".xpm") (gif ".gif") (png ".png") (jpeg ".jpg" ".jpeg")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 (xbm ".xbm"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 "Conversion alist from image formats to file name suffixes."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 :type '(repeat (cons :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (symbol :tag "Image Format" unknown)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 (repeat :tag "Suffixes"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (string :format "%v")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 ;; Don't use this, because we cannot yet distinguish between widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 ;; glyphs associated with user action, and actionless ones.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 ;(defvar widget-glyph-pointer-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 ; (make-pointer-glyph [cursor-font :data "hand2"])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 ; "Glyph to be used as the mouse pointer shape over glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 ;Use `set-glyph-image' to change this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 (defvar widget-glyph-cache nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 "Cache of glyphs associated with strings (files).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (defun widget-glyph-find (image tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 "Create a glyph corresponding to IMAGE with string TAG as fallback.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 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
756 xbm, gif, jpg, or png) located in `widget-glyph-directory', or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 in one of the data directories.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 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
759 used to make the glyph, with an additional TAG string fallback."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 (cond ((not (and image widget-glyph-enable))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 ;; We don't want to use glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 ((and (not (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 ;; We don't use glyphs on TTY consoles, although we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 ;; could. However, glyph faces aren't yet working
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 ;; properly, and movement through glyphs is unintuitive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 ;; As an exception, when TAG is nil, we assume that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 ;; caller knows what he is doing, and that the tag is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 ;; encoded within the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 (not (glyphp image)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 ((glyphp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 ;; Already a glyph. Use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 ((stringp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 ;; A string. Look it up in the cache first...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 (or (lax-plist-get widget-glyph-cache image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 ;; ...and then in the relevant directories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 (let* ((dirlist (cons (or widget-glyph-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 (locate-data-directory "custom"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 data-directory-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 (all-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (apply #'append
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 (lambda (el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 (and (valid-image-instantiator-format-p (car el))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 (cdr el)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 widget-image-file-name-suffixes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 (file (locate-file image dirlist all-suffixes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 (when file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 (let* ((extension (concat "." (file-name-extension file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 (format (car (rassoc* extension
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 widget-image-file-name-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 :test #'member))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 ;; We create a glyph with the file as the default image
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 ;; instantiator, and the TAG fallback
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 (let ((glyph (make-glyph `([,format :file ,file]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 [string :data ,tag]))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 ;; Cache the glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 (laxputf widget-glyph-cache image glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 ;; ...and return it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 glyph))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 ((valid-instantiator-p image 'image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 ;; A valid image instantiator (e.g. [gif :file "somefile"] etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (make-glyph `(,image [string :data ,tag])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 ;; Oh well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 (defun widget-glyph-insert (widget tag image &optional down inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 "In WIDGET, insert the text TAG or, if supported, IMAGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 IMAGE should either be a glyph, an image instantiator, an image file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 name sans extension (xpm, xbm, gif, jpg, or png) located in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 `widget-glyph-directory', or anything else allowed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 `widget-glyph-find'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 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
818 glyphs. The down and inactive glyphs are shown when glyph is pressed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 or inactive, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 The optional DOWN and INACTIVE arguments are deprecated, and exist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 only because of compatibility."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 ;; Convert between IMAGE being a list, etc. Must use `psetq',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 ;; because otherwise change to `image' screws up the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 (psetq image (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (car image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 down (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 (nth 1 image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 inactive (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 (nth 2 image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 (let ((glyph (widget-glyph-find image tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 (if glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 (widget-glyph-insert-glyph widget glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 (widget-glyph-find down tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 (widget-glyph-find inactive tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 (insert tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
842 (defun widget-glyph-insert-glyph (widget glyph &optional down inactive
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
843 instantiator)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 "In WIDGET, insert GLYPH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 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
846 glyphs used when the widget is pushed and inactive, respectively.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
847 INSTANTIATOR is the vector used to create the glyph."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 (insert "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 (let ((extent (make-extent (point) (1- (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (help-echo (and widget (widget-get widget :help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (map (and widget (widget-get widget :button-keymap))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 (set-extent-property extent 'glyph-widget widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 ;; 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
854 ;; doesn't mess with cursor motion. But atomic-extents library is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 ;; currently a mess, so I'd rather not use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 (set-extent-property extent 'invisible t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 (set-extent-property extent 'end-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 (set-extent-property extent 'keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 ;;(set-extent-property extent 'pointer widget-glyph-pointer-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 (set-extent-end-glyph extent glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 (unless (or (stringp help-echo) (null help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (when help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 (widget-handle-help-echo extent help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 (when widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 (widget-put widget :glyph-up glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 (when down (widget-put widget :glyph-down down))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
869 (when instantiator (widget-put widget :glyph-instantiator instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 (when inactive (widget-put widget :glyph-inactive inactive))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 ;;; Buttons.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 (defgroup widget-button nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 "The look of various kinds of buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 (defcustom widget-button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 "String used as prefix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 (defcustom widget-button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 "String used as suffix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 ;;; Creating Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 (defun widget-create (type &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
894 "Create a widget of type TYPE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 The optional ARGS are additional keyword arguments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (let ((widget (apply 'widget-convert type args)))
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 (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
901 "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
902 The child is converted, using the keyword arguments ARGS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (let ((widget (apply 'widget-convert type args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 (defun widget-create-child (parent type)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
913 "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
914 The child is not converted."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (let ((widget (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (defun widget-create-child-value (parent type value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 "Create widget of TYPE with value VALUE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 (let ((widget (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (widget-put widget :value (widget-apply widget :value-to-internal value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (defun widget-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 "Delete WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 (widget-apply widget :delete))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
941 (defun widget-copy (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
942 "Make a deep copy of WIDGET."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
943 (widget-apply (copy-sequence widget) :copy))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
944
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (defun widget-convert (type &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 "Convert TYPE to a widget without inserting it in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 The optional ARGS are additional keyword arguments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 ;; Don't touch the type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 (let* ((widget (if (symbolp type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (list type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 (current widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 (keys args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 ;; First set the :args keyword.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 (while (cdr current) ;Look in the type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 (let ((next (car (cdr current))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 (setq current (cdr (cdr current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (setcdr current (list :args (cdr current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 (setq current nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 (while args ;Look in the args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (let ((next (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (setq args (nthcdr 2 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 (widget-put widget :args args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 (setq args nil))))
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
967 ;; Then convert the widget.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 (setq type widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 (while type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 (let ((convert-widget (plist-get (cdr type) :convert-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 (if convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (setq widget (funcall convert-widget widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (setq type (get (car type) 'widget-type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 ;; Finally set the keyword args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (while keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 (let ((next (nth 0 keys)))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
977 (if (keywordp next)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (widget-put widget next (nth 1 keys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 (setq keys (nthcdr 2 keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (setq keys nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 ;; Convert the :value to internal format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (if (widget-member widget :value)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
984 (widget-put widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
985 :value (widget-apply widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
986 :value-to-internal
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
987 (widget-get widget :value))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 ;; Return the newly created widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
991 ;;;###autoload
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 (defun widget-insert (&rest args)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
993 "Call `insert' with ARGS even if surrounding text is read only."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 (apply 'insert args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 (defun widget-convert-text (type from to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 &optional button-from button-to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1002 "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
1003 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
1004 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
1005 the text between them.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1006 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
1007 used as the widget's button end points.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 Optional ARGS are extra keyword arguments for TYPE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 (let ((widget (apply 'widget-convert type :delete 'widget-leave-text args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 (from (copy-marker from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 (to (copy-marker to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 (set-marker-insertion-type from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (set-marker-insertion-type to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (widget-put widget :from from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 (widget-put widget :to to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 (when button-from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 (widget-specify-button widget button-from button-to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (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
1021 "Return a widget of type TYPE with endpoints FROM and TO.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 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
1023 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
1024 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
1025 end points. The widget is ``wrapped around'' the text between them."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (apply 'widget-convert-text type from to from to args))
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 (defun widget-leave-text (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 "Remove markers and extents from WIDGET and its children."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 (let ((from (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (to (widget-get widget :to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (button (widget-get widget :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 (sample (widget-get widget :sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (doc (widget-get widget :doc-extent))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1035 (field (widget-get widget :field-extent)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (set-marker to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 ;; Maybe we should delete the extents here? As this code doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 ;; remove them from widget structures, maybe it's safer to just
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1040 ;; detach them. That's what GNU-compatible `delete-overlay' does.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (when button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (detach-extent button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (when sample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (detach-extent sample))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 (when doc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (detach-extent doc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (when field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (detach-extent field))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1049 (mapc 'widget-leave-text (widget-get widget :children))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 ;;; Keymap and Commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 (defvar widget-keymap nil
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1055 "Keymap containing useful bindings for buffers containing widgets.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 Recommended as a parent keymap for modes using widgets.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 (unless widget-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 (setq widget-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 (define-key widget-keymap [tab] 'widget-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 (define-key widget-keymap [(shift tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 (define-key widget-keymap [(meta tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 (define-key widget-keymap [backtab] 'widget-backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 (defvar widget-global-map global-map
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1066 "Keymap used for events a widget does not handle itself.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 (make-variable-buffer-local 'widget-global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 (defvar widget-field-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 "Keymap used inside an editable field.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (unless widget-field-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 (setq widget-field-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (set-keymap-parents widget-field-keymap global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 (define-key widget-field-keymap "\C-k" 'widget-kill-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 (define-key widget-field-keymap [(meta tab)] 'widget-complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 (define-key widget-field-keymap [tab] 'widget-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (define-key widget-field-keymap [(shift tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 (define-key widget-field-keymap "\C-m" 'widget-field-activate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 (define-key widget-field-keymap "\C-e" 'widget-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 (define-key widget-field-keymap "\C-t" 'widget-transpose-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 (defvar widget-text-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 "Keymap used inside a text field.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 (unless widget-text-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (setq widget-text-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 (set-keymap-parents widget-field-keymap global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 (define-key widget-text-keymap "\C-e" 'widget-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (define-key widget-text-keymap "\C-t" 'widget-transpose-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (defvar widget-button-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 "Keymap used inside a button.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (unless widget-button-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (setq widget-button-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 (set-keymap-parents widget-button-keymap widget-keymap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (define-key widget-button-keymap "\C-m" 'widget-button-press)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 (define-key widget-button-keymap [button2] 'widget-button-click)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 ;; Ideally, button3 within a button should invoke a button-specific
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 ;; menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 (define-key widget-button-keymap [button3] 'widget-button-click)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 ;;Glyph support.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 (define-key widget-button-keymap [button1] 'widget-button1-click))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 (defun widget-field-activate (pos &optional event)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1110 "Invoke the editable field at point."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 (interactive "@d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 (let ((field (widget-field-find pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 (if field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 (widget-apply-action field event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 (call-interactively
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 (lookup-key widget-global-map (this-command-keys))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 (defface widget-button-pressed-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 '((((class color))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 (:foreground "red"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 (:bold t :underline t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 "Face used for pressed buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (defun widget-event-point (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 "Character position of the mouse event, or nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 (and (mouse-event-p event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 (event-point event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 (defun widget-button-click (event)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1132 "Invoke button under mouse pointer."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 (interactive "e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 (with-current-buffer (event-buffer event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 (cond ((event-glyph event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 (widget-glyph-click event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 ((widget-event-point event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 (let* ((pos (widget-event-point event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 (button (get-char-property pos 'button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 (if button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 (let* ((extent (widget-get button :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 (face (extent-property extent 'face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 (mouse-face (extent-property extent 'mouse-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (help-echo (extent-property extent 'help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 ;; Merge relevant faces, and make the result mouse-face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 (let ((merge `(widget-button-pressed-face ,mouse-face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (nconc merge (if (listp face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 face (list face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 (setq merge (delete-if-not 'find-face merge))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (set-extent-property extent 'mouse-face merge))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 (unless (widget-apply button :mouse-down-action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 ;; Wait for button release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 (while (not (button-release-event-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 (setq event (next-event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 (dispatch-event event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 ;; Disallow mouse-face and help-echo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 (set-extent-property extent 'mouse-face nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 (set-extent-property extent 'help-echo nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 (setq pos (widget-event-point event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 (unless (eq (current-buffer) (extent-object extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 ;; Barf if dispatch-event tripped us by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 ;; changing buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 (error "Buffer changed during mouse motion"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 ;; Do the associated action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 (when (and pos (extent-in-region-p extent pos pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (widget-apply-action button event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 ;; Unwinding: fully release the button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 (set-extent-property extent 'mouse-face mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 (set-extent-property extent 'help-echo help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 ;; This should not happen!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (error "`widget-button-click' called outside button"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 (message "You clicked somewhere weird")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (defun widget-button1-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 "Invoke glyph below mouse pointer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 (interactive "@e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 (if (event-glyph event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 (widget-glyph-click event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 ;; Should somehow avoid this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (let ((command (lookup-key widget-global-map (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 (and (commandp command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 (call-interactively command)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (defun widget-glyph-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 "Handle click on a glyph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 (let* ((glyph (event-glyph event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 (extent (event-glyph-extent event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (widget (extent-property extent 'glyph-widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 (down-glyph (or (and widget (widget-get widget :glyph-down)) glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 (up-glyph (or (and widget (widget-get widget :glyph-up)) glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 (last event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 (unless (widget-apply widget :active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 (error "This widget is inactive"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 (let ((current-glyph 'down))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 ;; We always know what glyph is drawn currently, to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 ;; unnecessary extent changes. Is this any noticeable gain?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 ;; Press the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 (set-extent-end-glyph extent down-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 ;; Redisplay (shouldn't be needed, but...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 (sit-for 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 (unless (widget-apply widget :mouse-down-action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 ;; Wait for the release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 (while (not (button-release-event-p last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 (unless (button-press-event-p last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 (dispatch-event last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 (when (motion-event-p last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 ;; Update glyphs on mouse motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 (if (eq extent (event-glyph-extent last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 (unless (eq current-glyph 'down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 (set-extent-end-glyph extent down-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 (setq current-glyph 'down))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 (unless (eq current-glyph 'up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 (set-extent-end-glyph extent up-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 (setq current-glyph 'up))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 (setq last (next-event event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 (unless (eq (current-buffer) (extent-object extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 ;; Barf if dispatch-event tripped us by changing buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (error "Buffer changed during mouse motion"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 ;; Apply widget action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 (when (eq extent (event-glyph-extent last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 (let ((widget (extent-property (event-glyph-extent event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 (cond ((null widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 (message "You clicked on a glyph"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 ((not (widget-apply widget :active))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 (error "This glyph is inactive"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 (widget-apply-action widget event))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 ;; Release the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 (and (eq current-glyph 'down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 ;; The extent might have been detached or deleted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 (extent-live-p extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 (not (extent-detached-p extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 (set-extent-end-glyph extent up-glyph))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 (defun widget-button-press (pos &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 "Invoke button at POS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 (interactive "@d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 (let ((button (get-char-property pos 'button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 (if button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 (widget-apply-action button event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 (let ((command (lookup-key widget-global-map (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 (when (commandp command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 (call-interactively command))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 (defun widget-tabable-at (&optional pos last-tab backwardp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 "Return the tabable widget at POS, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 POS defaults to the value of (point)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (unless pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 (setq pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 (let ((widget (widget-at pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 (if widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (let ((order (widget-get widget :tab-order)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 (if order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 (if last-tab (and (= order (if backwardp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 (1- last-tab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 (1+ last-tab)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (and (> order 0) widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 ;; Return the button or field extent at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 (defun widget-button-or-field-extent (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 (or (and (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 (widget-get (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 (and (get-char-property pos 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (widget-get (get-char-property pos 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 :field-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 (defun widget-next-button-or-field (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 "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
1279 Internal function, don't use it outside `wid-edit'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 (let* ((at-point (widget-button-or-field-extent pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 (extent (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 (lambda (ext ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 nil (if at-point (extent-end-position at-point) pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 nil nil 'start-open 'button-or-field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 (and extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 (extent-start-position extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 ;; This is too slow in buffers with many buttons (W3).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 (defun widget-previous-button-or-field (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 "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
1292 Internal function, don't use it outside `wid-edit'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 (let* ((at-point (widget-button-or-field-extent pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 previous-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 (lambda (ext ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 (if (eq ext at-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 ;; We reached the extent we were on originally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 (if (= pos (extent-start-position at-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 previous-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 (setq previous-extent at-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 (setq previous-extent ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 nil nil pos nil 'start-open 'button-or-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 (and previous-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 (extent-start-position previous-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 (defun widget-move (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 "Move point to the ARG next field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 ARG may be negative to move backward."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 (let ((opoint (point)) (wrapped 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 (last-tab (widget-get (widget-at (point)) :tab-order))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 nextpos found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 ;; Movement backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 (while (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 (setq nextpos (widget-previous-button-or-field (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 (if nextpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 (goto-char nextpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 (when (and (not (get-char-property nextpos 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 (widget-tabable-at nil last-tab t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 (incf arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 (setq found t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 last-tab (widget-get (widget-at (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 :tab-order))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 (if (and (not found) (> wrapped 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 (setq arg 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 (incf wrapped))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 ;; Movement forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 (setq nextpos (widget-next-button-or-field (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 (if nextpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 (goto-char nextpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 (when (and (not (get-char-property nextpos 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 (widget-tabable-at nil last-tab))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 (decf arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 (setq found t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 last-tab (widget-get (widget-at (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 :tab-order))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 (if (and (not found) (> wrapped 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 (setq arg 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 (incf wrapped))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 (if (not found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (widget-echo-help (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 (run-hooks 'widget-move-hook))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 (defun widget-forward (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 "Move point to the next field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 With optional ARG, move across that many fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 (run-hooks 'widget-forward-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (widget-move arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (defun widget-backward (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 "Move point to the previous field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 With optional ARG, move across that many fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 (run-hooks 'widget-backward-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 (widget-move (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (defun widget-beginning-of-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1368 "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
1369
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1370 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
1371 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 (start (and field (widget-field-start field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 (if (and start (not (eq start (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 (call-interactively 'beginning-of-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 (defun widget-end-of-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1380 "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
1381
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1382 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
1383 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 (end (and field (widget-field-end field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 (if (and end (not (eq end (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 (call-interactively 'end-of-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 (defun widget-kill-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1392 "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
1393
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1394 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
1395 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 (newline (save-excursion (forward-line 1) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 (end (and field (widget-field-end field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 (if (and field (> newline end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 (kill-region (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 (call-interactively 'kill-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 (defun widget-transpose-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 "Like `transpose-chars', but works correctly at end of widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 (start (and field (widget-field-start field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (end (and field (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 (last-non-space (and start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 (skip-chars-backward " \t\n" start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 (cond ((and last-non-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 (or (= last-non-space start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 (= last-non-space (1+ start))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 ;; empty or one-character field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 ((= (point) start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 ;; at the beginning of the field -- we would get an error here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 (error "Cannot transpose at beginning of field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 (when (and (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 (= last-non-space (point)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1426 (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 (transpose-chars arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 (defcustom widget-complete-field (lookup-key global-map "\M-\t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 "Default function to call for completion inside fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 :options '(ispell-complete-word complete-tag lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 (defun widget-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 "Complete content of editable field from point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 When not inside a field, move to the previous button or field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 ;; Somehow, this should make pressing M-TAB twice scroll the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 ;; completions window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 (let ((field (widget-field-find (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 (if field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 (widget-apply field :complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 (error "Not in an editable field"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 ;;; Setting up the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 (defvar widget-field-new nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 ;; List of all newly created editable fields in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 (make-variable-buffer-local 'widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 (defvar widget-field-list nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 ;; List of all editable fields in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 (make-variable-buffer-local 'widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1457 ;; Is this a misnomer?
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1458 (defun widget-at (pos)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1459 "The button or field at POS."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1460 (or (get-char-property pos 'button)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1461 (get-char-property pos 'field)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1462
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1463 ;;;###autoload
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 (defun widget-setup ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 "Setup current buffer so editing string widgets works."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 (after-change-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 (while widget-field-new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 (setq field (car widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 widget-field-new (cdr widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 widget-field-list (cons field widget-field-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 (let ((from (car (widget-get field :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 (to (cdr (widget-get field :field-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 (widget-specify-field field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 (marker-position from) (marker-position to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 (set-marker to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 ;; If the field is placed within the inactive zone, deactivate it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 (let ((extent (widget-get field :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 (when (get-char-property (extent-start-position extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 'widget-inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 (widget-activation-widget-mapper extent :deactivate)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (widget-clear-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 (widget-add-change))
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 (defvar widget-field-last nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 ;; Last field containing point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 (make-variable-buffer-local 'widget-field-last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 (defvar widget-field-was nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 ;; The widget data before the change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 (make-variable-buffer-local 'widget-field-was)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1496 (defun widget-field-at (pos)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1497 "Return the widget field at POS, or nil if none."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1498 (let ((field (get-char-property (or pos (point)) 'field)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1499 (if (eq field 'boundary)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1500 nil
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1501 field)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1502
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (defun widget-field-buffer (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1504 "Return the buffer containing WIDGET.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1505
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1506 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
1507 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 (and extent (extent-object extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 (defun widget-field-start (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1512 "Return the start of WIDGET's editing field.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1513
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1514 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
1515 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 (and extent (extent-start-position extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 (defun widget-field-end (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1520 "Return the end of WIDGET's editing field.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1521
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1522 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
1523 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 ;; 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
1526 (and extent (if (or widget-field-add-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 (null (widget-get widget :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 (1- (extent-end-position extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 (extent-end-position extent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 (defun widget-field-find (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 "Return the field at POS.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1533 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
1534
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1535 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
1536 `widget-setup' will always fail."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1537 ;; XEmacs: use `map-extents' instead of a while loop
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 (let ((field-extent (map-extents (lambda (extent ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 nil pos pos nil nil 'field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 (and field-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 (extent-property field-extent 'field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1544 ;; 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
1545 ;; invoking `widget-setup' will always fail.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 (defun widget-before-change (from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 ;; Barf if the text changed is outside the editable fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 (unless inhibit-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 (let ((from-field (widget-field-find from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 (to-field (widget-field-find to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 (cond ((or (null from-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 (null to-field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 ;; Either end of change is not within a field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 (error "Attempt to change text outside editable field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 ((not (eq from-field to-field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 ;; The change begins in one fields, and ends in another one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 (error "Change should be restricted to a single field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 ((or (and from-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 (get-char-property from 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 (and to-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 (get-char-property to 'widget-inactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 ;; Trying to change an inactive editable field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 (error "Attempt to change an inactive field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 (widget-field-use-before-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 ;; #### Bletch! This loses because XEmacs get confused
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 ;; if before-change-functions change the contents of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 ;; buffer before from/to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 (widget-apply from-field :notify from-field)
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 724
diff changeset
1573 (error (declare-fboundp (debug "Before Change")))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 (defun widget-add-change ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 (make-local-hook 'post-command-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 (remove-hook 'post-command-hook 'widget-add-change t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 (make-local-hook 'before-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 (add-hook 'before-change-functions 'widget-before-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 (make-local-hook 'after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 (add-hook 'after-change-functions 'widget-after-change nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 (defun widget-after-change (from to old)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1584 "Adjust field size and text properties.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1585
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1586 Also, notify the widgets (so, for example, a variable changes its
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1587 state to `modified'. when it is being edited)."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 (let ((field (widget-field-find from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 (other (widget-field-find to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 (when field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 (unless (eq field other)
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 724
diff changeset
1593 (declare-fboundp (debug "Change in different fields")))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 (let ((size (widget-get field :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 (when size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 (let ((begin (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 (end (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 (cond ((< (- end begin) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 ;; Field too small.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 (insert-char ?\ (- (+ begin size) end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 ((> (- end begin) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 ;; Field too large and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 (if (or (< (point) (+ begin size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 (> (point) end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 ;; Point is outside extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 (setq begin (+ begin size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 ;; Point is within the extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 (setq begin (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 (while (and (eq (preceding-char) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 (> (point) begin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 (delete-backward-char 1)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 (widget-specify-secret field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 (widget-apply field :notify field)))
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 724
diff changeset
1618 (error (declare-fboundp (debug "After Change")))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 ;;; Widget Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 ;; These functions are used in the definition of multiple widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 (defun widget-parent-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 "Tell :parent of WIDGET to handle the :action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 Optional EVENT is the event that triggered the action."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 (widget-apply (widget-get widget :parent) :action event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 (defun widget-children-value-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 "Delete all :children and :buttons in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 (mapc 'widget-delete (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 (widget-put widget :children nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 (mapc 'widget-delete (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 (widget-put widget :buttons nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 (defun widget-children-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 "All the :children must be valid."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 child found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 found (widget-apply child :validate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1647 (defun widget-types-copy (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1648 "Copy :args as widget types in WIDGET."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1649 (widget-put widget :args (mapcar 'widget-copy (widget-get widget :args)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1650 widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1651
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1652 ;; Made defsubst to speed up face editor creation.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1653 (defsubst widget-types-convert-widget (widget)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 "Convert :args as widget types in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 (defun widget-value-convert-widget (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 "Initialize :value from :args in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 (let ((args (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 (when args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 (widget-put widget :value (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 ;; Don't convert :value here, as this is done in `widget-convert'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 ;; (widget-put widget :value (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 ;; :value-to-internal (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 (widget-put widget :args nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 (defun widget-value-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 "Return the :value property of WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 ;;; The `default' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 (define-widget 'default nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 "Basic widget other widgets are derived from."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 :value-to-internal (lambda (widget value) value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 :value-to-external (lambda (widget value) value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 :button-prefix 'widget-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 :button-suffix 'widget-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 :complete 'widget-default-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 :create 'widget-default-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 :indent nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 :offset 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 :format-handler 'widget-default-format-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 :button-face-get 'widget-default-button-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 :sample-face-get 'widget-default-sample-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 :button-keymap widget-button-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 :delete 'widget-default-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 :value-set 'widget-default-value-set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 :value-inline 'widget-default-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 :default-get 'widget-default-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 :menu-tag-get 'widget-default-menu-tag-get
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1694 :validate #'ignore
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 :active 'widget-default-active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 :activate 'widget-specify-active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 :deactivate 'widget-default-deactivate
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1698 :mouse-down-action #'ignore
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 :action 'widget-default-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 :notify 'widget-default-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 :prompt-value 'widget-default-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 (defun widget-default-complete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 "Call the value of the :complete-function property of WIDGET.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 If that does not exists, call the value of `widget-complete-field'."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1706 (call-interactively (or (widget-get widget :complete-function)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1707 widget-complete-field)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 (defun widget-default-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 "Create WIDGET at point in the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 (let ((from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 button-begin button-end button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 sample-begin sample-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 doc-begin doc-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 value-pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 (insert (widget-get widget :format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 (goto-char from)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1719 ;; Parse escapes in format.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1720 ;; Coding this in C would speed up things *a lot*.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 (while (re-search-forward "%\\(.\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 (cond ((eq escape ?%)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1725 (insert ?%))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 ((eq escape ?\[)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 (setq button-begin (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 (set-marker-insertion-type button-begin nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 ((eq escape ?\])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 (setq button-end (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 (set-marker-insertion-type button-end nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 ((eq escape ?\{)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 (setq sample-begin (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 ((eq escape ?\})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 (setq sample-end (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 ((eq escape ?n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 (when (widget-get widget :indent)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1738 (insert ?\n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 (insert-char ?\ (widget-get widget :indent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 ((eq escape ?t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 (let* ((tag (widget-get widget :tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 (glyph (widget-get widget :tag-glyph)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 (cond (glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 (setq button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 (widget-glyph-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 widget (or tag "Image") glyph)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 (tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 (insert tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 (t
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1750 (princ (widget-get widget :value)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1751 (current-buffer))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 ((eq escape ?d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 (let ((doc (widget-get widget :doc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 (when doc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 (setq doc-begin (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 (insert doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 (while (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 (delete-backward-char 1))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1759 (insert ?\n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 (setq doc-end (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 (if (and button-begin (not button-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 (widget-apply widget :value-create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 (setq value-pos (point-marker))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 (widget-apply widget :format-handler escape)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 ;; Specify button, sample, and doc, and insert value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 (when (and button-begin button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 (unless button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 (goto-char button-begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 (insert (widget-get-indirect widget :button-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 (goto-char button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 (set-marker-insertion-type button-end t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 (insert (widget-get-indirect widget :button-suffix)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 (widget-specify-button widget button-begin button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 ;; Is this necessary?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 (set-marker button-begin nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 (set-marker button-end nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 (and sample-begin sample-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 (widget-specify-sample widget sample-begin sample-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 (and doc-begin doc-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 (widget-specify-doc widget doc-begin doc-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 (when value-pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 (goto-char value-pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 (widget-apply widget :value-create)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 (let ((from (point-min-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 (to (point-max-marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 (set-marker-insertion-type from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 (set-marker-insertion-type to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 (widget-put widget :from from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 (widget-put widget :to to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 (widget-clear-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 (defun widget-default-format-handler (widget escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 ;; We recognize the %h escape by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 (let* ((buttons (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 (cond ((eq escape ?h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 (let* ((doc-property (widget-get widget :documentation-property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 (doc-try (cond ((widget-get widget :doc))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1800 ((functionp doc-property)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1801 (funcall doc-property
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1802 (widget-get widget :value)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 ((symbolp doc-property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 (documentation-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 (widget-get widget :value)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1806 doc-property))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 (doc-text (and (stringp doc-try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 (> (length doc-try) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 doc-try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 (doc-indent (widget-get widget :documentation-indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 (when doc-text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 ;; The `*' in the beginning is redundant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 (when (eq (aref doc-text 0) ?*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 (setq doc-text (substring doc-text 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 ;; Get rid of trailing newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 (when (string-match "\n+\\'" doc-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 (setq doc-text (substring doc-text 0 (match-beginning 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 (push (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 widget 'documentation-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 :indent (cond ((numberp doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 ((null doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 (t 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 doc-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 buttons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 (signal 'error (list "Unknown escape" escape))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 (widget-put widget :buttons buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 (defun widget-default-button-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 ;; Use :button-face or widget-button-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 (or (widget-get widget :button-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 (if parent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 (widget-apply parent :button-face-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 widget-button-face))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 (defun widget-default-sample-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 ;; Use :sample-face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 (widget-get widget :sample-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 (defun widget-default-delete (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1847 "Remove widget from the buffer."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 (let ((from (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 (to (widget-get widget :to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 (inactive-extent (widget-get widget :inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 (button-extent (widget-get widget :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 (sample-extent (widget-get widget :sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 (doc-extent (widget-get widget :doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 after-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 (inhibit-read-only t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 (widget-apply widget :value-delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 (when inactive-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 (detach-extent inactive-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 (when button-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 (detach-extent button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 (when sample-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 (detach-extent sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 (when doc-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 (detach-extent doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 (when (< from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 ;; Kludge: this doesn't need to be true for empty formats.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 (delete-region from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 (set-marker to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 (widget-clear-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 (defun widget-default-value-set (widget value)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1874 "Recreate widget with new value."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 (let* ((old-pos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 (from (copy-marker (widget-get widget :from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 (to (copy-marker (widget-get widget :to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 (offset (if (and (<= from old-pos) (<= old-pos to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 (if (>= old-pos (1- to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 (- old-pos to 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 (- old-pos from)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 ;;??? 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
1883 ;; so that markers on either side of the value automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 ;; stay on the same side. -- rms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 (goto-char (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 (widget-apply widget :delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 (widget-put widget :value value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 (widget-apply widget :create))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1890 (if offset
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1891 (if (< offset 0)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1892 (goto-char (+ (widget-get widget :to) offset 1))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1893 (goto-char (min (+ from offset) (1- (widget-get widget :to))))))))
428
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 (defun widget-default-value-inline (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1896 "Wrap value in a list unless it is inline."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 (if (widget-get widget :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 (list (widget-value widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 (defun widget-default-default-get (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1902 "Get `:value'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 (defun widget-default-menu-tag-get (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1906 "Use tag or value for menus."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 (or (widget-get widget :menu-tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 (widget-get widget :tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 (widget-princ-to-string (widget-get widget :value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 (defun widget-default-active (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 "Return t iff this widget active (user modifiable)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 (and (not (widget-get widget :inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 (or (null parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 (widget-apply parent :active)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 (defun widget-default-deactivate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 "Make WIDGET inactive for user modifications."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 (widget-specify-inactive widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 (widget-get widget :from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 (widget-get widget :to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (defun widget-default-action (widget &optional event)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1925 "Notify the parent when a widget changes."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 (when parent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 (widget-apply parent :notify widget event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 (defun widget-default-notify (widget child &optional event)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1931 "Pass notification to parent."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 (widget-default-action widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 (defun widget-default-prompt-value (widget prompt value unbound)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1935 "Read an arbitrary value. Stolen from `set-variable'."
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1936 ;; (let ((initial (if unbound
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1937 ;; nil
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1938 ;; It would be nice if we could do a `(cons val 1)' here.
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1939 ;; (prin1-to-string (custom-quote value))))))
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1940 (eval-minibuffer prompt))
428
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 `item' 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 (define-widget 'item 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 "Constant items for inclusion in other widgets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 :convert-widget 'widget-value-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 :value-create 'widget-item-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 :value-delete 'ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 :value-get 'widget-value-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 :match 'widget-item-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 :match-inline 'widget-item-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 :action 'widget-item-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 :format "%t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 (defun widget-item-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1956 "Insert the printed representation of the value."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1957 (princ (widget-get widget :value) (current-buffer)))
428
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 (defun widget-item-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 ;; Match if the value is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 (equal (widget-get widget :value) value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 (defun widget-item-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 ;; Match if the value is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 (let ((value (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 (and (listp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 (<= (length value) (length values))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 (let ((head (widget-sublist values 0 (length value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 (and (equal head value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 (cons head (widget-sublist values (length value))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 (defun widget-sublist (list start &optional end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 "Return the sublist of LIST from START to END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 If END is omitted, it defaults to the length of LIST."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 (if (> start 0) (setq list (nthcdr start list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 (if end
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1977 (unless (<= end start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 (setq list (copy-sequence list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 (setcdr (nthcdr (- end start 1) list) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 (copy-sequence list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 (defun widget-item-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 ;; Just notify itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 (widget-apply widget :notify widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 ;;; The `push-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 (defcustom widget-push-button-gui widget-glyph-enable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 "If non nil, use GUI push buttons when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 :type 'boolean)
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-push-button-prefix "["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 "String used as prefix for buttons."
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-push-button-suffix "]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 "String used as suffix for buttons."
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 'push-button 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 "A pushable button."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 :value-create 'widget-push-button-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 :format "%[%v%]")
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 (defun widget-push-button-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2012 "Insert text representing the `on' and `off' states."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 (let* ((tag (or (widget-get widget :tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 (tag-glyph (widget-get widget :tag-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 (text (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 tag widget-push-button-suffix))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
2018 gui inst)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 (cond (tag-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 (widget-glyph-insert widget text tag-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 ;; We must check for console-on-window-system-p here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 ;; because GUI will not work otherwise (it needs RGB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 ;; components for colors, and they are not known on TTYs).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 ((and widget-push-button-gui
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 (console-on-window-system-p))
436
080151679be2 Import from CVS: tag r21-2-26
cvs
parents: 428
diff changeset
2026 (let* ((gui-button-shadow-thickness 1))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
2027 (setq inst (make-gui-button tag 'widget-gui-action widget))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
2028 (setq gui (make-glyph inst)))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
2029 (widget-glyph-insert-glyph widget gui nil nil inst))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 (insert text)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 (defun widget-gui-action (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 "Apply :action for WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 (widget-apply-action widget (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 ;;; The `link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 (defcustom widget-link-prefix "["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 "String used as prefix for links."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 (defcustom widget-link-suffix "]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 "String used as suffix for links."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 (define-widget 'link 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 "An embedded link."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 :button-prefix 'widget-link-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 :button-suffix 'widget-link-suffix
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2053 :help-echo "Follow the link."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 :format "%[%t%]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 ;;; The `info-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 (define-widget 'info-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 "A link to an info file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 :help-echo 'widget-info-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 :action 'widget-info-link-action)
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 (defun widget-info-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 (concat "Read the manual entry `" (widget-value widget) "'"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 (defun widget-info-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 "Open the info node specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 (Info-goto-node (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 ;;; The `url-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 (define-widget 'url-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 "A link to an www page."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 :help-echo 'widget-url-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 :action 'widget-url-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 (defun widget-url-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 (concat "Visit <URL:" (widget-value widget) ">"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 (defun widget-url-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 "Open the url specified by WIDGET."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2082 (if (fboundp 'browse-url)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2083 (browse-url (widget-value widget))
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2084 ;; #### Should subclass a 'missing-package error.
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2085 (error 'unimplemented
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2086 "No `browse-url' package; cannot follow URLs in this XEmacs")))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 ;;; The `function-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 (define-widget 'function-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 "A link to an Emacs function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 :action 'widget-function-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 (defun widget-function-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 "Show the function specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 (describe-function (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 ;;; The `variable-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 (define-widget 'variable-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 "A link to an Emacs variable."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 :action 'widget-variable-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 (defun widget-variable-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 "Show the variable specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 (describe-variable (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 ;;; The `file-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 (define-widget 'file-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 "A link to a file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 :action 'widget-file-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 (defun widget-file-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 "Find the file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 (find-file (widget-value widget)))
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 ;;; The `emacs-library-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 (define-widget 'emacs-library-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 "A link to an Emacs Lisp library file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 :help-echo 'widget-emacs-library-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 :action 'widget-emacs-library-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 (defun widget-emacs-library-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 (concat "Visit " (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 (defun widget-emacs-library-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 "Find the Emacs Library file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130 (find-file (locate-library (widget-value widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 ;;; The `emacs-commentary-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 (define-widget 'emacs-commentary-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 "A link to Commentary in an Emacs Lisp library file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 :action 'widget-emacs-commentary-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 (defun widget-emacs-commentary-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 "Find the Commentary section of the Emacs file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 (finder-commentary (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 ;;; The `editable-field' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 (define-widget 'editable-field 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 "An editable text field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 :convert-widget 'widget-value-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 :keymap widget-field-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 :format "%v"
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2149 :help-echo "M-TAB: complete field; RET: enter value"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 :value ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 :prompt-internal 'widget-field-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 :prompt-history 'widget-field-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 :prompt-value 'widget-field-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 :action 'widget-field-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 :validate 'widget-field-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 :valid-regexp ""
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2157 :error "Field's value doesn't match allowed forms"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 :value-create 'widget-field-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 :value-delete 'widget-field-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 :value-get 'widget-field-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 :match 'widget-field-match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 (defvar widget-field-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 "History of field minibuffer edits.")
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-prompt-internal (widget prompt initial history)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2167 "Read string for WIDGET prompting with PROMPT.
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2168 INITIAL is the initial input and HISTORY is a symbol containing
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2169 the earlier input."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 (read-string prompt initial history))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 (defun widget-field-prompt-value (widget prompt value unbound)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2173 "Prompt for a string."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2174 (widget-apply widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2175 :value-to-external
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2176 (widget-apply widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2177 :prompt-internal prompt
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2178 (unless unbound
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2179 (cons (widget-apply widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2180 :value-to-internal value)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2181 0))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2182 (widget-get widget :prompt-history))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 (defvar widget-edit-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 (defun widget-field-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 ;; Edit the value in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 (let* ((invalid (widget-apply widget :validate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 (prompt (concat (widget-apply widget :menu-tag-get) ": "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 (value (unless invalid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 (answer (widget-apply widget :prompt-value prompt value invalid)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 (unless (equal value answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 ;; This is a hack. We can't properly validate the widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 ;; because validation requires the new value to be in the field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 ;; However, widget-field-value-create will not function unless
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 ;; the new value matches. So, we check whether the thing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 ;; 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
2199 ;; message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 (unless (widget-apply widget :match answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 (let ((error-message (or (widget-get widget :type-error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 "Invalid field contents")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 (widget-put widget :error error-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 (error error-message)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 (widget-setup))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 (run-hook-with-args 'widget-edit-functions widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 ;(defun widget-field-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 ; ;; Move to next field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 ; (widget-forward 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 ; (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 (defun widget-field-validate (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2216 "Valid if the content matches `:valid-regexp'."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2217 (save-excursion ; XEmacs
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2218 (unless (string-match (widget-get widget :valid-regexp)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2219 (widget-apply widget :value-get))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2220 widget)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 (defun widget-field-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2223 "Create an editable text field."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 (let ((size (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 (value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 ;; This is changed to a real extent in `widget-setup'. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 ;; need the end points to behave differently until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 ;; `widget-setup' is called. Should probably be replaced with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 ;; a genuine extent, but some things break, then.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 (extent (cons (make-marker) (make-marker))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 (widget-put widget :field-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 (insert value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 (and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 (< (length value) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 (insert-char ?\ (- size (length value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 (unless (memq widget widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 (push widget widget-field-new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 (move-marker (cdr extent) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 (set-marker-insertion-type (cdr extent) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 (when (null size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 (insert ?\n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 (move-marker (car extent) from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 (set-marker-insertion-type (car extent) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 (defun widget-field-value-delete (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2247 "Remove the widget from the list of active editing fields."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 (setq widget-field-list (delq widget widget-field-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 ;; These are nil if the :format string doesn't contain `%v'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 (when extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 (detach-extent extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 (defun widget-field-value-get (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2255 "Return current text in editing field."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 (let ((from (widget-field-start widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 (to (widget-field-end widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 (buffer (widget-field-buffer widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 (size (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 (secret (widget-get widget :secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 (old (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 ((and from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 (while (and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 (not (zerop size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 (> to from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 (eq (char-after (1- to)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 (setq to (1- to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 (let ((result (buffer-substring-no-properties from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 (when secret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 (let ((index 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 (while (< (+ from index) to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 (aset result index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 (get-char-property (+ from index) 'secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 (incf index))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 (set-buffer old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 (widget-get widget :value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 (defun widget-field-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 ;; Match any string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 (stringp value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 ;;; The `text' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 (define-widget 'text 'editable-field
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2289 "A multiline text area."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2290 :keymap widget-text-keymap)
428
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 ;;; The `menu-choice' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 (define-widget 'menu-choice 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 "A menu of options."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 :format "%[%t%]: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 :case-fold t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 :tag "choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 :void '(item :format "invalid (%t)\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 :value-create 'widget-choice-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 :value-get 'widget-choice-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 :value-inline 'widget-choice-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 :default-get 'widget-choice-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 :mouse-down-action 'widget-choice-mouse-down-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 :action 'widget-choice-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 :error "Make a choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 :validate 'widget-choice-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 :match 'widget-choice-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 :match-inline 'widget-choice-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 (defun widget-choice-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2314 "Insert the first choice that matches the value."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 (let ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 (args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 (explicit (widget-get widget :explicit-choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 (if explicit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 (progn
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2321 ;; If the user specified the choice for this value,
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2322 ;; respect that choice as long as the value is the same.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 (widget-put widget :children (list (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 widget explicit value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 (widget-put widget :choice explicit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 (when (widget-apply current :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 (widget-put widget :children (list (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 widget current value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 (widget-put widget :choice current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 (setq args nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 current nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 (when current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 (let ((void (widget-get widget :void)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 (widget-put widget :children (list (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 widget void :value value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 (widget-put widget :choice void))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 (defun widget-choice-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 (widget-value (car (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 (defun widget-choice-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 (widget-apply (car (widget-get widget :children)) :value-inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 (defun widget-choice-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 ;; Get default for the first choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 (widget-default-get (car (widget-get widget :args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 (defcustom widget-choice-toggle nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 "If non-nil, a binary choice will just toggle between the values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 Otherwise, the user will explicitly have to choose between the values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 when he invoked the menu."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 (defun widget-choice-mouse-down-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 ;; Return non-nil if we need a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 (old (widget-get widget :choice)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 (cond ((not (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 ;; No place to pop up a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 ((< (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 ;; Empty or singleton list, just return the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 ((> (length args) widget-menu-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 ;; Too long, prompt.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 ((> (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 ;; Reasonable sized list, use menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 ((and widget-choice-toggle (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 ;; We toggle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 ;; Ask which of the two.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 (defun widget-choice-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 ;; Make a choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 (old (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 (tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 (completion-ignore-case (widget-get widget :case-fold))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 current choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 ;; Remember old value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 (if (and old (not (widget-apply widget :validate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 (let* ((external (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 (internal (widget-apply old :value-to-internal external)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 (widget-put old :value internal)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 ;; Find new choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 (setq current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 (cond ((= (length args) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 ((= (length args) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 ((and widget-choice-toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 (= (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 (if (eq old (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 (nth 1 args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 (setq choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 (cons (cons (widget-apply current :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 (let ((choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 (widget-choose tag (reverse choices) event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 (widget-put widget :explicit-choice choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 choice))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 (when current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 (let ((value (widget-default-get current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 (widget-value-set widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 (widget-apply current :value-to-external value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 (widget-apply widget :notify widget event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 (defun widget-choice-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 ;; Valid if we have made a valid choice.
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2429 (if (eq (widget-get widget :void) (widget-get widget :choice))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2430 widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2431 (widget-apply (car (widget-get widget :children)) :validate)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 (defun widget-choice-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 ;; Matches if one of the choices matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 (while (and args (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 found (widget-apply current :match value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 (defun widget-choice-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 ;; Matches if one of the choices matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 (while (and args (null found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 found (widget-match-inline current values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 ;;; The `toggle' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 (define-widget 'toggle 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 "Toggle between two states."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 :format "%[%v%]\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 :value-create 'widget-toggle-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 :action 'widget-toggle-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 :match (lambda (widget value) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 :on "on"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 :off "off")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 (defun widget-toggle-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2465 "Insert text representing the `on' and `off' states."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 (widget-glyph-insert widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 (widget-get widget :on)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 (widget-get widget :on-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 (widget-glyph-insert widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 (widget-get widget :off)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 (widget-get widget :off-glyph))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 (defun widget-toggle-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 ;; Toggle value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 (widget-value-set widget (not (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 ;;; The `checkbox' Widget.
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 (define-widget 'checkbox 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 "A checkbox toggle."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 :on "[X]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 :on-glyph "check1"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 :off "[ ]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 :off-glyph "check0"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 :action 'widget-checkbox-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 (defun widget-checkbox-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 "Toggle checkbox, notify parent, and set active state of sibling."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 (widget-toggle-action widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 (let ((sibling (widget-get-sibling widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 (when sibling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 (widget-apply sibling :activate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 (widget-apply sibling :deactivate)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 ;;; The `checklist' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 (define-widget 'checklist 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 "A multiple choice widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 :offset 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 :entry-format "%b %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 :menu-tag "checklist"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 :greedy nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 :value-create 'widget-checklist-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 :value-get 'widget-checklist-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 :validate 'widget-checklist-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 :match 'widget-checklist-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 :match-inline 'widget-checklist-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 (defun widget-checklist-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 (args (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 (widget-checklist-add-item widget (car args) (assq (car args) alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 (widget-put widget :children (nreverse (widget-get widget :children)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 (defun widget-checklist-add-item (widget type chosen)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2529 "Create checklist item in WIDGET of type TYPE.
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2530 If the item is checked, CHOSEN is a cons whose cdr is the value."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 (let* ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 (button-args (or (widget-get type :sibling-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 (widget-get widget :button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 (insert (widget-get widget :entry-format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 (while (re-search-forward "%\\([bv%]\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 (cond ((eq escape ?%)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2548 (insert ?%))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 ((eq escape ?b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 (setq button (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 widget 'checkbox
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 :value (not (null chosen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 (setq child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 (cond ((not chosen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 (let ((child (widget-create-child widget type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 (widget-apply child :deactivate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 ((widget-get type :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 widget type (cdr chosen)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 widget type (car (cdr chosen)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 ;; Update properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 (and button child (widget-put child :button button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 (and button (widget-put widget :buttons (cons button buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 (and child (widget-put widget :children (cons child children))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 (defun widget-checklist-match (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 ;; All values must match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 (and (listp values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 (null (cdr (widget-checklist-match-inline widget values)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 (defun widget-checklist-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 ;; Find the values which match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 (let ((greedy (widget-get widget :greedy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 (args (copy-sequence (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 found rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 (while values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 (let ((answer (widget-checklist-match-up args values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 (cond (answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 (let ((vals (widget-match-inline answer values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 (setq found (append found (car vals))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 values (cdr vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 args (delq answer args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 (greedy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 (setq rest (append rest (list (car values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 values (cdr values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 (setq rest (append rest values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 values nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 (cons found rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 (defun widget-checklist-match-find (widget vals)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2599 "Find the vals which match a type in the checklist.
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2600 Return an alist of (TYPE MATCH)."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 (let ((greedy (widget-get widget :greedy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 (args (copy-sequence (widget-get widget :args)))
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 (while vals
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 (let ((answer (widget-checklist-match-up args vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 (cond (answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 (let ((match (widget-match-inline answer vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 (setq found (cons (cons answer (car match)) found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 vals (cdr match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 args (delq answer args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 (greedy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 (setq vals (cdr vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 (setq vals nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 (defun widget-checklist-match-up (args vals)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2618 "Return the first type from ARGS that matches VALS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 (let (current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 (while (and args (null found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 found (widget-match-inline current vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 (if found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 (defun widget-checklist-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 ;; The values of all selected items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 child result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 (if (widget-value (widget-get child :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 (setq result (append result (widget-apply child :value-inline)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 (defun widget-checklist-validate (widget)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2640 ;; Ticked children must be valid.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 child button found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 button (widget-get child :button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 found (and (widget-value button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 (widget-apply child :validate))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 ;;; The `option' Widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 (define-widget 'option 'checklist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 "An widget with an optional item."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 :inline t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 ;;; The `choice-item' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 (define-widget 'choice-item 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 "Button items that delegate action events to their parents."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 :action 'widget-parent-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 :format "%[%t%] \n")
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 ;;; The `radio-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 (define-widget 'radio-button 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 "A radio button for use in the `radio' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 :notify 'widget-radio-button-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 :on "(*)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 :on-glyph '("radio1" nil "radio0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 :off "( )"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 :off-glyph "radio0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 (defun widget-radio-button-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 ;; Tell daddy.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 (widget-apply (widget-get widget :parent) :action widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 ;;; The `radio-button-choice' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 (define-widget 'radio-button-choice 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 "Select one of multiple options."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 :offset 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 :entry-format "%b %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 :menu-tag "radio"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 :value-create 'widget-radio-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 :value-get 'widget-radio-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 :value-inline 'widget-radio-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 :value-set 'widget-radio-value-set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 :error "You must push one of the buttons"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 :validate 'widget-radio-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 :match 'widget-choice-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 :match-inline 'widget-choice-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 :action 'widget-radio-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 (defun widget-radio-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 (setq arg (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 (widget-radio-add-item widget arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 (defun widget-radio-add-item (widget type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 "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
2712 ;; (setq type (widget-convert type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 (let* ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 (children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 (button-args (or (widget-get type :sibling-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 (widget-get widget :button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 (chosen (and (null (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 (widget-apply type :match value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 (insert (widget-get widget :entry-format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 (while (re-search-forward "%\\([bv%]\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 (cond ((eq escape ?%)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2733 (insert ?%))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 ((eq escape ?b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 (setq button (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 widget 'radio-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 :value (not (null chosen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 (setq child (if chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 widget type value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 (widget-create-child widget type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 (unless chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 (widget-apply child :deactivate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 ;; Update properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 (when chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 (widget-put widget :choice type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 (when button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 (widget-put child :button button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 (widget-put widget :buttons (nconc buttons (list button))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 (when child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 (widget-put widget :children (nconc children (list child))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 (defun widget-radio-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 (let ((chosen (widget-radio-chosen widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 (and chosen (widget-value chosen))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 (defun widget-radio-chosen (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 "Return the widget representing the chosen radio button."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 children (cdr children))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2770 (when (widget-apply (widget-get current :button) :value-get)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2771 (setq found current
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2772 children nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 (defun widget-radio-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 children (cdr children))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2782 (when (widget-apply (widget-get current :button) :value-get)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2783 (setq found (widget-apply current :value-inline)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2784 children nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 (defun widget-radio-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 ;; We can't just delete and recreate a radio widget, since children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 ;; can be added after the original creation and won't be recreated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 ;; by `:create'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 (let* ((button (widget-get current :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 (match (and (not found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 (widget-apply current :match value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 (widget-value-set button match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 (if match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 (widget-value-set current value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 (widget-apply current :activate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 (widget-apply current :deactivate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 (setq found (or found match))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 (defun widget-radio-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 ;; Valid if we have made a valid choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 current found button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 button (widget-get current :button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 found (widget-apply button :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 (if found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 (widget-apply current :validate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 (defun widget-radio-action (widget child event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 ;; Check if a radio button was pressed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 (when (memq child buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 (let* ((button (widget-get current :button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 (cond ((eq child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 (widget-value-set button t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 (widget-apply current :activate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 ((widget-value button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 (widget-value-set button nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 (widget-apply current :deactivate)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 ;; Pass notification to parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 (widget-apply widget :notify child event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 ;;; The `insert-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 (define-widget 'insert-button 'push-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 "An insert button for the `editable-list' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 :tag "INS"
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2844 :help-echo "Insert a new item into the list at this position."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 :action 'widget-insert-button-action)
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-insert-button-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 ;; Ask the parent to insert a new item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 (widget-apply (widget-get widget :parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 :insert-before (widget-get widget :widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 ;;; The `delete-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 (define-widget 'delete-button 'push-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 "A delete button for the `editable-list' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 :tag "DEL"
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2857 :help-echo "Delete this item from the list."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 :action 'widget-delete-button-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 (defun widget-delete-button-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 ;; Ask the parent to insert a new item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 (widget-apply (widget-get widget :parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 :delete-at (widget-get widget :widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 ;;; The `editable-list' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 (defcustom widget-editable-list-gui nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 "If non nil, use GUI push-buttons in editable list when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 (define-widget 'editable-list 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 "A variable list of widgets of the same type."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 :offset 12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 :format "%v%i\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 :format-handler 'widget-editable-list-format-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 :entry-format "%i %d %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 :menu-tag "editable-list"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 :value-create 'widget-editable-list-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 :value-get 'widget-editable-list-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 :validate 'widget-children-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 :match 'widget-editable-list-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 :match-inline 'widget-editable-list-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 :insert-before 'widget-editable-list-insert-before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 :delete-at 'widget-editable-list-delete-at)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 (defun widget-editable-list-format-handler (widget escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 ;; We recognize the insert button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 (let ((widget-push-button-gui widget-editable-list-gui))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 (cond ((eq escape ?i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 (and (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 widget 'insert-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 (widget-get widget :append-button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 (widget-default-format-handler widget escape)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 (defun widget-editable-list-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 (let* ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 (type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 (widget-put widget :value-pos (copy-marker (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 (set-marker-insertion-type (widget-get widget :value-pos) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 (while value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 (let ((answer (widget-match-inline type value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 (setq children (cons (widget-editable-list-entry-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 widget
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2913 (if (widget-get type :inline)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 (car answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 (car (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 (setq value nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 (widget-put widget :children (nreverse children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 (defun widget-editable-list-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 (widget-get widget :children))))
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-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 ;; 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
2929 (and (listp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 (null (cdr (widget-editable-list-match-inline widget value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 (defun widget-editable-list-match-inline (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 (let ((type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 (ok t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 (while (and value ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 (let ((answer (widget-match-inline type value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 (setq found (append found (car answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 (setq ok nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 (cons found value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 (defun widget-editable-list-insert-before (widget before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 ;; Insert a new child in the list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 (cond (before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 (goto-char (widget-get before :entry-from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 (goto-char (widget-get widget :value-pos))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 (let ((child (widget-editable-list-entry-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 widget nil nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 (when (< (widget-get child :entry-from) (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 (set-marker (widget-get widget :from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 (widget-get child :entry-from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 (if (eq (car children) before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 (widget-put widget :children (cons child children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 (while (not (eq (car (cdr children)) before))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 (setq children (cdr children)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 (setcdr children (cons child (cdr children)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 (widget-apply widget :notify widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 (defun widget-editable-list-delete-at (widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 ;; Delete child from list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 (let ((buttons (copy-sequence (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 (while buttons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 (setq button (car buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 buttons (cdr buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 (when (eq (widget-get button :widget) child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 :buttons (delq button (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 (widget-delete button))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 (let ((entry-from (widget-get child :entry-from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 (entry-to (widget-get child :entry-to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 (widget-delete child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 (delete-region entry-from entry-to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 (set-marker entry-from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 (set-marker entry-to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 (widget-put widget :children (delq child (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 (widget-apply widget :notify widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 (defun widget-editable-list-entry-create (widget value conv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 ;; Create a new entry to the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 (let ((type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 (widget-push-button-gui widget-editable-list-gui)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 child delete insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 (and (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 (insert (widget-get widget :entry-format)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 (while (re-search-forward "%\\(.\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 (cond ((eq escape ?%)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3011 (insert ?%))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 ((eq escape ?i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 (setq insert (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 widget 'insert-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 (widget-get widget :insert-button-args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 ((eq escape ?d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 (setq delete (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 widget 'delete-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 (widget-get widget :delete-button-args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 (if conv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 (setq child (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 widget type value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 (setq child (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 widget type (widget-default-get type)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 :buttons (cons delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 (cons insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 (widget-get widget :buttons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 (let ((entry-from (copy-marker (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 (entry-to (copy-marker (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 (set-marker-insertion-type entry-from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 (set-marker-insertion-type entry-to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 (widget-put child :entry-from entry-from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 (widget-put child :entry-to entry-to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 (widget-put insert :widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 (widget-put delete :widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040 child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 ;;; The `group' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 (define-widget 'group 'default
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3045 "A widget which groups other widgets inside."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 :value-create 'widget-group-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 :value-get 'widget-editable-list-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 :default-get 'widget-group-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 :validate 'widget-children-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 :match 'widget-group-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 :match-inline 'widget-group-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 (defun widget-group-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 ;; Create each component.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 (value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 arg answer children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 (setq arg (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 answer (widget-match-inline arg value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 (push (cond ((null answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 (widget-create-child widget arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 ((widget-get arg :inline)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3072 (widget-create-child-value widget arg (car answer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 (t
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3074 (widget-create-child-value widget arg (car (car answer)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 (widget-put widget :children (nreverse children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 (defun widget-group-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 ;; Get the default of the components.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 (mapcar 'widget-default-get (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 (defun widget-group-match (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 ;; Match if the components match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 (and (listp values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 (let ((match (widget-group-match-inline widget values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 (and match (null (cdr match))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 (defun widget-group-match-inline (widget vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 ;; Match if the components match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 argument answer found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 (setq argument (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 answer (widget-match-inline argument vals))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 (setq vals (cdr answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 found (append found (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 (setq vals nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 args nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 (cons found vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 nil)))
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 ;;; The `visibility' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 (define-widget 'visibility 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 "An indicator and manipulator for hidden items."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 :on "Hide"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 :off "Show"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 :value-create 'widget-visibility-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 :action 'widget-toggle-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 :match (lambda (widget value) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 (defun widget-visibility-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 ;; Insert text representing the `on' and `off' states.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 (let ((on (widget-get widget :on))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 (off (widget-get widget :off)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 (if on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 (setq on (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 widget-push-button-suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 (setq on ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 (if off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 (setq off (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 widget-push-button-suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 (setq off ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 (widget-glyph-insert widget on '("down" "down-pushed"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 (widget-glyph-insert widget off '("right" "right-pushed")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 ;;; The `documentation-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138 ;; This is a helper widget for `documentation-string'.
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 (define-widget 'documentation-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 "Link type used in documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 :tab-order -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 :help-echo 'widget-documentation-link-echo-help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 :action 'widget-documentation-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 (defun widget-documentation-link-echo-help (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 "Tell what this link will describe."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 (concat "Describe the `" (widget-get widget :value) "' symbol."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 (defun widget-documentation-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 "Display documentation for WIDGET's value. Ignore optional argument EVENT."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 (let* ((string (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 (symbol (intern string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 (if (and (fboundp symbol) (boundp symbol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 ;; 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
3156 (apropos (concat "\\`" (regexp-quote string) "\\'"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 (if (fboundp symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158 (describe-function symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 (describe-variable symbol)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 (defcustom widget-documentation-links t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 "Add hyperlinks to documentation strings when non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 (defcustom widget-documentation-link-regexp "`\\([^\n`' ]+\\)'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 "Regexp for matching potential links in documentation strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 The first group should be the link itself."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 :type 'regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 (defcustom widget-documentation-link-p 'intern-soft
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 "Predicate used to test if a string is useful as a link.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 The value should be a function. The function will be called one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 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
3176 link for that string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 :options '(widget-documentation-link-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 (defcustom widget-documentation-link-type 'documentation-link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 "Widget type used for links in documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 :type 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 (defun widget-documentation-link-add (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 (widget-specify-doc widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 (when widget-documentation-links
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 (let ((regexp widget-documentation-link-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 (predicate widget-documentation-link-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 (type widget-documentation-link-type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 (buttons (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 (while (re-search-forward regexp to t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 (let ((name (match-string 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 (begin (match-beginning 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 (end (match-end 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 (when (funcall predicate name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 (push (widget-convert-button type begin end :value name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 buttons)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 (widget-put widget :buttons buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 (let ((indent (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 (when (and indent (not (zerop indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 (narrow-to-region from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 (while (search-forward "\n" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 (insert-char ?\ indent)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 ;;; The `documentation-string' Widget.
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 (define-widget 'documentation-string 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 "A documentation string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 :action 'widget-documentation-string-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 :value-create 'widget-documentation-string-value-create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 (defun widget-documentation-string-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 ;; Insert documentation string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 (let ((doc (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 (indent (widget-get widget :indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 (shown (widget-get (widget-get widget :parent) :documentation-shown))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 (start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 (if (string-match "\n" doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 (let ((before (substring doc 0 (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 (after (substring doc (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 buttons)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3231 (insert before ?\ )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 (widget-documentation-link-add widget start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 (push (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 widget 'visibility
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 :help-echo (lambda (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 "Hide" "Show")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 " the rest of the documentation"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 :off "More"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 :action 'widget-parent-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 shown)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 (when shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 (when indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 (insert-char ?\ indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 (insert after)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 (widget-documentation-link-add widget start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 (widget-put widget :buttons buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 (insert doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 (widget-documentation-link-add widget start (point))))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3253 (insert ?\n))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 (defun widget-documentation-string-action (widget &rest ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 ;; Toggle documentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 (widget-put parent :documentation-shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 (not (widget-get parent :documentation-shown))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 ;; Redraw.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 (widget-value-set widget (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3263
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 ;;; The Sexp Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 (define-widget 'const 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 "An immutable sexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 :prompt-value 'widget-const-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 :format "%t\n%d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 (defun widget-const-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 ;; Return the value of the const.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 (define-widget 'function-item 'const
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 "An immutable function name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 :format "%v\n%h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 :documentation-property (lambda (symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 (documentation symbol t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 (define-widget 'variable-item 'const
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 "An immutable variable name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 :format "%v\n%h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 :documentation-property 'variable-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3288 (define-widget 'other 'sexp
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3289 "Matches any value, but doesn't let the user edit the value.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3290 This is useful as last item in a `choice' widget.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3291 You should use this widget type with a default value,
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3292 as in (other DEFAULT) or (other :tag \"NAME\" DEFAULT).
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3293 If the user selects this alternative, that specifies DEFAULT
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3294 as the value."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3295 :tag "Other"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3296 :format "%t%n"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3297 :value 'other)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3298
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 (defvar widget-string-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 "History of input to `widget-string-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 (define-widget 'string 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303 "A string"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304 :tag "String"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 :complete-function 'ispell-complete-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 :prompt-history 'widget-string-prompt-value-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 (define-widget 'regexp 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 "A regular expression."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 :match 'widget-regexp-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 :validate 'widget-regexp-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 ;; Doesn't work well with terminating newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 ;; :value-face 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 :tag "Regexp")
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-regexp-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 ;; Match valid regexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 (and (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 (prog1 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 (string-match value ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 (defun widget-regexp-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 "Check that the value of WIDGET is a valid regexp."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3327 (condition-case data
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3328 (prog1 nil
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3329 (string-match (widget-value widget) ""))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3330 (error (widget-put widget :error (error-message-string data))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3331 widget)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 (define-widget 'file 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 "A file widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 It will read a file name from the minibuffer when invoked."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 :complete-function 'widget-file-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 :prompt-value 'widget-file-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 ;; Doesn't work well with terminating newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 ;; :value-face 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 :tag "File")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 (defun widget-file-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 "Perform completion on file name preceding point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 (let* ((end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 (beg (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 (skip-chars-backward "^ ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 (pattern (buffer-substring beg end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 (name-part (file-name-nondirectory pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 (directory (file-name-directory pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 (completion (file-name-completion name-part directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 (cond ((eq completion t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 (message "Can't find completion for \"%s\"" pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 (ding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 ((not (string= name-part completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 (delete-region beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 (insert (expand-file-name completion directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 (message "Making completion list...")
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3363 (with-output-to-temp-buffer "*Completions*"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3364 (display-completion-list
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3365 (sort (file-name-all-completions name-part directory)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3366 'string<)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 (message "Making completion list...%s" "done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 (defun widget-file-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 ;; Read file from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 (abbreviate-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 (if unbound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 (read-file-name prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 (let ((prompt2 (format "%s (default %s) " prompt value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 (dir (file-name-directory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 (file (file-name-nondirectory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 (must-match (widget-get widget :must-match)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 (read-file-name prompt2 dir nil must-match file)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 ;;;(defun widget-file-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 ;;; ;; Read a file name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 ;;; (let* ((value (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 ;;; (dir (file-name-directory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 ;;; (file (file-name-nondirectory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 ;;; (menu-tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 ;;; (must-match (widget-get widget :must-match))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 ;;; (answer (read-file-name (concat menu-tag ": (default `" value "') ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 ;;; dir nil must-match file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 ;;; (widget-value-set widget (abbreviate-file-name answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390 ;;; (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 ;;; (widget-apply widget :notify widget event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3393 ;; Fixme: use file-name-as-directory.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 (define-widget 'directory 'file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 "A directory widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 It will read a directory name from the minibuffer when invoked."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 :tag "Directory")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 (defvar widget-symbol-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 "History of input to `widget-symbol-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 (define-widget 'symbol 'editable-field
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3403 "A Lisp symbol."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 :value nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 :tag "Symbol"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 :match (lambda (widget value) (symbolp value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 :complete-function 'lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 :prompt-internal 'widget-symbol-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 :prompt-match 'symbolp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 :prompt-history 'widget-symbol-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413 (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 (symbol-name value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 (intern value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 (defun widget-symbol-prompt-internal (widget prompt initial history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 ;; Read file from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 (let ((answer (completing-read prompt obarray
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 (widget-get widget :prompt-match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 nil initial history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 (if (and (stringp answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 (not (zerop (length answer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 (error "No value"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 (defvar widget-function-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 "History of input to `widget-function-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 (define-widget 'function 'sexp
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3435 "A Lisp function."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 :complete-function 'lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 :prompt-value 'widget-field-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 :prompt-internal 'widget-symbol-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 :prompt-match 'fboundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 :prompt-history 'widget-function-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 :action 'widget-field-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 :tag "Function")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 (defvar widget-variable-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 "History of input to `widget-variable-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 (define-widget 'variable 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448 ;; Should complete on variables.
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3449 "A Lisp variable."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 :prompt-match 'boundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 :prompt-history 'widget-variable-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 :tag "Variable")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 ;; This part issues a warning when compiling without Mule. Is there a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 ;; way of shutting it up?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 ;; OK, I'll simply comment the whole thing out, until someone decides
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 ;; to do something with it.
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3459
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3460 ;; OK, _I_'ll simply comment it back in, so somebody will get irritated and
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3461 ;; do something about it.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3462
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3463 (defvar widget-coding-system-prompt-value-history nil
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3464 "History of input to `widget-coding-system-prompt-value'.")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3465
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3466 (define-widget 'coding-system 'symbol
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3467 "A MULE coding-system."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3468 :format "%{%t%}: %v"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3469 :tag "Coding system"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3470 :prompt-history 'widget-coding-system-prompt-value-history
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3471 :prompt-value 'widget-coding-system-prompt-value
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3472 :action 'widget-coding-system-action)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3473
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3474 (defun widget-coding-system-prompt-value (widget prompt value unbound)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3475 ;; Read coding-system from minibuffer.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3476 (intern
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3477 (completing-read (format "%s (default %s) " prompt value)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3478 (mapcar (lambda (sym)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3479 (list (symbol-name sym)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3480 (coding-system-list)))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3481
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3482 (defun widget-coding-system-action (widget &optional event)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3483 ;; Read a file name from the minibuffer.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3484 (let ((answer
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3485 (widget-coding-system-prompt-value
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3486 widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3487 (widget-apply widget :menu-tag-get)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3488 (widget-value widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3489 t)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3490 (widget-value-set widget answer)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3491 (widget-apply widget :notify widget event)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3492 (widget-setup)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 (define-widget 'sexp 'editable-field
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3495 "An arbitrary Lisp expression."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 :tag "Lisp expression"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 :value nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 :validate 'widget-sexp-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 :match (lambda (widget value) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 :value-to-internal 'widget-sexp-value-to-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 :value-to-external (lambda (widget value) (read value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 :prompt-history 'widget-sexp-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 :prompt-value 'widget-sexp-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 (defun widget-sexp-value-to-internal (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 ;; Use cl-prettyprint for printer representation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 (let ((pp (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 (prin1-to-string value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 (widget-prettyprint-to-string value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 (if (> (length pp) 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512 (concat "\n" pp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 pp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 (defun widget-sexp-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 ;; 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
3517 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 (insert (widget-apply widget :value-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 (condition-case data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 (let ((value (read buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 (if (widget-apply widget :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 (widget-put widget :error (widget-get widget :type-error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 :error (format "Junk at end of expression: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 (buffer-substring (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 (error (widget-put widget :error (error-message-string data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 widget)))))
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 (defvar widget-sexp-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 "History of input to `widget-sexp-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 (defun widget-sexp-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 ;; Read an arbitrary sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 (let ((found (read-string prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 (if unbound nil (cons (prin1-to-string value) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 (widget-get widget :prompt-history))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 (insert found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 (let ((answer (read buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 (unless (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552 (signal 'error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 (list "Junk at end of expression"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 (buffer-substring (point) (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 answer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 (define-widget 'restricted-sexp 'sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 "A Lisp expression restricted to values that match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 To use this type, you must define :match or :match-alternatives."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 :type-error "The specified value is not valid"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 :match 'widget-restricted-sexp-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 (if (widget-apply widget :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 (prin1-to-string value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 (defun widget-restricted-sexp-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 (let ((alternatives (widget-get widget :match-alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 matched)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 (while (and alternatives (not matched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 (if (cond ((functionp (car alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 (funcall (car alternatives) value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 ((and (consp (car alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 (eq (car (car alternatives)) 'quote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 (eq value (nth 1 (car alternatives)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 (setq matched t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 (setq alternatives (cdr alternatives)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 matched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 (define-widget 'integer 'restricted-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 "An integer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 :tag "Integer"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 :value 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 :type-error "This field should contain an integer"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 :match-alternatives '(integerp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 (define-widget 'number 'restricted-sexp
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3588 "A number (floating point or integer)."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 :tag "Number"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 :value 0.0
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3591 :type-error "This field should contain a number (floating point or integer)"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 :match-alternatives '(numberp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3594 (define-widget 'float 'restricted-sexp
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3595 "A floating point number."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3596 :tag "Floating point number"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3597 :value 0.0
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3598 :type-error "This field should contain a floating point number"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3599 :match-alternatives '(floatp))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3600
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 (define-widget 'character 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 "A character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 :tag "Character"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 :value ?\0
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3605 :size 1
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 :valid-regexp "\\`[\0-\377]\\'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 :error "This field should contain a single character"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 (char-to-string value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 (aref value 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 :match (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 (characterp value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 (define-widget 'list 'group
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3621 "A Lisp list."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 :tag "List"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 :format "%{%t%}:\n%v")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 (define-widget 'vector 'group
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3626 "A Lisp vector."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 :tag "Vector"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 :match 'widget-vector-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 :value-to-internal (lambda (widget value) (append value nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 :value-to-external (lambda (widget value) (vconcat value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633 (defun widget-vector-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 (and (vectorp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 (widget-group-match widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636 (widget-apply widget :value-to-internal 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 'cons 'group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 "A cons-cell."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 :tag "Cons-cell"
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 :match 'widget-cons-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 (list (car value) (cdr value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 :value-to-external (lambda (widget value)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3646 (cons (nth 0 value) (nth 1 value))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648 (defun widget-cons-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 (and (consp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 (widget-group-match widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 (widget-apply widget :value-to-internal value))))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3652
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3653 ;;; The `plist' Widget.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3654 ;;
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3655 ;; Property lists.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3656
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3657 (define-widget 'plist 'list
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3658 "A property list."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3659 :key-type '(symbol :tag "Key")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3660 :value-type '(sexp :tag "Value")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3661 :convert-widget 'widget-plist-convert-widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3662 :tag "Plist")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3663
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3664 (defvar widget-plist-value-type) ;Dynamic variable
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3665
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3666 (defun widget-plist-convert-widget (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3667 ;; Handle `:options'.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3668 (let* ((options (widget-get widget :options))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3669 (widget-plist-value-type (widget-get widget :value-type))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3670 (other `(editable-list :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3671 (group :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3672 ,(widget-get widget :key-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3673 ,widget-plist-value-type)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3674 (args (if options
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3675 (list `(checklist :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3676 :greedy t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3677 ,@(mapcar 'widget-plist-convert-option
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3678 options))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3679 other)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3680 (list other))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3681 (widget-put widget :args args)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3682 widget))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3683
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3684 (defun widget-plist-convert-option (option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3685 ;; Convert a single plist option.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3686 (let (key-type value-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3687 (if (listp option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3688 (let ((key (nth 0 option)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3689 (setq value-type (nth 1 option))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3690 (if (listp key)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3691 (setq key-type key)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3692 (setq key-type `(const ,key))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3693 (setq key-type `(const ,option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3694 value-type widget-plist-value-type))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3695 `(group :format "Key: %v" :inline t ,key-type ,value-type)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3696
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3697
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3698 ;;; The `alist' Widget.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3699 ;;
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3700 ;; Association lists.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3701
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3702 (define-widget 'alist 'list
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3703 "An association list."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3704 :key-type '(sexp :tag "Key")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3705 :value-type '(sexp :tag "Value")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3706 :convert-widget 'widget-alist-convert-widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3707 :tag "Alist")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3708
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3709 (defvar widget-alist-value-type) ;Dynamic variable
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3710
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3711 (defun widget-alist-convert-widget (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3712 ;; Handle `:options'.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3713 (let* ((options (widget-get widget :options))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3714 (widget-alist-value-type (widget-get widget :value-type))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3715 (other `(editable-list :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3716 (cons :format "%v"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3717 ,(widget-get widget :key-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3718 ,widget-alist-value-type)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3719 (args (if options
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3720 (list `(checklist :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3721 :greedy t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3722 ,@(mapcar 'widget-alist-convert-option
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3723 options))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3724 other)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3725 (list other))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3726 (widget-put widget :args args)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3727 widget))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3728
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3729 (defun widget-alist-convert-option (option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3730 ;; Convert a single alist option.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3731 (let (key-type value-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3732 (if (listp option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3733 (let ((key (nth 0 option)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3734 (setq value-type (nth 1 option))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3735 (if (listp key)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3736 (setq key-type key)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3737 (setq key-type `(const ,key))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3738 (setq key-type `(const ,option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3739 value-type widget-alist-value-type))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3740 `(cons :format "Key: %v" ,key-type ,value-type)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3741
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3742
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743 (define-widget 'choice 'menu-choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3744 "A union of several sexp types."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745 :tag "Choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746 :format "%{%t%}: %[Value Menu%] %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3747 :button-prefix 'widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3748 :button-suffix 'widget-push-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3749 :prompt-value 'widget-choice-prompt-value)
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 (defun widget-choice-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3752 "Make a choice."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3753 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3754 (completion-ignore-case (widget-get widget :case-fold))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3755 current choices old)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3756 ;; Find the first arg that matches VALUE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3757 (let ((look args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3758 (while look
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3759 (if (widget-apply (car look) :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3760 (setq old (car look)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3761 look nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762 (setq look (cdr look)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3763 ;; Find new choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3764 (setq current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3765 (cond ((= (length args) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3766 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3767 ((= (length args) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3768 (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3769 ((and (= (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3770 (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3771 (if (eq old (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3772 (nth 1 args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3773 (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3774 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3775 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3776 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3777 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3778 (setq choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779 (cons (cons (widget-apply current :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3780 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3781 choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3782 (let ((val (completing-read prompt choices nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 (if (stringp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 (let ((try (try-completion val choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3785 (when (stringp try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786 (setq val try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 (cdr (assoc val choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3789 (if current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 (widget-prompt-value current prompt nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 (define-widget 'radio 'radio-button-choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794 "A union of several sexp types."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 :tag "Choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 :prompt-value 'widget-choice-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 (define-widget 'repeat 'editable-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800 "A variable length homogeneous list."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801 :tag "Repeat"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 :format "%{%t%}:\n%v%i\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804 (define-widget 'set 'checklist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3805 "A list of members from a fixed set."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3806 :tag "Set"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807 :format "%{%t%}:\n%v")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3809 (define-widget 'boolean 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810 "To be nil or non-nil, that is the question."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811 :tag "Boolean"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 :prompt-value 'widget-boolean-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813 :button-prefix 'widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814 :button-suffix 'widget-push-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 :format "%{%t%}: %[Toggle%] %v\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3816 :on "on (non-nil)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3817 :off "off (nil)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3819 (defun widget-boolean-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3820 ;; Toggle a boolean.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3821 (y-or-n-p prompt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3823 ;;; The `color' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3824
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3825 ;; Fixme: match
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3826 (define-widget 'color 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3827 "Choose a color name (with sample)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3828 :format "%[%t%]: %v (%{sample%})\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3829 :size 10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3830 :tag "Color"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3831 :value "black"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3832 :complete 'widget-color-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3833 :sample-face-get 'widget-color-sample-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3834 :notify 'widget-color-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3835 :action 'widget-color-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 (defun widget-color-complete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3838 "Complete the color in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3839 (let* ((prefix (buffer-substring-no-properties (widget-field-start widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3840 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3841 (list (read-color-completion-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3842 (completion (try-completion prefix list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3843 (cond ((eq completion t)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3844 (message "Exact match."))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3845 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3846 (error "Can't find completion for \"%s\"" prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3847 ((not (string-equal prefix completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3848 (insert (substring completion (length prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3849 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3850 (message "Making completion list...")
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3851 (with-output-to-temp-buffer "*Completions*"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3852 (display-completion-list (all-completions prefix list nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3853 (message "Making completion list...done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3855 (defun widget-color-sample-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856 (or (widget-get widget :sample-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3857 (let ((color (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858 (face (make-face (gensym "sample-face-") nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859 ;; Use the face object, not its name, to prevent lossage if gc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860 ;; happens before applying the face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3861 (widget-put widget :sample-face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3862 (and color
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3863 (not (equal color ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3864 (valid-color-name-p color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3865 (set-face-foreground face color))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3866 face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3868 (defvar widget-color-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3869 "History of entered colors.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3871 (defun widget-color-action (widget &optional event)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3872 "Prompt for a color."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3873 (let* ((tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3874 (answer (read-color (concat tag ": "))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3875 (unless (zerop (length answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3876 (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3877 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3878 (widget-apply widget :notify widget event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3879
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3880 (defun widget-color-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3881 "Update the sample, and notify the parent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3882 (let* ((face (widget-apply widget :sample-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3883 (color (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3884 (if (valid-color-name-p color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3885 (set-face-foreground face color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3886 (remove-face-property face 'foreground)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3887 (widget-default-notify widget child event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3888
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3889 ;;; The Help Echo
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3890
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3891 (defun widget-echo-help (pos)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3892 "Display the help-echo text for widget at POS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3893 (let* ((widget (widget-at pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3894 (help-echo (and widget (widget-get widget :help-echo))))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3895 (if (functionp help-echo)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3896 (setq help-echo (funcall help-echo widget)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3897 (if (stringp help-echo)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3898 (display-message 'help-echo help-echo))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3900 ;;; The End:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902 (provide 'wid-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3904 ;;; wid-edit.el ends here