]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Split up generic code to generate a gtk tree view column
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 2 Oct 2011 20:05:12 +0000 (13:05 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 2 Oct 2011 20:05:12 +0000 (13:05 -0700)
We used to do this just for the dive list, but the new cylinder view
will want to do a lot of the same boilerplate gtk stuff, so make it a
bit more generic and move it to gtk-gui.c.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
display-gtk.h
divelist.c
gtk-gui.c

index ad437465cee2ba136af0d60ef4be8f2f22c734a6..fe373a14fc3ab9eb1349ee14080fdd36a4d79eec 100644 (file)
@@ -33,4 +33,13 @@ extern GtkWidget *equipment_widget(void);
 
 extern GtkWidget *dive_list_create(void);
 
+typedef void (*data_func_t)(GtkTreeViewColumn *col,
+                           GtkCellRenderer *renderer,
+                           GtkTreeModel *model,
+                           GtkTreeIter *iter,
+                           gpointer data);
+
+extern GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
+               data_func_t data_func, PangoAlignment align, gboolean visible);
+
 #endif
index b43adfd0cd4728e6b50fefdcf6e46611ae10b015..1cc76b38aae6617e0cc1bdc646f1927abb82a882 100644 (file)
@@ -424,9 +424,9 @@ void update_dive_list_units(void)
 
 void update_dive_list_col_visibility(void)
 {
-               gtk_tree_view_column_set_visible(dive_list.sac, visible_cols.sac);
-               gtk_tree_view_column_set_visible(dive_list.otu, visible_cols.otu);
-               return;
+       gtk_tree_view_column_set_visible(dive_list.sac, visible_cols.sac);
+       gtk_tree_view_column_set_visible(dive_list.otu, visible_cols.otu);
+       return;
 }
 
 static void fill_dive_list(void)
@@ -469,46 +469,10 @@ void dive_list_update_dives(void)
        repaint_dive();
 }
 
-typedef void (*data_func_t)(GtkTreeViewColumn *col,
-                           GtkCellRenderer *renderer,
-                           GtkTreeModel *model,
-                           GtkTreeIter *iter,
-                           gpointer data);
-
 static GtkTreeViewColumn *divelist_column(struct DiveList *dl, int index, const char *title,
-                                       data_func_t data_func, PangoAlignment align, gboolean visible)
+                               data_func_t data_func, PangoAlignment align, gboolean visible)
 {
-       GtkCellRenderer *renderer;
-       GtkTreeViewColumn *col;
-       double xalign = 0.0; /* left as default */
-
-       renderer = gtk_cell_renderer_text_new();
-       col = gtk_tree_view_column_new();
-
-       gtk_tree_view_column_set_title(col, title);
-       gtk_tree_view_column_set_sort_column_id(col, index);
-       gtk_tree_view_column_set_resizable(col, TRUE);
-       gtk_tree_view_column_pack_start(col, renderer, TRUE);
-       if (data_func)
-               gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, NULL, NULL);
-       else
-               gtk_tree_view_column_add_attribute(col, renderer, "text", index);
-       gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
-       switch (align) {
-       case PANGO_ALIGN_LEFT:
-               xalign = 0.0;
-               break;
-       case PANGO_ALIGN_CENTER:
-               xalign = 0.5;
-               break;
-       case PANGO_ALIGN_RIGHT:
-               xalign = 1.0;
-               break;
-       }
-       gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
-       gtk_tree_view_column_set_visible(col, visible);
-       gtk_tree_view_append_column(GTK_TREE_VIEW(dl->tree_view), col);
-       return col;
+       return tree_view_column(dl->tree_view, index, title, data_func, align, visible);
 }
 
 /*
index 87cd8bf87de49c2eec6377d4c2841b84e150be5e..8ae67ecaa6bcf3ad445b2a52be889a9dfd7716a3 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -203,6 +203,42 @@ static void quit(GtkWidget *w, gpointer data)
        gtk_main_quit();
 }
 
+GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
+                               data_func_t data_func, PangoAlignment align, gboolean visible)
+{
+       GtkCellRenderer *renderer;
+       GtkTreeViewColumn *col;
+       double xalign = 0.0; /* left as default */
+
+       renderer = gtk_cell_renderer_text_new();
+       col = gtk_tree_view_column_new();
+
+       gtk_tree_view_column_set_title(col, title);
+       gtk_tree_view_column_set_sort_column_id(col, index);
+       gtk_tree_view_column_set_resizable(col, TRUE);
+       gtk_tree_view_column_pack_start(col, renderer, TRUE);
+       if (data_func)
+               gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, (void *)(long)index, NULL);
+       else
+               gtk_tree_view_column_add_attribute(col, renderer, "text", index);
+       gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
+       switch (align) {
+       case PANGO_ALIGN_LEFT:
+               xalign = 0.0;
+               break;
+       case PANGO_ALIGN_CENTER:
+               xalign = 0.5;
+               break;
+       case PANGO_ALIGN_RIGHT:
+               xalign = 1.0;
+               break;
+       }
+       gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
+       gtk_tree_view_column_set_visible(col, visible);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+       return col;
+}
+
 static void create_radio(GtkWidget *vbox, const char *name, ...)
 {
        va_list args;