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.
5 This file is part of XEmacs.
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
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
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. */
22 /* Synched up with: Not in FSF. */
27 #include "console-x.h"
28 #include "EmacsManager.h"
29 #include "EmacsFrame.h"
30 #include "EmacsShell.h"
34 #include "commands.h" /* zmacs_regions */
43 maybe_run_dbox_text_callback (LWLIB_ID id)
45 /* !!#### This function has not been Mule-ized */
48 wv = xmalloc_widget_value ();
49 wv->name = (char *) "value";
50 got_some = lw_get_some_values (id, wv);
53 Lisp_Object text_field_callback;
54 char *text_field_value = wv->value;
55 VOID_TO_LISP (text_field_callback, wv->call_data);
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);
64 free_widget_value (wv);
68 dbox_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
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));
74 Widget cur_widget = widget;
76 /* The parent which is actually connected to our EmacsFrame may be a
78 while (!f && cur_widget)
80 f = x_any_window_to_frame (d, XtWindow (cur_widget));
81 cur_widget = XtParent (cur_widget);
84 if (popup_handled_p (id))
86 assert (popup_up_p != 0);
87 ungcpro_popup_callbacks (id);
89 maybe_run_dbox_text_callback (id);
90 popup_selection_callback (widget, id, client_data);
91 lw_destroy_all_widgets (id);
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
96 #ifdef EXTERNAL_WIDGET
97 /* #### Not sure if this special case is necessary. */
98 if (!FRAME_X_EXTERNAL_WINDOW_P (f) && f)
102 lw_set_keyboard_focus (FRAME_X_SHELL_WIDGET (f), FRAME_X_TEXT_WIDGET (f));
105 static CONST char * CONST button_names [] = {
106 "button1", "button2", "button3", "button4", "button5",
107 "button6", "button7", "button8", "button9", "button10" };
109 /* can't have static frame locals because of some broken compilers */
110 static char tmp_dbox_name [255];
112 static widget_value *
113 dbox_descriptor_to_widget_value (Lisp_Object desc)
115 /* !!#### This function has not been Mule-ized */
116 /* This function can GC */
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;
124 int count = specpdl_depth ();
125 Lisp_Object wv_closure;
128 CHECK_STRING (XCAR (desc));
129 name = (char *) XSTRING_DATA (LISP_GETTEXT (XCAR (desc)));
132 error ("dialog boxes must have some buttons");
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. */
138 record_unwind_protect (restore_gc_inhibit,
139 make_int (gc_currently_forbidden));
140 gc_currently_forbidden = 1;
142 kids = prev = xmalloc_widget_value ();
144 /* Also make sure that we free the partially-created widget_value
145 tree on Lisp error. */
147 wv_closure = make_opaque_ptr (kids);
148 record_unwind_protect (widget_value_unwind, wv_closure);
149 prev->name = (char *) "message";
150 prev->value = xstrdup (name);
153 for (; !NILP (desc); desc = Fcdr (desc))
155 Lisp_Object button = XCAR (desc);
161 error ("more than one partition (nil) seen in dbox spec");
165 CHECK_VECTOR (button);
166 wv = xmalloc_widget_value ();
168 if (!button_item_to_widget_value (button, wv, allow_text_p, 1))
170 free_widget_value (wv);
174 if (wv->type == TEXT_TYPE)
177 allow_text_p = 0; /* only allow one */
179 else /* it's a button */
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];
191 if (lbuttons > 9 || rbuttons > 9)
192 error ("too many buttons (9)"); /* #### this leaks */
200 error ("dialog boxes must have some buttons");
202 char type = (text_field_p ? 'P' : 'Q');
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;
209 /* No more need to free the half-filled-in structures. */
210 set_opaque_ptr (wv_closure, 0);
211 unbind_to (count, Qnil);
217 x_popup_dialog_box (struct frame* f, Lisp_Object dbox_desc)
223 data = dbox_descriptor_to_widget_value (dbox_desc);
225 parent = FRAME_X_SHELL_WIDGET (f);
227 dbox_id = new_lwlib_id ();
228 dbox = lw_create_widget (data->name, "dialog", dbox_id, data, parent, 1, 0,
229 dbox_selection_callback, 0);
230 lw_modify_all_widgets (dbox_id, data, True);
231 lw_modify_all_widgets (dbox_id, data->contents, True);
232 free_popup_widget_value_tree (data);
234 gcpro_popup_callbacks (dbox_id);
236 /* Setting zmacs-region-stays is necessary here because executing a
237 command from a dialog is really a two-command process: the first
238 command (bound to the button-click) simply pops up the dialog,
239 and returns. This causes a sequence of magic-events (destined
240 for the dialog widget) to begin. Eventually, a dialog item is
241 selected, and a misc-user-event blip is pushed onto the end of
242 the input stream, which is then executed by the event loop.
244 So there are two command-events, with a bunch of magic-events
245 between them. We don't want the *first* command event to alter
246 the state of the region, so that the region can be available as
247 an argument for the second command. */
249 zmacs_region_stays = 1;
252 lw_pop_up_all_widgets (dbox_id);
256 syms_of_dialog_x (void)
261 console_type_create_dialog_x (void)
263 CONSOLE_HAS_METHOD (x, popup_dialog_box);
267 vars_of_dialog_x (void)
269 #if defined (LWLIB_DIALOGS_LUCID)
270 Fprovide (intern ("lucid-dialogs"));
271 #elif defined (LWLIB_DIALOGS_MOTIF)
272 Fprovide (intern ("motif-dialogs"));
273 #elif defined (LWLIB_DIALOGS_ATHENA)
274 Fprovide (intern ("athena-dialogs"));