462
|
1 ;;; dialog-gtk.el --- Dialog-box support for XEmacs w/GTK primitives
|
|
2
|
|
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: William M. Perry <wmperry@gnu.org>
|
|
6 ;; Keywords: extensions, internal, dumped
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
|
24
|
|
25 ;;; Synched up with: Not in FSF.
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This file is dumped with XEmacs (when dialog boxes are compiled in).
|
|
30
|
|
31 (require 'cl)
|
|
32 (require 'gtk-password-dialog)
|
|
33 (require 'gtk-file-dialog)
|
|
34
|
502
|
35 (globally-declare-fboundp
|
|
36 '(gtk-signal-connect
|
|
37 gtk-main-quit gtk-window-set-transient-for
|
|
38 gtk-widget-show-all gtk-main gtk-color-selection-dialog-new
|
|
39 gtk-color-selection-dialog-ok-button gtk-widget-hide-all
|
|
40 gtk-color-selection-get-color
|
|
41 gtk-color-selection-dialog-colorsel
|
|
42 gtk-color-selection-dialog-cancel-button gtk-widget-show-now
|
|
43 gtk-widget-grab-focus gtk-widget-destroy gtk-dialog-new
|
|
44 gtk-window-set-title gtk-container-set-border-width
|
|
45 gtk-box-set-spacing gtk-dialog-vbox gtk-container-add
|
|
46 gtk-label-new gtk-button-new-with-label
|
|
47 gtk-widget-set-sensitive gtk-widget-show gtk-dialog-action-area))
|
|
48
|
462
|
49 (defun popup-builtin-open-dialog (keys)
|
|
50 ;; Allowed keywords are:
|
|
51 ;;
|
|
52 ;; :initial-filename fname
|
|
53 ;; :initial-directory dir
|
|
54 ;; :filter-list (filter-desc filter ...)
|
|
55 ;; :directory t/nil
|
|
56 ;; :title string
|
|
57 ;; :allow-multi-select t/nil
|
|
58 ;; :create-prompt-on-nonexistent t/nil
|
|
59 ;; :overwrite-prompt t/nil
|
|
60 ;; :file-must-exist t/nil
|
|
61 ;; :no-network-button t/nil
|
|
62 ;; :no-read-only-return t/nil
|
|
63 (let ((initial-filename (plist-get keys :initial-filename))
|
|
64 (clicked-ok nil)
|
|
65 (widget nil))
|
|
66 (setq widget (gtk-file-dialog-new
|
|
67 :directory (plist-get keys :directory)
|
|
68 :callback `(lambda (f)
|
|
69 (setq clicked-ok t
|
|
70 filename f))
|
|
71 :initial-directory (or (plist-get keys :initial-directory nil)
|
|
72 (if initial-filename
|
|
73 (file-name-directory initial-filename)
|
|
74 default-directory))
|
|
75 :filter-list (plist-to-alist
|
|
76 (plist-get keys :filter-list nil))
|
|
77 :file-must-exist (plist-get keys :file-must-exist nil)))
|
|
78
|
|
79 (gtk-signal-connect widget 'destroy (lambda (obj data) (gtk-main-quit)))
|
|
80
|
|
81 (gtk-window-set-transient-for widget (frame-property nil 'shell-widget))
|
|
82 (gtk-widget-show-all widget)
|
|
83 (gtk-main)
|
|
84 (if (not clicked-ok)
|
608
|
85 (signal 'quit nil)
|
|
86 filename)))
|
462
|
87
|
|
88 (defalias 'popup-builtin-save-as-dialog 'popup-builtin-open-dialog)
|
|
89
|
|
90 (defun popup-builtin-color-dialog (keys)
|
|
91 ;; Allowed keys:
|
|
92 ;; :initial-color COLOR
|
502
|
93 (let (;(initial-color (or (plist-get keys :initial-color) "white"))
|
462
|
94 (title (or (plist-get keys :title "Select color...")))
|
|
95 (dialog nil)
|
|
96 (clicked-ok nil)
|
|
97 (color nil))
|
|
98 (setq dialog (gtk-color-selection-dialog-new title))
|
|
99 (gtk-signal-connect
|
|
100 (gtk-color-selection-dialog-ok-button dialog) 'clicked
|
|
101 (lambda (button colorsel)
|
|
102 (gtk-widget-hide-all dialog)
|
|
103 (setq color (gtk-color-selection-get-color colorsel)
|
|
104 clicked-ok t)
|
|
105 (gtk-main-quit))
|
|
106 (gtk-color-selection-dialog-colorsel dialog))
|
|
107
|
|
108 (gtk-signal-connect
|
|
109 (gtk-color-selection-dialog-cancel-button dialog) 'clicked
|
|
110 (lambda (&rest ignored)
|
|
111 (gtk-main-quit)))
|
|
112
|
|
113 (put dialog 'modal t)
|
|
114 (put dialog 'type 'dialog)
|
|
115 (gtk-window-set-transient-for dialog (frame-property nil 'shell-widget))
|
|
116
|
|
117 (unwind-protect
|
|
118 (progn
|
|
119 (gtk-widget-show-now dialog)
|
|
120 (gtk-main))
|
|
121 '(gtk-widget-destroy dialog))
|
|
122 (if (not clicked-ok)
|
|
123 (signal 'quit nil))
|
|
124 ;; Need to convert from (R G B A) to #rrggbb
|
|
125 (format "#%02x%02x%02x"
|
|
126 (* 256 (nth 0 color))
|
|
127 (* 256 (nth 1 color))
|
|
128 (* 256 (nth 2 color)))))
|
|
129
|
|
130 (defun popup-builtin-password-dialog (keys)
|
|
131 ;; Format is (default callback :keyword value)
|
|
132 ;; Allowed keywords are:
|
|
133 ;;
|
|
134 ;; :title string
|
|
135 :; :prompt string
|
|
136 ;; :default string
|
|
137 ;; :verify boolean
|
|
138 ;; :verify-prompt string
|
|
139 (let* ((default (plist-get keys :default))
|
|
140 (dialog nil)
|
|
141 (clicked-ok nil)
|
|
142 (passwd nil)
|
|
143 (info nil)
|
|
144 (generic-cb (lambda (x)
|
|
145 (setq clicked-ok t
|
|
146 passwd x))))
|
|
147
|
|
148 ;; Convert the descriptor to keywords and create the dialog
|
|
149 (setq info (copy-list keys)
|
|
150 info (plist-put info :callback generic-cb)
|
|
151 info (plist-put info :default default)
|
|
152 dialog (apply 'gtk-password-dialog-new info))
|
|
153
|
|
154 ;; Clicking any button or closing the box exits the main loop.
|
|
155 (gtk-signal-connect (gtk-password-dialog-ok-button dialog)
|
|
156 'clicked
|
|
157 (lambda (&rest ignored)
|
|
158 (gtk-main-quit)))
|
|
159
|
|
160 (gtk-signal-connect (gtk-password-dialog-cancel-button dialog)
|
|
161 'clicked
|
|
162 (lambda (&rest ignored)
|
|
163 (gtk-main-quit)))
|
|
164
|
|
165 (gtk-signal-connect dialog
|
|
166 'delete-event
|
|
167 (lambda (&rest ignored)
|
|
168 (gtk-main-quit)))
|
|
169
|
|
170 (gtk-widget-grab-focus (gtk-password-dialog-entry-widget dialog))
|
|
171
|
|
172 ;; Make us modal...
|
|
173 (put dialog 'modal t)
|
|
174 (gtk-window-set-transient-for dialog (frame-property nil 'shell-widget))
|
|
175
|
|
176 ;; Realize the damn thing & wait for some action...
|
|
177 (gtk-widget-show-all dialog)
|
|
178 (gtk-main)
|
|
179
|
|
180 (if (not clicked-ok)
|
|
181 (signal 'quit nil))
|
|
182
|
|
183 (gtk-widget-destroy dialog)
|
|
184 passwd))
|
|
185
|
|
186 (defun popup-builtin-question-dialog (keys)
|
|
187 ;; Allowed keywords:
|
|
188 ;; :question STRING
|
|
189 ;; :buttons BUTTONDESC
|
|
190 (let ((title (or (plist-get keys :title) "Question"))
|
|
191 (buttons-descr (plist-get keys :buttons))
|
|
192 (question (or (plist-get keys :question) "Question goes here..."))
|
|
193 (dialog nil) ; GtkDialog
|
|
194 (buttons nil) ; List of GtkButton objects
|
|
195 (activep t)
|
|
196 (flushrightp nil)
|
|
197 (errp t))
|
|
198 (if (not buttons-descr)
|
|
199 (error 'syntax-error
|
|
200 "Dialog descriptor must supply at least one button"))
|
|
201
|
|
202 ;; Do the basics - create the dialog, set the window title, and
|
|
203 ;; add the label asking the question.
|
|
204 (unwind-protect
|
|
205 (progn
|
|
206 (setq dialog (gtk-dialog-new))
|
|
207 (gtk-window-set-title dialog title)
|
|
208 (gtk-container-set-border-width dialog 3)
|
|
209 (gtk-box-set-spacing (gtk-dialog-vbox dialog) 5)
|
|
210 (gtk-container-add (gtk-dialog-vbox dialog) (gtk-label-new question))
|
|
211
|
|
212 ;; Create the buttons.
|
|
213 (mapc (lambda (button)
|
|
214 ;; Handle flushright buttons
|
|
215 (if (null button)
|
|
216 (setq flushrightp t)
|
|
217
|
|
218 ;; More sanity checking first of all.
|
|
219 (if (not (vectorp button))
|
|
220 (error "Button descriptor is not a vector: %S" button))
|
|
221
|
|
222 (if (< (length button) 3)
|
|
223 (error "Button descriptor is too small: %S" button))
|
|
224
|
|
225 (push (gtk-button-new-with-label (aref button 0)) buttons)
|
|
226
|
|
227 ;; Need to detect what flavor of descriptor it is.
|
|
228 (if (not (keywordp (aref button 2)))
|
|
229 ;; Simple style... just [ name callback activep ]
|
|
230 ;; We ignore the 'suffix' entry, because that is what
|
|
231 ;; the X code does.
|
|
232 (setq activep (aref button 2))
|
|
233 (let ((ctr 2)
|
|
234 (len (length button)))
|
|
235 (if (logand len 1)
|
|
236 (error
|
|
237 "Button descriptor has an odd number of keywords and values: %S"
|
|
238 button))
|
|
239 (while (< ctr len)
|
|
240 (if (eq (aref button ctr) :active)
|
|
241 (setq activep (aref button (1+ ctr))
|
|
242 ctr len))
|
|
243 (setq ctr (+ ctr 2)))))
|
|
244 (gtk-widget-set-sensitive (car buttons) (eval activep))
|
|
245
|
|
246 ;; Apply the callback
|
|
247 (gtk-signal-connect
|
|
248 (car buttons) 'clicked
|
|
249 (lambda (button data)
|
|
250 (push (make-event 'misc-user
|
|
251 (list 'object (car data)
|
|
252 'function
|
|
253 (if (symbolp (car data))
|
|
254 'call-interactively
|
|
255 'eval)))
|
|
256 unread-command-events)
|
|
257 (gtk-main-quit)
|
|
258 t)
|
|
259 (cons (aref button 1) dialog))
|
|
260
|
|
261 (gtk-widget-show (car buttons))
|
|
262 (funcall (if flushrightp 'gtk-box-pack-end 'gtk-box-pack-start)
|
|
263 (gtk-dialog-action-area dialog) (car buttons)
|
|
264 nil t 2)))
|
|
265 buttons-descr)
|
|
266
|
|
267 ;; Make sure they can't close it with the window manager
|
|
268 (gtk-signal-connect dialog 'delete-event (lambda (&rest ignored) t))
|
|
269 (gtk-window-set-transient-for dialog (frame-property nil 'shell-widget))
|
|
270 (put dialog 'type 'dialog)
|
|
271 (put dialog 'modal t)
|
|
272 (gtk-widget-show-all dialog)
|
|
273 (gtk-main)
|
|
274 (gtk-widget-destroy dialog)
|
|
275 (setq errp nil))
|
|
276 (if (not errp)
|
|
277 ;; Nothing, we successfully showed the dialog
|
|
278 nil
|
|
279 ;; We need to destroy all the widgets, just in case.
|
|
280 (mapc 'gtk-widget-destroy buttons)
|
|
281 (gtk-widget-destroy dialog)))))
|
|
282
|
|
283 (defun gtk-make-dialog-box-internal (type keys)
|
|
284 (case type
|
|
285 (file
|
|
286 (popup-builtin-open-dialog keys))
|
|
287 (password
|
|
288 (popup-builtin-password-dialog keys))
|
|
289 (question
|
|
290 (popup-builtin-question-dialog keys))
|
|
291 (color
|
|
292 (popup-builtin-color-dialog keys))
|
|
293 (find
|
|
294 )
|
|
295 (font
|
|
296 )
|
|
297 (replace
|
|
298 )
|
|
299 (mswindows-message
|
|
300 ;; This should really be renamed!
|
|
301 )
|
|
302 (print
|
|
303 )
|
|
304 (page-setup
|
|
305 )
|
|
306 (print-setup
|
|
307 )
|
|
308 (default
|
|
309 (error "Unknown type of dialog: %S" type))))
|
|
310
|
|
311 (provide 'dialog-gtk)
|