Mercurial > hg > xemacs-beta
comparison src/dialog-x.c @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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" | |
37 #include "opaque.h" | |
38 #include "window.h" | |
39 | |
40 | |
41 static void | |
42 maybe_run_dbox_text_callback (LWLIB_ID id) | |
43 { | |
44 /* !!#### This function has not been Mule-ized */ | |
45 widget_value *wv; | |
46 int got_some; | |
47 wv = xmalloc_widget_value (); | |
48 wv->name = "value"; | |
49 got_some = lw_get_some_values (id, wv); | |
50 if (got_some) | |
51 { | |
52 Lisp_Object text_field_callback; | |
53 char *text_field_value = wv->value; | |
54 VOID_TO_LISP (text_field_callback, wv->call_data); | |
55 if (text_field_value) | |
56 { | |
57 void *tmp = LISP_TO_VOID (list2 (text_field_callback, | |
58 build_string (text_field_value))); | |
59 popup_selection_callback (0, id, (XtPointer) tmp); | |
60 xfree (text_field_value); | |
61 } | |
62 } | |
63 free_widget_value (wv); | |
64 } | |
65 | |
66 static void | |
67 dbox_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data) | |
68 { | |
69 /* This is called with client_data == -1 when WM_DELETE_WINDOW is sent | |
70 instead of a button being selected. */ | |
71 struct device *d = get_device_from_display (XtDisplay (widget)); | |
72 struct frame *f = 0; | |
73 Widget cur_widget = widget; | |
74 | |
75 /* The parent which is actually connected to our EmacsFrame may be a | |
76 ways up the tree. */ | |
77 while (!f && cur_widget) | |
78 { | |
79 f = x_any_window_to_frame (d, XtWindow (cur_widget)); | |
80 cur_widget = XtParent (cur_widget); | |
81 } | |
82 | |
83 if (popup_handled_p (id)) | |
84 return; | |
85 assert (popup_up_p != 0); | |
86 ungcpro_popup_callbacks (id); | |
87 popup_up_p--; | |
88 maybe_run_dbox_text_callback (id); | |
89 popup_selection_callback (widget, id, client_data); | |
90 lw_destroy_all_widgets (id); | |
91 | |
92 /* The Motif dialog box sets the keyboard focus to itself. When it | |
93 goes away we have to take care of getting the focus back | |
94 ourselves. */ | |
95 #ifdef EXTERNAL_WIDGET | |
96 /* #### Not sure if this special case is necessary. */ | |
97 if (!FRAME_X_EXTERNAL_WINDOW_P (f) && f) | |
98 #else | |
99 if (f) | |
100 #endif | |
101 lw_set_keyboard_focus (FRAME_X_SHELL_WIDGET (f), FRAME_X_TEXT_WIDGET (f)); | |
102 } | |
103 | |
104 static CONST char * CONST button_names [] = { | |
105 "button1", "button2", "button3", "button4", "button5", | |
106 "button6", "button7", "button8", "button9", "button10" }; | |
107 | |
108 /* can't have static frame locals because of some broken compilers */ | |
109 static char tmp_dbox_name [255]; | |
110 | |
111 static widget_value * | |
112 dbox_descriptor_to_widget_value (Lisp_Object desc) | |
113 { | |
114 /* !!#### This function has not been Mule-ized */ | |
115 /* This function can GC */ | |
116 char *name; | |
117 int lbuttons = 0, rbuttons = 0; | |
118 int partition_seen = 0; | |
119 int text_field_p = 0; | |
120 int allow_text_p = 1; | |
121 widget_value *prev = 0, *kids = 0; | |
122 int n = 0; | |
123 int count = specpdl_depth (); | |
124 Lisp_Object wv_closure; | |
125 | |
126 CHECK_CONS (desc); | |
127 CHECK_STRING (XCAR (desc)); | |
128 name = (char *) string_data (XSTRING (LISP_GETTEXT (XCAR (desc)))); | |
129 desc = XCDR (desc); | |
130 if (!CONSP (desc)) | |
131 error ("dialog boxes must have some buttons"); | |
132 | |
133 /* Inhibit GC during this conversion. The reasons for this are | |
134 the same as in menu_item_descriptor_to_widget_value(); see | |
135 the large comment above that function. */ | |
136 | |
137 record_unwind_protect (restore_gc_inhibit, | |
138 make_int (gc_currently_forbidden)); | |
139 gc_currently_forbidden = 1; | |
140 | |
141 kids = prev = xmalloc_widget_value (); | |
142 | |
143 /* Also make sure that we free the partially-created widget_value | |
144 tree on Lisp error. */ | |
145 | |
146 wv_closure = make_opaque_ptr (kids); | |
147 record_unwind_protect (widget_value_unwind, wv_closure); | |
148 prev->name = "message"; | |
149 prev->value = xstrdup (name); | |
150 prev->enabled = 1; | |
151 | |
152 for (; !NILP (desc); desc = Fcdr (desc)) | |
153 { | |
154 Lisp_Object button = XCAR (desc); | |
155 widget_value *wv; | |
156 | |
157 if (NILP (button)) | |
158 { | |
159 if (partition_seen) | |
160 error ("more than one partition (nil) seen in dbox spec"); | |
161 partition_seen = 1; | |
162 continue; | |
163 } | |
164 CHECK_VECTOR (button); | |
165 wv = xmalloc_widget_value (); | |
166 | |
167 if (!button_item_to_widget_value (button, wv, allow_text_p, 1)) | |
168 { | |
169 free_widget_value (wv); | |
170 continue; | |
171 } | |
172 | |
173 if (wv->type == TEXT_TYPE) | |
174 { | |
175 text_field_p = 1; | |
176 allow_text_p = 0; /* only allow one */ | |
177 } | |
178 else /* it's a button */ | |
179 { | |
180 allow_text_p = 0; /* only allow text field at the front */ | |
181 wv->value = xstrdup (wv->name); /* what a mess... */ | |
182 wv->name = (char *) button_names [n]; | |
183 | |
184 if (partition_seen) | |
185 rbuttons++; | |
186 else | |
187 lbuttons++; | |
188 n++; | |
189 | |
190 if (lbuttons > 9 || rbuttons > 9) | |
191 error ("too many buttons (9)"); /* #### this leaks */ | |
192 } | |
193 | |
194 prev->next = wv; | |
195 prev = wv; | |
196 } | |
197 | |
198 if (n == 0) | |
199 error ("dialog boxes must have some buttons"); | |
200 { | |
201 char type = (text_field_p ? 'P' : 'Q'); | |
202 widget_value *dbox; | |
203 sprintf (tmp_dbox_name, "%c%dBR%d", type, lbuttons + rbuttons, rbuttons); | |
204 dbox = xmalloc_widget_value (); | |
205 dbox->name = tmp_dbox_name; | |
206 dbox->contents = kids; | |
207 | |
208 /* No more need to free the half-filled-in structures. */ | |
209 set_opaque_ptr (wv_closure, 0); | |
210 unbind_to (count, Qnil); | |
211 return dbox; | |
212 } | |
213 } | |
214 | |
215 DEFUN ("popup-dialog-box", Fpopup_dialog_box, Spopup_dialog_box, 1, 1, 0 /* | |
216 Pop up a dialog box. | |
217 A dialog box description is a list. | |
218 | |
219 The first element of a dialog box must be a string, which is the title or | |
220 question. | |
221 | |
222 The rest of the elements are descriptions of the dialog box's buttons. | |
223 Each of these is a vector, the syntax of which is essentially the same as | |
224 that of popup menu items. They may have any of the following forms: | |
225 | |
226 [ \"name\" callback <active-p> ] | |
227 [ \"name\" callback <active-p> \"suffix\" ] | |
228 [ \"name\" callback :<keyword> <value> :<keyword> <value> ... ] | |
229 | |
230 The name is the string to display on the button; it is filtered through the | |
231 resource database, so it is possible for resources to override what string | |
232 is actually displayed. | |
233 | |
234 If the `callback' of a button is a symbol, then it must name a command. | |
235 It will be invoked with `call-interactively'. If it is a list, then it is | |
236 evaluated with `eval'. | |
237 | |
238 One (and only one) of the buttons may be `nil'. This marker means that all | |
239 following buttons should be flushright instead of flushleft. | |
240 | |
241 Though the keyword/value syntax is supported for dialog boxes just as in | |
242 popup menus, the only keyword which is both meaningful and fully implemented | |
243 for dialog box buttons is `:active'. | |
244 */ ) | |
245 (dbox_desc) | |
246 Lisp_Object dbox_desc; | |
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. | |
281 | |
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 { | |
297 defsubr (&Spopup_dialog_box); | |
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 } |