GnuCash  4.11-137-g155922540d+
tree-view-utils.c
Go to the documentation of this file.
1 /*
2  * tree-view-utils.c -- some convenience functions for use with
3  * plain GtkTreeViews in situations where a
4  * fully fledged GncTreeView is overkill.
5  * Handy with GtkTreeViews defined in glade files.
6  *
7  * Copyright (C) 2013 Geert Janssens <geert@kobaltwit.be>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, contact:
21  *
22  * Free Software Foundation Voice: +1-617-542-5942
23  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
24  * Boston, MA 02110-1301, USA gnu@gnu.org
25  */
26 
36 #include <config.h>
37 
38 #include <gtk/gtk.h>
39 #include <string.h>
40 
41 #include "tree-view-utils.h"
42 
43 void tree_view_column_set_default_width (GtkTreeView *view,
44  GtkTreeViewColumn *column,
45  const gchar *sizing_text)
46 {
47  PangoLayout* layout;
48  int default_width, title_width;
49  const gchar *column_title;
50 
51  /* Default size is the larger of the column title and the sizing text */
52  column_title = gtk_tree_view_column_get_title (column);
53  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
54  pango_layout_get_pixel_size(layout, &title_width, NULL);
55  g_object_unref(layout);
56  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
57  pango_layout_get_pixel_size(layout, &default_width, NULL);
58  g_object_unref(layout);
59  default_width = MAX(default_width, title_width);
60  if (default_width)
61  {
62  default_width += 10; /* add some padding */
63  g_object_set(G_OBJECT(column),
64  "sizing", GTK_TREE_VIEW_COLUMN_FIXED,
65  "fixed-width", default_width,
66  NULL);
67  }
68 }
69 
void tree_view_column_set_default_width(GtkTreeView *view, GtkTreeViewColumn *column, const gchar *sizing_text)
Set default width for a treeview column.