2 * gtkdlg.c - GTK implementation of the PuTTY configuration box.
6 * TODO when porting to GTK 2.0:
8 * - GtkTree is apparently deprecated and we should switch to
10 * - GtkLabel has a built-in mnemonic scheme, so we should at
11 * least consider switching to that from the current adhockery.
19 #include <gdk/gdkkeysyms.h>
22 #include <X11/Xutil.h>
28 #define PUTTY_DO_GLOBALS /* actually _define_ globals */
43 struct Shortcut sc
[128];
50 int privdata_needs_free
;
51 GtkWidget
**buttons
; int nbuttons
; /* for radio buttons */
52 GtkWidget
*entry
; /* for editbox, combobox, filesel, fontsel */
53 GtkWidget
*button
; /* for filesel, fontsel */
54 GtkWidget
*list
; /* for combobox, listbox */
55 GtkWidget
*menu
; /* for optionmenu (==droplist) */
56 GtkWidget
*optmenu
; /* also for optionmenu */
57 GtkWidget
*text
; /* for text */
58 GtkAdjustment
*adj
; /* for the scrollbar in a list box */
63 tree234
*byctrl
, *bywidget
;
65 struct { unsigned char r
, g
, b
, ok
; } coloursel_result
; /* 0-255 */
66 /* `flags' are set to indicate when a GTK signal handler is being called
67 * due to automatic processing and should not flag a user event. */
69 struct Shortcuts
*shortcuts
;
70 GtkWidget
*window
, *cancelbutton
, *currtreeitem
, **treeitems
;
71 union control
*currfocus
, *lastfocus
;
75 #define FLAG_UPDATING_COMBO_LIST 1
77 enum { /* values for Shortcut.action */
78 SHORTCUT_EMPTY
, /* no shortcut on this key */
79 SHORTCUT_TREE
, /* focus a tree item */
80 SHORTCUT_FOCUS
, /* focus the supplied widget */
81 SHORTCUT_UCTRL
, /* do something sane with uctrl */
82 SHORTCUT_UCTRL_UP
, /* uctrl is a draglist, move Up */
83 SHORTCUT_UCTRL_DOWN
, /* uctrl is a draglist, move Down */
89 static gboolean
widget_focus(GtkWidget
*widget
, GdkEventFocus
*event
,
91 static void shortcut_add(struct Shortcuts
*scs
, GtkWidget
*labelw
,
92 int chr
, int action
, void *ptr
);
93 static int listitem_single_key(GtkWidget
*item
, GdkEventKey
*event
,
95 static int listitem_multi_key(GtkWidget
*item
, GdkEventKey
*event
,
97 static int listitem_button(GtkWidget
*item
, GdkEventButton
*event
,
99 static void menuitem_activate(GtkMenuItem
*item
, gpointer data
);
100 static void coloursel_ok(GtkButton
*button
, gpointer data
);
101 static void coloursel_cancel(GtkButton
*button
, gpointer data
);
102 static void window_destroy(GtkWidget
*widget
, gpointer data
);
104 static int uctrl_cmp_byctrl(void *av
, void *bv
)
106 struct uctrl
*a
= (struct uctrl
*)av
;
107 struct uctrl
*b
= (struct uctrl
*)bv
;
108 if (a
->ctrl
< b
->ctrl
)
110 else if (a
->ctrl
> b
->ctrl
)
115 static int uctrl_cmp_byctrl_find(void *av
, void *bv
)
117 union control
*a
= (union control
*)av
;
118 struct uctrl
*b
= (struct uctrl
*)bv
;
121 else if (a
> b
->ctrl
)
126 static int uctrl_cmp_bywidget(void *av
, void *bv
)
128 struct uctrl
*a
= (struct uctrl
*)av
;
129 struct uctrl
*b
= (struct uctrl
*)bv
;
130 if (a
->toplevel
< b
->toplevel
)
132 else if (a
->toplevel
> b
->toplevel
)
137 static int uctrl_cmp_bywidget_find(void *av
, void *bv
)
139 GtkWidget
*a
= (GtkWidget
*)av
;
140 struct uctrl
*b
= (struct uctrl
*)bv
;
143 else if (a
> b
->toplevel
)
148 static void dlg_init(struct dlgparam
*dp
)
150 dp
->byctrl
= newtree234(uctrl_cmp_byctrl
);
151 dp
->bywidget
= newtree234(uctrl_cmp_bywidget
);
152 dp
->coloursel_result
.ok
= FALSE
;
153 dp
->treeitems
= NULL
;
154 dp
->window
= dp
->cancelbutton
= dp
->currtreeitem
= NULL
;
157 static void dlg_cleanup(struct dlgparam
*dp
)
161 freetree234(dp
->byctrl
); /* doesn't free the uctrls inside */
163 while ( (uc
= index234(dp
->bywidget
, 0)) != NULL
) {
164 del234(dp
->bywidget
, uc
);
165 if (uc
->privdata_needs_free
)
170 freetree234(dp
->bywidget
);
172 sfree(dp
->treeitems
);
175 static void dlg_add_uctrl(struct dlgparam
*dp
, struct uctrl
*uc
)
177 add234(dp
->byctrl
, uc
);
178 add234(dp
->bywidget
, uc
);
181 static struct uctrl
*dlg_find_byctrl(struct dlgparam
*dp
, union control
*ctrl
)
185 return find234(dp
->byctrl
, ctrl
, uctrl_cmp_byctrl_find
);
188 static struct uctrl
*dlg_find_bywidget(struct dlgparam
*dp
, GtkWidget
*w
)
190 struct uctrl
*ret
= NULL
;
194 ret
= find234(dp
->bywidget
, w
, uctrl_cmp_bywidget_find
);
202 void *dlg_get_privdata(union control
*ctrl
, void *dlg
)
204 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
205 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
209 void dlg_set_privdata(union control
*ctrl
, void *dlg
, void *ptr
)
211 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
212 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
214 uc
->privdata_needs_free
= FALSE
;
217 void *dlg_alloc_privdata(union control
*ctrl
, void *dlg
, size_t size
)
219 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
220 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
222 * This is an internal allocation routine, so it's allowed to
223 * use smalloc directly.
225 uc
->privdata
= smalloc(size
);
226 uc
->privdata_needs_free
= FALSE
;
230 union control
*dlg_last_focused(union control
*ctrl
, void *dlg
)
232 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
233 if (dp
->currfocus
!= ctrl
)
234 return dp
->currfocus
;
236 return dp
->lastfocus
;
239 void dlg_radiobutton_set(union control
*ctrl
, void *dlg
, int which
)
241 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
242 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
243 assert(uc
->ctrl
->generic
.type
== CTRL_RADIO
);
244 assert(uc
->buttons
!= NULL
);
245 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(uc
->buttons
[which
]), TRUE
);
248 int dlg_radiobutton_get(union control
*ctrl
, void *dlg
)
250 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
251 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
254 assert(uc
->ctrl
->generic
.type
== CTRL_RADIO
);
255 assert(uc
->buttons
!= NULL
);
256 for (i
= 0; i
< uc
->nbuttons
; i
++)
257 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(uc
->buttons
[i
])))
259 return 0; /* got to return something */
262 void dlg_checkbox_set(union control
*ctrl
, void *dlg
, int checked
)
264 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
265 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
266 assert(uc
->ctrl
->generic
.type
== CTRL_CHECKBOX
);
267 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(uc
->toplevel
), checked
);
270 int dlg_checkbox_get(union control
*ctrl
, void *dlg
)
272 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
273 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
274 assert(uc
->ctrl
->generic
.type
== CTRL_CHECKBOX
);
275 return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(uc
->toplevel
));
278 void dlg_editbox_set(union control
*ctrl
, void *dlg
, char const *text
)
280 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
281 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
282 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
);
283 assert(uc
->entry
!= NULL
);
284 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), text
);
287 void dlg_editbox_get(union control
*ctrl
, void *dlg
, char *buffer
, int length
)
289 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
290 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
291 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
);
292 assert(uc
->entry
!= NULL
);
293 strncpy(buffer
, gtk_entry_get_text(GTK_ENTRY(uc
->entry
)),
295 buffer
[length
-1] = '\0';
298 static void container_remove_and_destroy(GtkWidget
*w
, gpointer data
)
300 GtkContainer
*cont
= GTK_CONTAINER(data
);
301 /* gtk_container_remove will unref the widget for us; we need not. */
302 gtk_container_remove(cont
, w
);
305 /* The `listbox' functions can also apply to combo boxes. */
306 void dlg_listbox_clear(union control
*ctrl
, void *dlg
)
308 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
309 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
312 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
313 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
314 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
316 cont
= (uc
->menu ?
GTK_CONTAINER(uc
->menu
) : GTK_CONTAINER(uc
->list
));
318 gtk_container_foreach(cont
, container_remove_and_destroy
, cont
);
321 void dlg_listbox_del(union control
*ctrl
, void *dlg
, int index
)
323 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
324 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
326 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
327 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
328 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
332 (GTK_CONTAINER(uc
->menu
),
333 g_list_nth_data(GTK_MENU_SHELL(uc
->menu
)->children
, index
));
335 gtk_list_clear_items(GTK_LIST(uc
->list
), index
, index
+1);
339 void dlg_listbox_add(union control
*ctrl
, void *dlg
, char const *text
)
341 dlg_listbox_addwithid(ctrl
, dlg
, text
, 0);
345 * Each listbox entry may have a numeric id associated with it.
346 * Note that some front ends only permit a string to be stored at
347 * each position, which means that _if_ you put two identical
348 * strings in any listbox then you MUST not assign them different
349 * IDs and expect to get meaningful results back.
351 void dlg_listbox_addwithid(union control
*ctrl
, void *dlg
,
352 char const *text
, int id
)
354 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
355 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
357 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
358 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
359 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
361 dp
->flags
|= FLAG_UPDATING_COMBO_LIST
;
365 * List item in a drop-down (but non-combo) list. Tabs are
366 * ignored; we just provide a standard menu item with the
369 GtkWidget
*menuitem
= gtk_menu_item_new_with_label(text
);
371 gtk_container_add(GTK_CONTAINER(uc
->menu
), menuitem
);
372 gtk_widget_show(menuitem
);
374 gtk_object_set_data(GTK_OBJECT(menuitem
), "user-data", (gpointer
)id
);
375 gtk_signal_connect(GTK_OBJECT(menuitem
), "activate",
376 GTK_SIGNAL_FUNC(menuitem_activate
), dp
);
377 } else if (!uc
->entry
) {
379 * List item in a non-combo-box list box. We make all of
380 * these Columns containing GtkLabels. This allows us to do
381 * the nasty force_left hack irrespective of whether there
382 * are tabs in the thing.
384 GtkWidget
*listitem
= gtk_list_item_new();
385 GtkWidget
*cols
= columns_new(10);
389 /* Count the tabs in the text, and hence determine # of columns. */
391 for (i
= 0; text
[i
]; i
++)
396 (uc
->ctrl
->listbox
.ncols ? uc
->ctrl
->listbox
.ncols
: 1));
397 percents
= snewn(ncols
, gint
);
398 percents
[ncols
-1] = 100;
399 for (i
= 0; i
< ncols
-1; i
++) {
400 percents
[i
] = uc
->ctrl
->listbox
.percentages
[i
];
401 percents
[ncols
-1] -= percents
[i
];
403 columns_set_cols(COLUMNS(cols
), ncols
, percents
);
406 for (i
= 0; i
< ncols
; i
++) {
407 int len
= strcspn(text
, "\t");
408 char *dup
= dupprintf("%.*s", len
, text
);
413 label
= gtk_label_new(dup
);
416 columns_add(COLUMNS(cols
), label
, i
, 1);
417 columns_force_left_align(COLUMNS(cols
), label
);
418 gtk_widget_show(label
);
420 gtk_container_add(GTK_CONTAINER(listitem
), cols
);
421 gtk_widget_show(cols
);
422 gtk_container_add(GTK_CONTAINER(uc
->list
), listitem
);
423 gtk_widget_show(listitem
);
425 if (ctrl
->listbox
.multisel
) {
426 gtk_signal_connect(GTK_OBJECT(listitem
), "key_press_event",
427 GTK_SIGNAL_FUNC(listitem_multi_key
), uc
->adj
);
429 gtk_signal_connect(GTK_OBJECT(listitem
), "key_press_event",
430 GTK_SIGNAL_FUNC(listitem_single_key
), uc
->adj
);
432 gtk_signal_connect(GTK_OBJECT(listitem
), "focus_in_event",
433 GTK_SIGNAL_FUNC(widget_focus
), dp
);
434 gtk_signal_connect(GTK_OBJECT(listitem
), "button_press_event",
435 GTK_SIGNAL_FUNC(listitem_button
), dp
);
436 gtk_object_set_data(GTK_OBJECT(listitem
), "user-data", (gpointer
)id
);
439 * List item in a combo-box list, which means the sensible
440 * thing to do is make it a perfectly normal label. Hence
441 * tabs are disregarded.
443 GtkWidget
*listitem
= gtk_list_item_new_with_label(text
);
445 gtk_container_add(GTK_CONTAINER(uc
->list
), listitem
);
446 gtk_widget_show(listitem
);
448 gtk_object_set_data(GTK_OBJECT(listitem
), "user-data", (gpointer
)id
);
451 dp
->flags
&= ~FLAG_UPDATING_COMBO_LIST
;
454 int dlg_listbox_getid(union control
*ctrl
, void *dlg
, int index
)
456 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
457 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
461 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
462 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
463 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
465 children
= gtk_container_children(GTK_CONTAINER(uc
->menu ? uc
->menu
:
467 item
= GTK_OBJECT(g_list_nth_data(children
, index
));
468 g_list_free(children
);
470 return (int)gtk_object_get_data(GTK_OBJECT(item
), "user-data");
473 /* dlg_listbox_index returns <0 if no single element is selected. */
474 int dlg_listbox_index(union control
*ctrl
, void *dlg
)
476 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
477 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
479 GtkWidget
*item
, *activeitem
;
483 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
484 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
485 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
488 activeitem
= gtk_menu_get_active(GTK_MENU(uc
->menu
));
490 children
= gtk_container_children(GTK_CONTAINER(uc
->menu ? uc
->menu
:
492 for (i
= 0; children
!=NULL
&& (item
= GTK_WIDGET(children
->data
))!=NULL
;
493 i
++, children
= children
->next
) {
494 if (uc
->menu ? activeitem
== item
:
495 GTK_WIDGET_STATE(item
) == GTK_STATE_SELECTED
) {
502 g_list_free(children
);
503 return selected
< 0 ?
-1 : selected
;
506 int dlg_listbox_issel(union control
*ctrl
, void *dlg
, int index
)
508 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
509 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
511 GtkWidget
*item
, *activeitem
;
513 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
514 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
515 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
517 children
= gtk_container_children(GTK_CONTAINER(uc
->menu ? uc
->menu
:
519 item
= GTK_WIDGET(g_list_nth_data(children
, index
));
520 g_list_free(children
);
523 activeitem
= gtk_menu_get_active(GTK_MENU(uc
->menu
));
524 return item
== activeitem
;
526 return GTK_WIDGET_STATE(item
) == GTK_STATE_SELECTED
;
530 void dlg_listbox_select(union control
*ctrl
, void *dlg
, int index
)
532 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
533 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
535 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
536 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
537 assert(uc
->optmenu
!= NULL
|| uc
->list
!= NULL
);
540 gtk_option_menu_set_history(GTK_OPTION_MENU(uc
->optmenu
), index
);
542 gtk_list_select_item(GTK_LIST(uc
->list
), index
);
546 void dlg_text_set(union control
*ctrl
, void *dlg
, char const *text
)
548 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
549 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
551 assert(uc
->ctrl
->generic
.type
== CTRL_TEXT
);
552 assert(uc
->text
!= NULL
);
554 gtk_label_set_text(GTK_LABEL(uc
->text
), text
);
557 void dlg_filesel_set(union control
*ctrl
, void *dlg
, Filename fn
)
559 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
560 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
561 assert(uc
->ctrl
->generic
.type
== CTRL_FILESELECT
);
562 assert(uc
->entry
!= NULL
);
563 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), fn
.path
);
566 void dlg_filesel_get(union control
*ctrl
, void *dlg
, Filename
*fn
)
568 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
569 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
570 assert(uc
->ctrl
->generic
.type
== CTRL_FILESELECT
);
571 assert(uc
->entry
!= NULL
);
572 strncpy(fn
->path
, gtk_entry_get_text(GTK_ENTRY(uc
->entry
)),
574 fn
->path
[lenof(fn
->path
)-1] = '\0';
577 void dlg_fontsel_set(union control
*ctrl
, void *dlg
, FontSpec fs
)
579 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
580 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
581 assert(uc
->ctrl
->generic
.type
== CTRL_FONTSELECT
);
582 assert(uc
->entry
!= NULL
);
583 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), fs
.name
);
586 void dlg_fontsel_get(union control
*ctrl
, void *dlg
, FontSpec
*fs
)
588 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
589 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
590 assert(uc
->ctrl
->generic
.type
== CTRL_FONTSELECT
);
591 assert(uc
->entry
!= NULL
);
592 strncpy(fs
->name
, gtk_entry_get_text(GTK_ENTRY(uc
->entry
)),
594 fs
->name
[lenof(fs
->name
)-1] = '\0';
598 * Bracketing a large set of updates in these two functions will
599 * cause the front end (if possible) to delay updating the screen
600 * until it's all complete, thus avoiding flicker.
602 void dlg_update_start(union control
*ctrl
, void *dlg
)
605 * Apparently we can't do this at all in GTK. GtkCList supports
606 * freeze and thaw, but not GtkList. Bah.
610 void dlg_update_done(union control
*ctrl
, void *dlg
)
613 * Apparently we can't do this at all in GTK. GtkCList supports
614 * freeze and thaw, but not GtkList. Bah.
618 void dlg_set_focus(union control
*ctrl
, void *dlg
)
620 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
621 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
623 switch (ctrl
->generic
.type
) {
626 /* Check boxes and buttons get the focus _and_ get toggled. */
627 gtk_widget_grab_focus(uc
->toplevel
);
629 case CTRL_FILESELECT
:
630 case CTRL_FONTSELECT
:
632 /* Anything containing an edit box gets that focused. */
633 gtk_widget_grab_focus(uc
->entry
);
637 * Radio buttons: we find the currently selected button and
642 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++)
643 if (gtk_toggle_button_get_active
644 (GTK_TOGGLE_BUTTON(uc
->buttons
[i
]))) {
645 gtk_widget_grab_focus(uc
->buttons
[i
]);
651 * If the list is really an option menu, we focus it.
652 * Otherwise we tell it to focus one of its children, which
653 * appears to do the Right Thing.
656 gtk_widget_grab_focus(uc
->optmenu
);
658 assert(uc
->list
!= NULL
);
659 gtk_container_focus(GTK_CONTAINER(uc
->list
), GTK_DIR_TAB_FORWARD
);
666 * During event processing, you might well want to give an error
667 * indication to the user. dlg_beep() is a quick and easy generic
668 * error; dlg_error() puts up a message-box or equivalent.
670 void dlg_beep(void *dlg
)
675 static void errmsg_button_clicked(GtkButton
*button
, gpointer data
)
677 gtk_widget_destroy(GTK_WIDGET(data
));
680 void dlg_error_msg(void *dlg
, char *msg
)
682 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
683 GtkWidget
*window
, *hbox
, *text
, *ok
;
685 window
= gtk_dialog_new();
686 text
= gtk_label_new(msg
);
687 gtk_misc_set_alignment(GTK_MISC(text
), 0.0, 0.0);
688 hbox
= gtk_hbox_new(FALSE
, 0);
689 gtk_box_pack_start(GTK_BOX(hbox
), text
, FALSE
, FALSE
, 20);
690 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
),
691 hbox
, FALSE
, FALSE
, 20);
692 gtk_widget_show(text
);
693 gtk_widget_show(hbox
);
694 gtk_window_set_title(GTK_WINDOW(window
), "Error");
695 gtk_label_set_line_wrap(GTK_LABEL(text
), TRUE
);
696 ok
= gtk_button_new_with_label("OK");
697 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(window
)->action_area
),
698 ok
, FALSE
, FALSE
, 0);
700 GTK_WIDGET_SET_FLAGS(ok
, GTK_CAN_DEFAULT
);
701 gtk_window_set_default(GTK_WINDOW(window
), ok
);
702 gtk_signal_connect(GTK_OBJECT(ok
), "clicked",
703 GTK_SIGNAL_FUNC(errmsg_button_clicked
), window
);
704 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
705 GTK_SIGNAL_FUNC(window_destroy
), NULL
);
706 gtk_window_set_modal(GTK_WINDOW(window
), TRUE
);
707 gtk_window_set_transient_for(GTK_WINDOW(window
), GTK_WINDOW(dp
->window
));
709 gint x
, y
, w
, h
, dx
, dy
;
710 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_NONE
);
711 gdk_window_get_origin(GTK_WIDGET(dp
->window
)->window
, &x
, &y
);
712 gdk_window_get_size(GTK_WIDGET(dp
->window
)->window
, &w
, &h
);
715 gtk_widget_set_uposition(GTK_WIDGET(window
), dx
, dy
);
717 gtk_widget_show(window
);
722 * This function signals to the front end that the dialog's
723 * processing is completed, and passes an integer value (typically
726 void dlg_end(void *dlg
, int value
)
728 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
730 gtk_widget_destroy(dp
->window
);
733 void dlg_refresh(union control
*ctrl
, void *dlg
)
735 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
739 if (ctrl
->generic
.handler
!= NULL
)
740 ctrl
->generic
.handler(ctrl
, dp
, dp
->data
, EVENT_REFRESH
);
744 for (i
= 0; (uc
= index234(dp
->byctrl
, i
)) != NULL
; i
++) {
745 assert(uc
->ctrl
!= NULL
);
746 if (uc
->ctrl
->generic
.handler
!= NULL
)
747 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
,
748 dp
->data
, EVENT_REFRESH
);
753 void dlg_coloursel_start(union control
*ctrl
, void *dlg
, int r
, int g
, int b
)
755 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
756 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
759 GtkWidget
*coloursel
=
760 gtk_color_selection_dialog_new("Select a colour");
761 GtkColorSelectionDialog
*ccs
= GTK_COLOR_SELECTION_DIALOG(coloursel
);
763 dp
->coloursel_result
.ok
= FALSE
;
765 gtk_window_set_modal(GTK_WINDOW(coloursel
), TRUE
);
766 gtk_color_selection_set_opacity(GTK_COLOR_SELECTION(ccs
->colorsel
), FALSE
);
767 cvals
[0] = r
/ 255.0;
768 cvals
[1] = g
/ 255.0;
769 cvals
[2] = b
/ 255.0;
770 cvals
[3] = 1.0; /* fully opaque! */
771 gtk_color_selection_set_color(GTK_COLOR_SELECTION(ccs
->colorsel
), cvals
);
773 gtk_object_set_data(GTK_OBJECT(ccs
->ok_button
), "user-data",
774 (gpointer
)coloursel
);
775 gtk_object_set_data(GTK_OBJECT(ccs
->cancel_button
), "user-data",
776 (gpointer
)coloursel
);
777 gtk_object_set_data(GTK_OBJECT(coloursel
), "user-data", (gpointer
)uc
);
778 gtk_signal_connect(GTK_OBJECT(ccs
->ok_button
), "clicked",
779 GTK_SIGNAL_FUNC(coloursel_ok
), (gpointer
)dp
);
780 gtk_signal_connect(GTK_OBJECT(ccs
->cancel_button
), "clicked",
781 GTK_SIGNAL_FUNC(coloursel_cancel
), (gpointer
)dp
);
782 gtk_signal_connect_object(GTK_OBJECT(ccs
->ok_button
), "clicked",
783 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
784 (gpointer
)coloursel
);
785 gtk_signal_connect_object(GTK_OBJECT(ccs
->cancel_button
), "clicked",
786 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
787 (gpointer
)coloursel
);
788 gtk_widget_show(coloursel
);
791 int dlg_coloursel_results(union control
*ctrl
, void *dlg
,
792 int *r
, int *g
, int *b
)
794 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
795 if (dp
->coloursel_result
.ok
) {
796 *r
= dp
->coloursel_result
.r
;
797 *g
= dp
->coloursel_result
.g
;
798 *b
= dp
->coloursel_result
.b
;
804 /* ----------------------------------------------------------------------
805 * Signal handlers while the dialog box is active.
808 static gboolean
widget_focus(GtkWidget
*widget
, GdkEventFocus
*event
,
811 struct dlgparam
*dp
= (struct dlgparam
*)data
;
812 struct uctrl
*uc
= dlg_find_bywidget(dp
, widget
);
813 union control
*focus
;
820 if (focus
!= dp
->currfocus
) {
821 dp
->lastfocus
= dp
->currfocus
;
822 dp
->currfocus
= focus
;
828 static void button_clicked(GtkButton
*button
, gpointer data
)
830 struct dlgparam
*dp
= (struct dlgparam
*)data
;
831 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(button
));
832 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_ACTION
);
835 static void button_toggled(GtkToggleButton
*tb
, gpointer data
)
837 struct dlgparam
*dp
= (struct dlgparam
*)data
;
838 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(tb
));
839 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_VALCHANGE
);
842 static int editbox_key(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
845 * GtkEntry has a nasty habit of eating the Return key, which
846 * is unhelpful since it doesn't actually _do_ anything with it
847 * (it calls gtk_widget_activate, but our edit boxes never need
848 * activating). So I catch Return before GtkEntry sees it, and
849 * pass it straight on to the parent widget. Effect: hitting
850 * Return in an edit box will now activate the default button
851 * in the dialog just like it will everywhere else.
853 if (event
->keyval
== GDK_Return
&& widget
->parent
!= NULL
) {
855 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
), "key_press_event");
856 gtk_signal_emit_by_name(GTK_OBJECT(widget
->parent
), "key_press_event",
863 static void editbox_changed(GtkEditable
*ed
, gpointer data
)
865 struct dlgparam
*dp
= (struct dlgparam
*)data
;
866 if (!(dp
->flags
& FLAG_UPDATING_COMBO_LIST
)) {
867 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(ed
));
868 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_VALCHANGE
);
872 static void editbox_lostfocus(GtkWidget
*ed
, GdkEventFocus
*event
,
875 struct dlgparam
*dp
= (struct dlgparam
*)data
;
876 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(ed
));
877 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_REFRESH
);
880 static int listitem_key(GtkWidget
*item
, GdkEventKey
*event
, gpointer data
,
883 GtkAdjustment
*adj
= GTK_ADJUSTMENT(data
);
885 if (event
->keyval
== GDK_Up
|| event
->keyval
== GDK_KP_Up
||
886 event
->keyval
== GDK_Down
|| event
->keyval
== GDK_KP_Down
||
887 event
->keyval
== GDK_Page_Up
|| event
->keyval
== GDK_KP_Page_Up
||
888 event
->keyval
== GDK_Page_Down
|| event
->keyval
== GDK_KP_Page_Down
) {
890 * Up, Down, PgUp or PgDn have been pressed on a ListItem
891 * in a list box. So, if the list box is single-selection:
893 * - if the list item in question isn't already selected,
894 * we simply select it.
895 * - otherwise, we find the next one (or next
896 * however-far-away) in whichever direction we're going,
898 * + in this case, we must also fiddle with the
899 * scrollbar to ensure the newly selected item is
902 * If it's multiple-selection, we do all of the above
903 * except actually selecting anything, so we move the focus
904 * and fiddle the scrollbar to follow it.
906 GtkWidget
*list
= item
->parent
;
908 gtk_signal_emit_stop_by_name(GTK_OBJECT(item
), "key_press_event");
911 GTK_WIDGET_STATE(item
) != GTK_STATE_SELECTED
) {
912 gtk_list_select_child(GTK_LIST(list
), item
);
915 (event
->keyval
==GDK_Up
|| event
->keyval
==GDK_KP_Up
||
916 event
->keyval
==GDK_Page_Up
|| event
->keyval
==GDK_KP_Page_Up
)
919 (event
->keyval
==GDK_Page_Down
||
920 event
->keyval
==GDK_KP_Page_Down
||
921 event
->keyval
==GDK_Page_Up
|| event
->keyval
==GDK_KP_Page_Up
)
924 GList
*children
, *chead
;
926 chead
= children
= gtk_container_children(GTK_CONTAINER(list
));
928 n
= g_list_length(children
);
932 * Figure out how many list items to a screenful,
933 * and adjust the step appropriately.
935 step
= 0.5 + adj
->page_size
* n
/ (adj
->upper
- adj
->lower
);
936 step
--; /* go by one less than that */
940 while (children
!= NULL
) {
941 if (item
== children
->data
)
943 children
= children
->next
;
948 if (direction
< 0 && i
> 0)
949 children
= children
->prev
, i
--;
950 else if (direction
> 0 && i
< n
-1)
951 children
= children
->next
, i
++;
955 if (children
&& children
->data
) {
957 gtk_list_select_child(GTK_LIST(list
),
958 GTK_WIDGET(children
->data
));
959 gtk_widget_grab_focus(GTK_WIDGET(children
->data
));
960 gtk_adjustment_clamp_page
962 adj
->lower
+ (adj
->upper
-adj
->lower
) * i
/ n
,
963 adj
->lower
+ (adj
->upper
-adj
->lower
) * (i
+1) / n
);
974 static int listitem_single_key(GtkWidget
*item
, GdkEventKey
*event
,
977 return listitem_key(item
, event
, data
, FALSE
);
980 static int listitem_multi_key(GtkWidget
*item
, GdkEventKey
*event
,
983 return listitem_key(item
, event
, data
, TRUE
);
986 static int listitem_button(GtkWidget
*item
, GdkEventButton
*event
,
989 struct dlgparam
*dp
= (struct dlgparam
*)data
;
990 if (event
->type
== GDK_2BUTTON_PRESS
||
991 event
->type
== GDK_3BUTTON_PRESS
) {
992 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(item
));
993 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_ACTION
);
999 static void list_selchange(GtkList
*list
, gpointer data
)
1001 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1002 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(list
));
1004 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_SELCHANGE
);
1007 static void menuitem_activate(GtkMenuItem
*item
, gpointer data
)
1009 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1010 GtkWidget
*menushell
= GTK_WIDGET(item
)->parent
;
1011 gpointer optmenu
= gtk_object_get_data(GTK_OBJECT(menushell
), "user-data");
1012 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(optmenu
));
1013 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_SELCHANGE
);
1016 static void draglist_move(struct dlgparam
*dp
, struct uctrl
*uc
, int direction
)
1018 int index
= dlg_listbox_index(uc
->ctrl
, dp
);
1019 GList
*children
= gtk_container_children(GTK_CONTAINER(uc
->list
));
1023 (index
== 0 && direction
< 0) ||
1024 (index
== g_list_length(children
)-1 && direction
> 0)) {
1029 child
= g_list_nth_data(children
, index
);
1030 gtk_widget_ref(child
);
1031 gtk_list_clear_items(GTK_LIST(uc
->list
), index
, index
+1);
1032 g_list_free(children
);
1035 children
= g_list_append(children
, child
);
1036 gtk_list_insert_items(GTK_LIST(uc
->list
), children
, index
+ direction
);
1037 gtk_list_select_item(GTK_LIST(uc
->list
), index
+ direction
);
1038 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_VALCHANGE
);
1041 static void draglist_up(GtkButton
*button
, gpointer data
)
1043 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1044 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(button
));
1045 draglist_move(dp
, uc
, -1);
1048 static void draglist_down(GtkButton
*button
, gpointer data
)
1050 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1051 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(button
));
1052 draglist_move(dp
, uc
, +1);
1055 static void filesel_ok(GtkButton
*button
, gpointer data
)
1057 /* struct dlgparam *dp = (struct dlgparam *)data; */
1058 gpointer filesel
= gtk_object_get_data(GTK_OBJECT(button
), "user-data");
1059 struct uctrl
*uc
= gtk_object_get_data(GTK_OBJECT(filesel
), "user-data");
1060 char *name
= gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel
));
1061 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), name
);
1064 static void fontsel_ok(GtkButton
*button
, gpointer data
)
1066 /* struct dlgparam *dp = (struct dlgparam *)data; */
1067 gpointer fontsel
= gtk_object_get_data(GTK_OBJECT(button
), "user-data");
1068 struct uctrl
*uc
= gtk_object_get_data(GTK_OBJECT(fontsel
), "user-data");
1069 char *name
= gtk_font_selection_dialog_get_font_name
1070 (GTK_FONT_SELECTION_DIALOG(fontsel
));
1071 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), name
);
1074 static void coloursel_ok(GtkButton
*button
, gpointer data
)
1076 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1077 gpointer coloursel
= gtk_object_get_data(GTK_OBJECT(button
), "user-data");
1078 struct uctrl
*uc
= gtk_object_get_data(GTK_OBJECT(coloursel
), "user-data");
1080 gtk_color_selection_get_color
1081 (GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(coloursel
)->colorsel
),
1083 dp
->coloursel_result
.r
= (int) (255 * cvals
[0]);
1084 dp
->coloursel_result
.g
= (int) (255 * cvals
[1]);
1085 dp
->coloursel_result
.b
= (int) (255 * cvals
[2]);
1086 dp
->coloursel_result
.ok
= TRUE
;
1087 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_CALLBACK
);
1090 static void coloursel_cancel(GtkButton
*button
, gpointer data
)
1092 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1093 gpointer coloursel
= gtk_object_get_data(GTK_OBJECT(button
), "user-data");
1094 struct uctrl
*uc
= gtk_object_get_data(GTK_OBJECT(coloursel
), "user-data");
1095 dp
->coloursel_result
.ok
= FALSE
;
1096 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_CALLBACK
);
1099 static void filefont_clicked(GtkButton
*button
, gpointer data
)
1101 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1102 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(button
));
1104 if (uc
->ctrl
->generic
.type
== CTRL_FILESELECT
) {
1105 GtkWidget
*filesel
=
1106 gtk_file_selection_new(uc
->ctrl
->fileselect
.title
);
1107 gtk_window_set_modal(GTK_WINDOW(filesel
), TRUE
);
1109 (GTK_OBJECT(GTK_FILE_SELECTION(filesel
)->ok_button
), "user-data",
1111 gtk_object_set_data(GTK_OBJECT(filesel
), "user-data", (gpointer
)uc
);
1113 (GTK_OBJECT(GTK_FILE_SELECTION(filesel
)->ok_button
), "clicked",
1114 GTK_SIGNAL_FUNC(filesel_ok
), (gpointer
)dp
);
1115 gtk_signal_connect_object
1116 (GTK_OBJECT(GTK_FILE_SELECTION(filesel
)->ok_button
), "clicked",
1117 GTK_SIGNAL_FUNC(gtk_widget_destroy
), (gpointer
)filesel
);
1118 gtk_signal_connect_object
1119 (GTK_OBJECT(GTK_FILE_SELECTION(filesel
)->cancel_button
), "clicked",
1120 GTK_SIGNAL_FUNC(gtk_widget_destroy
), (gpointer
)filesel
);
1121 gtk_widget_show(filesel
);
1124 if (uc
->ctrl
->generic
.type
== CTRL_FONTSELECT
) {
1125 gchar
*spacings
[] = { "c", "m", NULL
};
1126 gchar
*fontname
= gtk_entry_get_text(GTK_ENTRY(uc
->entry
));
1127 GtkWidget
*fontsel
=
1128 gtk_font_selection_dialog_new("Select a font");
1129 gtk_window_set_modal(GTK_WINDOW(fontsel
), TRUE
);
1130 gtk_font_selection_dialog_set_filter
1131 (GTK_FONT_SELECTION_DIALOG(fontsel
),
1132 GTK_FONT_FILTER_BASE
, GTK_FONT_ALL
,
1133 NULL
, NULL
, NULL
, NULL
, spacings
, NULL
);
1134 if (!gtk_font_selection_dialog_set_font_name
1135 (GTK_FONT_SELECTION_DIALOG(fontsel
), fontname
)) {
1137 * If the font name wasn't found as it was, try opening
1138 * it and extracting its FONT property. This should
1139 * have the effect of mapping short aliases into true
1142 GdkFont
*font
= gdk_font_load(fontname
);
1144 XFontStruct
*xfs
= GDK_FONT_XFONT(font
);
1145 Display
*disp
= GDK_FONT_XDISPLAY(font
);
1146 Atom fontprop
= XInternAtom(disp
, "FONT", False
);
1148 if (XGetFontProperty(xfs
, fontprop
, &ret
)) {
1149 char *name
= XGetAtomName(disp
, (Atom
)ret
);
1151 gtk_font_selection_dialog_set_font_name
1152 (GTK_FONT_SELECTION_DIALOG(fontsel
), name
);
1154 gdk_font_unref(font
);
1158 (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel
)->ok_button
),
1159 "user-data", (gpointer
)fontsel
);
1160 gtk_object_set_data(GTK_OBJECT(fontsel
), "user-data", (gpointer
)uc
);
1162 (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel
)->ok_button
),
1163 "clicked", GTK_SIGNAL_FUNC(fontsel_ok
), (gpointer
)dp
);
1164 gtk_signal_connect_object
1165 (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel
)->ok_button
),
1166 "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1168 gtk_signal_connect_object
1169 (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel
)->cancel_button
),
1170 "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1172 gtk_widget_show(fontsel
);
1176 static void label_sizealloc(GtkWidget
*widget
, GtkAllocation
*alloc
,
1179 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1180 struct uctrl
*uc
= dlg_find_bywidget(dp
, widget
);
1182 gtk_widget_set_usize(uc
->text
, alloc
->width
, -1);
1183 gtk_label_set_text(GTK_LABEL(uc
->text
), uc
->ctrl
->generic
.label
);
1184 gtk_signal_disconnect(GTK_OBJECT(uc
->text
), uc
->textsig
);
1187 /* ----------------------------------------------------------------------
1188 * This function does the main layout work: it reads a controlset,
1189 * it creates the relevant GTK controls, and returns a GtkWidget
1190 * containing the result. (This widget might be a title of some
1191 * sort, it might be a Columns containing many controls, or it
1192 * might be a GtkFrame containing a Columns; whatever it is, it's
1193 * definitely a GtkWidget and should probably be added to a
1196 * `listitemheight' is used to calculate a usize for list boxes: it
1197 * should be the height from the size request of a GtkListItem.
1199 * `win' is required for setting the default button. If it is
1200 * non-NULL, all buttons created will be default-capable (so they
1201 * have extra space round them for the default highlight).
1203 GtkWidget
*layout_ctrls(struct dlgparam
*dp
, struct Shortcuts
*scs
,
1204 struct controlset
*s
, int listitemheight
,
1211 if (!s
->boxname
&& s
->boxtitle
) {
1212 /* This controlset is a panel title. */
1213 return gtk_label_new(s
->boxtitle
);
1217 * Otherwise, we expect to be laying out actual controls, so
1218 * we'll start by creating a Columns for the purpose.
1220 cols
= COLUMNS(columns_new(4));
1221 ret
= GTK_WIDGET(cols
);
1222 gtk_widget_show(ret
);
1225 * Create a containing frame if we have a box name.
1228 ret
= gtk_frame_new(s
->boxtitle
); /* NULL is valid here */
1229 gtk_container_set_border_width(GTK_CONTAINER(cols
), 4);
1230 gtk_container_add(GTK_CONTAINER(ret
), GTK_WIDGET(cols
));
1231 gtk_widget_show(ret
);
1235 * Now iterate through the controls themselves, create them,
1236 * and add them to the Columns.
1238 for (i
= 0; i
< s
->ncontrols
; i
++) {
1239 union control
*ctrl
= s
->ctrls
[i
];
1242 GtkWidget
*w
= NULL
;
1244 switch (ctrl
->generic
.type
) {
1247 static const int simplecols
[1] = { 100 };
1248 columns_set_cols(cols
, ctrl
->columns
.ncols
,
1249 (ctrl
->columns
.percentages ?
1250 ctrl
->columns
.percentages
: simplecols
));
1252 continue; /* no actual control created */
1255 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
->tabdelay
.ctrl
);
1257 columns_taborder_last(cols
, uc
->toplevel
);
1259 continue; /* no actual control created */
1262 uc
= snew(struct uctrl
);
1264 uc
->privdata
= NULL
;
1265 uc
->privdata_needs_free
= FALSE
;
1267 uc
->entry
= uc
->list
= uc
->menu
= NULL
;
1268 uc
->button
= uc
->optmenu
= uc
->text
= NULL
;
1270 switch (ctrl
->generic
.type
) {
1272 w
= gtk_button_new_with_label(ctrl
->generic
.label
);
1274 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
1275 if (ctrl
->button
.isdefault
)
1276 gtk_window_set_default(win
, w
);
1277 if (ctrl
->button
.iscancel
)
1278 dp
->cancelbutton
= w
;
1280 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
1281 GTK_SIGNAL_FUNC(button_clicked
), dp
);
1282 gtk_signal_connect(GTK_OBJECT(w
), "focus_in_event",
1283 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1284 shortcut_add(scs
, GTK_BIN(w
)->child
, ctrl
->button
.shortcut
,
1285 SHORTCUT_UCTRL
, uc
);
1288 w
= gtk_check_button_new_with_label(ctrl
->generic
.label
);
1289 gtk_signal_connect(GTK_OBJECT(w
), "toggled",
1290 GTK_SIGNAL_FUNC(button_toggled
), dp
);
1291 gtk_signal_connect(GTK_OBJECT(w
), "focus_in_event",
1292 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1293 shortcut_add(scs
, GTK_BIN(w
)->child
, ctrl
->checkbox
.shortcut
,
1294 SHORTCUT_UCTRL
, uc
);
1299 * Radio buttons get to go inside their own Columns, no
1303 gint i
, *percentages
;
1307 if (ctrl
->generic
.label
) {
1308 GtkWidget
*label
= gtk_label_new(ctrl
->generic
.label
);
1309 columns_add(COLUMNS(w
), label
, 0, 1);
1310 columns_force_left_align(COLUMNS(w
), label
);
1311 gtk_widget_show(label
);
1312 shortcut_add(scs
, label
, ctrl
->radio
.shortcut
,
1313 SHORTCUT_UCTRL
, uc
);
1315 percentages
= g_new(gint
, ctrl
->radio
.ncolumns
);
1316 for (i
= 0; i
< ctrl
->radio
.ncolumns
; i
++) {
1318 ((100 * (i
+1) / ctrl
->radio
.ncolumns
) -
1319 100 * i
/ ctrl
->radio
.ncolumns
);
1321 columns_set_cols(COLUMNS(w
), ctrl
->radio
.ncolumns
,
1323 g_free(percentages
);
1326 uc
->nbuttons
= ctrl
->radio
.nbuttons
;
1327 uc
->buttons
= snewn(uc
->nbuttons
, GtkWidget
*);
1329 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
1333 b
= (gtk_radio_button_new_with_label
1334 (group
, ctrl
->radio
.buttons
[i
]));
1336 group
= gtk_radio_button_group(GTK_RADIO_BUTTON(b
));
1337 colstart
= i
% ctrl
->radio
.ncolumns
;
1338 columns_add(COLUMNS(w
), b
, colstart
,
1339 (i
== ctrl
->radio
.nbuttons
-1 ?
1340 ctrl
->radio
.ncolumns
- colstart
: 1));
1341 columns_force_left_align(COLUMNS(w
), b
);
1343 gtk_signal_connect(GTK_OBJECT(b
), "toggled",
1344 GTK_SIGNAL_FUNC(button_toggled
), dp
);
1345 gtk_signal_connect(GTK_OBJECT(b
), "focus_in_event",
1346 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1347 if (ctrl
->radio
.shortcuts
) {
1348 shortcut_add(scs
, GTK_BIN(b
)->child
,
1349 ctrl
->radio
.shortcuts
[i
],
1350 SHORTCUT_UCTRL
, uc
);
1359 if (ctrl
->editbox
.has_list
) {
1360 w
= gtk_combo_new();
1361 gtk_combo_set_value_in_list(GTK_COMBO(w
), FALSE
, TRUE
);
1362 uc
->entry
= GTK_COMBO(w
)->entry
;
1363 uc
->list
= GTK_COMBO(w
)->list
;
1365 w
= gtk_entry_new();
1366 if (ctrl
->editbox
.password
)
1367 gtk_entry_set_visibility(GTK_ENTRY(w
), FALSE
);
1370 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "changed",
1371 GTK_SIGNAL_FUNC(editbox_changed
), dp
);
1372 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "key_press_event",
1373 GTK_SIGNAL_FUNC(editbox_key
), dp
);
1374 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "focus_in_event",
1375 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1377 * Edit boxes, for some strange reason, have a minimum
1378 * width of 150 in GTK 1.2. We don't want this - we'd
1379 * rather the edit boxes acquired their natural width
1380 * from the column layout of the rest of the box.
1382 * Also, while we're here, we'll squirrel away the
1383 * edit box height so we can use that to centre its
1384 * label vertically beside it.
1386 gtk_widget_size_request(w
, &req
);
1387 gtk_widget_set_usize(w
, 10, req
.height
);
1389 if (ctrl
->generic
.label
) {
1390 GtkWidget
*label
, *container
;
1392 label
= gtk_label_new(ctrl
->generic
.label
);
1394 shortcut_add(scs
, label
, ctrl
->editbox
.shortcut
,
1395 SHORTCUT_FOCUS
, uc
->entry
);
1397 container
= columns_new(4);
1398 if (ctrl
->editbox
.percentwidth
== 100) {
1399 columns_add(COLUMNS(container
), label
, 0, 1);
1400 columns_force_left_align(COLUMNS(container
), label
);
1401 columns_add(COLUMNS(container
), w
, 0, 1);
1403 gint percentages
[2];
1404 percentages
[1] = ctrl
->editbox
.percentwidth
;
1405 percentages
[0] = 100 - ctrl
->editbox
.percentwidth
;
1406 columns_set_cols(COLUMNS(container
), 2, percentages
);
1407 columns_add(COLUMNS(container
), label
, 0, 1);
1408 columns_force_left_align(COLUMNS(container
), label
);
1409 columns_add(COLUMNS(container
), w
, 1, 1);
1410 /* Centre the label vertically. */
1411 gtk_widget_set_usize(label
, -1, req
.height
);
1412 gtk_misc_set_alignment(GTK_MISC(label
), 0.0, 0.5);
1414 gtk_widget_show(label
);
1419 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "focus_out_event",
1420 GTK_SIGNAL_FUNC(editbox_lostfocus
), dp
);
1423 case CTRL_FILESELECT
:
1424 case CTRL_FONTSELECT
:
1429 (ctrl
->generic
.type
== CTRL_FILESELECT ?
1430 "Browse..." : "Change...");
1432 gint percentages
[] = { 75, 25 };
1434 columns_set_cols(COLUMNS(w
), 2, percentages
);
1436 if (ctrl
->generic
.label
) {
1437 ww
= gtk_label_new(ctrl
->generic
.label
);
1438 columns_add(COLUMNS(w
), ww
, 0, 2);
1439 columns_force_left_align(COLUMNS(w
), ww
);
1440 gtk_widget_show(ww
);
1441 shortcut_add(scs
, ww
,
1442 (ctrl
->generic
.type
== CTRL_FILESELECT ?
1443 ctrl
->fileselect
.shortcut
:
1444 ctrl
->fontselect
.shortcut
),
1445 SHORTCUT_UCTRL
, uc
);
1448 uc
->entry
= ww
= gtk_entry_new();
1449 gtk_widget_size_request(ww
, &req
);
1450 gtk_widget_set_usize(ww
, 10, req
.height
);
1451 columns_add(COLUMNS(w
), ww
, 0, 1);
1452 gtk_widget_show(ww
);
1454 uc
->button
= ww
= gtk_button_new_with_label(browsebtn
);
1455 columns_add(COLUMNS(w
), ww
, 1, 1);
1456 gtk_widget_show(ww
);
1458 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "key_press_event",
1459 GTK_SIGNAL_FUNC(editbox_key
), dp
);
1460 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "changed",
1461 GTK_SIGNAL_FUNC(editbox_changed
), dp
);
1462 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "focus_in_event",
1463 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1464 gtk_signal_connect(GTK_OBJECT(uc
->button
), "focus_in_event",
1465 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1466 gtk_signal_connect(GTK_OBJECT(ww
), "clicked",
1467 GTK_SIGNAL_FUNC(filefont_clicked
), dp
);
1471 if (ctrl
->listbox
.height
== 0) {
1472 uc
->optmenu
= w
= gtk_option_menu_new();
1473 uc
->menu
= gtk_menu_new();
1474 gtk_option_menu_set_menu(GTK_OPTION_MENU(w
), uc
->menu
);
1475 gtk_object_set_data(GTK_OBJECT(uc
->menu
), "user-data",
1476 (gpointer
)uc
->optmenu
);
1477 gtk_signal_connect(GTK_OBJECT(uc
->optmenu
), "focus_in_event",
1478 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1480 uc
->list
= gtk_list_new();
1481 if (ctrl
->listbox
.multisel
== 2) {
1482 gtk_list_set_selection_mode(GTK_LIST(uc
->list
),
1483 GTK_SELECTION_EXTENDED
);
1484 } else if (ctrl
->listbox
.multisel
== 1) {
1485 gtk_list_set_selection_mode(GTK_LIST(uc
->list
),
1486 GTK_SELECTION_MULTIPLE
);
1488 gtk_list_set_selection_mode(GTK_LIST(uc
->list
),
1489 GTK_SELECTION_SINGLE
);
1491 w
= gtk_scrolled_window_new(NULL
, NULL
);
1492 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(w
),
1494 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w
),
1496 GTK_POLICY_AUTOMATIC
);
1497 uc
->adj
= gtk_scrolled_window_get_vadjustment
1498 (GTK_SCROLLED_WINDOW(w
));
1500 gtk_widget_show(uc
->list
);
1501 gtk_signal_connect(GTK_OBJECT(uc
->list
), "selection-changed",
1502 GTK_SIGNAL_FUNC(list_selchange
), dp
);
1503 gtk_signal_connect(GTK_OBJECT(uc
->list
), "focus_in_event",
1504 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1507 * Adjust the height of the scrolled window to the
1508 * minimum given by the height parameter.
1510 * This piece of guesswork is a horrid hack based
1511 * on looking inside the GTK 1.2 sources
1512 * (specifically gtkviewport.c, which appears to be
1513 * the widget which provides the border around the
1514 * scrolling area). Anyone lets me know how I can
1515 * do this in a way which isn't at risk from GTK
1516 * upgrades, I'd be grateful.
1519 int edge
= GTK_WIDGET(uc
->list
)->style
->klass
->ythickness
;
1520 gtk_widget_set_usize(w
, 10,
1521 2*edge
+ (ctrl
->listbox
.height
*
1525 if (ctrl
->listbox
.draglist
) {
1527 * GTK doesn't appear to make it easy to
1528 * implement a proper draggable list; so
1529 * instead I'm just going to have to put an Up
1530 * and a Down button to the right of the actual
1531 * list box. Ah well.
1533 GtkWidget
*cols
, *button
;
1534 static const gint percentages
[2] = { 80, 20 };
1536 cols
= columns_new(4);
1537 columns_set_cols(COLUMNS(cols
), 2, percentages
);
1538 columns_add(COLUMNS(cols
), w
, 0, 1);
1540 button
= gtk_button_new_with_label("Up");
1541 columns_add(COLUMNS(cols
), button
, 1, 1);
1542 gtk_widget_show(button
);
1543 gtk_signal_connect(GTK_OBJECT(button
), "clicked",
1544 GTK_SIGNAL_FUNC(draglist_up
), dp
);
1545 gtk_signal_connect(GTK_OBJECT(button
), "focus_in_event",
1546 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1547 button
= gtk_button_new_with_label("Down");
1548 columns_add(COLUMNS(cols
), button
, 1, 1);
1549 gtk_widget_show(button
);
1550 gtk_signal_connect(GTK_OBJECT(button
), "clicked",
1551 GTK_SIGNAL_FUNC(draglist_down
), dp
);
1552 gtk_signal_connect(GTK_OBJECT(button
), "focus_in_event",
1553 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1559 if (ctrl
->generic
.label
) {
1560 GtkWidget
*label
, *container
;
1562 label
= gtk_label_new(ctrl
->generic
.label
);
1564 container
= columns_new(4);
1565 if (ctrl
->listbox
.percentwidth
== 100) {
1566 columns_add(COLUMNS(container
), label
, 0, 1);
1567 columns_force_left_align(COLUMNS(container
), label
);
1568 columns_add(COLUMNS(container
), w
, 0, 1);
1570 gint percentages
[2];
1571 percentages
[1] = ctrl
->listbox
.percentwidth
;
1572 percentages
[0] = 100 - ctrl
->listbox
.percentwidth
;
1573 columns_set_cols(COLUMNS(container
), 2, percentages
);
1574 columns_add(COLUMNS(container
), label
, 0, 1);
1575 columns_force_left_align(COLUMNS(container
), label
);
1576 columns_add(COLUMNS(container
), w
, 1, 1);
1578 gtk_widget_show(label
);
1580 shortcut_add(scs
, label
, ctrl
->listbox
.shortcut
,
1581 SHORTCUT_UCTRL
, uc
);
1587 * Wrapping text widgets don't sit well with the GTK
1588 * layout model, in which widgets state a minimum size
1589 * and the whole window then adjusts to the smallest
1590 * size it can sensibly take given its contents. A
1591 * wrapping text widget _has_ no clear minimum size;
1592 * instead it has a range of possibilities. It can be
1593 * one line deep but 2000 wide, or two lines deep and
1594 * 1000 pixels, or three by 867, or four by 500 and so
1595 * on. It can be as short as you like provided you
1596 * don't mind it being wide, or as narrow as you like
1597 * provided you don't mind it being tall.
1599 * Therefore, it fits very badly into the layout model.
1600 * Hence the only thing to do is pick a width and let
1601 * it choose its own number of lines. To do this I'm
1602 * going to cheat a little. All new wrapping text
1603 * widgets will be created with a minimal text content
1604 * "X"; then, after the rest of the dialog box is set
1605 * up and its size calculated, the text widgets will be
1606 * told their width and given their real text, which
1607 * will cause the size to be recomputed in the y
1608 * direction (because many of them will expand to more
1611 uc
->text
= w
= gtk_label_new("X");
1612 gtk_misc_set_alignment(GTK_MISC(w
), 0.0, 0.0);
1613 gtk_label_set_line_wrap(GTK_LABEL(w
), TRUE
);
1615 gtk_signal_connect(GTK_OBJECT(w
), "size-allocate",
1616 GTK_SIGNAL_FUNC(label_sizealloc
), dp
);
1622 columns_add(cols
, w
,
1623 COLUMN_START(ctrl
->generic
.column
),
1624 COLUMN_SPAN(ctrl
->generic
.column
));
1626 columns_force_left_align(cols
, w
);
1630 dlg_add_uctrl(dp
, uc
);
1637 struct dlgparam
*dp
;
1639 GtkWidget
*panel
, *treeitem
;
1640 struct Shortcuts shortcuts
;
1643 static void treeitem_sel(GtkItem
*item
, gpointer data
)
1645 struct selparam
*sp
= (struct selparam
*)data
;
1647 panels_switch_to(sp
->panels
, sp
->panel
);
1649 sp
->dp
->shortcuts
= &sp
->shortcuts
;
1650 sp
->dp
->currtreeitem
= sp
->treeitem
;
1653 static void window_destroy(GtkWidget
*widget
, gpointer data
)
1658 static int tree_grab_focus(struct dlgparam
*dp
)
1663 * See if any of the treeitems has the focus.
1666 for (i
= 0; i
< dp
->ntreeitems
; i
++)
1667 if (GTK_WIDGET_HAS_FOCUS(dp
->treeitems
[i
])) {
1675 gtk_widget_grab_focus(dp
->currtreeitem
);
1680 gint
tree_focus(GtkContainer
*container
, GtkDirectionType direction
,
1683 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1685 gtk_signal_emit_stop_by_name(GTK_OBJECT(container
), "focus");
1687 * If there's a focused treeitem, we return FALSE to cause the
1688 * focus to move on to some totally other control. If not, we
1689 * focus the selected one.
1691 return tree_grab_focus(dp
);
1694 int win_key_press(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
1696 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1698 if (event
->keyval
== GDK_Escape
&& dp
->cancelbutton
) {
1699 gtk_signal_emit_by_name(GTK_OBJECT(dp
->cancelbutton
), "clicked");
1703 if ((event
->state
& GDK_MOD1_MASK
) &&
1704 (unsigned char)event
->string
[0] > 0 &&
1705 (unsigned char)event
->string
[0] <= 127) {
1706 int schr
= (unsigned char)event
->string
[0];
1707 struct Shortcut
*sc
= &dp
->shortcuts
->sc
[schr
];
1709 switch (sc
->action
) {
1711 tree_grab_focus(dp
);
1713 case SHORTCUT_FOCUS
:
1714 gtk_widget_grab_focus(sc
->widget
);
1716 case SHORTCUT_UCTRL
:
1718 * We must do something sensible with a uctrl.
1719 * Precisely what this is depends on the type of
1722 switch (sc
->uc
->ctrl
->generic
.type
) {
1725 /* Check boxes and buttons get the focus _and_ get toggled. */
1726 gtk_widget_grab_focus(sc
->uc
->toplevel
);
1727 gtk_signal_emit_by_name(GTK_OBJECT(sc
->uc
->toplevel
),
1730 case CTRL_FILESELECT
:
1731 case CTRL_FONTSELECT
:
1732 /* File/font selectors have their buttons pressed (ooer),
1733 * and focus transferred to the edit box. */
1734 gtk_signal_emit_by_name(GTK_OBJECT(sc
->uc
->button
),
1736 gtk_widget_grab_focus(sc
->uc
->entry
);
1740 * Radio buttons are fun, because they have
1741 * multiple shortcuts. We must find whether the
1742 * activated shortcut is the shortcut for the whole
1743 * group, or for a particular button. In the former
1744 * case, we find the currently selected button and
1745 * focus it; in the latter, we focus-and-click the
1746 * button whose shortcut was pressed.
1748 if (schr
== sc
->uc
->ctrl
->radio
.shortcut
) {
1750 for (i
= 0; i
< sc
->uc
->ctrl
->radio
.nbuttons
; i
++)
1751 if (gtk_toggle_button_get_active
1752 (GTK_TOGGLE_BUTTON(sc
->uc
->buttons
[i
]))) {
1753 gtk_widget_grab_focus(sc
->uc
->buttons
[i
]);
1755 } else if (sc
->uc
->ctrl
->radio
.shortcuts
) {
1757 for (i
= 0; i
< sc
->uc
->ctrl
->radio
.nbuttons
; i
++)
1758 if (schr
== sc
->uc
->ctrl
->radio
.shortcuts
[i
]) {
1759 gtk_widget_grab_focus(sc
->uc
->buttons
[i
]);
1760 gtk_signal_emit_by_name
1761 (GTK_OBJECT(sc
->uc
->buttons
[i
]), "clicked");
1767 * If the list is really an option menu, we focus
1768 * and click it. Otherwise we tell it to focus one
1769 * of its children, which appears to do the Right
1772 if (sc
->uc
->optmenu
) {
1776 gtk_widget_grab_focus(sc
->uc
->optmenu
);
1777 /* Option menus don't work using the "clicked" signal.
1778 * We need to manufacture a button press event :-/ */
1779 bev
.type
= GDK_BUTTON_PRESS
;
1781 gtk_signal_emit_by_name(GTK_OBJECT(sc
->uc
->optmenu
),
1782 "button_press_event",
1785 assert(sc
->uc
->list
!= NULL
);
1787 gtk_container_focus(GTK_CONTAINER(sc
->uc
->list
),
1788 GTK_DIR_TAB_FORWARD
);
1799 int tree_key_press(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
1801 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1803 if (event
->keyval
== GDK_Up
|| event
->keyval
== GDK_KP_Up
||
1804 event
->keyval
== GDK_Down
|| event
->keyval
== GDK_KP_Down
) {
1806 for (i
= 0; i
< dp
->ntreeitems
; i
++)
1807 if (widget
== dp
->treeitems
[i
])
1809 if (i
< dp
->ntreeitems
) {
1810 if (event
->keyval
== GDK_Up
|| event
->keyval
== GDK_KP_Up
)
1817 if (i
< 0 || i
>= dp
->ntreeitems
)
1818 break; /* nothing in that dir to select */
1820 * Determine if this tree item is visible.
1823 GtkWidget
*w
= dp
->treeitems
[i
];
1825 while (w
&& (GTK_IS_TREE_ITEM(w
) || GTK_IS_TREE(w
))) {
1826 if (!GTK_WIDGET_VISIBLE(w
)) {
1833 j
= i
; /* got one */
1839 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
),
1842 gtk_signal_emit_by_name(GTK_OBJECT(dp
->treeitems
[j
]), "toggle");
1843 gtk_widget_grab_focus(dp
->treeitems
[j
]);
1849 * It's nice for Left and Right to expand and collapse tree
1852 if (event
->keyval
== GDK_Left
|| event
->keyval
== GDK_KP_Left
) {
1853 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
),
1855 gtk_tree_item_collapse(GTK_TREE_ITEM(widget
));
1858 if (event
->keyval
== GDK_Right
|| event
->keyval
== GDK_KP_Right
) {
1859 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
),
1861 gtk_tree_item_expand(GTK_TREE_ITEM(widget
));
1868 void shortcut_add(struct Shortcuts
*scs
, GtkWidget
*labelw
,
1869 int chr
, int action
, void *ptr
)
1871 GtkLabel
*label
= GTK_LABEL(labelw
);
1872 gchar
*currstr
, *pattern
;
1875 if (chr
== NO_SHORTCUT
)
1878 chr
= tolower((unsigned char)chr
);
1880 assert(scs
->sc
[chr
].action
== SHORTCUT_EMPTY
);
1882 scs
->sc
[chr
].action
= action
;
1884 if (action
== SHORTCUT_FOCUS
) {
1885 scs
->sc
[chr
].uc
= NULL
;
1886 scs
->sc
[chr
].widget
= (GtkWidget
*)ptr
;
1888 scs
->sc
[chr
].widget
= NULL
;
1889 scs
->sc
[chr
].uc
= (struct uctrl
*)ptr
;
1892 gtk_label_get(label
, &currstr
);
1893 for (i
= 0; currstr
[i
]; i
++)
1894 if (tolower((unsigned char)currstr
[i
]) == chr
) {
1897 pattern
= dupprintf("%*s_", i
, "");
1899 gtk_widget_size_request(GTK_WIDGET(label
), &req
);
1900 gtk_label_set_pattern(label
, pattern
);
1901 gtk_widget_set_usize(GTK_WIDGET(label
), -1, req
.height
);
1908 int get_listitemheight(void)
1910 GtkWidget
*listitem
= gtk_list_item_new_with_label("foo");
1912 gtk_widget_size_request(listitem
, &req
);
1913 gtk_widget_unref(listitem
);
1917 int do_config_box(const char *title
, Config
*cfg
)
1919 GtkWidget
*window
, *hbox
, *vbox
, *cols
, *label
,
1920 *tree
, *treescroll
, *panels
, *panelvbox
;
1921 int index
, level
, listitemheight
;
1922 struct controlbox
*ctrlbox
;
1924 GtkTreeItem
*treeitemlevels
[8];
1925 GtkTree
*treelevels
[8];
1928 struct Shortcuts scs
;
1930 struct selparam
*selparams
= NULL
;
1931 int nselparams
= 0, selparamsize
= 0;
1935 get_sesslist(&sl
, TRUE
);
1937 listitemheight
= get_listitemheight();
1939 for (index
= 0; index
< lenof(scs
.sc
); index
++) {
1940 scs
.sc
[index
].action
= SHORTCUT_EMPTY
;
1943 ctrlbox
= ctrl_new_box();
1944 setup_config_box(ctrlbox
, &sl
, FALSE
, 0);
1945 unix_setup_config_box(ctrlbox
, FALSE
);
1947 window
= gtk_dialog_new();
1948 gtk_window_set_title(GTK_WINDOW(window
), title
);
1949 hbox
= gtk_hbox_new(FALSE
, 4);
1950 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
), hbox
, TRUE
, TRUE
, 0);
1951 gtk_container_set_border_width(GTK_CONTAINER(hbox
), 10);
1952 gtk_widget_show(hbox
);
1953 vbox
= gtk_vbox_new(FALSE
, 4);
1954 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, FALSE
, FALSE
, 0);
1955 gtk_widget_show(vbox
);
1956 cols
= columns_new(4);
1957 gtk_box_pack_start(GTK_BOX(vbox
), cols
, FALSE
, FALSE
, 0);
1958 gtk_widget_show(cols
);
1959 label
= gtk_label_new("Category:");
1960 columns_add(COLUMNS(cols
), label
, 0, 1);
1961 columns_force_left_align(COLUMNS(cols
), label
);
1962 gtk_widget_show(label
);
1963 treescroll
= gtk_scrolled_window_new(NULL
, NULL
);
1964 tree
= gtk_tree_new();
1965 gtk_signal_connect(GTK_OBJECT(tree
), "focus_in_event",
1966 GTK_SIGNAL_FUNC(widget_focus
), &dp
);
1967 shortcut_add(&scs
, label
, 'g', SHORTCUT_TREE
, tree
);
1968 gtk_tree_set_view_mode(GTK_TREE(tree
), GTK_TREE_VIEW_ITEM
);
1969 gtk_tree_set_selection_mode(GTK_TREE(tree
), GTK_SELECTION_BROWSE
);
1970 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(treescroll
),
1972 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(treescroll
),
1974 GTK_POLICY_AUTOMATIC
);
1975 gtk_signal_connect(GTK_OBJECT(tree
), "focus",
1976 GTK_SIGNAL_FUNC(tree_focus
), &dp
);
1977 gtk_widget_show(tree
);
1978 gtk_widget_show(treescroll
);
1979 gtk_box_pack_start(GTK_BOX(vbox
), treescroll
, TRUE
, TRUE
, 0);
1980 panels
= panels_new();
1981 gtk_box_pack_start(GTK_BOX(hbox
), panels
, TRUE
, TRUE
, 0);
1982 gtk_widget_show(panels
);
1987 for (index
= 0; index
< ctrlbox
->nctrlsets
; index
++) {
1988 struct controlset
*s
= ctrlbox
->ctrlsets
[index
];
1991 if (!*s
->pathname
) {
1992 w
= layout_ctrls(&dp
, &scs
, s
, listitemheight
, GTK_WINDOW(window
));
1993 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->action_area
),
1996 int j
= path ?
ctrl_path_compare(s
->pathname
, path
) : 0;
1997 if (j
!= INT_MAX
) { /* add to treeview, start new panel */
1999 GtkWidget
*treeitem
;
2003 * We expect never to find an implicit path
2004 * component. For example, we expect never to see
2005 * A/B/C followed by A/D/E, because that would
2006 * _implicitly_ create A/D. All our path prefixes
2007 * are expected to contain actual controls and be
2008 * selectable in the treeview; so we would expect
2009 * to see A/D _explicitly_ before encountering
2012 assert(j
== ctrl_path_elements(s
->pathname
) - 1);
2014 c
= strrchr(s
->pathname
, '/');
2020 treeitem
= gtk_tree_item_new_with_label(c
);
2021 assert(j
-1 < level
);
2023 if (!treelevels
[j
-1]) {
2024 treelevels
[j
-1] = GTK_TREE(gtk_tree_new());
2025 gtk_tree_item_set_subtree
2026 (treeitemlevels
[j
-1],
2027 GTK_WIDGET(treelevels
[j
-1]));
2028 gtk_tree_item_expand(treeitemlevels
[j
-1]);
2030 gtk_tree_append(treelevels
[j
-1], treeitem
);
2032 gtk_tree_append(GTK_TREE(tree
), treeitem
);
2034 treeitemlevels
[j
] = GTK_TREE_ITEM(treeitem
);
2035 treelevels
[j
] = NULL
;
2038 gtk_signal_connect(GTK_OBJECT(treeitem
), "key_press_event",
2039 GTK_SIGNAL_FUNC(tree_key_press
), &dp
);
2040 gtk_signal_connect(GTK_OBJECT(treeitem
), "focus_in_event",
2041 GTK_SIGNAL_FUNC(widget_focus
), &dp
);
2043 gtk_widget_show(treeitem
);
2047 first
= (panelvbox
== NULL
);
2049 panelvbox
= gtk_vbox_new(FALSE
, 4);
2050 gtk_container_add(GTK_CONTAINER(panels
), panelvbox
);
2052 panels_switch_to(PANELS(panels
), panelvbox
);
2053 gtk_tree_select_child(GTK_TREE(tree
), treeitem
);
2056 if (nselparams
>= selparamsize
) {
2058 selparams
= sresize(selparams
, selparamsize
,
2061 selparams
[nselparams
].dp
= &dp
;
2062 selparams
[nselparams
].panels
= PANELS(panels
);
2063 selparams
[nselparams
].panel
= panelvbox
;
2064 selparams
[nselparams
].shortcuts
= scs
; /* structure copy */
2065 selparams
[nselparams
].treeitem
= treeitem
;
2070 w
= layout_ctrls(&dp
,
2071 &selparams
[nselparams
-1].shortcuts
,
2072 s
, listitemheight
, NULL
);
2073 gtk_box_pack_start(GTK_BOX(panelvbox
), w
, FALSE
, FALSE
, 0);
2078 dp
.ntreeitems
= nselparams
;
2079 dp
.treeitems
= snewn(dp
.ntreeitems
, GtkWidget
*);
2081 for (index
= 0; index
< nselparams
; index
++) {
2082 gtk_signal_connect(GTK_OBJECT(selparams
[index
].treeitem
), "select",
2083 GTK_SIGNAL_FUNC(treeitem_sel
),
2085 dp
.treeitems
[index
] = selparams
[index
].treeitem
;
2089 dlg_refresh(NULL
, &dp
);
2091 dp
.shortcuts
= &selparams
[0].shortcuts
;
2092 dp
.currtreeitem
= dp
.treeitems
[0];
2093 dp
.lastfocus
= NULL
;
2097 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
2098 gtk_widget_show(window
);
2101 * Set focus into the first available control.
2103 for (index
= 0; index
< ctrlbox
->nctrlsets
; index
++) {
2104 struct controlset
*s
= ctrlbox
->ctrlsets
[index
];
2109 for (j
= 0; j
< s
->ncontrols
; j
++)
2110 if (s
->ctrls
[j
]->generic
.type
!= CTRL_TABDELAY
&&
2111 s
->ctrls
[j
]->generic
.type
!= CTRL_COLUMNS
&&
2112 s
->ctrls
[j
]->generic
.type
!= CTRL_TEXT
) {
2113 dlg_set_focus(s
->ctrls
[j
], &dp
);
2114 dp
.lastfocus
= s
->ctrls
[j
];
2123 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
2124 GTK_SIGNAL_FUNC(window_destroy
), NULL
);
2125 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
2126 GTK_SIGNAL_FUNC(win_key_press
), &dp
);
2130 get_sesslist(&sl
, FALSE
);
2137 static void messagebox_handler(union control
*ctrl
, void *dlg
,
2138 void *data
, int event
)
2140 if (event
== EVENT_ACTION
)
2141 dlg_end(dlg
, ctrl
->generic
.context
.i
);
2143 int messagebox(GtkWidget
*parentwin
, char *title
, char *msg
, int minwid
, ...)
2145 GtkWidget
*window
, *w0
, *w1
;
2146 struct controlbox
*ctrlbox
;
2147 struct controlset
*s0
, *s1
;
2150 struct Shortcuts scs
;
2156 for (index
= 0; index
< lenof(scs
.sc
); index
++) {
2157 scs
.sc
[index
].action
= SHORTCUT_EMPTY
;
2160 ctrlbox
= ctrl_new_box();
2163 va_start(ap
, minwid
);
2164 while (va_arg(ap
, char *) != NULL
) {
2166 (void) va_arg(ap
, int); /* shortcut */
2167 (void) va_arg(ap
, int); /* normal/default/cancel */
2168 (void) va_arg(ap
, int); /* end value */
2172 s0
= ctrl_getset(ctrlbox
, "", "", "");
2173 c
= ctrl_columns(s0
, 2, 50, 50);
2174 c
->columns
.ncols
= s0
->ncolumns
= ncols
;
2175 c
->columns
.percentages
= sresize(c
->columns
.percentages
, ncols
, int);
2176 for (index
= 0; index
< ncols
; index
++)
2177 c
->columns
.percentages
[index
] = (index
+1)*100/ncols
- index
*100/ncols
;
2178 va_start(ap
, minwid
);
2181 char *title
= va_arg(ap
, char *);
2182 int shortcut
, type
, value
;
2185 shortcut
= va_arg(ap
, int);
2186 type
= va_arg(ap
, int);
2187 value
= va_arg(ap
, int);
2188 c
= ctrl_pushbutton(s0
, title
, shortcut
, HELPCTX(no_help
),
2189 messagebox_handler
, I(value
));
2190 c
->generic
.column
= index
++;
2192 c
->button
.isdefault
= TRUE
;
2194 c
->button
.iscancel
= TRUE
;
2198 s1
= ctrl_getset(ctrlbox
, "x", "", "");
2199 ctrl_text(s1
, msg
, HELPCTX(no_help
));
2201 window
= gtk_dialog_new();
2202 gtk_window_set_title(GTK_WINDOW(window
), title
);
2203 w0
= layout_ctrls(&dp
, &scs
, s0
, 0, GTK_WINDOW(window
));
2204 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->action_area
),
2206 gtk_widget_show(w0
);
2207 w1
= layout_ctrls(&dp
, &scs
, s1
, 0, GTK_WINDOW(window
));
2208 gtk_container_set_border_width(GTK_CONTAINER(w1
), 10);
2209 gtk_widget_set_usize(w1
, minwid
+20, -1);
2210 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
),
2212 gtk_widget_show(w1
);
2214 dp
.shortcuts
= &scs
;
2215 dp
.lastfocus
= NULL
;
2219 gtk_window_set_modal(GTK_WINDOW(window
), TRUE
);
2221 gint x
, y
, w
, h
, dx
, dy
;
2222 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_NONE
);
2223 gdk_window_get_origin(parentwin
->window
, &x
, &y
);
2224 gdk_window_get_size(parentwin
->window
, &w
, &h
);
2227 gtk_widget_set_uposition(GTK_WIDGET(window
), dx
, dy
);
2228 gtk_window_set_transient_for(GTK_WINDOW(window
),
2229 GTK_WINDOW(parentwin
));
2231 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
2232 gtk_widget_show(window
);
2234 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
2235 GTK_SIGNAL_FUNC(window_destroy
), NULL
);
2236 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
2237 GTK_SIGNAL_FUNC(win_key_press
), &dp
);
2242 ctrl_free_box(ctrlbox
);
2247 static int string_width(char *text
)
2249 GtkWidget
*label
= gtk_label_new(text
);
2251 gtk_widget_size_request(label
, &req
);
2252 gtk_widget_unref(label
);
2256 void verify_ssh_host_key(void *frontend
, char *host
, int port
, char *keytype
,
2257 char *keystr
, char *fingerprint
)
2259 static const char absenttxt
[] =
2260 "The server's host key is not cached. You have no guarantee "
2261 "that the server is the computer you think it is.\n"
2262 "The server's key fingerprint is:\n"
2264 "If you trust this host, press \"Accept\" to add the key to "
2265 "PuTTY's cache and carry on connecting.\n"
2266 "If you want to carry on connecting just once, without "
2267 "adding the key to the cache, press \"Connect Once\".\n"
2268 "If you do not trust this host, press \"Cancel\" to abandon the "
2270 static const char wrongtxt
[] =
2271 "WARNING - POTENTIAL SECURITY BREACH!\n"
2272 "The server's host key does not match the one PuTTY has "
2273 "cached. This means that either the server administrator "
2274 "has changed the host key, or you have actually connected "
2275 "to another computer pretending to be the server.\n"
2276 "The new key fingerprint is:\n"
2278 "If you were expecting this change and trust the new key, "
2279 "press \"Accept\" to update PuTTY's cache and continue connecting.\n"
2280 "If you want to carry on connecting but without updating "
2281 "the cache, press \"Connect Once\".\n"
2282 "If you want to abandon the connection completely, press "
2283 "\"Cancel\" to cancel. Pressing \"Cancel\" is the ONLY guaranteed "
2291 ret
= verify_host_key(host
, port
, keytype
, keystr
);
2293 if (ret
== 0) /* success - key matched OK */
2296 text
= dupprintf((ret
== 2 ? wrongtxt
: absenttxt
), fingerprint
);
2298 ret
= messagebox(GTK_WIDGET(get_window(frontend
)),
2299 "PuTTY Security Alert", text
,
2300 string_width(fingerprint
),
2301 "Accept", 'a', 0, 2,
2302 "Connect Once", 'o', 0, 1,
2303 "Cancel", 'c', -1, 0,
2311 store_host_key(host
, port
, keytype
, keystr
);
2315 * Ask whether the selected cipher is acceptable (since it was
2316 * below the configured 'warn' threshold).
2317 * cs: 0 = both ways, 1 = client->server, 2 = server->client
2319 void askcipher(void *frontend
, char *ciphername
, int cs
)
2321 static const char msg
[] =
2322 "The first %scipher supported by the server is "
2323 "%s, which is below the configured warning threshold.\n"
2324 "Continue with connection?";
2328 text
= dupprintf(msg
, (cs
== 0) ?
"" :
2329 (cs
== 1) ?
"client-to-server " : "server-to-client ",
2331 ret
= messagebox(GTK_WIDGET(get_window(frontend
)),
2332 "PuTTY Security Alert", text
,
2333 string_width("Continue with connection?"),
2346 void old_keyfile_warning(void)
2349 * This should never happen on Unix. We hope.
2353 void fatal_message_box(void *window
, char *msg
)
2355 messagebox(window
, "PuTTY Fatal Error", msg
,
2356 string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
2357 "OK", 'o', 1, 1, NULL
);
2360 void fatalbox(char *p
, ...)
2365 msg
= dupvprintf(p
, ap
);
2367 fatal_message_box(NULL
, msg
);
2372 static GtkWidget
*aboutbox
= NULL
;
2374 static void about_close_clicked(GtkButton
*button
, gpointer data
)
2376 gtk_widget_destroy(aboutbox
);
2380 static void licence_clicked(GtkButton
*button
, gpointer data
)
2385 "Copyright 1997-2003 Simon Tatham.\n\n"
2387 "Portions copyright Robert de Bath, Joris van Rantwijk, Delian "
2388 "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas "
2389 "Barry, Justin Bradford, Ben Harris, and CORE SDI S.A.\n\n"
2391 "Permission is hereby granted, free of charge, to any person "
2392 "obtaining a copy of this software and associated documentation "
2393 "files (the ""Software""), to deal in the Software without restriction, "
2394 "including without limitation the rights to use, copy, modify, merge, "
2395 "publish, distribute, sublicense, and/or sell copies of the Software, "
2396 "and to permit persons to whom the Software is furnished to do so, "
2397 "subject to the following conditions:\n\n"
2399 "The above copyright notice and this permission notice shall be "
2400 "included in all copies or substantial portions of the Software.\n\n"
2402 "THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT "
2403 "WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, "
2404 "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF "
2405 "MERCHANTABILITY, FITNESS FOR A PARTICULAR "
2406 "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
2407 "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES "
2408 "OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, "
2409 "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN "
2410 "CONNECTION WITH THE SOFTWARE OR THE USE OR "
2411 "OTHER DEALINGS IN THE SOFTWARE.";
2413 title
= dupcat(appname
, " Licence", NULL
);
2414 assert(aboutbox
!= NULL
);
2415 messagebox(aboutbox
, title
, licence
,
2416 string_width("LONGISH LINE OF TEXT SO THE LICENCE"
2417 " BOX ISN'T EXCESSIVELY TALL AND THIN"),
2418 "OK", 'o', 1, 1, NULL
);
2422 void about_box(void)
2428 gtk_widget_grab_focus(aboutbox
);
2432 aboutbox
= gtk_dialog_new();
2433 gtk_container_set_border_width(GTK_CONTAINER(aboutbox
), 10);
2434 title
= dupcat("About ", appname
, NULL
);
2435 gtk_window_set_title(GTK_WINDOW(aboutbox
), title
);
2438 w
= gtk_button_new_with_label("Close");
2439 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
2440 gtk_window_set_default(GTK_WINDOW(aboutbox
), w
);
2441 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(aboutbox
)->action_area
),
2442 w
, FALSE
, FALSE
, 0);
2443 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
2444 GTK_SIGNAL_FUNC(about_close_clicked
), NULL
);
2447 w
= gtk_button_new_with_label("View Licence");
2448 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
2449 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(aboutbox
)->action_area
),
2450 w
, FALSE
, FALSE
, 0);
2451 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
2452 GTK_SIGNAL_FUNC(licence_clicked
), NULL
);
2455 w
= gtk_label_new(appname
);
2456 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox
)->vbox
),
2457 w
, FALSE
, FALSE
, 0);
2460 w
= gtk_label_new(ver
);
2461 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox
)->vbox
),
2462 w
, FALSE
, FALSE
, 5);
2465 w
= gtk_label_new("Copyright 1997-2003 Simon Tatham. All rights reserved");
2466 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox
)->vbox
),
2467 w
, FALSE
, FALSE
, 5);
2470 gtk_widget_show(aboutbox
);
2473 struct eventlog_stuff
{
2474 GtkWidget
*parentwin
, *window
;
2475 struct controlbox
*eventbox
;
2476 struct Shortcuts scs
;
2478 union control
*listctrl
;
2480 int nevents
, negsize
;
2483 static void eventlog_destroy(GtkWidget
*widget
, gpointer data
)
2485 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)data
;
2488 dlg_cleanup(&es
->dp
);
2489 ctrl_free_box(es
->eventbox
);
2491 static void eventlog_ok_handler(union control
*ctrl
, void *dlg
,
2492 void *data
, int event
)
2494 if (event
== EVENT_ACTION
)
2497 static void eventlog_list_handler(union control
*ctrl
, void *dlg
,
2498 void *data
, int event
)
2500 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)data
;
2502 if (event
== EVENT_REFRESH
) {
2505 dlg_update_start(ctrl
, dlg
);
2506 dlg_listbox_clear(ctrl
, dlg
);
2507 for (i
= 0; i
< es
->nevents
; i
++) {
2508 dlg_listbox_add(ctrl
, dlg
, es
->events
[i
]);
2510 dlg_update_done(ctrl
, dlg
);
2513 void showeventlog(void *estuff
, void *parentwin
)
2515 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)estuff
;
2516 GtkWidget
*window
, *w0
, *w1
;
2517 GtkWidget
*parent
= GTK_WIDGET(parentwin
);
2518 struct controlset
*s0
, *s1
;
2520 int listitemheight
, index
;
2524 gtk_widget_grab_focus(es
->window
);
2530 for (index
= 0; index
< lenof(es
->scs
.sc
); index
++) {
2531 es
->scs
.sc
[index
].action
= SHORTCUT_EMPTY
;
2534 es
->eventbox
= ctrl_new_box();
2536 s0
= ctrl_getset(es
->eventbox
, "", "", "");
2537 ctrl_columns(s0
, 3, 33, 34, 33);
2538 c
= ctrl_pushbutton(s0
, "Close", 'c', HELPCTX(no_help
),
2539 eventlog_ok_handler
, P(NULL
));
2540 c
->button
.column
= 1;
2541 c
->button
.isdefault
= TRUE
;
2543 s1
= ctrl_getset(es
->eventbox
, "x", "", "");
2544 es
->listctrl
= c
= ctrl_listbox(s1
, NULL
, NO_SHORTCUT
, HELPCTX(no_help
),
2545 eventlog_list_handler
, P(es
));
2546 c
->listbox
.height
= 10;
2547 c
->listbox
.multisel
= 2;
2548 c
->listbox
.ncols
= 3;
2549 c
->listbox
.percentages
= snewn(3, int);
2550 c
->listbox
.percentages
[0] = 25;
2551 c
->listbox
.percentages
[1] = 10;
2552 c
->listbox
.percentages
[2] = 65;
2554 listitemheight
= get_listitemheight();
2556 es
->window
= window
= gtk_dialog_new();
2557 title
= dupcat(appname
, " Event Log", NULL
);
2558 gtk_window_set_title(GTK_WINDOW(window
), title
);
2560 w0
= layout_ctrls(&es
->dp
, &es
->scs
, s0
,
2561 listitemheight
, GTK_WINDOW(window
));
2562 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->action_area
),
2564 gtk_widget_show(w0
);
2565 w1
= layout_ctrls(&es
->dp
, &es
->scs
, s1
,
2566 listitemheight
, GTK_WINDOW(window
));
2567 gtk_container_set_border_width(GTK_CONTAINER(w1
), 10);
2568 gtk_widget_set_usize(w1
, 20 +
2569 string_width("LINE OF TEXT GIVING WIDTH OF EVENT LOG"
2570 " IS QUITE LONG 'COS SSH LOG ENTRIES"
2572 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
),
2574 gtk_widget_show(w1
);
2577 es
->dp
.shortcuts
= &es
->scs
;
2578 es
->dp
.lastfocus
= NULL
;
2580 es
->dp
.window
= window
;
2582 dlg_refresh(NULL
, &es
->dp
);
2585 gint x
, y
, w
, h
, dx
, dy
;
2586 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_NONE
);
2587 gdk_window_get_origin(parent
->window
, &x
, &y
);
2588 gdk_window_get_size(parent
->window
, &w
, &h
);
2591 gtk_widget_set_uposition(GTK_WIDGET(window
), dx
, dy
);
2592 gtk_window_set_transient_for(GTK_WINDOW(window
),
2593 GTK_WINDOW(parent
));
2595 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
2596 gtk_widget_show(window
);
2598 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
2599 GTK_SIGNAL_FUNC(eventlog_destroy
), es
);
2600 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
2601 GTK_SIGNAL_FUNC(win_key_press
), &es
->dp
);
2604 void *eventlogstuff_new(void)
2606 struct eventlog_stuff
*es
;
2607 es
= snew(struct eventlog_stuff
);
2608 memset(es
, 0, sizeof(*es
));
2612 void logevent_dlg(void *estuff
, char *string
)
2614 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)estuff
;
2619 if (es
->nevents
>= es
->negsize
) {
2621 es
->events
= sresize(es
->events
, es
->negsize
, char *);
2625 strftime(timebuf
, sizeof(timebuf
), "%Y-%m-%d %H:%M:%S\t",
2628 es
->events
[es
->nevents
] = snewn(strlen(timebuf
) + strlen(string
) + 1, char);
2629 strcpy(es
->events
[es
->nevents
], timebuf
);
2630 strcat(es
->events
[es
->nevents
], string
);
2632 dlg_listbox_add(es
->listctrl
, &es
->dp
, es
->events
[es
->nevents
]);