summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-12-11 11:40:17 -0800
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-12-11 11:40:17 -0800
commitf078bc04e1f55ad9ecd0632fcfa5753440ba2267 (patch)
treea54d6bd997af8ea63db58915ba41908051b5a720
parent50d026230fa7303b33821da1346875b30f5ab00d (diff)
downloadsubsurface-f078bc04e1f55ad9ecd0632fcfa5753440ba2267.tar.gz
Make the cylinder table columns unsortable
They were never intended to be sortable, but using common code with the dive list picked up that "sort by index" thing by mistake. If we really want to be able to sort cylinders by O2 percentage (which really doesn't seem to make much sense, considering that you usually have just one or two cylinders) we will need to also handle the case of editing the (differently sorted) cylinder table. Which we don't do now. Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--display-gtk.h7
-rw-r--r--divelist.c29
-rw-r--r--equipment.c14
-rw-r--r--gtk-gui.c12
4 files changed, 38 insertions, 24 deletions
diff --git a/display-gtk.h b/display-gtk.h
index 9e5093d40..d5ffcb246 100644
--- a/display-gtk.h
+++ b/display-gtk.h
@@ -57,7 +57,12 @@ typedef void (*data_func_t)(GtkTreeViewColumn *col,
GtkTreeIter *iter,
gpointer data);
+#define ALIGN_LEFT 1
+#define ALIGN_RIGHT 2
+#define INVISIBLE 4
+#define UNSORTABLE 8
+
extern GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
- data_func_t data_func, PangoAlignment align, gboolean visible);
+ data_func_t data_func, unsigned int flags);
#endif
diff --git a/divelist.c b/divelist.c
index d311aee17..36c40b8b2 100644
--- a/divelist.c
+++ b/divelist.c
@@ -537,9 +537,11 @@ void dive_list_update_dives(void)
}
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, unsigned int flags, int visible)
{
- return tree_view_column(dl->tree_view, index, title, data_func, align, visible);
+ if (!visible)
+ flags |= INVISIBLE;
+ return tree_view_column(dl->tree_view, index, title, data_func, flags);
}
/*
@@ -591,18 +593,17 @@ GtkWidget *dive_list_create(void)
gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
gtk_widget_set_size_request(dive_list.tree_view, 200, 200);
- dive_list.nr = divelist_column(&dive_list, DIVE_NR, "#", NULL, PANGO_ALIGN_RIGHT, TRUE);
- gtk_tree_view_column_set_sort_column_id(dive_list.nr, -1);
- dive_list.date = divelist_column(&dive_list, DIVE_DATE, "Date", date_data_func, PANGO_ALIGN_LEFT, TRUE);
- dive_list.stars = divelist_column(&dive_list, DIVE_RATING, UTF8_BLACKSTAR, star_data_func, PANGO_ALIGN_LEFT, TRUE);
- dive_list.depth = divelist_column(&dive_list, DIVE_DEPTH, "ft", depth_data_func, PANGO_ALIGN_RIGHT, TRUE);
- dive_list.duration = divelist_column(&dive_list, DIVE_DURATION, "min", duration_data_func, PANGO_ALIGN_RIGHT, TRUE);
- dive_list.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, PANGO_ALIGN_RIGHT, visible_cols.temperature);
- dive_list.cylinder = divelist_column(&dive_list, DIVE_CYLINDER, "Cyl", NULL, PANGO_ALIGN_CENTER, visible_cols.cylinder);
- dive_list.nitrox = divelist_column(&dive_list, DIVE_NITROX, "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, PANGO_ALIGN_CENTER, visible_cols.nitrox);
- dive_list.sac = divelist_column(&dive_list, DIVE_SAC, "SAC", sac_data_func, PANGO_ALIGN_CENTER, visible_cols.sac);
- dive_list.otu = divelist_column(&dive_list, DIVE_OTU, "OTU", otu_data_func, PANGO_ALIGN_CENTER, visible_cols.otu);
- dive_list.location = divelist_column(&dive_list, DIVE_LOCATION, "Location", NULL, PANGO_ALIGN_LEFT, TRUE);
+ dive_list.nr = divelist_column(&dive_list, DIVE_NR, "#", NULL, ALIGN_RIGHT | UNSORTABLE, TRUE);
+ dive_list.date = divelist_column(&dive_list, DIVE_DATE, "Date", date_data_func, ALIGN_LEFT, TRUE);
+ dive_list.stars = divelist_column(&dive_list, DIVE_RATING, UTF8_BLACKSTAR, star_data_func, ALIGN_LEFT, TRUE);
+ dive_list.depth = divelist_column(&dive_list, DIVE_DEPTH, "ft", depth_data_func, ALIGN_RIGHT, TRUE);
+ dive_list.duration = divelist_column(&dive_list, DIVE_DURATION, "min", duration_data_func, ALIGN_RIGHT, TRUE);
+ dive_list.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, ALIGN_RIGHT, visible_cols.temperature);
+ dive_list.cylinder = divelist_column(&dive_list, DIVE_CYLINDER, "Cyl", NULL, 0, visible_cols.cylinder);
+ dive_list.nitrox = divelist_column(&dive_list, DIVE_NITROX, "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, 0, visible_cols.nitrox);
+ dive_list.sac = divelist_column(&dive_list, DIVE_SAC, "SAC", sac_data_func, 0, visible_cols.sac);
+ dive_list.otu = divelist_column(&dive_list, DIVE_OTU, "OTU", otu_data_func, 0, visible_cols.otu);
+ dive_list.location = divelist_column(&dive_list, DIVE_LOCATION, "Location", NULL, ALIGN_LEFT, TRUE);
fill_dive_list();
diff --git a/equipment.c b/equipment.c
index 6f09602d8..9c2b4054f 100644
--- a/equipment.c
+++ b/equipment.c
@@ -897,13 +897,13 @@ GtkWidget *cylinder_list_widget(void)
"enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH,
NULL);
- tree_view_column(tree_view, CYL_DESC, "Type", NULL, PANGO_ALIGN_LEFT, TRUE);
- tree_view_column(tree_view, CYL_SIZE, "Size", size_data_func, PANGO_ALIGN_RIGHT, TRUE);
- tree_view_column(tree_view, CYL_WORKP, "MaxPress", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
- tree_view_column(tree_view, CYL_STARTP, "Start", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
- tree_view_column(tree_view, CYL_ENDP, "End", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
- tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
- tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
+ tree_view_column(tree_view, CYL_DESC, "Type", NULL, ALIGN_LEFT | UNSORTABLE);
+ tree_view_column(tree_view, CYL_SIZE, "Size", size_data_func, ALIGN_RIGHT | UNSORTABLE);
+ tree_view_column(tree_view, CYL_WORKP, "MaxPress", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
+ tree_view_column(tree_view, CYL_STARTP, "Start", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
+ tree_view_column(tree_view, CYL_ENDP, "End", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
+ tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, ALIGN_RIGHT | UNSORTABLE);
+ tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, ALIGN_RIGHT | UNSORTABLE);
return tree_view;
}
diff --git a/gtk-gui.c b/gtk-gui.c
index 6df8f419b..dce537232 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -202,17 +202,25 @@ static void quit(GtkWidget *w, gpointer data)
}
GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
- data_func_t data_func, PangoAlignment align, gboolean visible)
+ data_func_t data_func, unsigned int flags)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *col;
double xalign = 0.0; /* left as default */
+ PangoAlignment align;
+ gboolean visible;
+
+ align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT :
+ (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT :
+ PANGO_ALIGN_CENTER;
+ visible = !(flags & INVISIBLE);
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);
+ if (!(flags & UNSORTABLE))
+ 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)