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
);
311 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
312 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
313 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
316 gtk_container_foreach(GTK_CONTAINER(uc
->menu
),
317 container_remove_and_destroy
,
318 GTK_CONTAINER(uc
->menu
));
320 gtk_list_clear_items(GTK_LIST(uc
->list
), 0, -1);
324 void dlg_listbox_del(union control
*ctrl
, void *dlg
, int index
)
326 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
327 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
329 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
330 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
331 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
335 (GTK_CONTAINER(uc
->menu
),
336 g_list_nth_data(GTK_MENU_SHELL(uc
->menu
)->children
, index
));
338 gtk_list_clear_items(GTK_LIST(uc
->list
), index
, index
+1);
342 void dlg_listbox_add(union control
*ctrl
, void *dlg
, char const *text
)
344 dlg_listbox_addwithid(ctrl
, dlg
, text
, 0);
348 * Each listbox entry may have a numeric id associated with it.
349 * Note that some front ends only permit a string to be stored at
350 * each position, which means that _if_ you put two identical
351 * strings in any listbox then you MUST not assign them different
352 * IDs and expect to get meaningful results back.
354 void dlg_listbox_addwithid(union control
*ctrl
, void *dlg
,
355 char const *text
, int id
)
357 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
358 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
360 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
361 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
362 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
364 dp
->flags
|= FLAG_UPDATING_COMBO_LIST
;
368 * List item in a drop-down (but non-combo) list. Tabs are
369 * ignored; we just provide a standard menu item with the
372 GtkWidget
*menuitem
= gtk_menu_item_new_with_label(text
);
374 gtk_container_add(GTK_CONTAINER(uc
->menu
), menuitem
);
375 gtk_widget_show(menuitem
);
377 gtk_object_set_data(GTK_OBJECT(menuitem
), "user-data", (gpointer
)id
);
378 gtk_signal_connect(GTK_OBJECT(menuitem
), "activate",
379 GTK_SIGNAL_FUNC(menuitem_activate
), dp
);
380 } else if (!uc
->entry
) {
382 * List item in a non-combo-box list box. We make all of
383 * these Columns containing GtkLabels. This allows us to do
384 * the nasty force_left hack irrespective of whether there
385 * are tabs in the thing.
387 GtkWidget
*listitem
= gtk_list_item_new();
388 GtkWidget
*cols
= columns_new(10);
392 /* Count the tabs in the text, and hence determine # of columns. */
394 for (i
= 0; text
[i
]; i
++)
399 (uc
->ctrl
->listbox
.ncols ? uc
->ctrl
->listbox
.ncols
: 1));
400 percents
= snewn(ncols
, gint
);
401 percents
[ncols
-1] = 100;
402 for (i
= 0; i
< ncols
-1; i
++) {
403 percents
[i
] = uc
->ctrl
->listbox
.percentages
[i
];
404 percents
[ncols
-1] -= percents
[i
];
406 columns_set_cols(COLUMNS(cols
), ncols
, percents
);
409 for (i
= 0; i
< ncols
; i
++) {
410 int len
= strcspn(text
, "\t");
411 char *dup
= dupprintf("%.*s", len
, text
);
416 label
= gtk_label_new(dup
);
419 columns_add(COLUMNS(cols
), label
, i
, 1);
420 columns_force_left_align(COLUMNS(cols
), label
);
421 gtk_widget_show(label
);
423 gtk_container_add(GTK_CONTAINER(listitem
), cols
);
424 gtk_widget_show(cols
);
425 gtk_container_add(GTK_CONTAINER(uc
->list
), listitem
);
426 gtk_widget_show(listitem
);
428 if (ctrl
->listbox
.multisel
) {
429 gtk_signal_connect(GTK_OBJECT(listitem
), "key_press_event",
430 GTK_SIGNAL_FUNC(listitem_multi_key
), uc
->adj
);
432 gtk_signal_connect(GTK_OBJECT(listitem
), "key_press_event",
433 GTK_SIGNAL_FUNC(listitem_single_key
), uc
->adj
);
435 gtk_signal_connect(GTK_OBJECT(listitem
), "focus_in_event",
436 GTK_SIGNAL_FUNC(widget_focus
), dp
);
437 gtk_signal_connect(GTK_OBJECT(listitem
), "button_press_event",
438 GTK_SIGNAL_FUNC(listitem_button
), dp
);
439 gtk_object_set_data(GTK_OBJECT(listitem
), "user-data", (gpointer
)id
);
442 * List item in a combo-box list, which means the sensible
443 * thing to do is make it a perfectly normal label. Hence
444 * tabs are disregarded.
446 GtkWidget
*listitem
= gtk_list_item_new_with_label(text
);
448 gtk_container_add(GTK_CONTAINER(uc
->list
), listitem
);
449 gtk_widget_show(listitem
);
451 gtk_object_set_data(GTK_OBJECT(listitem
), "user-data", (gpointer
)id
);
454 dp
->flags
&= ~FLAG_UPDATING_COMBO_LIST
;
457 int dlg_listbox_getid(union control
*ctrl
, void *dlg
, int index
)
459 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
460 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
464 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
465 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
466 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
468 children
= gtk_container_children(GTK_CONTAINER(uc
->menu ? uc
->menu
:
470 item
= GTK_OBJECT(g_list_nth_data(children
, index
));
471 g_list_free(children
);
473 return (int)gtk_object_get_data(GTK_OBJECT(item
), "user-data");
476 /* dlg_listbox_index returns <0 if no single element is selected. */
477 int dlg_listbox_index(union control
*ctrl
, void *dlg
)
479 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
480 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
482 GtkWidget
*item
, *activeitem
;
486 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
487 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
488 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
491 activeitem
= gtk_menu_get_active(GTK_MENU(uc
->menu
));
493 activeitem
= NULL
; /* unnecessarily placate gcc */
495 children
= gtk_container_children(GTK_CONTAINER(uc
->menu ? uc
->menu
:
497 for (i
= 0; children
!=NULL
&& (item
= GTK_WIDGET(children
->data
))!=NULL
;
498 i
++, children
= children
->next
) {
499 if (uc
->menu ? activeitem
== item
:
500 GTK_WIDGET_STATE(item
) == GTK_STATE_SELECTED
) {
507 g_list_free(children
);
508 return selected
< 0 ?
-1 : selected
;
511 int dlg_listbox_issel(union control
*ctrl
, void *dlg
, int index
)
513 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
514 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
516 GtkWidget
*item
, *activeitem
;
518 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
519 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
520 assert(uc
->menu
!= NULL
|| uc
->list
!= NULL
);
522 children
= gtk_container_children(GTK_CONTAINER(uc
->menu ? uc
->menu
:
524 item
= GTK_WIDGET(g_list_nth_data(children
, index
));
525 g_list_free(children
);
528 activeitem
= gtk_menu_get_active(GTK_MENU(uc
->menu
));
529 return item
== activeitem
;
531 return GTK_WIDGET_STATE(item
) == GTK_STATE_SELECTED
;
535 void dlg_listbox_select(union control
*ctrl
, void *dlg
, int index
)
537 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
538 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
540 assert(uc
->ctrl
->generic
.type
== CTRL_EDITBOX
||
541 uc
->ctrl
->generic
.type
== CTRL_LISTBOX
);
542 assert(uc
->optmenu
!= NULL
|| uc
->list
!= NULL
);
545 gtk_option_menu_set_history(GTK_OPTION_MENU(uc
->optmenu
), index
);
547 gtk_list_select_item(GTK_LIST(uc
->list
), index
);
551 void dlg_text_set(union control
*ctrl
, void *dlg
, char const *text
)
553 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
554 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
556 assert(uc
->ctrl
->generic
.type
== CTRL_TEXT
);
557 assert(uc
->text
!= NULL
);
559 gtk_label_set_text(GTK_LABEL(uc
->text
), text
);
562 void dlg_filesel_set(union control
*ctrl
, void *dlg
, Filename fn
)
564 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
565 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
566 assert(uc
->ctrl
->generic
.type
== CTRL_FILESELECT
);
567 assert(uc
->entry
!= NULL
);
568 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), fn
.path
);
571 void dlg_filesel_get(union control
*ctrl
, void *dlg
, Filename
*fn
)
573 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
574 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
575 assert(uc
->ctrl
->generic
.type
== CTRL_FILESELECT
);
576 assert(uc
->entry
!= NULL
);
577 strncpy(fn
->path
, gtk_entry_get_text(GTK_ENTRY(uc
->entry
)),
579 fn
->path
[lenof(fn
->path
)-1] = '\0';
582 void dlg_fontsel_set(union control
*ctrl
, void *dlg
, FontSpec fs
)
584 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
585 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
586 assert(uc
->ctrl
->generic
.type
== CTRL_FONTSELECT
);
587 assert(uc
->entry
!= NULL
);
588 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), fs
.name
);
591 void dlg_fontsel_get(union control
*ctrl
, void *dlg
, FontSpec
*fs
)
593 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
594 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
595 assert(uc
->ctrl
->generic
.type
== CTRL_FONTSELECT
);
596 assert(uc
->entry
!= NULL
);
597 strncpy(fs
->name
, gtk_entry_get_text(GTK_ENTRY(uc
->entry
)),
599 fs
->name
[lenof(fs
->name
)-1] = '\0';
603 * Bracketing a large set of updates in these two functions will
604 * cause the front end (if possible) to delay updating the screen
605 * until it's all complete, thus avoiding flicker.
607 void dlg_update_start(union control
*ctrl
, void *dlg
)
610 * Apparently we can't do this at all in GTK. GtkCList supports
611 * freeze and thaw, but not GtkList. Bah.
615 void dlg_update_done(union control
*ctrl
, void *dlg
)
618 * Apparently we can't do this at all in GTK. GtkCList supports
619 * freeze and thaw, but not GtkList. Bah.
623 void dlg_set_focus(union control
*ctrl
, void *dlg
)
625 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
626 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
628 switch (ctrl
->generic
.type
) {
631 /* Check boxes and buttons get the focus _and_ get toggled. */
632 gtk_widget_grab_focus(uc
->toplevel
);
634 case CTRL_FILESELECT
:
635 case CTRL_FONTSELECT
:
637 /* Anything containing an edit box gets that focused. */
638 gtk_widget_grab_focus(uc
->entry
);
642 * Radio buttons: we find the currently selected button and
647 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++)
648 if (gtk_toggle_button_get_active
649 (GTK_TOGGLE_BUTTON(uc
->buttons
[i
]))) {
650 gtk_widget_grab_focus(uc
->buttons
[i
]);
656 * If the list is really an option menu, we focus it.
657 * Otherwise we tell it to focus one of its children, which
658 * appears to do the Right Thing.
661 gtk_widget_grab_focus(uc
->optmenu
);
663 assert(uc
->list
!= NULL
);
664 gtk_container_focus(GTK_CONTAINER(uc
->list
), GTK_DIR_TAB_FORWARD
);
671 * During event processing, you might well want to give an error
672 * indication to the user. dlg_beep() is a quick and easy generic
673 * error; dlg_error() puts up a message-box or equivalent.
675 void dlg_beep(void *dlg
)
680 static void errmsg_button_clicked(GtkButton
*button
, gpointer data
)
682 gtk_widget_destroy(GTK_WIDGET(data
));
685 static void set_transient_window_pos(GtkWidget
*parent
, GtkWidget
*child
)
687 gint x
, y
, w
, h
, dx
, dy
;
689 gtk_window_set_position(GTK_WINDOW(child
), GTK_WIN_POS_NONE
);
690 gtk_widget_size_request(GTK_WIDGET(child
), &req
);
692 gdk_window_get_origin(GTK_WIDGET(parent
)->window
, &x
, &y
);
693 gdk_window_get_size(GTK_WIDGET(parent
)->window
, &w
, &h
);
696 * One corner of the transient will be offset inwards, by 1/4
697 * of the parent window's size, from the corresponding corner
698 * of the parent window. The corner will be chosen so as to
699 * place the transient closer to the centre of the screen; this
700 * should avoid transients going off the edge of the screen on
703 if (x
+ w
/2 < gdk_screen_width() / 2)
704 dx
= x
+ w
/4; /* work from left edges */
706 dx
= x
+ 3*w
/4 - req
.width
; /* work from right edges */
707 if (y
+ h
/2 < gdk_screen_height() / 2)
708 dy
= y
+ h
/4; /* work from top edges */
710 dy
= y
+ 3*h
/4 - req
.height
; /* work from bottom edges */
711 gtk_widget_set_uposition(GTK_WIDGET(child
), dx
, dy
);
714 void dlg_error_msg(void *dlg
, char *msg
)
716 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
717 GtkWidget
*window
, *hbox
, *text
, *ok
;
719 window
= gtk_dialog_new();
720 text
= gtk_label_new(msg
);
721 gtk_misc_set_alignment(GTK_MISC(text
), 0.0, 0.0);
722 hbox
= gtk_hbox_new(FALSE
, 0);
723 gtk_box_pack_start(GTK_BOX(hbox
), text
, FALSE
, FALSE
, 20);
724 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
),
725 hbox
, FALSE
, FALSE
, 20);
726 gtk_widget_show(text
);
727 gtk_widget_show(hbox
);
728 gtk_window_set_title(GTK_WINDOW(window
), "Error");
729 gtk_label_set_line_wrap(GTK_LABEL(text
), TRUE
);
730 ok
= gtk_button_new_with_label("OK");
731 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(window
)->action_area
),
732 ok
, FALSE
, FALSE
, 0);
734 GTK_WIDGET_SET_FLAGS(ok
, GTK_CAN_DEFAULT
);
735 gtk_window_set_default(GTK_WINDOW(window
), ok
);
736 gtk_signal_connect(GTK_OBJECT(ok
), "clicked",
737 GTK_SIGNAL_FUNC(errmsg_button_clicked
), window
);
738 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
739 GTK_SIGNAL_FUNC(window_destroy
), NULL
);
740 gtk_window_set_modal(GTK_WINDOW(window
), TRUE
);
741 gtk_window_set_transient_for(GTK_WINDOW(window
), GTK_WINDOW(dp
->window
));
742 set_transient_window_pos(dp
->window
, window
);
743 gtk_widget_show(window
);
748 * This function signals to the front end that the dialog's
749 * processing is completed, and passes an integer value (typically
752 void dlg_end(void *dlg
, int value
)
754 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
756 gtk_widget_destroy(dp
->window
);
759 void dlg_refresh(union control
*ctrl
, void *dlg
)
761 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
765 if (ctrl
->generic
.handler
!= NULL
)
766 ctrl
->generic
.handler(ctrl
, dp
, dp
->data
, EVENT_REFRESH
);
770 for (i
= 0; (uc
= index234(dp
->byctrl
, i
)) != NULL
; i
++) {
771 assert(uc
->ctrl
!= NULL
);
772 if (uc
->ctrl
->generic
.handler
!= NULL
)
773 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
,
774 dp
->data
, EVENT_REFRESH
);
779 void dlg_coloursel_start(union control
*ctrl
, void *dlg
, int r
, int g
, int b
)
781 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
782 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
);
785 GtkWidget
*coloursel
=
786 gtk_color_selection_dialog_new("Select a colour");
787 GtkColorSelectionDialog
*ccs
= GTK_COLOR_SELECTION_DIALOG(coloursel
);
789 dp
->coloursel_result
.ok
= FALSE
;
791 gtk_window_set_modal(GTK_WINDOW(coloursel
), TRUE
);
792 gtk_color_selection_set_opacity(GTK_COLOR_SELECTION(ccs
->colorsel
), FALSE
);
793 cvals
[0] = r
/ 255.0;
794 cvals
[1] = g
/ 255.0;
795 cvals
[2] = b
/ 255.0;
796 cvals
[3] = 1.0; /* fully opaque! */
797 gtk_color_selection_set_color(GTK_COLOR_SELECTION(ccs
->colorsel
), cvals
);
799 gtk_object_set_data(GTK_OBJECT(ccs
->ok_button
), "user-data",
800 (gpointer
)coloursel
);
801 gtk_object_set_data(GTK_OBJECT(ccs
->cancel_button
), "user-data",
802 (gpointer
)coloursel
);
803 gtk_object_set_data(GTK_OBJECT(coloursel
), "user-data", (gpointer
)uc
);
804 gtk_signal_connect(GTK_OBJECT(ccs
->ok_button
), "clicked",
805 GTK_SIGNAL_FUNC(coloursel_ok
), (gpointer
)dp
);
806 gtk_signal_connect(GTK_OBJECT(ccs
->cancel_button
), "clicked",
807 GTK_SIGNAL_FUNC(coloursel_cancel
), (gpointer
)dp
);
808 gtk_signal_connect_object(GTK_OBJECT(ccs
->ok_button
), "clicked",
809 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
810 (gpointer
)coloursel
);
811 gtk_signal_connect_object(GTK_OBJECT(ccs
->cancel_button
), "clicked",
812 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
813 (gpointer
)coloursel
);
814 gtk_widget_show(coloursel
);
817 int dlg_coloursel_results(union control
*ctrl
, void *dlg
,
818 int *r
, int *g
, int *b
)
820 struct dlgparam
*dp
= (struct dlgparam
*)dlg
;
821 if (dp
->coloursel_result
.ok
) {
822 *r
= dp
->coloursel_result
.r
;
823 *g
= dp
->coloursel_result
.g
;
824 *b
= dp
->coloursel_result
.b
;
830 /* ----------------------------------------------------------------------
831 * Signal handlers while the dialog box is active.
834 static gboolean
widget_focus(GtkWidget
*widget
, GdkEventFocus
*event
,
837 struct dlgparam
*dp
= (struct dlgparam
*)data
;
838 struct uctrl
*uc
= dlg_find_bywidget(dp
, widget
);
839 union control
*focus
;
846 if (focus
!= dp
->currfocus
) {
847 dp
->lastfocus
= dp
->currfocus
;
848 dp
->currfocus
= focus
;
854 static void button_clicked(GtkButton
*button
, gpointer data
)
856 struct dlgparam
*dp
= (struct dlgparam
*)data
;
857 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(button
));
858 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_ACTION
);
861 static void button_toggled(GtkToggleButton
*tb
, gpointer data
)
863 struct dlgparam
*dp
= (struct dlgparam
*)data
;
864 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(tb
));
865 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_VALCHANGE
);
868 static int editbox_key(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
871 * GtkEntry has a nasty habit of eating the Return key, which
872 * is unhelpful since it doesn't actually _do_ anything with it
873 * (it calls gtk_widget_activate, but our edit boxes never need
874 * activating). So I catch Return before GtkEntry sees it, and
875 * pass it straight on to the parent widget. Effect: hitting
876 * Return in an edit box will now activate the default button
877 * in the dialog just like it will everywhere else.
879 if (event
->keyval
== GDK_Return
&& widget
->parent
!= NULL
) {
881 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
), "key_press_event");
882 gtk_signal_emit_by_name(GTK_OBJECT(widget
->parent
), "key_press_event",
889 static void editbox_changed(GtkEditable
*ed
, gpointer data
)
891 struct dlgparam
*dp
= (struct dlgparam
*)data
;
892 if (!(dp
->flags
& FLAG_UPDATING_COMBO_LIST
)) {
893 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(ed
));
894 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_VALCHANGE
);
898 static void editbox_lostfocus(GtkWidget
*ed
, GdkEventFocus
*event
,
901 struct dlgparam
*dp
= (struct dlgparam
*)data
;
902 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(ed
));
903 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_REFRESH
);
906 static int listitem_key(GtkWidget
*item
, GdkEventKey
*event
, gpointer data
,
909 GtkAdjustment
*adj
= GTK_ADJUSTMENT(data
);
911 if (event
->keyval
== GDK_Up
|| event
->keyval
== GDK_KP_Up
||
912 event
->keyval
== GDK_Down
|| event
->keyval
== GDK_KP_Down
||
913 event
->keyval
== GDK_Page_Up
|| event
->keyval
== GDK_KP_Page_Up
||
914 event
->keyval
== GDK_Page_Down
|| event
->keyval
== GDK_KP_Page_Down
) {
916 * Up, Down, PgUp or PgDn have been pressed on a ListItem
917 * in a list box. So, if the list box is single-selection:
919 * - if the list item in question isn't already selected,
920 * we simply select it.
921 * - otherwise, we find the next one (or next
922 * however-far-away) in whichever direction we're going,
924 * + in this case, we must also fiddle with the
925 * scrollbar to ensure the newly selected item is
928 * If it's multiple-selection, we do all of the above
929 * except actually selecting anything, so we move the focus
930 * and fiddle the scrollbar to follow it.
932 GtkWidget
*list
= item
->parent
;
934 gtk_signal_emit_stop_by_name(GTK_OBJECT(item
), "key_press_event");
937 GTK_WIDGET_STATE(item
) != GTK_STATE_SELECTED
) {
938 gtk_list_select_child(GTK_LIST(list
), item
);
941 (event
->keyval
==GDK_Up
|| event
->keyval
==GDK_KP_Up
||
942 event
->keyval
==GDK_Page_Up
|| event
->keyval
==GDK_KP_Page_Up
)
945 (event
->keyval
==GDK_Page_Down
||
946 event
->keyval
==GDK_KP_Page_Down
||
947 event
->keyval
==GDK_Page_Up
|| event
->keyval
==GDK_KP_Page_Up
)
950 GList
*children
, *chead
;
952 chead
= children
= gtk_container_children(GTK_CONTAINER(list
));
954 n
= g_list_length(children
);
958 * Figure out how many list items to a screenful,
959 * and adjust the step appropriately.
961 step
= 0.5 + adj
->page_size
* n
/ (adj
->upper
- adj
->lower
);
962 step
--; /* go by one less than that */
966 while (children
!= NULL
) {
967 if (item
== children
->data
)
969 children
= children
->next
;
974 if (direction
< 0 && i
> 0)
975 children
= children
->prev
, i
--;
976 else if (direction
> 0 && i
< n
-1)
977 children
= children
->next
, i
++;
981 if (children
&& children
->data
) {
983 gtk_list_select_child(GTK_LIST(list
),
984 GTK_WIDGET(children
->data
));
985 gtk_widget_grab_focus(GTK_WIDGET(children
->data
));
986 gtk_adjustment_clamp_page
988 adj
->lower
+ (adj
->upper
-adj
->lower
) * i
/ n
,
989 adj
->lower
+ (adj
->upper
-adj
->lower
) * (i
+1) / n
);
1000 static int listitem_single_key(GtkWidget
*item
, GdkEventKey
*event
,
1003 return listitem_key(item
, event
, data
, FALSE
);
1006 static int listitem_multi_key(GtkWidget
*item
, GdkEventKey
*event
,
1009 return listitem_key(item
, event
, data
, TRUE
);
1012 static int listitem_button(GtkWidget
*item
, GdkEventButton
*event
,
1015 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1016 if (event
->type
== GDK_2BUTTON_PRESS
||
1017 event
->type
== GDK_3BUTTON_PRESS
) {
1018 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(item
));
1019 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_ACTION
);
1025 static void list_selchange(GtkList
*list
, gpointer data
)
1027 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1028 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(list
));
1030 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_SELCHANGE
);
1033 static void menuitem_activate(GtkMenuItem
*item
, gpointer data
)
1035 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1036 GtkWidget
*menushell
= GTK_WIDGET(item
)->parent
;
1037 gpointer optmenu
= gtk_object_get_data(GTK_OBJECT(menushell
), "user-data");
1038 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(optmenu
));
1039 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_SELCHANGE
);
1042 static void draglist_move(struct dlgparam
*dp
, struct uctrl
*uc
, int direction
)
1044 int index
= dlg_listbox_index(uc
->ctrl
, dp
);
1045 GList
*children
= gtk_container_children(GTK_CONTAINER(uc
->list
));
1049 (index
== 0 && direction
< 0) ||
1050 (index
== g_list_length(children
)-1 && direction
> 0)) {
1055 child
= g_list_nth_data(children
, index
);
1056 gtk_widget_ref(child
);
1057 gtk_list_clear_items(GTK_LIST(uc
->list
), index
, index
+1);
1058 g_list_free(children
);
1061 children
= g_list_append(children
, child
);
1062 gtk_list_insert_items(GTK_LIST(uc
->list
), children
, index
+ direction
);
1063 gtk_list_select_item(GTK_LIST(uc
->list
), index
+ direction
);
1064 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_VALCHANGE
);
1067 static void draglist_up(GtkButton
*button
, gpointer data
)
1069 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1070 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(button
));
1071 draglist_move(dp
, uc
, -1);
1074 static void draglist_down(GtkButton
*button
, gpointer data
)
1076 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1077 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(button
));
1078 draglist_move(dp
, uc
, +1);
1081 static void filesel_ok(GtkButton
*button
, gpointer data
)
1083 /* struct dlgparam *dp = (struct dlgparam *)data; */
1084 gpointer filesel
= gtk_object_get_data(GTK_OBJECT(button
), "user-data");
1085 struct uctrl
*uc
= gtk_object_get_data(GTK_OBJECT(filesel
), "user-data");
1086 char *name
= gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel
));
1087 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), name
);
1090 static void fontsel_ok(GtkButton
*button
, gpointer data
)
1092 /* struct dlgparam *dp = (struct dlgparam *)data; */
1093 gpointer fontsel
= gtk_object_get_data(GTK_OBJECT(button
), "user-data");
1094 struct uctrl
*uc
= gtk_object_get_data(GTK_OBJECT(fontsel
), "user-data");
1095 char *name
= gtk_font_selection_dialog_get_font_name
1096 (GTK_FONT_SELECTION_DIALOG(fontsel
));
1097 gtk_entry_set_text(GTK_ENTRY(uc
->entry
), name
);
1100 static void coloursel_ok(GtkButton
*button
, gpointer data
)
1102 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1103 gpointer coloursel
= gtk_object_get_data(GTK_OBJECT(button
), "user-data");
1104 struct uctrl
*uc
= gtk_object_get_data(GTK_OBJECT(coloursel
), "user-data");
1106 gtk_color_selection_get_color
1107 (GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(coloursel
)->colorsel
),
1109 dp
->coloursel_result
.r
= (int) (255 * cvals
[0]);
1110 dp
->coloursel_result
.g
= (int) (255 * cvals
[1]);
1111 dp
->coloursel_result
.b
= (int) (255 * cvals
[2]);
1112 dp
->coloursel_result
.ok
= TRUE
;
1113 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_CALLBACK
);
1116 static void coloursel_cancel(GtkButton
*button
, gpointer data
)
1118 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1119 gpointer coloursel
= gtk_object_get_data(GTK_OBJECT(button
), "user-data");
1120 struct uctrl
*uc
= gtk_object_get_data(GTK_OBJECT(coloursel
), "user-data");
1121 dp
->coloursel_result
.ok
= FALSE
;
1122 uc
->ctrl
->generic
.handler(uc
->ctrl
, dp
, dp
->data
, EVENT_CALLBACK
);
1125 static void filefont_clicked(GtkButton
*button
, gpointer data
)
1127 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1128 struct uctrl
*uc
= dlg_find_bywidget(dp
, GTK_WIDGET(button
));
1130 if (uc
->ctrl
->generic
.type
== CTRL_FILESELECT
) {
1131 GtkWidget
*filesel
=
1132 gtk_file_selection_new(uc
->ctrl
->fileselect
.title
);
1133 gtk_window_set_modal(GTK_WINDOW(filesel
), TRUE
);
1135 (GTK_OBJECT(GTK_FILE_SELECTION(filesel
)->ok_button
), "user-data",
1137 gtk_object_set_data(GTK_OBJECT(filesel
), "user-data", (gpointer
)uc
);
1139 (GTK_OBJECT(GTK_FILE_SELECTION(filesel
)->ok_button
), "clicked",
1140 GTK_SIGNAL_FUNC(filesel_ok
), (gpointer
)dp
);
1141 gtk_signal_connect_object
1142 (GTK_OBJECT(GTK_FILE_SELECTION(filesel
)->ok_button
), "clicked",
1143 GTK_SIGNAL_FUNC(gtk_widget_destroy
), (gpointer
)filesel
);
1144 gtk_signal_connect_object
1145 (GTK_OBJECT(GTK_FILE_SELECTION(filesel
)->cancel_button
), "clicked",
1146 GTK_SIGNAL_FUNC(gtk_widget_destroy
), (gpointer
)filesel
);
1147 gtk_widget_show(filesel
);
1150 if (uc
->ctrl
->generic
.type
== CTRL_FONTSELECT
) {
1151 gchar
*spacings
[] = { "c", "m", NULL
};
1152 gchar
*fontname
= gtk_entry_get_text(GTK_ENTRY(uc
->entry
));
1153 GtkWidget
*fontsel
=
1154 gtk_font_selection_dialog_new("Select a font");
1155 gtk_window_set_modal(GTK_WINDOW(fontsel
), TRUE
);
1156 gtk_font_selection_dialog_set_filter
1157 (GTK_FONT_SELECTION_DIALOG(fontsel
),
1158 GTK_FONT_FILTER_BASE
, GTK_FONT_ALL
,
1159 NULL
, NULL
, NULL
, NULL
, spacings
, NULL
);
1160 if (!gtk_font_selection_dialog_set_font_name
1161 (GTK_FONT_SELECTION_DIALOG(fontsel
), fontname
)) {
1163 * If the font name wasn't found as it was, try opening
1164 * it and extracting its FONT property. This should
1165 * have the effect of mapping short aliases into true
1168 GdkFont
*font
= gdk_font_load(fontname
);
1170 XFontStruct
*xfs
= GDK_FONT_XFONT(font
);
1171 Display
*disp
= GDK_FONT_XDISPLAY(font
);
1172 Atom fontprop
= XInternAtom(disp
, "FONT", False
);
1174 if (XGetFontProperty(xfs
, fontprop
, &ret
)) {
1175 char *name
= XGetAtomName(disp
, (Atom
)ret
);
1177 gtk_font_selection_dialog_set_font_name
1178 (GTK_FONT_SELECTION_DIALOG(fontsel
), name
);
1180 gdk_font_unref(font
);
1184 (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel
)->ok_button
),
1185 "user-data", (gpointer
)fontsel
);
1186 gtk_object_set_data(GTK_OBJECT(fontsel
), "user-data", (gpointer
)uc
);
1188 (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel
)->ok_button
),
1189 "clicked", GTK_SIGNAL_FUNC(fontsel_ok
), (gpointer
)dp
);
1190 gtk_signal_connect_object
1191 (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel
)->ok_button
),
1192 "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1194 gtk_signal_connect_object
1195 (GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel
)->cancel_button
),
1196 "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1198 gtk_widget_show(fontsel
);
1202 static void label_sizealloc(GtkWidget
*widget
, GtkAllocation
*alloc
,
1205 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1206 struct uctrl
*uc
= dlg_find_bywidget(dp
, widget
);
1208 gtk_widget_set_usize(uc
->text
, alloc
->width
, -1);
1209 gtk_label_set_text(GTK_LABEL(uc
->text
), uc
->ctrl
->generic
.label
);
1210 gtk_signal_disconnect(GTK_OBJECT(uc
->text
), uc
->textsig
);
1213 /* ----------------------------------------------------------------------
1214 * This function does the main layout work: it reads a controlset,
1215 * it creates the relevant GTK controls, and returns a GtkWidget
1216 * containing the result. (This widget might be a title of some
1217 * sort, it might be a Columns containing many controls, or it
1218 * might be a GtkFrame containing a Columns; whatever it is, it's
1219 * definitely a GtkWidget and should probably be added to a
1222 * `listitemheight' is used to calculate a usize for list boxes: it
1223 * should be the height from the size request of a GtkListItem.
1225 * `win' is required for setting the default button. If it is
1226 * non-NULL, all buttons created will be default-capable (so they
1227 * have extra space round them for the default highlight).
1229 GtkWidget
*layout_ctrls(struct dlgparam
*dp
, struct Shortcuts
*scs
,
1230 struct controlset
*s
, int listitemheight
,
1237 if (!s
->boxname
&& s
->boxtitle
) {
1238 /* This controlset is a panel title. */
1239 return gtk_label_new(s
->boxtitle
);
1243 * Otherwise, we expect to be laying out actual controls, so
1244 * we'll start by creating a Columns for the purpose.
1246 cols
= COLUMNS(columns_new(4));
1247 ret
= GTK_WIDGET(cols
);
1248 gtk_widget_show(ret
);
1251 * Create a containing frame if we have a box name.
1254 ret
= gtk_frame_new(s
->boxtitle
); /* NULL is valid here */
1255 gtk_container_set_border_width(GTK_CONTAINER(cols
), 4);
1256 gtk_container_add(GTK_CONTAINER(ret
), GTK_WIDGET(cols
));
1257 gtk_widget_show(ret
);
1261 * Now iterate through the controls themselves, create them,
1262 * and add them to the Columns.
1264 for (i
= 0; i
< s
->ncontrols
; i
++) {
1265 union control
*ctrl
= s
->ctrls
[i
];
1268 GtkWidget
*w
= NULL
;
1270 switch (ctrl
->generic
.type
) {
1273 static const int simplecols
[1] = { 100 };
1274 columns_set_cols(cols
, ctrl
->columns
.ncols
,
1275 (ctrl
->columns
.percentages ?
1276 ctrl
->columns
.percentages
: simplecols
));
1278 continue; /* no actual control created */
1281 struct uctrl
*uc
= dlg_find_byctrl(dp
, ctrl
->tabdelay
.ctrl
);
1283 columns_taborder_last(cols
, uc
->toplevel
);
1285 continue; /* no actual control created */
1288 uc
= snew(struct uctrl
);
1290 uc
->privdata
= NULL
;
1291 uc
->privdata_needs_free
= FALSE
;
1293 uc
->entry
= uc
->list
= uc
->menu
= NULL
;
1294 uc
->button
= uc
->optmenu
= uc
->text
= NULL
;
1296 switch (ctrl
->generic
.type
) {
1298 w
= gtk_button_new_with_label(ctrl
->generic
.label
);
1300 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
1301 if (ctrl
->button
.isdefault
)
1302 gtk_window_set_default(win
, w
);
1303 if (ctrl
->button
.iscancel
)
1304 dp
->cancelbutton
= w
;
1306 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
1307 GTK_SIGNAL_FUNC(button_clicked
), dp
);
1308 gtk_signal_connect(GTK_OBJECT(w
), "focus_in_event",
1309 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1310 shortcut_add(scs
, GTK_BIN(w
)->child
, ctrl
->button
.shortcut
,
1311 SHORTCUT_UCTRL
, uc
);
1314 w
= gtk_check_button_new_with_label(ctrl
->generic
.label
);
1315 gtk_signal_connect(GTK_OBJECT(w
), "toggled",
1316 GTK_SIGNAL_FUNC(button_toggled
), dp
);
1317 gtk_signal_connect(GTK_OBJECT(w
), "focus_in_event",
1318 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1319 shortcut_add(scs
, GTK_BIN(w
)->child
, ctrl
->checkbox
.shortcut
,
1320 SHORTCUT_UCTRL
, uc
);
1325 * Radio buttons get to go inside their own Columns, no
1329 gint i
, *percentages
;
1333 if (ctrl
->generic
.label
) {
1334 GtkWidget
*label
= gtk_label_new(ctrl
->generic
.label
);
1335 columns_add(COLUMNS(w
), label
, 0, 1);
1336 columns_force_left_align(COLUMNS(w
), label
);
1337 gtk_widget_show(label
);
1338 shortcut_add(scs
, label
, ctrl
->radio
.shortcut
,
1339 SHORTCUT_UCTRL
, uc
);
1341 percentages
= g_new(gint
, ctrl
->radio
.ncolumns
);
1342 for (i
= 0; i
< ctrl
->radio
.ncolumns
; i
++) {
1344 ((100 * (i
+1) / ctrl
->radio
.ncolumns
) -
1345 100 * i
/ ctrl
->radio
.ncolumns
);
1347 columns_set_cols(COLUMNS(w
), ctrl
->radio
.ncolumns
,
1349 g_free(percentages
);
1352 uc
->nbuttons
= ctrl
->radio
.nbuttons
;
1353 uc
->buttons
= snewn(uc
->nbuttons
, GtkWidget
*);
1355 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
1359 b
= (gtk_radio_button_new_with_label
1360 (group
, ctrl
->radio
.buttons
[i
]));
1362 group
= gtk_radio_button_group(GTK_RADIO_BUTTON(b
));
1363 colstart
= i
% ctrl
->radio
.ncolumns
;
1364 columns_add(COLUMNS(w
), b
, colstart
,
1365 (i
== ctrl
->radio
.nbuttons
-1 ?
1366 ctrl
->radio
.ncolumns
- colstart
: 1));
1367 columns_force_left_align(COLUMNS(w
), b
);
1369 gtk_signal_connect(GTK_OBJECT(b
), "toggled",
1370 GTK_SIGNAL_FUNC(button_toggled
), dp
);
1371 gtk_signal_connect(GTK_OBJECT(b
), "focus_in_event",
1372 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1373 if (ctrl
->radio
.shortcuts
) {
1374 shortcut_add(scs
, GTK_BIN(b
)->child
,
1375 ctrl
->radio
.shortcuts
[i
],
1376 SHORTCUT_UCTRL
, uc
);
1385 if (ctrl
->editbox
.has_list
) {
1386 w
= gtk_combo_new();
1387 gtk_combo_set_value_in_list(GTK_COMBO(w
), FALSE
, TRUE
);
1388 uc
->entry
= GTK_COMBO(w
)->entry
;
1389 uc
->list
= GTK_COMBO(w
)->list
;
1391 w
= gtk_entry_new();
1392 if (ctrl
->editbox
.password
)
1393 gtk_entry_set_visibility(GTK_ENTRY(w
), FALSE
);
1396 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "changed",
1397 GTK_SIGNAL_FUNC(editbox_changed
), dp
);
1398 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "key_press_event",
1399 GTK_SIGNAL_FUNC(editbox_key
), dp
);
1400 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "focus_in_event",
1401 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1403 * Edit boxes, for some strange reason, have a minimum
1404 * width of 150 in GTK 1.2. We don't want this - we'd
1405 * rather the edit boxes acquired their natural width
1406 * from the column layout of the rest of the box.
1408 * Also, while we're here, we'll squirrel away the
1409 * edit box height so we can use that to centre its
1410 * label vertically beside it.
1412 gtk_widget_size_request(w
, &req
);
1413 gtk_widget_set_usize(w
, 10, req
.height
);
1415 if (ctrl
->generic
.label
) {
1416 GtkWidget
*label
, *container
;
1418 label
= gtk_label_new(ctrl
->generic
.label
);
1420 shortcut_add(scs
, label
, ctrl
->editbox
.shortcut
,
1421 SHORTCUT_FOCUS
, uc
->entry
);
1423 container
= columns_new(4);
1424 if (ctrl
->editbox
.percentwidth
== 100) {
1425 columns_add(COLUMNS(container
), label
, 0, 1);
1426 columns_force_left_align(COLUMNS(container
), label
);
1427 columns_add(COLUMNS(container
), w
, 0, 1);
1429 gint percentages
[2];
1430 percentages
[1] = ctrl
->editbox
.percentwidth
;
1431 percentages
[0] = 100 - ctrl
->editbox
.percentwidth
;
1432 columns_set_cols(COLUMNS(container
), 2, percentages
);
1433 columns_add(COLUMNS(container
), label
, 0, 1);
1434 columns_force_left_align(COLUMNS(container
), label
);
1435 columns_add(COLUMNS(container
), w
, 1, 1);
1436 /* Centre the label vertically. */
1437 gtk_widget_set_usize(label
, -1, req
.height
);
1438 gtk_misc_set_alignment(GTK_MISC(label
), 0.0, 0.5);
1440 gtk_widget_show(label
);
1445 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "focus_out_event",
1446 GTK_SIGNAL_FUNC(editbox_lostfocus
), dp
);
1449 case CTRL_FILESELECT
:
1450 case CTRL_FONTSELECT
:
1455 (ctrl
->generic
.type
== CTRL_FILESELECT ?
1456 "Browse..." : "Change...");
1458 gint percentages
[] = { 75, 25 };
1460 columns_set_cols(COLUMNS(w
), 2, percentages
);
1462 if (ctrl
->generic
.label
) {
1463 ww
= gtk_label_new(ctrl
->generic
.label
);
1464 columns_add(COLUMNS(w
), ww
, 0, 2);
1465 columns_force_left_align(COLUMNS(w
), ww
);
1466 gtk_widget_show(ww
);
1467 shortcut_add(scs
, ww
,
1468 (ctrl
->generic
.type
== CTRL_FILESELECT ?
1469 ctrl
->fileselect
.shortcut
:
1470 ctrl
->fontselect
.shortcut
),
1471 SHORTCUT_UCTRL
, uc
);
1474 uc
->entry
= ww
= gtk_entry_new();
1475 gtk_widget_size_request(ww
, &req
);
1476 gtk_widget_set_usize(ww
, 10, req
.height
);
1477 columns_add(COLUMNS(w
), ww
, 0, 1);
1478 gtk_widget_show(ww
);
1480 uc
->button
= ww
= gtk_button_new_with_label(browsebtn
);
1481 columns_add(COLUMNS(w
), ww
, 1, 1);
1482 gtk_widget_show(ww
);
1484 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "key_press_event",
1485 GTK_SIGNAL_FUNC(editbox_key
), dp
);
1486 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "changed",
1487 GTK_SIGNAL_FUNC(editbox_changed
), dp
);
1488 gtk_signal_connect(GTK_OBJECT(uc
->entry
), "focus_in_event",
1489 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1490 gtk_signal_connect(GTK_OBJECT(uc
->button
), "focus_in_event",
1491 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1492 gtk_signal_connect(GTK_OBJECT(ww
), "clicked",
1493 GTK_SIGNAL_FUNC(filefont_clicked
), dp
);
1497 if (ctrl
->listbox
.height
== 0) {
1498 uc
->optmenu
= w
= gtk_option_menu_new();
1499 uc
->menu
= gtk_menu_new();
1500 gtk_option_menu_set_menu(GTK_OPTION_MENU(w
), uc
->menu
);
1501 gtk_object_set_data(GTK_OBJECT(uc
->menu
), "user-data",
1502 (gpointer
)uc
->optmenu
);
1503 gtk_signal_connect(GTK_OBJECT(uc
->optmenu
), "focus_in_event",
1504 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1506 uc
->list
= gtk_list_new();
1507 if (ctrl
->listbox
.multisel
== 2) {
1508 gtk_list_set_selection_mode(GTK_LIST(uc
->list
),
1509 GTK_SELECTION_EXTENDED
);
1510 } else if (ctrl
->listbox
.multisel
== 1) {
1511 gtk_list_set_selection_mode(GTK_LIST(uc
->list
),
1512 GTK_SELECTION_MULTIPLE
);
1514 gtk_list_set_selection_mode(GTK_LIST(uc
->list
),
1515 GTK_SELECTION_SINGLE
);
1517 w
= gtk_scrolled_window_new(NULL
, NULL
);
1518 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(w
),
1520 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w
),
1522 GTK_POLICY_AUTOMATIC
);
1523 uc
->adj
= gtk_scrolled_window_get_vadjustment
1524 (GTK_SCROLLED_WINDOW(w
));
1526 gtk_widget_show(uc
->list
);
1527 gtk_signal_connect(GTK_OBJECT(uc
->list
), "selection-changed",
1528 GTK_SIGNAL_FUNC(list_selchange
), dp
);
1529 gtk_signal_connect(GTK_OBJECT(uc
->list
), "focus_in_event",
1530 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1533 * Adjust the height of the scrolled window to the
1534 * minimum given by the height parameter.
1536 * This piece of guesswork is a horrid hack based
1537 * on looking inside the GTK 1.2 sources
1538 * (specifically gtkviewport.c, which appears to be
1539 * the widget which provides the border around the
1540 * scrolling area). Anyone lets me know how I can
1541 * do this in a way which isn't at risk from GTK
1542 * upgrades, I'd be grateful.
1545 int edge
= GTK_WIDGET(uc
->list
)->style
->klass
->ythickness
;
1546 gtk_widget_set_usize(w
, 10,
1547 2*edge
+ (ctrl
->listbox
.height
*
1551 if (ctrl
->listbox
.draglist
) {
1553 * GTK doesn't appear to make it easy to
1554 * implement a proper draggable list; so
1555 * instead I'm just going to have to put an Up
1556 * and a Down button to the right of the actual
1557 * list box. Ah well.
1559 GtkWidget
*cols
, *button
;
1560 static const gint percentages
[2] = { 80, 20 };
1562 cols
= columns_new(4);
1563 columns_set_cols(COLUMNS(cols
), 2, percentages
);
1564 columns_add(COLUMNS(cols
), w
, 0, 1);
1566 button
= gtk_button_new_with_label("Up");
1567 columns_add(COLUMNS(cols
), button
, 1, 1);
1568 gtk_widget_show(button
);
1569 gtk_signal_connect(GTK_OBJECT(button
), "clicked",
1570 GTK_SIGNAL_FUNC(draglist_up
), dp
);
1571 gtk_signal_connect(GTK_OBJECT(button
), "focus_in_event",
1572 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1573 button
= gtk_button_new_with_label("Down");
1574 columns_add(COLUMNS(cols
), button
, 1, 1);
1575 gtk_widget_show(button
);
1576 gtk_signal_connect(GTK_OBJECT(button
), "clicked",
1577 GTK_SIGNAL_FUNC(draglist_down
), dp
);
1578 gtk_signal_connect(GTK_OBJECT(button
), "focus_in_event",
1579 GTK_SIGNAL_FUNC(widget_focus
), dp
);
1585 if (ctrl
->generic
.label
) {
1586 GtkWidget
*label
, *container
;
1588 label
= gtk_label_new(ctrl
->generic
.label
);
1590 container
= columns_new(4);
1591 if (ctrl
->listbox
.percentwidth
== 100) {
1592 columns_add(COLUMNS(container
), label
, 0, 1);
1593 columns_force_left_align(COLUMNS(container
), label
);
1594 columns_add(COLUMNS(container
), w
, 0, 1);
1596 gint percentages
[2];
1597 percentages
[1] = ctrl
->listbox
.percentwidth
;
1598 percentages
[0] = 100 - ctrl
->listbox
.percentwidth
;
1599 columns_set_cols(COLUMNS(container
), 2, percentages
);
1600 columns_add(COLUMNS(container
), label
, 0, 1);
1601 columns_force_left_align(COLUMNS(container
), label
);
1602 columns_add(COLUMNS(container
), w
, 1, 1);
1604 gtk_widget_show(label
);
1606 shortcut_add(scs
, label
, ctrl
->listbox
.shortcut
,
1607 SHORTCUT_UCTRL
, uc
);
1613 * Wrapping text widgets don't sit well with the GTK
1614 * layout model, in which widgets state a minimum size
1615 * and the whole window then adjusts to the smallest
1616 * size it can sensibly take given its contents. A
1617 * wrapping text widget _has_ no clear minimum size;
1618 * instead it has a range of possibilities. It can be
1619 * one line deep but 2000 wide, or two lines deep and
1620 * 1000 pixels, or three by 867, or four by 500 and so
1621 * on. It can be as short as you like provided you
1622 * don't mind it being wide, or as narrow as you like
1623 * provided you don't mind it being tall.
1625 * Therefore, it fits very badly into the layout model.
1626 * Hence the only thing to do is pick a width and let
1627 * it choose its own number of lines. To do this I'm
1628 * going to cheat a little. All new wrapping text
1629 * widgets will be created with a minimal text content
1630 * "X"; then, after the rest of the dialog box is set
1631 * up and its size calculated, the text widgets will be
1632 * told their width and given their real text, which
1633 * will cause the size to be recomputed in the y
1634 * direction (because many of them will expand to more
1637 uc
->text
= w
= gtk_label_new("X");
1638 gtk_misc_set_alignment(GTK_MISC(w
), 0.0, 0.0);
1639 gtk_label_set_line_wrap(GTK_LABEL(w
), TRUE
);
1641 gtk_signal_connect(GTK_OBJECT(w
), "size-allocate",
1642 GTK_SIGNAL_FUNC(label_sizealloc
), dp
);
1648 columns_add(cols
, w
,
1649 COLUMN_START(ctrl
->generic
.column
),
1650 COLUMN_SPAN(ctrl
->generic
.column
));
1652 columns_force_left_align(cols
, w
);
1656 dlg_add_uctrl(dp
, uc
);
1663 struct dlgparam
*dp
;
1665 GtkWidget
*panel
, *treeitem
;
1666 struct Shortcuts shortcuts
;
1669 static void treeitem_sel(GtkItem
*item
, gpointer data
)
1671 struct selparam
*sp
= (struct selparam
*)data
;
1673 panels_switch_to(sp
->panels
, sp
->panel
);
1675 sp
->dp
->shortcuts
= &sp
->shortcuts
;
1676 sp
->dp
->currtreeitem
= sp
->treeitem
;
1679 static void window_destroy(GtkWidget
*widget
, gpointer data
)
1684 static int tree_grab_focus(struct dlgparam
*dp
)
1689 * See if any of the treeitems has the focus.
1692 for (i
= 0; i
< dp
->ntreeitems
; i
++)
1693 if (GTK_WIDGET_HAS_FOCUS(dp
->treeitems
[i
])) {
1701 gtk_widget_grab_focus(dp
->currtreeitem
);
1706 gint
tree_focus(GtkContainer
*container
, GtkDirectionType direction
,
1709 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1711 gtk_signal_emit_stop_by_name(GTK_OBJECT(container
), "focus");
1713 * If there's a focused treeitem, we return FALSE to cause the
1714 * focus to move on to some totally other control. If not, we
1715 * focus the selected one.
1717 return tree_grab_focus(dp
);
1720 int win_key_press(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
1722 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1724 if (event
->keyval
== GDK_Escape
&& dp
->cancelbutton
) {
1725 gtk_signal_emit_by_name(GTK_OBJECT(dp
->cancelbutton
), "clicked");
1729 if ((event
->state
& GDK_MOD1_MASK
) &&
1730 (unsigned char)event
->string
[0] > 0 &&
1731 (unsigned char)event
->string
[0] <= 127) {
1732 int schr
= (unsigned char)event
->string
[0];
1733 struct Shortcut
*sc
= &dp
->shortcuts
->sc
[schr
];
1735 switch (sc
->action
) {
1737 tree_grab_focus(dp
);
1739 case SHORTCUT_FOCUS
:
1740 gtk_widget_grab_focus(sc
->widget
);
1742 case SHORTCUT_UCTRL
:
1744 * We must do something sensible with a uctrl.
1745 * Precisely what this is depends on the type of
1748 switch (sc
->uc
->ctrl
->generic
.type
) {
1751 /* Check boxes and buttons get the focus _and_ get toggled. */
1752 gtk_widget_grab_focus(sc
->uc
->toplevel
);
1753 gtk_signal_emit_by_name(GTK_OBJECT(sc
->uc
->toplevel
),
1756 case CTRL_FILESELECT
:
1757 case CTRL_FONTSELECT
:
1758 /* File/font selectors have their buttons pressed (ooer),
1759 * and focus transferred to the edit box. */
1760 gtk_signal_emit_by_name(GTK_OBJECT(sc
->uc
->button
),
1762 gtk_widget_grab_focus(sc
->uc
->entry
);
1766 * Radio buttons are fun, because they have
1767 * multiple shortcuts. We must find whether the
1768 * activated shortcut is the shortcut for the whole
1769 * group, or for a particular button. In the former
1770 * case, we find the currently selected button and
1771 * focus it; in the latter, we focus-and-click the
1772 * button whose shortcut was pressed.
1774 if (schr
== sc
->uc
->ctrl
->radio
.shortcut
) {
1776 for (i
= 0; i
< sc
->uc
->ctrl
->radio
.nbuttons
; i
++)
1777 if (gtk_toggle_button_get_active
1778 (GTK_TOGGLE_BUTTON(sc
->uc
->buttons
[i
]))) {
1779 gtk_widget_grab_focus(sc
->uc
->buttons
[i
]);
1781 } else if (sc
->uc
->ctrl
->radio
.shortcuts
) {
1783 for (i
= 0; i
< sc
->uc
->ctrl
->radio
.nbuttons
; i
++)
1784 if (schr
== sc
->uc
->ctrl
->radio
.shortcuts
[i
]) {
1785 gtk_widget_grab_focus(sc
->uc
->buttons
[i
]);
1786 gtk_signal_emit_by_name
1787 (GTK_OBJECT(sc
->uc
->buttons
[i
]), "clicked");
1793 * If the list is really an option menu, we focus
1794 * and click it. Otherwise we tell it to focus one
1795 * of its children, which appears to do the Right
1798 if (sc
->uc
->optmenu
) {
1802 gtk_widget_grab_focus(sc
->uc
->optmenu
);
1803 /* Option menus don't work using the "clicked" signal.
1804 * We need to manufacture a button press event :-/ */
1805 bev
.type
= GDK_BUTTON_PRESS
;
1807 gtk_signal_emit_by_name(GTK_OBJECT(sc
->uc
->optmenu
),
1808 "button_press_event",
1811 assert(sc
->uc
->list
!= NULL
);
1813 gtk_container_focus(GTK_CONTAINER(sc
->uc
->list
),
1814 GTK_DIR_TAB_FORWARD
);
1825 int tree_key_press(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
1827 struct dlgparam
*dp
= (struct dlgparam
*)data
;
1829 if (event
->keyval
== GDK_Up
|| event
->keyval
== GDK_KP_Up
||
1830 event
->keyval
== GDK_Down
|| event
->keyval
== GDK_KP_Down
) {
1832 for (i
= 0; i
< dp
->ntreeitems
; i
++)
1833 if (widget
== dp
->treeitems
[i
])
1835 if (i
< dp
->ntreeitems
) {
1836 if (event
->keyval
== GDK_Up
|| event
->keyval
== GDK_KP_Up
)
1843 if (i
< 0 || i
>= dp
->ntreeitems
)
1844 break; /* nothing in that dir to select */
1846 * Determine if this tree item is visible.
1849 GtkWidget
*w
= dp
->treeitems
[i
];
1851 while (w
&& (GTK_IS_TREE_ITEM(w
) || GTK_IS_TREE(w
))) {
1852 if (!GTK_WIDGET_VISIBLE(w
)) {
1859 j
= i
; /* got one */
1865 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
),
1868 gtk_signal_emit_by_name(GTK_OBJECT(dp
->treeitems
[j
]), "toggle");
1869 gtk_widget_grab_focus(dp
->treeitems
[j
]);
1875 * It's nice for Left and Right to expand and collapse tree
1878 if (event
->keyval
== GDK_Left
|| event
->keyval
== GDK_KP_Left
) {
1879 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
),
1881 gtk_tree_item_collapse(GTK_TREE_ITEM(widget
));
1884 if (event
->keyval
== GDK_Right
|| event
->keyval
== GDK_KP_Right
) {
1885 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
),
1887 gtk_tree_item_expand(GTK_TREE_ITEM(widget
));
1894 void shortcut_add(struct Shortcuts
*scs
, GtkWidget
*labelw
,
1895 int chr
, int action
, void *ptr
)
1897 GtkLabel
*label
= GTK_LABEL(labelw
);
1898 gchar
*currstr
, *pattern
;
1901 if (chr
== NO_SHORTCUT
)
1904 chr
= tolower((unsigned char)chr
);
1906 assert(scs
->sc
[chr
].action
== SHORTCUT_EMPTY
);
1908 scs
->sc
[chr
].action
= action
;
1910 if (action
== SHORTCUT_FOCUS
) {
1911 scs
->sc
[chr
].uc
= NULL
;
1912 scs
->sc
[chr
].widget
= (GtkWidget
*)ptr
;
1914 scs
->sc
[chr
].widget
= NULL
;
1915 scs
->sc
[chr
].uc
= (struct uctrl
*)ptr
;
1918 gtk_label_get(label
, &currstr
);
1919 for (i
= 0; currstr
[i
]; i
++)
1920 if (tolower((unsigned char)currstr
[i
]) == chr
) {
1923 pattern
= dupprintf("%*s_", i
, "");
1925 gtk_widget_size_request(GTK_WIDGET(label
), &req
);
1926 gtk_label_set_pattern(label
, pattern
);
1927 gtk_widget_set_usize(GTK_WIDGET(label
), -1, req
.height
);
1934 int get_listitemheight(void)
1936 GtkWidget
*listitem
= gtk_list_item_new_with_label("foo");
1938 gtk_widget_size_request(listitem
, &req
);
1939 gtk_widget_unref(listitem
);
1943 int do_config_box(const char *title
, Config
*cfg
, int midsession
)
1945 GtkWidget
*window
, *hbox
, *vbox
, *cols
, *label
,
1946 *tree
, *treescroll
, *panels
, *panelvbox
;
1947 int index
, level
, listitemheight
;
1948 struct controlbox
*ctrlbox
;
1950 GtkTreeItem
*treeitemlevels
[8];
1951 GtkTree
*treelevels
[8];
1954 struct Shortcuts scs
;
1956 struct selparam
*selparams
= NULL
;
1957 int nselparams
= 0, selparamsize
= 0;
1961 get_sesslist(&sl
, TRUE
);
1963 listitemheight
= get_listitemheight();
1965 for (index
= 0; index
< lenof(scs
.sc
); index
++) {
1966 scs
.sc
[index
].action
= SHORTCUT_EMPTY
;
1969 window
= gtk_dialog_new();
1971 ctrlbox
= ctrl_new_box();
1972 setup_config_box(ctrlbox
, &sl
, midsession
, 0);
1973 unix_setup_config_box(ctrlbox
, midsession
, window
);
1975 gtk_window_set_title(GTK_WINDOW(window
), title
);
1976 hbox
= gtk_hbox_new(FALSE
, 4);
1977 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
), hbox
, TRUE
, TRUE
, 0);
1978 gtk_container_set_border_width(GTK_CONTAINER(hbox
), 10);
1979 gtk_widget_show(hbox
);
1980 vbox
= gtk_vbox_new(FALSE
, 4);
1981 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, FALSE
, FALSE
, 0);
1982 gtk_widget_show(vbox
);
1983 cols
= columns_new(4);
1984 gtk_box_pack_start(GTK_BOX(vbox
), cols
, FALSE
, FALSE
, 0);
1985 gtk_widget_show(cols
);
1986 label
= gtk_label_new("Category:");
1987 columns_add(COLUMNS(cols
), label
, 0, 1);
1988 columns_force_left_align(COLUMNS(cols
), label
);
1989 gtk_widget_show(label
);
1990 treescroll
= gtk_scrolled_window_new(NULL
, NULL
);
1991 tree
= gtk_tree_new();
1992 gtk_signal_connect(GTK_OBJECT(tree
), "focus_in_event",
1993 GTK_SIGNAL_FUNC(widget_focus
), &dp
);
1994 shortcut_add(&scs
, label
, 'g', SHORTCUT_TREE
, tree
);
1995 gtk_tree_set_view_mode(GTK_TREE(tree
), GTK_TREE_VIEW_ITEM
);
1996 gtk_tree_set_selection_mode(GTK_TREE(tree
), GTK_SELECTION_BROWSE
);
1997 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(treescroll
),
1999 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(treescroll
),
2001 GTK_POLICY_AUTOMATIC
);
2002 gtk_signal_connect(GTK_OBJECT(tree
), "focus",
2003 GTK_SIGNAL_FUNC(tree_focus
), &dp
);
2004 gtk_widget_show(tree
);
2005 gtk_widget_show(treescroll
);
2006 gtk_box_pack_start(GTK_BOX(vbox
), treescroll
, TRUE
, TRUE
, 0);
2007 panels
= panels_new();
2008 gtk_box_pack_start(GTK_BOX(hbox
), panels
, TRUE
, TRUE
, 0);
2009 gtk_widget_show(panels
);
2014 for (index
= 0; index
< ctrlbox
->nctrlsets
; index
++) {
2015 struct controlset
*s
= ctrlbox
->ctrlsets
[index
];
2018 if (!*s
->pathname
) {
2019 w
= layout_ctrls(&dp
, &scs
, s
, listitemheight
, GTK_WINDOW(window
));
2020 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->action_area
),
2023 int j
= path ?
ctrl_path_compare(s
->pathname
, path
) : 0;
2024 if (j
!= INT_MAX
) { /* add to treeview, start new panel */
2026 GtkWidget
*treeitem
;
2030 * We expect never to find an implicit path
2031 * component. For example, we expect never to see
2032 * A/B/C followed by A/D/E, because that would
2033 * _implicitly_ create A/D. All our path prefixes
2034 * are expected to contain actual controls and be
2035 * selectable in the treeview; so we would expect
2036 * to see A/D _explicitly_ before encountering
2039 assert(j
== ctrl_path_elements(s
->pathname
) - 1);
2041 c
= strrchr(s
->pathname
, '/');
2047 treeitem
= gtk_tree_item_new_with_label(c
);
2048 assert(j
-1 < level
);
2050 if (!treelevels
[j
-1]) {
2051 treelevels
[j
-1] = GTK_TREE(gtk_tree_new());
2052 gtk_tree_item_set_subtree
2053 (treeitemlevels
[j
-1],
2054 GTK_WIDGET(treelevels
[j
-1]));
2055 gtk_tree_item_expand(treeitemlevels
[j
-1]);
2057 gtk_tree_append(treelevels
[j
-1], treeitem
);
2059 gtk_tree_append(GTK_TREE(tree
), treeitem
);
2061 treeitemlevels
[j
] = GTK_TREE_ITEM(treeitem
);
2062 treelevels
[j
] = NULL
;
2065 gtk_signal_connect(GTK_OBJECT(treeitem
), "key_press_event",
2066 GTK_SIGNAL_FUNC(tree_key_press
), &dp
);
2067 gtk_signal_connect(GTK_OBJECT(treeitem
), "focus_in_event",
2068 GTK_SIGNAL_FUNC(widget_focus
), &dp
);
2070 gtk_widget_show(treeitem
);
2074 first
= (panelvbox
== NULL
);
2076 panelvbox
= gtk_vbox_new(FALSE
, 4);
2077 gtk_container_add(GTK_CONTAINER(panels
), panelvbox
);
2079 panels_switch_to(PANELS(panels
), panelvbox
);
2080 gtk_tree_select_child(GTK_TREE(tree
), treeitem
);
2083 if (nselparams
>= selparamsize
) {
2085 selparams
= sresize(selparams
, selparamsize
,
2088 selparams
[nselparams
].dp
= &dp
;
2089 selparams
[nselparams
].panels
= PANELS(panels
);
2090 selparams
[nselparams
].panel
= panelvbox
;
2091 selparams
[nselparams
].shortcuts
= scs
; /* structure copy */
2092 selparams
[nselparams
].treeitem
= treeitem
;
2097 w
= layout_ctrls(&dp
,
2098 &selparams
[nselparams
-1].shortcuts
,
2099 s
, listitemheight
, NULL
);
2100 gtk_box_pack_start(GTK_BOX(panelvbox
), w
, FALSE
, FALSE
, 0);
2105 dp
.ntreeitems
= nselparams
;
2106 dp
.treeitems
= snewn(dp
.ntreeitems
, GtkWidget
*);
2108 for (index
= 0; index
< nselparams
; index
++) {
2109 gtk_signal_connect(GTK_OBJECT(selparams
[index
].treeitem
), "select",
2110 GTK_SIGNAL_FUNC(treeitem_sel
),
2112 dp
.treeitems
[index
] = selparams
[index
].treeitem
;
2116 dlg_refresh(NULL
, &dp
);
2118 dp
.shortcuts
= &selparams
[0].shortcuts
;
2119 dp
.currtreeitem
= dp
.treeitems
[0];
2120 dp
.lastfocus
= NULL
;
2124 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
2125 gtk_widget_show(window
);
2128 * Set focus into the first available control.
2130 for (index
= 0; index
< ctrlbox
->nctrlsets
; index
++) {
2131 struct controlset
*s
= ctrlbox
->ctrlsets
[index
];
2136 for (j
= 0; j
< s
->ncontrols
; j
++)
2137 if (s
->ctrls
[j
]->generic
.type
!= CTRL_TABDELAY
&&
2138 s
->ctrls
[j
]->generic
.type
!= CTRL_COLUMNS
&&
2139 s
->ctrls
[j
]->generic
.type
!= CTRL_TEXT
) {
2140 dlg_set_focus(s
->ctrls
[j
], &dp
);
2141 dp
.lastfocus
= s
->ctrls
[j
];
2150 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
2151 GTK_SIGNAL_FUNC(window_destroy
), NULL
);
2152 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
2153 GTK_SIGNAL_FUNC(win_key_press
), &dp
);
2157 get_sesslist(&sl
, FALSE
);
2164 static void messagebox_handler(union control
*ctrl
, void *dlg
,
2165 void *data
, int event
)
2167 if (event
== EVENT_ACTION
)
2168 dlg_end(dlg
, ctrl
->generic
.context
.i
);
2170 int messagebox(GtkWidget
*parentwin
, char *title
, char *msg
, int minwid
, ...)
2172 GtkWidget
*window
, *w0
, *w1
;
2173 struct controlbox
*ctrlbox
;
2174 struct controlset
*s0
, *s1
;
2177 struct Shortcuts scs
;
2183 for (index
= 0; index
< lenof(scs
.sc
); index
++) {
2184 scs
.sc
[index
].action
= SHORTCUT_EMPTY
;
2187 ctrlbox
= ctrl_new_box();
2190 va_start(ap
, minwid
);
2191 while (va_arg(ap
, char *) != NULL
) {
2193 (void) va_arg(ap
, int); /* shortcut */
2194 (void) va_arg(ap
, int); /* normal/default/cancel */
2195 (void) va_arg(ap
, int); /* end value */
2199 s0
= ctrl_getset(ctrlbox
, "", "", "");
2200 c
= ctrl_columns(s0
, 2, 50, 50);
2201 c
->columns
.ncols
= s0
->ncolumns
= ncols
;
2202 c
->columns
.percentages
= sresize(c
->columns
.percentages
, ncols
, int);
2203 for (index
= 0; index
< ncols
; index
++)
2204 c
->columns
.percentages
[index
] = (index
+1)*100/ncols
- index
*100/ncols
;
2205 va_start(ap
, minwid
);
2208 char *title
= va_arg(ap
, char *);
2209 int shortcut
, type
, value
;
2212 shortcut
= va_arg(ap
, int);
2213 type
= va_arg(ap
, int);
2214 value
= va_arg(ap
, int);
2215 c
= ctrl_pushbutton(s0
, title
, shortcut
, HELPCTX(no_help
),
2216 messagebox_handler
, I(value
));
2217 c
->generic
.column
= index
++;
2219 c
->button
.isdefault
= TRUE
;
2221 c
->button
.iscancel
= TRUE
;
2225 s1
= ctrl_getset(ctrlbox
, "x", "", "");
2226 ctrl_text(s1
, msg
, HELPCTX(no_help
));
2228 window
= gtk_dialog_new();
2229 gtk_window_set_title(GTK_WINDOW(window
), title
);
2230 w0
= layout_ctrls(&dp
, &scs
, s0
, 0, GTK_WINDOW(window
));
2231 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->action_area
),
2233 gtk_widget_show(w0
);
2234 w1
= layout_ctrls(&dp
, &scs
, s1
, 0, GTK_WINDOW(window
));
2235 gtk_container_set_border_width(GTK_CONTAINER(w1
), 10);
2236 gtk_widget_set_usize(w1
, minwid
+20, -1);
2237 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
),
2239 gtk_widget_show(w1
);
2241 dp
.shortcuts
= &scs
;
2242 dp
.lastfocus
= NULL
;
2246 gtk_window_set_modal(GTK_WINDOW(window
), TRUE
);
2248 set_transient_window_pos(parentwin
, window
);
2249 gtk_window_set_transient_for(GTK_WINDOW(window
),
2250 GTK_WINDOW(parentwin
));
2252 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
2253 gtk_widget_show(window
);
2255 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
2256 GTK_SIGNAL_FUNC(window_destroy
), NULL
);
2257 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
2258 GTK_SIGNAL_FUNC(win_key_press
), &dp
);
2263 ctrl_free_box(ctrlbox
);
2268 static int string_width(char *text
)
2270 GtkWidget
*label
= gtk_label_new(text
);
2272 gtk_widget_size_request(label
, &req
);
2273 gtk_widget_unref(label
);
2277 int reallyclose(void *frontend
)
2279 char *title
= dupcat(appname
, " Exit Confirmation", NULL
);
2280 int ret
= messagebox(GTK_WIDGET(get_window(frontend
)),
2281 title
, "Are you sure you want to close this session?",
2282 string_width("Most of the width of the above text"),
2290 void verify_ssh_host_key(void *frontend
, char *host
, int port
, char *keytype
,
2291 char *keystr
, char *fingerprint
)
2293 static const char absenttxt
[] =
2294 "The server's host key is not cached. You have no guarantee "
2295 "that the server is the computer you think it is.\n"
2296 "The server's key fingerprint is:\n"
2298 "If you trust this host, press \"Accept\" to add the key to "
2299 "PuTTY's cache and carry on connecting.\n"
2300 "If you want to carry on connecting just once, without "
2301 "adding the key to the cache, press \"Connect Once\".\n"
2302 "If you do not trust this host, press \"Cancel\" to abandon the "
2304 static const char wrongtxt
[] =
2305 "WARNING - POTENTIAL SECURITY BREACH!\n"
2306 "The server's host key does not match the one PuTTY has "
2307 "cached. This means that either the server administrator "
2308 "has changed the host key, or you have actually connected "
2309 "to another computer pretending to be the server.\n"
2310 "The new key fingerprint is:\n"
2312 "If you were expecting this change and trust the new key, "
2313 "press \"Accept\" to update PuTTY's cache and continue connecting.\n"
2314 "If you want to carry on connecting but without updating "
2315 "the cache, press \"Connect Once\".\n"
2316 "If you want to abandon the connection completely, press "
2317 "\"Cancel\" to cancel. Pressing \"Cancel\" is the ONLY guaranteed "
2325 ret
= verify_host_key(host
, port
, keytype
, keystr
);
2327 if (ret
== 0) /* success - key matched OK */
2330 text
= dupprintf((ret
== 2 ? wrongtxt
: absenttxt
), fingerprint
);
2332 ret
= messagebox(GTK_WIDGET(get_window(frontend
)),
2333 "PuTTY Security Alert", text
,
2334 string_width(fingerprint
),
2335 "Accept", 'a', 0, 2,
2336 "Connect Once", 'o', 0, 1,
2337 "Cancel", 'c', -1, 0,
2345 store_host_key(host
, port
, keytype
, keystr
);
2349 * Ask whether the selected cipher is acceptable (since it was
2350 * below the configured 'warn' threshold).
2351 * cs: 0 = both ways, 1 = client->server, 2 = server->client
2353 void askcipher(void *frontend
, char *ciphername
, int cs
)
2355 static const char msg
[] =
2356 "The first %scipher supported by the server is "
2357 "%s, which is below the configured warning threshold.\n"
2358 "Continue with connection?";
2362 text
= dupprintf(msg
, (cs
== 0) ?
"" :
2363 (cs
== 1) ?
"client-to-server " : "server-to-client ",
2365 ret
= messagebox(GTK_WIDGET(get_window(frontend
)),
2366 "PuTTY Security Alert", text
,
2367 string_width("Continue with connection?"),
2380 void old_keyfile_warning(void)
2383 * This should never happen on Unix. We hope.
2387 void fatal_message_box(void *window
, char *msg
)
2389 messagebox(window
, "PuTTY Fatal Error", msg
,
2390 string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
2391 "OK", 'o', 1, 1, NULL
);
2394 void fatalbox(char *p
, ...)
2399 msg
= dupvprintf(p
, ap
);
2401 fatal_message_box(NULL
, msg
);
2406 static GtkWidget
*aboutbox
= NULL
;
2408 static void about_close_clicked(GtkButton
*button
, gpointer data
)
2410 gtk_widget_destroy(aboutbox
);
2414 static void licence_clicked(GtkButton
*button
, gpointer data
)
2419 "Copyright 1997-2003 Simon Tatham.\n\n"
2421 "Portions copyright Robert de Bath, Joris van Rantwijk, Delian "
2422 "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas "
2423 "Barry, Justin Bradford, Ben Harris, and CORE SDI S.A.\n\n"
2425 "Permission is hereby granted, free of charge, to any person "
2426 "obtaining a copy of this software and associated documentation "
2427 "files (the ""Software""), to deal in the Software without restriction, "
2428 "including without limitation the rights to use, copy, modify, merge, "
2429 "publish, distribute, sublicense, and/or sell copies of the Software, "
2430 "and to permit persons to whom the Software is furnished to do so, "
2431 "subject to the following conditions:\n\n"
2433 "The above copyright notice and this permission notice shall be "
2434 "included in all copies or substantial portions of the Software.\n\n"
2436 "THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT "
2437 "WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, "
2438 "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF "
2439 "MERCHANTABILITY, FITNESS FOR A PARTICULAR "
2440 "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
2441 "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES "
2442 "OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, "
2443 "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN "
2444 "CONNECTION WITH THE SOFTWARE OR THE USE OR "
2445 "OTHER DEALINGS IN THE SOFTWARE.";
2447 title
= dupcat(appname
, " Licence", NULL
);
2448 assert(aboutbox
!= NULL
);
2449 messagebox(aboutbox
, title
, licence
,
2450 string_width("LONGISH LINE OF TEXT SO THE LICENCE"
2451 " BOX ISN'T EXCESSIVELY TALL AND THIN"),
2452 "OK", 'o', 1, 1, NULL
);
2456 void about_box(void *window
)
2462 gtk_widget_grab_focus(aboutbox
);
2466 aboutbox
= gtk_dialog_new();
2467 gtk_container_set_border_width(GTK_CONTAINER(aboutbox
), 10);
2468 title
= dupcat("About ", appname
, NULL
);
2469 gtk_window_set_title(GTK_WINDOW(aboutbox
), title
);
2472 w
= gtk_button_new_with_label("Close");
2473 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
2474 gtk_window_set_default(GTK_WINDOW(aboutbox
), w
);
2475 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(aboutbox
)->action_area
),
2476 w
, FALSE
, FALSE
, 0);
2477 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
2478 GTK_SIGNAL_FUNC(about_close_clicked
), NULL
);
2481 w
= gtk_button_new_with_label("View Licence");
2482 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
2483 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(aboutbox
)->action_area
),
2484 w
, FALSE
, FALSE
, 0);
2485 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
2486 GTK_SIGNAL_FUNC(licence_clicked
), NULL
);
2489 w
= gtk_label_new(appname
);
2490 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox
)->vbox
),
2491 w
, FALSE
, FALSE
, 0);
2494 w
= gtk_label_new(ver
);
2495 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox
)->vbox
),
2496 w
, FALSE
, FALSE
, 5);
2499 w
= gtk_label_new("Copyright 1997-2003 Simon Tatham. All rights reserved");
2500 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox
)->vbox
),
2501 w
, FALSE
, FALSE
, 5);
2504 set_transient_window_pos(GTK_WIDGET(window
), aboutbox
);
2505 gtk_widget_show(aboutbox
);
2508 struct eventlog_stuff
{
2509 GtkWidget
*parentwin
, *window
;
2510 struct controlbox
*eventbox
;
2511 struct Shortcuts scs
;
2513 union control
*listctrl
;
2515 int nevents
, negsize
;
2518 int ignore_selchange
;
2521 static void eventlog_destroy(GtkWidget
*widget
, gpointer data
)
2523 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)data
;
2527 dlg_cleanup(&es
->dp
);
2528 ctrl_free_box(es
->eventbox
);
2530 static void eventlog_ok_handler(union control
*ctrl
, void *dlg
,
2531 void *data
, int event
)
2533 if (event
== EVENT_ACTION
)
2536 static void eventlog_list_handler(union control
*ctrl
, void *dlg
,
2537 void *data
, int event
)
2539 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)data
;
2541 if (event
== EVENT_REFRESH
) {
2544 dlg_update_start(ctrl
, dlg
);
2545 dlg_listbox_clear(ctrl
, dlg
);
2546 for (i
= 0; i
< es
->nevents
; i
++) {
2547 dlg_listbox_add(ctrl
, dlg
, es
->events
[i
]);
2549 dlg_update_done(ctrl
, dlg
);
2550 } else if (event
== EVENT_SELCHANGE
) {
2555 * If this SELCHANGE event is happening as a result of
2556 * deliberate deselection because someone else has grabbed
2557 * the selection, the last thing we want to do is pre-empt
2560 if (es
->ignore_selchange
)
2564 * Construct the data to use as the selection.
2569 for (i
= 0; i
< es
->nevents
; i
++) {
2570 if (dlg_listbox_issel(ctrl
, dlg
, i
)) {
2571 int extralen
= strlen(es
->events
[i
]);
2573 if (es
->sellen
+ extralen
+ 2 > selsize
) {
2574 selsize
= es
->sellen
+ extralen
+ 512;
2575 es
->seldata
= sresize(es
->seldata
, selsize
, char);
2578 strcpy(es
->seldata
+ es
->sellen
, es
->events
[i
]);
2579 es
->sellen
+= extralen
;
2580 es
->seldata
[es
->sellen
++] = '\n';
2584 if (gtk_selection_owner_set(es
->window
, GDK_SELECTION_PRIMARY
,
2585 GDK_CURRENT_TIME
)) {
2586 extern GdkAtom compound_text_atom
;
2588 gtk_selection_add_target(es
->window
, GDK_SELECTION_PRIMARY
,
2589 GDK_SELECTION_TYPE_STRING
, 1);
2590 gtk_selection_add_target(es
->window
, GDK_SELECTION_PRIMARY
,
2591 compound_text_atom
, 1);
2597 void eventlog_selection_get(GtkWidget
*widget
, GtkSelectionData
*seldata
,
2598 guint info
, guint time_stamp
, gpointer data
)
2600 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)data
;
2602 gtk_selection_data_set(seldata
, seldata
->target
, 8,
2603 es
->seldata
, es
->sellen
);
2606 gint
eventlog_selection_clear(GtkWidget
*widget
, GdkEventSelection
*seldata
,
2609 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)data
;
2613 * Deselect everything in the list box.
2615 uc
= dlg_find_byctrl(&es
->dp
, es
->listctrl
);
2616 es
->ignore_selchange
= 1;
2617 gtk_list_unselect_all(GTK_LIST(uc
->list
));
2618 es
->ignore_selchange
= 0;
2626 void showeventlog(void *estuff
, void *parentwin
)
2628 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)estuff
;
2629 GtkWidget
*window
, *w0
, *w1
;
2630 GtkWidget
*parent
= GTK_WIDGET(parentwin
);
2631 struct controlset
*s0
, *s1
;
2633 int listitemheight
, index
;
2637 gtk_widget_grab_focus(es
->window
);
2643 for (index
= 0; index
< lenof(es
->scs
.sc
); index
++) {
2644 es
->scs
.sc
[index
].action
= SHORTCUT_EMPTY
;
2647 es
->eventbox
= ctrl_new_box();
2649 s0
= ctrl_getset(es
->eventbox
, "", "", "");
2650 ctrl_columns(s0
, 3, 33, 34, 33);
2651 c
= ctrl_pushbutton(s0
, "Close", 'c', HELPCTX(no_help
),
2652 eventlog_ok_handler
, P(NULL
));
2653 c
->button
.column
= 1;
2654 c
->button
.isdefault
= TRUE
;
2656 s1
= ctrl_getset(es
->eventbox
, "x", "", "");
2657 es
->listctrl
= c
= ctrl_listbox(s1
, NULL
, NO_SHORTCUT
, HELPCTX(no_help
),
2658 eventlog_list_handler
, P(es
));
2659 c
->listbox
.height
= 10;
2660 c
->listbox
.multisel
= 2;
2661 c
->listbox
.ncols
= 3;
2662 c
->listbox
.percentages
= snewn(3, int);
2663 c
->listbox
.percentages
[0] = 25;
2664 c
->listbox
.percentages
[1] = 10;
2665 c
->listbox
.percentages
[2] = 65;
2667 listitemheight
= get_listitemheight();
2669 es
->window
= window
= gtk_dialog_new();
2670 title
= dupcat(appname
, " Event Log", NULL
);
2671 gtk_window_set_title(GTK_WINDOW(window
), title
);
2673 w0
= layout_ctrls(&es
->dp
, &es
->scs
, s0
,
2674 listitemheight
, GTK_WINDOW(window
));
2675 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->action_area
),
2677 gtk_widget_show(w0
);
2678 w1
= layout_ctrls(&es
->dp
, &es
->scs
, s1
,
2679 listitemheight
, GTK_WINDOW(window
));
2680 gtk_container_set_border_width(GTK_CONTAINER(w1
), 10);
2681 gtk_widget_set_usize(w1
, 20 +
2682 string_width("LINE OF TEXT GIVING WIDTH OF EVENT LOG"
2683 " IS QUITE LONG 'COS SSH LOG ENTRIES"
2685 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
),
2687 gtk_widget_show(w1
);
2690 es
->dp
.shortcuts
= &es
->scs
;
2691 es
->dp
.lastfocus
= NULL
;
2693 es
->dp
.window
= window
;
2695 dlg_refresh(NULL
, &es
->dp
);
2698 set_transient_window_pos(parent
, window
);
2699 gtk_window_set_transient_for(GTK_WINDOW(window
),
2700 GTK_WINDOW(parent
));
2702 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
2703 gtk_widget_show(window
);
2705 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
2706 GTK_SIGNAL_FUNC(eventlog_destroy
), es
);
2707 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
2708 GTK_SIGNAL_FUNC(win_key_press
), &es
->dp
);
2709 gtk_signal_connect(GTK_OBJECT(window
), "selection_get",
2710 GTK_SIGNAL_FUNC(eventlog_selection_get
), es
);
2711 gtk_signal_connect(GTK_OBJECT(window
), "selection_clear_event",
2712 GTK_SIGNAL_FUNC(eventlog_selection_clear
), es
);
2715 void *eventlogstuff_new(void)
2717 struct eventlog_stuff
*es
;
2718 es
= snew(struct eventlog_stuff
);
2719 memset(es
, 0, sizeof(*es
));
2723 void logevent_dlg(void *estuff
, char *string
)
2725 struct eventlog_stuff
*es
= (struct eventlog_stuff
*)estuff
;
2730 if (es
->nevents
>= es
->negsize
) {
2732 es
->events
= sresize(es
->events
, es
->negsize
, char *);
2736 strftime(timebuf
, sizeof(timebuf
), "%Y-%m-%d %H:%M:%S\t",
2739 es
->events
[es
->nevents
] = snewn(strlen(timebuf
) + strlen(string
) + 1, char);
2740 strcpy(es
->events
[es
->nevents
], timebuf
);
2741 strcat(es
->events
[es
->nevents
], string
);
2743 dlg_listbox_add(es
->listctrl
, &es
->dp
, es
->events
[es
->nevents
]);
2748 int askappend(void *frontend
, Filename filename
)
2750 static const char msgtemplate
[] =
2751 "The session log file \"%.*s\" already exists. "
2752 "You can overwrite it with a new session log, "
2753 "append your session log to the end of it, "
2754 "or disable session logging for this session.";
2759 message
= dupprintf(msgtemplate
, FILENAME_MAX
, filename
.path
);
2760 mbtitle
= dupprintf("%s Log to File", appname
);
2762 mbret
= messagebox(get_window(frontend
), mbtitle
, message
,
2763 string_width("LINE OF TEXT SUITABLE FOR THE"
2764 " ASKAPPEND WIDTH"),
2765 "Overwrite", 'o', 1, 2,
2766 "Append", 'a', 0, 1,
2767 "Disable", 'd', -1, 0,