+ break;
+ case CTRL_LISTBOX:
+
+#if GTK_CHECK_VERSION(2,0,0)
+ /*
+ * First construct the list data store, with the right
+ * number of columns.
+ */
+# if !GTK_CHECK_VERSION(2,4,0)
+ /* (For GTK 2.0 to 2.3, we do this for full listboxes only,
+ * because combo boxes are still done the old GTK1 way.) */
+ if (ctrl->listbox.height > 0)
+# endif
+ {
+ GType *types;
+ int i;
+ int cols;
+
+ cols = ctrl->listbox.ncols;
+ cols = cols ? cols : 1;
+ types = snewn(1 + cols, GType);
+
+ types[0] = G_TYPE_INT;
+ for (i = 0; i < cols; i++)
+ types[i+1] = G_TYPE_STRING;
+
+ uc->listmodel = gtk_list_store_newv(1 + cols, types);
+
+ sfree(types);
+ }
+#endif
+
+ /*
+ * See if it's a drop-down list (non-editable combo
+ * box).
+ */
+ if (ctrl->listbox.height == 0) {
+#if !GTK_CHECK_VERSION(2,4,0)
+ /*
+ * GTK1 and early-GTK2 option-menu style of
+ * drop-down list.
+ */
+ uc->optmenu = w = gtk_option_menu_new();
+ uc->menu = gtk_menu_new();
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(w), uc->menu);
+ gtk_object_set_data(GTK_OBJECT(uc->menu), "user-data",
+ (gpointer)uc->optmenu);
+ gtk_signal_connect(GTK_OBJECT(uc->optmenu), "focus_in_event",
+ GTK_SIGNAL_FUNC(widget_focus), dp);
+#else
+ /*
+ * Late-GTK2 style using a GtkComboBox.
+ */
+ GtkCellRenderer *cr;
+
+ /*
+ * Create a non-editable GtkComboBox (that is, not
+ * its subclass GtkComboBoxEntry).
+ */
+ w = gtk_combo_box_new_with_model
+ (GTK_TREE_MODEL(uc->listmodel));
+ uc->combo = w;
+
+ /*
+ * Tell it how to render a list item (i.e. which
+ * column to look at in the list model).
+ */
+ cr = gtk_cell_renderer_text_new();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), cr, TRUE);
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(w), cr,
+ "text", 1, NULL);
+
+ /*
+ * And tell it to notify us when the selection
+ * changes.
+ */
+ g_signal_connect(G_OBJECT(w), "changed",
+ G_CALLBACK(droplist_selchange), dp);
+#endif
+ } else {
+#if !GTK_CHECK_VERSION(2,0,0)
+ /*
+ * GTK1-style full list box.
+ */
+ uc->list = gtk_list_new();
+ if (ctrl->listbox.multisel == 2) {
+ gtk_list_set_selection_mode(GTK_LIST(uc->list),
+ GTK_SELECTION_EXTENDED);
+ } else if (ctrl->listbox.multisel == 1) {
+ gtk_list_set_selection_mode(GTK_LIST(uc->list),
+ GTK_SELECTION_MULTIPLE);
+ } else {
+ gtk_list_set_selection_mode(GTK_LIST(uc->list),
+ GTK_SELECTION_SINGLE);
+ }
+ w = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(w),
+ uc->list);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w),
+ GTK_POLICY_NEVER,
+ GTK_POLICY_AUTOMATIC);
+ uc->adj = gtk_scrolled_window_get_vadjustment
+ (GTK_SCROLLED_WINDOW(w));
+
+ gtk_widget_show(uc->list);
+ gtk_signal_connect(GTK_OBJECT(uc->list), "selection-changed",
+ GTK_SIGNAL_FUNC(list_selchange), dp);
+ gtk_signal_connect(GTK_OBJECT(uc->list), "focus_in_event",
+ GTK_SIGNAL_FUNC(widget_focus), dp);
+
+ /*
+ * Adjust the height of the scrolled window to the
+ * minimum given by the height parameter.
+ *
+ * This piece of guesswork is a horrid hack based
+ * on looking inside the GTK 1.2 sources
+ * (specifically gtkviewport.c, which appears to be
+ * the widget which provides the border around the
+ * scrolling area). Anyone lets me know how I can
+ * do this in a way which isn't at risk from GTK
+ * upgrades, I'd be grateful.
+ */
+ {
+ int edge;
+ edge = GTK_WIDGET(uc->list)->style->klass->ythickness;
+ gtk_widget_set_usize(w, 10,
+ 2*edge + (ctrl->listbox.height *
+ get_listitemheight(w)));
+ }
+
+ if (ctrl->listbox.draglist) {
+ /*
+ * GTK doesn't appear to make it easy to
+ * implement a proper draggable list; so
+ * instead I'm just going to have to put an Up
+ * and a Down button to the right of the actual
+ * list box. Ah well.
+ */
+ GtkWidget *cols, *button;
+ static const gint percentages[2] = { 80, 20 };
+
+ cols = columns_new(4);
+ columns_set_cols(COLUMNS(cols), 2, percentages);
+ columns_add(COLUMNS(cols), w, 0, 1);
+ gtk_widget_show(w);
+ button = gtk_button_new_with_label("Up");
+ columns_add(COLUMNS(cols), button, 1, 1);
+ gtk_widget_show(button);
+ gtk_signal_connect(GTK_OBJECT(button), "clicked",
+ GTK_SIGNAL_FUNC(draglist_up), dp);
+ gtk_signal_connect(GTK_OBJECT(button), "focus_in_event",
+ GTK_SIGNAL_FUNC(widget_focus), dp);
+ button = gtk_button_new_with_label("Down");
+ columns_add(COLUMNS(cols), button, 1, 1);
+ gtk_widget_show(button);
+ gtk_signal_connect(GTK_OBJECT(button), "clicked",
+ GTK_SIGNAL_FUNC(draglist_down), dp);
+ gtk_signal_connect(GTK_OBJECT(button), "focus_in_event",
+ GTK_SIGNAL_FUNC(widget_focus), dp);
+
+ w = cols;
+ }
+#else
+ /*
+ * GTK2 treeview-based full list box.
+ */
+ GtkTreeSelection *sel;
+
+ /*
+ * Create the list box itself, its columns, and
+ * its containing scrolled window.
+ */
+ w = gtk_tree_view_new_with_model
+ (GTK_TREE_MODEL(uc->listmodel));
+ g_object_set_data(G_OBJECT(uc->listmodel), "user-data",
+ (gpointer)w);
+ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(w), FALSE);
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
+ gtk_tree_selection_set_mode
+ (sel, ctrl->listbox.multisel ? GTK_SELECTION_MULTIPLE :
+ GTK_SELECTION_SINGLE);
+ uc->treeview = w;
+ gtk_signal_connect(GTK_OBJECT(w), "row-activated",
+ GTK_SIGNAL_FUNC(listbox_doubleclick), dp);
+ g_signal_connect(G_OBJECT(sel), "changed",
+ G_CALLBACK(listbox_selchange), dp);
+
+ if (ctrl->listbox.draglist) {
+ gtk_tree_view_set_reorderable(GTK_TREE_VIEW(w), TRUE);
+ g_signal_connect(G_OBJECT(uc->listmodel), "row-inserted",
+ G_CALLBACK(listbox_reorder), dp);
+ }
+
+ {
+ int i;
+ int cols;
+
+ cols = ctrl->listbox.ncols;
+ cols = cols ? cols : 1;
+ for (i = 0; i < cols; i++) {
+ GtkTreeViewColumn *column;
+ /*
+ * It appears that GTK 2 doesn't leave us any
+ * particularly sensible way to honour the
+ * "percentages" specification in the ctrl
+ * structure.
+ */
+ column = gtk_tree_view_column_new_with_attributes
+ ("heading", gtk_cell_renderer_text_new(),
+ "text", i+1, (char *)NULL);
+ gtk_tree_view_column_set_sizing
+ (column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(w), column);
+ }
+ }
+
+ {
+ GtkWidget *scroll;
+
+ scroll = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_shadow_type
+ (GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN);
+ gtk_widget_show(w);
+ gtk_container_add(GTK_CONTAINER(scroll), w);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_ALWAYS);
+ gtk_widget_set_size_request
+ (scroll, -1,
+ ctrl->listbox.height * get_listitemheight(w));
+
+ w = scroll;
+ }
+#endif
+ }
+
+ if (ctrl->generic.label) {
+ GtkWidget *label, *container;
+ GtkRequisition req;
+
+ label = gtk_label_new(ctrl->generic.label);
+
+ shortcut_add(scs, label, ctrl->listbox.shortcut,
+ SHORTCUT_FOCUS, w);
+
+ container = columns_new(4);
+ if (ctrl->listbox.percentwidth == 100) {
+ columns_add(COLUMNS(container), label, 0, 1);
+ columns_force_left_align(COLUMNS(container), label);
+ columns_add(COLUMNS(container), w, 0, 1);
+ } else {
+ gint percentages[2];
+ percentages[1] = ctrl->listbox.percentwidth;
+ percentages[0] = 100 - ctrl->listbox.percentwidth;
+ columns_set_cols(COLUMNS(container), 2, percentages);
+ columns_add(COLUMNS(container), label, 0, 1);
+ columns_force_left_align(COLUMNS(container), label);
+ columns_add(COLUMNS(container), w, 1, 1);
+ /* Centre the label vertically. */
+ gtk_widget_size_request(w, &req);
+ gtk_widget_set_usize(label, -1, req.height);
+ gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+ }
+ gtk_widget_show(label);
+ gtk_widget_show(w);
+
+ w = container;
+ uc->label = label;
+ }
+
+ break;
+ case CTRL_TEXT:
+ /*
+ * Wrapping text widgets don't sit well with the GTK
+ * layout model, in which widgets state a minimum size
+ * and the whole window then adjusts to the smallest
+ * size it can sensibly take given its contents. A
+ * wrapping text widget _has_ no clear minimum size;
+ * instead it has a range of possibilities. It can be
+ * one line deep but 2000 wide, or two lines deep and
+ * 1000 pixels, or three by 867, or four by 500 and so
+ * on. It can be as short as you like provided you
+ * don't mind it being wide, or as narrow as you like
+ * provided you don't mind it being tall.
+ *
+ * Therefore, it fits very badly into the layout model.
+ * Hence the only thing to do is pick a width and let
+ * it choose its own number of lines. To do this I'm
+ * going to cheat a little. All new wrapping text
+ * widgets will be created with a minimal text content
+ * "X"; then, after the rest of the dialog box is set
+ * up and its size calculated, the text widgets will be
+ * told their width and given their real text, which
+ * will cause the size to be recomputed in the y
+ * direction (because many of them will expand to more
+ * than one line).
+ */
+ uc->text = w = gtk_label_new("X");
+ gtk_misc_set_alignment(GTK_MISC(w), 0.0, 0.0);
+ gtk_label_set_line_wrap(GTK_LABEL(w), TRUE);
+ uc->textsig =
+ gtk_signal_connect(GTK_OBJECT(w), "size-allocate",
+ GTK_SIGNAL_FUNC(label_sizealloc), dp);
+ break;
+ }
+
+ assert(w != NULL);
+
+ columns_add(cols, w,
+ COLUMN_START(ctrl->generic.column),
+ COLUMN_SPAN(ctrl->generic.column));
+ if (left)
+ columns_force_left_align(cols, w);
+ gtk_widget_show(w);
+
+ uc->toplevel = w;
+ dlg_add_uctrl(dp, uc);
+ }
+
+ return ret;
+}
+
+struct selparam {
+ struct dlgparam *dp;
+ GtkNotebook *panels;
+ GtkWidget *panel;
+#if !GTK_CHECK_VERSION(2,0,0)
+ GtkWidget *treeitem;
+#else
+ int depth;
+ GtkTreePath *treepath;
+#endif
+ struct Shortcuts shortcuts;
+};
+
+#if GTK_CHECK_VERSION(2,0,0)
+static void treeselection_changed(GtkTreeSelection *treeselection,
+ gpointer data)
+{
+ struct selparam *sps = (struct selparam *)data, *sp;
+ GtkTreeModel *treemodel;
+ GtkTreeIter treeiter;
+ gint spindex;
+ gint page_num;
+
+ if (!gtk_tree_selection_get_selected(treeselection, &treemodel, &treeiter))
+ return;
+
+ gtk_tree_model_get(treemodel, &treeiter, TREESTORE_PARAMS, &spindex, -1);
+ sp = &sps[spindex];
+
+ page_num = gtk_notebook_page_num(sp->panels, sp->panel);
+ gtk_notebook_set_page(sp->panels, page_num);
+
+ dlg_refresh(NULL, sp->dp);
+
+ sp->dp->shortcuts = &sp->shortcuts;
+}
+#else
+static void treeitem_sel(GtkItem *item, gpointer data)
+{
+ struct selparam *sp = (struct selparam *)data;
+ gint page_num;
+
+ page_num = gtk_notebook_page_num(sp->panels, sp->panel);
+ gtk_notebook_set_page(sp->panels, page_num);
+
+ dlg_refresh(NULL, sp->dp);
+
+ sp->dp->shortcuts = &sp->shortcuts;
+ sp->dp->currtreeitem = sp->treeitem;
+}
+#endif
+
+static void window_destroy(GtkWidget *widget, gpointer data)
+{
+ gtk_main_quit();
+}
+
+#if !GTK_CHECK_VERSION(2,0,0)
+static int tree_grab_focus(struct dlgparam *dp)
+{
+ int i, f;
+
+ /*
+ * See if any of the treeitems has the focus.
+ */
+ f = -1;
+ for (i = 0; i < dp->ntreeitems; i++)
+ if (GTK_WIDGET_HAS_FOCUS(dp->treeitems[i])) {
+ f = i;
+ break;
+ }
+
+ if (f >= 0)
+ return FALSE;
+ else {
+ gtk_widget_grab_focus(dp->currtreeitem);
+ return TRUE;
+ }
+}
+
+gint tree_focus(GtkContainer *container, GtkDirectionType direction,
+ gpointer data)
+{
+ struct dlgparam *dp = (struct dlgparam *)data;
+
+ gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus");
+ /*
+ * If there's a focused treeitem, we return FALSE to cause the
+ * focus to move on to some totally other control. If not, we
+ * focus the selected one.
+ */
+ return tree_grab_focus(dp);
+}
+#endif
+
+int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
+{
+ struct dlgparam *dp = (struct dlgparam *)data;