+#if !GTK_CHECK_VERSION(2,0,0)
+
+/*
+ * GTK 1 list box event handlers.
+ */
+
+static gboolean listitem_key(GtkWidget *item, GdkEventKey *event,
+ gpointer data, int multiple)
+{
+ GtkAdjustment *adj = GTK_ADJUSTMENT(data);
+
+ if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up ||
+ event->keyval == GDK_Down || event->keyval == GDK_KP_Down ||
+ event->keyval == GDK_Page_Up || event->keyval == GDK_KP_Page_Up ||
+ event->keyval == GDK_Page_Down || event->keyval == GDK_KP_Page_Down) {
+ /*
+ * Up, Down, PgUp or PgDn have been pressed on a ListItem
+ * in a list box. So, if the list box is single-selection:
+ *
+ * - if the list item in question isn't already selected,
+ * we simply select it.
+ * - otherwise, we find the next one (or next
+ * however-far-away) in whichever direction we're going,
+ * and select that.
+ * + in this case, we must also fiddle with the
+ * scrollbar to ensure the newly selected item is
+ * actually visible.
+ *
+ * If it's multiple-selection, we do all of the above
+ * except actually selecting anything, so we move the focus
+ * and fiddle the scrollbar to follow it.
+ */
+ GtkWidget *list = item->parent;
+
+ g_signal_stop_emission_by_name(G_OBJECT(item), "key_press_event");
+
+ if (!multiple &&
+ GTK_WIDGET_STATE(item) != GTK_STATE_SELECTED) {
+ gtk_list_select_child(GTK_LIST(list), item);
+ } else {
+ int direction =
+ (event->keyval==GDK_Up || event->keyval==GDK_KP_Up ||
+ event->keyval==GDK_Page_Up || event->keyval==GDK_KP_Page_Up)
+ ? -1 : +1;
+ int step =
+ (event->keyval==GDK_Page_Down ||
+ event->keyval==GDK_KP_Page_Down ||
+ event->keyval==GDK_Page_Up || event->keyval==GDK_KP_Page_Up)
+ ? 2 : 1;
+ int i, n;
+ GList *children, *chead;
+
+ chead = children = gtk_container_children(GTK_CONTAINER(list));
+
+ n = g_list_length(children);
+
+ if (step == 2) {
+ /*
+ * Figure out how many list items to a screenful,
+ * and adjust the step appropriately.
+ */
+ step = 0.5 + adj->page_size * n / (adj->upper - adj->lower);
+ step--; /* go by one less than that */
+ }
+
+ i = 0;
+ while (children != NULL) {
+ if (item == children->data)
+ break;
+ children = children->next;
+ i++;
+ }
+
+ while (step > 0) {
+ if (direction < 0 && i > 0)
+ children = children->prev, i--;
+ else if (direction > 0 && i < n-1)
+ children = children->next, i++;
+ step--;
+ }
+
+ if (children && children->data) {
+ if (!multiple)
+ gtk_list_select_child(GTK_LIST(list),
+ GTK_WIDGET(children->data));
+ gtk_widget_grab_focus(GTK_WIDGET(children->data));
+ gtk_adjustment_clamp_page
+ (adj,
+ adj->lower + (adj->upper-adj->lower) * i / n,
+ adj->lower + (adj->upper-adj->lower) * (i+1) / n);
+ }
+
+ g_list_free(chead);
+ }
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean listitem_single_key(GtkWidget *item, GdkEventKey *event,
+ gpointer data)
+{
+ return listitem_key(item, event, data, FALSE);
+}
+
+static gboolean listitem_multi_key(GtkWidget *item, GdkEventKey *event,
+ gpointer data)
+{
+ return listitem_key(item, event, data, TRUE);
+}
+
+static gboolean listitem_button_press(GtkWidget *item, GdkEventButton *event,
+ gpointer data)
+{
+ struct dlgparam *dp = (struct dlgparam *)data;
+ struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(item));
+ switch (event->type) {
+ default:
+ case GDK_BUTTON_PRESS: uc->nclicks = 1; break;
+ case GDK_2BUTTON_PRESS: uc->nclicks = 2; break;
+ case GDK_3BUTTON_PRESS: uc->nclicks = 3; break;
+ }
+ return FALSE;
+}
+
+static gboolean listitem_button_release(GtkWidget *item, GdkEventButton *event,
+ gpointer data)
+{
+ struct dlgparam *dp = (struct dlgparam *)data;
+ struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(item));
+ if (uc->nclicks>1) {
+ uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_ACTION);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void list_selchange(GtkList *list, gpointer data)
+{
+ struct dlgparam *dp = (struct dlgparam *)data;
+ struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(list));
+ if (!uc) return;
+ uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_SELCHANGE);
+}
+
+static void draglist_move(struct dlgparam *dp, struct uctrl *uc, int direction)
+{
+ int index = dlg_listbox_index(uc->ctrl, dp);
+ GList *children = gtk_container_children(GTK_CONTAINER(uc->list));
+ GtkWidget *child;
+
+ if ((index < 0) ||
+ (index == 0 && direction < 0) ||
+ (index == g_list_length(children)-1 && direction > 0)) {
+ gdk_beep();
+ return;
+ }
+
+ child = g_list_nth_data(children, index);
+ gtk_widget_ref(child);
+ gtk_list_clear_items(GTK_LIST(uc->list), index, index+1);
+ g_list_free(children);
+
+ children = NULL;
+ children = g_list_append(children, child);
+ gtk_list_insert_items(GTK_LIST(uc->list), children, index + direction);
+ gtk_list_select_item(GTK_LIST(uc->list), index + direction);
+ uc->ctrl->generic.handler(uc->ctrl, dp, dp->data, EVENT_VALCHANGE);
+}
+
+static void draglist_up(GtkButton *button, gpointer data)
+{
+ struct dlgparam *dp = (struct dlgparam *)data;
+ struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(button));
+ draglist_move(dp, uc, -1);
+}
+
+static void draglist_down(GtkButton *button, gpointer data)
+{
+ struct dlgparam *dp = (struct dlgparam *)data;
+ struct uctrl *uc = dlg_find_bywidget(dp, GTK_WIDGET(button));
+ draglist_move(dp, uc, +1);
+}
+
+#else /* !GTK_CHECK_VERSION(2,0,0) */
+
+/*
+ * GTK 2 list box event handlers.
+ */
+