annotate lisp/generic-widgets.el @ 462:0784d089fdc9 r21-2-46

Import from CVS: tag r21-2-46
author cvs
date Mon, 13 Aug 2007 11:44:37 +0200
parents
children 7039e6323819
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1 ;;; generic-widgets.el --- Generic UI building
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
3 ;; Copyright (C) 2000 Free Software Foundation
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
4
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
5 ;; Maintainer: William Perry <wmperry@gnu.org>
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
6 ;; Keywords: extensions, dumped
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
7
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
9
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
13 ;; any later version.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
14
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
18 ;; General Public License for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
19
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
24
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
25 ;;; Synched up with: Not in FSF
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
26
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
27 ;;; Commentary:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
28
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
29 ;; This file is dumped with XEmacs.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
30
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
31 (defun build-ui (ui)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
32 (if (null ui)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
33 (gtk-label-new "[empty]")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
34 (let ((builder-func (intern-soft (format "build-ui::%s" (car ui))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
35 (widget nil))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
36 (if (and builder-func (fboundp builder-func))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
37 (progn
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
38 (setq widget (funcall builder-func ui))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
39 (setcdr ui (plist-put (cdr ui) :x-internal-widget widget))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
40 widget)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
41 (error "Unknown ui element: %s" (car ui))))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
42
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
43 (defun show-ui (ui)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
44 (let ((widget (plist-get (cdr ui) :x-internal-widget)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
45 (if (not widget)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
46 (error "Attempting to show unrealized UI"))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
47 (gtk-widget-show-all widget)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
48 (gtk-signal-connect widget 'destroy
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
49 (lambda (widget ui)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
50 (setcdr ui (plist-put (cdr ui) :x-internal-widget nil))) ui)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
51
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
52
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
53 (defun build-ui::window (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
54 "Create a top-level window for containing other widgets.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
55 Properties:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
56 :items list A list of child UI specs. Only the first is used.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
57 :type toplevel/dialog/popup What type of window to create. Window managers
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
58 can (and usually do) treat each type differently.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
59 "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
60 (let ((plist (cdr spec))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
61 (window nil)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
62 (child nil))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
63 (setq window (gtk-window-new (plist-get plist :type 'toplevel))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
64 child (build-ui (car (plist-get plist :items))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
65 (gtk-container-add window child)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
66 window))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
67
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
68 (defun build-ui::box (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
69 "Create a box for containing other widgets.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
70 Properties:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
71 :items list A list of child UI specs.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
72 :homogeneous t/nil Whether all children are the same width/height.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
73 :spacing number Spacing between children.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
74 :orientation horizontal/vertical How the widgets are stacked.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
75
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
76 Additional properties on child widgets:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
77 :expand t/nil Whether the new child is to be given extra space
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
78 allocated to box. The extra space will be divided
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
79 evenly between all children of box that use this
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
80 option.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
81 :fill t/nil Whether space given to child by the expand option is
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
82 actually allocated to child, rather than just padding
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
83 it. This parameter has no effect if :expand is set to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
84 nil. A child is always allocated the full height of a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
85 horizontal box and the full width of a vertical box.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
86 This option affects the other dimension.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
87 :padding number Extra padding around this widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
88 "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
89 (let* ((plist (cdr spec))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
90 (orientation (plist-get plist :orientation 'horizontal))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
91 (children (plist-get plist :items))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
92 (box nil)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
93 (child-widget nil)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
94 (child-plist nil))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
95 (case orientation
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
96 (vertical (setq box (gtk-vbox-new (plist-get plist :homogeneous)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
97 (plist-get plist :spacing))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
98 (horizontal (setq box (gtk-hbox-new (plist-get plist :homogeneous)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
99 (plist-get plist :spacing))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
100 (otherwise (error "Unknown orientation for box: %s" orientation)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
101 (mapc
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
102 (lambda (child)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
103 (setq child-plist (cdr child)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
104 child-widget (build-ui child))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
105 (if (listp child-widget)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
106 (mapc (lambda (w)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
107 (gtk-box-pack-start box w
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
108 (plist-get child-plist :expand)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
109 (plist-get child-plist :fill)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
110 (plist-get child-plist :padding))) child-widget)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
111 (gtk-box-pack-start box child-widget
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
112 (plist-get child-plist :expand)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
113 (plist-get child-plist :fill)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
114 (plist-get child-plist :padding))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
115 children)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
116 box))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
117
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
118 (defun build-ui::tab-control (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
119 "Create a notebook widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
120 Properties:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
121 :items list A list of UI specs to use as notebook pages.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
122 :homogeneous t/nil Whether all tabs are the same width.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
123 :orientation top/bottom/left/right Position of tabs
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
124 :show-tabs t/nil Show the tabs on screen?
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
125 :scrollable t/nil Allow scrolling to view all tab widgets?
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
126
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
127 Additional properties on child widgets:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
128 :tab-label ui A UI spec to use for the tab label.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
129 "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
130 (let* ((plist (cdr spec))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
131 (notebook (gtk-notebook-new))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
132 (children (plist-get plist :items))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
133 (page-counter 1)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
134 (label-widget nil)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
135 (child-widget nil)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
136 (child-plist nil))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
137 ;; Set all the properties
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
138 (gtk-notebook-set-homogeneous-tabs notebook (plist-get plist :homogeneous))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
139 (gtk-notebook-set-scrollable notebook (plist-get plist :scrollable t))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
140 (gtk-notebook-set-show-tabs notebook (plist-get plist :show-tabs t))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
141 (gtk-notebook-set-tab-pos notebook (plist-get plist :orientation 'top))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
142
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
143 ;; Now fill in the tabs
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
144 (mapc
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
145 (lambda (child)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
146 (setq child-plist (cdr child)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
147 child-widget (build-ui child)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
148 label-widget (build-ui (plist-get child-plist :tab-label
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
149 (list 'label :text (format "tab %d" page-counter))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
150 page-counter (1+ page-counter))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
151 (gtk-notebook-append-page notebook child-widget label-widget))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
152 children)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
153 notebook))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
154
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
155 (defun build-ui::text (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
156 "Create a multi-line text widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
157 Properties:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
158 :editable t/nil Whether the user can change the contents
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
159 :word-wrap t/nil Automatic word wrapping?
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
160 :line-wrap t/nil Automatic line wrapping?
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
161 :text string Initial contents of the widget
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
162 :file filename File for initial contents (takes precedence over :text)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
163 :face facename XEmacs face to use in the widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
164 "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
165 (let* ((plist (cdr spec))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
166 (text (gtk-text-new nil nil))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
167 (face (plist-get plist :face 'default))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
168 (info (plist-get plist :text))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
169 (file (plist-get plist :file)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
170 (gtk-text-set-editable text (plist-get plist :editable))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
171 (gtk-text-set-word-wrap text (plist-get plist :word-wrap))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
172 (gtk-text-set-line-wrap text (plist-get plist :line-wrap))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
173 (gtk-widget-set-style text 'default)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
174
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
175 ;; Possible convert the file portion
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
176 (if (and file (not (stringp file)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
177 (setq file (eval file)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
178
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
179 (if (and info (not (stringp info)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
180 (setq info (eval info)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
181
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
182 (if (and file (file-exists-p file) (file-readable-p file))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
183 (save-excursion
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
184 (set-buffer (get-buffer-create " *improbable buffer name*"))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
185 (insert-file-contents file)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
186 (setq info (buffer-string))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
187
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
188 (gtk-text-insert text
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
189 (face-font face)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
190 (face-foreground face)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
191 (face-background face)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
192 info (length info))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
193 text))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
194
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
195 (defun build-ui::label (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
196 "Create a label widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
197 Properties:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
198 :text string Text inside the label
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
199 :face facename XEmacs face to use in the widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
200 :justification right/left/center How to justify the text.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
201 "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
202 (let* ((plist (cdr spec))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
203 (label (gtk-label-new (plist-get plist :text))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
204 (gtk-label-set-line-wrap label t)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
205 (gtk-label-set-justify label (plist-get plist :justification))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
206 (gtk-widget-set-style label (plist-get plist :face 'default))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
207 label))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
208
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
209 (defun build-ui::pixmap (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
210 "Create a multi-line text widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
211 Properties:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
212 :text string Text inside the label
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
213 :face facename XEmacs face to use in the widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
214 :justification right/left/center How to justify the text.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
215 "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
216 (let* ((plist (cdr spec))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
217 (label (gtk-label-new (plist-get plist :text))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
218 (gtk-label-set-line-wrap label t)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
219 (gtk-label-set-justify label (plist-get plist :justification))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
220 (gtk-widget-set-style label (plist-get plist :face 'default))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
221 label))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
222
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
223 (defun build-ui::radio-group (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
224 "A convenience when specifying a group of radio buttons."
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
225 (let ((build-ui::radio-group nil))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
226 (mapcar 'build-ui (plist-get (cdr spec) :items))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
227
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
228 (defun build-ui::button (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
229 "Create a button widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
230 Properties:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
231 :type radio/check/toggle/nil What type of button to create.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
232 :text string Text in the button.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
233 :glyph glyph Image in the button.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
234 :label ui A UI spec to use for the label.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
235 :relief normal/half/none How to draw button edges.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
236
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
237 NOTE: Radio buttons must be in a radio-group object for them to work.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
238 "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
239 (let ((plist (cdr spec))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
240 (button nil)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
241 (button-type (plist-get plist :type 'normal))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
242 (label nil))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
243 (case button-type
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
244 (radio
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
245 (if (not (boundp 'build-ui::radio-group))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
246 (error "Attempt to use a radio button outside a radio-group"))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
247 (setq button (gtk-radio-button-new build-ui::radio-group)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
248 build-ui::radio-group (gtk-radio-button-group button)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
249 (check
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
250 (setq button (gtk-check-button-new)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
251 (toggle
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
252 (setq button (gtk-toggle-button-new)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
253 (normal
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
254 (setq button (gtk-button-new)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
255 (otherwise
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
256 (error "Unknown button type: %s" button-type)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
257 (gtk-container-add
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
258 button
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
259 (build-ui (plist-get plist :label
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
260 (list 'label :text
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
261 (plist-get plist
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
262 :text (format "%s button" button-type))))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
263 button))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
264
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
265 (defun build-ui::progress-gauge (spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
266 "Create a progress meter.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
267 Properties:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
268 :orientation left-to-right/right-to-left/top-to-bottom/bottom-to-top
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
269 :type discrete/continuous
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
270
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
271 "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
272 (let ((plist (cdr spec))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
273 (gauge (gtk-progress-bar-new)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
274 (gtk-progress-bar-set-orientation gauge (plist-get plist :orientation 'left-to-right))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
275 (gtk-progress-bar-set-bar-style gauge (plist-get plist :type 'continuous))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
276 gauge))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
277
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
278 (provide 'generic-widgets)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
279
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
280 (when (featurep 'gtk) ; just loading this file should be OK
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
281 (gtk-widget-show-all
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
282 (build-ui
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
283 '(window :type dialog
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
284 :items ((tab-control
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
285 :homogeneous t
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
286 :orientation bottom
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
287 :items ((box :orientation vertical
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
288 :tab-label (label :text "vertical")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
289 :items ((label :text "Vertical")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
290 (progress-gauge)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
291 (label :text "Box stacking")))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
292 (box :orientation horizontal
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
293 :spacing 10
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
294 :items ((label :text "Horizontal box")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
295 (label :text "stacking")))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
296
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
297 (box :orientation vertical
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
298 :items
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
299 ((radio-group
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
300 :items ((button :type radio
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
301 :expand nil
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
302 :fill nil
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
303 :text "Item 1")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
304 (button :type radio
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
305 :expand nil
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
306 :fill nil
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
307 :text "Item 2")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
308 (button :type radio
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
309 :expand nil
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
310 :fill nil
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
311 :text "Item 3")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
312 (button :type radio
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
313 :expand nil
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
314 :fill nil)))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
315 (box :orientation vertical
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
316 :items ((button :type check
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
317 :text "Item 1")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
318 (button :type check
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
319 :text "Item 2")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
320 (button :type normal
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
321 :text "Item 3")
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
322 (button :type toggle)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
323 (text :editable t
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
324 :word-wrap t
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
325 :file (locate-data-file "COPYING"))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
326 (text :editable t
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
327 :face display-time-mail-balloon-enhance-face
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
328 :word-wrap t
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
329 :text "Text with a face on it")))))))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
330 )