+static struct divelist_column {
+ const char *header;
+ data_func_t data;
+ sort_func_t sort;
+ unsigned int flags;
+ int *visible;
+} dl_column[] = {
+ [DIVE_NR] = { "#", nr_data_func, NULL, ALIGN_RIGHT | UNSORTABLE },
+ [DIVE_DATE] = { "Date", date_data_func, NULL, ALIGN_LEFT },
+ [DIVE_RATING] = { UTF8_BLACKSTAR, star_data_func, NULL, ALIGN_LEFT },
+ [DIVE_DEPTH] = { "ft", depth_data_func, NULL, ALIGN_RIGHT },
+ [DIVE_DURATION] = { "min", duration_data_func, NULL, ALIGN_RIGHT },
+ [DIVE_TEMPERATURE] = { UTF8_DEGREE "F", temperature_data_func, NULL, ALIGN_RIGHT, &visible_cols.temperature },
+ [DIVE_TOTALWEIGHT] = { "lbs", weight_data_func, NULL, ALIGN_RIGHT, &visible_cols.totalweight },
+ [DIVE_SUIT] = { "Suit", NULL, NULL, ALIGN_LEFT, &visible_cols.suit },
+ [DIVE_CYLINDER] = { "Cyl", NULL, NULL, 0, &visible_cols.cylinder },
+ [DIVE_NITROX] = { "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, nitrox_sort_func, 0, &visible_cols.nitrox },
+ [DIVE_SAC] = { "SAC", sac_data_func, NULL, 0, &visible_cols.sac },
+ [DIVE_OTU] = { "OTU", otu_data_func, NULL, 0, &visible_cols.otu },
+ [DIVE_LOCATION] = { "Location", NULL, NULL, ALIGN_LEFT },
+};
+
+
+static GtkTreeViewColumn *divelist_column(struct DiveList *dl, struct divelist_column *col)
+{
+ int index = col - &dl_column[0];
+ const char *title = col->header;
+ data_func_t data_func = col->data;
+ sort_func_t sort_func = col->sort;
+ unsigned int flags = col->flags;
+ int *visible = col->visible;
+ GtkWidget *tree_view = dl->tree_view;
+ GtkTreeStore *treemodel = dl->treemodel;
+ GtkTreeStore *listmodel = dl->listmodel;
+ GtkTreeViewColumn *ret;
+
+ if (visible && !*visible)
+ flags |= INVISIBLE;
+ ret = tree_view_column(tree_view, index, title, data_func, flags);
+ if (sort_func) {
+ /* the sort functions are needed in the corresponding models */
+ if (index == DIVE_DATE)
+ gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(treemodel), index, sort_func, NULL, NULL);
+ else
+ gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(listmodel), index, sort_func, NULL, NULL);
+ }
+ return ret;
+}
+
+/*
+ * This is some crazy crap. The only way to get default focus seems
+ * to be to grab focus as the widget is being shown the first time.
+ */
+static void realize_cb(GtkWidget *tree_view, gpointer userdata)
+{
+ gtk_widget_grab_focus(tree_view);
+}
+
+/*
+ * Double-clicking on a group entry will expand a collapsed group
+ * and vice versa.
+ */
+static void collapse_expand(GtkTreeView *tree_view, GtkTreePath *path)
+{
+ if (!gtk_tree_view_row_expanded(tree_view, path))
+ gtk_tree_view_expand_row(tree_view, path, FALSE);
+ else
+ gtk_tree_view_collapse_row(tree_view, path);
+
+}
+
+/* Double-click on a dive list */
+static void row_activated_cb(GtkTreeView *tree_view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer userdata)
+{
+ int index;
+ GtkTreeIter iter;
+
+ if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(dive_list.model), &iter, path))
+ return;
+
+ gtk_tree_model_get(GTK_TREE_MODEL(dive_list.model), &iter, DIVE_INDEX, &index, -1);
+ /* a negative index is special for the "group by date" entries */
+ if (index < 0) {
+ collapse_expand(tree_view, path);
+ return;
+ }
+ edit_dive_info(get_dive(index));
+}
+
+void add_dive_cb(GtkWidget *menuitem, gpointer data)
+{
+ struct dive *dive;
+
+ dive = alloc_dive();
+ if (add_new_dive(dive)) {
+ record_dive(dive);
+ report_dives(TRUE);
+ return;
+ }
+ free(dive);
+}
+
+void edit_dive_cb(GtkWidget *menuitem, gpointer data)
+{
+ edit_multi_dive_info(NULL);
+}
+
+static void expand_all_cb(GtkWidget *menuitem, GtkTreeView *tree_view)
+{
+ gtk_tree_view_expand_all(tree_view);
+}
+
+static void collapse_all_cb(GtkWidget *menuitem, GtkTreeView *tree_view)
+{
+ gtk_tree_view_collapse_all(tree_view);
+}