From f3860ec95ea6308ce58cd891dedac1dc8751686e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 9 Sep 2014 11:46:14 +0000 Subject: [PATCH] Add an option to suppress horizontal scroll bars in list boxes. I'm about to add a list box which expects to contain some very long but uninformative strings, and which is also quite vertically squashed so there's not much room for a horizontal scroll bar to appear in it. So here's an option in the list box specification structure which causes the constructed GTKTreeView to use the 'ellipsize' option for all its cell renderers, i.e. too-long strings are truncated with an ellipsis. Windows needs no change, because its list boxes already work this way. [originally from svn r10219] --- dialog.c | 1 + dialog.h | 6 ++++++ unix/gtkdlg.c | 11 +++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/dialog.c b/dialog.c index 84869195..cbe95124 100644 --- a/dialog.c +++ b/dialog.c @@ -364,6 +364,7 @@ union control *ctrl_listbox(struct controlset *s,char *label,char shortcut, c->listbox.percentwidth = 100; c->listbox.ncols = 0; c->listbox.percentages = NULL; + c->listbox.hscroll = TRUE; return c; } diff --git a/dialog.h b/dialog.h index 9ea8599e..6f454f56 100644 --- a/dialog.h +++ b/dialog.h @@ -345,6 +345,12 @@ union control { */ int ncols; /* number of columns */ int *percentages; /* % width of each column */ + /* + * Flag which can be set to FALSE to suppress the horizontal + * scroll bar if a list box entry goes off the right-hand + * side. + */ + int hscroll; } listbox; struct { STANDARD_PREFIX; diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 86fa310e..3776df8c 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -2276,15 +2276,22 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, cols = cols ? cols : 1; for (i = 0; i < cols; i++) { GtkTreeViewColumn *column; + GtkCellRenderer *cellrend; /* * It appears that GTK 2 doesn't leave us any * particularly sensible way to honour the * "percentages" specification in the ctrl * structure. */ + cellrend = gtk_cell_renderer_text_new(); + if (!ctrl->listbox.hscroll) { + gtk_object_set(GTK_OBJECT(cellrend), + "ellipsize", PANGO_ELLIPSIZE_END, + "ellipsize-set", TRUE, + NULL); + } column = gtk_tree_view_column_new_with_attributes - ("heading", gtk_cell_renderer_text_new(), - "text", i+1, (char *)NULL); + ("heading", cellrend, "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);