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