diff --git a/ChangeLog b/ChangeLog index 0adb6a34fe..3c39862f9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Fri May 25 19:04:17 2001 Jonathan Blandford + + * gtk/gtktreeview.c (gtk_tree_view_calc_size): Remove almost all + instances of GtkCellRenderer in code (all but dnd icon code). + Virtualized in GtkTreeViewColumn. Now I need to move focus in + there, and I can do multiple Cells per column. + + * gtk/gtktreeviewcolumn.c: Proxy all cell calls correctly + + * gtk/gtktreemodel.c (gtk_tree_row_reference_new_proxy): fix bug + when model was unreffed prior to removing the row reference. + 2001-05-25 Havoc Pennington * gtk/gtkiconfactory.c: fix so that default icons are created if diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 0adb6a34fe..3c39862f9f 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,15 @@ +Fri May 25 19:04:17 2001 Jonathan Blandford + + * gtk/gtktreeview.c (gtk_tree_view_calc_size): Remove almost all + instances of GtkCellRenderer in code (all but dnd icon code). + Virtualized in GtkTreeViewColumn. Now I need to move focus in + there, and I can do multiple Cells per column. + + * gtk/gtktreeviewcolumn.c: Proxy all cell calls correctly + + * gtk/gtktreemodel.c (gtk_tree_row_reference_new_proxy): fix bug + when model was unreffed prior to removing the row reference. + 2001-05-25 Havoc Pennington * gtk/gtkiconfactory.c: fix so that default icons are created if diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 0adb6a34fe..3c39862f9f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +Fri May 25 19:04:17 2001 Jonathan Blandford + + * gtk/gtktreeview.c (gtk_tree_view_calc_size): Remove almost all + instances of GtkCellRenderer in code (all but dnd icon code). + Virtualized in GtkTreeViewColumn. Now I need to move focus in + there, and I can do multiple Cells per column. + + * gtk/gtktreeviewcolumn.c: Proxy all cell calls correctly + + * gtk/gtktreemodel.c (gtk_tree_row_reference_new_proxy): fix bug + when model was unreffed prior to removing the row reference. + 2001-05-25 Havoc Pennington * gtk/gtkiconfactory.c: fix so that default icons are created if diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 0adb6a34fe..3c39862f9f 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,15 @@ +Fri May 25 19:04:17 2001 Jonathan Blandford + + * gtk/gtktreeview.c (gtk_tree_view_calc_size): Remove almost all + instances of GtkCellRenderer in code (all but dnd icon code). + Virtualized in GtkTreeViewColumn. Now I need to move focus in + there, and I can do multiple Cells per column. + + * gtk/gtktreeviewcolumn.c: Proxy all cell calls correctly + + * gtk/gtktreemodel.c (gtk_tree_row_reference_new_proxy): fix bug + when model was unreffed prior to removing the row reference. + 2001-05-25 Havoc Pennington * gtk/gtkiconfactory.c: fix so that default icons are created if diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 0adb6a34fe..3c39862f9f 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,15 @@ +Fri May 25 19:04:17 2001 Jonathan Blandford + + * gtk/gtktreeview.c (gtk_tree_view_calc_size): Remove almost all + instances of GtkCellRenderer in code (all but dnd icon code). + Virtualized in GtkTreeViewColumn. Now I need to move focus in + there, and I can do multiple Cells per column. + + * gtk/gtktreeviewcolumn.c: Proxy all cell calls correctly + + * gtk/gtktreemodel.c (gtk_tree_row_reference_new_proxy): fix bug + when model was unreffed prior to removing the row reference. + 2001-05-25 Havoc Pennington * gtk/gtkiconfactory.c: fix so that default icons are created if diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 0adb6a34fe..3c39862f9f 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,15 @@ +Fri May 25 19:04:17 2001 Jonathan Blandford + + * gtk/gtktreeview.c (gtk_tree_view_calc_size): Remove almost all + instances of GtkCellRenderer in code (all but dnd icon code). + Virtualized in GtkTreeViewColumn. Now I need to move focus in + there, and I can do multiple Cells per column. + + * gtk/gtktreeviewcolumn.c: Proxy all cell calls correctly + + * gtk/gtktreemodel.c (gtk_tree_row_reference_new_proxy): fix bug + when model was unreffed prior to removing the row reference. + 2001-05-25 Havoc Pennington * gtk/gtkiconfactory.c: fix so that default icons are created if diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 0adb6a34fe..3c39862f9f 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +Fri May 25 19:04:17 2001 Jonathan Blandford + + * gtk/gtktreeview.c (gtk_tree_view_calc_size): Remove almost all + instances of GtkCellRenderer in code (all but dnd icon code). + Virtualized in GtkTreeViewColumn. Now I need to move focus in + there, and I can do multiple Cells per column. + + * gtk/gtktreeviewcolumn.c: Proxy all cell calls correctly + + * gtk/gtktreemodel.c (gtk_tree_row_reference_new_proxy): fix bug + when model was unreffed prior to removing the row reference. + 2001-05-25 Havoc Pennington * gtk/gtkiconfactory.c: fix so that default icons are created if diff --git a/gtk/gtkcellrenderertoggle.c b/gtk/gtkcellrenderertoggle.c index 281c4adbec..f80e9f5f66 100644 --- a/gtk/gtkcellrenderertoggle.c +++ b/gtk/gtkcellrenderertoggle.c @@ -387,5 +387,5 @@ gtk_cell_renderer_toggle_set_active (GtkCellRendererToggle *toggle, { g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle)); - g_object_set (G_OBJECT (toggle), "active", !! setting, NULL); + g_object_set (G_OBJECT (toggle), "active", setting?TRUE:FALSE, NULL); } diff --git a/gtk/gtktreemodel.c b/gtk/gtktreemodel.c index f4a08ec416..244fca757d 100644 --- a/gtk/gtktreemodel.c +++ b/gtk/gtktreemodel.c @@ -1407,6 +1407,8 @@ gtk_tree_row_reference_new_proxy (GObject *proxy, reference = g_new (GtkTreeRowReference, 1); + g_object_ref (proxy); + g_object_ref (model); reference->proxy = proxy; reference->model = model; reference->path = gtk_tree_path_copy (path); @@ -1452,27 +1454,26 @@ gtk_tree_row_reference_free (GtkTreeRowReference *reference) g_return_if_fail (reference != NULL); - if (reference->proxy) + refs = g_object_get_data (G_OBJECT (reference->proxy), ROW_REF_DATA_STRING); + + if (refs == NULL) { - refs = g_object_get_data (G_OBJECT (reference->proxy), ROW_REF_DATA_STRING); - - if (refs == NULL) - { - g_warning (G_STRLOC": bad row reference, proxy has no outstanding row references"); - return; - } - - refs->list = g_slist_remove (refs->list, reference); - - if (refs->list == NULL) - { - disconnect_ref_callbacks (reference->model); - g_object_set_data (G_OBJECT (reference->proxy), - ROW_REF_DATA_STRING, - NULL); - } + g_warning (G_STRLOC": bad row reference, proxy has no outstanding row references"); + return; } + refs->list = g_slist_remove (refs->list, reference); + + if (refs->list == NULL) + { + disconnect_ref_callbacks (reference->model); + g_object_set_data (G_OBJECT (reference->proxy), + ROW_REF_DATA_STRING, + NULL); + } + g_object_unref (reference->proxy); + g_object_unref (reference->model); + if (reference->path) gtk_tree_path_free (reference->path); diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index a6e83137e5..f19424f145 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -992,7 +992,10 @@ gtk_tree_view_size_request_buttons (GtkTreeView *tree_view) for (list = tree_view->priv->columns; list; list = list->next) { GtkRequisition requisition; - GtkTreeViewColumn *column; + GtkTreeViewColumn *column = list->data; + + if (column->button == NULL) + continue; column = list->data; @@ -1215,10 +1218,7 @@ gtk_tree_view_button_press (GtkWidget *widget, for (i = 0, list = tree_view->priv->columns; i < tree_view->priv->n_columns; i++, list = list->next) { - GtkCellRenderer *cell; GtkTreeIter iter; - gboolean visible; - gboolean can_activate; column = list->data; @@ -1238,8 +1238,6 @@ gtk_tree_view_button_press (GtkWidget *widget, cell_area = background_area; } - cell = column->cell; - if ((background_area.x > (gint) event->x) || (background_area.y > (gint) event->y) || (background_area.x + background_area.width <= (gint) event->x) || @@ -1252,22 +1250,17 @@ gtk_tree_view_button_press (GtkWidget *widget, gtk_tree_model_get_iter (tree_view->priv->model, &iter, path); - gtk_tree_view_column_set_cell_data (column, - tree_view->priv->model, - &iter); + gtk_tree_view_column_cell_set_cell_data (column, + tree_view->priv->model, + &iter); path_string = gtk_tree_path_to_string (path); - g_object_get (G_OBJECT (cell), - "visible", &visible, - "can_activate", &can_activate, - NULL); - if (visible && - can_activate && - gtk_cell_renderer_event (cell, (GdkEvent *)event, - widget, path_string, - &background_area, - &cell_area, 0)) + if (gtk_tree_view_column_cell_event (column, + (GdkEvent *)event, + path_string, + &background_area, + &cell_area, 0)) { g_free (path_string); gtk_tree_path_free (path); @@ -2124,7 +2117,7 @@ gtk_tree_view_draw_focus (GtkWidget *widget) cell_area.height = CELL_HEIGHT (node, vertical_separator); gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path); - gtk_tree_view_column_set_cell_data (tree_view->priv->focus_column, tree_view->priv->model, &iter); + gtk_tree_view_column_cell_set_cell_data (tree_view->priv->focus_column, tree_view->priv->model, &iter); gtk_cell_renderer_get_size (tree_view->priv->focus_column->cell, GTK_WIDGET (tree_view), &cell_area, &x_offset, &y_offset, &width, &height); width += 2; @@ -2161,7 +2154,6 @@ gtk_tree_view_bin_expose (GtkWidget *widget, GtkRBNode *drag_highlight = NULL; GtkRBTree *drag_highlight_tree = NULL; GtkTreeIter iter; - GtkCellRenderer *cell; gint new_y; gint y_offset, x_offset, cell_offset; gint i, max_height; @@ -2244,11 +2236,6 @@ gtk_tree_view_bin_expose (GtkWidget *widget, do { - /* Need to think about this more. - if (tree_view->priv->show_expanders) - max_height = MAX (TREE_VIEW_EXPANDER_MIN_HEIGHT, GTK_RBNODE_GET_HEIGHT (node)); - else - */ gboolean parity; max_height = BACKGROUND_HEIGHT (node); @@ -2264,11 +2251,11 @@ gtk_tree_view_bin_expose (GtkWidget *widget, if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_PRELIT)) flags |= GTK_CELL_RENDERER_PRELIT; - parity = _gtk_rbtree_node_find_parity (tree, node); - if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED)) flags |= GTK_CELL_RENDERER_SELECTED; + parity = _gtk_rbtree_node_find_parity (tree, node); + for (i = 0, list = tree_view->priv->columns; i < tree_view->priv->n_columns; i++, list = list->next) { GtkTreeViewColumn *column = list->data; @@ -2289,10 +2276,9 @@ gtk_tree_view_bin_expose (GtkWidget *widget, else flags &= ~GTK_CELL_RENDERER_SORTED; - cell = column->cell; - gtk_tree_view_column_set_cell_data (column, - tree_view->priv->model, - &iter); + gtk_tree_view_column_cell_set_cell_data (column, + tree_view->priv->model, + &iter); background_area.x = cell_offset; background_area.width = column->displayed_width; @@ -2363,8 +2349,6 @@ gtk_tree_view_bin_expose (GtkWidget *widget, if (i == tree_view->priv->expander_column && TREE_VIEW_DRAW_EXPANDERS(tree_view)) { - gboolean visible; - cell_area.x += depth*tree_view->priv->tab_offset; cell_area.width -= depth*tree_view->priv->tab_offset; @@ -2374,16 +2358,12 @@ gtk_tree_view_bin_expose (GtkWidget *widget, */ highlight_x = cell_area.x; - g_object_get (G_OBJECT (cell), "visible", &visible, NULL); - if (visible) - gtk_cell_renderer_render (cell, - event->window, - widget, - &background_area, - &cell_area, - &event->area, - flags); - + gtk_tree_view_column_cell_render (column, + event->window, + &background_area, + &cell_area, + &event->area, + flags); if ((node->flags & GTK_RBNODE_IS_PARENT) == GTK_RBNODE_IS_PARENT) { gint x, y; @@ -2396,17 +2376,12 @@ gtk_tree_view_bin_expose (GtkWidget *widget, } else { - gboolean visible; - g_object_get (G_OBJECT (cell), "visible", &visible, NULL); - - if (visible) - gtk_cell_renderer_render (cell, - event->window, - widget, - &background_area, - &cell_area, - &event->area, - flags); + gtk_tree_view_column_cell_render (column, + event->window, + &background_area, + &cell_area, + &event->area, + flags); } cell_offset += column->displayed_width; } @@ -2479,7 +2454,6 @@ gtk_tree_view_bin_expose (GtkWidget *widget, has_child = gtk_tree_model_iter_children (tree_view->priv->model, &iter, &parent); - cell = gtk_tree_view_get_column (tree_view, 0)->cell; depth++; /* Sanity Check! */ @@ -2494,7 +2468,6 @@ gtk_tree_view_bin_expose (GtkWidget *widget, if (node != NULL) { gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter); - cell = gtk_tree_view_get_column (tree_view, 0)->cell; done = TRUE; /* Sanity Check! */ @@ -4116,6 +4089,7 @@ gtk_tree_view_range_changed (GtkTreeModel *model, gboolean free_path = FALSE; gint vertical_separator; + g_return_if_fail (path != NULL || iter != NULL); gtk_widget_style_get (GTK_WIDGET (data), "vertical_separator", &vertical_separator, NULL); @@ -4152,9 +4126,7 @@ gtk_tree_view_range_changed (GtkTreeModel *model, if (dirty_marked) gtk_widget_queue_resize (GTK_WIDGET (data)); else - { - gtk_tree_view_queue_draw_node (tree_view, tree, node, NULL); - } + gtk_tree_view_queue_draw_node (tree_view, tree, node, NULL); done: if (free_path) @@ -4663,7 +4635,6 @@ gtk_tree_view_insert_iter_height (GtkTreeView *tree_view, gint depth) { GtkTreeViewColumn *column; - GtkCellRenderer *cell; GList *list; gint max_height = 0; gint i; @@ -4687,10 +4658,9 @@ gtk_tree_view_insert_iter_height (GtkTreeView *tree_view, continue; } - cell = column->cell; - gtk_tree_view_column_set_cell_data (column, tree_view->priv->model, iter); + gtk_tree_view_column_cell_set_cell_data (column, tree_view->priv->model, iter); - gtk_cell_renderer_get_size (cell, GTK_WIDGET (tree_view), NULL, NULL, NULL, &width, &height); + gtk_tree_view_column_cell_get_size (column, NULL, NULL, NULL, &width, &height); max_height = MAX (max_height, vertical_separator + height); if (i == tree_view->priv->expander_column && @@ -4758,7 +4728,6 @@ gtk_tree_view_calc_size (GtkTreeView *tree_view, { GtkRBNode *temp; GtkTreeIter child; - GtkCellRenderer *cell; GList *list; GtkTreeViewColumn *column; gint max_height; @@ -4785,9 +4754,8 @@ gtk_tree_view_calc_size (GtkTreeView *tree_view, if (!column->visible) continue; - gtk_tree_view_column_set_cell_data (column, tree_view->priv->model, iter); - cell = column->cell; - gtk_cell_renderer_get_size (cell, GTK_WIDGET (tree_view), NULL, NULL, NULL, &width, &height); + gtk_tree_view_column_cell_set_cell_data (column, tree_view->priv->model, iter); + gtk_tree_view_column_cell_get_size (column, NULL, NULL, NULL, &width, &height); max_height = MAX (max_height, vertical_separator + height); /* FIXME: I'm getting the width of all nodes here. )-: */ @@ -4822,7 +4790,6 @@ gtk_tree_view_discover_dirty_iter (GtkTreeView *tree_view, gint depth, gint *height) { - GtkCellRenderer *cell; GtkTreeViewColumn *column; GList *list; gint i; @@ -4841,17 +4808,20 @@ gtk_tree_view_discover_dirty_iter (GtkTreeView *tree_view, if (!column->visible) continue; - cell = column->cell; - gtk_tree_view_column_set_cell_data (column, tree_view->priv->model, iter); + gtk_tree_view_column_cell_set_cell_data (column, tree_view->priv->model, iter); if (height) { - gtk_cell_renderer_get_size (cell, GTK_WIDGET (tree_view), NULL, NULL, NULL, &width, &tmpheight); + gtk_tree_view_column_cell_get_size (column, + NULL, NULL, NULL, + &width, &tmpheight); *height = MAX (*height, tmpheight); } else { - gtk_cell_renderer_get_size (cell, GTK_WIDGET (tree_view), NULL, NULL, NULL, &width, NULL); + gtk_tree_view_column_cell_get_size (column, + NULL, NULL, NULL, + &width, NULL); } if (i == tree_view->priv->expander_column && TREE_VIEW_DRAW_EXPANDERS (tree_view)) @@ -5140,7 +5110,7 @@ gtk_tree_view_set_column_drag_info (GtkTreeView *tree_view, GtkTreeViewColumn *column) { GtkTreeViewColumn *left_column; - GtkTreeViewColumn *cur_column; + GtkTreeViewColumn *cur_column = NULL; GtkTreeViewColumnReorder *reorder; GList *tmp_list; @@ -7548,9 +7518,9 @@ gtk_tree_view_create_row_drag_icon (GtkTreeView *tree_view, continue; cell = column->cell; - gtk_tree_view_column_set_cell_data (column, - tree_view->priv->model, - &iter); + gtk_tree_view_column_cell_set_cell_data (column, + tree_view->priv->model, + &iter); background_area.x = cell_offset; background_area.width = column->displayed_width; diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c index 824f1c19c9..b3ec91e44e 100644 --- a/gtk/gtktreeviewcolumn.c +++ b/gtk/gtktreeviewcolumn.c @@ -376,6 +376,11 @@ gtk_tree_view_column_set_property (GObject *object, g_value_get_float (value)); break; + case PROP_REORDERABLE: + gtk_tree_view_column_set_reorderable (tree_column, + g_value_get_boolean (value)); + break; + case PROP_SORT_INDICATOR: gtk_tree_view_column_set_sort_indicator (tree_column, g_value_get_boolean (value)); @@ -454,6 +459,11 @@ gtk_tree_view_column_get_property (GObject *object, gtk_tree_view_column_get_alignment (tree_column)); break; + case PROP_REORDERABLE: + g_value_set_boolean (value, + gtk_tree_view_column_get_reorderable (tree_column)); + break; + case PROP_SORT_INDICATOR: g_value_set_boolean (value, gtk_tree_view_column_get_sort_indicator (tree_column)); @@ -494,6 +504,8 @@ gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column) /* make sure we own a reference to it as well. */ gtk_widget_set_parent (tree_column->button, GTK_WIDGET (tree_view)); + if (tree_view->priv->header_window) + gtk_widget_set_parent_window (tree_column->button, tree_view->priv->header_window); gtk_signal_connect (GTK_OBJECT (tree_column->button), "realize", (GtkSignalFunc) gtk_tree_view_column_button_realize, @@ -643,7 +655,7 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column) { if (tree_column->visible) { - gtk_widget_show (tree_column->button); + gtk_widget_show_now (tree_column->button); if (tree_column->window) { if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_RESIZEABLE) @@ -666,9 +678,15 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column) } if (tree_column->reorderable || tree_column->clickable) - GTK_WIDGET_SET_FLAGS (tree_column->button, GTK_CAN_FOCUS); + { + GTK_WIDGET_SET_FLAGS (tree_column->button, GTK_CAN_FOCUS); + } else - GTK_WIDGET_UNSET_FLAGS (tree_column->button, GTK_CAN_FOCUS); + { + GTK_WIDGET_UNSET_FLAGS (tree_column->button, GTK_CAN_FOCUS); + if (GTK_WIDGET_HAS_FOCUS (tree_column->button)) + gtk_window_set_focus (GTK_WINDOW (gtk_widget_get_toplevel (tree_column->tree_view)), NULL); + } tree_column->dirty = TRUE; gtk_widget_queue_resize (tree_column->tree_view); @@ -1253,55 +1271,6 @@ gtk_tree_view_column_clear_attributes (GtkTreeViewColumn *tree_column) } } -/** - * gtk_tree_view_column_set_cell_data: - * @tree_column: A #GtkTreeViewColumn. - * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from. - * @iter: The #GtkTreeIter to to get the cell renderer's attributes from. - * - * Sets the cell renderer based on the @tree_model and @tree_node. That is, for - * every attribute mapping in @tree_column, it will get a value from the set - * column on the @tree_node, and use that value to set the attribute on the cell - * renderer. - **/ -void -gtk_tree_view_column_set_cell_data (GtkTreeViewColumn *tree_column, - GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - GSList *list; - GValue value = { 0, }; - GObject *cell; - - g_return_if_fail (tree_column != NULL); - g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column)); - g_return_if_fail (tree_column->cell != NULL); - - if (tree_model == NULL) - return; - - cell = (GObject *) tree_column->cell; - list = tree_column->attributes; - - g_object_freeze_notify (cell); - - while (list && list->next) - { - gtk_tree_model_get_value (tree_model, iter, - GPOINTER_TO_INT (list->next->data), - &value); - g_object_set_property (cell, (gchar *) list->data, &value); - g_value_unset (&value); - list = list->next->next; - - } - - if (tree_column->func) - (* tree_column->func) (tree_column, tree_column->cell, tree_model, iter, tree_column->func_data); - - g_object_thaw_notify (cell); -} - /* Options for manipulating the columns */ /** @@ -1916,3 +1885,162 @@ gtk_tree_view_column_get_sort_order (GtkTreeViewColumn *tree_column) + +/** + * gtk_tree_view_column_cell_set_cell_data: + * @tree_column: A #GtkTreeViewColumn. + * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from. + * @iter: The #GtkTreeIter to to get the cell renderer's attributes from. + * + * Sets the cell renderer based on the @tree_model and @tree_node. That is, for + * every attribute mapping in @tree_column, it will get a value from the set + * column on the @tree_node, and use that value to set the attribute on the cell + * renderer. This is used primarily by the GtkTreeView. + **/ +void +gtk_tree_view_column_cell_set_cell_data (GtkTreeViewColumn *tree_column, + GtkTreeModel *tree_model, + GtkTreeIter *iter) +{ + GSList *list; + GValue value = { 0, }; + GObject *cell; + + g_return_if_fail (tree_column != NULL); + g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column)); + g_return_if_fail (tree_column->cell != NULL); + + if (tree_model == NULL) + return; + + cell = (GObject *) tree_column->cell; + list = tree_column->attributes; + + g_object_freeze_notify (cell); + + while (list && list->next) + { + gtk_tree_model_get_value (tree_model, iter, + GPOINTER_TO_INT (list->next->data), + &value); + g_object_set_property (cell, (gchar *) list->data, &value); + g_value_unset (&value); + list = list->next->next; + + } + + if (tree_column->func) + (* tree_column->func) (tree_column, tree_column->cell, tree_model, iter, tree_column->func_data); + + g_object_thaw_notify (cell); +} + +/** + * gtk_tree_view_column_cell_get_size: + * @tree_column: A #GtkTreeViewColumn. + * @cell_area: The area a the column will be allocated, or %NULL + * @x_offset: location to return x offset of cell relative to @cell_area, or %NULL + * @y_offset: location to return y offset of cell relative to @cell_area, or %NULL + * @width: location to return width needed to render a cell, or %NULL + * @height: location to return height needed to render a cell, or %NULL + * + * Obtains the width and height needed to render the column. This is used + * primarily by the GtkTreeView. + **/ +void +gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column, + GdkRectangle *cell_area, + gint *x_offset, + gint *y_offset, + gint *width, + gint *height) +{ + g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column)); + + gtk_cell_renderer_get_size (tree_column->cell, + tree_column->tree_view, + cell_area, + x_offset, + y_offset, + width, + height); + +} + +/** + * gtk_tree_view_column_cell_render: + * @tree_column: A #GtkTreeViewColumn. + * @window: a #GdkDrawable to draw to + * @background_area: entire cell area (including tree expanders and maybe padding on the sides) + * @cell_area: area normally rendered by a cell renderer + * @expose_area: area that actually needs updating + * @flags: flags that affect rendering + * + * Renders the cell contained by #tree_column. This is used primarily by the + * GtkTreeView. + **/ +void +gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column, + GdkWindow *window, + GdkRectangle *background_area, + GdkRectangle *cell_area, + GdkRectangle *expose_area, + guint flags) +{ + gboolean visible; + g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column)); + + g_object_get (G_OBJECT (tree_column->cell), "visible", &visible, NULL); + if (visible) + gtk_cell_renderer_render (tree_column->cell, + window, + tree_column->tree_view, + background_area, + cell_area, + expose_area, + flags); +} + +/** + * gtk_tree_view_column_cell_event: + * @tree_column: A #GtkTreeViewColumn. + * @event: a #GdkEvent + * @path_string: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath + * @background_area: background area as passed to gtk_cell_renderer_render() + * @cell_area: cell area as passed to gtk_cell_renderer_render() + * @flags: render flags + * + * Handles an event. This is used primarily by the GtkTreeView. + * + * Return value: %TRUE if the event was consumed/handled + **/ +gboolean +gtk_tree_view_column_cell_event (GtkTreeViewColumn *tree_column, + GdkEvent *event, + gchar *path_string, + GdkRectangle *background_area, + GdkRectangle *cell_area, + guint flags) +{ + gboolean visible, can_activate; + + g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE); + + g_object_get (G_OBJECT (tree_column->cell), + "visible", &visible, + "can_activate", &can_activate, + NULL); + if (visible && can_activate) + { + if (gtk_cell_renderer_event (tree_column->cell, + event, + tree_column->tree_view, + path_string, + background_area, + cell_area, + flags)) + return TRUE; + + } + return FALSE; +} diff --git a/gtk/gtktreeviewcolumn.h b/gtk/gtktreeviewcolumn.h index 2ee09b77db..a3fa3c45f2 100644 --- a/gtk/gtktreeviewcolumn.h +++ b/gtk/gtktreeviewcolumn.h @@ -106,78 +106,99 @@ struct _GtkTreeViewColumnClass }; -GtkType gtk_tree_view_column_get_type (void); -GtkTreeViewColumn *gtk_tree_view_column_new (void); -GtkTreeViewColumn *gtk_tree_view_column_new_with_attributes (const gchar *title, - GtkCellRenderer *cell, - ...); -void gtk_tree_view_column_set_cell_renderer (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell); -GtkCellRenderer *gtk_tree_view_column_get_cell_renderer (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_add_attribute (GtkTreeViewColumn *tree_column, - const gchar *attribute, - gint column); -void gtk_tree_view_column_set_attributes (GtkTreeViewColumn *tree_column, - ...); -void gtk_tree_view_column_set_cell_data_func (GtkTreeViewColumn *tree_column, - GtkCellDataFunc func, - gpointer func_data, - GtkDestroyNotify destroy); -void gtk_tree_view_column_clear_attributes (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_cell_data (GtkTreeViewColumn *tree_column, - GtkTreeModel *tree_model, - GtkTreeIter *iter); -void gtk_tree_view_column_set_visible (GtkTreeViewColumn *tree_column, - gboolean visible); -gboolean gtk_tree_view_column_get_visible (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_sizing (GtkTreeViewColumn *tree_column, - GtkTreeViewColumnSizing type); -gint gtk_tree_view_column_get_sizing (GtkTreeViewColumn *tree_column); -gint gtk_tree_view_column_get_width (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_width (GtkTreeViewColumn *tree_column, - gint size); -void gtk_tree_view_column_set_min_width (GtkTreeViewColumn *tree_column, - gint min_width); -gint gtk_tree_view_column_get_min_width (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_max_width (GtkTreeViewColumn *tree_column, - gint max_width); -gint gtk_tree_view_column_get_max_width (GtkTreeViewColumn *tree_column); +GtkType gtk_tree_view_column_get_type (void); +GtkTreeViewColumn *gtk_tree_view_column_new (void); +GtkTreeViewColumn *gtk_tree_view_column_new_with_attributes (const gchar *title, + GtkCellRenderer *cell, + ...); +void gtk_tree_view_column_set_cell_renderer (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell); +GtkCellRenderer *gtk_tree_view_column_get_cell_renderer (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_add_attribute (GtkTreeViewColumn *tree_column, + const gchar *attribute, + gint column); +void gtk_tree_view_column_set_attributes (GtkTreeViewColumn *tree_column, + ...); +void gtk_tree_view_column_set_cell_data_func (GtkTreeViewColumn *tree_column, + GtkCellDataFunc func, + gpointer func_data, + GtkDestroyNotify destroy); +void gtk_tree_view_column_clear_attributes (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_visible (GtkTreeViewColumn *tree_column, + gboolean visible); +gboolean gtk_tree_view_column_get_visible (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_sizing (GtkTreeViewColumn *tree_column, + GtkTreeViewColumnSizing type); +gint gtk_tree_view_column_get_sizing (GtkTreeViewColumn *tree_column); +gint gtk_tree_view_column_get_width (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_width (GtkTreeViewColumn *tree_column, + gint size); +void gtk_tree_view_column_set_min_width (GtkTreeViewColumn *tree_column, + gint min_width); +gint gtk_tree_view_column_get_min_width (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_max_width (GtkTreeViewColumn *tree_column, + gint max_width); +gint gtk_tree_view_column_get_max_width (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_clicked (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_clicked (GtkTreeViewColumn *tree_column); - /* Options for manipulating the column headers */ -void gtk_tree_view_column_set_title (GtkTreeViewColumn *tree_column, - const gchar *title); -G_CONST_RETURN gchar *gtk_tree_view_column_get_title (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_clickable (GtkTreeViewColumn *tree_column, - gboolean clickable); -gboolean gtk_tree_view_column_get_clickable (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_widget (GtkTreeViewColumn *tree_column, - GtkWidget *widget); -GtkWidget *gtk_tree_view_column_get_widget (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_alignment (GtkTreeViewColumn *tree_column, - gfloat xalign); -gfloat gtk_tree_view_column_get_alignment (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_reorderable (GtkTreeViewColumn *tree_column, - gboolean reorderable); -gboolean gtk_tree_view_column_get_reorderable (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_title (GtkTreeViewColumn *tree_column, + const gchar *title); +G_CONST_RETURN gchar *gtk_tree_view_column_get_title (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_clickable (GtkTreeViewColumn *tree_column, + gboolean clickable); +gboolean gtk_tree_view_column_get_clickable (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_widget (GtkTreeViewColumn *tree_column, + GtkWidget *widget); +GtkWidget *gtk_tree_view_column_get_widget (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_alignment (GtkTreeViewColumn *tree_column, + gfloat xalign); +gfloat gtk_tree_view_column_get_alignment (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_reorderable (GtkTreeViewColumn *tree_column, + gboolean reorderable); +gboolean gtk_tree_view_column_get_reorderable (GtkTreeViewColumn *tree_column); + /* You probably only want to use gtk_tree_view_column_set_sort_column_id. The * other sorting functions exist primarily to let others do their own custom sorting. */ +void gtk_tree_view_column_set_sort_column_id (GtkTreeViewColumn *tree_column, + gint sort_column_id); +void gtk_tree_view_column_set_sort_indicator (GtkTreeViewColumn *tree_column, + gboolean setting); +gboolean gtk_tree_view_column_get_sort_indicator (GtkTreeViewColumn *tree_column); +void gtk_tree_view_column_set_sort_order (GtkTreeViewColumn *tree_column, + GtkTreeSortOrder order); +GtkTreeSortOrder gtk_tree_view_column_get_sort_order (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_sort_column_id (GtkTreeViewColumn *tree_column, - gint sort_column_id); -void gtk_tree_view_column_set_sort_indicator (GtkTreeViewColumn *tree_column, - gboolean setting); -gboolean gtk_tree_view_column_get_sort_indicator (GtkTreeViewColumn *tree_column); -void gtk_tree_view_column_set_sort_order (GtkTreeViewColumn *tree_column, - GtkTreeSortOrder order); -GtkTreeSortOrder gtk_tree_view_column_get_sort_order (GtkTreeViewColumn *tree_column); +/* These functions are meant primarily for interaction between the GtkTreeView and the column. + */ +void gtk_tree_view_column_cell_set_cell_data (GtkTreeViewColumn *tree_column, + GtkTreeModel *tree_model, + GtkTreeIter *iter); +void gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column, + GdkRectangle *cell_area, + gint *x_offset, + gint *y_offset, + gint *width, + gint *height); +void gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column, + GdkWindow *window, + GdkRectangle *background_area, + GdkRectangle *cell_area, + GdkRectangle *expose_area, + guint flags); +gboolean gtk_tree_view_column_cell_event (GtkTreeViewColumn *tree_column, + GdkEvent *event, + gchar *path_string, + GdkRectangle *background_area, + GdkRectangle *cell_area, + guint flags); + diff --git a/tests/testtreecolumns.c b/tests/testtreecolumns.c index eabfb3b0bd..7c9c788307 100644 --- a/tests/testtreecolumns.c +++ b/tests/testtreecolumns.c @@ -421,7 +421,7 @@ get_visible (GtkTreeViewColumn *tree_column, if (column) { gtk_cell_renderer_toggle_set_active (GTK_CELL_RENDERER_TOGGLE (cell), - column->visible); + gtk_tree_view_column_get_visible (column)); } } diff --git a/tests/testtreeview.c b/tests/testtreeview.c index 24d64165b8..ee582c9561 100644 --- a/tests/testtreeview.c +++ b/tests/testtreeview.c @@ -158,6 +158,7 @@ col_clicked_cb (GtkTreeViewColumn *col, gpointer data) static void setup_column (GtkTreeViewColumn *col) { + gtk_tree_view_column_set_clickable (col, TRUE); g_signal_connect_data (G_OBJECT (col), "clicked", (GCallback) col_clicked_cb,