0
|
1 /* Implements elisp-programmable dialog boxes -- X interface.
|
|
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 #include <config.h>
|
|
25 #include "lisp.h"
|
|
26
|
|
27 #include "console-x.h"
|
|
28 #include "EmacsManager.h"
|
|
29 #include "EmacsFrame.h"
|
|
30 #include "EmacsShell.h"
|
|
31 #include "gui-x.h"
|
|
32
|
|
33 #include "buffer.h"
|
|
34 #include "commands.h" /* zmacs_regions */
|
|
35 #include "events.h"
|
|
36 #include "frame.h"
|
231
|
37 #include "gui.h"
|
0
|
38 #include "opaque.h"
|
|
39 #include "window.h"
|
|
40
|
|
41
|
|
42 static void
|
|
43 maybe_run_dbox_text_callback (LWLIB_ID id)
|
|
44 {
|
|
45 /* !!#### This function has not been Mule-ized */
|
|
46 widget_value *wv;
|
|
47 int got_some;
|
|
48 wv = xmalloc_widget_value ();
|
2
|
49 wv->name = (char *) "value";
|
0
|
50 got_some = lw_get_some_values (id, wv);
|
|
51 if (got_some)
|
|
52 {
|
|
53 Lisp_Object text_field_callback;
|
|
54 char *text_field_value = wv->value;
|
|
55 VOID_TO_LISP (text_field_callback, wv->call_data);
|
|
56 if (text_field_value)
|
|
57 {
|
|
58 void *tmp = LISP_TO_VOID (list2 (text_field_callback,
|
|
59 build_string (text_field_value)));
|
|
60 popup_selection_callback (0, id, (XtPointer) tmp);
|
|
61 xfree (text_field_value);
|
|
62 }
|
|
63 }
|
|
64 free_widget_value (wv);
|
|
65 }
|
|
66
|
|
67 static void
|
|
68 dbox_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
69 {
|
|
70 /* This is called with client_data == -1 when WM_DELETE_WINDOW is sent
|
|
71 instead of a button being selected. */
|
|
72 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
73 struct frame *f = 0;
|
|
74 Widget cur_widget = widget;
|
|
75
|
|
76 /* The parent which is actually connected to our EmacsFrame may be a
|
|
77 ways up the tree. */
|
|
78 while (!f && cur_widget)
|
|
79 {
|
|
80 f = x_any_window_to_frame (d, XtWindow (cur_widget));
|
|
81 cur_widget = XtParent (cur_widget);
|
|
82 }
|
|
83
|
|
84 if (popup_handled_p (id))
|
|
85 return;
|
|
86 assert (popup_up_p != 0);
|
|
87 ungcpro_popup_callbacks (id);
|
|
88 popup_up_p--;
|
|
89 maybe_run_dbox_text_callback (id);
|
|
90 popup_selection_callback (widget, id, client_data);
|
|
91 lw_destroy_all_widgets (id);
|
|
92
|
|
93 /* The Motif dialog box sets the keyboard focus to itself. When it
|
|
94 goes away we have to take care of getting the focus back
|
|
95 ourselves. */
|
|
96 #ifdef EXTERNAL_WIDGET
|
|
97 /* #### Not sure if this special case is necessary. */
|
|
98 if (!FRAME_X_EXTERNAL_WINDOW_P (f) && f)
|
|
99 #else
|
|
100 if (f)
|
|
101 #endif
|
|
102 lw_set_keyboard_focus (FRAME_X_SHELL_WIDGET (f), FRAME_X_TEXT_WIDGET (f));
|
|
103 }
|
|
104
|
|
105 static CONST char * CONST button_names [] = {
|
|
106 "button1", "button2", "button3", "button4", "button5",
|
|
107 "button6", "button7", "button8", "button9", "button10" };
|
|
108
|
|
109 /* can't have static frame locals because of some broken compilers */
|
|
110 static char tmp_dbox_name [255];
|
|
111
|
|
112 static widget_value *
|
|
113 dbox_descriptor_to_widget_value (Lisp_Object desc)
|
|
114 {
|
|
115 /* !!#### This function has not been Mule-ized */
|
|
116 /* This function can GC */
|
|
117 char *name;
|
|
118 int lbuttons = 0, rbuttons = 0;
|
|
119 int partition_seen = 0;
|
|
120 int text_field_p = 0;
|
|
121 int allow_text_p = 1;
|
|
122 widget_value *prev = 0, *kids = 0;
|
|
123 int n = 0;
|
|
124 int count = specpdl_depth ();
|
|
125 Lisp_Object wv_closure;
|
|
126
|
|
127 CHECK_CONS (desc);
|
|
128 CHECK_STRING (XCAR (desc));
|
14
|
129 name = (char *) XSTRING_DATA (LISP_GETTEXT (XCAR (desc)));
|
0
|
130 desc = XCDR (desc);
|
|
131 if (!CONSP (desc))
|
|
132 error ("dialog boxes must have some buttons");
|
|
133
|
|
134 /* Inhibit GC during this conversion. The reasons for this are
|
|
135 the same as in menu_item_descriptor_to_widget_value(); see
|
|
136 the large comment above that function. */
|
|
137
|
|
138 record_unwind_protect (restore_gc_inhibit,
|
|
139 make_int (gc_currently_forbidden));
|
|
140 gc_currently_forbidden = 1;
|
|
141
|
|
142 kids = prev = xmalloc_widget_value ();
|
|
143
|
|
144 /* Also make sure that we free the partially-created widget_value
|
|
145 tree on Lisp error. */
|
|
146
|
|
147 wv_closure = make_opaque_ptr (kids);
|
|
148 record_unwind_protect (widget_value_unwind, wv_closure);
|
2
|
149 prev->name = (char *) "message";
|
0
|
150 prev->value = xstrdup (name);
|
|
151 prev->enabled = 1;
|
|
152
|
|
153 for (; !NILP (desc); desc = Fcdr (desc))
|
|
154 {
|
|
155 Lisp_Object button = XCAR (desc);
|
|
156 widget_value *wv;
|
|
157
|
|
158 if (NILP (button))
|
|
159 {
|
|
160 if (partition_seen)
|
|
161 error ("more than one partition (nil) seen in dbox spec");
|
|
162 partition_seen = 1;
|
|
163 continue;
|
|
164 }
|
|
165 CHECK_VECTOR (button);
|
|
166 wv = xmalloc_widget_value ();
|
|
167
|
|
168 if (!button_item_to_widget_value (button, wv, allow_text_p, 1))
|
|
169 {
|
|
170 free_widget_value (wv);
|
|
171 continue;
|
|
172 }
|
|
173
|
|
174 if (wv->type == TEXT_TYPE)
|
|
175 {
|
|
176 text_field_p = 1;
|
|
177 allow_text_p = 0; /* only allow one */
|
|
178 }
|
|
179 else /* it's a button */
|
|
180 {
|
|
181 allow_text_p = 0; /* only allow text field at the front */
|
|
182 wv->value = xstrdup (wv->name); /* what a mess... */
|
|
183 wv->name = (char *) button_names [n];
|
|
184
|
|
185 if (partition_seen)
|
|
186 rbuttons++;
|
|
187 else
|
|
188 lbuttons++;
|
|
189 n++;
|
|
190
|
|
191 if (lbuttons > 9 || rbuttons > 9)
|
|
192 error ("too many buttons (9)"); /* #### this leaks */
|
|
193 }
|
|
194
|
|
195 prev->next = wv;
|
|
196 prev = wv;
|
|
197 }
|
|
198
|
|
199 if (n == 0)
|
|
200 error ("dialog boxes must have some buttons");
|
|
201 {
|
|
202 char type = (text_field_p ? 'P' : 'Q');
|
|
203 widget_value *dbox;
|
|
204 sprintf (tmp_dbox_name, "%c%dBR%d", type, lbuttons + rbuttons, rbuttons);
|
|
205 dbox = xmalloc_widget_value ();
|
|
206 dbox->name = tmp_dbox_name;
|
|
207 dbox->contents = kids;
|
|
208
|
|
209 /* No more need to free the half-filled-in structures. */
|
|
210 set_opaque_ptr (wv_closure, 0);
|
|
211 unbind_to (count, Qnil);
|
|
212 return dbox;
|
|
213 }
|
|
214 }
|
|
215
|
20
|
216 DEFUN ("popup-dialog-box", Fpopup_dialog_box, 1, 1, 0, /*
|
0
|
217 Pop up a dialog box.
|
|
218 A dialog box description is a list.
|
|
219
|
|
220 The first element of a dialog box must be a string, which is the title or
|
|
221 question.
|
|
222
|
|
223 The rest of the elements are descriptions of the dialog box's buttons.
|
|
224 Each of these is a vector, the syntax of which is essentially the same as
|
|
225 that of popup menu items. They may have any of the following forms:
|
|
226
|
185
|
227 [ "name" callback <active-p> ]
|
|
228 [ "name" callback <active-p> "suffix" ]
|
|
229 [ "name" callback :<keyword> <value> :<keyword> <value> ... ]
|
0
|
230
|
|
231 The name is the string to display on the button; it is filtered through the
|
|
232 resource database, so it is possible for resources to override what string
|
|
233 is actually displayed.
|
|
234
|
|
235 If the `callback' of a button is a symbol, then it must name a command.
|
|
236 It will be invoked with `call-interactively'. If it is a list, then it is
|
|
237 evaluated with `eval'.
|
|
238
|
|
239 One (and only one) of the buttons may be `nil'. This marker means that all
|
|
240 following buttons should be flushright instead of flushleft.
|
|
241
|
185
|
242 Though the keyword/value syntax is supported for dialog boxes just as in
|
0
|
243 popup menus, the only keyword which is both meaningful and fully implemented
|
|
244 for dialog box buttons is `:active'.
|
20
|
245 */
|
70
|
246 (dbox_desc))
|
0
|
247 {
|
|
248 int dbox_id;
|
|
249 struct frame *f = selected_frame ();
|
|
250 widget_value *data;
|
|
251 Widget parent, dbox;
|
|
252 Lisp_Object frame = Qnil;
|
|
253
|
|
254 XSETFRAME (frame, f);
|
|
255
|
|
256 CHECK_X_FRAME (frame);
|
|
257 if (SYMBOLP (dbox_desc))
|
|
258 dbox_desc = Fsymbol_value (dbox_desc);
|
|
259 CHECK_CONS (dbox_desc);
|
|
260 CHECK_STRING (XCAR (dbox_desc));
|
|
261 data = dbox_descriptor_to_widget_value (dbox_desc);
|
|
262
|
|
263 parent = FRAME_X_SHELL_WIDGET (f);
|
|
264
|
|
265 dbox_id = new_lwlib_id ();
|
|
266 dbox = lw_create_widget (data->name, "dialog", dbox_id, data, parent, 1, 0,
|
|
267 dbox_selection_callback, 0);
|
|
268 lw_modify_all_widgets (dbox_id, data, True);
|
|
269 lw_modify_all_widgets (dbox_id, data->contents, True);
|
|
270 free_popup_widget_value_tree (data);
|
|
271
|
|
272 gcpro_popup_callbacks (dbox_id);
|
|
273
|
|
274 /* Setting zmacs-region-stays is necessary here because executing a
|
|
275 command from a dialog is really a two-command process: the first
|
|
276 command (bound to the button-click) simply pops up the dialog,
|
|
277 and returns. This causes a sequence of magic-events (destined
|
|
278 for the dialog widget) to begin. Eventually, a dialog item is
|
|
279 selected, and a misc-user-event blip is pushed onto the end of
|
|
280 the input stream, which is then executed by the event loop.
|
185
|
281
|
0
|
282 So there are two command-events, with a bunch of magic-events
|
|
283 between them. We don't want the *first* command event to alter
|
|
284 the state of the region, so that the region can be available as
|
|
285 an argument for the second command. */
|
|
286 if (zmacs_regions)
|
|
287 zmacs_region_stays = 1;
|
|
288
|
|
289 popup_up_p++;
|
|
290 lw_pop_up_all_widgets (dbox_id);
|
|
291 return Qnil;
|
|
292 }
|
|
293
|
|
294 void
|
|
295 syms_of_dialog_x (void)
|
|
296 {
|
20
|
297 DEFSUBR (Fpopup_dialog_box);
|
0
|
298 }
|
|
299
|
|
300 void
|
|
301 vars_of_dialog_x (void)
|
|
302 {
|
|
303 #if defined (LWLIB_DIALOGS_LUCID)
|
|
304 Fprovide (intern ("lucid-dialogs"));
|
|
305 #elif defined (LWLIB_DIALOGS_MOTIF)
|
|
306 Fprovide (intern ("motif-dialogs"));
|
|
307 #elif defined (LWLIB_DIALOGS_ATHENA)
|
|
308 Fprovide (intern ("athena-dialogs"));
|
|
309 #endif
|
|
310 }
|