d9b15094 |
1 | /* |
2 | * gtkdlg.c - GTK implementation of the PuTTY configuration box. |
3 | */ |
4 | |
1d0d4a3b |
5 | /* |
1c291fcf |
6 | * TODO when porting to GTK 2.0: |
7 | * |
8 | * - GtkTree is apparently deprecated and we should switch to |
9 | * GtkTreeView instead. |
10 | * - GtkLabel has a built-in mnemonic scheme, so we should at |
11 | * least consider switching to that from the current adhockery. |
1d0d4a3b |
12 | */ |
13 | |
d9b15094 |
14 | #include <assert.h> |
5bf9955d |
15 | #include <stdarg.h> |
1c291fcf |
16 | #include <ctype.h> |
d9b15094 |
17 | #include <gtk/gtk.h> |
1c291fcf |
18 | #include <gdk/gdkkeysyms.h> |
0bd8d76d |
19 | #include <gdk/gdkx.h> |
20 | #include <X11/Xlib.h> |
21 | #include <X11/Xutil.h> |
d9b15094 |
22 | |
23 | #include "gtkcols.h" |
24 | #include "gtkpanel.h" |
25 | |
26 | #ifdef TESTMODE |
27 | #define PUTTY_DO_GLOBALS /* actually _define_ globals */ |
28 | #endif |
29 | |
30 | #include "putty.h" |
5bf9955d |
31 | #include "storage.h" |
d9b15094 |
32 | #include "dialog.h" |
0f5e1f75 |
33 | #include "tree234.h" |
34 | |
1c291fcf |
35 | struct Shortcut { |
36 | GtkWidget *widget; |
37 | struct uctrl *uc; |
38 | int action; |
39 | }; |
40 | |
41 | struct Shortcuts { |
42 | struct Shortcut sc[128]; |
43 | }; |
44 | |
0f5e1f75 |
45 | struct uctrl { |
46 | union control *ctrl; |
47 | GtkWidget *toplevel; |
48 | void *privdata; |
49 | int privdata_needs_free; |
50 | GtkWidget **buttons; int nbuttons; /* for radio buttons */ |
51 | GtkWidget *entry; /* for editbox, combobox, filesel, fontsel */ |
1c291fcf |
52 | GtkWidget *button; /* for filesel, fontsel */ |
0f5e1f75 |
53 | GtkWidget *list; /* for combobox, listbox */ |
54 | GtkWidget *menu; /* for optionmenu (==droplist) */ |
55 | GtkWidget *optmenu; /* also for optionmenu */ |
56 | GtkWidget *text; /* for text */ |
0bd8d76d |
57 | GtkAdjustment *adj; /* for the scrollbar in a list box */ |
c5d64b49 |
58 | guint textsig; |
0f5e1f75 |
59 | }; |
60 | |
61 | struct dlgparam { |
62 | tree234 *byctrl, *bywidget; |
63 | void *data; |
64 | struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */ |
65 | /* `flags' are set to indicate when a GTK signal handler is being called |
66 | * due to automatic processing and should not flag a user event. */ |
67 | int flags; |
1c291fcf |
68 | struct Shortcuts *shortcuts; |
23897ed0 |
69 | GtkWidget *window, *cancelbutton, *currtreeitem, **treeitems; |
0bd8d76d |
70 | union control *currfocus, *lastfocus; |
71 | int ntreeitems; |
72 | int retval; |
0f5e1f75 |
73 | }; |
74 | #define FLAG_UPDATING_COMBO_LIST 1 |
75 | |
1c291fcf |
76 | enum { /* values for Shortcut.action */ |
77 | SHORTCUT_EMPTY, /* no shortcut on this key */ |
c5d64b49 |
78 | SHORTCUT_TREE, /* focus a tree item */ |
1c291fcf |
79 | SHORTCUT_FOCUS, /* focus the supplied widget */ |
80 | SHORTCUT_UCTRL, /* do something sane with uctrl */ |
81 | SHORTCUT_UCTRL_UP, /* uctrl is a draglist, move Up */ |
82 | SHORTCUT_UCTRL_DOWN, /* uctrl is a draglist, move Down */ |
83 | }; |
84 | |
0f5e1f75 |
85 | /* |
86 | * Forward references. |
87 | */ |
0bd8d76d |
88 | static gboolean widget_focus(GtkWidget *widget, GdkEventFocus *event, |
89 | gpointer data); |
1c291fcf |
90 | static void shortcut_add(struct Shortcuts *scs, GtkWidget *labelw, |
91 | int chr, int action, void *ptr); |
0bd8d76d |
92 | static int listitem_single_key(GtkWidget *item, GdkEventKey *event, |
93 | gpointer data); |
94 | static int listitem_multi_key(GtkWidget *item, GdkEventKey *event, |
95 | gpointer data); |
96 | static int listitem_button(GtkWidget *item, GdkEventButton *event, |
0f5e1f75 |
97 | gpointer data); |
98 | static void menuitem_activate(GtkMenuItem *item, gpointer data); |
99 | static void coloursel_ok(GtkButton *button, gpointer data); |
100 | static void coloursel_cancel(GtkButton *button, gpointer data); |
0bd8d76d |
101 | static void window_destroy(GtkWidget *widget, gpointer data); |
0f5e1f75 |
102 | |
103 | static int uctrl_cmp_byctrl(void *av, void *bv) |
104 | { |
105 | struct uctrl *a = (struct uctrl *)av; |
106 | struct uctrl *b = (struct uctrl *)bv; |
107 | if (a->ctrl < b->ctrl) |
108 | return -1; |
109 | else if (a->ctrl > b->ctrl) |
110 | return +1; |
111 | return 0; |
112 | } |
113 | |
114 | static int uctrl_cmp_byctrl_find(void *av, void *bv) |
115 | { |
116 | union control *a = (union control *)av; |
117 | struct uctrl *b = (struct uctrl *)bv; |
118 | if (a < b->ctrl) |
119 | return -1; |
120 | else if (a > b->ctrl) |
121 | return +1; |
122 | return 0; |
123 | } |
124 | |
125 | static int uctrl_cmp_bywidget(void *av, void *bv) |
126 | { |
127 | struct uctrl *a = (struct uctrl *)av; |
128 | struct uctrl *b = (struct uctrl *)bv; |
129 | if (a->toplevel < b->toplevel) |
130 | return -1; |
131 | else if (a->toplevel > b->toplevel) |
132 | return +1; |
133 | return 0; |
134 | } |
135 | |
136 | static int uctrl_cmp_bywidget_find(void *av, void *bv) |
137 | { |
138 | GtkWidget *a = (GtkWidget *)av; |
139 | struct uctrl *b = (struct uctrl *)bv; |
140 | if (a < b->toplevel) |
141 | return -1; |
142 | else if (a > b->toplevel) |
143 | return +1; |
144 | return 0; |
145 | } |
146 | |
147 | static void dlg_init(struct dlgparam *dp) |
148 | { |
149 | dp->byctrl = newtree234(uctrl_cmp_byctrl); |
150 | dp->bywidget = newtree234(uctrl_cmp_bywidget); |
151 | dp->coloursel_result.ok = FALSE; |
5bf9955d |
152 | dp->treeitems = NULL; |
153 | dp->window = dp->cancelbutton = dp->currtreeitem = NULL; |
0f5e1f75 |
154 | } |
155 | |
156 | static void dlg_cleanup(struct dlgparam *dp) |
157 | { |
158 | struct uctrl *uc; |
159 | |
160 | freetree234(dp->byctrl); /* doesn't free the uctrls inside */ |
161 | while ( (uc = index234(dp->bywidget, 0)) != NULL) { |
162 | del234(dp->bywidget, uc); |
163 | if (uc->privdata_needs_free) |
164 | sfree(uc->privdata); |
165 | sfree(uc->buttons); |
166 | sfree(uc); |
167 | } |
168 | freetree234(dp->bywidget); |
0bd8d76d |
169 | sfree(dp->treeitems); |
0f5e1f75 |
170 | } |
171 | |
172 | static void dlg_add_uctrl(struct dlgparam *dp, struct uctrl *uc) |
173 | { |
174 | add234(dp->byctrl, uc); |
175 | add234(dp->bywidget, uc); |
176 | } |
177 | |
178 | static struct uctrl *dlg_find_byctrl(struct dlgparam *dp, union control *ctrl) |
179 | { |
180 | return find234(dp->byctrl, ctrl, uctrl_cmp_byctrl_find); |
181 | } |
182 | |
183 | static struct uctrl *dlg_find_bywidget(struct dlgparam *dp, GtkWidget *w) |
184 | { |
185 | struct uctrl *ret = NULL; |
186 | do { |
187 | ret = find234(dp->bywidget, w, uctrl_cmp_bywidget_find); |
188 | if (ret) |
189 | return ret; |
190 | w = w->parent; |
191 | } while (w); |
192 | return ret; |
193 | } |
d9b15094 |
194 | |
d9b15094 |
195 | void *dlg_get_privdata(union control *ctrl, void *dlg) |
196 | { |
0f5e1f75 |
197 | struct dlgparam *dp = (struct dlgparam *)dlg; |
198 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
199 | return uc->privdata; |
d9b15094 |
200 | } |
201 | |
202 | void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr) |
203 | { |
0f5e1f75 |
204 | struct dlgparam *dp = (struct dlgparam *)dlg; |
205 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
206 | uc->privdata = ptr; |
207 | uc->privdata_needs_free = FALSE; |
d9b15094 |
208 | } |
209 | |
210 | void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size) |
211 | { |
0f5e1f75 |
212 | struct dlgparam *dp = (struct dlgparam *)dlg; |
213 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
3d88e64d |
214 | /* |
215 | * This is an internal allocation routine, so it's allowed to |
216 | * use smalloc directly. |
217 | */ |
0f5e1f75 |
218 | uc->privdata = smalloc(size); |
219 | uc->privdata_needs_free = FALSE; |
220 | return uc->privdata; |
d9b15094 |
221 | } |
222 | |
0bd8d76d |
223 | union control *dlg_last_focused(union control *ctrl, void *dlg) |
d9b15094 |
224 | { |
0f5e1f75 |
225 | struct dlgparam *dp = (struct dlgparam *)dlg; |
0bd8d76d |
226 | if (dp->currfocus != ctrl) |
227 | return dp->currfocus; |
228 | else |
229 | return dp->lastfocus; |
d9b15094 |
230 | } |
231 | |
0f5e1f75 |
232 | void dlg_radiobutton_set(union control *ctrl, void *dlg, int which) |
d9b15094 |
233 | { |
0f5e1f75 |
234 | struct dlgparam *dp = (struct dlgparam *)dlg; |
235 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
236 | assert(uc->ctrl->generic.type == CTRL_RADIO); |
237 | assert(uc->buttons != NULL); |
238 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(uc->buttons[which]), TRUE); |
d9b15094 |
239 | } |
240 | |
241 | int dlg_radiobutton_get(union control *ctrl, void *dlg) |
242 | { |
0f5e1f75 |
243 | struct dlgparam *dp = (struct dlgparam *)dlg; |
244 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
245 | int i; |
246 | |
247 | assert(uc->ctrl->generic.type == CTRL_RADIO); |
248 | assert(uc->buttons != NULL); |
249 | for (i = 0; i < uc->nbuttons; i++) |
250 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(uc->buttons[i]))) |
251 | return i; |
252 | return 0; /* got to return something */ |
d9b15094 |
253 | } |
254 | |
255 | void dlg_checkbox_set(union control *ctrl, void *dlg, int checked) |
256 | { |
0f5e1f75 |
257 | struct dlgparam *dp = (struct dlgparam *)dlg; |
258 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
259 | assert(uc->ctrl->generic.type == CTRL_CHECKBOX); |
260 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(uc->toplevel), checked); |
d9b15094 |
261 | } |
262 | |
263 | int dlg_checkbox_get(union control *ctrl, void *dlg) |
264 | { |
0f5e1f75 |
265 | struct dlgparam *dp = (struct dlgparam *)dlg; |
266 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
267 | assert(uc->ctrl->generic.type == CTRL_CHECKBOX); |
268 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(uc->toplevel)); |
d9b15094 |
269 | } |
270 | |
271 | void dlg_editbox_set(union control *ctrl, void *dlg, char const *text) |
272 | { |
0f5e1f75 |
273 | struct dlgparam *dp = (struct dlgparam *)dlg; |
274 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
275 | assert(uc->ctrl->generic.type == CTRL_EDITBOX); |
276 | assert(uc->entry != NULL); |
277 | gtk_entry_set_text(GTK_ENTRY(uc->entry), text); |
d9b15094 |
278 | } |
279 | |
280 | void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length) |
281 | { |
0f5e1f75 |
282 | struct dlgparam *dp = (struct dlgparam *)dlg; |
283 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
284 | assert(uc->ctrl->generic.type == CTRL_EDITBOX); |
285 | assert(uc->entry != NULL); |
286 | strncpy(buffer, gtk_entry_get_text(GTK_ENTRY(uc->entry)), |
287 | length); |
288 | buffer[length-1] = '\0'; |
289 | } |
290 | |
291 | static void container_remove_and_destroy(GtkWidget *w, gpointer data) |
292 | { |
293 | GtkContainer *cont = GTK_CONTAINER(data); |
294 | /* gtk_container_remove will unref the widget for us; we need not. */ |
295 | gtk_container_remove(cont, w); |
d9b15094 |
296 | } |
297 | |
298 | /* The `listbox' functions can also apply to combo boxes. */ |
299 | void dlg_listbox_clear(union control *ctrl, void *dlg) |
300 | { |
0f5e1f75 |
301 | struct dlgparam *dp = (struct dlgparam *)dlg; |
302 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
303 | GtkContainer *cont; |
304 | |
305 | assert(uc->ctrl->generic.type == CTRL_EDITBOX || |
306 | uc->ctrl->generic.type == CTRL_LISTBOX); |
307 | assert(uc->menu != NULL || uc->list != NULL); |
308 | |
309 | cont = (uc->menu ? GTK_CONTAINER(uc->menu) : GTK_CONTAINER(uc->list)); |
310 | |
311 | gtk_container_foreach(cont, container_remove_and_destroy, cont); |
d9b15094 |
312 | } |
313 | |
314 | void dlg_listbox_del(union control *ctrl, void *dlg, int index) |
315 | { |
0f5e1f75 |
316 | struct dlgparam *dp = (struct dlgparam *)dlg; |
317 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
318 | |
319 | assert(uc->ctrl->generic.type == CTRL_EDITBOX || |
320 | uc->ctrl->generic.type == CTRL_LISTBOX); |
321 | assert(uc->menu != NULL || uc->list != NULL); |
322 | |
323 | if (uc->menu) { |
324 | gtk_container_remove |
325 | (GTK_CONTAINER(uc->menu), |
326 | g_list_nth_data(GTK_MENU_SHELL(uc->menu)->children, index)); |
327 | } else { |
328 | gtk_list_clear_items(GTK_LIST(uc->list), index, index+1); |
329 | } |
d9b15094 |
330 | } |
331 | |
332 | void dlg_listbox_add(union control *ctrl, void *dlg, char const *text) |
333 | { |
4eaff8d4 |
334 | dlg_listbox_addwithid(ctrl, dlg, text, 0); |
d9b15094 |
335 | } |
336 | |
337 | /* |
338 | * Each listbox entry may have a numeric id associated with it. |
339 | * Note that some front ends only permit a string to be stored at |
340 | * each position, which means that _if_ you put two identical |
341 | * strings in any listbox then you MUST not assign them different |
342 | * IDs and expect to get meaningful results back. |
343 | */ |
4eaff8d4 |
344 | void dlg_listbox_addwithid(union control *ctrl, void *dlg, |
345 | char const *text, int id) |
d9b15094 |
346 | { |
0f5e1f75 |
347 | struct dlgparam *dp = (struct dlgparam *)dlg; |
348 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
349 | |
350 | assert(uc->ctrl->generic.type == CTRL_EDITBOX || |
351 | uc->ctrl->generic.type == CTRL_LISTBOX); |
352 | assert(uc->menu != NULL || uc->list != NULL); |
353 | |
354 | dp->flags |= FLAG_UPDATING_COMBO_LIST; |
355 | |
356 | if (uc->menu) { |
357 | /* |
358 | * List item in a drop-down (but non-combo) list. Tabs are |
359 | * ignored; we just provide a standard menu item with the |
360 | * text. |
361 | */ |
362 | GtkWidget *menuitem = gtk_menu_item_new_with_label(text); |
363 | |
364 | gtk_container_add(GTK_CONTAINER(uc->menu), menuitem); |
365 | gtk_widget_show(menuitem); |
366 | |
367 | gtk_object_set_data(GTK_OBJECT(menuitem), "user-data", (gpointer)id); |
368 | gtk_signal_connect(GTK_OBJECT(menuitem), "activate", |
369 | GTK_SIGNAL_FUNC(menuitem_activate), dp); |
370 | } else if (!uc->entry) { |
371 | /* |
372 | * List item in a non-combo-box list box. We make all of |
373 | * these Columns containing GtkLabels. This allows us to do |
374 | * the nasty force_left hack irrespective of whether there |
375 | * are tabs in the thing. |
376 | */ |
377 | GtkWidget *listitem = gtk_list_item_new(); |
523fd1da |
378 | GtkWidget *cols = columns_new(10); |
0f5e1f75 |
379 | gint *percents; |
380 | int i, ncols; |
381 | |
382 | /* Count the tabs in the text, and hence determine # of columns. */ |
383 | ncols = 1; |
384 | for (i = 0; text[i]; i++) |
385 | if (text[i] == '\t') |
386 | ncols++; |
387 | |
388 | assert(ncols <= |
389 | (uc->ctrl->listbox.ncols ? uc->ctrl->listbox.ncols : 1)); |
3d88e64d |
390 | percents = snewn(ncols, gint); |
0f5e1f75 |
391 | percents[ncols-1] = 100; |
392 | for (i = 0; i < ncols-1; i++) { |
393 | percents[i] = uc->ctrl->listbox.percentages[i]; |
394 | percents[ncols-1] -= percents[i]; |
395 | } |
396 | columns_set_cols(COLUMNS(cols), ncols, percents); |
397 | sfree(percents); |
398 | |
399 | for (i = 0; i < ncols; i++) { |
400 | int len = strcspn(text, "\t"); |
401 | char *dup = dupprintf("%.*s", len, text); |
402 | GtkWidget *label; |
403 | |
404 | text += len; |
405 | if (*text) text++; |
406 | label = gtk_label_new(dup); |
407 | sfree(dup); |
408 | |
409 | columns_add(COLUMNS(cols), label, i, 1); |
410 | columns_force_left_align(COLUMNS(cols), label); |
411 | gtk_widget_show(label); |
412 | } |
413 | gtk_container_add(GTK_CONTAINER(listitem), cols); |
414 | gtk_widget_show(cols); |
415 | gtk_container_add(GTK_CONTAINER(uc->list), listitem); |
416 | gtk_widget_show(listitem); |
417 | |
0bd8d76d |
418 | if (ctrl->listbox.multisel) { |
419 | gtk_signal_connect(GTK_OBJECT(listitem), "key_press_event", |
420 | GTK_SIGNAL_FUNC(listitem_multi_key), uc->adj); |
421 | } else { |
422 | gtk_signal_connect(GTK_OBJECT(listitem), "key_press_event", |
423 | GTK_SIGNAL_FUNC(listitem_single_key), uc->adj); |
424 | } |
425 | gtk_signal_connect(GTK_OBJECT(listitem), "focus_in_event", |
426 | GTK_SIGNAL_FUNC(widget_focus), dp); |
0f5e1f75 |
427 | gtk_signal_connect(GTK_OBJECT(listitem), "button_press_event", |
428 | GTK_SIGNAL_FUNC(listitem_button), dp); |
429 | gtk_object_set_data(GTK_OBJECT(listitem), "user-data", (gpointer)id); |
430 | } else { |
431 | /* |
432 | * List item in a combo-box list, which means the sensible |
433 | * thing to do is make it a perfectly normal label. Hence |
434 | * tabs are disregarded. |
435 | */ |
436 | GtkWidget *listitem = gtk_list_item_new_with_label(text); |
437 | |
438 | gtk_container_add(GTK_CONTAINER(uc->list), listitem); |
439 | gtk_widget_show(listitem); |
440 | |
441 | gtk_object_set_data(GTK_OBJECT(listitem), "user-data", (gpointer)id); |
442 | } |
443 | |
444 | dp->flags &= ~FLAG_UPDATING_COMBO_LIST; |
d9b15094 |
445 | } |
446 | |
447 | int dlg_listbox_getid(union control *ctrl, void *dlg, int index) |
448 | { |
0f5e1f75 |
449 | struct dlgparam *dp = (struct dlgparam *)dlg; |
450 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
451 | GList *children; |
452 | GtkObject *item; |
453 | |
454 | assert(uc->ctrl->generic.type == CTRL_EDITBOX || |
455 | uc->ctrl->generic.type == CTRL_LISTBOX); |
456 | assert(uc->menu != NULL || uc->list != NULL); |
457 | |
458 | children = gtk_container_children(GTK_CONTAINER(uc->menu ? uc->menu : |
459 | uc->list)); |
460 | item = GTK_OBJECT(g_list_nth_data(children, index)); |
0bd8d76d |
461 | g_list_free(children); |
0f5e1f75 |
462 | |
463 | return (int)gtk_object_get_data(GTK_OBJECT(item), "user-data"); |
d9b15094 |
464 | } |
465 | |
466 | /* dlg_listbox_index returns <0 if no single element is selected. */ |
467 | int dlg_listbox_index(union control *ctrl, void *dlg) |
468 | { |
0f5e1f75 |
469 | struct dlgparam *dp = (struct dlgparam *)dlg; |
470 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
471 | GList *children; |
472 | GtkWidget *item, *activeitem; |
473 | int i; |
474 | int selected = -1; |
475 | |
476 | assert(uc->ctrl->generic.type == CTRL_EDITBOX || |
477 | uc->ctrl->generic.type == CTRL_LISTBOX); |
478 | assert(uc->menu != NULL || uc->list != NULL); |
479 | |
480 | if (uc->menu) |
481 | activeitem = gtk_menu_get_active(GTK_MENU(uc->menu)); |
482 | |
483 | children = gtk_container_children(GTK_CONTAINER(uc->menu ? uc->menu : |
484 | uc->list)); |
485 | for (i = 0; children!=NULL && (item = GTK_WIDGET(children->data))!=NULL; |
486 | i++, children = children->next) { |
487 | if (uc->menu ? activeitem == item : |
488 | GTK_WIDGET_STATE(item) == GTK_STATE_SELECTED) { |
0bd8d76d |
489 | if (selected == -1) |
0f5e1f75 |
490 | selected = i; |
491 | else |
0bd8d76d |
492 | selected = -2; |
0f5e1f75 |
493 | } |
494 | } |
0bd8d76d |
495 | g_list_free(children); |
496 | return selected < 0 ? -1 : selected; |
d9b15094 |
497 | } |
498 | |
499 | int dlg_listbox_issel(union control *ctrl, void *dlg, int index) |
500 | { |
0f5e1f75 |
501 | struct dlgparam *dp = (struct dlgparam *)dlg; |
502 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
503 | GList *children; |
504 | GtkWidget *item, *activeitem; |
505 | |
506 | assert(uc->ctrl->generic.type == CTRL_EDITBOX || |
507 | uc->ctrl->generic.type == CTRL_LISTBOX); |
508 | assert(uc->menu != NULL || uc->list != NULL); |
509 | |
510 | children = gtk_container_children(GTK_CONTAINER(uc->menu ? uc->menu : |
511 | uc->list)); |
512 | item = GTK_WIDGET(g_list_nth_data(children, index)); |
0bd8d76d |
513 | g_list_free(children); |
0f5e1f75 |
514 | |
515 | if (uc->menu) { |
516 | activeitem = gtk_menu_get_active(GTK_MENU(uc->menu)); |
517 | return item == activeitem; |
518 | } else { |
519 | return GTK_WIDGET_STATE(item) == GTK_STATE_SELECTED; |
520 | } |
d9b15094 |
521 | } |
522 | |
523 | void dlg_listbox_select(union control *ctrl, void *dlg, int index) |
524 | { |
0f5e1f75 |
525 | struct dlgparam *dp = (struct dlgparam *)dlg; |
526 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
527 | |
528 | assert(uc->ctrl->generic.type == CTRL_EDITBOX || |
529 | uc->ctrl->generic.type == CTRL_LISTBOX); |
530 | assert(uc->optmenu != NULL || uc->list != NULL); |
531 | |
532 | if (uc->optmenu) { |
533 | gtk_option_menu_set_history(GTK_OPTION_MENU(uc->optmenu), index); |
534 | } else { |
535 | gtk_list_select_item(GTK_LIST(uc->list), index); |
536 | } |
d9b15094 |
537 | } |
538 | |
539 | void dlg_text_set(union control *ctrl, void *dlg, char const *text) |
540 | { |
0f5e1f75 |
541 | struct dlgparam *dp = (struct dlgparam *)dlg; |
542 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
543 | |
544 | assert(uc->ctrl->generic.type == CTRL_TEXT); |
545 | assert(uc->text != NULL); |
546 | |
547 | gtk_label_set_text(GTK_LABEL(uc->text), text); |
d9b15094 |
548 | } |
549 | |
550 | void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn) |
551 | { |
0f5e1f75 |
552 | struct dlgparam *dp = (struct dlgparam *)dlg; |
553 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
554 | assert(uc->ctrl->generic.type == CTRL_FILESELECT); |
555 | assert(uc->entry != NULL); |
556 | gtk_entry_set_text(GTK_ENTRY(uc->entry), fn.path); |
d9b15094 |
557 | } |
558 | |
559 | void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn) |
560 | { |
0f5e1f75 |
561 | struct dlgparam *dp = (struct dlgparam *)dlg; |
562 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
563 | assert(uc->ctrl->generic.type == CTRL_FILESELECT); |
564 | assert(uc->entry != NULL); |
565 | strncpy(fn->path, gtk_entry_get_text(GTK_ENTRY(uc->entry)), |
566 | lenof(fn->path)); |
567 | fn->path[lenof(fn->path)-1] = '\0'; |
d9b15094 |
568 | } |
569 | |
570 | void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fs) |
571 | { |
0f5e1f75 |
572 | struct dlgparam *dp = (struct dlgparam *)dlg; |
573 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
574 | assert(uc->ctrl->generic.type == CTRL_FONTSELECT); |
575 | assert(uc->entry != NULL); |
576 | gtk_entry_set_text(GTK_ENTRY(uc->entry), fs.name); |
d9b15094 |
577 | } |
578 | |
579 | void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fs) |
580 | { |
0f5e1f75 |
581 | struct dlgparam *dp = (struct dlgparam *)dlg; |
582 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
583 | assert(uc->ctrl->generic.type == CTRL_FONTSELECT); |
584 | assert(uc->entry != NULL); |
585 | strncpy(fs->name, gtk_entry_get_text(GTK_ENTRY(uc->entry)), |
586 | lenof(fs->name)); |
587 | fs->name[lenof(fs->name)-1] = '\0'; |
d9b15094 |
588 | } |
589 | |
590 | /* |
591 | * Bracketing a large set of updates in these two functions will |
592 | * cause the front end (if possible) to delay updating the screen |
593 | * until it's all complete, thus avoiding flicker. |
594 | */ |
595 | void dlg_update_start(union control *ctrl, void *dlg) |
596 | { |
0f5e1f75 |
597 | /* |
598 | * Apparently we can't do this at all in GTK. GtkCList supports |
599 | * freeze and thaw, but not GtkList. Bah. |
600 | */ |
d9b15094 |
601 | } |
602 | |
603 | void dlg_update_done(union control *ctrl, void *dlg) |
604 | { |
0f5e1f75 |
605 | /* |
606 | * Apparently we can't do this at all in GTK. GtkCList supports |
607 | * freeze and thaw, but not GtkList. Bah. |
608 | */ |
d9b15094 |
609 | } |
610 | |
611 | void dlg_set_focus(union control *ctrl, void *dlg) |
612 | { |
0f5e1f75 |
613 | struct dlgparam *dp = (struct dlgparam *)dlg; |
0bd8d76d |
614 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
615 | |
616 | switch (ctrl->generic.type) { |
617 | case CTRL_CHECKBOX: |
618 | case CTRL_BUTTON: |
619 | /* Check boxes and buttons get the focus _and_ get toggled. */ |
620 | gtk_widget_grab_focus(uc->toplevel); |
621 | break; |
622 | case CTRL_FILESELECT: |
623 | case CTRL_FONTSELECT: |
624 | case CTRL_EDITBOX: |
625 | /* Anything containing an edit box gets that focused. */ |
626 | gtk_widget_grab_focus(uc->entry); |
627 | break; |
628 | case CTRL_RADIO: |
629 | /* |
630 | * Radio buttons: we find the currently selected button and |
631 | * focus it. |
632 | */ |
633 | { |
634 | int i; |
635 | for (i = 0; i < ctrl->radio.nbuttons; i++) |
636 | if (gtk_toggle_button_get_active |
637 | (GTK_TOGGLE_BUTTON(uc->buttons[i]))) { |
638 | gtk_widget_grab_focus(uc->buttons[i]); |
639 | } |
640 | } |
641 | break; |
642 | case CTRL_LISTBOX: |
643 | /* |
644 | * If the list is really an option menu, we focus it. |
645 | * Otherwise we tell it to focus one of its children, which |
646 | * appears to do the Right Thing. |
647 | */ |
648 | if (uc->optmenu) { |
649 | gtk_widget_grab_focus(uc->optmenu); |
650 | } else { |
651 | assert(uc->list != NULL); |
652 | gtk_container_focus(GTK_CONTAINER(uc->list), GTK_DIR_TAB_FORWARD); |
653 | } |
654 | break; |
655 | } |
d9b15094 |
656 | } |
657 | |
658 | /* |
659 | * During event processing, you might well want to give an error |
660 | * indication to the user. dlg_beep() is a quick and easy generic |
661 | * error; dlg_error() puts up a message-box or equivalent. |
662 | */ |
663 | void dlg_beep(void *dlg) |
664 | { |
0f5e1f75 |
665 | gdk_beep(); |
d9b15094 |
666 | } |
667 | |
0bd8d76d |
668 | static void errmsg_button_clicked(GtkButton *button, gpointer data) |
669 | { |
670 | gtk_widget_destroy(GTK_WIDGET(data)); |
671 | } |
672 | |
d9b15094 |
673 | void dlg_error_msg(void *dlg, char *msg) |
674 | { |
0f5e1f75 |
675 | struct dlgparam *dp = (struct dlgparam *)dlg; |
23897ed0 |
676 | GtkWidget *window, *hbox, *text, *ok; |
0bd8d76d |
677 | |
678 | window = gtk_dialog_new(); |
679 | text = gtk_label_new(msg); |
680 | gtk_misc_set_alignment(GTK_MISC(text), 0.0, 0.0); |
23897ed0 |
681 | hbox = gtk_hbox_new(FALSE, 0); |
682 | gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 20); |
0bd8d76d |
683 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), |
23897ed0 |
684 | hbox, FALSE, FALSE, 20); |
0bd8d76d |
685 | gtk_widget_show(text); |
23897ed0 |
686 | gtk_widget_show(hbox); |
687 | gtk_window_set_title(GTK_WINDOW(window), "Error"); |
0bd8d76d |
688 | gtk_label_set_line_wrap(GTK_LABEL(text), TRUE); |
689 | ok = gtk_button_new_with_label("OK"); |
690 | gtk_box_pack_end(GTK_BOX(GTK_DIALOG(window)->action_area), |
691 | ok, FALSE, FALSE, 0); |
692 | gtk_widget_show(ok); |
693 | GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT); |
694 | gtk_window_set_default(GTK_WINDOW(window), ok); |
695 | gtk_signal_connect(GTK_OBJECT(ok), "clicked", |
696 | GTK_SIGNAL_FUNC(errmsg_button_clicked), window); |
697 | gtk_signal_connect(GTK_OBJECT(window), "destroy", |
698 | GTK_SIGNAL_FUNC(window_destroy), NULL); |
699 | gtk_window_set_modal(GTK_WINDOW(window), TRUE); |
23897ed0 |
700 | gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(dp->window)); |
701 | { |
702 | gint x, y, w, h, dx, dy; |
703 | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_NONE); |
704 | gdk_window_get_origin(GTK_WIDGET(dp->window)->window, &x, &y); |
705 | gdk_window_get_size(GTK_WIDGET(dp->window)->window, &w, &h); |
706 | dx = x + w/4; |
707 | dy = y + h/4; |
708 | gtk_widget_set_uposition(GTK_WIDGET(window), dx, dy); |
709 | } |
0bd8d76d |
710 | gtk_widget_show(window); |
711 | gtk_main(); |
d9b15094 |
712 | } |
713 | |
714 | /* |
715 | * This function signals to the front end that the dialog's |
716 | * processing is completed, and passes an integer value (typically |
717 | * a success status). |
718 | */ |
719 | void dlg_end(void *dlg, int value) |
720 | { |
0f5e1f75 |
721 | struct dlgparam *dp = (struct dlgparam *)dlg; |
0bd8d76d |
722 | dp->retval = value; |
1d009ae7 |
723 | gtk_widget_destroy(dp->window); |
d9b15094 |
724 | } |
725 | |
726 | void dlg_refresh(union control *ctrl, void *dlg) |
727 | { |
0f5e1f75 |
728 | struct dlgparam *dp = (struct dlgparam *)dlg; |
729 | struct uctrl *uc; |
730 | |
731 | if (ctrl) { |
732 | if (ctrl->generic.handler != NULL) |
733 | ctrl->generic.handler(ctrl, dp, dp->data, EVENT_REFRESH); |
734 | } else { |
735 | int i; |
736 | |
737 | for (i = 0; (uc = index234(dp->byctrl, i)) != NULL; i++) { |
738 | assert(uc->ctrl != NULL); |
739 | if (uc->ctrl->generic.handler != NULL) |
740 | uc->ctrl->generic.handler(uc->ctrl, dp, |
741 | dp->data, EVENT_REFRESH); |
742 | } |
743 | } |
d9b15094 |
744 | } |
745 | |
746 | void dlg_coloursel_start(union control *ctrl, void *dlg, int r, int g, int b) |
747 | { |
0f5e1f75 |
748 | struct dlgparam *dp = (struct dlgparam *)dlg; |
749 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl); |
750 | gdouble cvals[4]; |
751 | |
752 | GtkWidget *coloursel = |
753 | gtk_color_selection_dialog_new("Select a colour"); |
754 | GtkColorSelectionDialog *ccs = GTK_COLOR_SELECTION_DIALOG(coloursel); |
755 | |
756 | dp->coloursel_result.ok = FALSE; |
757 | |
758 | gtk_window_set_modal(GTK_WINDOW(coloursel), TRUE); |
759 | gtk_color_selection_set_opacity(GTK_COLOR_SELECTION(ccs->colorsel), FALSE); |
760 | cvals[0] = r / 255.0; |
761 | cvals[1] = g / 255.0; |
762 | cvals[2] = b / 255.0; |
763 | cvals[3] = 1.0; /* fully opaque! */ |
764 | gtk_color_selection_set_color(GTK_COLOR_SELECTION(ccs->colorsel), cvals); |
765 | |
766 | gtk_object_set_data(GTK_OBJECT(ccs->ok_button), "user-data", |
767 | (gpointer)coloursel); |
768 | gtk_object_set_data(GTK_OBJECT(ccs->cancel_button), "user-data", |
769 | (gpointer)coloursel); |
770 | gtk_object_set_data(GTK_OBJECT(coloursel), "user-data", (gpointer)uc); |
771 | gtk_signal_connect(GTK_OBJECT(ccs->ok_button), "clicked", |
772 | GTK_SIGNAL_FUNC(coloursel_ok), (gpointer)dp); |
773 | gtk_signal_connect(GTK_OBJECT(ccs->cancel_button), "clicked", |
774 | GTK_SIGNAL_FUNC(coloursel_cancel), (gpointer)dp); |
775 | gtk_signal_connect_object(GTK_OBJECT(ccs->ok_button), "clicked", |
776 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
777 | (gpointer)coloursel); |
778 | gtk_signal_connect_object(GTK_OBJECT(ccs->cancel_button), "clicked", |
779 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
780 | (gpointer)coloursel); |
781 | gtk_widget_show(coloursel); |
d9b15094 |
782 | } |
783 | |
784 | int dlg_coloursel_results(union control *ctrl, void *dlg, |
785 | int *r, int *g, int *b) |
786 | { |
0f5e1f75 |
787 | struct dlgparam *dp = (struct dlgparam *)dlg; |
788 | if (dp->coloursel_result.ok) { |
789 | *r = dp->coloursel_result.r; |
790 | *g = dp->coloursel_result.g; |
791 | *b = dp->coloursel_result.b; |
792 | return 1; |
793 | } else |
794 | return 0; |
d9b15094 |
795 | } |
796 | |
0f5e1f75 |
797 | /* ---------------------------------------------------------------------- |
798 | * Signal handlers while the dialog box is active. |
799 | */ |
800 | |
0bd8d76d |
801 | static gboolean widget_focus(GtkWidget *widget, GdkEventFocus *event, |
802 | gpointer data) |
803 | { |
804 | struct dlgparam *dp = (struct dlgparam *)data; |
805 | struct uctrl *uc = dlg_find_bywidget(dp, widget); |
806 | union control *focus; |
807 | |
808 | if (uc && uc->ctrl) |
809 | focus = uc->ctrl; |
810 | else |
811 | focus = NULL; |
812 | |
813 | if (focus != dp->currfocus) { |
814 | dp->lastfocus = dp->currfocus; |
815 | dp->currfocus = focus; |
816 | } |
817 | |
818 | return FALSE; |
819 | } |
820 | |
0f5e1f75 |
821 | static void button_clicked(GtkButton *button, gpointer data) |
822 | { |
823 | struct dlgparam *dp = (struct dlgparam *)data; |
824 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(button)); |
825 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_ACTION); |
826 | } |
827 | |
828 | static void button_toggled(GtkToggleButton *tb, gpointer data) |
829 | { |
830 | struct dlgparam *dp = (struct dlgparam *)data; |
831 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(tb)); |
832 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_VALCHANGE); |
833 | } |
834 | |
1c291fcf |
835 | static int editbox_key(GtkWidget *widget, GdkEventKey *event, gpointer data) |
836 | { |
837 | /* |
838 | * GtkEntry has a nasty habit of eating the Return key, which |
839 | * is unhelpful since it doesn't actually _do_ anything with it |
840 | * (it calls gtk_widget_activate, but our edit boxes never need |
841 | * activating). So I catch Return before GtkEntry sees it, and |
842 | * pass it straight on to the parent widget. Effect: hitting |
843 | * Return in an edit box will now activate the default button |
844 | * in the dialog just like it will everywhere else. |
845 | */ |
846 | if (event->keyval == GDK_Return && widget->parent != NULL) { |
847 | gint return_val; |
0bd8d76d |
848 | gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event"); |
1c291fcf |
849 | gtk_signal_emit_by_name(GTK_OBJECT(widget->parent), "key_press_event", |
850 | event, &return_val); |
851 | return return_val; |
852 | } |
853 | return FALSE; |
854 | } |
855 | |
0f5e1f75 |
856 | static void editbox_changed(GtkEditable *ed, gpointer data) |
857 | { |
858 | struct dlgparam *dp = (struct dlgparam *)data; |
859 | if (!(dp->flags & FLAG_UPDATING_COMBO_LIST)) { |
860 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(ed)); |
861 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_VALCHANGE); |
862 | } |
863 | } |
864 | |
865 | static void editbox_lostfocus(GtkWidget *ed, GdkEventFocus *event, |
866 | gpointer data) |
867 | { |
868 | struct dlgparam *dp = (struct dlgparam *)data; |
869 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(ed)); |
870 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_REFRESH); |
871 | } |
872 | |
0bd8d76d |
873 | static int listitem_key(GtkWidget *item, GdkEventKey *event, gpointer data, |
874 | int multiple) |
875 | { |
876 | GtkAdjustment *adj = GTK_ADJUSTMENT(data); |
877 | |
878 | if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up || |
879 | event->keyval == GDK_Down || event->keyval == GDK_KP_Down || |
880 | event->keyval == GDK_Page_Up || event->keyval == GDK_KP_Page_Up || |
881 | event->keyval == GDK_Page_Down || event->keyval == GDK_KP_Page_Down) { |
882 | /* |
883 | * Up, Down, PgUp or PgDn have been pressed on a ListItem |
884 | * in a list box. So, if the list box is single-selection: |
885 | * |
886 | * - if the list item in question isn't already selected, |
887 | * we simply select it. |
888 | * - otherwise, we find the next one (or next |
889 | * however-far-away) in whichever direction we're going, |
890 | * and select that. |
891 | * + in this case, we must also fiddle with the |
892 | * scrollbar to ensure the newly selected item is |
893 | * actually visible. |
894 | * |
895 | * If it's multiple-selection, we do all of the above |
896 | * except actually selecting anything, so we move the focus |
897 | * and fiddle the scrollbar to follow it. |
898 | */ |
899 | GtkWidget *list = item->parent; |
900 | |
901 | gtk_signal_emit_stop_by_name(GTK_OBJECT(item), "key_press_event"); |
902 | |
903 | if (!multiple && |
904 | GTK_WIDGET_STATE(item) != GTK_STATE_SELECTED) { |
905 | gtk_list_select_child(GTK_LIST(list), item); |
906 | } else { |
907 | int direction = |
908 | (event->keyval==GDK_Up || event->keyval==GDK_KP_Up || |
909 | event->keyval==GDK_Page_Up || event->keyval==GDK_KP_Page_Up) |
910 | ? -1 : +1; |
911 | int step = |
912 | (event->keyval==GDK_Page_Down || |
913 | event->keyval==GDK_KP_Page_Down || |
914 | event->keyval==GDK_Page_Up || event->keyval==GDK_KP_Page_Up) |
915 | ? 2 : 1; |
916 | int i, n; |
0bd8d76d |
917 | GList *children, *chead; |
918 | |
919 | chead = children = gtk_container_children(GTK_CONTAINER(list)); |
920 | |
921 | n = g_list_length(children); |
922 | |
923 | if (step == 2) { |
924 | /* |
925 | * Figure out how many list items to a screenful, |
926 | * and adjust the step appropriately. |
927 | */ |
928 | step = 0.5 + adj->page_size * n / (adj->upper - adj->lower); |
929 | step--; /* go by one less than that */ |
930 | } |
931 | |
932 | i = 0; |
933 | while (children != NULL) { |
934 | if (item == children->data) |
935 | break; |
936 | children = children->next; |
937 | i++; |
938 | } |
939 | |
940 | while (step > 0) { |
941 | if (direction < 0 && i > 0) |
942 | children = children->prev, i--; |
943 | else if (direction > 0 && i < n-1) |
944 | children = children->next, i++; |
945 | step--; |
946 | } |
947 | |
948 | if (children && children->data) { |
949 | if (!multiple) |
950 | gtk_list_select_child(GTK_LIST(list), |
951 | GTK_WIDGET(children->data)); |
952 | gtk_widget_grab_focus(GTK_WIDGET(children->data)); |
953 | gtk_adjustment_clamp_page |
954 | (adj, |
955 | adj->lower + (adj->upper-adj->lower) * i / n, |
956 | adj->lower + (adj->upper-adj->lower) * (i+1) / n); |
957 | } |
958 | |
959 | g_list_free(chead); |
960 | } |
961 | return TRUE; |
962 | } |
963 | |
964 | return FALSE; |
965 | } |
966 | |
967 | static int listitem_single_key(GtkWidget *item, GdkEventKey *event, |
968 | gpointer data) |
969 | { |
1d009ae7 |
970 | return listitem_key(item, event, data, FALSE); |
0bd8d76d |
971 | } |
972 | |
973 | static int listitem_multi_key(GtkWidget *item, GdkEventKey *event, |
974 | gpointer data) |
975 | { |
1d009ae7 |
976 | return listitem_key(item, event, data, TRUE); |
0bd8d76d |
977 | } |
978 | |
979 | static int listitem_button(GtkWidget *item, GdkEventButton *event, |
0f5e1f75 |
980 | gpointer data) |
981 | { |
982 | struct dlgparam *dp = (struct dlgparam *)data; |
983 | if (event->type == GDK_2BUTTON_PRESS || |
984 | event->type == GDK_3BUTTON_PRESS) { |
985 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(item)); |
986 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_ACTION); |
0bd8d76d |
987 | return TRUE; |
0f5e1f75 |
988 | } |
0bd8d76d |
989 | return FALSE; |
0f5e1f75 |
990 | } |
991 | |
992 | static void list_selchange(GtkList *list, gpointer data) |
993 | { |
994 | struct dlgparam *dp = (struct dlgparam *)data; |
995 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(list)); |
8dacc30e |
996 | if (!uc) return; |
0f5e1f75 |
997 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_SELCHANGE); |
998 | } |
999 | |
1000 | static void menuitem_activate(GtkMenuItem *item, gpointer data) |
1001 | { |
1002 | struct dlgparam *dp = (struct dlgparam *)data; |
1003 | GtkWidget *menushell = GTK_WIDGET(item)->parent; |
1004 | gpointer optmenu = gtk_object_get_data(GTK_OBJECT(menushell), "user-data"); |
1005 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(optmenu)); |
1006 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_SELCHANGE); |
1007 | } |
1008 | |
1009 | static void draglist_move(struct dlgparam *dp, struct uctrl *uc, int direction) |
1010 | { |
1011 | int index = dlg_listbox_index(uc->ctrl, dp); |
1012 | GList *children = gtk_container_children(GTK_CONTAINER(uc->list)); |
1013 | GtkWidget *child; |
1014 | |
1015 | if ((index < 0) || |
1016 | (index == 0 && direction < 0) || |
1017 | (index == g_list_length(children)-1 && direction > 0)) { |
1018 | gdk_beep(); |
1019 | return; |
1020 | } |
1021 | |
1022 | child = g_list_nth_data(children, index); |
1023 | gtk_widget_ref(child); |
1024 | gtk_list_clear_items(GTK_LIST(uc->list), index, index+1); |
0bd8d76d |
1025 | g_list_free(children); |
1026 | |
0f5e1f75 |
1027 | children = NULL; |
1028 | children = g_list_append(children, child); |
1029 | gtk_list_insert_items(GTK_LIST(uc->list), children, index + direction); |
1030 | gtk_list_select_item(GTK_LIST(uc->list), index + direction); |
1031 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_VALCHANGE); |
1032 | } |
1033 | |
1034 | static void draglist_up(GtkButton *button, gpointer data) |
1035 | { |
1036 | struct dlgparam *dp = (struct dlgparam *)data; |
1037 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(button)); |
1038 | draglist_move(dp, uc, -1); |
1039 | } |
1040 | |
1041 | static void draglist_down(GtkButton *button, gpointer data) |
1042 | { |
1043 | struct dlgparam *dp = (struct dlgparam *)data; |
1044 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(button)); |
1045 | draglist_move(dp, uc, +1); |
1046 | } |
1047 | |
1048 | static void filesel_ok(GtkButton *button, gpointer data) |
1049 | { |
1d009ae7 |
1050 | /* struct dlgparam *dp = (struct dlgparam *)data; */ |
0f5e1f75 |
1051 | gpointer filesel = gtk_object_get_data(GTK_OBJECT(button), "user-data"); |
1052 | struct uctrl *uc = gtk_object_get_data(GTK_OBJECT(filesel), "user-data"); |
1053 | char *name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel)); |
1054 | gtk_entry_set_text(GTK_ENTRY(uc->entry), name); |
1055 | } |
1056 | |
1057 | static void fontsel_ok(GtkButton *button, gpointer data) |
1058 | { |
1d009ae7 |
1059 | /* struct dlgparam *dp = (struct dlgparam *)data; */ |
0f5e1f75 |
1060 | gpointer fontsel = gtk_object_get_data(GTK_OBJECT(button), "user-data"); |
1061 | struct uctrl *uc = gtk_object_get_data(GTK_OBJECT(fontsel), "user-data"); |
1062 | char *name = gtk_font_selection_dialog_get_font_name |
1063 | (GTK_FONT_SELECTION_DIALOG(fontsel)); |
1064 | gtk_entry_set_text(GTK_ENTRY(uc->entry), name); |
1065 | } |
1066 | |
1067 | static void coloursel_ok(GtkButton *button, gpointer data) |
1068 | { |
1069 | struct dlgparam *dp = (struct dlgparam *)data; |
1070 | gpointer coloursel = gtk_object_get_data(GTK_OBJECT(button), "user-data"); |
1071 | struct uctrl *uc = gtk_object_get_data(GTK_OBJECT(coloursel), "user-data"); |
1072 | gdouble cvals[4]; |
1073 | gtk_color_selection_get_color |
1074 | (GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(coloursel)->colorsel), |
1075 | cvals); |
1076 | dp->coloursel_result.r = (int) (255 * cvals[0]); |
1077 | dp->coloursel_result.g = (int) (255 * cvals[1]); |
1078 | dp->coloursel_result.b = (int) (255 * cvals[2]); |
1079 | dp->coloursel_result.ok = TRUE; |
1080 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_CALLBACK); |
1081 | } |
1082 | |
1083 | static void coloursel_cancel(GtkButton *button, gpointer data) |
1084 | { |
1085 | struct dlgparam *dp = (struct dlgparam *)data; |
1086 | gpointer coloursel = gtk_object_get_data(GTK_OBJECT(button), "user-data"); |
1087 | struct uctrl *uc = gtk_object_get_data(GTK_OBJECT(coloursel), "user-data"); |
1088 | dp->coloursel_result.ok = FALSE; |
1089 | uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_CALLBACK); |
1090 | } |
1091 | |
1092 | static void filefont_clicked(GtkButton *button, gpointer data) |
1093 | { |
1094 | struct dlgparam *dp = (struct dlgparam *)data; |
1095 | struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(button)); |
1096 | |
1097 | if (uc->ctrl->generic.type == CTRL_FILESELECT) { |
1098 | GtkWidget *filesel = |
1099 | gtk_file_selection_new(uc->ctrl->fileselect.title); |
1100 | gtk_window_set_modal(GTK_WINDOW(filesel), TRUE); |
1101 | gtk_object_set_data |
1102 | (GTK_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), "user-data", |
1103 | (gpointer)filesel); |
1104 | gtk_object_set_data(GTK_OBJECT(filesel), "user-data", (gpointer)uc); |
1105 | gtk_signal_connect |
1106 | (GTK_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), "clicked", |
1107 | GTK_SIGNAL_FUNC(filesel_ok), (gpointer)dp); |
1108 | gtk_signal_connect_object |
1109 | (GTK_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), "clicked", |
1110 | GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer)filesel); |
1111 | gtk_signal_connect_object |
1112 | (GTK_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), "clicked", |
1113 | GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer)filesel); |
1114 | gtk_widget_show(filesel); |
1115 | } |
1116 | |
1117 | if (uc->ctrl->generic.type == CTRL_FONTSELECT) { |
1118 | gchar *spacings[] = { "c", "m", NULL }; |
0bd8d76d |
1119 | gchar *fontname = gtk_entry_get_text(GTK_ENTRY(uc->entry)); |
0f5e1f75 |
1120 | GtkWidget *fontsel = |
1121 | gtk_font_selection_dialog_new("Select a font"); |
1122 | gtk_window_set_modal(GTK_WINDOW(fontsel), TRUE); |
1123 | gtk_font_selection_dialog_set_filter |
1124 | (GTK_FONT_SELECTION_DIALOG(fontsel), |
1125 | GTK_FONT_FILTER_BASE, GTK_FONT_ALL, |
1126 | NULL, NULL, NULL, NULL, spacings, NULL); |
0bd8d76d |
1127 | if (!gtk_font_selection_dialog_set_font_name |
1128 | (GTK_FONT_SELECTION_DIALOG(fontsel), fontname)) { |
1129 | /* |
1130 | * If the font name wasn't found as it was, try opening |
1131 | * it and extracting its FONT property. This should |
1132 | * have the effect of mapping short aliases into true |
1133 | * XLFDs. |
1134 | */ |
1135 | GdkFont *font = gdk_font_load(fontname); |
1136 | if (font) { |
1137 | XFontStruct *xfs = GDK_FONT_XFONT(font); |
1138 | Display *disp = GDK_FONT_XDISPLAY(font); |
1139 | Atom fontprop = XInternAtom(disp, "FONT", False); |
1140 | unsigned long ret; |
1141 | if (XGetFontProperty(xfs, fontprop, &ret)) { |
1142 | char *name = XGetAtomName(disp, (Atom)ret); |
1143 | if (name) |
1144 | gtk_font_selection_dialog_set_font_name |
1145 | (GTK_FONT_SELECTION_DIALOG(fontsel), name); |
1146 | } |
1147 | gdk_font_unref(font); |
1148 | } |
1149 | } |
0f5e1f75 |
1150 | gtk_object_set_data |
1151 | (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel)->ok_button), |
1152 | "user-data", (gpointer)fontsel); |
1153 | gtk_object_set_data(GTK_OBJECT(fontsel), "user-data", (gpointer)uc); |
1154 | gtk_signal_connect |
1155 | (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel)->ok_button), |
1156 | "clicked", GTK_SIGNAL_FUNC(fontsel_ok), (gpointer)dp); |
1157 | gtk_signal_connect_object |
1158 | (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel)->ok_button), |
1159 | "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), |
1160 | (gpointer)fontsel); |
1161 | gtk_signal_connect_object |
1162 | (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel)->cancel_button), |
1163 | "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), |
1164 | (gpointer)fontsel); |
1165 | gtk_widget_show(fontsel); |
1166 | } |
1167 | } |
1168 | |
c5d64b49 |
1169 | static void label_sizealloc(GtkWidget *widget, GtkAllocation *alloc, |
1170 | gpointer data) |
1171 | { |
1172 | struct dlgparam *dp = (struct dlgparam *)data; |
1173 | struct uctrl *uc = dlg_find_bywidget(dp, widget); |
1174 | |
1175 | gtk_widget_set_usize(uc->text, alloc->width, -1); |
1176 | gtk_label_set_text(GTK_LABEL(uc->text), uc->ctrl->generic.label); |
1177 | gtk_signal_disconnect(GTK_OBJECT(uc->text), uc->textsig); |
1178 | } |
1179 | |
0f5e1f75 |
1180 | /* ---------------------------------------------------------------------- |
d9b15094 |
1181 | * This function does the main layout work: it reads a controlset, |
1182 | * it creates the relevant GTK controls, and returns a GtkWidget |
1183 | * containing the result. (This widget might be a title of some |
1184 | * sort, it might be a Columns containing many controls, or it |
1185 | * might be a GtkFrame containing a Columns; whatever it is, it's |
1186 | * definitely a GtkWidget and should probably be added to a |
1187 | * GtkVbox.) |
1c291fcf |
1188 | * |
1189 | * `listitemheight' is used to calculate a usize for list boxes: it |
1190 | * should be the height from the size request of a GtkListItem. |
1191 | * |
1192 | * `win' is required for setting the default button. If it is |
1193 | * non-NULL, all buttons created will be default-capable (so they |
1194 | * have extra space round them for the default highlight). |
d9b15094 |
1195 | */ |
1c291fcf |
1196 | GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, |
1197 | struct controlset *s, int listitemheight, |
1198 | GtkWindow *win) |
d9b15094 |
1199 | { |
1200 | Columns *cols; |
1201 | GtkWidget *ret; |
1202 | int i; |
1203 | |
1204 | if (!s->boxname && s->boxtitle) { |
1205 | /* This controlset is a panel title. */ |
1206 | return gtk_label_new(s->boxtitle); |
1207 | } |
1208 | |
1209 | /* |
1210 | * Otherwise, we expect to be laying out actual controls, so |
1211 | * we'll start by creating a Columns for the purpose. |
1212 | */ |
1213 | cols = COLUMNS(columns_new(4)); |
1214 | ret = GTK_WIDGET(cols); |
1215 | gtk_widget_show(ret); |
1216 | |
1217 | /* |
1218 | * Create a containing frame if we have a box name. |
1219 | */ |
1220 | if (*s->boxname) { |
1221 | ret = gtk_frame_new(s->boxtitle); /* NULL is valid here */ |
1222 | gtk_container_set_border_width(GTK_CONTAINER(cols), 4); |
1223 | gtk_container_add(GTK_CONTAINER(ret), GTK_WIDGET(cols)); |
1224 | gtk_widget_show(ret); |
1225 | } |
1226 | |
1227 | /* |
1228 | * Now iterate through the controls themselves, create them, |
1229 | * and add them to the Columns. |
1230 | */ |
1231 | for (i = 0; i < s->ncontrols; i++) { |
1232 | union control *ctrl = s->ctrls[i]; |
1c291fcf |
1233 | struct uctrl *uc; |
1234 | int left = FALSE; |
d9b15094 |
1235 | GtkWidget *w = NULL; |
1236 | |
1237 | switch (ctrl->generic.type) { |
1238 | case CTRL_COLUMNS: |
1239 | { |
1240 | static const int simplecols[1] = { 100 }; |
1241 | columns_set_cols(cols, ctrl->columns.ncols, |
1242 | (ctrl->columns.percentages ? |
1243 | ctrl->columns.percentages : simplecols)); |
1244 | } |
1245 | continue; /* no actual control created */ |
1246 | case CTRL_TABDELAY: |
0f5e1f75 |
1247 | { |
1248 | struct uctrl *uc = dlg_find_byctrl(dp, ctrl->tabdelay.ctrl); |
1249 | if (uc) |
1250 | columns_taborder_last(cols, uc->toplevel); |
1251 | } |
d9b15094 |
1252 | continue; /* no actual control created */ |
1c291fcf |
1253 | } |
1254 | |
3d88e64d |
1255 | uc = snew(struct uctrl); |
1c291fcf |
1256 | uc->ctrl = ctrl; |
1257 | uc->privdata = NULL; |
1258 | uc->privdata_needs_free = FALSE; |
1259 | uc->buttons = NULL; |
1260 | uc->entry = uc->list = uc->menu = NULL; |
1261 | uc->button = uc->optmenu = uc->text = NULL; |
1262 | |
1263 | switch (ctrl->generic.type) { |
d9b15094 |
1264 | case CTRL_BUTTON: |
1265 | w = gtk_button_new_with_label(ctrl->generic.label); |
1c291fcf |
1266 | if (win) { |
1267 | GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT); |
1268 | if (ctrl->button.isdefault) |
1269 | gtk_window_set_default(win, w); |
0bd8d76d |
1270 | if (ctrl->button.iscancel) |
1271 | dp->cancelbutton = w; |
1c291fcf |
1272 | } |
0f5e1f75 |
1273 | gtk_signal_connect(GTK_OBJECT(w), "clicked", |
1274 | GTK_SIGNAL_FUNC(button_clicked), dp); |
0bd8d76d |
1275 | gtk_signal_connect(GTK_OBJECT(w), "focus_in_event", |
1276 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1c291fcf |
1277 | shortcut_add(scs, GTK_BIN(w)->child, ctrl->button.shortcut, |
1278 | SHORTCUT_UCTRL, uc); |
d9b15094 |
1279 | break; |
1280 | case CTRL_CHECKBOX: |
1281 | w = gtk_check_button_new_with_label(ctrl->generic.label); |
0f5e1f75 |
1282 | gtk_signal_connect(GTK_OBJECT(w), "toggled", |
1283 | GTK_SIGNAL_FUNC(button_toggled), dp); |
0bd8d76d |
1284 | gtk_signal_connect(GTK_OBJECT(w), "focus_in_event", |
1285 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1c291fcf |
1286 | shortcut_add(scs, GTK_BIN(w)->child, ctrl->checkbox.shortcut, |
1287 | SHORTCUT_UCTRL, uc); |
1288 | left = TRUE; |
d9b15094 |
1289 | break; |
1290 | case CTRL_RADIO: |
1291 | /* |
1292 | * Radio buttons get to go inside their own Columns, no |
1293 | * matter what. |
1294 | */ |
1295 | { |
1296 | gint i, *percentages; |
1297 | GSList *group; |
1298 | |
c5d64b49 |
1299 | w = columns_new(0); |
d9b15094 |
1300 | if (ctrl->generic.label) { |
1301 | GtkWidget *label = gtk_label_new(ctrl->generic.label); |
1302 | columns_add(COLUMNS(w), label, 0, 1); |
1303 | columns_force_left_align(COLUMNS(w), label); |
1304 | gtk_widget_show(label); |
1c291fcf |
1305 | shortcut_add(scs, label, ctrl->radio.shortcut, |
1306 | SHORTCUT_UCTRL, uc); |
d9b15094 |
1307 | } |
1308 | percentages = g_new(gint, ctrl->radio.ncolumns); |
1309 | for (i = 0; i < ctrl->radio.ncolumns; i++) { |
1310 | percentages[i] = |
1311 | ((100 * (i+1) / ctrl->radio.ncolumns) - |
1312 | 100 * i / ctrl->radio.ncolumns); |
1313 | } |
1314 | columns_set_cols(COLUMNS(w), ctrl->radio.ncolumns, |
1315 | percentages); |
1316 | g_free(percentages); |
1317 | group = NULL; |
0f5e1f75 |
1318 | |
1c291fcf |
1319 | uc->nbuttons = ctrl->radio.nbuttons; |
3d88e64d |
1320 | uc->buttons = snewn(uc->nbuttons, GtkWidget *); |
0f5e1f75 |
1321 | |
d9b15094 |
1322 | for (i = 0; i < ctrl->radio.nbuttons; i++) { |
1323 | GtkWidget *b; |
1324 | gint colstart; |
1325 | |
1326 | b = (gtk_radio_button_new_with_label |
1327 | (group, ctrl->radio.buttons[i])); |
1c291fcf |
1328 | uc->buttons[i] = b; |
d9b15094 |
1329 | group = gtk_radio_button_group(GTK_RADIO_BUTTON(b)); |
1330 | colstart = i % ctrl->radio.ncolumns; |
1331 | columns_add(COLUMNS(w), b, colstart, |
1332 | (i == ctrl->radio.nbuttons-1 ? |
1333 | ctrl->radio.ncolumns - colstart : 1)); |
1c291fcf |
1334 | columns_force_left_align(COLUMNS(w), b); |
d9b15094 |
1335 | gtk_widget_show(b); |
0f5e1f75 |
1336 | gtk_signal_connect(GTK_OBJECT(b), "toggled", |
1337 | GTK_SIGNAL_FUNC(button_toggled), dp); |
0bd8d76d |
1338 | gtk_signal_connect(GTK_OBJECT(b), "focus_in_event", |
1339 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1c291fcf |
1340 | if (ctrl->radio.shortcuts) { |
1341 | shortcut_add(scs, GTK_BIN(b)->child, |
1342 | ctrl->radio.shortcuts[i], |
1343 | SHORTCUT_UCTRL, uc); |
1344 | } |
d9b15094 |
1345 | } |
1346 | } |
1347 | break; |
1348 | case CTRL_EDITBOX: |
c5d64b49 |
1349 | { |
d9b15094 |
1350 | GtkRequisition req; |
c5d64b49 |
1351 | |
1352 | if (ctrl->editbox.has_list) { |
1353 | w = gtk_combo_new(); |
1354 | gtk_combo_set_value_in_list(GTK_COMBO(w), FALSE, TRUE); |
1355 | uc->entry = GTK_COMBO(w)->entry; |
1356 | uc->list = GTK_COMBO(w)->list; |
1357 | } else { |
1358 | w = gtk_entry_new(); |
1359 | if (ctrl->editbox.password) |
1360 | gtk_entry_set_visibility(GTK_ENTRY(w), FALSE); |
1361 | uc->entry = w; |
1362 | } |
1363 | gtk_signal_connect(GTK_OBJECT(uc->entry), "changed", |
1364 | GTK_SIGNAL_FUNC(editbox_changed), dp); |
1365 | gtk_signal_connect(GTK_OBJECT(uc->entry), "key_press_event", |
1366 | GTK_SIGNAL_FUNC(editbox_key), dp); |
1367 | gtk_signal_connect(GTK_OBJECT(uc->entry), "focus_in_event", |
1368 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1369 | /* |
1370 | * Edit boxes, for some strange reason, have a minimum |
1371 | * width of 150 in GTK 1.2. We don't want this - we'd |
1372 | * rather the edit boxes acquired their natural width |
1373 | * from the column layout of the rest of the box. |
1374 | * |
1375 | * Also, while we're here, we'll squirrel away the |
1376 | * edit box height so we can use that to centre its |
1377 | * label vertically beside it. |
1378 | */ |
d9b15094 |
1379 | gtk_widget_size_request(w, &req); |
1380 | gtk_widget_set_usize(w, 10, req.height); |
d9b15094 |
1381 | |
c5d64b49 |
1382 | if (ctrl->generic.label) { |
1383 | GtkWidget *label, *container; |
1384 | |
1385 | label = gtk_label_new(ctrl->generic.label); |
1386 | |
1387 | shortcut_add(scs, label, ctrl->editbox.shortcut, |
1388 | SHORTCUT_FOCUS, uc->entry); |
1389 | |
1390 | container = columns_new(4); |
1391 | if (ctrl->editbox.percentwidth == 100) { |
1392 | columns_add(COLUMNS(container), label, 0, 1); |
1393 | columns_force_left_align(COLUMNS(container), label); |
1394 | columns_add(COLUMNS(container), w, 0, 1); |
1395 | } else { |
1396 | gint percentages[2]; |
1397 | percentages[1] = ctrl->editbox.percentwidth; |
1398 | percentages[0] = 100 - ctrl->editbox.percentwidth; |
1399 | columns_set_cols(COLUMNS(container), 2, percentages); |
1400 | columns_add(COLUMNS(container), label, 0, 1); |
1401 | columns_force_left_align(COLUMNS(container), label); |
1402 | columns_add(COLUMNS(container), w, 1, 1); |
1403 | /* Centre the label vertically. */ |
1404 | gtk_widget_set_usize(label, -1, req.height); |
1405 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); |
1406 | } |
1407 | gtk_widget_show(label); |
1408 | gtk_widget_show(w); |
d9b15094 |
1409 | |
c5d64b49 |
1410 | w = container; |
1411 | } |
1412 | gtk_signal_connect(GTK_OBJECT(uc->entry), "focus_out_event", |
1413 | GTK_SIGNAL_FUNC(editbox_lostfocus), dp); |
1414 | } |
d9b15094 |
1415 | break; |
1d0d4a3b |
1416 | case CTRL_FILESELECT: |
1417 | case CTRL_FONTSELECT: |
1418 | { |
1419 | GtkWidget *ww; |
1420 | GtkRequisition req; |
1421 | char *browsebtn = |
1422 | (ctrl->generic.type == CTRL_FILESELECT ? |
1423 | "Browse..." : "Change..."); |
1424 | |
1425 | gint percentages[] = { 75, 25 }; |
1426 | w = columns_new(4); |
1427 | columns_set_cols(COLUMNS(w), 2, percentages); |
1428 | |
1429 | if (ctrl->generic.label) { |
1430 | ww = gtk_label_new(ctrl->generic.label); |
1431 | columns_add(COLUMNS(w), ww, 0, 2); |
1432 | columns_force_left_align(COLUMNS(w), ww); |
1433 | gtk_widget_show(ww); |
1c291fcf |
1434 | shortcut_add(scs, ww, |
1435 | (ctrl->generic.type == CTRL_FILESELECT ? |
1436 | ctrl->fileselect.shortcut : |
1437 | ctrl->fontselect.shortcut), |
1438 | SHORTCUT_UCTRL, uc); |
1d0d4a3b |
1439 | } |
1440 | |
1c291fcf |
1441 | uc->entry = ww = gtk_entry_new(); |
1d0d4a3b |
1442 | gtk_widget_size_request(ww, &req); |
1443 | gtk_widget_set_usize(ww, 10, req.height); |
1444 | columns_add(COLUMNS(w), ww, 0, 1); |
1445 | gtk_widget_show(ww); |
1446 | |
1c291fcf |
1447 | uc->button = ww = gtk_button_new_with_label(browsebtn); |
1d0d4a3b |
1448 | columns_add(COLUMNS(w), ww, 1, 1); |
1449 | gtk_widget_show(ww); |
0f5e1f75 |
1450 | |
1c291fcf |
1451 | gtk_signal_connect(GTK_OBJECT(uc->entry), "key_press_event", |
1452 | GTK_SIGNAL_FUNC(editbox_key), dp); |
1453 | gtk_signal_connect(GTK_OBJECT(uc->entry), "changed", |
0f5e1f75 |
1454 | GTK_SIGNAL_FUNC(editbox_changed), dp); |
0bd8d76d |
1455 | gtk_signal_connect(GTK_OBJECT(uc->entry), "focus_in_event", |
1456 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1457 | gtk_signal_connect(GTK_OBJECT(uc->button), "focus_in_event", |
1458 | GTK_SIGNAL_FUNC(widget_focus), dp); |
0f5e1f75 |
1459 | gtk_signal_connect(GTK_OBJECT(ww), "clicked", |
1460 | GTK_SIGNAL_FUNC(filefont_clicked), dp); |
1d0d4a3b |
1461 | } |
1462 | break; |
1463 | case CTRL_LISTBOX: |
1464 | if (ctrl->listbox.height == 0) { |
1c291fcf |
1465 | uc->optmenu = w = gtk_option_menu_new(); |
1466 | uc->menu = gtk_menu_new(); |
1467 | gtk_option_menu_set_menu(GTK_OPTION_MENU(w), uc->menu); |
1468 | gtk_object_set_data(GTK_OBJECT(uc->menu), "user-data", |
1469 | (gpointer)uc->optmenu); |
0bd8d76d |
1470 | gtk_signal_connect(GTK_OBJECT(uc->optmenu), "focus_in_event", |
1471 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1d0d4a3b |
1472 | } else { |
1c291fcf |
1473 | uc->list = gtk_list_new(); |
0bd8d76d |
1474 | if (ctrl->listbox.multisel) { |
1475 | gtk_list_set_selection_mode(GTK_LIST(uc->list), |
1476 | GTK_SELECTION_MULTIPLE); |
1477 | } else { |
1478 | gtk_list_set_selection_mode(GTK_LIST(uc->list), |
1479 | GTK_SELECTION_SINGLE); |
1480 | } |
1d0d4a3b |
1481 | w = gtk_scrolled_window_new(NULL, NULL); |
1482 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(w), |
1c291fcf |
1483 | uc->list); |
1d0d4a3b |
1484 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), |
1485 | GTK_POLICY_NEVER, |
1486 | GTK_POLICY_AUTOMATIC); |
0bd8d76d |
1487 | uc->adj = gtk_scrolled_window_get_vadjustment |
1488 | (GTK_SCROLLED_WINDOW(w)); |
1489 | |
1c291fcf |
1490 | gtk_widget_show(uc->list); |
1491 | gtk_signal_connect(GTK_OBJECT(uc->list), "selection-changed", |
0f5e1f75 |
1492 | GTK_SIGNAL_FUNC(list_selchange), dp); |
0bd8d76d |
1493 | gtk_signal_connect(GTK_OBJECT(uc->list), "focus_in_event", |
1494 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1d0d4a3b |
1495 | |
1496 | /* |
1497 | * Adjust the height of the scrolled window to the |
1498 | * minimum given by the height parameter. |
1499 | * |
1500 | * This piece of guesswork is a horrid hack based |
1501 | * on looking inside the GTK 1.2 sources |
1502 | * (specifically gtkviewport.c, which appears to be |
1503 | * the widget which provides the border around the |
1504 | * scrolling area). Anyone lets me know how I can |
1505 | * do this in a way which isn't at risk from GTK |
1506 | * upgrades, I'd be grateful. |
1507 | */ |
1508 | { |
1c291fcf |
1509 | int edge = GTK_WIDGET(uc->list)->style->klass->ythickness; |
1d0d4a3b |
1510 | gtk_widget_set_usize(w, 10, |
1511 | 2*edge + (ctrl->listbox.height * |
1512 | listitemheight)); |
1513 | } |
1d0d4a3b |
1514 | |
1515 | if (ctrl->listbox.draglist) { |
1516 | /* |
1517 | * GTK doesn't appear to make it easy to |
1518 | * implement a proper draggable list; so |
1519 | * instead I'm just going to have to put an Up |
1520 | * and a Down button to the right of the actual |
1521 | * list box. Ah well. |
1522 | */ |
1523 | GtkWidget *cols, *button; |
1524 | static const gint percentages[2] = { 80, 20 }; |
1525 | |
1526 | cols = columns_new(4); |
1527 | columns_set_cols(COLUMNS(cols), 2, percentages); |
1528 | columns_add(COLUMNS(cols), w, 0, 1); |
1529 | gtk_widget_show(w); |
1530 | button = gtk_button_new_with_label("Up"); |
1531 | columns_add(COLUMNS(cols), button, 1, 1); |
1532 | gtk_widget_show(button); |
0f5e1f75 |
1533 | gtk_signal_connect(GTK_OBJECT(button), "clicked", |
1534 | GTK_SIGNAL_FUNC(draglist_up), dp); |
0bd8d76d |
1535 | gtk_signal_connect(GTK_OBJECT(button), "focus_in_event", |
1536 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1d0d4a3b |
1537 | button = gtk_button_new_with_label("Down"); |
1538 | columns_add(COLUMNS(cols), button, 1, 1); |
1539 | gtk_widget_show(button); |
0f5e1f75 |
1540 | gtk_signal_connect(GTK_OBJECT(button), "clicked", |
1541 | GTK_SIGNAL_FUNC(draglist_down), dp); |
0bd8d76d |
1542 | gtk_signal_connect(GTK_OBJECT(button), "focus_in_event", |
1543 | GTK_SIGNAL_FUNC(widget_focus), dp); |
1d0d4a3b |
1544 | |
1545 | w = cols; |
1546 | } |
1547 | |
1548 | } |
1549 | if (ctrl->generic.label) { |
1550 | GtkWidget *label, *container; |
1551 | |
1552 | label = gtk_label_new(ctrl->generic.label); |
1553 | |
1554 | container = columns_new(4); |
1555 | if (ctrl->listbox.percentwidth == 100) { |
1556 | columns_add(COLUMNS(container), label, 0, 1); |
1557 | columns_force_left_align(COLUMNS(container), label); |
1558 | columns_add(COLUMNS(container), w, 0, 1); |
1559 | } else { |
1560 | gint percentages[2]; |
1561 | percentages[1] = ctrl->listbox.percentwidth; |
1562 | percentages[0] = 100 - ctrl->listbox.percentwidth; |
1563 | columns_set_cols(COLUMNS(container), 2, percentages); |
1564 | columns_add(COLUMNS(container), label, 0, 1); |
1565 | columns_force_left_align(COLUMNS(container), label); |
1566 | columns_add(COLUMNS(container), w, 1, 1); |
1567 | } |
1568 | gtk_widget_show(label); |
1569 | gtk_widget_show(w); |
1c291fcf |
1570 | shortcut_add(scs, label, ctrl->listbox.shortcut, |
1571 | SHORTCUT_UCTRL, uc); |
1d0d4a3b |
1572 | w = container; |
1573 | } |
1574 | break; |
d9b15094 |
1575 | case CTRL_TEXT: |
c5d64b49 |
1576 | /* |
1577 | * Wrapping text widgets don't sit well with the GTK |
1578 | * layout model, in which widgets state a minimum size |
1579 | * and the whole window then adjusts to the smallest |
1580 | * size it can sensibly take given its contents. A |
1581 | * wrapping text widget _has_ no clear minimum size; |
1582 | * instead it has a range of possibilities. It can be |
1583 | * one line deep but 2000 wide, or two lines deep and |
1584 | * 1000 pixels, or three by 867, or four by 500 and so |
1585 | * on. It can be as short as you like provided you |
1586 | * don't mind it being wide, or as narrow as you like |
1587 | * provided you don't mind it being tall. |
1588 | * |
1589 | * Therefore, it fits very badly into the layout model. |
1590 | * Hence the only thing to do is pick a width and let |
1591 | * it choose its own number of lines. To do this I'm |
1592 | * going to cheat a little. All new wrapping text |
1593 | * widgets will be created with a minimal text content |
1594 | * "X"; then, after the rest of the dialog box is set |
1595 | * up and its size calculated, the text widgets will be |
1596 | * told their width and given their real text, which |
1597 | * will cause the size to be recomputed in the y |
1598 | * direction (because many of them will expand to more |
1599 | * than one line). |
1600 | */ |
1601 | uc->text = w = gtk_label_new("X"); |
0bd8d76d |
1602 | gtk_misc_set_alignment(GTK_MISC(w), 0.0, 0.0); |
d9b15094 |
1603 | gtk_label_set_line_wrap(GTK_LABEL(w), TRUE); |
c5d64b49 |
1604 | uc->textsig = |
1605 | gtk_signal_connect(GTK_OBJECT(w), "size-allocate", |
1606 | GTK_SIGNAL_FUNC(label_sizealloc), dp); |
d9b15094 |
1607 | break; |
1608 | } |
0f5e1f75 |
1609 | |
1c291fcf |
1610 | assert(w != NULL); |
0f5e1f75 |
1611 | |
1c291fcf |
1612 | columns_add(cols, w, |
1613 | COLUMN_START(ctrl->generic.column), |
1614 | COLUMN_SPAN(ctrl->generic.column)); |
1615 | if (left) |
1616 | columns_force_left_align(cols, w); |
1617 | gtk_widget_show(w); |
1618 | |
1619 | uc->toplevel = w; |
1620 | dlg_add_uctrl(dp, uc); |
d9b15094 |
1621 | } |
1622 | |
1623 | return ret; |
1624 | } |
1625 | |
1626 | struct selparam { |
1c291fcf |
1627 | struct dlgparam *dp; |
d9b15094 |
1628 | Panels *panels; |
1629 | GtkWidget *panel, *treeitem; |
1c291fcf |
1630 | struct Shortcuts shortcuts; |
d9b15094 |
1631 | }; |
1632 | |
1633 | static void treeitem_sel(GtkItem *item, gpointer data) |
1634 | { |
1635 | struct selparam *sp = (struct selparam *)data; |
1636 | |
1637 | panels_switch_to(sp->panels, sp->panel); |
1c291fcf |
1638 | |
1639 | sp->dp->shortcuts = &sp->shortcuts; |
0bd8d76d |
1640 | sp->dp->currtreeitem = sp->treeitem; |
d9b15094 |
1641 | } |
1642 | |
0bd8d76d |
1643 | static void window_destroy(GtkWidget *widget, gpointer data) |
d9b15094 |
1644 | { |
1645 | gtk_main_quit(); |
1646 | } |
1647 | |
c5d64b49 |
1648 | static int tree_grab_focus(struct dlgparam *dp) |
1649 | { |
1650 | int i, f; |
1651 | |
1652 | /* |
1653 | * See if any of the treeitems has the focus. |
1654 | */ |
1655 | f = -1; |
1656 | for (i = 0; i < dp->ntreeitems; i++) |
1657 | if (GTK_WIDGET_HAS_FOCUS(dp->treeitems[i])) { |
1658 | f = i; |
1659 | break; |
1660 | } |
1661 | |
1662 | if (f >= 0) |
1663 | return FALSE; |
1664 | else { |
1665 | gtk_widget_grab_focus(dp->currtreeitem); |
1666 | return TRUE; |
1667 | } |
1668 | } |
1669 | |
1670 | gint tree_focus(GtkContainer *container, GtkDirectionType direction, |
1671 | gpointer data) |
1672 | { |
1673 | struct dlgparam *dp = (struct dlgparam *)data; |
1674 | |
1675 | gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); |
1676 | /* |
1677 | * If there's a focused treeitem, we return FALSE to cause the |
1678 | * focus to move on to some totally other control. If not, we |
1679 | * focus the selected one. |
1680 | */ |
1681 | return tree_grab_focus(dp); |
1682 | } |
1683 | |
1c291fcf |
1684 | int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) |
1685 | { |
1686 | struct dlgparam *dp = (struct dlgparam *)data; |
1687 | |
0bd8d76d |
1688 | if (event->keyval == GDK_Escape && dp->cancelbutton) { |
1689 | gtk_signal_emit_by_name(GTK_OBJECT(dp->cancelbutton), "clicked"); |
1c291fcf |
1690 | return TRUE; |
1691 | } |
1692 | |
1693 | if ((event->state & GDK_MOD1_MASK) && |
1694 | (unsigned char)event->string[0] > 0 && |
1695 | (unsigned char)event->string[0] <= 127) { |
1696 | int schr = (unsigned char)event->string[0]; |
1697 | struct Shortcut *sc = &dp->shortcuts->sc[schr]; |
1698 | |
1699 | switch (sc->action) { |
c5d64b49 |
1700 | case SHORTCUT_TREE: |
1701 | tree_grab_focus(dp); |
1702 | break; |
1c291fcf |
1703 | case SHORTCUT_FOCUS: |
1704 | gtk_widget_grab_focus(sc->widget); |
1705 | break; |
1706 | case SHORTCUT_UCTRL: |
1707 | /* |
1708 | * We must do something sensible with a uctrl. |
1709 | * Precisely what this is depends on the type of |
1710 | * control. |
1711 | */ |
1712 | switch (sc->uc->ctrl->generic.type) { |
1713 | case CTRL_CHECKBOX: |
1714 | case CTRL_BUTTON: |
1715 | /* Check boxes and buttons get the focus _and_ get toggled. */ |
1716 | gtk_widget_grab_focus(sc->uc->toplevel); |
1717 | gtk_signal_emit_by_name(GTK_OBJECT(sc->uc->toplevel), |
1718 | "clicked"); |
1719 | break; |
1720 | case CTRL_FILESELECT: |
1721 | case CTRL_FONTSELECT: |
1722 | /* File/font selectors have their buttons pressed (ooer), |
1723 | * and focus transferred to the edit box. */ |
1724 | gtk_signal_emit_by_name(GTK_OBJECT(sc->uc->button), |
1725 | "clicked"); |
1726 | gtk_widget_grab_focus(sc->uc->entry); |
1727 | break; |
1728 | case CTRL_RADIO: |
1729 | /* |
1730 | * Radio buttons are fun, because they have |
1731 | * multiple shortcuts. We must find whether the |
1732 | * activated shortcut is the shortcut for the whole |
1733 | * group, or for a particular button. In the former |
1734 | * case, we find the currently selected button and |
1735 | * focus it; in the latter, we focus-and-click the |
1736 | * button whose shortcut was pressed. |
1737 | */ |
1738 | if (schr == sc->uc->ctrl->radio.shortcut) { |
1739 | int i; |
1740 | for (i = 0; i < sc->uc->ctrl->radio.nbuttons; i++) |
1741 | if (gtk_toggle_button_get_active |
1742 | (GTK_TOGGLE_BUTTON(sc->uc->buttons[i]))) { |
1743 | gtk_widget_grab_focus(sc->uc->buttons[i]); |
1744 | } |
1745 | } else if (sc->uc->ctrl->radio.shortcuts) { |
1746 | int i; |
1747 | for (i = 0; i < sc->uc->ctrl->radio.nbuttons; i++) |
1748 | if (schr == sc->uc->ctrl->radio.shortcuts[i]) { |
1749 | gtk_widget_grab_focus(sc->uc->buttons[i]); |
1750 | gtk_signal_emit_by_name |
1751 | (GTK_OBJECT(sc->uc->buttons[i]), "clicked"); |
1752 | } |
1753 | } |
1754 | break; |
1755 | case CTRL_LISTBOX: |
1756 | /* |
0bd8d76d |
1757 | * If the list is really an option menu, we focus |
1758 | * and click it. Otherwise we tell it to focus one |
1759 | * of its children, which appears to do the Right |
1760 | * Thing. |
1c291fcf |
1761 | */ |
1762 | if (sc->uc->optmenu) { |
1763 | GdkEventButton bev; |
1764 | gint returnval; |
1765 | |
1766 | gtk_widget_grab_focus(sc->uc->optmenu); |
1767 | /* Option menus don't work using the "clicked" signal. |
1768 | * We need to manufacture a button press event :-/ */ |
1769 | bev.type = GDK_BUTTON_PRESS; |
1770 | bev.button = 1; |
1771 | gtk_signal_emit_by_name(GTK_OBJECT(sc->uc->optmenu), |
1772 | "button_press_event", |
1773 | &bev, &returnval); |
1774 | } else { |
0bd8d76d |
1775 | assert(sc->uc->list != NULL); |
1776 | |
1777 | gtk_container_focus(GTK_CONTAINER(sc->uc->list), |
1778 | GTK_DIR_TAB_FORWARD); |
1c291fcf |
1779 | } |
1780 | break; |
1781 | } |
1782 | break; |
1783 | } |
1784 | } |
1785 | |
1786 | return FALSE; |
1787 | } |
1788 | |
0bd8d76d |
1789 | int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) |
1790 | { |
1791 | struct dlgparam *dp = (struct dlgparam *)data; |
1792 | |
1793 | if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up || |
1794 | event->keyval == GDK_Down || event->keyval == GDK_KP_Down) { |
c5d64b49 |
1795 | int dir, i, j = -1; |
0bd8d76d |
1796 | for (i = 0; i < dp->ntreeitems; i++) |
c5d64b49 |
1797 | if (widget == dp->treeitems[i]) |
1798 | break; |
1799 | if (i < dp->ntreeitems) { |
1800 | if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up) |
1801 | dir = -1; |
1802 | else |
1803 | dir = +1; |
1804 | |
1805 | while (1) { |
1806 | i += dir; |
1807 | if (i < 0 || i >= dp->ntreeitems) |
1808 | break; /* nothing in that dir to select */ |
1809 | /* |
1810 | * Determine if this tree item is visible. |
1811 | */ |
1812 | { |
1813 | GtkWidget *w = dp->treeitems[i]; |
1814 | int vis = TRUE; |
1d009ae7 |
1815 | while (w && (GTK_IS_TREE_ITEM(w) || GTK_IS_TREE(w))) { |
c5d64b49 |
1816 | if (!GTK_WIDGET_VISIBLE(w)) { |
1817 | vis = FALSE; |
1818 | break; |
1819 | } |
1820 | w = w->parent; |
1821 | } |
1822 | if (vis) { |
1823 | j = i; /* got one */ |
1824 | break; |
1825 | } |
1826 | } |
1827 | } |
1828 | } |
0bd8d76d |
1829 | gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), |
1830 | "key_press_event"); |
1831 | if (j >= 0) { |
0bd8d76d |
1832 | gtk_signal_emit_by_name(GTK_OBJECT(dp->treeitems[j]), "toggle"); |
1833 | gtk_widget_grab_focus(dp->treeitems[j]); |
1834 | } |
1835 | return TRUE; |
1836 | } |
1837 | |
0bd8d76d |
1838 | /* |
c5d64b49 |
1839 | * It's nice for Left and Right to expand and collapse tree |
1840 | * branches. |
0bd8d76d |
1841 | */ |
c5d64b49 |
1842 | if (event->keyval == GDK_Left || event->keyval == GDK_KP_Left) { |
1843 | gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), |
1844 | "key_press_event"); |
1845 | gtk_tree_item_collapse(GTK_TREE_ITEM(widget)); |
1846 | return TRUE; |
1847 | } |
1848 | if (event->keyval == GDK_Right || event->keyval == GDK_KP_Right) { |
1849 | gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), |
1850 | "key_press_event"); |
1851 | gtk_tree_item_expand(GTK_TREE_ITEM(widget)); |
1852 | return TRUE; |
0bd8d76d |
1853 | } |
c5d64b49 |
1854 | |
1855 | return FALSE; |
0bd8d76d |
1856 | } |
1857 | |
1c291fcf |
1858 | void shortcut_add(struct Shortcuts *scs, GtkWidget *labelw, |
1859 | int chr, int action, void *ptr) |
1860 | { |
1861 | GtkLabel *label = GTK_LABEL(labelw); |
1862 | gchar *currstr, *pattern; |
1863 | int i; |
1864 | |
1865 | if (chr == NO_SHORTCUT) |
1866 | return; |
1867 | |
1868 | chr = tolower((unsigned char)chr); |
1869 | |
1870 | assert(scs->sc[chr].action == SHORTCUT_EMPTY); |
1871 | |
1872 | scs->sc[chr].action = action; |
1873 | |
1874 | if (action == SHORTCUT_FOCUS) { |
1875 | scs->sc[chr].uc = NULL; |
1876 | scs->sc[chr].widget = (GtkWidget *)ptr; |
1877 | } else { |
1878 | scs->sc[chr].widget = NULL; |
1879 | scs->sc[chr].uc = (struct uctrl *)ptr; |
1880 | } |
1881 | |
1882 | gtk_label_get(label, &currstr); |
1883 | for (i = 0; currstr[i]; i++) |
1884 | if (tolower((unsigned char)currstr[i]) == chr) { |
1885 | GtkRequisition req; |
1886 | |
1887 | pattern = dupprintf("%*s_", i, ""); |
1888 | |
1889 | gtk_widget_size_request(GTK_WIDGET(label), &req); |
1890 | gtk_label_set_pattern(label, pattern); |
1891 | gtk_widget_set_usize(GTK_WIDGET(label), -1, req.height); |
1892 | |
1893 | sfree(pattern); |
1894 | break; |
1895 | } |
1896 | } |
1897 | |
1d009ae7 |
1898 | int do_config_box(const char *title, Config *cfg) |
d9b15094 |
1899 | { |
1900 | GtkWidget *window, *hbox, *vbox, *cols, *label, |
1901 | *tree, *treescroll, *panels, *panelvbox; |
1d0d4a3b |
1902 | int index, level, listitemheight; |
d9b15094 |
1903 | struct controlbox *ctrlbox; |
1904 | char *path; |
1905 | GtkTreeItem *treeitemlevels[8]; |
1906 | GtkTree *treelevels[8]; |
0f5e1f75 |
1907 | struct dlgparam dp; |
1908 | struct sesslist sl; |
1c291fcf |
1909 | struct Shortcuts scs; |
d9b15094 |
1910 | |
1911 | struct selparam *selparams = NULL; |
1912 | int nselparams = 0, selparamsize = 0; |
1913 | |
0f5e1f75 |
1914 | dlg_init(&dp); |
1915 | |
1d0d4a3b |
1916 | { |
1917 | GtkWidget *listitem = gtk_list_item_new_with_label("foo"); |
1918 | GtkRequisition req; |
1919 | gtk_widget_size_request(listitem, &req); |
1920 | listitemheight = req.height; |
1921 | gtk_widget_unref(listitem); |
1922 | } |
1923 | |
8dacc30e |
1924 | get_sesslist(&sl, TRUE); |
0f5e1f75 |
1925 | |
1c291fcf |
1926 | for (index = 0; index < lenof(scs.sc); index++) { |
1927 | scs.sc[index].action = SHORTCUT_EMPTY; |
1928 | } |
1929 | |
d9b15094 |
1930 | ctrlbox = ctrl_new_box(); |
0f5e1f75 |
1931 | setup_config_box(ctrlbox, &sl, FALSE, 0); |
1d0d4a3b |
1932 | unix_setup_config_box(ctrlbox, FALSE); |
d9b15094 |
1933 | |
1934 | window = gtk_dialog_new(); |
c5d64b49 |
1935 | gtk_window_set_title(GTK_WINDOW(window), title); |
d9b15094 |
1936 | hbox = gtk_hbox_new(FALSE, 4); |
1937 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), hbox, TRUE, TRUE, 0); |
1d0d4a3b |
1938 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 10); |
d9b15094 |
1939 | gtk_widget_show(hbox); |
1940 | vbox = gtk_vbox_new(FALSE, 4); |
1941 | gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
1942 | gtk_widget_show(vbox); |
1943 | cols = columns_new(4); |
1944 | gtk_box_pack_start(GTK_BOX(vbox), cols, FALSE, FALSE, 0); |
1945 | gtk_widget_show(cols); |
1946 | label = gtk_label_new("Category:"); |
1947 | columns_add(COLUMNS(cols), label, 0, 1); |
1948 | columns_force_left_align(COLUMNS(cols), label); |
1949 | gtk_widget_show(label); |
1950 | treescroll = gtk_scrolled_window_new(NULL, NULL); |
1951 | tree = gtk_tree_new(); |
0bd8d76d |
1952 | gtk_signal_connect(GTK_OBJECT(tree), "focus_in_event", |
1953 | GTK_SIGNAL_FUNC(widget_focus), &dp); |
c5d64b49 |
1954 | shortcut_add(&scs, label, 'g', SHORTCUT_TREE, tree); |
d9b15094 |
1955 | gtk_tree_set_view_mode(GTK_TREE(tree), GTK_TREE_VIEW_ITEM); |
1d0d4a3b |
1956 | gtk_tree_set_selection_mode(GTK_TREE(tree), GTK_SELECTION_BROWSE); |
d9b15094 |
1957 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(treescroll), |
1958 | tree); |
1959 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(treescroll), |
1960 | GTK_POLICY_NEVER, |
1961 | GTK_POLICY_AUTOMATIC); |
0bd8d76d |
1962 | gtk_signal_connect(GTK_OBJECT(tree), "focus", |
1963 | GTK_SIGNAL_FUNC(tree_focus), &dp); |
d9b15094 |
1964 | gtk_widget_show(tree); |
1965 | gtk_widget_show(treescroll); |
1966 | gtk_box_pack_start(GTK_BOX(vbox), treescroll, TRUE, TRUE, 0); |
1967 | panels = panels_new(); |
1968 | gtk_box_pack_start(GTK_BOX(hbox), panels, TRUE, TRUE, 0); |
1969 | gtk_widget_show(panels); |
1970 | |
1971 | panelvbox = NULL; |
1972 | path = NULL; |
1973 | level = 0; |
1974 | for (index = 0; index < ctrlbox->nctrlsets; index++) { |
1975 | struct controlset *s = ctrlbox->ctrlsets[index]; |
1c291fcf |
1976 | GtkWidget *w; |
d9b15094 |
1977 | |
1978 | if (!*s->pathname) { |
1c291fcf |
1979 | w = layout_ctrls(&dp, &scs, s, listitemheight, GTK_WINDOW(window)); |
d9b15094 |
1980 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->action_area), |
1981 | w, TRUE, TRUE, 0); |
1982 | } else { |
1983 | int j = path ? ctrl_path_compare(s->pathname, path) : 0; |
1984 | if (j != INT_MAX) { /* add to treeview, start new panel */ |
1985 | char *c; |
1986 | GtkWidget *treeitem; |
1987 | int first; |
1988 | |
1989 | /* |
1990 | * We expect never to find an implicit path |
1991 | * component. For example, we expect never to see |
1992 | * A/B/C followed by A/D/E, because that would |
1993 | * _implicitly_ create A/D. All our path prefixes |
1994 | * are expected to contain actual controls and be |
1995 | * selectable in the treeview; so we would expect |
1996 | * to see A/D _explicitly_ before encountering |
1997 | * A/D/E. |
1998 | */ |
1999 | assert(j == ctrl_path_elements(s->pathname) - 1); |
2000 | |
2001 | c = strrchr(s->pathname, '/'); |
2002 | if (!c) |
2003 | c = s->pathname; |
2004 | else |
2005 | c++; |
2006 | |
2007 | treeitem = gtk_tree_item_new_with_label(c); |
2008 | assert(j-1 < level); |
2009 | if (j > 0) { |
2010 | if (!treelevels[j-1]) { |
2011 | treelevels[j-1] = GTK_TREE(gtk_tree_new()); |
2012 | gtk_tree_item_set_subtree |
2013 | (treeitemlevels[j-1], |
2014 | GTK_WIDGET(treelevels[j-1])); |
2015 | gtk_tree_item_expand(treeitemlevels[j-1]); |
2016 | } |
2017 | gtk_tree_append(treelevels[j-1], treeitem); |
2018 | } else { |
2019 | gtk_tree_append(GTK_TREE(tree), treeitem); |
2020 | } |
2021 | treeitemlevels[j] = GTK_TREE_ITEM(treeitem); |
2022 | treelevels[j] = NULL; |
2023 | level = j+1; |
2024 | |
0bd8d76d |
2025 | gtk_signal_connect(GTK_OBJECT(treeitem), "key_press_event", |
2026 | GTK_SIGNAL_FUNC(tree_key_press), &dp); |
2027 | gtk_signal_connect(GTK_OBJECT(treeitem), "focus_in_event", |
2028 | GTK_SIGNAL_FUNC(widget_focus), &dp); |
2029 | |
d9b15094 |
2030 | gtk_widget_show(treeitem); |
2031 | |
2032 | path = s->pathname; |
2033 | |
2034 | first = (panelvbox == NULL); |
2035 | |
2036 | panelvbox = gtk_vbox_new(FALSE, 4); |
2037 | gtk_container_add(GTK_CONTAINER(panels), panelvbox); |
2038 | if (first) { |
2039 | panels_switch_to(PANELS(panels), panelvbox); |
2040 | gtk_tree_select_child(GTK_TREE(tree), treeitem); |
2041 | } |
2042 | |
2043 | if (nselparams >= selparamsize) { |
2044 | selparamsize += 16; |
3d88e64d |
2045 | selparams = sresize(selparams, selparamsize, |
2046 | struct selparam); |
d9b15094 |
2047 | } |
1c291fcf |
2048 | selparams[nselparams].dp = &dp; |
d9b15094 |
2049 | selparams[nselparams].panels = PANELS(panels); |
2050 | selparams[nselparams].panel = panelvbox; |
1c291fcf |
2051 | selparams[nselparams].shortcuts = scs; /* structure copy */ |
d9b15094 |
2052 | selparams[nselparams].treeitem = treeitem; |
2053 | nselparams++; |
2054 | |
2055 | } |
2056 | |
1c291fcf |
2057 | w = layout_ctrls(&dp, |
2058 | &selparams[nselparams-1].shortcuts, |
2059 | s, listitemheight, NULL); |
d9b15094 |
2060 | gtk_box_pack_start(GTK_BOX(panelvbox), w, FALSE, FALSE, 0); |
1d0d4a3b |
2061 | gtk_widget_show(w); |
d9b15094 |
2062 | } |
2063 | } |
2064 | |
0bd8d76d |
2065 | dp.ntreeitems = nselparams; |
3d88e64d |
2066 | dp.treeitems = snewn(dp.ntreeitems, GtkWidget *); |
0bd8d76d |
2067 | |
d9b15094 |
2068 | for (index = 0; index < nselparams; index++) { |
2069 | gtk_signal_connect(GTK_OBJECT(selparams[index].treeitem), "select", |
2070 | GTK_SIGNAL_FUNC(treeitem_sel), |
2071 | &selparams[index]); |
0bd8d76d |
2072 | dp.treeitems[index] = selparams[index].treeitem; |
d9b15094 |
2073 | } |
2074 | |
1d009ae7 |
2075 | dp.data = cfg; |
0f5e1f75 |
2076 | dlg_refresh(NULL, &dp); |
2077 | |
1c291fcf |
2078 | dp.shortcuts = &selparams[0].shortcuts; |
0bd8d76d |
2079 | dp.currtreeitem = dp.treeitems[0]; |
2080 | dp.lastfocus = NULL; |
2081 | dp.retval = 0; |
23897ed0 |
2082 | dp.window = window; |
1c291fcf |
2083 | |
23897ed0 |
2084 | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); |
d9b15094 |
2085 | gtk_widget_show(window); |
2086 | |
0bd8d76d |
2087 | /* |
2088 | * Set focus into the first available control. |
2089 | */ |
2090 | for (index = 0; index < ctrlbox->nctrlsets; index++) { |
2091 | struct controlset *s = ctrlbox->ctrlsets[index]; |
2092 | int done = 0; |
2093 | int j; |
2094 | |
2095 | if (*s->pathname) { |
2096 | for (j = 0; j < s->ncontrols; j++) |
2097 | if (s->ctrls[j]->generic.type != CTRL_TABDELAY && |
2098 | s->ctrls[j]->generic.type != CTRL_COLUMNS && |
2099 | s->ctrls[j]->generic.type != CTRL_TEXT) { |
2100 | dlg_set_focus(s->ctrls[j], &dp); |
2101 | dp.lastfocus = s->ctrls[j]; |
2102 | done = 1; |
2103 | break; |
2104 | } |
2105 | } |
2106 | if (done) |
2107 | break; |
2108 | } |
2109 | |
d9b15094 |
2110 | gtk_signal_connect(GTK_OBJECT(window), "destroy", |
0bd8d76d |
2111 | GTK_SIGNAL_FUNC(window_destroy), NULL); |
1c291fcf |
2112 | gtk_signal_connect(GTK_OBJECT(window), "key_press_event", |
2113 | GTK_SIGNAL_FUNC(win_key_press), &dp); |
d9b15094 |
2114 | |
2115 | gtk_main(); |
2116 | |
8dacc30e |
2117 | get_sesslist(&sl, FALSE); |
0f5e1f75 |
2118 | dlg_cleanup(&dp); |
d9b15094 |
2119 | sfree(selparams); |
0bd8d76d |
2120 | |
2121 | return dp.retval; |
d9b15094 |
2122 | } |
2123 | |
5bf9955d |
2124 | static void messagebox_handler(union control *ctrl, void *dlg, |
2125 | void *data, int event) |
2126 | { |
2127 | if (event == EVENT_ACTION) |
2128 | dlg_end(dlg, ctrl->generic.context.i); |
2129 | } |
2130 | int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...) |
2131 | { |
2132 | GtkWidget *window, *w0, *w1; |
2133 | struct controlbox *ctrlbox; |
2134 | struct controlset *s0, *s1; |
2135 | union control *c; |
2136 | struct dlgparam dp; |
2137 | struct Shortcuts scs; |
2138 | int index, ncols; |
2139 | va_list ap; |
d9b15094 |
2140 | |
5bf9955d |
2141 | dlg_init(&dp); |
d9b15094 |
2142 | |
5bf9955d |
2143 | for (index = 0; index < lenof(scs.sc); index++) { |
2144 | scs.sc[index].action = SHORTCUT_EMPTY; |
2145 | } |
d9b15094 |
2146 | |
5bf9955d |
2147 | ctrlbox = ctrl_new_box(); |
c5d64b49 |
2148 | |
5bf9955d |
2149 | ncols = 0; |
2150 | va_start(ap, minwid); |
2151 | while (va_arg(ap, char *) != NULL) { |
2152 | ncols++; |
2153 | (void) va_arg(ap, int); /* shortcut */ |
2154 | (void) va_arg(ap, int); /* normal/default/cancel */ |
2155 | (void) va_arg(ap, int); /* end value */ |
2156 | } |
2157 | va_end(ap); |
d9b15094 |
2158 | |
5bf9955d |
2159 | s0 = ctrl_getset(ctrlbox, "", "", ""); |
2160 | c = ctrl_columns(s0, 2, 50, 50); |
2161 | c->columns.ncols = s0->ncolumns = ncols; |
2162 | c->columns.percentages = sresize(c->columns.percentages, ncols, int); |
2163 | for (index = 0; index < ncols; index++) |
2164 | c->columns.percentages[index] = (index+1)*100/ncols - index*100/ncols; |
2165 | va_start(ap, minwid); |
2166 | index = 0; |
2167 | while (1) { |
2168 | char *title = va_arg(ap, char *); |
2169 | int shortcut, type, value; |
2170 | if (title == NULL) |
2171 | break; |
2172 | shortcut = va_arg(ap, int); |
2173 | type = va_arg(ap, int); |
2174 | value = va_arg(ap, int); |
2175 | c = ctrl_pushbutton(s0, title, shortcut, HELPCTX(no_help), |
2176 | messagebox_handler, I(value)); |
2177 | c->generic.column = index++; |
2178 | if (type > 0) |
2179 | c->button.isdefault = TRUE; |
2180 | else if (type < 0) |
2181 | c->button.iscancel = TRUE; |
2182 | } |
d9b15094 |
2183 | va_end(ap); |
d9b15094 |
2184 | |
5bf9955d |
2185 | s1 = ctrl_getset(ctrlbox, "x", "", ""); |
2186 | ctrl_text(s1, msg, HELPCTX(no_help)); |
d9b15094 |
2187 | |
5bf9955d |
2188 | window = gtk_dialog_new(); |
2189 | gtk_window_set_title(GTK_WINDOW(window), title); |
2190 | w0 = layout_ctrls(&dp, &scs, s0, 0, GTK_WINDOW(window)); |
2191 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->action_area), |
2192 | w0, TRUE, TRUE, 0); |
2193 | gtk_widget_show(w0); |
2194 | w1 = layout_ctrls(&dp, &scs, s1, 0, GTK_WINDOW(window)); |
2195 | gtk_container_set_border_width(GTK_CONTAINER(w1), 10); |
2196 | gtk_widget_set_usize(w1, minwid+20, -1); |
2197 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), |
2198 | w1, TRUE, TRUE, 0); |
2199 | gtk_widget_show(w1); |
d9b15094 |
2200 | |
5bf9955d |
2201 | dp.shortcuts = &scs; |
2202 | dp.lastfocus = NULL; |
2203 | dp.retval = 0; |
2204 | dp.window = window; |
d9b15094 |
2205 | |
5bf9955d |
2206 | gtk_window_set_modal(GTK_WINDOW(window), TRUE); |
2207 | if (parentwin) { |
2208 | gint x, y, w, h, dx, dy; |
2209 | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_NONE); |
2210 | gdk_window_get_origin(parentwin->window, &x, &y); |
2211 | gdk_window_get_size(parentwin->window, &w, &h); |
2212 | dx = x + w/4; |
2213 | dy = y + h/4; |
2214 | gtk_widget_set_uposition(GTK_WIDGET(window), dx, dy); |
2215 | gtk_window_set_transient_for(GTK_WINDOW(window), |
2216 | GTK_WINDOW(parentwin)); |
2217 | } else |
2218 | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); |
2219 | gtk_widget_show(window); |
d9b15094 |
2220 | |
5bf9955d |
2221 | gtk_signal_connect(GTK_OBJECT(window), "destroy", |
2222 | GTK_SIGNAL_FUNC(window_destroy), NULL); |
2223 | gtk_signal_connect(GTK_OBJECT(window), "key_press_event", |
2224 | GTK_SIGNAL_FUNC(win_key_press), &dp); |
d9b15094 |
2225 | |
5bf9955d |
2226 | gtk_main(); |
2227 | |
2228 | dlg_cleanup(&dp); |
2229 | ctrl_free_box(ctrlbox); |
2230 | |
2231 | return dp.retval; |
d9b15094 |
2232 | } |
2233 | |
5bf9955d |
2234 | static int string_width(char *text) |
2235 | { |
2236 | GtkWidget *label = gtk_label_new(text); |
2237 | GtkRequisition req; |
2238 | gtk_widget_size_request(label, &req); |
2239 | gtk_widget_unref(label); |
2240 | return req.width; |
2241 | } |
2242 | |
2243 | void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, |
2244 | char *keystr, char *fingerprint) |
2245 | { |
2246 | static const char absenttxt[] = |
2247 | "The server's host key is not cached. You have no guarantee " |
2248 | "that the server is the computer you think it is.\n" |
2249 | "The server's key fingerprint is:\n" |
2250 | "%s\n" |
2251 | "If you trust this host, press \"Accept\" to add the key to " |
2252 | "PuTTY's cache and carry on connecting.\n" |
2253 | "If you want to carry on connecting just once, without " |
2254 | "adding the key to the cache, press \"Connect Once\".\n" |
2255 | "If you do not trust this host, press \"Cancel\" to abandon the " |
2256 | "connection."; |
2257 | static const char wrongtxt[] = |
2258 | "WARNING - POTENTIAL SECURITY BREACH!\n" |
2259 | "The server's host key does not match the one PuTTY has " |
2260 | "cached. This means that either the server administrator " |
2261 | "has changed the host key, or you have actually connected " |
2262 | "to another computer pretending to be the server.\n" |
2263 | "The new key fingerprint is:\n" |
2264 | "%s\n" |
2265 | "If you were expecting this change and trust the new key, " |
2266 | "press \"Accept\" to update PuTTY's cache and continue connecting.\n" |
2267 | "If you want to carry on connecting but without updating " |
2268 | "the cache, press \"Connect Once\".\n" |
2269 | "If you want to abandon the connection completely, press " |
2270 | "\"Cancel\" to cancel. Pressing \"Cancel\" is the ONLY guaranteed " |
2271 | "safe choice."; |
2272 | char *text; |
2273 | int ret; |
2274 | |
2275 | /* |
2276 | * Verify the key. |
2277 | */ |
2278 | ret = verify_host_key(host, port, keytype, keystr); |
2279 | |
2280 | if (ret == 0) /* success - key matched OK */ |
2281 | return; |
2282 | |
2283 | text = dupprintf((ret == 2 ? wrongtxt : absenttxt), fingerprint); |
2284 | |
2285 | ret = messagebox(GTK_WIDGET(get_window(frontend)), |
2286 | "PuTTY Security Alert", text, |
2287 | string_width(fingerprint), |
2288 | "Accept", 'a', 0, 2, |
2289 | "Connect Once", 'o', 0, 1, |
2290 | "Cancel", 'c', -1, 0, |
2291 | NULL); |
2292 | |
2293 | sfree(text); |
2294 | |
2295 | if (ret == 0) |
2296 | cleanup_exit(0); |
2297 | else if (ret == 2) |
2298 | store_host_key(host, port, keytype, keystr); |
d9b15094 |
2299 | } |
2300 | |
5bf9955d |
2301 | /* |
2302 | * Ask whether the selected cipher is acceptable (since it was |
2303 | * below the configured 'warn' threshold). |
2304 | * cs: 0 = both ways, 1 = client->server, 2 = server->client |
2305 | */ |
2306 | void askcipher(void *frontend, char *ciphername, int cs) |
2307 | { |
2308 | static const char msg[] = |
2309 | "The first %scipher supported by the server is " |
2310 | "%s, which is below the configured warning threshold.\n" |
2311 | "Continue with connection?"; |
2312 | char *text; |
2313 | int ret; |
2314 | |
2315 | text = dupprintf(msg, (cs == 0) ? "" : |
2316 | (cs == 1) ? "client-to-server " : "server-to-client ", |
2317 | ciphername); |
2318 | ret = messagebox(GTK_WIDGET(get_window(frontend)), |
2319 | "PuTTY Security Alert", text, |
2320 | string_width("Continue with connection?"), |
2321 | "Yes", 'y', 0, 1, |
2322 | "No", 'n', 0, 0, |
2323 | NULL); |
2324 | sfree(text); |
2325 | |
2326 | if (ret) { |
2327 | return; |
2328 | } else { |
2329 | cleanup_exit(0); |
2330 | } |
d9b15094 |
2331 | } |
2332 | |
5bf9955d |
2333 | void old_keyfile_warning(void) |
d9b15094 |
2334 | { |
5bf9955d |
2335 | /* |
2336 | * This should never happen on Unix. We hope. |
2337 | */ |
d9b15094 |
2338 | } |
2339 | |
3f935d5b |
2340 | void fatal_message_box(void *window, char *msg) |
d9b15094 |
2341 | { |
3f935d5b |
2342 | messagebox(window, "PuTTY Fatal Error", msg, |
5bf9955d |
2343 | string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"), |
2344 | "OK", 'o', 1, 1, NULL); |
d9b15094 |
2345 | } |
3f935d5b |
2346 | |
2347 | void fatalbox(char *p, ...) |
d9b15094 |
2348 | { |
5bf9955d |
2349 | va_list ap; |
2350 | char *msg; |
2351 | va_start(ap, p); |
2352 | msg = dupvprintf(p, ap); |
2353 | va_end(ap); |
3f935d5b |
2354 | fatal_message_box(NULL, msg); |
5bf9955d |
2355 | sfree(msg); |
2356 | cleanup_exit(1); |
d9b15094 |
2357 | } |
47e4e735 |
2358 | |
2359 | static GtkWidget *aboutbox = NULL; |
2360 | |
2361 | static void about_close_clicked(GtkButton *button, gpointer data) |
2362 | { |
2363 | gtk_widget_destroy(aboutbox); |
2364 | aboutbox = NULL; |
2365 | } |
2366 | |
2367 | static void licence_clicked(GtkButton *button, gpointer data) |
2368 | { |
2369 | char *title; |
2370 | |
2371 | char *licence = |
2372 | "Copyright 1997-2003 Simon Tatham.\n\n" |
2373 | |
2374 | "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " |
2375 | "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas " |
2376 | "Barry, Justin Bradford, Ben Harris, and CORE SDI S.A.\n\n" |
2377 | |
2378 | "Permission is hereby granted, free of charge, to any person " |
2379 | "obtaining a copy of this software and associated documentation " |
2380 | "files (the ""Software""), to deal in the Software without restriction, " |
2381 | "including without limitation the rights to use, copy, modify, merge, " |
2382 | "publish, distribute, sublicense, and/or sell copies of the Software, " |
2383 | "and to permit persons to whom the Software is furnished to do so, " |
2384 | "subject to the following conditions:\n\n" |
2385 | |
2386 | "The above copyright notice and this permission notice shall be " |
2387 | "included in all copies or substantial portions of the Software.\n\n" |
2388 | |
2389 | "THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT " |
2390 | "WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, " |
2391 | "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " |
2392 | "MERCHANTABILITY, FITNESS FOR A PARTICULAR " |
2393 | "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " |
2394 | "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES " |
2395 | "OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " |
2396 | "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN " |
2397 | "CONNECTION WITH THE SOFTWARE OR THE USE OR " |
2398 | "OTHER DEALINGS IN THE SOFTWARE."; |
2399 | |
2400 | title = dupcat(appname, " Licence", NULL); |
2401 | assert(aboutbox != NULL); |
2402 | messagebox(aboutbox, title, licence, |
2403 | string_width("LONGISH LINE OF TEXT SO THE LICENCE" |
2404 | " BOX ISN'T EXCESSIVELY TALL AND THIN"), |
2405 | "OK", 'o', 1, 1, NULL); |
2406 | sfree(title); |
2407 | } |
2408 | |
2409 | void about_box(void) |
2410 | { |
2411 | GtkWidget *w; |
2412 | char *title; |
2413 | |
2414 | if (aboutbox) { |
2415 | gtk_widget_grab_focus(aboutbox); |
2416 | return; |
2417 | } |
2418 | |
2419 | aboutbox = gtk_dialog_new(); |
2420 | gtk_container_set_border_width(GTK_CONTAINER(aboutbox), 10); |
2421 | title = dupcat("About ", appname, NULL); |
2422 | gtk_window_set_title(GTK_WINDOW(aboutbox), title); |
2423 | sfree(title); |
2424 | |
2425 | w = gtk_button_new_with_label("Close"); |
2426 | GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT); |
2427 | gtk_window_set_default(GTK_WINDOW(aboutbox), w); |
2428 | gtk_box_pack_end(GTK_BOX(GTK_DIALOG(aboutbox)->action_area), |
2429 | w, FALSE, FALSE, 0); |
2430 | gtk_signal_connect(GTK_OBJECT(w), "clicked", |
2431 | GTK_SIGNAL_FUNC(about_close_clicked), NULL); |
2432 | gtk_widget_show(w); |
2433 | |
2434 | w = gtk_button_new_with_label("View Licence"); |
2435 | GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT); |
2436 | gtk_box_pack_end(GTK_BOX(GTK_DIALOG(aboutbox)->action_area), |
2437 | w, FALSE, FALSE, 0); |
2438 | gtk_signal_connect(GTK_OBJECT(w), "clicked", |
2439 | GTK_SIGNAL_FUNC(licence_clicked), NULL); |
2440 | gtk_widget_show(w); |
2441 | |
2442 | w = gtk_label_new(appname); |
2443 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox)->vbox), |
2444 | w, FALSE, FALSE, 0); |
2445 | gtk_widget_show(w); |
2446 | |
2447 | w = gtk_label_new(ver); |
2448 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox)->vbox), |
2449 | w, FALSE, FALSE, 5); |
2450 | gtk_widget_show(w); |
2451 | |
2452 | w = gtk_label_new("Copyright 1997-2003 Simon Tatham. All rights reserved"); |
2453 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox)->vbox), |
2454 | w, FALSE, FALSE, 5); |
2455 | gtk_widget_show(w); |
2456 | |
2457 | gtk_widget_show(aboutbox); |
2458 | } |