Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add new function to gnc-tree-view to display icon column
  • Loading branch information
Bob-IT committed Dec 16, 2022
1 parent fb84cf7 commit 5108c52
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
57 changes: 57 additions & 0 deletions gnucash/gnome-utils/gnc-tree-view.c
Expand Up @@ -1957,6 +1957,63 @@ gnc_tree_view_add_text_view_column (GncTreeView *view,
column_sort_fn);
}

/** This function adds a new pixbuf view column to a GncTreeView base view.
* It takes all the parameters necessary to hook a GtkTreeModel
* column to a GtkTreeViewColumn. If the tree has a state section
* associated with it, this function also wires up the column so that
* its visibility and width are remembered.
*
* Parameters are defined in gnc-tree-view.h
*/
GtkTreeViewColumn *
gnc_tree_view_add_pix_column (GncTreeView *view,
const gchar *column_title,
const gchar *pref_name,
const gchar *sizing_text,
gint model_data_column,
gint model_visibility_column,
GtkTreeIterCompareFunc column_sort_fn)
{
GtkTreeViewColumn *column;
PangoLayout* layout;
int default_width, title_width;
GtkCellRenderer *renderer;

g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);

renderer = gtk_cell_renderer_pixbuf_new ();

column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, column_title);

/* Set up a text renderer and attributes */
gtk_tree_view_column_pack_start (column, renderer, TRUE);

/* Set renderer attributes controlled by the model */
if (model_data_column != GNC_TREE_VIEW_COLUMN_DATA_NONE)
gtk_tree_view_column_add_attribute (column, renderer,
"icon-name", model_data_column);
if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
gtk_tree_view_column_add_attribute (column, renderer,
"visible", model_visibility_column);

/* Default size is the larger of the column title and the sizing text */
layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
pango_layout_get_pixel_size (layout, &title_width, NULL);
g_object_unref (layout);
layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
pango_layout_get_pixel_size (layout, &default_width, NULL);
g_object_unref (layout);
default_width = MAX(default_width, title_width);
if (default_width)
default_width += 10; /* padding on either side */
gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
default_width, TRUE, column_sort_fn);

gnc_tree_view_append_column (view, column);
return column;
}


/** This function adds a new date column to a GncTreeView base view.
* It takes all the parameters necessary to hook a GtkTreeModel
Expand Down
41 changes: 41 additions & 0 deletions gnucash/gnome-utils/gnc-tree-view.h
Expand Up @@ -246,6 +246,47 @@ gnc_tree_view_add_text_view_column (GncTreeView *view,
gint model_visibility_column,
GtkTreeIterCompareFunc column_sort_fn);

/** This function adds a pixbuf view column to a GncTreeView base view.
* It takes all the parameters necessary to hook a GtkTreeModel
* column to a GtkTreeViewColumn.
*
* @param view A pointer to a generic GncTreeView.
*
* @param column_title The title for this column.
*
* @param pref_name The internal name of this column. This name is
* used in several functions to look up the column, and it is also
* used when saving/restoring the view's state.
*
* @param sizing_text A string used to compute the default width of
* the column. This text is never displayed.
*
* @param model_data_column The index of the GtkTreeModel data column
* used to determine the data that will be displayed in this column
* for each row in the view. Use GNC_TREE_VIEW_COLUMN_DATA_NONE if
* you plan on using a non-model data source for this column. This
* index is connected to the "icon-name" attribute of the cell renderer.
*
* @param model_visibility_column The index of the GtkTreeModel data
* column used to determine whether or not a checkbox for each row
* will be displayed at all. Use GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS
* if the checkbox should be displayed in all rows.
*
* @param column_sort_fn The function that GtkTreeModelSort
* will call to compare two rows to determine their displayed
* order.
*
* @return The newly created GtkTreeViewColumn.
*/
GtkTreeViewColumn *
gnc_tree_view_add_pix_column (GncTreeView *view,
const gchar *column_title,
const gchar *pref_name,
const gchar *sizing_text,
gint model_data_column,
gint model_visibility_column,
GtkTreeIterCompareFunc column_sort_fn);

/** This function adds a new combobox column to a GncTreeView base
* view. The parameters it takes in common with
* gnc_tree_view_add_text_column() behave the same as there. In
Expand Down

0 comments on commit 5108c52

Please sign in to comment.