annotate lisp/wid-edit.el @ 652:2cf5d151eeb9

[xemacs-hg @ 2001-08-26 10:25:11 by stephent] Update docs for widgets and lisp/README. <15240.52706.361788.550139@turnbull.sk.tsukuba.ac.jp>
author stephent
date Sun, 26 Aug 2001 10:25:14 +0000
parents d7a9135ec789
children 76d5a3dd827a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; wid-edit.el --- Functions for creating and using widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 ;;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
3 ;; Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: extensions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; Version: 1.9960-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; See `widget.el'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 (require 'widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 (autoload 'finder-commentary "finder" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;;; Customization.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 (defgroup widgets nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 "Customization support for the Widget Library."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 :link '(custom-manual "(widget)Top")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 :link '(url-link :tag "Development Page"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 "http://www.dina.kvl.dk/~abraham/custom/")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 :link '(emacs-library-link :tag "Lisp File" "widget.el")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 :prefix "widget-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 :group 'extensions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 :group 'hypermedia)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 (defgroup widget-documentation nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 "Options controlling the display of documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 (defgroup widget-faces nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 "Faces used by the widget library."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 :group 'faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 (defvar widget-documentation-face 'widget-documentation-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 "Face used for documentation strings in widges.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 This exists as a variable so it can be set locally in certain buffers.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 (defface widget-documentation-face '((((class color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 (:foreground "lime green"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (((class color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (:foreground "dark green"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 "Face used for documentation text."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 :group 'widget-documentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (defvar widget-button-face 'widget-button-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 "Face used for buttons in widges.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 This exists as a variable so it can be set locally in certain buffers.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (defface widget-button-face '((t (:bold t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 "Face used for widget buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (defcustom widget-mouse-face 'highlight
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 "Face used for widget buttons when the mouse is above them."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 :type 'face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (defface widget-field-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (:background "gray85"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (:background "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 "Face used for editable fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 ;; Currently unused
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ;(defface widget-single-line-field-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ; (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 ; (:background "gray85"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 ; (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 ; (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ; (:background "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 ; (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 ; (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ; "Face used for editable fields spanning only a single line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ; :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ;(defvar widget-single-line-display-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ; (let ((table (make-display-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ; (aset table 9 "^I")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ; (aset table 10 "^J")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ; table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ; "Display table used for single-line editable fields.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ;(set-face-display-table 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ; widget-single-line-display-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ;; Some functions from this file have been ported to C for speed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ;; Setting this to t (*before* loading wid-edit.el) will make them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ;; shadow the subrs. It should be used only for debugging purposes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (defvar widget-shadow-subrs nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 ;;; Utility functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 ;; These are not really widget specific.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 (when (or (not (fboundp 'widget-plist-member))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 ;; Recoded in C, for efficiency. It used to be a defsubst, but old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 ;; compiled code won't fail -- it will just be slower.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (defun widget-plist-member (plist prop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ;; Return non-nil if PLIST has the property PROP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ;; PLIST is a property list, which is a list of the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 ;; (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 ;; Unlike `plist-get', this allows you to distinguish between a missing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 ;; property and a property with the value nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 ;; The value is actually the tail of PLIST whose car is PROP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (while (and plist (not (eq (car plist) prop)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (setq plist (cddr plist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 (defun widget-princ-to-string (object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 ;; Return string representation of OBJECT, any Lisp object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 ;; No quoting characters are used; no delimiters are printed around
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 ;; the contents of strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (with-current-buffer (get-buffer-create " *widget-tmp*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (princ object (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (buffer-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (defun widget-prettyprint-to-string (object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ;; Like pp-to-string, but uses `cl-prettyprint'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (with-current-buffer (get-buffer-create " *widget-tmp*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (cl-prettyprint object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 ;; `cl-prettyprint' always surrounds the text with newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (when (eq (char-after (point-min)) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (delete-region (point-min) (1+ (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (when (eq (char-before (point-max)) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (delete-region (1- (point-max)) (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (buffer-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (defun widget-clear-undo ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 "Clear all undo information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (buffer-disable-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (buffer-enable-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (defcustom widget-menu-max-size 40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 "Largest number of items allowed in a popup-menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 Larger menus are read through the minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 :type 'integer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (defcustom widget-menu-minibuffer-flag nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 "*Control how to ask for a choice from the keyboard.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 Non-nil means use the minibuffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 nil means read a single character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (defun widget-choose (title items &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 "Choose an item from a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 First argument TITLE is the name of the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 Second argument ITEMS is an list whose members are either
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (NAME . VALUE), to indicate selectable items, or just strings to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 indicate unselectable items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 Optional third argument EVENT is an input event.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 The user is asked to choose between each NAME from the items alist,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 and the VALUE of the chosen element will be returned. If EVENT is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 mouse event, and the number of elements in items is less than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 `widget-menu-max-size', a popup menu will be used, otherwise the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (cond ((and (< (length items) widget-menu-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 ;; Pressed by the mouse.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (let ((val (get-popup-menu-response
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (cons title
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (mapcar (lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (if (stringp x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (vector x nil nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (vector (car x) (list (car x)) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 items)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (setq val (and val
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (listp (event-object val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (stringp (car-safe (event-object val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (car (event-object val))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (cdr (assoc val items))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 ((and (not widget-menu-minibuffer-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 ;; Can't handle more than 10 items (as many digits)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (<= (length items) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 ;; Construct a menu of the choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 ;; and then use it for prompting for a single character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (let* ((overriding-terminal-local-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (map (make-sparse-keymap title))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (next-digit ?0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 some-choice-enabled value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 ;; Define SPC as a prefix char to get to this menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (define-key overriding-terminal-local-map " " map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 (with-current-buffer (get-buffer-create " widget-choose")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (insert "Available choices:\n\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (dolist (choice items)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (when (consp choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (let* ((name (car choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (function (cdr choice)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (insert (format "%c = %s\n" next-digit name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (define-key map (vector next-digit) function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (setq some-choice-enabled t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ;; Allocate digits to disabled alternatives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ;; so that the digit of a given alternative never varies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (incf next-digit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (insert "\nC-g = Quit"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (or some-choice-enabled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (error "None of the choices is currently meaningful"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (define-key map [?\C-g] 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (define-key map [t] 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 ;(setcdr map (nreverse (cdr map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 ;; Unread a SPC to lead to our new menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (push (character-to-event ?\ ) unread-command-events)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ;; Read a char with the menu, and return the result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ;; that corresponds to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (save-window-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (display-buffer (get-buffer " widget-choose"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (let ((cursor-in-echo-area t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (setq value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (lookup-key overriding-terminal-local-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (read-key-sequence (concat title ": ") t)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (message "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (when (or (eq value 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (null value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (error "Canceled"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 ;; Read the choice of name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (setq items (remove-if 'stringp items))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (let ((val (completing-read (concat title ": ") items nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (if (stringp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (let ((try (try-completion val items)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (when (stringp try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (setq val try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (cdr (assoc val items)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 ;;; Widget text specifications.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 ;; These functions are for specifying text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (defcustom widget-field-add-space t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 ;; Setting this to nil might be available, once some problems are resolved.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 "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
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 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
282 it will become impossible to edit a zero size field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (defcustom widget-field-use-before-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (and (or (> emacs-minor-version 34)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (> emacs-major-version 19))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (not (string-match "XEmacs" emacs-version)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 "Non-nil means use `before-change-functions' to track editable fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 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
292 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
293 new value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (defun widget-echo-this-extent (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (let* ((widget (or (extent-property extent 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (extent-property extent 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (extent-property extent 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (setq help-echo (funcall help-echo widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (when (stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (setq help-echo-owns-message t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (display-message 'help-echo help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (defsubst widget-handle-help-echo (extent help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (set-extent-property extent 'balloon-help help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (set-extent-property extent 'help-echo help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (when (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (set-extent-property extent 'balloon-help 'widget-echo-this-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (set-extent-property extent 'help-echo 'widget-echo-this-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (defun widget-specify-field (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 "Specify editable button for WIDGET between FROM and TO."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (goto-char to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (cond ((null (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 ;; Terminating space is not part of the field, but necessary in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 ;; 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
323 ;; at the end of the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (widget-field-add-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (insert-and-inherit " ")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (setq to (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (let ((map (widget-get widget :keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (face (or (widget-get widget :value-face) 'widget-field-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (help-echo (widget-get widget :help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (unless (or (stringp help-echo) (null help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (widget-put widget :field-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (and (or (not widget-field-add-space)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (set-extent-property extent 'end-closed nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (set-extent-property extent 'detachable nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (set-extent-property extent 'field widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (set-extent-property extent 'button-or-field t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (set-extent-property extent 'keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (widget-handle-help-echo extent help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (widget-specify-secret widget))
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-secret (field)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
346 "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
347
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
348 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
349 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (let ((secret (widget-get field :secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (size (widget-get field :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (when secret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (let ((begin (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (end (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (when size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (while (and (> end begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (eq (char-after (1- end)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (setq end (1- end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (while (< begin end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (let ((old (char-after begin)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (unless (eq old secret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (subst-char-in-region begin (1+ begin) old secret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (put-text-property begin (1+ begin) 'secret old))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (setq begin (1+ begin))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (defun widget-specify-button (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 "Specify button for WIDGET between FROM and TO."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (let ((face (widget-apply widget :button-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (help-echo (widget-get widget :help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (extent (make-extent from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (map (widget-get widget :button-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (widget-put widget :button-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (unless (or (null help-echo) (stringp help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (set-extent-property extent 'button widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (set-extent-property extent 'button-or-field t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (set-extent-property extent 'mouse-face widget-mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (widget-handle-help-echo extent help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (set-extent-property extent 'keymap map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (defun widget-mouse-help (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 "Find mouse help string for button in extent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (let* ((widget (widget-at (extent-start-position extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (cond ((stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 ((and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (stringp (setq help-echo (funcall help-echo widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (format "(widget %S :help-echo %S)" widget help-echo)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (defun widget-specify-sample (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 ;; Specify sample for WIDGET between FROM and TO.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (let ((face (widget-apply widget :sample-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (extent (make-extent from to nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (widget-put widget :sample-extent extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (defun widget-specify-doc (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 ;; Specify documentation for WIDGET between FROM and TO.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (let ((extent (make-extent from to)))
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 'widget-doc widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (set-extent-property extent 'face widget-documentation-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (widget-put widget :doc-extent extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (defmacro widget-specify-insert (&rest form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 ;; Execute FORM without inheriting any text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 `(save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (insert "<>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (narrow-to-region (- (point) 2) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (goto-char (1+ (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 ;; We use `prog1' instead of a `result' variable, as the latter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 ;; confuses the byte-compiler in some cases (a warning).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (prog1 (progn ,@form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (delete-region (point-min) (1+ (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (delete-region (1- (point-max)) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (goto-char (point-max))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (put 'widget-specify-insert 'edebug-form-spec '(&rest form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 ;;; Inactive Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (defface widget-inactive-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (:foreground "light gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (:foreground "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 "Face used for inactive widgets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 ;; For inactiveness to work on complex structures, it is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 ;; sufficient to keep track of whether a button/field/glyph is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 ;; inactive or not -- we must know how many time it was deactivated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 ;; (inactiveness level). Successive deactivations of the same button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 ;; increment its inactive-count, and activations decrement it. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 ;; inactive-count reaches 0, the button/field/glyph is reactivated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (defun widget-activation-widget-mapper (extent action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 "Activate or deactivate EXTENT's widget (button or field).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 Suitable for use with `map-extents'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (ecase action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (:activate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (decf (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (when (zerop (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 extent (extent-property extent :inactive-plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 (set-extent-property extent :inactive-plist nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (:deactivate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (incf (extent-property extent :inactive-count 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 ;; Store a plist of old properties, which will be fed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 ;; `set-extent-properties'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (unless (extent-property extent :inactive-plist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 (set-extent-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 extent :inactive-plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 (list 'mouse-face (extent-property extent 'mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 'help-echo (extent-property extent 'help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 'keymap (extent-property extent 'keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 extent '(mouse-face nil help-echo nil keymap nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 nil)
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 (defun widget-activation-glyph-mapper (extent action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 (let ((activate-p (if (eq action :activate) t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 (if activate-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 (decf (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 (incf (extent-property extent :inactive-count 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 (when (or (and activate-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (zerop (extent-property extent :inactive-count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 (and (not activate-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (not (zerop (extent-property extent :inactive-count)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (let* ((glyph-widget (extent-property extent 'glyph-widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (up-glyph (widget-get glyph-widget :glyph-up))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (inactive-glyph (widget-get glyph-widget :glyph-inactive))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
486 (instantiator (widget-get glyph-widget :glyph-instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (new-glyph (if activate-p up-glyph inactive-glyph)))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
488 (cond
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
489 ;; Assume that an instantiator means a native widget.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
490 (instantiator
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
491 (setq instantiator
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
492 (set-instantiator-property instantiator :active activate-p))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
493 (widget-put glyph-widget :glyph-instantiator instantiator)
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
494 (set-glyph-image up-glyph instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 ;; Check that the new glyph exists, and differs from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 ;; default one.
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
497 ((and up-glyph inactive-glyph (not (eq up-glyph inactive-glyph))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
498 ;; Check if the glyph is already installed.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
499 (not (eq (extent-end-glyph extent) new-glyph)))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
500 ;; Change it.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
501 (set-extent-end-glyph extent new-glyph))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 (defun widget-specify-inactive (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 "Make WIDGET inactive for user modifications."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (unless (widget-get widget :inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (let ((extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 ;; 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
509 ;; the inactive editable fields now lose their keymaps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 extent '(start-open t face widget-inactive-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 detachable t priority 2001 widget-inactive t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (widget-put widget :inactive extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 ;; Deactivate the buttons and fields within the range. In some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 ;; cases, the fields are not yet setup at the time this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 ;; is called. Those fields are deactivated explicitly by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 ;; `widget-setup'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (map-extents 'widget-activation-widget-mapper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 nil from to :deactivate nil 'button-or-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 ;; Deactivate glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 (map-extents 'widget-activation-glyph-mapper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 nil from to :deactivate nil 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 (defun widget-specify-active (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 "Make WIDGET active for user modifications."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
526 (let ((inactive (widget-get widget :inactive))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
527 (from (widget-get widget :from))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
528 (to (widget-get widget :to)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 (when (and inactive (not (extent-detached-p inactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 ;; Reactivate the buttons and fields covered by the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (map-extents 'widget-activation-widget-mapper
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
532 nil from to :activate nil 'button-or-field)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 ;; Reactivate the glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (map-extents 'widget-activation-glyph-mapper
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
535 nil from to :activate nil 'end-glyph)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (delete-extent inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (widget-put widget :inactive nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 ;;; Widget Properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (defsubst widget-type (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 "Return the type of WIDGET, a symbol."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (car widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (when (or (not (fboundp 'widget-put))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (defun widget-put (widget property value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 "In WIDGET set PROPERTY to VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 The value can later be retrieved with `widget-get'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (setcdr widget (plist-put (cdr widget) property value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 ;; Recoded in C, for efficiency:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 (when (or (not (fboundp 'widget-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 (defun widget-get (widget property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 "In WIDGET, get the value of PROPERTY.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
558 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
559 later with `widget-put'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (let ((missing t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 value tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 (while missing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 (cond ((setq tmp (widget-plist-member (cdr widget) property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 (setq value (car (cdr tmp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 missing nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 ((setq tmp (car widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (setq widget (get tmp 'widget-type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 (setq missing nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 (defun widget-get-indirect (widget property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 "In WIDGET, get the value of PROPERTY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 If the value is a symbol, return its binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 Otherwise, just return the value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (let ((value (widget-get widget property)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 (symbol-value value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 (defun widget-member (widget property)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
582 "Return t if there is a definition in WIDGET for PROPERTY."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (cond ((widget-plist-member (cdr widget) property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 ((car widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 (widget-member (get (car widget) 'widget-type) property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 (t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 (when (or (not (fboundp 'widget-apply))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 ;;This is in C, so don't ###utoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 (defun widget-apply (widget property &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 "Apply the value of WIDGET's PROPERTY to the widget itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 ARGS are passed as extra arguments to the function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (apply (widget-get widget property) widget args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (defun widget-value (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 "Extract the current value of WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 :value-to-external (widget-apply widget :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (defun widget-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 "Set the current value of WIDGET to VALUE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 :value-set (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 :value-to-internal value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 (defun widget-default-get (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
609 "Extract the default value of WIDGET."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (or (widget-get widget :value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 (widget-apply widget :default-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (defun widget-match-inline (widget vals)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
614 "In WIDGET, match the start of VALS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (cond ((widget-get widget :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (widget-apply widget :match-inline vals))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
617 ((and (listp vals)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 (widget-apply widget :match (car vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 (cons (list (car vals)) (cdr vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 (t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 (defun widget-apply-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 "Apply :action in WIDGET in response to EVENT."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 (if (widget-apply widget :active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (widget-apply widget :action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (error "Attempt to perform action on inactive widget")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
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 ;;; Helper functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 ;; These are widget specific.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (defun widget-prompt-value (widget prompt &optional value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 "Prompt for a value matching WIDGET, using PROMPT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 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
637 (unless (listp widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 (setq widget (list widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 (setq prompt (format "[%s] %s" (widget-type widget) prompt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 (setq widget (widget-convert widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (let ((answer (widget-apply widget :prompt-value prompt value unbound)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 (while (not (widget-apply widget :match answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 (setq answer (signal 'error (list "Answer does not match type"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 answer (widget-type widget)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (defun widget-get-sibling (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 "Get the item WIDGET is assumed to toggle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 This is only meaningful for radio buttons or checkboxes in a list."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 (let* ((parent (widget-get widget :parent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 (children (widget-get parent :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (catch 'child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (when (eq (widget-get child :button) widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (throw 'child child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (defun widget-map-buttons (function &optional buffer maparg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 "Map FUNCTION over the buttons in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 FUNCTION is called with the arguments WIDGET and MAPARG.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 If FUNCTION returns non-nil, the walk is cancelled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 The arguments MAPARG, and BUFFER default to nil and (current-buffer),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 respectively."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (map-extents (lambda (extent ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 ;; If FUNCTION returns non-nil, we bail out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 (funcall function (extent-property extent 'button) maparg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 nil nil nil nil nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 'button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 ;;; Glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 (defcustom widget-glyph-directory (locate-data-directory "custom")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 "Where widget glyphs are located.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 If this variable is nil, widget will try to locate the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 automatically."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 :type 'directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 (defcustom widget-glyph-enable t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 "If non nil, use glyphs in images when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 (defcustom widget-image-file-name-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 '((xpm ".xpm") (gif ".gif") (png ".png") (jpeg ".jpg" ".jpeg")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (xbm ".xbm"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 "Conversion alist from image formats to file name suffixes."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 :type '(repeat (cons :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (symbol :tag "Image Format" unknown)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 (repeat :tag "Suffixes"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 (string :format "%v")))))
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 ;; Don't use this, because we cannot yet distinguish between widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 ;; glyphs associated with user action, and actionless ones.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 ;(defvar widget-glyph-pointer-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 ; (make-pointer-glyph [cursor-font :data "hand2"])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 ; "Glyph to be used as the mouse pointer shape over glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 ;Use `set-glyph-image' to change this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 (defvar widget-glyph-cache nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 "Cache of glyphs associated with strings (files).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 (defun widget-glyph-find (image tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 "Create a glyph corresponding to IMAGE with string TAG as fallback.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 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
713 xbm, gif, jpg, or png) located in `widget-glyph-directory', or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 in one of the data directories.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 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
716 used to make the glyph, with an additional TAG string fallback."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 (cond ((not (and image widget-glyph-enable))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 ;; We don't want to use glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 ((and (not (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 ;; We don't use glyphs on TTY consoles, although we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 ;; could. However, glyph faces aren't yet working
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 ;; properly, and movement through glyphs is unintuitive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 ;; As an exception, when TAG is nil, we assume that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 ;; caller knows what he is doing, and that the tag is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 ;; encoded within the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 (not (glyphp image)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 ((glyphp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 ;; Already a glyph. Use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 ((stringp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 ;; A string. Look it up in the cache first...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 (or (lax-plist-get widget-glyph-cache image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 ;; ...and then in the relevant directories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 (let* ((dirlist (cons (or widget-glyph-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (locate-data-directory "custom"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 data-directory-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (all-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 (apply #'append
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 (lambda (el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 (and (valid-image-instantiator-format-p (car el))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 (cdr el)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 widget-image-file-name-suffixes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 (file (locate-file image dirlist all-suffixes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 (when file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 (let* ((extension (concat "." (file-name-extension file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 (format (car (rassoc* extension
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 widget-image-file-name-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 :test #'member))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 ;; We create a glyph with the file as the default image
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 ;; instantiator, and the TAG fallback
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (let ((glyph (make-glyph `([,format :file ,file]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 [string :data ,tag]))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 ;; Cache the glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 (laxputf widget-glyph-cache image glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 ;; ...and return it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 glyph))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 ((valid-instantiator-p image 'image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 ;; A valid image instantiator (e.g. [gif :file "somefile"] etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 (make-glyph `(,image [string :data ,tag])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 ;; Oh well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 (defun widget-glyph-insert (widget tag image &optional down inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 "In WIDGET, insert the text TAG or, if supported, IMAGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 IMAGE should either be a glyph, an image instantiator, an image file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 name sans extension (xpm, xbm, gif, jpg, or png) located in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 `widget-glyph-directory', or anything else allowed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 `widget-glyph-find'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 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
775 glyphs. The down and inactive glyphs are shown when glyph is pressed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 or inactive, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 The optional DOWN and INACTIVE arguments are deprecated, and exist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 only because of compatibility."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 ;; Convert between IMAGE being a list, etc. Must use `psetq',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 ;; because otherwise change to `image' screws up the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 (psetq image (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (car image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 down (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 (nth 1 image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 inactive (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 (nth 2 image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 (let ((glyph (widget-glyph-find image tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 (if glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 (widget-glyph-insert-glyph widget glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 (widget-glyph-find down tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 (widget-glyph-find inactive tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 (insert tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
799 (defun widget-glyph-insert-glyph (widget glyph &optional down inactive
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
800 instantiator)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 "In WIDGET, insert GLYPH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 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
803 glyphs used when the widget is pushed and inactive, respectively.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
804 INSTANTIATOR is the vector used to create the glyph."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (insert "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (let ((extent (make-extent (point) (1- (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 (help-echo (and widget (widget-get widget :help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 (map (and widget (widget-get widget :button-keymap))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 (set-extent-property extent 'glyph-widget widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 ;; 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
811 ;; doesn't mess with cursor motion. But atomic-extents library is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 ;; currently a mess, so I'd rather not use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 (set-extent-property extent 'invisible t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 (set-extent-property extent 'end-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 (set-extent-property extent 'keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 ;;(set-extent-property extent 'pointer widget-glyph-pointer-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 (set-extent-end-glyph extent glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 (unless (or (stringp help-echo) (null help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 (when help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 (widget-handle-help-echo extent help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 (when widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 (widget-put widget :glyph-up glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 (when down (widget-put widget :glyph-down down))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
826 (when instantiator (widget-put widget :glyph-instantiator instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (when inactive (widget-put widget :glyph-inactive inactive))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 ;;; Buttons.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 (defgroup widget-button nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 "The look of various kinds of buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 (defcustom widget-button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 "String used as prefix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 (defcustom widget-button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 "String used as suffix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 ;;; Creating Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (defun widget-create (type &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
851 "Create a widget of type TYPE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 The optional ARGS are additional keyword arguments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 (let ((widget (apply 'widget-convert type args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (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
858 "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
859 The child is converted, using the keyword arguments ARGS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 (let ((widget (apply 'widget-convert type args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (defun widget-create-child (parent type)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
870 "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
871 The child is not converted."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (let ((widget (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 (defun widget-create-child-value (parent type value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 "Create widget of TYPE with value VALUE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (let ((widget (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 (widget-put widget :value (widget-apply widget :value-to-internal value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 (defun widget-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 "Delete WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (widget-apply widget :delete))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 (defun widget-convert (type &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 "Convert TYPE to a widget without inserting it in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 The optional ARGS are additional keyword arguments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 ;; Don't touch the type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 (let* ((widget (if (symbolp type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (list type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (current widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (keys args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 ;; First set the :args keyword.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 (while (cdr current) ;Look in the type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 (let ((next (car (cdr current))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (setq current (cdr (cdr current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 (setcdr current (list :args (cdr current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 (setq current nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 (while args ;Look in the args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (let ((next (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (setq args (nthcdr 2 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (widget-put widget :args args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (setq args nil))))
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
920 ;; Then convert the widget.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (setq type widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 (while type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (let ((convert-widget (plist-get (cdr type) :convert-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (if convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (setq widget (funcall convert-widget widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 (setq type (get (car type) 'widget-type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 ;; Finally set the keyword args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (while keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (let ((next (nth 0 keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (widget-put widget next (nth 1 keys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (setq keys (nthcdr 2 keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (setq keys nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 ;; Convert the :value to internal format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 (if (widget-member widget :value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (let ((value (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 :value (widget-apply widget :value-to-internal value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 ;; Return the newly created widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 (defun widget-insert (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 "Call `insert' with ARGS and make the text read only."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 (apply 'insert args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (defun widget-convert-text (type from to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 &optional button-from button-to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
953 "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
954 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
955 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
956 the text between them.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
957 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
958 used as the widget's button end points.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 Optional ARGS are extra keyword arguments for TYPE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 (let ((widget (apply 'widget-convert type :delete 'widget-leave-text args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 (from (copy-marker from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (to (copy-marker to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 (set-marker-insertion-type from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (set-marker-insertion-type to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 (widget-put widget :from from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 (widget-put widget :to to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 (when button-from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 (widget-specify-button widget button-from button-to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 (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
972 "Return a widget of type TYPE with endpoints FROM and TO.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 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
974 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
975 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
976 end points. The widget is ``wrapped around'' the text between them."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (apply 'widget-convert-text type from to from to args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (defun widget-leave-text (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 "Remove markers and extents from WIDGET and its children."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (let ((from (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (to (widget-get widget :to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (button (widget-get widget :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (sample (widget-get widget :sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 (doc (widget-get widget :doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (field (widget-get widget :field-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 (children (widget-get widget :children)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 (set-marker to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 ;; Maybe we should delete the extents here? As this code doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 ;; remove them from widget structures, maybe it's safer to just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 ;; detach them. That's what `delete-overlay' did.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 (when button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 (detach-extent button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 (when sample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 (detach-extent sample))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 (when doc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 (detach-extent doc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 (when field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 (detach-extent field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 (mapc 'widget-leave-text children)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 ;;; Keymap and Commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 (defvar widget-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 "Keymap containing useful binding for buffers containing widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 Recommended as a parent keymap for modes using widgets.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 (unless widget-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 (setq widget-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 (define-key widget-keymap [tab] 'widget-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (define-key widget-keymap [(shift tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (define-key widget-keymap [(meta tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 (define-key widget-keymap [backtab] 'widget-backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 (defvar widget-global-map global-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 "Keymap used for events the widget does not handle themselves.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 (make-variable-buffer-local 'widget-global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 (defvar widget-field-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 "Keymap used inside an editable field.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 (unless widget-field-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 (setq widget-field-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (set-keymap-parents widget-field-keymap global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 (define-key widget-field-keymap "\C-k" 'widget-kill-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 (define-key widget-field-keymap [(meta tab)] 'widget-complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 (define-key widget-field-keymap [tab] 'widget-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 (define-key widget-field-keymap [(shift tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (define-key widget-field-keymap "\C-m" 'widget-field-activate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 (define-key widget-field-keymap "\C-e" 'widget-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (define-key widget-field-keymap "\C-t" 'widget-transpose-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (defvar widget-text-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 "Keymap used inside a text field.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (unless widget-text-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (setq widget-text-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (set-keymap-parents widget-field-keymap global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (define-key widget-text-keymap "\C-e" 'widget-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (define-key widget-text-keymap "\C-t" 'widget-transpose-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (defvar widget-button-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 "Keymap used inside a button.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (unless widget-button-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (setq widget-button-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (set-keymap-parents widget-button-keymap widget-keymap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (define-key widget-button-keymap "\C-m" 'widget-button-press)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (define-key widget-button-keymap [button2] 'widget-button-click)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 ;; Ideally, button3 within a button should invoke a button-specific
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 ;; menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (define-key widget-button-keymap [button3] 'widget-button-click)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 ;;Glyph support.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 (define-key widget-button-keymap [button1] 'widget-button1-click))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 (defun widget-field-activate (pos &optional event)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1062 "Invoke the editable field at point."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 (interactive "@d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 (let ((field (widget-field-find pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 (if field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (widget-apply-action field event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 (call-interactively
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (lookup-key widget-global-map (this-command-keys))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 (defface widget-button-pressed-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 '((((class color))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (:foreground "red"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (:bold t :underline t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 "Face used for pressed buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (defun widget-event-point (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 "Character position of the mouse event, or nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (and (mouse-event-p event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 (event-point event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 (defun widget-button-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 "Invoke button below mouse pointer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 (interactive "e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 (with-current-buffer (event-buffer event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 (cond ((event-glyph event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (widget-glyph-click event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 ((widget-event-point event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 (let* ((pos (widget-event-point event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 (button (get-char-property pos 'button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (if button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 (let* ((extent (widget-get button :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (face (extent-property extent 'face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 (mouse-face (extent-property extent 'mouse-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 (help-echo (extent-property extent 'help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 ;; Merge relevant faces, and make the result mouse-face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (let ((merge `(widget-button-pressed-face ,mouse-face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 (nconc merge (if (listp face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 face (list face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 (setq merge (delete-if-not 'find-face merge))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 (set-extent-property extent 'mouse-face merge))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 (unless (widget-apply button :mouse-down-action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 ;; Wait for button release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 (while (not (button-release-event-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 (setq event (next-event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 (dispatch-event event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 ;; Disallow mouse-face and help-echo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 (set-extent-property extent 'mouse-face nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 (set-extent-property extent 'help-echo nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 (setq pos (widget-event-point event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 (unless (eq (current-buffer) (extent-object extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 ;; Barf if dispatch-event tripped us by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 ;; changing buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 (error "Buffer changed during mouse motion"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 ;; Do the associated action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 (when (and pos (extent-in-region-p extent pos pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 (widget-apply-action button event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 ;; Unwinding: fully release the button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 (set-extent-property extent 'mouse-face mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 (set-extent-property extent 'help-echo help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 ;; This should not happen!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 (error "`widget-button-click' called outside button"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 (message "You clicked somewhere weird")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 (defun widget-button1-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 "Invoke glyph below mouse pointer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 (interactive "@e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 (if (event-glyph event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 (widget-glyph-click event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 ;; Should somehow avoid this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 (let ((command (lookup-key widget-global-map (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 (and (commandp command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 (call-interactively command)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 (defun widget-glyph-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 "Handle click on a glyph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 (let* ((glyph (event-glyph event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 (extent (event-glyph-extent event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 (widget (extent-property extent 'glyph-widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (down-glyph (or (and widget (widget-get widget :glyph-down)) glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 (up-glyph (or (and widget (widget-get widget :glyph-up)) glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 (last event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 (unless (widget-apply widget :active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 (error "This widget is inactive"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (let ((current-glyph 'down))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 ;; We always know what glyph is drawn currently, to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 ;; unnecessary extent changes. Is this any noticeable gain?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 ;; Press the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 (set-extent-end-glyph extent down-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 ;; Redisplay (shouldn't be needed, but...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 (sit-for 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 (unless (widget-apply widget :mouse-down-action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 ;; Wait for the release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 (while (not (button-release-event-p last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 (unless (button-press-event-p last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 (dispatch-event last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 (when (motion-event-p last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 ;; Update glyphs on mouse motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 (if (eq extent (event-glyph-extent last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 (unless (eq current-glyph 'down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 (set-extent-end-glyph extent down-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (setq current-glyph 'down))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 (unless (eq current-glyph 'up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 (set-extent-end-glyph extent up-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 (setq current-glyph 'up))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 (setq last (next-event event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (unless (eq (current-buffer) (extent-object extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 ;; Barf if dispatch-event tripped us by changing buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 (error "Buffer changed during mouse motion"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 ;; Apply widget action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (when (eq extent (event-glyph-extent last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 (let ((widget (extent-property (event-glyph-extent event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 (cond ((null widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 (message "You clicked on a glyph"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 ((not (widget-apply widget :active))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (error "This glyph is inactive"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 (widget-apply-action widget event))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 ;; Release the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (and (eq current-glyph 'down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 ;; The extent might have been detached or deleted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 (extent-live-p extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 (not (extent-detached-p extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (set-extent-end-glyph extent up-glyph))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 (defun widget-button-press (pos &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 "Invoke button at POS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 (interactive "@d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 (let ((button (get-char-property pos 'button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 (if button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 (widget-apply-action button event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 (let ((command (lookup-key widget-global-map (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 (when (commandp command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 (call-interactively command))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 (defun widget-tabable-at (&optional pos last-tab backwardp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 "Return the tabable widget at POS, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 POS defaults to the value of (point)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 (unless pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 (setq pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 (let ((widget (widget-at pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 (if widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 (let ((order (widget-get widget :tab-order)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 (if order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 (if last-tab (and (= order (if backwardp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 (1- last-tab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 (1+ last-tab)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 (and (> order 0) widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 ;; Return the button or field extent at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 (defun widget-button-or-field-extent (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 (or (and (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (widget-get (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 (and (get-char-property pos 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 (widget-get (get-char-property pos 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 :field-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 (defun widget-next-button-or-field (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 "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
1231 Internal function, don't use it outside `wid-edit'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 (let* ((at-point (widget-button-or-field-extent pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 (extent (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 (lambda (ext ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 nil (if at-point (extent-end-position at-point) pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 nil nil 'start-open 'button-or-field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 (and extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 (extent-start-position extent))))
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 ;; This is too slow in buffers with many buttons (W3).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 (defun widget-previous-button-or-field (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 "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
1244 Internal function, don't use it outside `wid-edit'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 (let* ((at-point (widget-button-or-field-extent pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 previous-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 (lambda (ext ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 (if (eq ext at-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 ;; We reached the extent we were on originally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 (if (= pos (extent-start-position at-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 previous-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 (setq previous-extent at-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (setq previous-extent ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 nil nil pos nil 'start-open 'button-or-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 (and previous-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (extent-start-position previous-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 (defun widget-move (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 "Move point to the ARG next field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 ARG may be negative to move backward."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 (let ((opoint (point)) (wrapped 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (last-tab (widget-get (widget-at (point)) :tab-order))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 nextpos found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 ;; Movement backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 (while (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 (setq nextpos (widget-previous-button-or-field (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 (if nextpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 (goto-char nextpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 (when (and (not (get-char-property nextpos 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 (widget-tabable-at nil last-tab t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (incf arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 (setq found t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 last-tab (widget-get (widget-at (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 :tab-order))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 (if (and (not found) (> wrapped 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 (setq arg 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 (incf wrapped))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 ;; Movement forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 (setq nextpos (widget-next-button-or-field (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 (if nextpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 (goto-char nextpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 (when (and (not (get-char-property nextpos 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 (widget-tabable-at nil last-tab))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 (decf arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 (setq found t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 last-tab (widget-get (widget-at (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 :tab-order))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 (if (and (not found) (> wrapped 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 (setq arg 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 (incf wrapped))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 (if (not found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 (widget-echo-help (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 (run-hooks 'widget-move-hook))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 (defun widget-forward (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 "Move point to the next field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 With optional ARG, move across that many fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 (run-hooks 'widget-forward-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 (widget-move arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 (defun widget-backward (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 "Move point to the previous field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 With optional ARG, move across that many fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 (run-hooks 'widget-backward-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 (widget-move (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 (defun widget-beginning-of-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1320 "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
1321
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1322 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
1323 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 (start (and field (widget-field-start field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 (if (and start (not (eq start (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 (call-interactively 'beginning-of-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 (defun widget-end-of-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1332 "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
1333
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1334 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
1335 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 (end (and field (widget-field-end field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 (if (and end (not (eq end (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 (call-interactively 'end-of-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 (defun widget-kill-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1344 "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
1345
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1346 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
1347 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (newline (save-excursion (forward-line 1) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 (end (and field (widget-field-end field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 (if (and field (> newline end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 (kill-region (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 (call-interactively 'kill-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (defun widget-transpose-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 "Like `transpose-chars', but works correctly at end of widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (start (and field (widget-field-start field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 (end (and field (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 (last-non-space (and start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 (skip-chars-backward " \t\n" start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (cond ((and last-non-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 (or (= last-non-space start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 (= last-non-space (1+ start))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 ;; empty or one-character field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 ((= (point) start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 ;; at the beginning of the field -- we would get an error here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 (error "Cannot transpose at beginning of field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 (when (and (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 (= last-non-space (point)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1378 (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 (transpose-chars arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 (defcustom widget-complete-field (lookup-key global-map "\M-\t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 "Default function to call for completion inside fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 :options '(ispell-complete-word complete-tag lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 (defun widget-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 "Complete content of editable field from point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 When not inside a field, move to the previous button or field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 ;; Somehow, this should make pressing M-TAB twice scroll the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 ;; completions window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 (let ((field (widget-field-find (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 (if field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 (widget-apply field :complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 (error "Not in an editable field"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 ;;; Setting up the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 (defvar widget-field-new nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 ;; List of all newly created editable fields in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 (make-variable-buffer-local 'widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 (defvar widget-field-list nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 ;; List of all editable fields in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 (make-variable-buffer-local 'widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (defun widget-setup ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 "Setup current buffer so editing string widgets works."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 (after-change-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 (while widget-field-new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 (setq field (car widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 widget-field-new (cdr widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 widget-field-list (cons field widget-field-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 (let ((from (car (widget-get field :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 (to (cdr (widget-get field :field-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 (widget-specify-field field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 (marker-position from) (marker-position to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 (set-marker to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 ;; If the field is placed within the inactive zone, deactivate it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 (let ((extent (widget-get field :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 (when (get-char-property (extent-start-position extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 'widget-inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 (widget-activation-widget-mapper extent :deactivate)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 (widget-clear-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 (widget-add-change))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 (defvar widget-field-last nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 ;; Last field containing point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 (make-variable-buffer-local 'widget-field-last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 (defvar widget-field-was nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 ;; The widget data before the change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 (make-variable-buffer-local 'widget-field-was)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 (defun widget-field-buffer (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1442 "Return the buffer containing WIDGET.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1443
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1444 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
1445 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 (and extent (extent-object extent))))
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 (defun widget-field-start (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1450 "Return the start of WIDGET's editing field.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1451
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1452 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
1453 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 (and extent (extent-start-position extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 (defun widget-field-end (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1458 "Return the end of WIDGET's editing field.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1459
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1460 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
1461 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 ;; 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
1464 (and extent (if (or widget-field-add-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 (null (widget-get widget :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 (1- (extent-end-position extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 (extent-end-position extent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 (defun widget-field-find (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 "Return the field at POS.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1471 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
1472
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1473 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
1474 `widget-setup' will always fail."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 (let ((field-extent (map-extents (lambda (extent ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 nil pos pos nil nil 'field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 (and field-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 (extent-property field-extent 'field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 ;; Old version, without `map-extents'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 ;(defun widget-field-find (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 ; (let ((fields widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 ; field found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 ; (while fields
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 ; (setq field (car fields)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 ; fields (cdr fields))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 ; (let ((start (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 ; (end (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 ; (when (and (<= start pos) (<= pos end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 ; (when found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 ; (debug "Overlapping fields"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 ; (setq found field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 ; found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1496 ;; 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
1497 ;; invoking `widget-setup' will always fail.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 (defun widget-before-change (from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 ;; Barf if the text changed is outside the editable fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 (unless inhibit-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 (let ((from-field (widget-field-find from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 (to-field (widget-field-find to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (cond ((or (null from-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 (null to-field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 ;; Either end of change is not within a field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 (error "Attempt to change text outside editable field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 ((not (eq from-field to-field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 ;; The change begins in one fields, and ends in another one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 (error "Change should be restricted to a single field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 ((or (and from-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 (get-char-property from 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 (and to-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 (get-char-property to 'widget-inactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 ;; Trying to change an inactive editable field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 (error "Attempt to change an inactive field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 (widget-field-use-before-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 ;; #### Bletch! This loses because XEmacs get confused
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 ;; if before-change-functions change the contents of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 ;; buffer before from/to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 (widget-apply from-field :notify from-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 (error (debug "Before Change"))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 (defun widget-add-change ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 (make-local-hook 'post-command-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 (remove-hook 'post-command-hook 'widget-add-change t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 (make-local-hook 'before-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 (add-hook 'before-change-functions 'widget-before-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 (make-local-hook 'after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 (add-hook 'after-change-functions 'widget-after-change nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 (defun widget-after-change (from to old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 ;; Adjust field size and text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 ;; Also, notify the widgets (so, for example, a variable changes its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 ;; state to `modified'. when it is being edited.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 (let ((field (widget-field-find from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 (other (widget-field-find to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 (when field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 (unless (eq field other)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 (debug "Change in different fields"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 (let ((size (widget-get field :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 (when size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 (let ((begin (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 (end (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 (cond ((< (- end begin) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 ;; Field too small.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 (insert-char ?\ (- (+ begin size) end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 ((> (- end begin) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 ;; Field too large and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 (if (or (< (point) (+ begin size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 (> (point) end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 ;; Point is outside extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 (setq begin (+ begin size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 ;; Point is within the extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 (setq begin (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 (while (and (eq (preceding-char) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 (> (point) begin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 (delete-backward-char 1)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 (widget-specify-secret field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 (widget-apply field :notify field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 (error (debug "After Change"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 ;;; Widget Functions
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 ;; These functions are used in the definition of multiple widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 (defun widget-parent-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 "Tell :parent of WIDGET to handle the :action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 Optional EVENT is the event that triggered the action."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 (widget-apply (widget-get widget :parent) :action event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 (defun widget-children-value-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 "Delete all :children and :buttons in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 (mapc 'widget-delete (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 (widget-put widget :children nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 (mapc 'widget-delete (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 (widget-put widget :buttons nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 (defun widget-children-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 "All the :children must be valid."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 child found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 found (widget-apply child :validate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 (defun widget-types-convert-widget (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 "Convert :args as widget types in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 (defun widget-value-convert-widget (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 "Initialize :value from :args in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 (let ((args (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 (when args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 (widget-put widget :value (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 ;; Don't convert :value here, as this is done in `widget-convert'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 ;; (widget-put widget :value (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 ;; :value-to-internal (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 (widget-put widget :args nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 (defun widget-value-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 "Return the :value property of WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 ;;; The `default' Widget.
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 (define-widget 'default nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 "Basic widget other widgets are derived from."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 :value-to-internal (lambda (widget value) value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 :value-to-external (lambda (widget value) value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 :button-prefix 'widget-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 :button-suffix 'widget-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 :complete 'widget-default-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 :create 'widget-default-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 :indent nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 :offset 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 :format-handler 'widget-default-format-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 :button-face-get 'widget-default-button-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 :sample-face-get 'widget-default-sample-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 :button-keymap widget-button-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 :delete 'widget-default-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 :value-set 'widget-default-value-set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 :value-inline 'widget-default-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 :default-get 'widget-default-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 :menu-tag-get 'widget-default-menu-tag-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 :validate (lambda (widget) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 :active 'widget-default-active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 :activate 'widget-specify-active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 :deactivate 'widget-default-deactivate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 :mouse-down-action (lambda (widget event) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 :action 'widget-default-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 :notify 'widget-default-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 :prompt-value 'widget-default-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 (defun widget-default-complete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 "Call the value of the :complete-function property of WIDGET.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 If that does not exists, call the value of `widget-complete-field'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 (let ((fun (widget-get widget :complete-function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 (call-interactively (or fun widget-complete-field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 (defun widget-default-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 "Create WIDGET at point in the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 (let ((from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 button-begin button-end button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 sample-begin sample-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 doc-begin doc-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 value-pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 (insert (widget-get widget :format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 ;; Parse escapes in format. Coding this in C would speed up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 ;; things *a lot*.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 (while (re-search-forward "%\\(.\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 (cond ((eq escape ?%)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 (insert "%"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 ((eq escape ?\[)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 (setq button-begin (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 (set-marker-insertion-type button-begin nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 ((eq escape ?\])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 (setq button-end (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 (set-marker-insertion-type button-end nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 ((eq escape ?\{)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 (setq sample-begin (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 ((eq escape ?\})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 (setq sample-end (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 ((eq escape ?n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 (when (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 (insert "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 (insert-char ?\ (widget-get widget :indent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 ((eq escape ?t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 (let* ((tag (widget-get widget :tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 (glyph (widget-get widget :tag-glyph)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 (cond (glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 (setq button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 (widget-glyph-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 widget (or tag "Image") glyph)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 (tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 (insert tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 (let ((standard-output (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 (princ (widget-get widget :value)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 ((eq escape ?d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 (let ((doc (widget-get widget :doc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 (when doc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 (setq doc-begin (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 (insert doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 (while (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 (delete-backward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 (insert "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 (setq doc-end (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 (if (and button-begin (not button-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 (widget-apply widget :value-create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 (setq value-pos (point-marker))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 (widget-apply widget :format-handler escape)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 ;; Specify button, sample, and doc, and insert value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 (when (and button-begin button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 (unless button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 (goto-char button-begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 (insert (widget-get-indirect widget :button-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 (goto-char button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 (set-marker-insertion-type button-end t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 (insert (widget-get-indirect widget :button-suffix)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 (widget-specify-button widget button-begin button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 ;; Is this necessary?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 (set-marker button-begin nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 (set-marker button-end nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 (and sample-begin sample-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 (widget-specify-sample widget sample-begin sample-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 (and doc-begin doc-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 (widget-specify-doc widget doc-begin doc-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 (when value-pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 (goto-char value-pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 (widget-apply widget :value-create)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 (let ((from (point-min-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 (to (point-max-marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 (set-marker-insertion-type from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 (set-marker-insertion-type to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 (widget-put widget :from from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 (widget-put widget :to to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 (widget-clear-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 (defun widget-default-format-handler (widget escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 ;; We recognize the %h escape by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 (let* ((buttons (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 (cond ((eq escape ?h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 (let* ((doc-property (widget-get widget :documentation-property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 (doc-try (cond ((widget-get widget :doc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 ((symbolp doc-property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 (documentation-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 (widget-get widget :value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 doc-property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 (funcall doc-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 (widget-get widget :value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 (doc-text (and (stringp doc-try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 (> (length doc-try) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 doc-try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 (doc-indent (widget-get widget :documentation-indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 (when doc-text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 ;; The `*' in the beginning is redundant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 (when (eq (aref doc-text 0) ?*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 (setq doc-text (substring doc-text 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 ;; Get rid of trailing newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 (when (string-match "\n+\\'" doc-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 (setq doc-text (substring doc-text 0 (match-beginning 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 (push (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 widget 'documentation-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 :indent (cond ((numberp doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 ((null doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 (t 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 doc-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 buttons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 (signal 'error (list "Unknown escape" escape))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 (widget-put widget :buttons buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 (defun widget-default-button-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 ;; Use :button-face or widget-button-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 (or (widget-get widget :button-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 (if parent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 (widget-apply parent :button-face-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 widget-button-face))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 (defun widget-default-sample-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 ;; Use :sample-face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 (widget-get widget :sample-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 (defun widget-default-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 ;; Remove widget from the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 (let ((from (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 (to (widget-get widget :to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 (inactive-extent (widget-get widget :inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 (button-extent (widget-get widget :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 (sample-extent (widget-get widget :sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 (doc-extent (widget-get widget :doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 after-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 (inhibit-read-only t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 (widget-apply widget :value-delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 (when inactive-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 (detach-extent inactive-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 (when button-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 (detach-extent button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 (when sample-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 (detach-extent sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 (when doc-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 (detach-extent doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 (when (< from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 ;; Kludge: this doesn't need to be true for empty formats.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 (delete-region from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 (set-marker to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 (widget-clear-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 (defun widget-default-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 ;; Recreate widget with new value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 (let* ((old-pos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 (from (copy-marker (widget-get widget :from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 (to (copy-marker (widget-get widget :to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 (offset (if (and (<= from old-pos) (<= old-pos to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 (if (>= old-pos (1- to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 (- old-pos to 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 (- old-pos from)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 ;;??? 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
1829 ;; so that markers on either side of the value automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 ;; stay on the same side. -- rms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 (goto-char (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 (widget-apply widget :delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 (widget-put widget :value value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 (widget-apply widget :create))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 (when offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 (if (< offset 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 (goto-char (+ (widget-get widget :to) offset 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 (goto-char (min (+ from offset) (1- (widget-get widget :to))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 (defun widget-default-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 ;; Wrap value in a list unless it is inline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 (if (widget-get widget :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 (list (widget-value widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 (defun widget-default-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 ;; Get `:value'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 (defun widget-default-menu-tag-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 ;; Use tag or value for menus.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 (or (widget-get widget :menu-tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 (widget-get widget :tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 (widget-princ-to-string (widget-get widget :value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 (defun widget-default-active (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 "Return t iff this widget active (user modifiable)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 (and (not (widget-get widget :inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 (or (null parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 (widget-apply parent :active)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 (defun widget-default-deactivate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 "Make WIDGET inactive for user modifications."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 (widget-specify-inactive widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 (widget-get widget :from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 (widget-get widget :to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 (defun widget-default-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 ;; Notify the parent when a widget change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 (when parent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 (widget-apply parent :notify widget event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 (defun widget-default-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 ;; Pass notification to parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 (widget-default-action widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 (defun widget-default-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 ;; Read an arbitrary value. Stolen from `set-variable'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 ;; (let ((initial (if unbound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 ;; nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 ;; ;; It would be nice if we could do a `(cons val 1)' here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 ;; (prin1-to-string (custom-quote value))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 (eval-minibuffer prompt ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 ;;; The `item' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 (define-widget 'item 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 "Constant items for inclusion in other widgets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 :convert-widget 'widget-value-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 :value-create 'widget-item-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 :value-delete 'ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 :value-get 'widget-value-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 :match 'widget-item-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 :match-inline 'widget-item-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 :action 'widget-item-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 :format "%t\n")
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-item-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 ;; Insert the printed representation of the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 (let ((standard-output (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 (princ (widget-get widget :value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 (defun widget-item-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 ;; Match if the value is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 (equal (widget-get widget :value) value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 (defun widget-item-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 ;; Match if the value is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 (let ((value (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 (and (listp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 (<= (length value) (length values))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 (let ((head (widget-sublist values 0 (length value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 (and (equal head value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 (cons head (widget-sublist values (length value))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 (defun widget-sublist (list start &optional end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 "Return the sublist of LIST from START to END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 If END is omitted, it defaults to the length of LIST."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 (if (> start 0) (setq list (nthcdr start list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 (if end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (if (<= end start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 (setq list (copy-sequence list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 (setcdr (nthcdr (- end start 1) list) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 (copy-sequence list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 (defun widget-item-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 ;; Just notify itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 (widget-apply widget :notify widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 ;;; The `push-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 (defcustom widget-push-button-gui widget-glyph-enable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 "If non nil, use GUI push buttons when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 :type 'boolean)
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 (defcustom widget-push-button-prefix "["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 "String used as prefix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 (defcustom widget-push-button-suffix "]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 "String used as suffix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 (define-widget 'push-button 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 "A pushable button."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 :value-create 'widget-push-button-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 :format "%[%v%]")
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-push-button-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 ;; Insert text representing the `on' and `off' states.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 (let* ((tag (or (widget-get widget :tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 (tag-glyph (widget-get widget :tag-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 (text (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 tag widget-push-button-suffix))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
1966 gui inst)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 (cond (tag-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 (widget-glyph-insert widget text tag-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 ;; We must check for console-on-window-system-p here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 ;; because GUI will not work otherwise (it needs RGB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 ;; components for colors, and they are not known on TTYs).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 ((and widget-push-button-gui
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 (console-on-window-system-p))
436
080151679be2 Import from CVS: tag r21-2-26
cvs
parents: 428
diff changeset
1974 (let* ((gui-button-shadow-thickness 1))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
1975 (setq inst (make-gui-button tag 'widget-gui-action widget))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
1976 (setq gui (make-glyph inst)))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
1977 (widget-glyph-insert-glyph widget gui nil nil inst))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 (insert text)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 (defun widget-gui-action (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 "Apply :action for WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 (widget-apply-action widget (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 ;;; The `link' Widget.
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 (defcustom widget-link-prefix "["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 "String used as prefix for links."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 (defcustom widget-link-suffix "]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 "String used as suffix for links."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 (define-widget 'link 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 "An embedded link."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 :button-prefix 'widget-link-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 :button-suffix 'widget-link-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 :help-echo "Follow the link"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 :format "%[%t%]")
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 ;;; The `info-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 (define-widget 'info-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 "A link to an info file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 :help-echo 'widget-info-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 :action 'widget-info-link-action)
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-info-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 (concat "Read the manual entry `" (widget-value widget) "'"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 (defun widget-info-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 "Open the info node specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 (Info-goto-node (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 ;;; The `url-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 (define-widget 'url-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 "A link to an www page."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 :help-echo 'widget-url-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 :action 'widget-url-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 (defun widget-url-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 (concat "Visit <URL:" (widget-value widget) ">"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 (defun widget-url-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 "Open the url specified by WIDGET."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2030 (if (fboundp 'browse-url)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2031 (browse-url (widget-value widget))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 (error "Cannot follow URLs in this XEmacs")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 ;;; The `function-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 (define-widget 'function-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 "A link to an Emacs function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 :action 'widget-function-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 (defun widget-function-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 "Show the function specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 (describe-function (widget-value widget)))
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 ;;; The `variable-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 (define-widget 'variable-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 "A link to an Emacs variable."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 :action 'widget-variable-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 (defun widget-variable-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 "Show the variable specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 (describe-variable (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 ;;; The `file-link' Widget.
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 (define-widget 'file-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 "A link to a file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 :action 'widget-file-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 (defun widget-file-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 "Find the file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 (find-file (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 ;;; The `emacs-library-link' 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 (define-widget 'emacs-library-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 "A link to an Emacs Lisp library file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 :help-echo 'widget-emacs-library-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 :action 'widget-emacs-library-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 (defun widget-emacs-library-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 (concat "Visit " (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 (defun widget-emacs-library-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 "Find the Emacs Library file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 (find-file (locate-library (widget-value widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 ;;; The `emacs-commentary-link' 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 (define-widget 'emacs-commentary-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 "A link to Commentary in an Emacs Lisp library file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 :action 'widget-emacs-commentary-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 (defun widget-emacs-commentary-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 "Find the Commentary section of the Emacs file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 (finder-commentary (widget-value widget)))
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 `editable-field' 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 'editable-field 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 "An editable text field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 :convert-widget 'widget-value-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 :keymap widget-field-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 :value ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 :prompt-internal 'widget-field-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 :prompt-history 'widget-field-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 :prompt-value 'widget-field-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 :action 'widget-field-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 :validate 'widget-field-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 :valid-regexp ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 :error "No match"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 :value-create 'widget-field-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 :value-delete 'widget-field-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 :value-get 'widget-field-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 :match 'widget-field-match)
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 (defvar widget-field-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 "History of field minibuffer edits.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 (defun widget-field-prompt-internal (widget prompt initial history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 ;; Read string for WIDGET prompting with PROMPT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 ;; INITIAL is the initial input and HISTORY is a symbol containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 ;; the earlier input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 (read-string prompt initial history))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117 (defun widget-field-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118 ;; Prompt for a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 (let ((initial (if unbound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 (cons (widget-apply widget :value-to-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 value) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 (history (widget-get widget :prompt-history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 (let ((answer (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 :prompt-internal prompt initial history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 (widget-apply widget :value-to-external answer))))
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 (defvar widget-edit-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130 (defun widget-field-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 ;; Edit the value in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 (let* ((invalid (widget-apply widget :validate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 (prompt (concat (widget-apply widget :menu-tag-get) ": "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 (value (unless invalid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 (answer (widget-apply widget :prompt-value prompt value invalid)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137 (unless (equal value answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 ;; This is a hack. We can't properly validate the widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 ;; because validation requires the new value to be in the field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 ;; However, widget-field-value-create will not function unless
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 ;; the new value matches. So, we check whether the thing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 ;; 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
2143 ;; message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 (unless (widget-apply widget :match answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 (let ((error-message (or (widget-get widget :type-error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 "Invalid field contents")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 (widget-put widget :error error-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 (error error-message)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 (widget-setup))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 (run-hook-with-args 'widget-edit-functions widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 ;(defun widget-field-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 ; ;; Move to next field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 ; (widget-forward 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 ; (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 (defun widget-field-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 ;; Valid if the content matches `:valid-regexp'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 (let ((value (widget-apply widget :value-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 (regexp (widget-get widget :valid-regexp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 (if (string-match regexp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 (defun widget-field-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 ;; Create an editable text field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 (let ((size (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 (value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 ;; This is changed to a real extent in `widget-setup'. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 ;; need the end points to behave differently until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 ;; `widget-setup' is called. Should probably be replaced with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 ;; a genuine extent, but some things break, then.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 (extent (cons (make-marker) (make-marker))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 (widget-put widget :field-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 (insert value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 (and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 (< (length value) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 (insert-char ?\ (- size (length value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 (unless (memq widget widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 (push widget widget-field-new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 (move-marker (cdr extent) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 (set-marker-insertion-type (cdr extent) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 (when (null size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 (insert ?\n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 (move-marker (car extent) from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 (set-marker-insertion-type (car extent) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 (defun widget-field-value-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 ;; Remove the widget from the list of active editing fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 (setq widget-field-list (delq widget widget-field-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 ;; These are nil if the :format string doesn't contain `%v'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 (when extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 (detach-extent extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 (defun widget-field-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 ;; Return current text in editing field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 (let ((from (widget-field-start widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 (to (widget-field-end widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 (buffer (widget-field-buffer widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 (size (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 (secret (widget-get widget :secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 (old (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 ((and from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 (while (and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 (not (zerop size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 (> to from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 (eq (char-after (1- to)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 (setq to (1- to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 (let ((result (buffer-substring-no-properties from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 (when secret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 (let ((index 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 (while (< (+ from index) to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 (aset result index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 (get-char-property (+ from index) 'secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 (incf index))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 (set-buffer old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 (widget-get widget :value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 (defun widget-field-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 ;; Match any string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 (stringp value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 ;;; The `text' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 (define-widget 'text 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 :keymap widget-text-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 "A multiline text area.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 ;;; The `menu-choice' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 (define-widget 'menu-choice 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 "A menu of options."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 :format "%[%t%]: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 :case-fold t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 :tag "choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 :void '(item :format "invalid (%t)\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 :value-create 'widget-choice-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 :value-get 'widget-choice-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 :value-inline 'widget-choice-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 :default-get 'widget-choice-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 :mouse-down-action 'widget-choice-mouse-down-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 :action 'widget-choice-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 :error "Make a choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 :validate 'widget-choice-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 :match 'widget-choice-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 :match-inline 'widget-choice-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 (defun widget-choice-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 ;; Insert the first choice that matches the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 (let ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 (args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 (explicit (widget-get widget :explicit-choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 (if explicit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 (widget-put widget :children (list (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 widget explicit value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 (widget-put widget :choice explicit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 (when (widget-apply current :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 (widget-put widget :children (list (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 widget current value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 (widget-put widget :choice current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 (setq args nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 current nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 (when current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 (let ((void (widget-get widget :void)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 (widget-put widget :children (list (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 widget void :value value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 (widget-put widget :choice void))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 (defun widget-choice-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 (widget-value (car (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 (defun widget-choice-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 (widget-apply (car (widget-get widget :children)) :value-inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 (defun widget-choice-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 ;; Get default for the first choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 (widget-default-get (car (widget-get widget :args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 (defcustom widget-choice-toggle nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 "If non-nil, a binary choice will just toggle between the values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 Otherwise, the user will explicitly have to choose between the values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 when he invoked the menu."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 (defun widget-choice-mouse-down-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 ;; Return non-nil if we need a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 (old (widget-get widget :choice)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 (cond ((not (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 ;; No place to pop up a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 ((< (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 ;; Empty or singleton list, just return the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 ((> (length args) widget-menu-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 ;; Too long, prompt.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 ((> (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 ;; Reasonable sized list, use menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 ((and widget-choice-toggle (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 ;; We toggle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 ;; Ask which of the two.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 (defun widget-choice-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 ;; Make a choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 (old (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 (tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 (completion-ignore-case (widget-get widget :case-fold))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 current choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 ;; Remember old value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 (if (and old (not (widget-apply widget :validate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 (let* ((external (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 (internal (widget-apply old :value-to-internal external)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 (widget-put old :value internal)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 ;; Find new choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 (setq current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 (cond ((= (length args) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 ((= (length args) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 ((and widget-choice-toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 (= (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 (if (eq old (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 (nth 1 args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 (setq choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 (cons (cons (widget-apply current :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 (let ((choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 (widget-choose tag (reverse choices) event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 (widget-put widget :explicit-choice choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 choice))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 (when current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 (let ((value (widget-default-get current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 (widget-value-set widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 (widget-apply current :value-to-external value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 (widget-apply widget :notify widget event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 (defun widget-choice-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 ;; Valid if we have made a valid choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 (let ((void (widget-get widget :void))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 (choice (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 (child (car (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 (if (eq void choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 (widget-apply child :validate))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 (defun widget-choice-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 ;; Matches if one of the choices matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 (while (and args (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 found (widget-apply current :match value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 (defun widget-choice-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 ;; Matches if one of the choices matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 (while (and args (null found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 found (widget-match-inline current values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 ;;; The `toggle' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 (define-widget 'toggle 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 "Toggle between two states."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 :format "%[%v%]\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 :value-create 'widget-toggle-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 :action 'widget-toggle-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 :match (lambda (widget value) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 :on "on"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 :off "off")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 (defun widget-toggle-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 ;; Insert text representing the `on' and `off' states.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 (widget-glyph-insert widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 (widget-get widget :on)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 (widget-get widget :on-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 (widget-glyph-insert widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 (widget-get widget :off)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 (widget-get widget :off-glyph))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 (defun widget-toggle-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 ;; Toggle value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 (widget-value-set widget (not (widget-value widget)))
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 ;;; The `checkbox' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 (define-widget 'checkbox 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 "A checkbox toggle."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 :on "[X]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 :on-glyph "check1"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 :off "[ ]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 :off-glyph "check0"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 :action 'widget-checkbox-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 (defun widget-checkbox-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 "Toggle checkbox, notify parent, and set active state of sibling."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 (widget-toggle-action widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 (let ((sibling (widget-get-sibling widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 (when sibling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 (widget-apply sibling :activate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 (widget-apply sibling :deactivate)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 ;;; The `checklist' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 (define-widget 'checklist 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 "A multiple choice widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 :offset 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 :entry-format "%b %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 :menu-tag "checklist"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 :greedy nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 :value-create 'widget-checklist-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 :value-get 'widget-checklist-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 :validate 'widget-checklist-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 :match 'widget-checklist-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 :match-inline 'widget-checklist-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 (defun widget-checklist-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 (args (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 (widget-checklist-add-item widget (car args) (assq (car args) alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 (widget-put widget :children (nreverse (widget-get widget :children)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 (defun widget-checklist-add-item (widget type chosen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 ;; Create checklist item in WIDGET of type TYPE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 ;; If the item is checked, CHOSEN is a cons whose cdr is the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 (let* ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 (button-args (or (widget-get type :sibling-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 (widget-get widget :button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 (insert (widget-get widget :entry-format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 (while (re-search-forward "%\\([bv%]\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 (cond ((eq escape ?%)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 (insert "%"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 ((eq escape ?b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 (setq button (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 widget 'checkbox
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 :value (not (null chosen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 (setq child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 (cond ((not chosen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 (let ((child (widget-create-child widget type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 (widget-apply child :deactivate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 ((widget-get type :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 widget type (cdr chosen)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 widget type (car (cdr chosen)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 ;; Update properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 (and button child (widget-put child :button button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 (and button (widget-put widget :buttons (cons button buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 (and child (widget-put widget :children (cons child children))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 (defun widget-checklist-match (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 ;; All values must match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 (and (listp values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 (null (cdr (widget-checklist-match-inline widget values)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 (defun widget-checklist-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 ;; Find the values which match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 (let ((greedy (widget-get widget :greedy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 (args (copy-sequence (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 found rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 (while values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 (let ((answer (widget-checklist-match-up args values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 (cond (answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 (let ((vals (widget-match-inline answer values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 (setq found (append found (car vals))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 values (cdr vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 args (delq answer args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 (greedy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 (setq rest (append rest (list (car values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 values (cdr values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 (setq rest (append rest values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 values nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 (cons found rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 (defun widget-checklist-match-find (widget vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 ;; Find the vals which match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 ;; Return an alist of (TYPE MATCH).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 (let ((greedy (widget-get widget :greedy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 (args (copy-sequence (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 (while vals
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 (let ((answer (widget-checklist-match-up args vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 (cond (answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 (let ((match (widget-match-inline answer vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 (setq found (cons (cons answer (car match)) found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 vals (cdr match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 args (delq answer args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 (greedy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 (setq vals (cdr vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 (setq vals nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 (defun widget-checklist-match-up (args vals)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2565 ;; Return the first type from ARGS that matches VALS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 (let (current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 (while (and args (null found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 found (widget-match-inline current vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 (if found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 (defun widget-checklist-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 ;; The values of all selected items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 child result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 (if (widget-value (widget-get child :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 (setq result (append result (widget-apply child :value-inline)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 (defun widget-checklist-validate (widget)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2587 ;; Ticked children must be valid.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 child button found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 button (widget-get child :button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 found (and (widget-value button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 (widget-apply child :validate))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 found))
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 ;;; The `option' Widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 (define-widget 'option 'checklist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 "An widget with an optional item."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 :inline t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 ;;; The `choice-item' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 (define-widget 'choice-item 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 "Button items that delegate action events to their parents."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 :action 'widget-parent-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 :format "%[%t%] \n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 ;;; The `radio-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 (define-widget 'radio-button 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 "A radio button for use in the `radio' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 :notify 'widget-radio-button-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 :on "(*)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 :on-glyph '("radio1" nil "radio0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 :off "( )"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 :off-glyph "radio0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 (defun widget-radio-button-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 ;; Tell daddy.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 (widget-apply (widget-get widget :parent) :action widget event))
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 ;;; The `radio-button-choice' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 (define-widget 'radio-button-choice 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 "Select one of multiple options."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 :offset 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 :entry-format "%b %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 :menu-tag "radio"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 :value-create 'widget-radio-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 :value-get 'widget-radio-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 :value-inline 'widget-radio-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 :value-set 'widget-radio-value-set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 :error "You must push one of the buttons"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 :validate 'widget-radio-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 :match 'widget-choice-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 :match-inline 'widget-choice-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 :action 'widget-radio-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 (defun widget-radio-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 (setq arg (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 (widget-radio-add-item widget arg))))
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 (defun widget-radio-add-item (widget type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 "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
2659 ;; (setq type (widget-convert type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 (let* ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 (children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 (button-args (or (widget-get type :sibling-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 (widget-get widget :button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 (chosen (and (null (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 (widget-apply type :match value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 (insert (widget-get widget :entry-format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 (while (re-search-forward "%\\([bv%]\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 (cond ((eq escape ?%)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 (insert "%"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 ((eq escape ?b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 (setq button (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 widget 'radio-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 :value (not (null chosen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 (setq child (if chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 widget type value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 (widget-create-child widget type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 (unless chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 (widget-apply child :deactivate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 ;; Update properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 (when chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 (widget-put widget :choice type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 (when button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 (widget-put child :button button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 (widget-put widget :buttons (nconc buttons (list button))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 (when child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 (widget-put widget :children (nconc children (list child))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 (defun widget-radio-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 (let ((chosen (widget-radio-chosen widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 (and chosen (widget-value chosen))))
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-chosen (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 "Return the widget representing the chosen radio button."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 (let* ((button (widget-get current :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 (value (widget-apply button :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 (when value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 (setq found current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 children nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 (defun widget-radio-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 (let* ((button (widget-get current :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 (value (widget-apply button :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 (when value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 (setq found (widget-apply current :value-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 children nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 (defun widget-radio-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 ;; We can't just delete and recreate a radio widget, since children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 ;; can be added after the original creation and won't be recreated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 ;; by `:create'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 (let* ((button (widget-get current :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 (match (and (not found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 (widget-apply current :match value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 (widget-value-set button match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 (if match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 (widget-value-set current value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 (widget-apply current :activate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 (widget-apply current :deactivate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 (setq found (or found match))))))
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-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 ;; Valid if we have made a valid choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 current found button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 button (widget-get current :button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 found (widget-apply button :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 (if found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 (widget-apply current :validate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 (defun widget-radio-action (widget child event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 ;; Check if a radio button was pressed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 (when (memq child buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 (let* ((button (widget-get current :button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 (cond ((eq child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 (widget-value-set button t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 (widget-apply current :activate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 ((widget-value button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 (widget-value-set button nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 (widget-apply current :deactivate)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 ;; Pass notification to parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 (widget-apply widget :notify child event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 ;;; The `insert-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 (define-widget 'insert-button 'push-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 "An insert button for the `editable-list' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 :tag "INS"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 :help-echo "Insert a new item into the list at this position"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 :action 'widget-insert-button-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 (defun widget-insert-button-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 ;; Ask the parent to insert a new item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 (widget-apply (widget-get widget :parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 :insert-before (widget-get widget :widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 ;;; The `delete-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 (define-widget 'delete-button 'push-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 "A delete button for the `editable-list' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 :tag "DEL"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 :help-echo "Delete this item from the list"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 :action 'widget-delete-button-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 (defun widget-delete-button-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 ;; Ask the parent to insert a new item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 (widget-apply (widget-get widget :parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 :delete-at (widget-get widget :widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 ;;; The `editable-list' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 (defcustom widget-editable-list-gui nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 "If non nil, use GUI push-buttons in editable list when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 (define-widget 'editable-list 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 "A variable list of widgets of the same type."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 :offset 12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 :format "%v%i\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 :format-handler 'widget-editable-list-format-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 :entry-format "%i %d %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 :menu-tag "editable-list"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 :value-create 'widget-editable-list-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 :value-get 'widget-editable-list-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 :validate 'widget-children-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 :match 'widget-editable-list-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 :match-inline 'widget-editable-list-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 :insert-before 'widget-editable-list-insert-before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 :delete-at 'widget-editable-list-delete-at)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 (defun widget-editable-list-format-handler (widget escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 ;; We recognize the insert button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 (let ((widget-push-button-gui widget-editable-list-gui))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 (cond ((eq escape ?i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 (and (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 widget 'insert-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 (widget-get widget :append-button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 (widget-default-format-handler widget escape)))))
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 (defun widget-editable-list-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 (let* ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 (type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 (inlinep (widget-get type :inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 (widget-put widget :value-pos (copy-marker (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 (set-marker-insertion-type (widget-get widget :value-pos) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 (while value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 (let ((answer (widget-match-inline type value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 (setq children (cons (widget-editable-list-entry-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 (if inlinep
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 (car answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 (car (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 (setq value nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 (widget-put widget :children (nreverse children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 (defun widget-editable-list-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 (defun widget-editable-list-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 ;; 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
2881 (and (listp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 (null (cdr (widget-editable-list-match-inline widget value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 (defun widget-editable-list-match-inline (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 (let ((type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 (ok t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 (while (and value ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 (let ((answer (widget-match-inline type value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 (setq found (append found (car answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 (setq ok nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 (cons found value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 (defun widget-editable-list-insert-before (widget before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 ;; Insert a new child in the list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 (cond (before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 (goto-char (widget-get before :entry-from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 (goto-char (widget-get widget :value-pos))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 (let ((child (widget-editable-list-entry-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 widget nil nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 (when (< (widget-get child :entry-from) (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 (set-marker (widget-get widget :from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 (widget-get child :entry-from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 (if (eq (car children) before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 (widget-put widget :children (cons child children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 (while (not (eq (car (cdr children)) before))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 (setq children (cdr children)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 (setcdr children (cons child (cdr children)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 (widget-apply widget :notify widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 (defun widget-editable-list-delete-at (widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 ;; Delete child from list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 (let ((buttons (copy-sequence (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 (while buttons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 (setq button (car buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 buttons (cdr buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 (when (eq (widget-get button :widget) child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 :buttons (delq button (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 (widget-delete button))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 (let ((entry-from (widget-get child :entry-from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 (entry-to (widget-get child :entry-to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 (widget-delete child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 (delete-region entry-from entry-to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 (set-marker entry-from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 (set-marker entry-to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 (widget-put widget :children (delq child (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 (widget-apply widget :notify widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 (defun widget-editable-list-entry-create (widget value conv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 ;; Create a new entry to the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 (let ((type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 (widget-push-button-gui widget-editable-list-gui)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 child delete insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 (and (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 (insert (widget-get widget :entry-format)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 (while (re-search-forward "%\\(.\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 (cond ((eq escape ?%)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 (insert "%"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 ((eq escape ?i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 (setq insert (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 widget 'insert-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 (widget-get widget :insert-button-args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 ((eq escape ?d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 (setq delete (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 widget 'delete-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 (widget-get widget :delete-button-args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 (if conv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 (setq child (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 widget type value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 (setq child (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 widget type (widget-default-get type)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 (signal 'error (list "Unknown escape" escape))))))
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 (cons delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 (cons insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 (widget-get widget :buttons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 (let ((entry-from (copy-marker (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 (entry-to (copy-marker (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 (set-marker-insertion-type entry-from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 (set-marker-insertion-type entry-to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 (widget-put child :entry-from entry-from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 (widget-put child :entry-to entry-to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 (widget-put insert :widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 (widget-put delete :widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 ;;; The `group' 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 (define-widget 'group 'default
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
2997 "A widget which groups other widgets inside."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 :value-create 'widget-group-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 :value-get 'widget-editable-list-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 :default-get 'widget-group-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 :validate 'widget-children-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 :match 'widget-group-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 :match-inline 'widget-group-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 (defun widget-group-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 ;; Create each component.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 (value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 arg answer children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 (setq arg (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 answer (widget-match-inline arg value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 (push (cond ((null answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 (widget-create-child widget arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 ((widget-get arg :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 (widget-create-child-value widget arg (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 (widget-create-child-value widget arg (car (car answer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 (widget-put widget :children (nreverse children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 (defun widget-group-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 ;; Get the default of the components.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 (mapcar 'widget-default-get (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 (defun widget-group-match (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 ;; Match if the components match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 (and (listp values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 (let ((match (widget-group-match-inline widget values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 (and match (null (cdr match))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040 (defun widget-group-match-inline (widget vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 ;; Match if the components match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 argument answer found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 (setq argument (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 answer (widget-match-inline argument vals))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 (setq vals (cdr answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 found (append found (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 (setq vals nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 args nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 (cons found vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 ;;; The `visibility' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 (define-widget 'visibility 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 "An indicator and manipulator for hidden items."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 :on "Hide"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 :off "Show"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 :value-create 'widget-visibility-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 :action 'widget-toggle-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 :match (lambda (widget value) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 (defun widget-visibility-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 ;; Insert text representing the `on' and `off' states.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 (let ((on (widget-get widget :on))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 (off (widget-get widget :off)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 (if on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 (setq on (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 widget-push-button-suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 (setq on ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 (if off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 (setq off (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 widget-push-button-suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 (setq off ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 (widget-glyph-insert widget on '("down" "down-pushed"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 (widget-glyph-insert widget off '("right" "right-pushed")))))
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 ;;; The `documentation-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 ;; This is a helper widget for `documentation-string'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 (define-widget 'documentation-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 "Link type used in documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 :tab-order -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 :help-echo 'widget-documentation-link-echo-help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 :action 'widget-documentation-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 (defun widget-documentation-link-echo-help (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 "Tell what this link will describe."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 (concat "Describe the `" (widget-get widget :value) "' symbol."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 (defun widget-documentation-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 "Display documentation for WIDGET's value. Ignore optional argument EVENT."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104 (let* ((string (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 (symbol (intern string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 (if (and (fboundp symbol) (boundp symbol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 ;; 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
3108 (apropos (concat "\\`" (regexp-quote string) "\\'"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 (if (fboundp symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 (describe-function symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 (describe-variable symbol)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 (defcustom widget-documentation-links t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 "Add hyperlinks to documentation strings when non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 :group 'widget-documentation)
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 (defcustom widget-documentation-link-regexp "`\\([^\n`' ]+\\)'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 "Regexp for matching potential links in documentation strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 The first group should be the link itself."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 :type 'regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 (defcustom widget-documentation-link-p 'intern-soft
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 "Predicate used to test if a string is useful as a link.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 The value should be a function. The function will be called one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 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
3128 link for that string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 :options '(widget-documentation-link-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 (defcustom widget-documentation-link-type 'documentation-link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 "Widget type used for links in documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 :type 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 :group 'widget-documentation)
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 (defun widget-documentation-link-add (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 (widget-specify-doc widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 (when widget-documentation-links
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 (let ((regexp widget-documentation-link-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 (predicate widget-documentation-link-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 (type widget-documentation-link-type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 (buttons (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 (while (re-search-forward regexp to t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 (let ((name (match-string 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 (begin (match-beginning 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 (end (match-end 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 (when (funcall predicate name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 (push (widget-convert-button type begin end :value name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 buttons)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 (widget-put widget :buttons buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 (let ((indent (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 (when (and indent (not (zerop indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 (narrow-to-region from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 (while (search-forward "\n" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 (insert-char ?\ indent)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 ;;; The `documentation-string' Widget.
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 (define-widget 'documentation-string 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 "A documentation string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 :action 'widget-documentation-string-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171 :value-create 'widget-documentation-string-value-create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 (defun widget-documentation-string-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 ;; Insert documentation string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 (let ((doc (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 (indent (widget-get widget :indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 (shown (widget-get (widget-get widget :parent) :documentation-shown))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 (start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 (if (string-match "\n" doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180 (let ((before (substring doc 0 (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 (after (substring doc (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 (insert before " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 (widget-documentation-link-add widget start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 (push (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 widget 'visibility
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 :help-echo (lambda (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 "Hide" "Show")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 " the rest of the documentation"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 :off "More"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 :action 'widget-parent-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 shown)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 (when shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 (when indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 (insert-char ?\ indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 (insert after)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 (widget-documentation-link-add widget start (point)))
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 (insert doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 (widget-documentation-link-add widget start (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 (insert "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 (defun widget-documentation-string-action (widget &rest ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 ;; Toggle documentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 (widget-put parent :documentation-shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 (not (widget-get parent :documentation-shown))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 ;; Redraw.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 (widget-value-set widget (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 ;;; The Sexp Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 (define-widget 'const 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 "An immutable sexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 :prompt-value 'widget-const-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 :format "%t\n%d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 (defun widget-const-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 ;; Return the value of the const.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 (define-widget 'function-item 'const
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 "An immutable function name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 :format "%v\n%h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 :documentation-property (lambda (symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 (documentation symbol t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 (define-widget 'variable-item 'const
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 "An immutable variable name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 :format "%v\n%h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 :documentation-property 'variable-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 (defvar widget-string-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 "History of input to `widget-string-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 (define-widget 'string 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 "A string"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 :tag "String"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 :complete-function 'ispell-complete-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 :prompt-history 'widget-string-prompt-value-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 (define-widget 'regexp 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 "A regular expression."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 :match 'widget-regexp-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 :validate 'widget-regexp-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 ;; Doesn't work well with terminating newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 ;; :value-face 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 :tag "Regexp")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 (defun widget-regexp-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 ;; Match valid regexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 (and (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 (prog1 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 (string-match value ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 (defun widget-regexp-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 "Check that the value of WIDGET is a valid regexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 (let ((value (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 (condition-case data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 (prog1 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 (string-match value ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 (error (widget-put widget :error (error-message-string data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 (define-widget 'file 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 "A file widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 It will read a file name from the minibuffer when invoked."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 :complete-function 'widget-file-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 :prompt-value 'widget-file-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 ;; Doesn't work well with terminating newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 ;; :value-face 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 :tag "File")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 (defun widget-file-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 "Perform completion on file name preceding point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 (let* ((end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 (beg (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 (skip-chars-backward "^ ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 (pattern (buffer-substring beg end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 (name-part (file-name-nondirectory pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 (directory (file-name-directory pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 (completion (file-name-completion name-part directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295 (cond ((eq completion t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 (message "Can't find completion for \"%s\"" pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 (ding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 ((not (string= name-part completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 (delete-region beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 (insert (expand-file-name completion directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303 (message "Making completion list...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304 (let ((list (file-name-all-completions name-part directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 (setq list (sort list 'string<))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 (with-output-to-temp-buffer "*Completions*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 (display-completion-list list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 (message "Making completion list...%s" "done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 (defun widget-file-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 ;; Read file from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 (abbreviate-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 (if unbound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 (read-file-name prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 (let ((prompt2 (format "%s (default %s) " prompt value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 (dir (file-name-directory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 (file (file-name-nondirectory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 (must-match (widget-get widget :must-match)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 (read-file-name prompt2 dir nil must-match file)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 ;;;(defun widget-file-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 ;;; ;; Read a file name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 ;;; (let* ((value (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 ;;; (dir (file-name-directory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 ;;; (file (file-name-nondirectory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 ;;; (menu-tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 ;;; (must-match (widget-get widget :must-match))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 ;;; (answer (read-file-name (concat menu-tag ": (default `" value "') ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 ;;; dir nil must-match file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330 ;;; (widget-value-set widget (abbreviate-file-name answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 ;;; (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 ;;; (widget-apply widget :notify widget event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 (define-widget 'directory 'file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 "A directory widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 It will read a directory name from the minibuffer when invoked."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 :tag "Directory")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 (defvar widget-symbol-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 "History of input to `widget-symbol-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 (define-widget 'symbol 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 "A lisp symbol."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 :value nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345 :tag "Symbol"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 :match (lambda (widget value) (symbolp value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 :complete-function 'lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 :prompt-internal 'widget-symbol-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 :prompt-match 'symbolp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 :prompt-history 'widget-symbol-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 (symbol-name value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 (intern value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 (defun widget-symbol-prompt-internal (widget prompt initial history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 ;; Read file from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363 (let ((answer (completing-read prompt obarray
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364 (widget-get widget :prompt-match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 nil initial history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 (if (and (stringp answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 (not (zerop (length answer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 (error "No value"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 (defvar widget-function-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 "History of input to `widget-function-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 (define-widget 'function 'sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 "A lisp function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 :complete-function 'lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 :prompt-value 'widget-field-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 :prompt-internal 'widget-symbol-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 :prompt-match 'fboundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 :prompt-history 'widget-function-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 :action 'widget-field-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 :tag "Function")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 (defvar widget-variable-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 "History of input to `widget-variable-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 (define-widget 'variable 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 ;; Should complete on variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 "A lisp variable."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390 :prompt-match 'boundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 :prompt-history 'widget-variable-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 :tag "Variable")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 ;; This part issues a warning when compiling without Mule. Is there a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 ;; way of shutting it up?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 ;; OK, I'll simply comment the whole thing out, until someone decides
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 ;; to do something with it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 ;(defvar widget-coding-system-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 ; "History of input to `widget-coding-system-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 'coding-system 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 ; "A MULE coding-system."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 ; :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 ; :tag "Coding system"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 ; :prompt-history 'widget-coding-system-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 ; :prompt-value 'widget-coding-system-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 ; :action 'widget-coding-system-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 ;(defun widget-coding-system-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 ; ;; Read coding-system from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 ; (intern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413 ; (completing-read (format "%s (default %s) " prompt value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 ; (mapcar (lambda (sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 ; (list (symbol-name sym)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 ; (coding-system-list)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 ;(defun widget-coding-system-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 ; ;; Read a file name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 ; (let ((answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 ; (widget-coding-system-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 ; widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 ; (widget-apply widget :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 ; (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 ; t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 ; (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 ; (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 ; (widget-setup)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 (define-widget 'sexp 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 "An arbitrary lisp expression."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 :tag "Lisp expression"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 :value nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 :validate 'widget-sexp-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 :match (lambda (widget value) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 :value-to-internal 'widget-sexp-value-to-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 :value-to-external (lambda (widget value) (read value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 :prompt-history 'widget-sexp-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 :prompt-value 'widget-sexp-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 (defun widget-sexp-value-to-internal (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 ;; Use cl-prettyprint for printer representation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 (let ((pp (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 (prin1-to-string value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446 (widget-prettyprint-to-string value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 (if (> (length pp) 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448 (concat "\n" pp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449 pp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 (defun widget-sexp-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 ;; 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
3453 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 (insert (widget-apply widget :value-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 (condition-case data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459 (let ((value (read buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 (if (widget-apply widget :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 (widget-put widget :error (widget-get widget :type-error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 :error (format "Junk at end of expression: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 (buffer-substring (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 (error (widget-put widget :error (error-message-string data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 widget)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 (defvar widget-sexp-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 "History of input to `widget-sexp-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 (defun widget-sexp-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 ;; Read an arbitrary sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 (let ((found (read-string prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 (if unbound nil (cons (prin1-to-string value) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 (widget-get widget :prompt-history))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 (insert found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 (let ((answer (read buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 (unless (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 (signal 'error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489 (list "Junk at end of expression"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 (buffer-substring (point) (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 answer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 (define-widget 'restricted-sexp 'sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 "A Lisp expression restricted to values that match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 To use this type, you must define :match or :match-alternatives."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 :type-error "The specified value is not valid"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 :match 'widget-restricted-sexp-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 (if (widget-apply widget :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 (prin1-to-string value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 (defun widget-restricted-sexp-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 (let ((alternatives (widget-get widget :match-alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 matched)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 (while (and alternatives (not matched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 (if (cond ((functionp (car alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 (funcall (car alternatives) value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 ((and (consp (car alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 (eq (car (car alternatives)) 'quote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 (eq value (nth 1 (car alternatives)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512 (setq matched t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 (setq alternatives (cdr alternatives)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 matched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 (define-widget 'integer 'restricted-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 "An integer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 :tag "Integer"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 :value 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 :type-error "This field should contain an integer"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 :match-alternatives '(integerp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 (define-widget 'number 'restricted-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 "A floating point number."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 :tag "Number"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 :value 0.0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 :type-error "This field should contain a number"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 :match-alternatives '(numberp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 (define-widget 'character 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 "A character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 :tag "Character"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 :value ?\0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 :valid-regexp "\\`[\0-\377]\\'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 :error "This field should contain a single character"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 (char-to-string value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 (aref value 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 :match (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 (characterp value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 (define-widget 'list 'group
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3549 "A Lisp list."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 :tag "List"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 :format "%{%t%}:\n%v")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 (define-widget 'vector 'group
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3554 "A Lisp vector."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 :tag "Vector"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 :match 'widget-vector-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 :value-to-internal (lambda (widget value) (append value nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 :value-to-external (lambda (widget value) (vconcat value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 (defun widget-vector-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 (and (vectorp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 (widget-group-match widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 (widget-apply widget :value-to-internal value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566 (define-widget 'cons 'group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 "A cons-cell."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 :tag "Cons-cell"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 :match 'widget-cons-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 (list (car value) (cdr value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 (cons (car value) (cadr value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 (defun widget-cons-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 (and (consp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 (widget-group-match widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 (widget-apply widget :value-to-internal value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 (define-widget 'choice 'menu-choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 "A union of several sexp types."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 :tag "Choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 :format "%{%t%}: %[Value Menu%] %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 :button-prefix 'widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 :button-suffix 'widget-push-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 :prompt-value 'widget-choice-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 (defun widget-choice-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 "Make a choice."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 (completion-ignore-case (widget-get widget :case-fold))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 current choices old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 ;; Find the first arg that match VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 (let ((look args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 (while look
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 (if (widget-apply (car look) :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 (setq old (car look)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 look nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 (setq look (cdr look)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 ;; Find new choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 (setq current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 (cond ((= (length args) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 ((= (length args) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 ((and (= (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 (if (eq old (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 (nth 1 args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 (setq choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 (cons (cons (widget-apply current :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 (let ((val (completing-read prompt choices nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 (if (stringp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 (let ((try (try-completion val choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 (when (stringp try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 (setq val try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 (cdr (assoc val choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 (if current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 (widget-prompt-value current prompt nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 (define-widget 'radio 'radio-button-choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 "A union of several sexp types."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633 :tag "Choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 :prompt-value 'widget-choice-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637 (define-widget 'repeat 'editable-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3638 "A variable length homogeneous list."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 :tag "Repeat"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 :format "%{%t%}:\n%v%i\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 (define-widget 'set 'checklist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 "A list of members from a fixed set."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 :tag "Set"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 :format "%{%t%}:\n%v")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647 (define-widget 'boolean 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648 "To be nil or non-nil, that is the question."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 :tag "Boolean"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 :prompt-value 'widget-boolean-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 :button-prefix 'widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 :button-suffix 'widget-push-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 :format "%{%t%}: %[Toggle%] %v\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654 :on "on (non-nil)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 :off "off (nil)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3657 (defun widget-boolean-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658 ;; Toggle a boolean.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 (y-or-n-p prompt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661 ;;; The `color' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663 (define-widget 'color 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3664 "Choose a color name (with sample)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 :format "%[%t%]: %v (%{sample%})\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 :size 10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667 :tag "Color"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668 :value "black"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669 :complete 'widget-color-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 :sample-face-get 'widget-color-sample-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 :notify 'widget-color-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 :action 'widget-color-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 (defun widget-color-complete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 "Complete the color in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3676 (let* ((prefix (buffer-substring-no-properties (widget-field-start widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 (list (read-color-completion-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 (completion (try-completion prefix list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680 (cond ((eq completion t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 (message "Exact match"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683 (error "Can't find completion for \"%s\"" prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 ((not (string-equal prefix completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685 (insert (substring completion (length prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 (message "Making completion list...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 (let ((list (all-completions prefix list nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 (with-output-to-temp-buffer "*Completions*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 (display-completion-list list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 (message "Making completion list...done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 (defun widget-color-sample-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 (or (widget-get widget :sample-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3695 (let ((color (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696 (face (make-face (gensym "sample-face-") nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 ;; Use the face object, not its name, to prevent lossage if gc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 ;; happens before applying the face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699 (widget-put widget :sample-face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700 (and color
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 (not (equal color ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3702 (valid-color-name-p color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 (set-face-foreground face color))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704 face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 (defvar widget-color-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3707 "History of entered colors.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3709 (defun widget-color-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 ;; Prompt for a color.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 (let* ((tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712 (answer (read-color (concat tag ": "))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 (unless (zerop (length answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 (widget-apply widget :notify widget event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 (defun widget-color-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 "Update the sample, and notify the parent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 (let* ((face (widget-apply widget :sample-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 (color (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 (if (valid-color-name-p color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 (set-face-foreground face color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724 (remove-face-property face 'foreground)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 (widget-default-notify widget child event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 ;; Is this a misnomer?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 (defun widget-at (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 "The button or field at POS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730 (or (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 (get-char-property pos 'field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733 (defun widget-echo-help (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 "Display the help echo for widget at POS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735 (let* ((widget (widget-at pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 (and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738 (setq help-echo (funcall help-echo widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 (when (stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 (display-message 'help-echo help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742 ;;; The End:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3744 (provide 'wid-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746 ;; wid-edit.el ends here