GnuCash  4.9-160-g22a1c354f+
Files | Data Structures | Macros | Enumerations | Functions
GncTreeView

Files

file  gnc-tree-view.c
 Base GncTreeView implementation for gnucash trees.
 
file  tree-view-utils.c
 Simple convenience functions for common tasks on GtkTreeViews.
 
file  tree-view-utils.c
 Simple convenience functions for common tasks on GtkTreeViews.
 

Data Structures

struct  GncTreeViewPrivate
 Private Data Structure. More...
 

Macros

#define STATE_KEY   "state-key"
 
#define STATE_KEY_SORT_COLUMN   "sort_column"
 
#define STATE_KEY_SORT_ORDER   "sort_order"
 
#define STATE_KEY_COLUMN_ORDER   "column_order"
 
#define STATE_KEY_SUFF_VISIBLE   "visible"
 
#define STATE_KEY_SUFF_WIDTH   "width"
 

Enumerations

enum  { PROP_0, PROP_STATE_SECTION, PROP_SHOW_COLUMN_MENU }
 

Functions

void gnc_tree_view_configure_columns (GncTreeView *view)
 Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available. More...
 
GtkTreeViewColumn * gnc_tree_view_add_toggle_column (GncTreeView *view, const gchar *column_title, const gchar *column_short_title, const gchar *pref_name, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn, renderer_toggled toggle_edited_cb)
 This function adds a new toggle column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_text_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new text column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_text_view_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new text view column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_date_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new date column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_combo_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeModel *combo_tree_model, gint combo_model_text_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new combobox column to a GncTreeView base view. More...
 
GtkCellRenderer * gnc_tree_view_column_get_renderer (GtkTreeViewColumn *column)
 Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the convenience routines. More...
 
GtkTreeViewColumn * gnc_tree_view_add_numeric_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *sizing_text, gint model_data_column, gint model_color_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new numeric column to a GncTreeView base view. More...
 
gint gnc_tree_view_append_column (GncTreeView *view, GtkTreeViewColumn *column)
 Add a column to a view based upon a GncTreeView. More...
 
gboolean gnc_tree_view_path_is_valid (GncTreeView *view, GtkTreePath *path)
 
void gnc_tree_view_keynav (GncTreeView *view, GtkTreeViewColumn **col, GtkTreePath *path, GdkEventKey *event)
 
void gnc_tree_view_set_editing_started_cb (GncTreeView *view, GFunc editing_started_cb, gpointer editing_cb_data)
 Setup a callback for when the user starts editing so appropriate actions can be taken like disable the actions delete menu option.
 
void gnc_tree_view_set_editing_finished_cb (GncTreeView *view, GFunc editing_finished_cb, gpointer editing_cb_data)
 Setup a callback for when the user finishes editing so appropriate actions can be taken like enable the actions delete menu option.
 
void tree_view_column_set_default_width (GtkTreeView *view, GtkTreeViewColumn *column, const gchar *sizing_text)
 Set default width for a treeview column. More...
 

Gnc Tree View Auxiliary Functions

GtkTreeViewColumn * gnc_tree_view_find_column_by_name (GncTreeView *view, const gchar *wanted)
 Find a tree column given the "pref name" used with saved state. More...
 

Gnc Tree View state Callback / Related Functions

void gnc_tree_view_remove_state_information (GncTreeView *view)
 Completely wipe the treeview's state information (column visibility, width, sorting order,..). More...
 
void gnc_tree_view_set_state_section (GncTreeView *view, const gchar *section)
 Set up or remove an association between a saved state section and the display of a view. More...
 
const gchar * gnc_tree_view_get_state_section (GncTreeView *view)
 Get the name of the state section this tree view is associated with. More...
 
void gnc_tree_view_save_state (GncTreeView *view)
 This function is called to write the treeview's state information (column visibility, width, sorting order,..) to the state file. More...
 

Gnc Tree View Column Selection Menu Related Functions

void gnc_tree_view_expand_columns (GncTreeView *view, gchar *first_column_name,...)
 This function set the columns that will be allocated the free space in the view. More...
 
void gnc_tree_view_set_control_column_background (GncTreeView *view, gint column, GtkTreeCellDataFunc func)
 This function links the cell backgrounds of the two control columns to a column in the model that has color strings or a cell data function that sets the "cell-background" property. More...
 
void gnc_tree_view_set_sort_user_data (GncTreeView *view, GtkTreeModel *s_model)
 This allows the columns to be setup without the model connected. More...
 
void gnc_tree_view_set_show_column_menu (GncTreeView *view, gboolean visible)
 This function is called to set the "show-column-menu" property on this view. More...
 
gboolean gnc_tree_view_get_show_column_menu (GncTreeView *view)
 This function is called to get the current value of the "show-column-menu" property. More...
 

Detailed Description

Function Documentation

◆ gnc_tree_view_add_combo_column()

GtkTreeViewColumn* gnc_tree_view_add_combo_column ( GncTreeView view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeModel *  combo_tree_model,
gint  combo_model_text_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 addition, it will use combo_tree_model as the GtkTreeModel for the combobox, and combo_model_text_column will be the column in the model used for displaying the text in the combobox.

Definition at line 2024 of file gnc-tree-view.c.

2033 {
2034  GtkTreeViewColumn *column;
2035  GtkCellRenderer *renderer;
2036  PangoLayout* layout;
2037  int default_width, title_width;
2038 
2039  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
2040 
2041  column = gtk_tree_view_column_new ();
2042  gtk_tree_view_column_set_title (column, gettext(column_title));
2043 
2044  /* Set up a renderer and attributes */
2045  renderer = gtk_cell_renderer_combo_new ();
2046  gtk_tree_view_column_pack_start (column, renderer, TRUE);
2047 
2048  /* Set renderer attributes controlled by the model */
2049  if (model_data_column != GNC_TREE_VIEW_COLUMN_DATA_NONE)
2050  gtk_tree_view_column_add_attribute (column, renderer,
2051  "text", model_data_column);
2052  if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
2053  gtk_tree_view_column_add_attribute (column, renderer,
2054  "visible", model_visibility_column);
2055 
2056  /* Default size is the larger of the column title and the sizing text */
2057  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
2058  pango_layout_get_pixel_size (layout, &title_width, NULL);
2059  g_object_unref (layout);
2060  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
2061  pango_layout_get_pixel_size (layout, &default_width, NULL);
2062  g_object_unref (layout);
2063  default_width = MAX(default_width, title_width);
2064  if (default_width)
2065  default_width += 10; /* padding on either side */
2066 
2067  gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
2068  default_width, TRUE, column_sort_fn);
2069 
2070  /* Stuff specific to combo */
2071  if (combo_tree_model)
2072  {
2073  g_object_set (G_OBJECT(renderer), "model", combo_tree_model,
2074  "text-column", combo_model_text_column, NULL);
2075  }
2076  /* TODO: has-entry? */
2077 
2078  gnc_tree_view_append_column (view, column);
2079  return column;
2080 }
gint gnc_tree_view_append_column(GncTreeView *view, GtkTreeViewColumn *column)
Add a column to a view based upon a GncTreeView.

◆ gnc_tree_view_add_date_column()

GtkTreeViewColumn* gnc_tree_view_add_date_column ( GncTreeView view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  icon_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new date 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

Definition at line 1966 of file gnc-tree-view.c.

1974 {
1975  GtkTreeViewColumn *column;
1976  GtkCellRenderer *renderer;
1977  PangoLayout* layout;
1978  int default_width, title_width;
1979 
1980  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1981 
1982  column = gtk_tree_view_column_new ();
1983  gtk_tree_view_column_set_title (column, column_title);
1984 
1985  /* Set up an icon renderer if requested */
1986  if (icon_name)
1987  {
1988  renderer = gtk_cell_renderer_pixbuf_new ();
1989  g_object_set (renderer, "icon-name", icon_name, NULL);
1990  gtk_tree_view_column_pack_start (column, renderer, FALSE);
1991  }
1992 
1993  /* Set up a text renderer and attributes */
1994  renderer = gnc_cell_renderer_date_new (TRUE);
1995  gtk_tree_view_column_pack_start (column, renderer, TRUE);
1996 
1997  /* Set renderer attributes controlled by the model */
1998  if (model_data_column != GNC_TREE_VIEW_COLUMN_DATA_NONE)
1999  gtk_tree_view_column_add_attribute (column, renderer,
2000  "text", model_data_column);
2001  if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
2002  gtk_tree_view_column_add_attribute (column, renderer,
2003  "visible", model_visibility_column);
2004 
2005  /* Default size is the larger of the column title and the sizing text */
2006  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
2007  pango_layout_get_pixel_size (layout, &title_width, NULL);
2008  g_object_unref (layout);
2009  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
2010  pango_layout_get_pixel_size (layout, &default_width, NULL);
2011  g_object_unref (layout);
2012  default_width = MAX(default_width, title_width);
2013  if (default_width)
2014  default_width += 10; /* padding on either side */
2015  gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
2016  default_width, TRUE, column_sort_fn);
2017 
2018  gnc_tree_view_append_column (view, column);
2019  return column;
2020 }
gint gnc_tree_view_append_column(GncTreeView *view, GtkTreeViewColumn *column)
Add a column to a view based upon a GncTreeView.

◆ gnc_tree_view_add_numeric_column()

GtkTreeViewColumn* gnc_tree_view_add_numeric_column ( GncTreeView view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_color_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new numeric 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. A numeric column is nothing more then a text column with a few extra attributes.

Parameters are defined in gnc-tree-view.h

Definition at line 2110 of file gnc-tree-view.c.

2118 {
2119  GtkTreeViewColumn *column;
2120  GtkCellRenderer *renderer;
2121  gfloat alignment = 1.0;
2122 
2123  column = gnc_tree_view_add_text_column (view, column_title, pref_name,
2124  NULL, sizing_text, model_data_column,
2125  model_visibility_column,
2126  column_sort_fn);
2127 
2128  renderer = gnc_tree_view_column_get_renderer (column);
2129 
2130  /* Right align the column title and data for both ltr and rtl */
2131  if (gtk_widget_get_direction (GTK_WIDGET(view)) == GTK_TEXT_DIR_RTL)
2132  alignment = 0.0;
2133 
2134  g_object_set (G_OBJECT(column), "alignment", alignment, NULL);
2135  g_object_set (G_OBJECT(renderer), "xalign", alignment, NULL);
2136 
2137  /* Change the text color */
2138  if (model_color_column != GNC_TREE_VIEW_COLUMN_COLOR_NONE)
2139  gtk_tree_view_column_add_attribute (column, renderer,
2140  "foreground", model_color_column);
2141 
2142  return column;
2143 }
GtkCellRenderer * gnc_tree_view_column_get_renderer(GtkTreeViewColumn *column)
Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the conveni...
GtkTreeViewColumn * gnc_tree_view_add_text_column(GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
This function adds a new text column to a GncTreeView base view.

◆ gnc_tree_view_add_text_column()

GtkTreeViewColumn* gnc_tree_view_add_text_column ( GncTreeView view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  icon_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new text 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

Definition at line 1901 of file gnc-tree-view.c.

1909 {
1910  GtkCellRenderer *renderer;
1911 
1912  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1913 
1914  renderer = gtk_cell_renderer_text_new ();
1915 
1916  return add_text_column_variant (view, renderer,
1917  column_title, pref_name,
1918  icon_name, sizing_text,
1919  model_data_column,
1920  model_visibility_column,
1921  column_sort_fn);
1922 }

◆ gnc_tree_view_add_text_view_column()

GtkTreeViewColumn* gnc_tree_view_add_text_view_column ( GncTreeView view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  icon_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new text 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

Definition at line 1933 of file gnc-tree-view.c.

1941 {
1942  GtkCellRenderer *renderer;
1943 
1944  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1945 
1946  renderer = gnc_cell_renderer_text_view_new ();
1947 
1948  return add_text_column_variant (view, renderer,
1949  column_title, pref_name,
1950  icon_name, sizing_text,
1951  model_data_column,
1952  model_visibility_column,
1953  column_sort_fn);
1954 }

◆ gnc_tree_view_add_toggle_column()

GtkTreeViewColumn* gnc_tree_view_add_toggle_column ( GncTreeView view,
const gchar *  column_title,
const gchar *  column_short_title,
const gchar *  pref_name,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn,
renderer_toggled  toggle_edited_cb 
)

This function adds a new toggle column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. It handles creating a tooltip to show the full title name, and setting the sort and edit callback functions. 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

Definition at line 1748 of file gnc-tree-view.c.

1756 {
1757  GtkTreeViewColumn *column;
1758  GtkCellRenderer *renderer;
1759 
1760  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1761 
1762  renderer = gtk_cell_renderer_toggle_new ();
1763  if (!toggle_edited_cb)
1764  {
1765  gtk_cell_renderer_toggle_set_activatable (GTK_CELL_RENDERER_TOGGLE(renderer), FALSE);
1766  }
1767  column =
1768  gtk_tree_view_column_new_with_attributes (column_short_title,
1769  renderer,
1770  "active", model_data_column,
1771  NULL);
1772 
1773  /* Add the full title to the object for menu creation */
1774  g_object_set_data_full (G_OBJECT(column), REAL_TITLE,
1775  g_strdup(column_title), g_free);
1776  if (toggle_edited_cb)
1777  g_signal_connect (G_OBJECT(renderer), "toggled",
1778  G_CALLBACK(toggle_edited_cb), view);
1779 
1780  if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
1781  gtk_tree_view_column_add_attribute (column, renderer,
1782  "visible", model_visibility_column);
1783 
1784 
1785  gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
1786  0, FALSE, column_sort_fn);
1787 
1788  gnc_tree_view_append_column (view, column);
1789 
1790  /* Also add the full title to the object as a tooltip */
1791  gtk_widget_set_tooltip_text (gtk_tree_view_column_get_button (column), column_title);
1792 
1793  return column;
1794 }
gint gnc_tree_view_append_column(GncTreeView *view, GtkTreeViewColumn *column)
Add a column to a view based upon a GncTreeView.

◆ gnc_tree_view_append_column()

gint gnc_tree_view_append_column ( GncTreeView view,
GtkTreeViewColumn *  column 
)

Add a column to a view based upon a GncTreeView.

This function knows about the two special columns on the right side of this type of view, and adds the new column before these two columns. You could say that it appends to the data columns and ignores the infrastructure columns.

Parameters are defined in gnc-tree-view.h

Definition at line 2154 of file gnc-tree-view.c.

2156 {
2157  GList *columns;
2158  int n;
2159 
2160  /* There's no easy way to get this number. */
2161  columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
2162  n = g_list_length (columns);
2163  g_list_free (columns);
2164 
2165  /* Ignore the initial column, the selection menu */
2166  if (n >= 1)
2167  n -= 1;
2168  return gtk_tree_view_insert_column (GTK_TREE_VIEW(view), column, n);
2169 }

◆ gnc_tree_view_column_get_renderer()

GtkCellRenderer* gnc_tree_view_column_get_renderer ( GtkTreeViewColumn *  column)

Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the convenience routines.

Parameters
columnThe tree view column that was added to the GncTreeView
Returns
The cell renderer in use in the column.

Definition at line 2083 of file gnc-tree-view.c.

2084 {
2085  GList *renderers;
2086  GtkCellRenderer *cr = NULL;
2087 
2088  g_return_val_if_fail (GTK_TREE_VIEW_COLUMN(column), NULL);
2089 
2090  /* Get the list of one renderer */
2091  renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(column));
2092  if (g_list_length (renderers) > 0)
2093  cr = GTK_CELL_RENDERER(renderers->data);
2094  g_list_free (renderers);
2095 
2096  return cr;
2097 }

◆ gnc_tree_view_configure_columns()

void gnc_tree_view_configure_columns ( GncTreeView view)

Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available.

Parameters
viewA pointer to an gnc tree view.

Definition at line 1578 of file gnc-tree-view.c.

1579 {
1580  GncTreeViewPrivate *priv;
1581  GtkTreeViewColumn *column;
1582  GList *columns;
1583  gboolean hide_menu_column;
1584 
1585  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1586 
1587  ENTER(" ");
1588 
1589  /* Update the view and saved state */
1590  columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1591  g_list_foreach (columns, (GFunc)gnc_tree_view_update_visibility, view);
1592  g_list_free (columns);
1593 
1594  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1595  if (priv->state_section)
1596  priv->seen_state_visibility = TRUE;
1597 
1598  /* If only the first column is visible, hide the spacer and make that
1599  * column expand. */
1600  hide_menu_column = (gnc_tree_view_count_visible_columns (view) == 1);
1601  column = gtk_tree_view_get_column (GTK_TREE_VIEW(view), 0);
1602  gtk_tree_view_column_set_expand (column, hide_menu_column);
1603  gtk_tree_view_column_set_visible (priv->column_menu_column, !hide_menu_column);
1604 
1605  LEAVE(" ");
1606 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_expand_columns()

void gnc_tree_view_expand_columns ( GncTreeView view,
gchar *  first_column_name,
  ... 
)

This function set the columns that will be allocated the free space in the view.

Parameters
viewThe tree view.
listof column names.

Definition at line 1408 of file gnc-tree-view.c.

1411 {
1412  GncTreeViewPrivate *priv;
1413  GtkTreeViewColumn *column;
1414  gboolean hide_spacer;
1415  GList *columns, *tmp;
1416  gchar *name, *pref_name;
1417  va_list args;
1418 
1419  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1420  ENTER(" ");
1421  va_start (args, first_column_name);
1422  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1423  name = first_column_name;
1424  hide_spacer = FALSE;
1425 
1426  /* First disable the expand property on all (non-infrastructure) columns. */
1427  columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1428  for (tmp = columns; tmp; tmp = g_list_next (tmp))
1429  {
1430  column = tmp->data;
1431  pref_name = g_object_get_data (G_OBJECT(column), PREF_NAME);
1432  if (pref_name != NULL)
1433  gtk_tree_view_column_set_expand (column, FALSE);
1434  }
1435  g_list_free(columns);
1436 
1437  /* Now enable it on the requested columns. */
1438  while (name != NULL)
1439  {
1440  column = gnc_tree_view_find_column_by_name (view, name);
1441  if (column != NULL)
1442  {
1443  gtk_tree_view_column_set_expand (column, TRUE);
1444  hide_spacer = TRUE;
1445  }
1446  name = va_arg (args, gchar*);
1447  }
1448  va_end (args);
1449 
1450  LEAVE(" ");
1451 }
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
Find a tree column given the "pref name" used with saved state.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_find_column_by_name()

GtkTreeViewColumn* gnc_tree_view_find_column_by_name ( GncTreeView view,
const gchar *  wanted 
)

Find a tree column given the "pref name" used with saved state.

Find a tree column given the "pref name".

This function simply runs the list of all (visible and invisible) columns looking for a match. Column names were attached to each column at the time the column was created.

Parameters
viewThe visible tree widget.
wantedThe "pref name" to find.

Definition at line 534 of file gnc-tree-view.c.

536 {
537  GtkTreeViewColumn *column, *found = NULL;
538  GList *column_list, *tmp;
539  const gchar *name;
540 
541  // ENTER("view %p, wanted %s", view, wanted);
542  column_list = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
543  for (tmp = column_list; tmp; tmp = g_list_next (tmp))
544  {
545  column = tmp->data;
546  name = g_object_get_data (G_OBJECT(column), PREF_NAME);
547  if (!name || (strcmp(name, wanted) != 0))
548  continue;
549  found = column;
550  break;
551  }
552  g_list_free (column_list);
553 
554  // LEAVE("column %p", found);
555  return found;
556 }

◆ gnc_tree_view_get_show_column_menu()

gboolean gnc_tree_view_get_show_column_menu ( GncTreeView view)

This function is called to get the current value of the "show-column-menu" property.

It returns the same value passed to gnc_tree_view_set_show_menu_column().

Parameters are defined in gnc-tree-view.h

Definition at line 1542 of file gnc-tree-view.c.

1543 {
1544  GncTreeViewPrivate *priv;
1545 
1546  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), FALSE);
1547 
1548  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1549  return (priv->show_column_menu);
1550 }
Private Data Structure.

◆ gnc_tree_view_get_state_section()

const gchar* gnc_tree_view_get_state_section ( GncTreeView view)

Get the name of the state section this tree view is associated with.

This function is called to get the current association between a saved state section and the display of a view.

It returns the same value passed to gnc_tree_view_set_state_section(); i.e. a string like "dialogs/edit_prices".

Parameters are defined in gnc-tree-view.h

Definition at line 1116 of file gnc-tree-view.c.

1117 {
1118  GncTreeViewPrivate *priv;
1119 
1120  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1121 
1122  priv = GNC_TREE_VIEW_GET_PRIVATE (view);
1123  return priv->state_section;
1124 }
Private Data Structure.

◆ gnc_tree_view_remove_state_information()

void gnc_tree_view_remove_state_information ( GncTreeView view)

Completely wipe the treeview's state information (column visibility, width, sorting order,..).

This function is called to completely wipe the treeview's state information (column visibility, width, sorting order,..).

This function may be called at any time; either when the user wants to disconnect or when the view object is being destroyed.

Parameters
viewThe tree view.

Definition at line 978 of file gnc-tree-view.c.

979 {
980  GncTreeViewPrivate *priv;
981  GKeyFile *state_file = gnc_state_get_current ();
982 
983  ENTER(" ");
984  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
985  if (!priv->state_section)
986  {
987  LEAVE("no state section");
988  return;
989  }
990 
991  g_key_file_remove_group (state_file, priv->state_section, NULL);
992  g_free (priv->state_section);
993  priv->state_section = NULL;
994  LEAVE(" ");
995 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_save_state()

void gnc_tree_view_save_state ( GncTreeView view)

This function is called to write the treeview's state information (column visibility, width, sorting order,..) to the state file.

Parameters
viewThe tree view.

Definition at line 1126 of file gnc-tree-view.c.

1127 {
1128  GncTreeViewPrivate *priv;
1129 
1130  ENTER("view %p", view);
1131  g_return_if_fail (view != NULL);
1132  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1133 
1134  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1135 
1136  if (priv->state_section)
1137  {
1138  /* Save state. Only store non-default values when possible. */
1139  GList *column_list, *tmp;
1140  GKeyFile *state_file = gnc_state_get_current();
1141  gsize num_cols = 0;
1142  gchar *sort_column = gnc_tree_view_get_sort_column (view);
1143  gchar *sort_order = gnc_tree_view_get_sort_order (view);
1144  gchar **col_order = gnc_tree_view_get_column_order (view, &num_cols);
1145 
1146  /* Default sort column is the name column */
1147  if (sort_column && (g_strcmp0 (sort_column, "name") != 0))
1148  g_key_file_set_string (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, sort_column);
1149  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, NULL))
1150  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, NULL);
1151  g_free (sort_column);
1152 
1153 
1154  /* Default sort order is "ascending" */
1155  if (g_strcmp0 (sort_order, "descending") == 0)
1156  g_key_file_set_string (state_file, priv->state_section, STATE_KEY_SORT_ORDER, sort_order);
1157  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_SORT_ORDER, NULL))
1158  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_SORT_ORDER, NULL);
1159  g_free (sort_order);
1160 
1161  if (col_order && (num_cols > 0))
1162  g_key_file_set_string_list (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER,
1163  (const gchar**) col_order, num_cols);
1164  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER, NULL))
1165  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER, NULL);
1166 
1167  g_strfreev (col_order);
1168 
1169 
1170  // ENTER("view %p, wanted %s", view, wanted);
1171  column_list = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1172  for (tmp = column_list; tmp; tmp = g_list_next (tmp))
1173  {
1174  GtkTreeViewColumn *column = tmp->data;
1175  gchar *key=NULL;
1176  const gchar *name = g_object_get_data (G_OBJECT(column), PREF_NAME);
1177  if (!name)
1178  continue;
1179 
1180  if (!g_object_get_data (G_OBJECT(column), ALWAYS_VISIBLE))
1181  {
1182  key = g_strjoin ("_", name, STATE_KEY_SUFF_VISIBLE, NULL);
1183  g_key_file_set_boolean (state_file, priv->state_section, key,
1184  gtk_tree_view_column_get_visible (column));
1185  g_free (key);
1186  }
1187 
1188  key = g_strjoin ("_", name, STATE_KEY_SUFF_WIDTH, NULL);
1189  if (g_object_get_data (G_OBJECT(column), "default-width") &&
1190  (GPOINTER_TO_INT((g_object_get_data (G_OBJECT(column), "default-width")))
1191  != gtk_tree_view_column_get_width (column)))
1192  {
1193  g_key_file_set_integer (state_file, priv->state_section, key,
1194  gtk_tree_view_column_get_width (column));
1195  }
1196  else if (g_key_file_has_key (state_file, priv->state_section, key, NULL))
1197  g_key_file_remove_key (state_file, priv->state_section, key, NULL);
1198  g_free (key);
1199  }
1200  g_list_free (column_list);
1201  }
1202 
1203  LEAVE(" ");
1204 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_control_column_background()

void gnc_tree_view_set_control_column_background ( GncTreeView view,
gint  column,
GtkTreeCellDataFunc  func 
)

This function links the cell backgrounds of the two control columns to a column in the model that has color strings or a cell data function that sets the "cell-background" property.

Parameters
viewThe tree view.
columnThe column in the model containing color strings.
funcThis is a cell data function that sets the "cell-background".

Definition at line 1482 of file gnc-tree-view.c.

1483 {
1484  GncTreeViewPrivate *priv;
1485 
1486  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1487 
1488  ENTER("view %p, column %d, func %p", view, column, func);
1489  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1490 
1491  update_control_cell_renderers_background (view, priv->column_menu_column, column, func);
1492 
1493  LEAVE(" ");
1494 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_show_column_menu()

void gnc_tree_view_set_show_column_menu ( GncTreeView view,
gboolean  visible 
)

This function is called to set the "show-column-menu" property on this view.

This function has no visible effect if the "state-section" property has not been set.

Parameters are defined in gnc-tree-view.h

Definition at line 1521 of file gnc-tree-view.c.

1523 {
1524  GncTreeViewPrivate *priv;
1525 
1526  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1527 
1528  ENTER("view %p, show menu %d", view, visible);
1529  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1530  priv->show_column_menu = visible;
1531  gnc_tree_view_build_column_menu (view);
1532  LEAVE(" ");
1533 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_sort_user_data()

void gnc_tree_view_set_sort_user_data ( GncTreeView view,
GtkTreeModel *  s_model 
)

This allows the columns to be setup without the model connected.

Parameters
viewThe tree view.
sortmodel.

Definition at line 1500 of file gnc-tree-view.c.

1501 {
1502  GncTreeViewPrivate *priv;
1503 
1504  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1505 
1506  ENTER("view %p, sort_model %p", view, s_model);
1507  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1508 
1509  priv->sort_model = s_model;
1510  LEAVE(" ");
1511 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_state_section()

void gnc_tree_view_set_state_section ( GncTreeView view,
const gchar *  section 
)

Set up or remove an association between a saved state section and the display of a view.

This function is called to set up or remove an association between a saved state section and the display of a view.

It will first remove any existing association, and then install the new one. If the new section has state information, update the view with this information.

Parameters are defined in gnc-tree-view.h

Definition at line 1005 of file gnc-tree-view.c.

1007 {
1008  GncTreeViewPrivate *priv;
1009  GKeyFile *state_file;
1010 
1011  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1012 
1013  ENTER("view %p, section %s", view, section);
1014 
1015  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1016 
1017  /* Drop any previous state section */
1018  if (priv->state_section)
1020 
1021  if (!section)
1022  {
1023  LEAVE("cleared state section");
1024  return;
1025  }
1026 
1027  /* Catch changes in state. Propagate to view. */
1028  priv->state_section = g_strdup (section);
1029 
1030  state_file = gnc_state_get_current ();
1031  if (g_key_file_has_group (state_file, priv->state_section))
1032  {
1033  gsize num_keys, idx;
1034  gchar **keys = g_key_file_get_keys (state_file, priv->state_section, &num_keys, NULL);
1035  for (idx = 0; idx < num_keys; idx++)
1036  {
1037  gchar *key = keys[idx];
1038  if (g_strcmp0 (key, STATE_KEY_SORT_COLUMN) == 0)
1039  {
1040  gnc_tree_view_set_sort_column (view,
1041  g_key_file_get_string (state_file, priv->state_section, key, NULL));
1042  }
1043  else if (g_strcmp0 (key, STATE_KEY_SORT_ORDER) == 0)
1044  {
1045  gnc_tree_view_set_sort_order (view,
1046  g_key_file_get_string (state_file, priv->state_section, key, NULL));
1047  }
1048  else if (g_strcmp0 (key, STATE_KEY_COLUMN_ORDER) == 0)
1049  {
1050  gsize length;
1051  gchar **columns = g_key_file_get_string_list (state_file, priv->state_section,
1052  key, &length, NULL);
1053  gnc_tree_view_set_column_order (view, columns, length);
1054  g_strfreev (columns);
1055  }
1056  else
1057  {
1058  /* Make a copy of the local part of the key so it can be split
1059  * into column name and key type */
1060  gboolean known = FALSE;
1061  gchar *column_name = g_strdup (key);
1062  gchar *type_name = g_strrstr (column_name, "_");
1063 
1064  if (type_name != NULL) //guard against not finding '_'
1065  {
1066  *type_name++ = '\0';
1067 
1068  if (g_strcmp0 (type_name, STATE_KEY_SUFF_VISIBLE) == 0)
1069  {
1070  GtkTreeViewColumn *column = gnc_tree_view_find_column_by_name (view, column_name);
1071  if (column)
1072  {
1073  known = TRUE;
1074  if (!g_object_get_data (G_OBJECT (column), ALWAYS_VISIBLE))
1075  {
1076  gtk_tree_view_column_set_visible (column,
1077  g_key_file_get_boolean (state_file, priv->state_section, key, NULL));
1078  }
1079  }
1080  }
1081  else if (g_strcmp0 (type_name, STATE_KEY_SUFF_WIDTH) == 0)
1082  {
1083  gint width = g_key_file_get_integer (state_file, priv->state_section, key, NULL);
1084  GtkTreeViewColumn *column = gnc_tree_view_find_column_by_name (view, column_name);
1085  if (column)
1086  {
1087  known = TRUE;
1088  if (width && (width != gtk_tree_view_column_get_width (column)))
1089  {
1090  gtk_tree_view_column_set_fixed_width (column, width);
1091  }
1092  }
1093  }
1094  if (!known)
1095  DEBUG ("Ignored key %s", key);
1096 
1097  g_free (column_name);
1098  }
1099  }
1100  }
1101  g_strfreev (keys);
1102  }
1103 
1104  /* Rebuild the column visibility menu */
1105  gnc_tree_view_build_column_menu (view);
1106  LEAVE ("set state section");
1107 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
void gnc_tree_view_remove_state_information(GncTreeView *view)
Completely wipe the treeview&#39;s state information (column visibility, width, sorting order...
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
Find a tree column given the "pref name" used with saved state.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ tree_view_column_set_default_width()

void tree_view_column_set_default_width ( GtkTreeView *  view,
GtkTreeViewColumn *  column,
const gchar *  sizing_text 
)

Set default width for a treeview column.

This base width is the largest of the column title and some arbitrary text passed in via sizing_text. This base width is then increased with some padding.

Definition at line 43 of file tree-view-utils.c.

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 }