GnuCash 2.3.0
Data Structures | Files | Defines | Typedefs | Enumerations | Functions
GncTreeView
GUI

Data Structures

struct  GncTreeViewPrivate

Files

file  gnc-tree-view.c
 

Base GncTreeView implementation for gnucash trees.


Defines

#define MODEL_COLUMN   "model_column"
#define REAL_TITLE   "real_title"
#define PREF_NAME   "pref-name"
#define GCONF_KEY   "gconf-key"
#define GCONF_KEY_SORT_COLUMN   "sort_column"
#define GCONF_KEY_SORT_ORDER   "sort_order"
#define GCONF_KEY_COLUMN_ORDER   "column_order"
#define GCONF_KEY_VISIBLE   "visible"
#define GCONF_KEY_WIDTH   "width"
#define GNC_TREE_VIEW_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_TREE_VIEW, GncTreeViewPrivate))

Typedefs

typedef struct GncTreeViewPrivate GncTreeViewPrivate

Enumerations

enum  { PROP_0, PROP_GCONF_SECTION, PROP_SHOW_COLUMN_MENU }

Functions

void gnc_tree_view_set_model (GncTreeView *view, GtkTreeModel *model)
void gnc_tree_view_configure_columns (GncTreeView *view)
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)
GtkTreeViewColumn * gnc_tree_view_add_text_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *stock_icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
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)
GtkCellRenderer * gnc_tree_view_column_get_renderer (GtkTreeViewColumn *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)
gint gnc_tree_view_append_column (GncTreeView *view, GtkTreeViewColumn *column)
gboolean gnc_tree_view_path_is_valid (GncTreeView *view, GtkTreePath *path)
void gnc_tree_view_keynav (GncTreeView *view, GtkTreeViewColumn **col, GtkTreePath *path, GdkEventKey *event)

Gnc Tree View Object Implementation

GType gnc_tree_view_get_type (void)

Gnc Tree View Auxiliary Functions

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

Gnc Tree View Gconf Callback / Related Functions

void gnc_tree_view_set_gconf_section (GncTreeView *view, const gchar *section)
const gchar * gnc_tree_view_get_gconf_section (GncTreeView *view)

Gnc Tree View Column Selection Menu Related Functions

void gnc_tree_view_expand_columns (GncTreeView *view, gchar *first_column_name,...)
void gnc_tree_view_set_show_column_menu (GncTreeView *view, gboolean visible)
gboolean gnc_tree_view_get_show_column_menu (GncTreeView *view)

Typedef Documentation

Private Data Structure


Function Documentation

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 2001 of file gnc-tree-view.c.

{
    GtkTreeViewColumn *column;
    GtkCellRenderer *renderer;
    PangoLayout* layout;
    int default_width, title_width;

    g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);

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

    /* Set up a renderer and attributes */
    renderer = gtk_cell_renderer_combo_new ();
    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,
                                            "text", 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);

    /* Stuff specific to combo */
    if (combo_tree_model)
    {
        g_object_set(G_OBJECT(renderer), "model", combo_tree_model,
                     "text-column", combo_model_text_column, NULL);
    }
    /* TODO: has-entry? */

    gnc_tree_view_append_column (view, column);
    return 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 gconf 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 2087 of file gnc-tree-view.c.

{
    GtkTreeViewColumn *column;
    GtkCellRenderer *renderer;

    column = gnc_tree_view_add_text_column (view, column_title, pref_name,
                                            NULL, sizing_text, model_data_column,
                                            model_visibility_column,
                                            column_sort_fn);

    renderer = gnc_tree_view_column_get_renderer(column);

    /* Right align the column title and data */
    g_object_set(G_OBJECT(column), "alignment",   1.0, NULL);
    g_object_set(G_OBJECT(renderer), "xalign",   1.0, NULL);

    /* Change the text color */
    if (model_color_column != GNC_TREE_VIEW_COLUMN_COLOR_NONE)
        gtk_tree_view_column_add_attribute (column, renderer,
                                            "foreground", model_color_column);

    return column;
}
GtkTreeViewColumn* gnc_tree_view_add_text_column ( GncTreeView view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  stock_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 gconf 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 1944 of file gnc-tree-view.c.

{
    GtkTreeViewColumn *column;
    GtkCellRenderer *renderer;
    PangoLayout* layout;
    int default_width, title_width;

    g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);

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

    /* Set up an icon renderer if requested */
    if (stock_icon_name)
    {
        renderer = gtk_cell_renderer_pixbuf_new ();
        g_object_set (renderer, "stock-id", stock_icon_name, NULL);
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
    }

    /* Set up a text renderer and attributes */
    renderer = gtk_cell_renderer_text_new ();
    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,
                                            "text", 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;
}
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 gconf 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 1889 of file gnc-tree-view.c.

{
    GncTreeViewPrivate *priv;
    GtkTreeViewColumn *column;
    GtkCellRenderer *renderer;

    g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);

    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
    renderer = gtk_cell_renderer_toggle_new ();
    column =
        gtk_tree_view_column_new_with_attributes (column_short_title,
                renderer,
                "active", model_data_column,
                NULL);

    /* Add the full title to the object for menu creation */
    g_object_set_data_full(G_OBJECT(column), REAL_TITLE,
                           g_strdup(column_title), g_free);
    if (toggle_edited_cb)
        g_signal_connect(G_OBJECT(renderer), "toggled",
                         G_CALLBACK(toggle_edited_cb), view);

    if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
        gtk_tree_view_column_add_attribute (column, renderer,
                                            "visible", model_visibility_column);


    gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
                                     0, FALSE, column_sort_fn);

    gnc_tree_view_append_column (view, column);

    /* Also add the full title to the object as a tooltip */
    gtk_widget_set_tooltip_text(column->button, column_title);

    return 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 2127 of file gnc-tree-view.c.

{
    GList *columns;
    int n;

    /* There's no easy way to get this number. */
    columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
    n = g_list_length(columns);
    g_list_free(columns);

    /* Ignore the initial two columns (the spacer and the selection menu) */
    if (n >= 2)
        n -= 2;
    return gtk_tree_view_insert_column (GTK_TREE_VIEW(view), column, n);
}
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 2060 of file gnc-tree-view.c.

{
    GList *renderers;
    GtkCellRenderer *cr = NULL;

    g_return_val_if_fail(GTK_TREE_VIEW_COLUMN(column), NULL);

    /* Get the list of one renderer */
    renderers = gtk_tree_view_column_get_cell_renderers(column);
    if (g_list_length(renderers) > 0)
        cr = GTK_CELL_RENDERER(renderers->data);
    g_list_free(renderers);

    return cr;
}
void gnc_tree_view_configure_columns ( GncTreeView view)

Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and their gconf visibility settings, if managed by gconf.

Parameters:
viewA pointer to an gnc tree view.

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

{
    GncTreeViewPrivate *priv;
    GtkTreeViewColumn *column;
    GList *columns;
    gboolean hide_spacer;

    g_return_if_fail(GNC_IS_TREE_VIEW(view));

    ENTER(" ");

    /* Update the view and gconf */
    columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
    g_list_foreach(columns, (GFunc)gnc_tree_view_update_visibility, view);
    g_list_free(columns);

    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
    if (priv->gconf_section)
        priv->seen_gconf_visibility = TRUE;

    /* If only the first column is visible, hide the spacer and make that
     * column expand. */
    hide_spacer = (gnc_tree_view_count_visible_columns(view) == 1);
    column = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 0);
    gtk_tree_view_column_set_expand(column, hide_spacer);
    gtk_tree_view_column_set_visible(priv->spacer_column, !hide_spacer);
    gtk_tree_view_column_set_visible(priv->selection_column, !hide_spacer);

    LEAVE(" ");
}
GtkTreeViewColumn* gnc_tree_view_find_column_by_name ( GncTreeView view,
const gchar *  wanted 
)

Find a tree column given the "pref name" used with gconf. 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 498 of file gnc-tree-view.c.

{
    GtkTreeViewColumn *column, *found = NULL;
    GList *column_list, *tmp;
    const gchar *name;

    // ENTER("view %p, wanted %s", view, wanted);
    column_list = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
    for (tmp = column_list; tmp; tmp = g_list_next(tmp))
    {
        column = tmp->data;
        name = g_object_get_data(G_OBJECT(column), PREF_NAME);
        if (!name || (strcmp(name, wanted) != 0))
            continue;
        found = column;
        break;
    }
    g_list_free(column_list);

    // LEAVE("column %p", found);
    return found;
}
const gchar* gnc_tree_view_get_gconf_section ( GncTreeView view)

This function is called to get the current association between a gconf section and the display of a view. It returns the same value passed to gnc_tree_view_set_gconf_section(); i.e. a string like "dialogs/edit_prices".

Parameters are defined in gnc-tree-view.h

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

{
    GncTreeViewPrivate *priv;

    g_return_val_if_fail(GNC_IS_TREE_VIEW(view), NULL);

    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
    return(priv->gconf_section);
}
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 1660 of file gnc-tree-view.c.

{
    GncTreeViewPrivate *priv;

    g_return_val_if_fail(GNC_IS_TREE_VIEW(view), FALSE);

    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
    return(priv->show_column_menu);
}
GType gnc_tree_view_get_type ( void  )

Create a new glib type for the base gnucash tree view.

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

{
    static GType gnc_tree_view_type = 0;

    if (gnc_tree_view_type == 0)
    {
        static const GTypeInfo our_info =
        {
            sizeof (GncTreeViewClass),
            NULL,
            NULL,
            (GClassInitFunc) gnc_tree_view_class_init,
            NULL,
            NULL,
            sizeof (GncTreeView),
            0,
            (GInstanceInitFunc) gnc_tree_view_init
        };

        gnc_tree_view_type = g_type_register_static (GTK_TYPE_TREE_VIEW,
                             GNC_TREE_VIEW_NAME,
                             &our_info, 0);
    }

    return gnc_tree_view_type;
}
void gnc_tree_view_set_gconf_section ( GncTreeView view,
const gchar *  section 
)

This function is called to set up or remove an association between a gconf section and the display of a view. It will first remove any existing association, and then install the new one. This involves storing the gconf section value, requesting notification from gconf of any changes to keys in that section, then attaching several signals to catch user changes to the view.

Parameters are defined in gnc-tree-view.h

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

{
    GncTreeViewPrivate *priv;
    GtkTreeModel *model;
    gulong id;

    g_return_if_fail(GNC_IS_TREE_VIEW(view));

    ENTER("view %p, section %s", view, section);
    gnc_tree_view_remove_gconf(view);

    if (!section)
    {
        LEAVE("cleared gconf section");
        return;
    }

    /* Catch changes in gconf. Propagate to view. */
    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
    priv->gconf_section = g_strdup(section);
    gnc_gconf_add_notification(G_OBJECT(view), section,
                               gnc_tree_view_gconf_changed,
                               GNC_TREE_VIEW_NAME);

    /* Catch changes to the sort column. Propagate to gconf. The key can
     * be set before the model, so the code must handle that case. */
    model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
    if (model)
        priv->sort_column_changed_cb_id =
            g_signal_connect(GTK_TREE_SORTABLE(model), "sort-column-changed",
                             (GCallback)gtk_tree_view_sort_column_changed_cb, view);

    /* Catch changes to the column order. Propagate to gconf */
    id = g_signal_connect(view, "columns-changed",
                          (GCallback)gtk_tree_view_columns_changed_cb, NULL);
    priv->columns_changed_cb_id = id;

    /* Catch changes to the column width. Propagate to gconf */
    id = g_signal_connect(view, "size-allocate",
                          (GCallback)gtk_tree_view_size_allocate_cb, NULL);
    priv->size_allocate_cb_id = id;

    /* Force an update of the view with all items from gconf. */
    gnc_tree_view_gconf_force_update(view);

    /* Rebuild the column visibility menu */
    gnc_tree_view_build_column_menu(view);
    LEAVE("set gconf section");
}
void gnc_tree_view_set_model ( GncTreeView view,
GtkTreeModel *  model 
)

Attach a data model to a visible GncTreeView widget. Users of this view object must use this function instead of directly calling the gtk_tree_view_set_model function. This function takes the additional step of attaching a callback function to the model to catch any changes to the sorting of the model. These changes are propagated into gconf by the callback function.

Parameters are defined in gnc-tree-view.h

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

{
    GncTreeViewPrivate *priv;
    GtkTreeModel *old_model;

    /* Remove existing callback */
    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
    if (priv->sort_column_changed_cb_id)
    {
        old_model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
        g_signal_handler_disconnect (old_model, priv->sort_column_changed_cb_id);
        priv->sort_column_changed_cb_id = 0;
    }

    gtk_tree_view_set_model (GTK_TREE_VIEW(view), model);

    /* Maybe add a new callback */
    if (model && priv->gconf_section)
    {
        priv->sort_column_changed_cb_id =
            g_signal_connect(GTK_TREE_SORTABLE(model), "sort-column-changed",
                             (GCallback)gtk_tree_view_sort_column_changed_cb, view);
    }
}
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 "gconf-section" property has not been set.

Parameters are defined in gnc-tree-view.h

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

{
    GncTreeViewPrivate *priv;

    g_return_if_fail(GNC_IS_TREE_VIEW(view));

    ENTER("view %p, show menu %d", view, visible);
    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
    priv->show_column_menu = visible;
    gnc_tree_view_build_column_menu(view);
    LEAVE(" ");
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines