annotate lisp/wid-edit.el @ 5327:d1b17a33450b

Move the heavy lifting from cl-seq.el to C. src/ChangeLog addition: 2010-12-30 Aidan Kehoe <kehoea@parhasard.net> Move the heavy lifting from cl-seq.el to C, finally making those functions first-class XEmacs citizens, with circularity checking, built-in support for tests other than #'eql, and as much compatibility with current Common Lisp as Paul Dietz' tests require. * fns.c (check_eq_nokey, check_eq_key, check_eql_nokey) (check_eql_key, check_equal_nokey, check_equal_key) (check_equalp_nokey, check_equalp_key, check_string_match_nokey) (check_string_match_key, check_other_nokey, check_other_key) (check_if_nokey, check_if_key, check_match_eq_key) (check_match_eql_key, check_match_equal_key) (check_match_equalp_key, check_match_other_key): New. These are basically to provide function pointers to be used by Lisp functions that take TEST, TEST-NOT and KEY arguments. (get_check_match_function_1, get_check_test_function) (get_check_match_function): These functions work out which of the previous list of functions to use, given the keywords supplied by the user. (count_with_tail): New. This is the bones of #'count. (list_count_from_end, string_count_from_end): Utility functions for #'count. (Fcount): New, moved from cl-seq.el. (list_position_cons_before): New. The implementation of #'member*, and important in implementing various other functions. (FmemberX, Fadjoin, FassocX, FrassocX, Fposition, Ffind) (FdeleteX, FremoveX, Fdelete_duplicates, Fremove_duplicates) (Fnsubstitute, Fsubstitute, Fsublis, Fnsublis, Fsubst, Fnsubst) (Ftree_equal, Fmismatch, Fsearch, Fintersection, Fnintersection) (Fsubsetp, Fset_difference, Fnset_difference, Fnunion, Funion) (Fset_exclusive_or, Fnset_exclusive_or): New, moved here from cl-seq.el. (position): New. The implementation of #'find and #'position. (list_delete_duplicates_from_end, subst, sublis, nsublis) (tree_equal, mismatch_from_end, mismatch_list_list) (mismatch_list_string, mismatch_list_array) (mismatch_string_array, mismatch_string_string) (mismatch_array_array, get_mismatch_func): Helper C functions for the Lisp-visible functions. (venn, nvenn): New. The implementation of the main Lisp functions that treat lists as sets. lisp/ChangeLog addition: 2010-12-30 Aidan Kehoe <kehoea@parhasard.net> * cl-seq.el: Move the heavy lifting from this file to C. Dump the cl-parsing-keywords macro, but don't use defun* for the functions we define that do take keywords, dynamic scope lossage makes that not practical. * subr.el (sort, fillarray): Move these aliases here. (map-plist): #'nsublis is now built-in, but at this point #'eql isn't necessarily available as a test; use #'eq. * obsolete.el (cl-delete-duplicates): Make this available for old compiler macros and old code. (memql): Document that this is equivalent to #'member*, and worse. * cl.el (adjoin, subst): Removed. These are in C.
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 30 Dec 2010 01:59:52 +0000
parents e687f1912d5b
children f00192e1cd49 308d34e9f07d
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 ;;
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3 ;; Copyright (C) 2007 Didier Verna
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
4 ;; Copyright (C) 1996-1997, 1999-2002 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
7 ;; Maintainer: Didier Verna <didier@xemacs.org>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; Keywords: extensions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; Version: 1.9960-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; XEmacs is free software; you can redistribute it and/or modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; 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
16 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; XEmacs is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;; along with XEmacs; see the file COPYING. If not, write to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;;
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
31 ;; See `widget.el' and the wishlist in `../man/widget.texi'.
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 (require 'widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
38 ;; XEmacs: autoload of `finder-commentary' is redundant.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;;; Customization.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 (defgroup widgets nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 "Customization support for the Widget Library."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 :link '(custom-manual "(widget)Top")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 :link '(url-link :tag "Development Page"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 "http://www.dina.kvl.dk/~abraham/custom/")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 :link '(emacs-library-link :tag "Lisp File" "widget.el")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 :prefix "widget-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 :group 'extensions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 :group 'hypermedia)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 (defgroup widget-documentation nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 "Options controlling the display of documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 (defgroup widget-faces nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 "Faces used by the widget library."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 :group 'faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 (defvar widget-documentation-face 'widget-documentation-face
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
62 "Face used for documentation strings in widgets.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 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
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (defface widget-documentation-face '((((class color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (:foreground "lime green"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (((class color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (:foreground "dark green"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 "Face used for documentation text."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 :group 'widget-documentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 (defvar widget-button-face 'widget-button-face
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
77 "Face used for buttons in widgets.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 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
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (defface widget-button-face '((t (:bold t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 "Face used for widget buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (defcustom widget-mouse-face 'highlight
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 "Face used for widget buttons when the mouse is above them."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 :type 'face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
89 ;; #### comment from GNU Emacs 21.3.50, test the first spec.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
90 ;; TTY gets special definitions here and in the next defface, because
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
91 ;; the gray colors defined for other displays cause black text on a black
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
92 ;; background, at least on light-background TTYs.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
93 (defface widget-field-face '(
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
94 ;; #### sjt sez: XEmacs doesn't like this.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
95 ;; The Custom face editor widget shows a Lisp
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
96 ;; form, not a face structure. Does it produce
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
97 ;; the right face on TTYs?
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
98 ;; One hypothesis is that the editor doesn't
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
99 ;; grok non-default display types in the value.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
100 (((type tty))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
101 (:background "yellow3")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
102 (:foreground "black"))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
103 (((class grayscale color)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 (:background "gray85"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 (:background "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 "Face used for editable fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ;; Currently unused
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ;(defface widget-single-line-field-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ; (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ; (:background "gray85"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ; (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ; (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ; (:background "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 ; (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ; (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ; "Face used for editable fields spanning only a single line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ; :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 ;(defvar widget-single-line-display-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 ; (let ((table (make-display-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 ; (aset table 9 "^I")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 ; (aset table 10 "^J")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 ; table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 ; "Display table used for single-line editable fields.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 ;(set-face-display-table 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 ; widget-single-line-display-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ;; Some functions from this file have been ported to C for speed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ;; Setting this to t (*before* loading wid-edit.el) will make them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 ;; shadow the subrs. It should be used only for debugging purposes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (defvar widget-shadow-subrs nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 ;;; Utility functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 ;; These are not really widget specific.
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 (when (or (not (fboundp 'widget-plist-member))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 ;; 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
150 ;; compiled code won't fail -- it will just be slower.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (defun widget-plist-member (plist prop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 ;; Return non-nil if PLIST has the property PROP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 ;; PLIST is a property list, which is a list of the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 ;; (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 ;; Unlike `plist-get', this allows you to distinguish between a missing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 ;; property and a property with the value nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ;; The value is actually the tail of PLIST whose car is PROP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (while (and plist (not (eq (car plist) prop)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (setq plist (cddr plist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
162 (defsubst widget-princ-to-string (object)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
163 "Return string representation of OBJECT, any Lisp object.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
164
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
165 No quoting characters or string delimiters are used."
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
166 ;(with-current-buffer (get-buffer-create " *widget-tmp*")
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
167 ; (erase-buffer)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
168 ; (princ object (current-buffer))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
169 ; (buffer-string))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
170 (prin1-to-string object t)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
171 )
428
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 (defun widget-prettyprint-to-string (object)
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
174 "Use `cl-prettyprint' to generate a string representation of OBJECT.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
175
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
176 Cleans up `cl-prettyprint''s gratuitous surrounding newlines."
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
177 (with-temp-buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (cl-prettyprint object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ;; `cl-prettyprint' always surrounds the text with newlines.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
180 (buffer-string (if (eq (char-after (point-min)) ?\n)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
181 (1+ (point-min))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
182 (point-min))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
183 (if (eq (char-before (point-max)) ?\n)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
184 (1- (point-max))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
185 (point-max)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (defun widget-clear-undo ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 "Clear all undo information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (buffer-disable-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (buffer-enable-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
192 (defun widget-sublist (list start &optional end)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
193 "Return the sublist of LIST from START to END.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
194 If END is omitted, it defaults to the length of LIST."
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
195 (if (> start 0) (setq list (nthcdr start list)))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
196 (if end
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
197 (if (<= end start)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
198 nil
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
199 (setq list (copy-sequence list))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
200 (setcdr (nthcdr (- end start 1) list) nil)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
201 list)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
202 (copy-sequence list)))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
203
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
204 ;; Is unimplemented the right superclass?
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
205 (define-error 'missing-package "Package not installed" 'unimplemented)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
206
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (defcustom widget-menu-max-size 40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 "Largest number of items allowed in a popup-menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 Larger menus are read through the minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 :type 'integer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
213 (defcustom widget-menu-max-shortcuts 40
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
214 "Largest number of items for which it works to choose one with a character.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
215 For a larger number of items, the minibuffer is used.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
216 #### Not yet implemented in XEmacs."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
217 :group 'widgets
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
218 :type 'integer)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
219
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (defcustom widget-menu-minibuffer-flag nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 "*Control how to ask for a choice from the keyboard.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 Non-nil means use the minibuffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 nil means read a single character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 (defun widget-choose (title items &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 "Choose an item from a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 First argument TITLE is the name of the list.
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
231 Second argument ITEMS is a list whose members are either
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (NAME . VALUE), to indicate selectable items, or just strings to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 indicate unselectable items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 Optional third argument EVENT is an input event.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
236 The user is asked to choose a NAME from the items alist, and the VALUE of
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
237 the chosen element will be returned. If EVENT is a mouse event, and the
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
238 number of elements in items is less than `widget-menu-max-size', a popup
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
239 menu will be used, otherwise the minibuffer is used."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (cond ((and (< (length items) widget-menu-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 ;; Pressed by the mouse.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (let ((val (get-popup-menu-response
724
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
245 (let ((menu-thingee
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (cons title
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (mapcar (lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (if (stringp x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (vector x nil nil)
724
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
250 (vector (car x)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
251 (list (car x)) ; 'eval 'quote
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
252 t)))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
253 items))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
254 ))
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
255 (message "%s" menu-thingee)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
256 menu-thingee)
76d5a3dd827a [xemacs-hg @ 2002-01-05 07:33:11 by stephent]
stephent
parents: 652
diff changeset
257 )))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (setq val (and val
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (listp (event-object val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (stringp (car-safe (event-object val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (car (event-object val))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (cdr (assoc val items))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 ((and (not widget-menu-minibuffer-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 ;; Can't handle more than 10 items (as many digits)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (<= (length items) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 ;; Construct a menu of the choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 ;; and then use it for prompting for a single character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (let* ((overriding-terminal-local-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (map (make-sparse-keymap title))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (next-digit ?0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 some-choice-enabled value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 ;; Define SPC as a prefix char to get to this menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (define-key overriding-terminal-local-map " " map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (with-current-buffer (get-buffer-create " widget-choose")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (insert "Available choices:\n\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (dolist (choice items)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (when (consp choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (let* ((name (car choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (function (cdr choice)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (insert (format "%c = %s\n" next-digit name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (define-key map (vector next-digit) function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (setq some-choice-enabled t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 ;; Allocate digits to disabled alternatives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 ;; so that the digit of a given alternative never varies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (incf next-digit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (insert "\nC-g = Quit"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (or some-choice-enabled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (error "None of the choices is currently meaningful"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (define-key map [?\C-g] 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (define-key map [t] 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 ;(setcdr map (nreverse (cdr map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 ;; Unread a SPC to lead to our new menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (push (character-to-event ?\ ) unread-command-events)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 ;; Read a char with the menu, and return the result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 ;; that corresponds to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (save-window-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (display-buffer (get-buffer " widget-choose"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (let ((cursor-in-echo-area t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (setq value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (lookup-key overriding-terminal-local-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (read-key-sequence (concat title ": ") t)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (message "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (when (or (eq value 'keyboard-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (null value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (error "Canceled"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 ;; Read the choice of name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (setq items (remove-if 'stringp items))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (let ((val (completing-read (concat title ": ") items nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (if (stringp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (let ((try (try-completion val items)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (when (stringp try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (setq val try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (cdr (assoc val items)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
319 ;; GNU Emacs 21.3.50 uses this in `widget-choose'
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
320 (defun widget-remove-if (predicate list)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
321 (let (result (tail list))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
322 (while tail
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
323 (or (funcall predicate (car tail))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
324 (setq result (cons (car tail) result)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
325 (setq tail (cdr tail)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
326 (nreverse result)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
327
3287
681d0fbb904e [xemacs-hg @ 2006-03-17 16:50:03 by james]
james
parents: 2367
diff changeset
328 (defun widget-move-and-invoke (event)
681d0fbb904e [xemacs-hg @ 2006-03-17 16:50:03 by james]
james
parents: 2367
diff changeset
329 "Move to where you click, and if it is an active field, invoke it."
681d0fbb904e [xemacs-hg @ 2006-03-17 16:50:03 by james]
james
parents: 2367
diff changeset
330 (interactive "e")
681d0fbb904e [xemacs-hg @ 2006-03-17 16:50:03 by james]
james
parents: 2367
diff changeset
331 (mouse-set-point event)
681d0fbb904e [xemacs-hg @ 2006-03-17 16:50:03 by james]
james
parents: 2367
diff changeset
332 (let ((pos (event-point event)))
681d0fbb904e [xemacs-hg @ 2006-03-17 16:50:03 by james]
james
parents: 2367
diff changeset
333 (if (and pos (get-char-property pos 'button))
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
334 (widget-button-click event))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 ;;; Widget text specifications.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 ;; These functions are for specifying text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
340 ;; XEmacs: This probably should be unnecessary with end-closed extents.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
341 ;; If it doesn't work, it should be made to work.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (defcustom widget-field-add-space t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 ;; Setting this to nil might be available, once some problems are resolved.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 "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
345
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
346 Currently should be left set to `t', because without the space it becomes
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
347 impossible to edit a zero size field."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
351 ;; #### Why aren't these used in XEmacs?
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (defcustom widget-field-use-before-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (and (or (> emacs-minor-version 34)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (> emacs-major-version 19))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (not (string-match "XEmacs" emacs-version)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 "Non-nil means use `before-change-functions' to track editable fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 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
358 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
359 new value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (defun widget-echo-this-extent (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (let* ((widget (or (extent-property extent 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (extent-property extent 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (extent-property extent 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (setq help-echo (funcall help-echo widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (when (stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (setq help-echo-owns-message t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (display-message 'help-echo help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (defsubst widget-handle-help-echo (extent help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (set-extent-property extent 'balloon-help help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (set-extent-property extent 'help-echo help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (when (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (set-extent-property extent 'balloon-help 'widget-echo-this-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (set-extent-property extent 'help-echo 'widget-echo-this-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (defun widget-specify-field (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 "Specify editable button for WIDGET between FROM and TO."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (goto-char to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (cond ((null (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 (forward-char 1))
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
387 ;; XEmacs: This comment goes outside of the save-excursion in GNU.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 ;; Terminating space is not part of the field, but necessary in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 ;; 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
390 ;; at the end of the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (widget-field-add-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (insert-and-inherit " ")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (setq to (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 (let ((map (widget-get widget :keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (face (or (widget-get widget :value-face) 'widget-field-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 (help-echo (widget-get widget :help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (unless (or (stringp help-echo) (null help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (widget-put widget :field-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (and (or (not widget-field-add-space)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (set-extent-property extent 'end-closed nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (set-extent-property extent 'detachable nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (set-extent-property extent 'field widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (set-extent-property extent 'button-or-field t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (set-extent-property extent 'keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (widget-handle-help-echo extent help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (widget-specify-secret widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (defun widget-specify-secret (field)
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
413 "Replace text in FIELD with value of the `:secret' property, if non-nil.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
414
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
415 The value of the `:secret' property, if non-nil, must be a character.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
416 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
417 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (let ((secret (widget-get field :secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (size (widget-get field :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (when secret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (let ((begin (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (end (widget-field-end field)))
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
423 (when size
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (while (and (> end begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (eq (char-after (1- end)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (setq end (1- end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (while (< begin end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (let ((old (char-after begin)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (unless (eq old secret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (subst-char-in-region begin (1+ begin) old secret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (put-text-property begin (1+ begin) 'secret old))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (setq begin (1+ begin))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (defun widget-specify-button (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 "Specify button for WIDGET between FROM and TO."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (let ((face (widget-apply widget :button-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (help-echo (widget-get widget :help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (extent (make-extent from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (map (widget-get widget :button-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (widget-put widget :button-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (unless (or (null help-echo) (stringp help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (set-extent-property extent 'button widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (set-extent-property extent 'button-or-field t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (set-extent-property extent 'mouse-face widget-mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 (widget-handle-help-echo extent help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 (set-extent-property extent 'keymap map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 (defun widget-mouse-help (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 "Find mouse help string for button in extent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (let* ((widget (widget-at (extent-start-position extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (help-echo (and widget (widget-get widget :help-echo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (cond ((stringp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 ((and (functionp help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (stringp (setq help-echo (funcall help-echo widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (format "(widget %S :help-echo %S)" widget help-echo)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 (defun widget-specify-sample (widget from to)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
464 "Specify sample for WIDGET between FROM and TO."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 (let ((face (widget-apply widget :sample-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (extent (make-extent from to nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (set-extent-property extent 'face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 (widget-put widget :sample-extent extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (defun widget-specify-doc (widget from to)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
472 "Specify documentation for WIDGET between FROM and TO."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 (let ((extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 (set-extent-property extent 'widget-doc widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 (set-extent-property extent 'face widget-documentation-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 (widget-put widget :doc-extent extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 (defmacro widget-specify-insert (&rest form)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
480 "Execute FORM without inheriting any text properties."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 `(save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (insert "<>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (narrow-to-region (- (point) 2) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (goto-char (1+ (point-min)))
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
488 ;; XEmacs: use `prog1' instead of a `result' variable. The latter
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 ;; confuses the byte-compiler in some cases (a warning).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (prog1 (progn ,@form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (delete-region (point-min) (1+ (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (delete-region (1- (point-max)) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 (goto-char (point-max))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 (put 'widget-specify-insert 'edebug-form-spec '(&rest form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 ;;; Inactive Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 (defface widget-inactive-face '((((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (background dark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 (:foreground "light gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 (((class grayscale color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 (background light))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (:foreground "dim gray"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (:italic t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 "Face used for inactive widgets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 :group 'widget-faces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 ;; For inactiveness to work on complex structures, it is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 ;; sufficient to keep track of whether a button/field/glyph is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 ;; inactive or not -- we must know how many time it was deactivated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 ;; (inactiveness level). Successive deactivations of the same button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 ;; increment its inactive-count, and activations decrement it. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 ;; inactive-count reaches 0, the button/field/glyph is reactivated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (defun widget-activation-widget-mapper (extent action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 "Activate or deactivate EXTENT's widget (button or field).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 Suitable for use with `map-extents'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 (ecase action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 (:activate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 (decf (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 (when (zerop (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 extent (extent-property extent :inactive-plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (set-extent-property extent :inactive-plist nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (:deactivate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 (incf (extent-property extent :inactive-count 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 ;; Store a plist of old properties, which will be fed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 ;; `set-extent-properties'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (unless (extent-property extent :inactive-plist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (set-extent-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 extent :inactive-plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (list 'mouse-face (extent-property extent 'mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 'help-echo (extent-property extent 'help-echo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 'keymap (extent-property extent 'keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 extent '(mouse-face nil help-echo nil keymap nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 nil)
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 (defun widget-activation-glyph-mapper (extent action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (let ((activate-p (if (eq action :activate) t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (if activate-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (decf (extent-property extent :inactive-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (incf (extent-property extent :inactive-count 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (when (or (and activate-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (zerop (extent-property extent :inactive-count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (and (not activate-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 (not (zerop (extent-property extent :inactive-count)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (let* ((glyph-widget (extent-property extent 'glyph-widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (up-glyph (widget-get glyph-widget :glyph-up))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (inactive-glyph (widget-get glyph-widget :glyph-inactive))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
554 (instantiator (widget-get glyph-widget :glyph-instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 (new-glyph (if activate-p up-glyph inactive-glyph)))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
556 (cond
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
557 ;; Assume that an instantiator means a native widget.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
558 (instantiator
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
559 (setq instantiator
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
560 (set-instantiator-property instantiator :active activate-p))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
561 (widget-put glyph-widget :glyph-instantiator instantiator)
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
562 (set-glyph-image up-glyph instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 ;; Check that the new glyph exists, and differs from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 ;; default one.
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
565 ((and up-glyph inactive-glyph (not (eq up-glyph inactive-glyph))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
566 ;; Check if the glyph is already installed.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
567 (not (eq (extent-end-glyph extent) new-glyph)))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
568 ;; Change it.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
569 (set-extent-end-glyph extent new-glyph))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 nil)
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-specify-inactive (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 "Make WIDGET inactive for user modifications."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (unless (widget-get widget :inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 (let ((extent (make-extent from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 ;; 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
577 ;; the inactive editable fields now lose their keymaps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 (set-extent-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 extent '(start-open t face widget-inactive-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 detachable t priority 2001 widget-inactive t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 (widget-put widget :inactive extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 ;; Deactivate the buttons and fields within the range. In some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 ;; cases, the fields are not yet setup at the time this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 ;; is called. Those fields are deactivated explicitly by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 ;; `widget-setup'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 (map-extents 'widget-activation-widget-mapper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 nil from to :deactivate nil 'button-or-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 ;; Deactivate glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 (map-extents 'widget-activation-glyph-mapper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 nil from to :deactivate nil 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 (defun widget-specify-active (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 "Make WIDGET active for user modifications."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
594 (let ((inactive (widget-get widget :inactive))
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
595 (from (widget-get widget :from))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
596 (to (widget-get widget :to)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (when (and inactive (not (extent-detached-p inactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 ;; Reactivate the buttons and fields covered by the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (map-extents 'widget-activation-widget-mapper
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
600 nil from to :activate nil 'button-or-field)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 ;; Reactivate the glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (map-extents 'widget-activation-glyph-mapper
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
603 nil from to :activate nil 'end-glyph)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (delete-extent inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 (widget-put widget :inactive nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
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 ;;; Widget Properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (defsubst widget-type (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 "Return the type of WIDGET, a symbol."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (car widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
614 ;;;###autoload
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
615 (defun widgetp (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
616 "Return non-nil iff WIDGET is a widget."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
617 (if (symbolp widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
618 (get widget 'widget-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
619 (and (consp widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
620 (symbolp (car widget))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
621 (get (car widget) 'widget-type))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
622
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (when (or (not (fboundp 'widget-put))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (defun widget-put (widget property value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 "In WIDGET set PROPERTY to VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 The value can later be retrieved with `widget-get'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (setcdr widget (plist-put (cdr widget) property value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 ;; Recoded in C, for efficiency:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 (when (or (not (fboundp 'widget-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 (defun widget-get (widget property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 "In WIDGET, get the value of PROPERTY.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
635 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
636 later with `widget-put'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 (let ((missing t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 value tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 (while missing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 (cond ((setq tmp (widget-plist-member (cdr widget) property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (setq value (car (cdr tmp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 missing nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 ((setq tmp (car widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (setq widget (get tmp 'widget-type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (setq missing nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 (defun widget-get-indirect (widget property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 "In WIDGET, get the value of PROPERTY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 If the value is a symbol, return its binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 Otherwise, just return the value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (let ((value (widget-get widget property)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (symbol-value value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (defun widget-member (widget property)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
659 "Non-nil iff there is a definition in WIDGET for PROPERTY."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 (cond ((widget-plist-member (cdr widget) property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 ((car widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 (widget-member (get (car widget) 'widget-type) property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 (t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 (when (or (not (fboundp 'widget-apply))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 widget-shadow-subrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 ;;This is in C, so don't ###utoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (defun widget-apply (widget property &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 "Apply the value of WIDGET's PROPERTY to the widget itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 ARGS are passed as extra arguments to the function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 (apply (widget-get widget property) widget args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (defun widget-value (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 "Extract the current value of WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 :value-to-external (widget-apply widget :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 (defun widget-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 "Set the current value of WIDGET to VALUE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 :value-set (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 :value-to-internal value)))
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 (defun widget-default-get (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
686 "Extract the default value of WIDGET."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 (or (widget-get widget :value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 (widget-apply widget :default-get)))
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 (defun widget-match-inline (widget vals)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
691 "In WIDGET, match the start of VALS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (cond ((widget-get widget :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 (widget-apply widget :match-inline vals))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
694 ((and (listp vals)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 (widget-apply widget :match (car vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (cons (list (car vals)) (cdr vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 (t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 (defun widget-apply-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 "Apply :action in WIDGET in response to EVENT."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 (if (widget-apply widget :active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 (widget-apply widget :action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 (error "Attempt to perform action on inactive widget")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 ;;; Helper functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 ;; These are widget specific.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
710 ;; #### Note: this should probably be a more general utility -- dvl
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
711 (defsubst widget-prompt-spaceify (prompt)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
712 ;; Add a space at the end of PROMPT if needed
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
713 (if (or (string= prompt "") (eq ? (aref prompt (1- (length prompt)))))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
714 prompt
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
715 (concat prompt " ")))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
716
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
717 (defsubst widget-prompt (widget &optional prompt default-prompt)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
718 ;; Construct a prompt for WIDGET.
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
719 ;; - If PROMPT is given, use it.
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
720 ;; - Otherwise, use the :tag property, if any.
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
721 ;; - Otherwise, use DEFAULT-PROMPT, if given.
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
722 ;; - Otherise, use "Value".
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
723 ;; - If the result is not the empty string, add a space for later addition
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
724 ;; of the widget type by `widget-prompt-value'.
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
725 (unless prompt
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
726 (setq prompt (or (and (widget-get widget :tag)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
727 (replace-in-string (widget-get widget :tag)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
728 "^[ \t]+" "" t))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
729 default-prompt
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
730 "Value")))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
731 (widget-prompt-spaceify prompt))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
732
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
733
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 ;;;###autoload
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
735 (defun widget-prompt-value (widget &optional prompt value unbound)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
736 "Prompt for a value matching WIDGET.
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
737 Prompt with PROMPT, or WIDGET's :tag otherwise.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 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
739 (unless (listp widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 (setq widget (list widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (setq widget (widget-convert widget))
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
742 (let ((answer (widget-apply widget
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
743 :prompt-value
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
744 (format "%s[%s]"
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
745 (widget-prompt widget prompt)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
746 (widget-type widget))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
747 value unbound)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 (while (not (widget-apply widget :match answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 (setq answer (signal 'error (list "Answer does not match type"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 answer (widget-type widget)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (defun widget-get-sibling (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 "Get the item WIDGET is assumed to toggle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 This is only meaningful for radio buttons or checkboxes in a list."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
756 (let* ((children (widget-get (widget-get widget :parent) :children))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 (catch 'child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 (when (eq (widget-get child :button) widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 (throw 'child child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 (defun widget-map-buttons (function &optional buffer maparg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 "Map FUNCTION over the buttons in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 FUNCTION is called with the arguments WIDGET and MAPARG.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 If FUNCTION returns non-nil, the walk is cancelled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 The arguments MAPARG, and BUFFER default to nil and (current-buffer),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 respectively."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 (map-extents (lambda (extent ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 ;; If FUNCTION returns non-nil, we bail out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 (funcall function (extent-property extent 'button) maparg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 nil nil nil nil nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 'button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 ;;; Glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (defcustom widget-glyph-directory (locate-data-directory "custom")
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
784 "Where widget button glyphs are located.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 If this variable is nil, widget will try to locate the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 automatically."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 :type 'directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 (defcustom widget-glyph-enable t
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
791 "If non nil, use glyph buttons in widgets when available."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
795 ;; #### What happens if you try to customize this?
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
796 (define-compatible-variable-alias 'widget-image-conversion
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
797 'widget-image-file-name-suffixes)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
798
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 (defcustom widget-image-file-name-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 '((xpm ".xpm") (gif ".gif") (png ".png") (jpeg ".jpg" ".jpeg")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 (xbm ".xbm"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 "Conversion alist from image formats to file name suffixes."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 :type '(repeat (cons :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (symbol :tag "Image Format" unknown)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (repeat :tag "Suffixes"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 (string :format "%v")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 ;; Don't use this, because we cannot yet distinguish between widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 ;; glyphs associated with user action, and actionless ones.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 ;(defvar widget-glyph-pointer-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 ; (make-pointer-glyph [cursor-font :data "hand2"])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 ; "Glyph to be used as the mouse pointer shape over glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 ;Use `set-glyph-image' to change this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 (defvar widget-glyph-cache nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 "Cache of glyphs associated with strings (files).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 (defun widget-glyph-find (image tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 "Create a glyph corresponding to IMAGE with string TAG as fallback.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 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
822 xbm, gif, jpg, or png) located in `widget-glyph-directory', or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 in one of the data directories.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 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
825 used to make the glyph, with an additional TAG string fallback."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (cond ((not (and image widget-glyph-enable))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 ;; We don't want to use glyphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 ((and (not (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 ;; We don't use glyphs on TTY consoles, although we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 ;; could. However, glyph faces aren't yet working
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 ;; properly, and movement through glyphs is unintuitive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 ;; As an exception, when TAG is nil, we assume that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 ;; caller knows what he is doing, and that the tag is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 ;; encoded within the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 (not (glyphp image)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 ((glyphp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 ;; Already a glyph. Use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 ((stringp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 ;; A string. Look it up in the cache first...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (or (lax-plist-get widget-glyph-cache image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 ;; ...and then in the relevant directories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 (let* ((dirlist (cons (or widget-glyph-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 (locate-data-directory "custom"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 data-directory-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 (all-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 (apply #'append
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (lambda (el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 (and (valid-image-instantiator-format-p (car el))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 (cdr el)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 widget-image-file-name-suffixes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 (file (locate-file image dirlist all-suffixes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 (when file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (let* ((extension (concat "." (file-name-extension file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 (format (car (rassoc* extension
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 widget-image-file-name-suffixes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 :test #'member))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 ;; We create a glyph with the file as the default image
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 ;; instantiator, and the TAG fallback
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (let ((glyph (make-glyph `([,format :file ,file]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 [string :data ,tag]))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 ;; Cache the glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 (laxputf widget-glyph-cache image glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 ;; ...and return it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 glyph))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 ((valid-instantiator-p image 'image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 ;; A valid image instantiator (e.g. [gif :file "somefile"] etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 (make-glyph `(,image [string :data ,tag])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 ;; Oh well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (defun widget-glyph-insert (widget tag image &optional down inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 "In WIDGET, insert the text TAG or, if supported, IMAGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 IMAGE should either be a glyph, an image instantiator, an image file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 name sans extension (xpm, xbm, gif, jpg, or png) located in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 `widget-glyph-directory', or anything else allowed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 `widget-glyph-find'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 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
884 glyphs. The down and inactive glyphs are shown when glyph is pressed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 or inactive, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 The optional DOWN and INACTIVE arguments are deprecated, and exist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 only because of compatibility."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 ;; Convert between IMAGE being a list, etc. Must use `psetq',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 ;; because otherwise change to `image' screws up the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 (psetq image (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (car image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 down (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 (nth 1 image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 inactive (or (and (consp image)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 (nth 2 image))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 (let ((glyph (widget-glyph-find image tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 (if glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 (widget-glyph-insert-glyph widget glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (widget-glyph-find down tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 (widget-glyph-find inactive tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (insert tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
908 (defun widget-glyph-insert-glyph (widget glyph &optional down inactive
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
909 instantiator)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 "In WIDGET, insert GLYPH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 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
912 glyphs used when the widget is pushed and inactive, respectively.
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
913 INSTANTIATOR is the vector used to create the glyph."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 (insert "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (let ((extent (make-extent (point) (1- (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (help-echo (and widget (widget-get widget :help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (map (and widget (widget-get widget :button-keymap))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (set-extent-property extent 'glyph-widget widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 ;; 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
920 ;; doesn't mess with cursor motion. But atomic-extents library is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 ;; currently a mess, so I'd rather not use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 (set-extent-property extent 'invisible t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (set-extent-property extent 'start-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (set-extent-property extent 'end-open t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (set-extent-property extent 'keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 ;;(set-extent-property extent 'pointer widget-glyph-pointer-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (set-extent-end-glyph extent glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (unless (or (stringp help-echo) (null help-echo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (setq help-echo 'widget-mouse-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (when help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (widget-handle-help-echo extent help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (when widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (widget-put widget :glyph-up glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (when down (widget-put widget :glyph-down down))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
935 (when instantiator (widget-put widget :glyph-instantiator instantiator))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 (when inactive (widget-put widget :glyph-inactive inactive))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 ;;; Buttons.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (defgroup widget-button nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 "The look of various kinds of buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (defcustom widget-button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 "String used as prefix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 :group 'widget-button)
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 (defcustom widget-button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 "String used as suffix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 ;;; Creating Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (defun widget-create (type &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
960 "Create a widget of type TYPE.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
961
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
962 TYPE is copied, then converted to a widget using the keyword arguments ARGS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 (let ((widget (apply 'widget-convert type args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 (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
968 "As a child of widget PARENT, create a widget of type TYPE.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
969
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
970 TYPE is copied, then converted to a widget using the keyword arguments ARGS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 (let ((widget (apply 'widget-convert type args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 (defun widget-create-child (parent type)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
981 "As a child of widget PARENT, create a widget of type TYPE.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
982
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
983 TYPE is copied, then used as a widget as-is."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (let ((widget (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 (defun widget-create-child-value (parent type value)
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
994 "As a child of widget PARENT, create a widget with type TYPE and value VALUE.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
995
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
996 TYPE is copied, then used as a widget as-is."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 (let ((widget (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 (widget-put widget :value (widget-apply widget :value-to-internal value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 (widget-put widget :parent parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 (unless (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 (or (widget-get widget :extra-offset) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 (widget-get parent :offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 (widget-apply widget :create)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 (defun widget-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 "Delete WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 (widget-apply widget :delete))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1012 (defun widget-copy (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1013 "Make a deep copy of WIDGET."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1014 (widget-apply (copy-sequence widget) :copy))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1015
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1309
diff changeset
1016 ;;;###autoload
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 (defun widget-convert (type &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 "Convert TYPE to a widget without inserting it in the buffer.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1019 The optional ARGS are additional keyword arguments.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1020
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1021 The widget's :args property is set from the longest tail of ARGS whose cdr
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1022 is not a keyword, or from the longest tail of TYPE's :args property whose
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1023 cdr is not a keyword. Keyword arguments from ARGS are set, and the :value
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1024 property (if any) is converted from external to internal format."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 ;; Don't touch the type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (let* ((widget (if (symbolp type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 (list type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 (copy-sequence type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 (current widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 (keys args))
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1031 ;; First set the :args.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1032 (while (cdr current) ; Use first non-keyword element of type.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 (let ((next (car (cdr current))))
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1034 (if (keywordp next)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 (setq current (cdr (cdr current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (setcdr current (list :args (cdr current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (setq current nil))))
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1038 (while args ; Use first non-keyword element in ARGS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (let ((next (nth 0 args)))
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1040 (if (keywordp next)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (setq args (nthcdr 2 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (widget-put widget :args args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (setq args nil))))
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1044 ;; Then convert the widget.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 (setq type widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (while type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (let ((convert-widget (plist-get (cdr type) :convert-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (if convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (setq widget (funcall convert-widget widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (setq type (get (car type) 'widget-type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 ;; Finally set the keyword args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (while keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (let ((next (nth 0 keys)))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1054 (if (keywordp next)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (widget-put widget next (nth 1 keys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (setq keys (nthcdr 2 keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 (setq keys nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 ;; Convert the :value to internal format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 (if (widget-member widget :value)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1061 (widget-put widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1062 :value (widget-apply widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1063 :value-to-internal
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1064 (widget-get widget :value))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 ;; Return the newly created widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1068 ;;;###autoload
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 (defun widget-insert (&rest args)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1070 "Call `insert' with ARGS even if surrounding text is read only."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (apply 'insert args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 (defun widget-convert-text (type from to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 &optional button-from button-to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 &rest args)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1079 "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
1080 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
1081 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
1082 the text between them.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1083 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
1084 used as the widget's button end points.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 Optional ARGS are extra keyword arguments for TYPE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 (let ((widget (apply 'widget-convert type :delete 'widget-leave-text args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 (from (copy-marker from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (to (copy-marker to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 (set-marker-insertion-type from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 (set-marker-insertion-type to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 (widget-put widget :from from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (widget-put widget :to to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 (when button-from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (widget-specify-button widget button-from button-to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (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
1098 "Return a widget of type TYPE with endpoints FROM and TO.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 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
1100 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
1101 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
1102 end points. The widget is ``wrapped around'' the text between them."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 (apply 'widget-convert-text type from to from to args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 (defun widget-leave-text (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 "Remove markers and extents from WIDGET and its children."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 (let ((from (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 (to (widget-get widget :to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 (button (widget-get widget :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 (sample (widget-get widget :sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 (doc (widget-get widget :doc-extent))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1112 (field (widget-get widget :field-extent)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 (set-marker to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 ;; Maybe we should delete the extents here? As this code doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 ;; remove them from widget structures, maybe it's safer to just
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1117 ;; detach them. That's what GNU-compatible `delete-overlay' does.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 (when button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 (detach-extent button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 (when sample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 (detach-extent sample))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 (when doc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 (detach-extent doc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 (when field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 (detach-extent field))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1126 (mapc 'widget-leave-text (widget-get widget :children))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127
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 ;;; Keymap and Commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 (defvar widget-keymap nil
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1132 "Keymap containing useful bindings for buffers containing widgets.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 Recommended as a parent keymap for modes using widgets.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 (unless widget-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 (setq widget-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 (define-key widget-keymap [tab] 'widget-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 (define-key widget-keymap [(shift tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 (define-key widget-keymap [(meta tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 (define-key widget-keymap [backtab] 'widget-backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 (defvar widget-global-map global-map
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1143 "Keymap used for events a widget does not handle itself.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (make-variable-buffer-local 'widget-global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 (defvar widget-field-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 "Keymap used inside an editable field.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (unless widget-field-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (setq widget-field-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 (set-keymap-parents widget-field-keymap global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (define-key widget-field-keymap "\C-k" 'widget-kill-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 (define-key widget-field-keymap [(meta tab)] 'widget-complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 (define-key widget-field-keymap [tab] 'widget-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 (define-key widget-field-keymap [(shift tab)] 'widget-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 (define-key widget-field-keymap "\C-m" 'widget-field-activate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 (define-key widget-field-keymap "\C-e" 'widget-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 (define-key widget-field-keymap "\C-t" 'widget-transpose-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 (defvar widget-text-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 "Keymap used inside a text field.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 (unless widget-text-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 (setq widget-text-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 (set-keymap-parents widget-field-keymap global-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (define-key widget-text-keymap "\C-e" 'widget-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 (define-key widget-text-keymap "\C-t" 'widget-transpose-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 (defvar widget-button-keymap nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 "Keymap used inside a button.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 (unless widget-button-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 (setq widget-button-keymap (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 (set-keymap-parents widget-button-keymap widget-keymap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (define-key widget-button-keymap "\C-m" 'widget-button-press)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 (define-key widget-button-keymap [button2] 'widget-button-click)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 ;; Ideally, button3 within a button should invoke a button-specific
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 ;; menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 (define-key widget-button-keymap [button3] 'widget-button-click)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 ;;Glyph support.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (define-key widget-button-keymap [button1] 'widget-button1-click))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 (defun widget-field-activate (pos &optional event)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1187 "Invoke the editable field at point."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (interactive "@d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 (let ((field (widget-field-find pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 (if field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (widget-apply-action field event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 (call-interactively
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 (lookup-key widget-global-map (this-command-keys))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 (defface widget-button-pressed-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 '((((class color))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 (:foreground "red"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 (:bold t :underline t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 "Face used for pressed buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 :group 'widget-faces)
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-event-point (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 "Character position of the mouse event, or nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 (and (mouse-event-p event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 (event-point event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 (defun widget-button-click (event)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1209 "Invoke button under mouse pointer."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 (interactive "e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 (with-current-buffer (event-buffer event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 (cond ((event-glyph event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 (widget-glyph-click event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 ((widget-event-point event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 (let* ((pos (widget-event-point event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 (button (get-char-property pos 'button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 (if button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 (let* ((extent (widget-get button :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 (face (extent-property extent 'face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 (mouse-face (extent-property extent 'mouse-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 (help-echo (extent-property extent 'help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 ;; Merge relevant faces, and make the result mouse-face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 (let ((merge `(widget-button-pressed-face ,mouse-face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 (nconc merge (if (listp face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 face (list face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 (setq merge (delete-if-not 'find-face merge))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 (set-extent-property extent 'mouse-face merge))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 (unless (widget-apply button :mouse-down-action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 ;; Wait for button release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 (while (not (button-release-event-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 (setq event (next-event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 (dispatch-event event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 ;; Disallow mouse-face and help-echo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 (set-extent-property extent 'mouse-face nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 (set-extent-property extent 'help-echo nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 (setq pos (widget-event-point event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 (unless (eq (current-buffer) (extent-object extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 ;; Barf if dispatch-event tripped us by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 ;; changing buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 (error "Buffer changed during mouse motion"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 ;; Do the associated action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 (when (and pos (extent-in-region-p extent pos pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 (widget-apply-action button event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 ;; Unwinding: fully release the button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 (set-extent-property extent 'mouse-face mouse-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 (set-extent-property extent 'help-echo help-echo)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 ;; This should not happen!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 (error "`widget-button-click' called outside button"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 (message "You clicked somewhere weird")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (defun widget-button1-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 "Invoke glyph below mouse pointer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 (interactive "@e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 (if (event-glyph event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (widget-glyph-click event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 ;; Should somehow avoid this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 (let ((command (lookup-key widget-global-map (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 (and (commandp command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 (call-interactively command)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (defun widget-glyph-click (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 "Handle click on a glyph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 (let* ((glyph (event-glyph event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 (extent (event-glyph-extent event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 (widget (extent-property extent 'glyph-widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 (down-glyph (or (and widget (widget-get widget :glyph-down)) glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 (up-glyph (or (and widget (widget-get widget :glyph-up)) glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 (last event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 (unless (widget-apply widget :active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 (error "This widget is inactive"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (let ((current-glyph 'down))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 ;; We always know what glyph is drawn currently, to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 ;; unnecessary extent changes. Is this any noticeable gain?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 ;; Press the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 (set-extent-end-glyph extent down-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 ;; Redisplay (shouldn't be needed, but...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 (sit-for 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 (unless (widget-apply widget :mouse-down-action event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 ;; Wait for the release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 (while (not (button-release-event-p last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 (unless (button-press-event-p last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 (dispatch-event last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 (when (motion-event-p last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 ;; Update glyphs on mouse motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 (if (eq extent (event-glyph-extent last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 (unless (eq current-glyph 'down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 (set-extent-end-glyph extent down-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 (setq current-glyph 'down))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 (unless (eq current-glyph 'up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 (set-extent-end-glyph extent up-glyph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 (setq current-glyph 'up))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 (setq last (next-event event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 (unless (eq (current-buffer) (extent-object extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 ;; Barf if dispatch-event tripped us by changing buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 (error "Buffer changed during mouse motion"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 ;; Apply widget action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 (when (eq extent (event-glyph-extent last))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 (let ((widget (extent-property (event-glyph-extent event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 'glyph-widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 (cond ((null widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 (message "You clicked on a glyph"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 ((not (widget-apply widget :active))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 (error "This glyph is inactive"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 (widget-apply-action widget event))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 ;; Release the glyph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 (and (eq current-glyph 'down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 ;; The extent might have been detached or deleted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 (extent-live-p extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 (not (extent-detached-p extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 (set-extent-end-glyph extent up-glyph))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 (defun widget-button-press (pos &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 "Invoke button at POS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 (interactive "@d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 (let ((button (get-char-property pos 'button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 (if button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 (widget-apply-action button event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 (let ((command (lookup-key widget-global-map (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 (when (commandp command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 (call-interactively command))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 (defun widget-tabable-at (&optional pos last-tab backwardp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 "Return the tabable widget at POS, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 POS defaults to the value of (point)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 (unless pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 (setq pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 (let ((widget (widget-at pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 (if widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 (let ((order (widget-get widget :tab-order)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 (if order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 (if last-tab (and (= order (if backwardp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 (1- last-tab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 (1+ last-tab)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 (and (> order 0) widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 ;; Return the button or field extent at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 (defun widget-button-or-field-extent (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 (or (and (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 (widget-get (get-char-property pos 'button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (and (get-char-property pos 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 (widget-get (get-char-property pos 'field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 :field-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 (defun widget-next-button-or-field (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 "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
1356 Internal function, don't use it outside `wid-edit'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 (let* ((at-point (widget-button-or-field-extent pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (extent (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 (lambda (ext ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 nil (if at-point (extent-end-position at-point) pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 nil nil 'start-open 'button-or-field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 (and extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 (extent-start-position extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 ;; This is too slow in buffers with many buttons (W3).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (defun widget-previous-button-or-field (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 "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
1369 Internal function, don't use it outside `wid-edit'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 (let* ((at-point (widget-button-or-field-extent pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 previous-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 (lambda (ext ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 (if (eq ext at-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 ;; We reached the extent we were on originally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 (if (= pos (extent-start-position at-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 previous-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 (setq previous-extent at-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 (setq previous-extent ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 nil nil pos nil 'start-open 'button-or-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 (and previous-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 (extent-start-position previous-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 (defun widget-move (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 "Move point to the ARG next field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 ARG may be negative to move backward."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 (let ((opoint (point)) (wrapped 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 (last-tab (widget-get (widget-at (point)) :tab-order))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 nextpos found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 ;; Movement backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 (while (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 (setq nextpos (widget-previous-button-or-field (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 (if nextpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 (goto-char nextpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 (when (and (not (get-char-property nextpos 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 (widget-tabable-at nil last-tab t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 (incf arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 (setq found t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 last-tab (widget-get (widget-at (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 :tab-order))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 (if (and (not found) (> wrapped 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 (setq arg 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 (incf wrapped))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 ;; Movement forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 (setq nextpos (widget-next-button-or-field (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 (if nextpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 (goto-char nextpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 (when (and (not (get-char-property nextpos 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 (widget-tabable-at nil last-tab))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 (decf arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 (setq found t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 last-tab (widget-get (widget-at (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 :tab-order))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 (if (and (not found) (> wrapped 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 (setq arg 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 found nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 (incf wrapped))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 (if (not found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 (widget-echo-help (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 (run-hooks 'widget-move-hook))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 (defun widget-forward (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 "Move point to the next field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 With optional ARG, move across that many fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 (run-hooks 'widget-forward-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 (widget-move arg))
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 (defun widget-backward (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 "Move point to the previous field or button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 With optional ARG, move across that many fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 (run-hooks 'widget-backward-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 (widget-move (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 (defun widget-beginning-of-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1445 "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
1446
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1447 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
1448 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 (start (and field (widget-field-start field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 (if (and start (not (eq start (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 (call-interactively 'beginning-of-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 (defun widget-end-of-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1457 "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
1458
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1459 It is an error to use this function after creating the widget but before
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1460 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 (end (and field (widget-field-end field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 (if (and end (not (eq end (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 (call-interactively 'end-of-line))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 (defun widget-kill-line ()
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1469 "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
1470
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1471 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
1472 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 (newline (save-excursion (forward-line 1) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 (end (and field (widget-field-end field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 (if (and field (> newline end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 (kill-region (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 (call-interactively 'kill-line))))
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 (defun widget-transpose-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 "Like `transpose-chars', but works correctly at end of widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 (let* ((field (widget-field-find (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (start (and field (widget-field-start field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 (end (and field (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 (last-non-space (and start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 (skip-chars-backward " \t\n" start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 (cond ((and last-non-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 (or (= last-non-space start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 (= last-non-space (1+ start))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 ;; empty or one-character field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 ((= (point) start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 ;; at the beginning of the field -- we would get an error here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 (error "Cannot transpose at beginning of field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 (when (and (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 (= last-non-space (point)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1503 (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 (transpose-chars arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 (defcustom widget-complete-field (lookup-key global-map "\M-\t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 "Default function to call for completion inside fields."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 :options '(ispell-complete-word complete-tag lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 (defun widget-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 "Complete content of editable field from point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 When not inside a field, move to the previous button or field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 ;; Somehow, this should make pressing M-TAB twice scroll the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 ;; completions window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 (let ((field (widget-field-find (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 (if field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 (widget-apply field :complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 (error "Not in an editable field"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 ;;; Setting up the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1526 (defvar widget-field-new nil
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1527 "List of all newly created editable fields in the buffer.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 (make-variable-buffer-local 'widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1530 (defvar widget-field-list nil
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1531 "List of all editable fields in the buffer.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 (make-variable-buffer-local 'widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1534 ;; Is this a misnomer?
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1535 (defun widget-at (pos)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1536 "The button or field at POS."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1537 (or (get-char-property pos 'button)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1538 (get-char-property pos 'field)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1539
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1540 ;;;###autoload
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 (defun widget-setup ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 "Setup current buffer so editing string widgets works."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 (after-change-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 (while widget-field-new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 (setq field (car widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 widget-field-new (cdr widget-field-new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 widget-field-list (cons field widget-field-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 (let ((from (car (widget-get field :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 (to (cdr (widget-get field :field-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 (widget-specify-field field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 (marker-position from) (marker-position to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 (set-marker to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 ;; If the field is placed within the inactive zone, deactivate it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 (let ((extent (widget-get field :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 (when (get-char-property (extent-start-position extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 'widget-inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 (widget-activation-widget-mapper extent :deactivate)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 (widget-clear-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 (widget-add-change))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 (defvar widget-field-last nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 ;; Last field containing point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 (make-variable-buffer-local 'widget-field-last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 (defvar widget-field-was nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 ;; The widget data before the change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 (make-variable-buffer-local 'widget-field-was)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1573 (defun widget-field-at (pos)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1574 "Return the widget field at POS, or nil if none."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1575 (let ((field (get-char-property (or pos (point)) 'field)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1576 (if (eq field 'boundary)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1577 nil
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1578 field)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1579
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 (defun widget-field-buffer (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1581 "Return the buffer containing WIDGET.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1582
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1583 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
1584 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 (and extent (extent-object extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 (defun widget-field-start (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1589 "Return the start of WIDGET's editing field.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1590
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1591 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
1592 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 (and extent (extent-start-position extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 (defun widget-field-end (widget)
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1597 "Return the end of WIDGET's editing field.
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1598
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1599 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
1600 invoking `widget-setup'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 ;; 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
1603 (and extent (if (or widget-field-add-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 (null (widget-get widget :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 (1- (extent-end-position extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 (extent-end-position extent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 (defun widget-field-find (pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 "Return the field at POS.
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1610 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
1611
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1612 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
1613 `widget-setup' will always fail."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1614 ;; XEmacs: use `map-extents' instead of a while loop
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 (let ((field-extent (map-extents (lambda (extent ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 nil pos pos nil nil 'field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 (and field-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 (extent-property field-extent 'field))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
1621 ;; 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
1622 ;; invoking `widget-setup' will always fail.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 (defun widget-before-change (from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 ;; Barf if the text changed is outside the editable fields.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 (unless inhibit-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 (let ((from-field (widget-field-find from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 (to-field (widget-field-find to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 (cond ((or (null from-field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 (null to-field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 ;; Either end of change is not within a field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 (error "Attempt to change text outside editable field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 ((not (eq from-field to-field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 ;; The change begins in one fields, and ends in another one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 (error "Change should be restricted to a single field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 ((or (and from-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 (get-char-property from 'widget-inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 (and to-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 (get-char-property to 'widget-inactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 ;; Trying to change an inactive editable field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 (add-hook 'post-command-hook 'widget-add-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 (error "Attempt to change an inactive field"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 (widget-field-use-before-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 ;; #### Bletch! This loses because XEmacs get confused
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 ;; if before-change-functions change the contents of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 ;; buffer before from/to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 (widget-apply from-field :notify from-field)
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 724
diff changeset
1650 (error (declare-fboundp (debug "Before Change")))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 (defun widget-add-change ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 (make-local-hook 'post-command-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 (remove-hook 'post-command-hook 'widget-add-change t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 (make-local-hook 'before-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 (add-hook 'before-change-functions 'widget-before-change nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 (make-local-hook 'after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 (add-hook 'after-change-functions 'widget-after-change nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 (defun widget-after-change (from to old)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1661 "Adjust field size and text properties.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1662
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1663 Also, notify the widgets (so, for example, a variable changes its
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1664 state to `modified'. when it is being edited)."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 (let ((field (widget-field-find from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 (other (widget-field-find to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 (when field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 (unless (eq field other)
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 724
diff changeset
1670 (declare-fboundp (debug "Change in different fields")))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 (let ((size (widget-get field :size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 (when size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 (let ((begin (widget-field-start field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 (end (widget-field-end field)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 (cond ((< (- end begin) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 ;; Field too small.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 (insert-char ?\ (- (+ begin size) end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 ((> (- end begin) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 ;; Field too large and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 (if (or (< (point) (+ begin size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 (> (point) end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 ;; Point is outside extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 (setq begin (+ begin size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 ;; Point is within the extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 (setq begin (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 (while (and (eq (preceding-char) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 (> (point) begin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 (delete-backward-char 1)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 (widget-specify-secret field))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 (widget-apply field :notify field)))
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 724
diff changeset
1695 (error (declare-fboundp (debug "After Change")))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 ;;; Widget Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 ;; These functions are used in the definition of multiple widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 (defun widget-parent-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 "Tell :parent of WIDGET to handle the :action.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 Optional EVENT is the event that triggered the action."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 (widget-apply (widget-get widget :parent) :action event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 (defun widget-children-value-delete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 "Delete all :children and :buttons in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 (mapc 'widget-delete (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 (widget-put widget :children nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 (mapc 'widget-delete (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 (widget-put widget :buttons nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 (defun widget-children-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 "All the :children must be valid."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 child found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 found (widget-apply child :validate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1724 (defun widget-types-copy (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1725 "Copy :args as widget types in WIDGET."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1726 (widget-put widget :args (mapcar 'widget-copy (widget-get widget :args)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1727 widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1728
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1729 ;; Made defsubst to speed up face editor creation.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1730 (defsubst widget-types-convert-widget (widget)
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1731 "Convert each member of :args in WIDGET from a widget type to a widget."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 (defun widget-value-convert-widget (widget)
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1736 "Initialize :value from `(car :args)' in WIDGET, and reset :args."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 (let ((args (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 (when args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 (widget-put widget :value (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 ;; Don't convert :value here, as this is done in `widget-convert'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 ;; (widget-put widget :value (widget-apply widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 ;; :value-to-internal (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 (widget-put widget :args nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 (defun widget-value-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 "Return the :value property of WIDGET."
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 ;;; The `default' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 (define-widget 'default nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 "Basic widget other widgets are derived from."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 :value-to-internal (lambda (widget value) value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 :value-to-external (lambda (widget value) value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 :button-prefix 'widget-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 :button-suffix 'widget-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 :complete 'widget-default-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 :create 'widget-default-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 :indent nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 :offset 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 :format-handler 'widget-default-format-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 :button-face-get 'widget-default-button-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 :sample-face-get 'widget-default-sample-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 :button-keymap widget-button-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 :delete 'widget-default-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 :value-set 'widget-default-value-set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 :value-inline 'widget-default-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 :default-get 'widget-default-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 :menu-tag-get 'widget-default-menu-tag-get
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1771 :validate #'ignore
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 :active 'widget-default-active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 :activate 'widget-specify-active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 :deactivate 'widget-default-deactivate
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1775 :mouse-down-action #'ignore
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 :action 'widget-default-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 :notify 'widget-default-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 :prompt-value 'widget-default-prompt-value)
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-complete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 "Call the value of the :complete-function property of WIDGET.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 If that does not exists, call the value of `widget-complete-field'."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1783 (call-interactively (or (widget-get widget :complete-function)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1784 widget-complete-field)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 (defun widget-default-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 "Create WIDGET at point in the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 (let ((from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 button-begin button-end button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 sample-begin sample-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 doc-begin doc-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 value-pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 (insert (widget-get widget :format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 (goto-char from)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1796 ;; Parse escapes in format.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1797 ;; Coding this in C would speed up things *a lot*.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1798 ;; sjt sez:
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1799 ;; There are other things to try:
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1800 ;; 1. Use skip-chars-forward.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1801 ;; 2. Use a LIMIT (or narrow buffer?) in the search/skip expression.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1802 ;; 3. Search/skip backward to allow LIMIT to be constant.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 (while (re-search-forward "%\\(.\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 (replace-match "" t t)
1735
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1806 (funcall
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1807 (aref
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1808 [(lambda () ;?%
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1809 (insert ?%))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1810 (lambda () ;?\[
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1811 (setq button-begin (point-marker))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1812 (set-marker-insertion-type button-begin nil))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1813 (lambda () ;?\]
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1814 (setq button-end (point-marker))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1815 (set-marker-insertion-type button-end nil))
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
1816 (lambda () ;?\{
1735
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1817 (setq sample-begin (point)))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1818 (lambda () ;?\}
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1819 (setq sample-end (point)))
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
1820 (lambda () ;?n
1735
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1821 (when (widget-get widget :indent)
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1822 (insert ?\n)
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1823 (insert-char ?\ (widget-get widget :indent))))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1824 (lambda () ;?t
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1825 (let* ((tag (widget-get widget :tag))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1826 (glyph (widget-get widget :tag-glyph)))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1827 (cond (glyph
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1828 (setq button-glyph
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1829 (widget-glyph-insert
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1830 widget (or tag "Image") glyph)))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1831 (tag
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1832 (insert tag))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1833 (t
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1834 (princ (widget-get widget :value)
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1835 (current-buffer))))))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1836 (lambda () ;?d
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1837 (let ((doc (widget-get widget :doc)))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1838 (when doc
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1839 (setq doc-begin (point))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1840 (insert doc)
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1841 (while (eq (preceding-char) ?\n)
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1842 (delete-backward-char 1))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1843 (insert ?\n)
1735
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1844 (setq doc-end (point)))))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1845 (lambda () ;?v
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1846 (if (and button-begin (not button-end))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1847 (widget-apply widget :value-create)
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1848 (setq value-pos (point-marker))))
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1849 (lambda () ;otherwise
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1850 (widget-apply widget :format-handler escape))]
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1851 (string-match (format "[%c\010]" escape) ;^H can't be found in buff
c521eeaafa0d [xemacs-hg @ 2003-10-10 10:44:55 by stephent]
stephent
parents: 1376
diff changeset
1852 "%[]{}ntdv\010"))))) ;so it can be 'otherwise' cond
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 ;; Specify button, sample, and doc, and insert value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 (when (and button-begin button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 (unless button-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 (goto-char button-begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 (insert (widget-get-indirect widget :button-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 (goto-char button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 (set-marker-insertion-type button-end t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 (insert (widget-get-indirect widget :button-suffix)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 (widget-specify-button widget button-begin button-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 ;; Is this necessary?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 (set-marker button-begin nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 (set-marker button-end nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 (and sample-begin sample-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 (widget-specify-sample widget sample-begin sample-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 (and doc-begin doc-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 (widget-specify-doc widget doc-begin doc-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 (when value-pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 (goto-char value-pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 (widget-apply widget :value-create)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 (let ((from (point-min-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 (to (point-max-marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 (set-marker-insertion-type from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 (set-marker-insertion-type to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 (widget-put widget :from from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 (widget-put widget :to to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 (widget-clear-undo))
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-format-handler (widget escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 ;; We recognize the %h escape by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 (let* ((buttons (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 (cond ((eq escape ?h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 (let* ((doc-property (widget-get widget :documentation-property))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 (doc-try (cond ((widget-get widget :doc))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1886 ((functionp doc-property)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1887 (funcall doc-property
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1888 (widget-get widget :value)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 ((symbolp doc-property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 (documentation-property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 (widget-get widget :value)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1892 doc-property))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 (doc-text (and (stringp doc-try)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 (> (length doc-try) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 doc-try))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 (doc-indent (widget-get widget :documentation-indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 (when doc-text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 ;; The `*' in the beginning is redundant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 (when (eq (aref doc-text 0) ?*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 (setq doc-text (substring doc-text 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 ;; Get rid of trailing newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 (when (string-match "\n+\\'" doc-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 (setq doc-text (substring doc-text 0 (match-beginning 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 (push (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 widget 'documentation-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 :indent (cond ((numberp doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 ((null doc-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 (t 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 doc-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 buttons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 (signal 'error (list "Unknown escape" escape))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 (widget-put widget :buttons buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 (defun widget-default-button-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 ;; Use :button-face or widget-button-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 (or (widget-get widget :button-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (if parent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 (widget-apply parent :button-face-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 widget-button-face))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1928 ;; Shouldn't this be like `widget-default-button-face-get', and recurse, and
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1929 ;; have a fallback?
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 (defun widget-default-sample-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 ;; Use :sample-face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 (widget-get widget :sample-face))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 (defun widget-default-delete (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1935 "Remove widget from the buffer."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 (let ((from (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 (to (widget-get widget :to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 (inactive-extent (widget-get widget :inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 (button-extent (widget-get widget :button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 (sample-extent (widget-get widget :sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 (doc-extent (widget-get widget :doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 after-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 (inhibit-read-only t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 (widget-apply widget :value-delete)
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1946 ;; #### In current code, these are never reinserted, but recreated.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1947 ;; So they should either be destroyed, or we should think about how to
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
1948 ;; reuse them.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 (when inactive-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 (detach-extent inactive-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 (when button-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 (detach-extent button-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 (when sample-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 (detach-extent sample-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 (when doc-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 (detach-extent doc-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 (when (< from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 ;; Kludge: this doesn't need to be true for empty formats.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 (delete-region from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 (set-marker from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 (set-marker to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 (widget-clear-undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 (defun widget-default-value-set (widget value)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1965 "Recreate widget with new value."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 (let* ((old-pos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 (from (copy-marker (widget-get widget :from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 (to (copy-marker (widget-get widget :to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 (offset (if (and (<= from old-pos) (<= old-pos to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 (if (>= old-pos (1- to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 (- old-pos to 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 (- old-pos from)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 ;;??? 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
1974 ;; so that markers on either side of the value automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 ;; stay on the same side. -- rms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 (goto-char (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 (widget-apply widget :delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 (widget-put widget :value value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 (widget-apply widget :create))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1981 (if offset
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1982 (if (< offset 0)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1983 (goto-char (+ (widget-get widget :to) offset 1))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
1984 (goto-char (min (+ from offset) (1- (widget-get widget :to))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 (defun widget-default-value-inline (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1987 "Wrap value in a list unless it is inline."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 (if (widget-get widget :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 (list (widget-value widget))))
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 (defun widget-default-default-get (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1993 "Get `:value'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 (defun widget-default-menu-tag-get (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
1997 "Use tag or value for menus."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 (or (widget-get widget :menu-tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 (widget-get widget :tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 (widget-princ-to-string (widget-get widget :value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 (defun widget-default-active (widget)
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2003 "Return non-nil iff WIDGET is user-modifiable."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 (and (not (widget-get widget :inactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 (or (null parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 (widget-apply parent :active)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 (defun widget-default-deactivate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 "Make WIDGET inactive for user modifications."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 (widget-specify-inactive widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 (widget-get widget :from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 (widget-get widget :to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 (defun widget-default-action (widget &optional event)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2016 "Notify the parent when a widget changes."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 (when parent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 (widget-apply parent :notify widget event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 (defun widget-default-notify (widget child &optional event)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2022 "Pass notification to parent."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 (widget-default-action widget event))
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-default-prompt-value (widget prompt value unbound)
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2026 "Read an arbitrary value."
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2027 ;; #### XEmacs: What does this mean?
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2028 ;; Stolen from `set-variable'.
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2029 ;; (let ((initial (if unbound
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2030 ;; nil
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2031 ;; It would be nice if we could do a `(cons val 1)' here.
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2032 ;; (prin1-to-string (custom-quote value))))))
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2033 ;; XEmacs: make this use default VALUE. Need to check callers.
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2034 (eval-minibuffer (concat prompt ": ")))
428
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 ;;; The `item' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 (define-widget 'item 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 "Constant items for inclusion in other widgets."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 :convert-widget 'widget-value-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 :value-create 'widget-item-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 :value-delete 'ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 :value-get 'widget-value-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 :match 'widget-item-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 :match-inline 'widget-item-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 :action 'widget-item-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 :format "%t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 (defun widget-item-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2050 "Insert the printed representation of the value."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2051 (princ (widget-get widget :value) (current-buffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 (defun widget-item-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 ;; Match if the value is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 (equal (widget-get widget :value) value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 (defun widget-item-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 ;; Match if the value is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 (let ((value (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 (and (listp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 (<= (length value) (length values))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 (let ((head (widget-sublist values 0 (length value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 (and (equal head value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 (cons head (widget-sublist values (length value))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 (defun widget-item-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 ;; Just notify itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 (widget-apply widget :notify widget event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 ;;; The `push-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2072 ;; XEmacs: this seems to refer to button images. How about native widgets?
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 (defcustom widget-push-button-gui widget-glyph-enable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 "If non nil, use GUI push buttons when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 :group 'widgets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 :type 'boolean)
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 (defcustom widget-push-button-prefix "["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 "String used as prefix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 (defcustom widget-push-button-suffix "]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 "String used as suffix for buttons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 :group 'widget-button)
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 (define-widget 'push-button 'item
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2089 "A button which invokes an action.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2090
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2091 Creators should usually specify `:action' and `:help-echo' members."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 :value-create 'widget-push-button-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 :format "%[%v%]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 (defun widget-push-button-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2098 "Insert text representing the `on' and `off' states."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 (let* ((tag (or (widget-get widget :tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 (tag-glyph (widget-get widget :tag-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 (text (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 tag widget-push-button-suffix))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
2104 gui inst)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 (cond (tag-glyph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 (widget-glyph-insert widget text tag-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107 ;; We must check for console-on-window-system-p here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 ;; because GUI will not work otherwise (it needs RGB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 ;; components for colors, and they are not known on TTYs).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 ((and widget-push-button-gui
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 (console-on-window-system-p))
436
080151679be2 Import from CVS: tag r21-2-26
cvs
parents: 428
diff changeset
2112 (let* ((gui-button-shadow-thickness 1))
454
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
2113 (setq inst (make-gui-button tag 'widget-gui-action widget))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
2114 (setq gui (make-glyph inst)))
d7a9135ec789 Import from CVS: tag r21-2-42
cvs
parents: 446
diff changeset
2115 (widget-glyph-insert-glyph widget gui nil nil inst))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117 (insert text)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 (defun widget-gui-action (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 "Apply :action for WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 (widget-apply-action widget (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 ;;; The `link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 (defcustom widget-link-prefix "["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 "String used as prefix for links."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 :group 'widget-button)
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 (defcustom widget-link-suffix "]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 "String used as suffix for links."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 :group 'widget-button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 (define-widget 'link 'item
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2136 "An embedded link.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2137
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2138 This is an abstract widget. Subclasses should usually specify `:action'
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2139 and `:help-echo' members."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 :button-prefix 'widget-link-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 :button-suffix 'widget-link-suffix
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2142 :help-echo "Follow the link."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 :format "%[%t%]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 ;;; The `info-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 (define-widget 'info-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 "A link to an info file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 :help-echo 'widget-info-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 :action 'widget-info-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 (defun widget-info-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 (concat "Read the manual entry `" (widget-value widget) "'"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 (defun widget-info-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 "Open the info node specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 (Info-goto-node (widget-value 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 ;;; The `url-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 (define-widget 'url-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 "A link to an www page."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 :help-echo 'widget-url-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 :action 'widget-url-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 (defun widget-url-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 (concat "Visit <URL:" (widget-value widget) ">"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 (defun widget-url-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 "Open the url specified by WIDGET."
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1873
diff changeset
2171 (if-fboundp 'browse-url
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2172 (browse-url (widget-value widget))
1376
2e0147538471 [xemacs-hg @ 2003-03-24 14:51:45 by stephent]
stephent
parents: 1362
diff changeset
2173 (error 'missing-package "Cannot browse URLs in this XEmacs" 'browse-url)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 ;;; The `function-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 (define-widget 'function-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 "A link to an Emacs function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 :action 'widget-function-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 (defun widget-function-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 "Show the function specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 (describe-function (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 ;;; The `variable-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 (define-widget 'variable-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 "A link to an Emacs variable."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 :action 'widget-variable-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 (defun widget-variable-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 "Show the variable specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 (describe-variable (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 ;;; The `file-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 (define-widget 'file-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 "A link to a file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 :action 'widget-file-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 (defun widget-file-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 "Find the file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 (find-file (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 ;;; The `emacs-library-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 (define-widget 'emacs-library-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 "A link to an Emacs Lisp library file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 :help-echo 'widget-emacs-library-link-help-echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 :action 'widget-emacs-library-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 (defun widget-emacs-library-link-help-echo (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 (concat "Visit " (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 (defun widget-emacs-library-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 "Find the Emacs Library file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 (find-file (locate-library (widget-value widget))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 ;;; The `emacs-commentary-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 (define-widget 'emacs-commentary-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 "A link to Commentary in an Emacs Lisp library file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 :action 'widget-emacs-commentary-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 (defun widget-emacs-commentary-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 "Find the Commentary section of the Emacs file specified by WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 (finder-commentary (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 ;;; The `editable-field' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 (define-widget 'editable-field 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 "An editable text field."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 :convert-widget 'widget-value-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 :keymap widget-field-keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 :format "%v"
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2236 :help-echo "M-TAB: complete field; RET: enter value"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 :value ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 :prompt-internal 'widget-field-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 :prompt-history 'widget-field-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 :prompt-value 'widget-field-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 :action 'widget-field-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 :validate 'widget-field-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 :valid-regexp ""
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2244 :error "Field's value doesn't match allowed forms"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 :value-create 'widget-field-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 :value-delete 'widget-field-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 :value-get 'widget-field-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 :match 'widget-field-match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 (defvar widget-field-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 "History of field minibuffer edits.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 (defun widget-field-prompt-internal (widget prompt initial history)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2254 "Read string for WIDGET prompting with PROMPT.
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2255 INITIAL is the initial input and HISTORY is a symbol containing
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2256 the earlier input."
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2257 (read-string (concat prompt ": ") initial history))
428
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-field-prompt-value (widget prompt value unbound)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2260 "Prompt for a string."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2261 (widget-apply widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2262 :value-to-external
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2263 (widget-apply widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2264 :prompt-internal prompt
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2265 (unless unbound
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2266 (cons (widget-apply widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2267 :value-to-internal value)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2268 0))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2269 (widget-get widget :prompt-history))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2271 ;; #### Should be named `widget-action-hooks'.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2272 (defvar widget-edit-functions nil
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2273 "Functions run on certain actions.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2274
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2275 Not a regular hook; each function should take a widget as an argument.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2276 The standard widget functions `widget-field-action', `widget-choice-action',
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2277 and `widget-toggle-action' use `run-hook-with-args' to run these functions.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 (defun widget-field-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 ;; Edit the value in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 (let* ((invalid (widget-apply widget :validate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 (prompt (concat (widget-apply widget :menu-tag-get) ": "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 (value (unless invalid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 (answer (widget-apply widget :prompt-value prompt value invalid)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 (unless (equal value answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 ;; This is a hack. We can't properly validate the widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 ;; because validation requires the new value to be in the field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 ;; However, widget-field-value-create will not function unless
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 ;; the new value matches. So, we check whether the thing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 ;; 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
2292 ;; message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 (unless (widget-apply widget :match answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 (let ((error-message (or (widget-get widget :type-error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 "Invalid field contents")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 (widget-put widget :error error-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 (error error-message)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 (widget-setup))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 (run-hook-with-args 'widget-edit-functions widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 ;(defun widget-field-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 ; ;; Move to next field.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 ; (widget-forward 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 ; (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 (defun widget-field-validate (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2309 "Valid if the content matches `:valid-regexp'."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2310 (save-excursion ; XEmacs
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2311 (unless (string-match (widget-get widget :valid-regexp)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2312 (widget-apply widget :value-get))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2313 widget)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 (defun widget-field-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2316 "Create an editable text field."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 (let ((size (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 (value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 ;; This is changed to a real extent in `widget-setup'. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 ;; need the end points to behave differently until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 ;; `widget-setup' is called. Should probably be replaced with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 ;; a genuine extent, but some things break, then.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 (extent (cons (make-marker) (make-marker))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 (widget-put widget :field-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 (insert value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 (and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 (< (length value) size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 (insert-char ?\ (- size (length value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 (unless (memq widget widget-field-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 (push widget widget-field-new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 (move-marker (cdr extent) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 (set-marker-insertion-type (cdr extent) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 (when (null size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 (insert ?\n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 (move-marker (car extent) from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 (set-marker-insertion-type (car extent) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 (defun widget-field-value-delete (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2340 "Remove the widget from the list of active editing fields."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 (setq widget-field-list (delq widget widget-field-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 ;; These are nil if the :format string doesn't contain `%v'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 (let ((extent (widget-get widget :field-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 (when extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 (detach-extent extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 (defun widget-field-value-get (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2348 "Return current text in editing field."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 (let ((from (widget-field-start widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 (to (widget-field-end widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 (buffer (widget-field-buffer widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 (size (widget-get widget :size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 (secret (widget-get widget :secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 (old (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 ((and from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 (while (and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 (not (zerop size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 (> to from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 (eq (char-after (1- to)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 (setq to (1- to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 (let ((result (buffer-substring-no-properties from to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 (when secret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 (let ((index 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 (while (< (+ from index) to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 (aset result index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 (get-char-property (+ from index) 'secret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 (incf index))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 (set-buffer old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 (widget-get widget :value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 (defun widget-field-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 ;; Match any string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 (stringp value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 ;;; The `text' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 (define-widget 'text 'editable-field
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2382 "A multiline text area."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2383 :keymap widget-text-keymap)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 ;;; The `menu-choice' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 (define-widget 'menu-choice 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 "A menu of options."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 :format "%[%t%]: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 :case-fold t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 :tag "choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 :void '(item :format "invalid (%t)\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 :value-create 'widget-choice-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 :value-get 'widget-choice-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 :value-inline 'widget-choice-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 :default-get 'widget-choice-default-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 :mouse-down-action 'widget-choice-mouse-down-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 :action 'widget-choice-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 :error "Make a choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 :validate 'widget-choice-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 :match 'widget-choice-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 :match-inline 'widget-choice-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 (defun widget-choice-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2407 "Insert the first choice that matches the value."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 (let ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 (args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 (explicit (widget-get widget :explicit-choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 (if explicit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 (progn
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2414 ;; If the user specified the choice for this value,
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2415 ;; respect that choice as long as the value is the same.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 (widget-put widget :children (list (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 widget explicit value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 (widget-put widget :choice explicit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 (when (widget-apply current :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 (widget-put widget :children (list (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 widget current value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 (widget-put widget :choice current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 (setq args nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 current nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 (when current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 (let ((void (widget-get widget :void)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 (widget-put widget :children (list (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 widget void :value value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 (widget-put widget :choice void))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 (defun widget-choice-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 (widget-value (car (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 (defun widget-choice-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 (widget-apply (car (widget-get widget :children)) :value-inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 (defun widget-choice-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 ;; Get default for the first choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 (widget-default-get (car (widget-get widget :args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 (defcustom widget-choice-toggle nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 "If non-nil, a binary choice will just toggle between the values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 Otherwise, the user will explicitly have to choose between the values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 when he invoked the menu."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 (defun widget-choice-mouse-down-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 ;; Return non-nil if we need a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 (old (widget-get widget :choice)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 (cond ((not (console-on-window-system-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 ;; No place to pop up a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 ((< (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 ;; Empty or singleton list, just return the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 ((> (length args) widget-menu-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 ;; Too long, prompt.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 ((> (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 ;; Reasonable sized list, use menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 ((and widget-choice-toggle (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 ;; We toggle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 ;; Ask which of the two.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 (defun widget-choice-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 ;; Make a choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 (old (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 (tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 (completion-ignore-case (widget-get widget :case-fold))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 current choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 ;; Remember old value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 (if (and old (not (widget-apply widget :validate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 (let* ((external (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 (internal (widget-apply old :value-to-internal external)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 (widget-put old :value internal)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 ;; Find new choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 (setq current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 (cond ((= (length args) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 ((= (length args) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 ((and widget-choice-toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 (= (length args) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 (memq old args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 (if (eq old (nth 0 args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 (nth 1 args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 (nth 0 args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 (setq choices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 (cons (cons (widget-apply current :menu-tag-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 (let ((choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 (widget-choose tag (reverse choices) event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 (widget-put widget :explicit-choice choice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 choice))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 (when current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 (let ((value (widget-default-get current)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 (widget-value-set widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 (widget-apply current :value-to-external value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 (widget-apply widget :notify widget event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 (run-hook-with-args 'widget-edit-functions widget))
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-choice-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 ;; Valid if we have made a valid choice.
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2522 (if (eq (widget-get widget :void) (widget-get widget :choice))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2523 widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2524 (widget-apply (car (widget-get widget :children)) :validate)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 (defun widget-choice-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 ;; Matches if one of the choices matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 (while (and args (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 found (widget-apply current :match value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 (defun widget-choice-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 ;; Matches if one of the choices matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 (while (and args (null found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 found (widget-match-inline current values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 ;;; The `toggle' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 (define-widget 'toggle 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 "Toggle between two states."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 :format "%[%v%]\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 :value-create 'widget-toggle-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 :action 'widget-toggle-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 :match (lambda (widget value) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 :on "on"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 :off "off")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 (defun widget-toggle-value-create (widget)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2558 "Insert text representing the `on' and `off' states."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 (widget-glyph-insert widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 (widget-get widget :on)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 (widget-get widget :on-glyph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 (widget-glyph-insert widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 (widget-get widget :off)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 (widget-get widget :off-glyph))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 (defun widget-toggle-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 ;; Toggle value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 (widget-value-set widget (not (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 (widget-apply widget :notify widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 (run-hook-with-args 'widget-edit-functions widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 ;;; The `checkbox' Widget.
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 (define-widget 'checkbox 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 "A checkbox toggle."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 :on "[X]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 :on-glyph "check1"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 :off "[ ]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 :off-glyph "check0"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 :action 'widget-checkbox-action)
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-checkbox-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 "Toggle checkbox, notify parent, and set active state of sibling."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 (widget-toggle-action widget event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 (let ((sibling (widget-get-sibling widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 (when sibling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 (widget-apply sibling :activate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 (widget-apply sibling :deactivate)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 ;;; The `checklist' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 (define-widget 'checklist 'default
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2598 "A set widget, selecting zero or more of many.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2599
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2600 The parent of several `checkbox' widgets, one for each option."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 :offset 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 :entry-format "%b %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 :menu-tag "checklist"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 :greedy nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 :value-create 'widget-checklist-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 :value-get 'widget-checklist-value-get
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2610 :prompt-value 'widget-checklist-prompt-value
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 :validate 'widget-checklist-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 :match 'widget-checklist-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 :match-inline 'widget-checklist-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 (defun widget-checklist-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 (args (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 (widget-checklist-add-item widget (car args) (assq (car args) alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 (widget-put widget :children (nreverse (widget-get widget :children)))))
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-checklist-add-item (widget type chosen)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2625 "Create checklist item in WIDGET of type TYPE.
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2626 If the item is checked, CHOSEN is a cons whose cdr is the value."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 (let* ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 (button-args (or (widget-get type :sibling-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 (widget-get widget :button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 (insert (widget-get widget :entry-format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 (while (re-search-forward "%\\([bv%]\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 (cond ((eq escape ?%)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2644 (insert ?%))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 ((eq escape ?b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 (setq button (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 widget 'checkbox
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 :value (not (null chosen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 (setq child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 (cond ((not chosen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 (let ((child (widget-create-child widget type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 (widget-apply child :deactivate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 ((widget-get type :inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 widget type (cdr chosen)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 widget type (car (cdr chosen)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 ;; Update properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 (and button child (widget-put child :button button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 (and button (widget-put widget :buttons (cons button buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 (and child (widget-put widget :children (cons child children))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 (defun widget-checklist-match (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 ;; All values must match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 (and (listp values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 (null (cdr (widget-checklist-match-inline widget values)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 (defun widget-checklist-match-inline (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 ;; Find the values which match a type in the checklist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 (let ((greedy (widget-get widget :greedy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 (args (copy-sequence (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 found rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 (while values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 (let ((answer (widget-checklist-match-up args values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 (cond (answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 (let ((vals (widget-match-inline answer values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 (setq found (append found (car vals))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 values (cdr vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 args (delq answer args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 (greedy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 (setq rest (append rest (list (car values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 values (cdr values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 (setq rest (append rest values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 values nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 (cons found rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 (defun widget-checklist-match-find (widget vals)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2695 "Find the vals which match a type in the checklist.
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2696 Return an alist of (TYPE MATCH)."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 (let ((greedy (widget-get widget :greedy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 (args (copy-sequence (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 (while vals
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 (let ((answer (widget-checklist-match-up args vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 (cond (answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 (let ((match (widget-match-inline answer vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 (setq found (cons (cons answer (car match)) found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 vals (cdr match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 args (delq answer args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 (greedy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 (setq vals (cdr vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 (setq vals nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 (defun widget-checklist-match-up (args vals)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2714 "Return the first type from ARGS that matches VALS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 (let (current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 (while (and args (null found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 (setq current (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 found (widget-match-inline current vals)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 (if found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 nil)))
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-checklist-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 ;; The values of all selected items.
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 child result)
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 child (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 (if (widget-value (widget-get child :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 (setq result (append result (widget-apply child :value-inline)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2735 ;; #### FIXME: should handle default value some day -- dvl
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2736 (defun widget-checklist-prompt-value (widget prompt value unbound)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2737 ;; Prompt for items to be selected, and the prompt for their value
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2738 (let* ((args (widget-get widget :args))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2739 (choices (mapcar (lambda (elt)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2740 (cons (widget-get elt :tag) elt))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2741 args))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2742 (continue t)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2743 value)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2744 (while continue
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2745 (setq continue (completing-read
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2746 (concat (widget-prompt-spaceify prompt)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2747 "select [ret. when done]: ")
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2748 choices nil t))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2749 (if (string= continue "")
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2750 (setq continue nil)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2751 (push (widget-prompt-value (cdr (assoc continue choices))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2752 prompt nil t)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2753 value)))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2754 (nreverse value)))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
2755
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 (defun widget-checklist-validate (widget)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2757 ;; Ticked children must be valid.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 child button found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 (setq child (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 button (widget-get child :button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 found (and (widget-value button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 (widget-apply child :validate))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 ;;; The `option' Widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 (define-widget 'option 'checklist
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2771 "A widget presenting optional items for inline inclusion in a parent widget."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 :inline t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 ;;; The `choice-item' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 (define-widget 'choice-item 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 "Button items that delegate action events to their parents."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 :action 'widget-parent-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 :format "%[%t%] \n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 ;;; The `radio-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 (define-widget 'radio-button 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 "A radio button for use in the `radio' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 :notify 'widget-radio-button-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 :on "(*)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 :on-glyph '("radio1" nil "radio0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 :off "( )"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 :off-glyph "radio0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 (defun widget-radio-button-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 ;; Tell daddy.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 (widget-apply (widget-get widget :parent) :action widget event))
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 ;;; The `radio-button-choice' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 (define-widget 'radio-button-choice 'default
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2801 "A set widget, selecting exactly one of many options.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2802
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
2803 The parent of several `radio-button' widgets, one for each option."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 :offset 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 :entry-format "%b %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 :menu-tag "radio"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 :value-create 'widget-radio-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 :value-get 'widget-radio-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 :value-inline 'widget-radio-value-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 :value-set 'widget-radio-value-set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 :error "You must push one of the buttons"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 :validate 'widget-radio-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 :match 'widget-choice-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 :match-inline 'widget-choice-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 :action 'widget-radio-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 (defun widget-radio-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 (setq arg (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 args (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 (widget-radio-add-item widget arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 (defun widget-radio-add-item (widget type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 "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
2831 ;; (setq type (widget-convert type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 (let* ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 (children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 (button-args (or (widget-get type :sibling-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 (widget-get widget :button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 (from (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 (chosen (and (null (widget-get widget :choice))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 (widget-apply type :match value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 (insert (widget-get widget :entry-format))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 (while (re-search-forward "%\\([bv%]\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 (cond ((eq escape ?%)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2852 (insert ?%))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 ((eq escape ?b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 (setq button (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 widget 'radio-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 :value (not (null chosen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 (setq child (if chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 widget type value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 (widget-create-child widget type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 (unless chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 (widget-apply child :deactivate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 ;; Update properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 (when chosen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 (widget-put widget :choice type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 (when button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 (widget-put child :button button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 (widget-put widget :buttons (nconc buttons (list button))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 (when child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 (widget-put widget :children (nconc children (list child))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 (defun widget-radio-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 (let ((chosen (widget-radio-chosen widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 (and chosen (widget-value chosen))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 (defun widget-radio-chosen (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 "Return the widget representing the chosen radio button."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 children (cdr children))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2889 (when (widget-apply (widget-get current :button) :value-get)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2890 (setq found current
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2891 children nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 (defun widget-radio-value-inline (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 children (cdr children))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2901 (when (widget-apply (widget-get current :button) :value-get)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2902 (setq found (widget-apply current :value-inline)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
2903 children nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 (defun widget-radio-value-set (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 ;; We can't just delete and recreate a radio widget, since children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 ;; can be added after the original creation and won't be recreated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 ;; by `:create'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 current found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 (let* ((button (widget-get current :button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 (match (and (not found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 (widget-apply current :match value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 (widget-value-set button match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 (if match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 (widget-value-set current value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 (widget-apply current :activate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 (widget-apply current :deactivate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 (setq found (or found match))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 (defun widget-radio-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 ;; Valid if we have made a valid choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 current found button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 (while (and children (not found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 children (cdr children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 button (widget-get current :button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 found (widget-apply button :value-get)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 (if found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 (widget-apply current :validate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 (defun widget-radio-action (widget child event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 ;; Check if a radio button was pressed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 (buttons (widget-get widget :buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 (when (memq child buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 (while children
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 (setq current (car children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 children (cdr children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 (let* ((button (widget-get current :button)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 (cond ((eq child button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 (widget-value-set button t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 (widget-apply current :activate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 ((widget-value button)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 (widget-value-set button nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 (widget-apply current :deactivate)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 ;; Pass notification to parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 (widget-apply widget :notify child event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 ;;; The `insert-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 (define-widget 'insert-button 'push-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 "An insert button for the `editable-list' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 :tag "INS"
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2963 :help-echo "Insert a new item into the list at this position."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 :action 'widget-insert-button-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 (defun widget-insert-button-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 ;; Ask the parent to insert a new item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 (widget-apply (widget-get widget :parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 :insert-before (widget-get widget :widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 ;;; The `delete-button' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 (define-widget 'delete-button 'push-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 "A delete button for the `editable-list' widget."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 :tag "DEL"
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
2976 :help-echo "Delete this item from the list."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 :action 'widget-delete-button-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 (defun widget-delete-button-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 ;; Ask the parent to insert a new item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 (widget-apply (widget-get widget :parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 :delete-at (widget-get widget :widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 ;;; The `editable-list' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 (defcustom widget-editable-list-gui nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 "If non nil, use GUI push-buttons in editable list when available."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 :group 'widgets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 (define-widget 'editable-list 'default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 "A variable list of widgets of the same type."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 :offset 12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 :format "%v%i\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 :format-handler 'widget-editable-list-format-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 :entry-format "%i %d %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 :menu-tag "editable-list"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 :value-create 'widget-editable-list-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 :value-get 'widget-editable-list-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 :validate 'widget-children-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 :match 'widget-editable-list-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 :match-inline 'widget-editable-list-match-inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 :insert-before 'widget-editable-list-insert-before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 :delete-at 'widget-editable-list-delete-at)
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-editable-list-format-handler (widget escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 ;; We recognize the insert button.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 (let ((widget-push-button-gui widget-editable-list-gui))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 (cond ((eq escape ?i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 (and (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 widget 'insert-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 (widget-get widget :append-button-args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 (widget-default-format-handler widget escape)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 (defun widget-editable-list-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 ;; Insert all values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 (let* ((value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 (type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 (widget-put widget :value-pos (copy-marker (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 (set-marker-insertion-type (widget-get widget :value-pos) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 (while value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 (let ((answer (widget-match-inline type value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 (setq children (cons (widget-editable-list-entry-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 widget
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3032 (if (widget-get type :inline)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 (car answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 (car (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 (setq value nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 (widget-put widget :children (nreverse children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 (defun widget-editable-list-value-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 ;; Get value of the child widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 (defun widget-editable-list-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 ;; 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
3048 (and (listp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 (null (cdr (widget-editable-list-match-inline widget value)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 (defun widget-editable-list-match-inline (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 (let ((type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 (ok t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 (while (and value ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 (let ((answer (widget-match-inline type value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 (setq found (append found (car answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 (setq ok nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 (cons found value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 (defun widget-editable-list-insert-before (widget before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 ;; Insert a new child in the list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 (let ((children (widget-get widget :children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 (cond (before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 (goto-char (widget-get before :entry-from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 (goto-char (widget-get widget :value-pos))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 (let ((child (widget-editable-list-entry-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 widget nil nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 (when (< (widget-get child :entry-from) (widget-get widget :from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 (set-marker (widget-get widget :from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 (widget-get child :entry-from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 (if (eq (car children) before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 (widget-put widget :children (cons child children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 (while (not (eq (car (cdr children)) before))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 (setq children (cdr children)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 (setcdr children (cons child (cdr children)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 (widget-apply widget :notify widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087 (defun widget-editable-list-delete-at (widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 ;; Delete child from list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 (let ((buttons (copy-sequence (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 (while buttons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 (setq button (car buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 buttons (cdr buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 (when (eq (widget-get button :widget) child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 :buttons (delq button (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 (widget-delete button))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 (let ((entry-from (widget-get child :entry-from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 (entry-to (widget-get child :entry-to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104 (inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 after-change-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 (widget-delete child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 (delete-region entry-from entry-to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 (set-marker entry-from nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 (set-marker entry-to nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 (widget-put widget :children (delq child (widget-get widget :children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 (widget-apply widget :notify widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 (defun widget-editable-list-entry-create (widget value conv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 ;; Create a new entry to the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 (let ((type (nth 0 (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 (widget-push-button-gui widget-editable-list-gui)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 child delete insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 (widget-specify-insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 (and (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 (insert (widget-get widget :entry-format)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 ;; Parse % escapes in format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 (while (re-search-forward "%\\(.\\)" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 (let ((escape (aref (match-string 1) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 (replace-match "" t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 (cond ((eq escape ?%)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3130 (insert ?%))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 ((eq escape ?i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 (setq insert (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 widget 'insert-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 (widget-get widget :insert-button-args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 ((eq escape ?d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 (setq delete (apply 'widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 widget 'delete-button
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138 (widget-get widget :delete-button-args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 ((eq escape ?v)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 (if conv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 (setq child (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 widget type value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 (setq child (widget-create-child-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 widget type (widget-default-get type)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 (signal 'error (list "Unknown escape" escape))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 (widget-put widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 :buttons (cons delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 (cons insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 (widget-get widget :buttons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 (let ((entry-from (copy-marker (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 (entry-to (copy-marker (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 (set-marker-insertion-type entry-from t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 (set-marker-insertion-type entry-to nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 (widget-put child :entry-from entry-from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 (widget-put child :entry-to entry-to)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 (widget-put insert :widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158 (widget-put delete :widget child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 ;;; The `group' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 (define-widget 'group 'default
652
2cf5d151eeb9 [xemacs-hg @ 2001-08-26 10:25:11 by stephent]
stephent
parents: 454
diff changeset
3164 "A widget which groups other widgets inside."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165 :convert-widget 'widget-types-convert-widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 :value-create 'widget-group-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 :value-get 'widget-editable-list-value-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 :default-get 'widget-group-default-get
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3171 :prompt-value 'widget-group-prompt-value
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 :validate 'widget-children-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 :match 'widget-group-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 :match-inline 'widget-group-match-inline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 (defun widget-group-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 ;; Create each component.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 (value (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180 arg answer children)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 (setq arg (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 answer (widget-match-inline arg value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 value (cdr answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 (and (eq (preceding-char) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 (widget-get widget :indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 (insert-char ?\ (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 (push (cond ((null answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 (widget-create-child widget arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 ((widget-get arg :inline)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3192 (widget-create-child-value widget arg (car answer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 (t
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3194 (widget-create-child-value widget arg (car (car answer)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 children))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 (widget-put widget :children (nreverse children))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 (defun widget-group-default-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 ;; Get the default of the components.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 (mapcar 'widget-default-get (widget-get widget :args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3202 (defun widget-group-prompt-value (widget prompt value unbound)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3203 ;; Prompt in turn for every component of the group.
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3204 (let ((args (widget-get widget :args)))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3205 (widget-apply
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3206 widget :value-to-external
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3207 (if unbound
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3208 (mapcar #'(lambda (arg)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3209 (widget-prompt-value
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3210 arg
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3211 (concat (widget-prompt-spaceify prompt)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3212 (widget-prompt arg nil ""))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3213 nil t))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3214 args)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3215 ;; If VALUE is bound, the situation is a bit more complex because we
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3216 ;; have to split it into a list of default values for every child. Oh,
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3217 ;; boy, do I miss 'cl here... -- dvl
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3218 (let ((children args)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3219 (defaults (widget-apply widget
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3220 :value-to-internal value))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3221 child default result)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3222 (while (setq child (pop children))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3223 (setq default (pop defaults))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3224 (push
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3225 (widget-prompt-value
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3226 child
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3227 (concat (widget-prompt-spaceify prompt)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3228 (widget-prompt child nil ""))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3229 default) result))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3230 (nreverse result))))))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3231
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 (defun widget-group-match (widget values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 ;; Match if the components match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 (and (listp values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 (let ((match (widget-group-match-inline widget values)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 (and match (null (cdr match))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 (defun widget-group-match-inline (widget vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 ;; Match if the components match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 argument answer found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 (setq argument (car args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 args (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 answer (widget-match-inline argument vals))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 (setq vals (cdr answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 found (append found (car answer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 (setq vals nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 args nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 (if answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 (cons found vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 ;;; The `visibility' Widget.
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 (define-widget 'visibility 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 "An indicator and manipulator for hidden items."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 :format "%[%v%]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 :button-prefix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 :button-suffix ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 :on "Hide"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 :off "Show"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 :value-create 'widget-visibility-value-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 :action 'widget-toggle-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 :match (lambda (widget value) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 (defun widget-visibility-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 ;; Insert text representing the `on' and `off' states.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 (let ((on (widget-get widget :on))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 (off (widget-get widget :off)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 (if on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 (setq on (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 widget-push-button-suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 (setq on ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 (if off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 (setq off (concat widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 widget-push-button-suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 (setq off ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 (widget-glyph-insert widget on '("down" "down-pushed"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 (widget-glyph-insert widget off '("right" "right-pushed")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 ;;; The `documentation-link' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 ;; This is a helper widget for `documentation-string'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 (define-widget 'documentation-link 'link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 "Link type used in documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 :tab-order -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 :help-echo 'widget-documentation-link-echo-help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 :action 'widget-documentation-link-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 (defun widget-documentation-link-echo-help (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 "Tell what this link will describe."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 (concat "Describe the `" (widget-get widget :value) "' symbol."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 (defun widget-documentation-link-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 "Display documentation for WIDGET's value. Ignore optional argument EVENT."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 (let* ((string (widget-get widget :value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303 (symbol (intern string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304 (if (and (fboundp symbol) (boundp symbol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 ;; 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
3306 (apropos (concat "\\`" (regexp-quote string) "\\'"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 (if (fboundp symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 (describe-function symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 (describe-variable symbol)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 (defcustom widget-documentation-links t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 "Add hyperlinks to documentation strings when non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 (defcustom widget-documentation-link-regexp "`\\([^\n`' ]+\\)'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 "Regexp for matching potential links in documentation strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 The first group should be the link itself."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 :type 'regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 (defcustom widget-documentation-link-p 'intern-soft
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 "Predicate used to test if a string is useful as a link.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 The value should be a function. The function will be called one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 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
3326 link for that string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 :options '(widget-documentation-link-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 (defcustom widget-documentation-link-type 'documentation-link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 "Widget type used for links in documentation strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 :type 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 :group 'widget-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 (defun widget-documentation-link-add (widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 (widget-specify-doc widget from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 (when widget-documentation-links
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 (let ((regexp widget-documentation-link-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 (predicate widget-documentation-link-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 (type widget-documentation-link-type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 (buttons (widget-get widget :buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345 (while (re-search-forward regexp to t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 (let ((name (match-string 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 (begin (match-beginning 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 (end (match-end 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 (when (funcall predicate name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 (push (widget-convert-button type begin end :value name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 buttons)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 (widget-put widget :buttons buttons)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 (let ((indent (widget-get widget :indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 (when (and indent (not (zerop indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 (narrow-to-region from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 (while (search-forward "\n" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 (insert-char ?\ indent)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 ;;; The `documentation-string' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364 (define-widget 'documentation-string 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 "A documentation string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 :action 'widget-documentation-string-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 :value-delete 'widget-children-value-delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 :value-create 'widget-documentation-string-value-create)
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 (defun widget-documentation-string-value-create (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 ;; Insert documentation string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 (let ((doc (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 (indent (widget-get widget :indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 (shown (widget-get (widget-get widget :parent) :documentation-shown))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 (start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 (if (string-match "\n" doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 (let ((before (substring doc 0 (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 (after (substring doc (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 buttons)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3381 (insert before ?\ )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 (widget-documentation-link-add widget start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 (push (widget-create-child-and-convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 widget 'visibility
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 :help-echo (lambda (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 (if (widget-value widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 "Hide" "Show")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 " the rest of the documentation"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390 :off "More"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 :action 'widget-parent-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 shown)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393 buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 (when shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 (when indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 (insert-char ?\ indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 (insert after)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 (widget-documentation-link-add widget start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 (widget-put widget :buttons buttons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 (insert doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 (widget-documentation-link-add widget start (point))))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3403 (insert ?\n))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 (defun widget-documentation-string-action (widget &rest ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 ;; Toggle documentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 (let ((parent (widget-get widget :parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 (widget-put parent :documentation-shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 (not (widget-get parent :documentation-shown))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 ;; Redraw.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 (widget-value-set widget (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3413
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 ;;; The Sexp Widgets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3416 (define-widget 'sexp 'editable-field
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3417 "An arbitrary Lisp expression."
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3418 :tag "Lisp expression"
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3419 :format "%{%t%}: %v"
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3420 :value nil
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3421 :validate 'widget-sexp-validate
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3422 :match (lambda (widget value) t)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3423 :value-to-internal 'widget-sexp-value-to-internal
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3424 :value-to-external (lambda (widget value) (read value))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3425 :prompt-history 'widget-sexp-prompt-value-history
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3426 :prompt-value 'widget-sexp-prompt-value)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3427
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3428 (defun widget-sexp-value-to-internal (widget value)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3429 ;; Use cl-prettyprint for printer representation.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3430 (let ((pp (if (symbolp value)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3431 (prin1-to-string value)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3432 (widget-prettyprint-to-string value))))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3433 (if (> (length pp) 40)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3434 (concat "\n" pp)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3435 pp)))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3436
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3437 (defun widget-sexp-validate (widget)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3438 ;; Valid if we can read the string and there is no junk left after it.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3439 (save-excursion
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3440 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3441 (erase-buffer)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3442 (insert (widget-apply widget :value-get))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3443 (goto-char (point-min))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3444 (condition-case data
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3445 (let ((value (read buffer)))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3446 (if (eobp)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3447 (if (widget-apply widget :match value)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3448 nil
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3449 (widget-put widget :error (widget-get widget :type-error))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3450 widget)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3451 (widget-put widget
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3452 :error (format "Junk at end of expression: %s"
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3453 (buffer-substring (point)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3454 (point-max))))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3455 widget))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3456 (error (widget-put widget :error (error-message-string data))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3457 widget)))))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3458
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3459 (defvar widget-sexp-prompt-value-history nil
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3460 "History of input to `widget-sexp-prompt-value'.")
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3461
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3462 (defun widget-sexp-prompt-value (widget prompt value unbound)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3463 ;; Read an arbitrary sexp.
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3464 (let ((found (read-string (concat prompt ": ")
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3465 (if unbound nil (cons (prin1-to-string value) 0))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3466 (widget-get widget :prompt-history))))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3467 (save-excursion
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3468 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3469 (erase-buffer)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3470 (insert found)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3471 (goto-char (point-min))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3472 (let ((answer (read buffer)))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3473 (unless (eobp)
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3474 (signal 'error
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3475 (list "Junk at end of expression"
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3476 (buffer-substring (point) (point-max)))))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3477 answer)))))
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3478
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3479 ;; Various constant sexps.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3480
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 (define-widget 'const 'item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 "An immutable sexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 :prompt-value 'widget-const-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 :format "%t\n%d")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 (defun widget-const-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 ;; Return the value of the const.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 (define-widget 'function-item 'const
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 "An immutable function name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 :format "%v\n%h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 :documentation-property (lambda (symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 (documentation symbol t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 (define-widget 'variable-item 'const
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 "An immutable variable name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 :format "%v\n%h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 :documentation-property 'variable-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3503 (define-widget 'other 'sexp
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3504 "Matches any value, but doesn't let the user edit the value.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3505 This is useful as last item in a `choice' widget.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3506 You should use this widget type with a default value,
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3507 as in (other DEFAULT) or (other :tag \"NAME\" DEFAULT).
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3508 If the user selects this alternative, that specifies DEFAULT
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3509 as the value."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3510 :tag "Other"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3511 :format "%t%n"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3512 :value 'other)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3513
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 (defvar widget-string-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 "History of input to `widget-string-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 (define-widget 'string 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 "A string"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 :tag "String"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 :complete-function 'ispell-complete-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 :prompt-history 'widget-string-prompt-value-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 (define-widget 'regexp 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 "A regular expression."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 :match 'widget-regexp-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 :validate 'widget-regexp-validate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 ;; Doesn't work well with terminating newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529 ;; :value-face 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 :tag "Regexp")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 (defun widget-regexp-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 ;; Match valid regexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 (and (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 (prog1 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 (string-match value ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 (defun widget-regexp-validate (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 "Check that the value of WIDGET is a valid regexp."
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3542 (condition-case data
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3543 (prog1 nil
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3544 (string-match (widget-value widget) ""))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3545 (error (widget-put widget :error (error-message-string data))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3546 widget)))
428
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 'file 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 "A file widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 It will read a file name from the minibuffer when invoked."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 :complete-function 'widget-file-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552 :prompt-value 'widget-file-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 ;; Doesn't work well with terminating newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 ;; :value-face 'widget-single-line-field-face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 :tag "File")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 (defun widget-file-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 "Perform completion on file name preceding point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 (let* ((end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 (beg (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 (skip-chars-backward "^ ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 (pattern (buffer-substring beg end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566 (name-part (file-name-nondirectory pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 (directory (file-name-directory pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 (completion (file-name-completion name-part directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 (cond ((eq completion t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 (message "Can't find completion for \"%s\"" pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 (ding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 ((not (string= name-part completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 (delete-region beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 (insert (expand-file-name completion directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 (message "Making completion list...")
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3578 (with-output-to-temp-buffer "*Completions*"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3579 (display-completion-list
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3580 (sort (file-name-all-completions name-part directory)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3581 'string<)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 (message "Making completion list...%s" "done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 (defun widget-file-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 ;; Read file from minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 (abbreviate-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 (if unbound
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3588 (read-file-name (concat prompt ": "))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3589 (let ((prompt2 (format "%s: (default %s) " prompt value))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 (dir (file-name-directory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 (file (file-name-nondirectory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 (must-match (widget-get widget :must-match)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 (read-file-name prompt2 dir nil must-match file)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 ;;;(defun widget-file-action (widget &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 ;;; ;; Read a file name from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 ;;; (let* ((value (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 ;;; (dir (file-name-directory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 ;;; (file (file-name-nondirectory value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 ;;; (menu-tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 ;;; (must-match (widget-get widget :must-match))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 ;;; (answer (read-file-name (concat menu-tag ": (default `" value "') ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 ;;; dir nil must-match file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 ;;; (widget-value-set widget (abbreviate-file-name answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 ;;; (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 ;;; (widget-apply widget :notify widget event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3608 ;; Fixme: use file-name-as-directory.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 (define-widget 'directory 'file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 "A directory widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 It will read a directory name from the minibuffer when invoked."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 :tag "Directory")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 (defvar widget-symbol-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 "History of input to `widget-symbol-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 (define-widget 'symbol 'editable-field
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3618 "A Lisp symbol."
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3619 :value t
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 :tag "Symbol"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 :format "%{%t%}: %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 :match (lambda (widget value) (symbolp value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 :complete-function 'lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 :prompt-internal 'widget-symbol-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 :prompt-match 'symbolp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 :prompt-history 'widget-symbol-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 (if (symbolp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 (symbol-name value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633 (intern value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636 (defun widget-symbol-prompt-internal (widget prompt initial history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637 ;; Read file from minibuffer.
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3638 (let ((answer (completing-read (concat prompt ": ") obarray
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 (widget-get widget :prompt-match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 nil initial history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 (if (and (stringp answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 (not (zerop (length answer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 (error "No value"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 (defvar widget-function-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647 "History of input to `widget-function-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 (define-widget 'function 'sexp
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3650 "A Lisp function."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 :complete-function 'lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 :prompt-value 'widget-field-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 :prompt-internal 'widget-symbol-prompt-internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654 :prompt-match 'fboundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 :prompt-history 'widget-function-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656 :action 'widget-field-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3657 :tag "Function")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 (defvar widget-variable-prompt-value-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3660 "History of input to `widget-variable-prompt-value'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 (define-widget 'variable 'symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663 ;; Should complete on variables.
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3664 "A Lisp variable."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 :prompt-match 'boundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 :prompt-history 'widget-variable-prompt-value-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667 :tag "Variable")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669 ;; This part issues a warning when compiling without Mule. Is there a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 ;; way of shutting it up?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 ;; OK, I'll simply comment the whole thing out, until someone decides
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673 ;; to do something with it.
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3674
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3675 ;; OK, _I_'ll simply comment it back in, so somebody will get irritated and
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3676 ;; do something about it.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3677
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3678 (defvar widget-coding-system-prompt-value-history nil
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3679 "History of input to `widget-coding-system-prompt-value'.")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3680
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3681 (define-widget 'coding-system 'symbol
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3682 "A MULE coding-system."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3683 :format "%{%t%}: %v"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3684 :tag "Coding system"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3685 :prompt-history 'widget-coding-system-prompt-value-history
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3686 :prompt-value 'widget-coding-system-prompt-value
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3687 :action 'widget-coding-system-action)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3688
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3689 (defun widget-coding-system-prompt-value (widget prompt value unbound)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3690 ;; Read coding-system from minibuffer.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3691 (intern
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3692 (completing-read (format "%s (default %s) " prompt value)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3693 (mapcar (lambda (sym)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3694 (list (symbol-name sym)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3695 (coding-system-list)))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3696
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3697 (defun widget-coding-system-action (widget &optional event)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3698 ;; Read a file name from the minibuffer.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3699 (let ((answer
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3700 (widget-coding-system-prompt-value
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3701 widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3702 (widget-apply widget :menu-tag-get)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3703 (widget-value widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3704 t)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3705 (widget-value-set widget answer)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3706 (widget-apply widget :notify widget event)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3707 (widget-setup)))
428
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 (define-widget 'restricted-sexp 'sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 "A Lisp expression restricted to values that match.
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3711
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3712 Either the `:match' or the `:match-alternatives' property must be defined."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 :type-error "The specified value is not valid"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 :match 'widget-restricted-sexp-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 (if (widget-apply widget :match value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717 (prin1-to-string value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 (defun widget-restricted-sexp-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 (let ((alternatives (widget-get widget :match-alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 matched)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 (while (and alternatives (not matched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724 (if (cond ((functionp (car alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 (funcall (car alternatives) value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726 ((and (consp (car alternatives))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 (eq (car (car alternatives)) 'quote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 (eq value (nth 1 (car alternatives)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 (setq matched t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730 (setq alternatives (cdr alternatives)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 matched))
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 (define-widget 'integer 'restricted-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 "An integer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735 :tag "Integer"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 :value 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 :type-error "This field should contain an integer"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738 :match-alternatives '(integerp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 (define-widget 'number 'restricted-sexp
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3741 "A number (floating point or integer)."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742 :tag "Number"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743 :value 0.0
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3744 :type-error "This field should contain a number (floating point or integer)"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745 :match-alternatives '(numberp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3747 (define-widget 'float 'restricted-sexp
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3748 "A floating point number."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3749 :tag "Floating point number"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3750 :value 0.0
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3751 :type-error "This field should contain a floating point number"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3752 :match-alternatives '(floatp))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3753
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3754 (define-widget 'character 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3755 "A character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3756 :tag "Character"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3757 :value ?\0
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3758 :size 1
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3759 :format "%{%t%}: %v"
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3760 ;; #### This is incorrect for Mule.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3761 :valid-regexp "\\`[\0-\377]\\'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762 :error "This field should contain a single character"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3763 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3764 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3765 value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3766 (char-to-string value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3767 :value-to-external (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3768 (if (stringp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3769 (aref value 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3770 value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3771 :match (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3772 (characterp value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3774 (define-widget 'list 'group
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3775 "A Lisp list of fixed length with fixed type for each element."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3776 :tag "List"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3777 :format "%{%t%}:\n%v")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779 (define-widget 'vector 'group
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3780 "A Lisp vector of fixed length with fixed type for each element."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3781 :tag "Vector"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3782 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 :match 'widget-vector-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 :value-to-internal (lambda (widget value) (append value nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3785 :value-to-external (lambda (widget value) (vconcat value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 (defun widget-vector-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788 (and (vectorp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3789 (widget-group-match widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 (widget-apply widget :value-to-internal value))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 (define-widget 'cons 'group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 "A cons-cell."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794 :tag "Cons-cell"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 :match 'widget-cons-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 :value-to-internal (lambda (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798 (list (car value) (cdr value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 :value-to-external (lambda (widget value)
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3800 (cons (nth 0 value) (nth 1 value))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 (defun widget-cons-match (widget value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3803 (and (consp value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804 (widget-group-match widget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3805 (widget-apply widget :value-to-internal value))))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3806
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3807 ;;; The `plist' Widget.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3808 ;;
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3809 ;; Property lists.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3810
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3811 (define-widget 'plist 'list
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3812 "A property list."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3813 :key-type '(symbol :tag "Key")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3814 :value-type '(sexp :tag "Value")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3815 :convert-widget 'widget-plist-convert-widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3816 :tag "Plist")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3817
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3818 (defvar widget-plist-value-type) ;Dynamic variable
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3819
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3820 (defun widget-plist-convert-widget (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3821 ;; Handle `:options'.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3822 (let* ((options (widget-get widget :options))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3823 (widget-plist-value-type (widget-get widget :value-type))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3824 (other `(editable-list :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3825 (group :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3826 ,(widget-get widget :key-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3827 ,widget-plist-value-type)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3828 (args (if options
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3829 (list `(checklist :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3830 :greedy t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3831 ,@(mapcar 'widget-plist-convert-option
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3832 options))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3833 other)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3834 (list other))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3835 (widget-put widget :args args)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3836 widget))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3837
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3838 (defun widget-plist-convert-option (option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3839 ;; Convert a single plist option.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3840 (let (key-type value-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3841 (if (listp option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3842 (let ((key (nth 0 option)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3843 (setq value-type (nth 1 option))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3844 (if (listp key)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3845 (setq key-type key)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3846 (setq key-type `(const ,key))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3847 (setq key-type `(const ,option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3848 value-type widget-plist-value-type))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3849 `(group :format "Key: %v" :inline t ,key-type ,value-type)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3850
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3851
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3852 ;;; The `alist' Widget.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3853 ;;
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3854 ;; Association lists.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3855
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3856 (define-widget 'alist 'list
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3857 "An association list."
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3858 :key-type '(sexp :tag "Key")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3859 :value-type '(sexp :tag "Value")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3860 :convert-widget 'widget-alist-convert-widget
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3861 :tag "Alist")
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3862
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3863 (defvar widget-alist-value-type) ;Dynamic variable
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3864
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3865 (defun widget-alist-convert-widget (widget)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3866 ;; Handle `:options'.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3867 (let* ((options (widget-get widget :options))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3868 (widget-alist-value-type (widget-get widget :value-type))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3869 (other `(editable-list :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3870 (cons :format "%v"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3871 ,(widget-get widget :key-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3872 ,widget-alist-value-type)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3873 (args (if options
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3874 (list `(checklist :inline t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3875 :greedy t
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3876 ,@(mapcar 'widget-alist-convert-option
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3877 options))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3878 other)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3879 (list other))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3880 (widget-put widget :args args)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3881 widget))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3882
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3883 (defun widget-alist-convert-option (option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3884 ;; Convert a single alist option.
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3885 (let (key-type value-type)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3886 (if (listp option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3887 (let ((key (nth 0 option)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3888 (setq value-type (nth 1 option))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3889 (if (listp key)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3890 (setq key-type key)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3891 (setq key-type `(const ,key))))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3892 (setq key-type `(const ,option)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3893 value-type widget-alist-value-type))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3894 `(cons :format "Key: %v" ,key-type ,value-type)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3895
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
3896
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3897 (define-widget 'choice 'menu-choice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3898 "A union of several sexp types."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3899 :tag "Choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3900 :format "%{%t%}: %[Value Menu%] %v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3901 :button-prefix 'widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902 :button-suffix 'widget-push-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903 :prompt-value 'widget-choice-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3904
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3905 (defun widget-choice-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3906 "Make a choice."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3907 (let ((args (widget-get widget :args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 (completion-ignore-case (widget-get widget :case-fold))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3909 current choices old)
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3910 ;; Find the first choice matching VALUE (if given):
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3911 (unless unbound
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3912 (let ((look args))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3913 (while look
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3914 (if (widget-apply (car look) :match value)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3915 (setq old (car look)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3916 look nil)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3917 (setq look (cdr look)))))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3918 ;; If VALUE is invalid (it doesn't match any choice), discard it by
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3919 ;; considering it unbound:
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3920 (unless old
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3921 (setq unbound t)))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3922 ;; Now offer the choice, providing the given default value when/where
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3923 ;; appropriate:
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3924 (while args
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3925 (setq current (car args)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3926 args (cdr args))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3927 (setq choices
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3928 (cons (cons (widget-apply current :menu-tag-get)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3929 current)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3930 choices)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 (setq current
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3932 (let ((val (completing-read (concat prompt ": ") choices nil t
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3933 (when old
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3934 (widget-apply old :menu-tag-get)))))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3935 (if (stringp val) ;; #### is this really needed ? --dvl
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3936 (let ((try (try-completion val choices)))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3937 (when (stringp try) ;; #### and this ? --dvl
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3938 (setq val try))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3939 (cdr (assoc val choices)))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3940 nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3941 (if current
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3942 (widget-prompt-value current
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3943 (concat (widget-prompt-spaceify prompt)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3944 (widget-get current :tag))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3945 (unless unbound
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3946 (when (eq current old) value))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3947 (or unbound (not (eq current old))))
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3948 (and (not unbound) value))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3950 (define-widget 'radio 'radio-button-choice
1362
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3951 "A set widget, selecting exactly one from many.
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3952
cfe4bcb9bdd4 [xemacs-hg @ 2003-03-18 06:58:19 by stephent]
stephent
parents: 1333
diff changeset
3953 The parent of several `radio-button' widgets, one for each option."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3954 :tag "Choice"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3955 :format "%{%t%}:\n%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3956 :prompt-value 'widget-choice-prompt-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3958 (define-widget 'repeat 'editable-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3959 "A variable length homogeneous list."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3960 :tag "Repeat"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3961 :format "%{%t%}:\n%v%i\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3963 (define-widget 'set 'checklist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3964 "A list of members from a fixed set."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3965 :tag "Set"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3966 :format "%{%t%}:\n%v")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3968 (define-widget 'boolean 'toggle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3969 "To be nil or non-nil, that is the question."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 :tag "Boolean"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971 :prompt-value 'widget-boolean-prompt-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972 :button-prefix 'widget-push-button-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 :button-suffix 'widget-push-button-suffix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974 :format "%{%t%}: %[Toggle%] %v\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 :on "on (non-nil)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976 :off "off (nil)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3978 (defun widget-boolean-prompt-value (widget prompt value unbound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979 ;; Toggle a boolean.
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
3980 (y-or-n-p (concat prompt ": ")))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3982 ;;; The `color' Widget.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3983
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
3984 ;; Fixme: match
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3985 (define-widget 'color 'editable-field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986 "Choose a color name (with sample)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987 :format "%[%t%]: %v (%{sample%})\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3988 :size 10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3989 :tag "Color"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3990 :value "black"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3991 :complete 'widget-color-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3992 :sample-face-get 'widget-color-sample-face-get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993 :notify 'widget-color-notify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 :action 'widget-color-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3996 (defun widget-color-complete (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3997 "Complete the color in WIDGET."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3998 (let* ((prefix (buffer-substring-no-properties (widget-field-start widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3999 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000 (list (read-color-completion-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4001 (completion (try-completion prefix list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4002 (cond ((eq completion t)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
4003 (message "Exact match."))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4004 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4005 (error "Can't find completion for \"%s\"" prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006 ((not (string-equal prefix completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 (insert (substring completion (length prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4008 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4009 (message "Making completion list...")
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
4010 (with-output-to-temp-buffer "*Completions*"
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
4011 (display-completion-list (all-completions prefix list nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012 (message "Making completion list...done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4014 (defun widget-color-sample-face-get (widget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 (or (widget-get widget :sample-face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4016 (let ((color (widget-value widget))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017 (face (make-face (gensym "sample-face-") nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4018 ;; Use the face object, not its name, to prevent lossage if gc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 ;; happens before applying the face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4020 (widget-put widget :sample-face face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021 (and color
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4022 (not (equal color ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023 (valid-color-name-p color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4024 (set-face-foreground face color))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4025 face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027 (defvar widget-color-history nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 "History of entered colors.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 (defun widget-color-action (widget &optional event)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
4031 "Prompt for a color."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4032 (let* ((tag (widget-apply widget :menu-tag-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033 (answer (read-color (concat tag ": "))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 (unless (zerop (length answer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035 (widget-value-set widget answer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4036 (widget-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037 (widget-apply widget :notify widget event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039 (defun widget-color-notify (widget child &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4040 "Update the sample, and notify the parent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4041 (let* ((face (widget-apply widget :sample-face-get))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042 (color (widget-value widget)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4043 (if (valid-color-name-p color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4044 (set-face-foreground face color)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4045 (remove-face-property face 'foreground)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4046 (widget-default-notify widget child event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4047
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
4048 ;;; The Help Echo
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
4049
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4050 (defun widget-echo-help (pos)
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
4051 "Display the help-echo text for widget at POS."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4052 (let* ((widget (widget-at pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4053 (help-echo (and widget (widget-get widget :help-echo))))
1309
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
4054 (if (functionp help-echo)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
4055 (setq help-echo (funcall help-echo widget)))
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
4056 (if (stringp help-echo)
00abb1091204 [xemacs-hg @ 2003-02-17 14:50:55 by stephent]
stephent
parents: 1173
diff changeset
4057 (display-message 'help-echo help-echo))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058
1833
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4059 (define-widget 'lazy 'default
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4060 "Base widget for recursive datastructures.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4061
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4062 The `lazy' widget will, when instantiated, contain a single inferior
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4063 widget, of the widget type specified by the :type parameter. The
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4064 value of the `lazy' widget is the same as the value of the inferior
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4065 widget. When deriving a new widget from the 'lazy' widget, the :type
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4066 parameter is allowed to refer to the widget currently being defined,
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4067 thus allowing recursive datastructures to be described.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4068
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4069 The:type parameter takes the same arguments as the defcustom
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4070 parameter with the same name.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4071
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4072 Most composite widgets, i.e. widgets containing other widgets, does
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4073 not allow recursion. That is, when you define a new widget type, none
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4074 of the inferior widgets may be of the same type you are currently
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4075 defining.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4076
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4077 In Lisp, however, it is custom to define datastructures in terms of
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4078 themselves. A list, for example, is defined as either nil, or a cons
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4079 cell whose cdr itself is a list. The obvious way to translate this
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4080 into a widget type would be
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4081
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4082 (define-widget 'my-list 'choice
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4083 \"A list of sexps.\"
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4084 :tag \"Sexp list\"
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4085 :args '((const nil) (cons :value (nil) sexp my-list)))
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4086
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4087 Here we attempt to define my-list as a choice of either the constant
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4088 nil, or a cons-cell containing a sexp and my-lisp. This will not work
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4089 because the `choice' widget does not allow recursion.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4090
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
4091 Using the `lazy' widget you can overcome this problem, as in this
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
4092 example:
1833
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4093
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4094 (define-widget 'sexp-list 'lazy
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4095 \"A list of sexps.\"
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4096 :tag \"Sexp list\"
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4097 :type '(choice (const nil) (cons :value (nil) sexp sexp-list)))"
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4098 :format "%{%t%}: %v"
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4099 ;; We don't convert :type because we want to allow recursive
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4100 ;; datastructures. This is slow, so we should not create speed
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
4101 ;; critical widgets by deriving from this.
1833
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4102 :convert-widget 'widget-value-convert-widget
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4103 :value-create 'widget-type-value-create
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4104 :value-delete 'widget-children-value-delete
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4105 :value-get 'widget-child-value-get
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4106 :value-inline 'widget-child-value-inline
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4107 :default-get 'widget-type-default-get
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4108 :match 'widget-type-match
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4109 :validate 'widget-child-validate)
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4110
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4111 (defun widget-child-value-get (widget)
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4112 "Get the value of the first member of :children in WIDGET."
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4113 (widget-value (car (widget-get widget :children))))
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4114
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4115 (defun widget-child-value-inline (widget)
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4116 "Get the inline value of the first member of :children in WIDGET."
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4117 (widget-apply (car (widget-get widget :children)) :value-inline))
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4118
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4119 (defun widget-child-validate (widget)
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4120 "The result of validating the first member of :children in WIDGET."
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4121 (widget-apply (car (widget-get widget :children)) :validate))
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4122
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4123 (defun widget-type-value-create (widget)
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4124 "Convert and instantiate the value of the :type attribute of WIDGET.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4125 Store the newly created widget in the :children attribute.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4126
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4127 The value of the :type attribute should be an unconverted widget type."
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4128 (let ((value (widget-get widget :value))
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4129 (type (widget-get widget :type)))
4178
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
4130 (widget-put widget :children
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
4131 (list (widget-create-child-value widget
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
4132 (widget-convert type)
e687f1912d5b [xemacs-hg @ 2007-09-20 21:18:33 by didierv]
didierv
parents: 3287
diff changeset
4133 value)))))
1833
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4134
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4135 (defun widget-type-default-get (widget)
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4136 "Get default value from the :type attribute of WIDGET.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4137
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4138 The value of the :type attribute should be an unconverted widget type."
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4139 (widget-default-get (widget-convert (widget-get widget :type))))
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4140
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4141 (defun widget-type-match (widget value)
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4142 "Non-nil if the :type value of WIDGET matches VALUE.
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4143
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4144 The value of the :type attribute should be an unconverted widget type."
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4145 (widget-apply (widget-convert (widget-get widget :type)) :match value))
eed841acc858 [xemacs-hg @ 2003-12-19 14:28:45 by youngs]
youngs
parents: 1736
diff changeset
4146
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4147 ;;; The End:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 (provide 'wid-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150
1173
315720febed1 [xemacs-hg @ 2002-12-26 15:52:41 by stephent]
stephent
parents: 776
diff changeset
4151 ;;; wid-edit.el ends here