X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtktreeviewcolumn.c;h=70dfd24258be80b4ec09a8367317307058304631;hb=f35439bfacf90900e2c24f7ae3da173183c79d34;hp=f221a5e549d9f86c458c0fb989abae3e02ccffde;hpb=864c47e7dc6607b2eb679f155fd5327f062ddcff;p=~andy%2Fgtk diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c index f221a5e54..70dfd2425 100644 --- a/gtk/gtktreeviewcolumn.c +++ b/gtk/gtktreeviewcolumn.c @@ -19,7 +19,6 @@ #include #include -#include "gtkalias.h" #include "gtktreeviewcolumn.h" #include "gtktreeview.h" #include "gtktreeprivate.h" @@ -30,7 +29,9 @@ #include "gtkhbox.h" #include "gtkmarshalers.h" #include "gtkarrow.h" +#include "gtkprivate.h" #include "gtkintl.h" +#include "gtkalias.h" enum { @@ -76,8 +77,6 @@ struct _GtkTreeViewColumnCellInfo }; /* Type methods */ -static void gtk_tree_view_column_init (GtkTreeViewColumn *tree_column); -static void gtk_tree_view_column_class_init (GtkTreeViewColumnClass *klass); static void gtk_tree_view_column_cell_layout_init (GtkCellLayoutIface *iface); /* GObject methods */ @@ -113,6 +112,7 @@ static void gtk_tree_view_column_cell_layout_clear_attributes (GtkCellLayout static void gtk_tree_view_column_cell_layout_reorder (GtkCellLayout *cell_layout, GtkCellRenderer *cell, gint position); +static GList *gtk_tree_view_column_cell_layout_get_cells (GtkCellLayout *cell_layout); /* Button handling code */ static void gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column); @@ -151,49 +151,17 @@ static GList *gtk_tree_view_column_cell_prev (GtkTreeViewColum GList *current); static void gtk_tree_view_column_clear_attributes_by_info (GtkTreeViewColumn *tree_column, GtkTreeViewColumnCellInfo *info); +/* GtkBuildable implementation */ +static void gtk_tree_view_column_buildable_init (GtkBuildableIface *iface); -static GtkObjectClass *parent_class = NULL; static guint tree_column_signals[LAST_SIGNAL] = { 0 }; +G_DEFINE_TYPE_WITH_CODE (GtkTreeViewColumn, gtk_tree_view_column, GTK_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT, + gtk_tree_view_column_cell_layout_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, + gtk_tree_view_column_buildable_init)) -GType -gtk_tree_view_column_get_type (void) -{ - static GType tree_column_type = 0; - - if (!tree_column_type) - { - static const GTypeInfo tree_column_info = - { - sizeof (GtkTreeViewColumnClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) gtk_tree_view_column_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GtkTreeViewColumn), - 0, - (GInstanceInitFunc) gtk_tree_view_column_init - }; - - static const GInterfaceInfo cell_layout_info = - { - (GInterfaceInitFunc) gtk_tree_view_column_cell_layout_init, - NULL, - NULL - }; - - tree_column_type = - g_type_register_static (GTK_TYPE_OBJECT, "GtkTreeViewColumn", - &tree_column_info, 0); - - g_type_add_interface_static (tree_column_type, - GTK_TYPE_CELL_LAYOUT, - &cell_layout_info); - } - - return tree_column_type; -} static void gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) @@ -202,8 +170,6 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) object_class = (GObjectClass*) class; - parent_class = g_type_class_peek_parent (class); - class->clicked = NULL; object_class->finalize = gtk_tree_view_column_finalize; @@ -211,7 +177,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) object_class->get_property = gtk_tree_view_column_get_property; tree_column_signals[CLICKED] = - g_signal_new ("clicked", + g_signal_new (I_("clicked"), G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GtkTreeViewColumnClass, clicked), @@ -225,7 +191,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) P_("Visible"), P_("Whether to display the column"), TRUE, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_RESIZABLE, @@ -233,7 +199,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) P_("Resizable"), P_("Column is user-resizable"), FALSE, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_WIDTH, @@ -243,7 +209,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) 0, G_MAXINT, 0, - G_PARAM_READABLE)); + GTK_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_SPACING, g_param_spec_int ("spacing", @@ -252,7 +218,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) 0, G_MAXINT, 0, - G_PARAM_READWRITE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_SIZING, g_param_spec_enum ("sizing", @@ -260,37 +226,37 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) P_("Resize mode of the column"), GTK_TYPE_TREE_VIEW_COLUMN_SIZING, GTK_TREE_VIEW_COLUMN_GROW_ONLY, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_FIXED_WIDTH, - g_param_spec_int ("fixed_width", + g_param_spec_int ("fixed-width", P_("Fixed Width"), P_("Current fixed width of the column"), 1, G_MAXINT, 1, /* not useful */ - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_MIN_WIDTH, - g_param_spec_int ("min_width", + g_param_spec_int ("min-width", P_("Minimum Width"), P_("Minimum allowed width of the column"), -1, G_MAXINT, -1, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_MAX_WIDTH, - g_param_spec_int ("max_width", + g_param_spec_int ("max-width", P_("Maximum Width"), P_("Maximum allowed width of the column"), -1, G_MAXINT, -1, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_TITLE, @@ -298,7 +264,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) P_("Title"), P_("Title to appear in column header"), "", - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_EXPAND, @@ -306,7 +272,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) P_("Expand"), P_("Column gets share of extra width allocated to the widget"), FALSE, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_CLICKABLE, @@ -314,7 +280,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) P_("Clickable"), P_("Whether the header can be clicked"), FALSE, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, @@ -323,7 +289,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) P_("Widget"), P_("Widget to put in column header button instead of column title"), GTK_TYPE_WIDGET, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_ALIGNMENT, @@ -333,7 +299,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) 0.0, 1.0, 0.0, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_REORDERABLE, @@ -341,27 +307,35 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) P_("Reorderable"), P_("Whether the column can be reordered around the headers"), FALSE, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_SORT_INDICATOR, - g_param_spec_boolean ("sort_indicator", + g_param_spec_boolean ("sort-indicator", P_("Sort indicator"), P_("Whether to show a sort indicator"), FALSE, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_SORT_ORDER, - g_param_spec_enum ("sort_order", + g_param_spec_enum ("sort-order", P_("Sort order"), P_("Sort direction the sort indicator should indicate"), GTK_TYPE_SORT_TYPE, GTK_SORT_ASCENDING, - G_PARAM_READABLE | G_PARAM_WRITABLE)); + GTK_PARAM_READWRITE)); } +static void +gtk_tree_view_column_buildable_init (GtkBuildableIface *iface) +{ + iface->add_child = _gtk_cell_layout_buildable_add_child; + iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start; + iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end; +} + static void gtk_tree_view_column_cell_layout_init (GtkCellLayoutIface *iface) { @@ -372,6 +346,7 @@ gtk_tree_view_column_cell_layout_init (GtkCellLayoutIface *iface) iface->set_cell_data_func = gtk_tree_view_column_cell_layout_set_cell_data_func; iface->clear_attributes = gtk_tree_view_column_cell_layout_clear_attributes; iface->reorder = gtk_tree_view_column_cell_layout_reorder; + iface->get_cells = gtk_tree_view_column_cell_layout_get_cells; } static void @@ -432,7 +407,7 @@ gtk_tree_view_column_finalize (GObject *object) if (tree_column->child) g_object_unref (tree_column->child); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (gtk_tree_view_column_parent_class)->finalize (object); } static void @@ -641,8 +616,7 @@ gtk_tree_view_column_cell_layout_pack_start (GtkCellLayout *cell_layout, column = GTK_TREE_VIEW_COLUMN (cell_layout); g_return_if_fail (! gtk_tree_view_column_get_cell_info (column, cell)); - g_object_ref (cell); - gtk_object_sink (GTK_OBJECT (cell)); + g_object_ref_sink (cell); cell_info = g_new0 (GtkTreeViewColumnCellInfo, 1); cell_info->cell = cell; @@ -666,8 +640,7 @@ gtk_tree_view_column_cell_layout_pack_end (GtkCellLayout *cell_layout, column = GTK_TREE_VIEW_COLUMN (cell_layout); g_return_if_fail (! gtk_tree_view_column_get_cell_info (column, cell)); - g_object_ref (cell); - gtk_object_sink (GTK_OBJECT (cell)); + g_object_ref_sink (cell); cell_info = g_new0 (GtkTreeViewColumnCellInfo, 1); cell_info->cell = cell; @@ -692,7 +665,7 @@ gtk_tree_view_column_cell_layout_clear (GtkCellLayout *cell_layout) GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *)column->cell_list->data; gtk_tree_view_column_cell_layout_clear_attributes (cell_layout, info->cell); - g_object_unref (G_OBJECT (info->cell)); + g_object_unref (info->cell); g_free (info); column->cell_list = g_list_delete_link (column->cell_list, column->cell_list); @@ -789,10 +762,11 @@ gtk_tree_view_column_cell_layout_reorder (GtkCellLayout *cell_layout, g_return_if_fail (link != NULL); - column->cell_list = g_list_remove_link (column->cell_list, link); + column->cell_list = g_list_delete_link (column->cell_list, link); column->cell_list = g_list_insert (column->cell_list, info, position); - gtk_widget_queue_draw (column->tree_view); + if (column->tree_view) + gtk_widget_queue_draw (column->tree_view); } static void @@ -884,10 +858,18 @@ gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column) static void gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column) { + gint sort_column_id = -1; GtkWidget *hbox; GtkWidget *alignment; GtkWidget *arrow; GtkWidget *current_child; + GtkArrowType arrow_type = GTK_ARROW_NONE; + GtkTreeModel *model; + + if (tree_column->tree_view) + model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_column->tree_view)); + else + model = NULL; /* Create a button if necessary */ if (tree_column->visible && @@ -938,25 +920,39 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column) ""); } - switch (tree_column->sort_order) + if (GTK_IS_TREE_SORTABLE (model)) + gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model), + &sort_column_id, + NULL); + + if (tree_column->show_sort_indicator) { - case GTK_SORT_ASCENDING: - gtk_arrow_set (GTK_ARROW (arrow), - GTK_ARROW_DOWN, - GTK_SHADOW_IN); - break; + gboolean alternative; - case GTK_SORT_DESCENDING: - gtk_arrow_set (GTK_ARROW (arrow), - GTK_ARROW_UP, - GTK_SHADOW_IN); - break; - - default: - g_warning (G_STRLOC": bad sort order"); - break; + g_object_get (gtk_widget_get_settings (tree_column->tree_view), + "gtk-alternative-sort-arrows", &alternative, + NULL); + + switch (tree_column->sort_order) + { + case GTK_SORT_ASCENDING: + arrow_type = alternative ? GTK_ARROW_UP : GTK_ARROW_DOWN; + break; + + case GTK_SORT_DESCENDING: + arrow_type = alternative ? GTK_ARROW_DOWN : GTK_ARROW_UP; + break; + + default: + g_warning (G_STRLOC": bad sort order"); + break; + } } + gtk_arrow_set (GTK_ARROW (arrow), + arrow_type, + GTK_SHADOW_IN); + /* Put arrow on the right if the text is left-or-center justified, and on the * left otherwise; do this by packing boxes, so flipping text direction will * reverse things @@ -976,7 +972,8 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column) } g_object_unref (arrow); - if (tree_column->show_sort_indicator) + if (tree_column->show_sort_indicator + || (GTK_IS_TREE_SORTABLE (model) && tree_column->sort_column_id >= 0)) gtk_widget_show (arrow); else gtk_widget_hide (arrow); @@ -1048,22 +1045,23 @@ gtk_tree_view_column_button_event (GtkWidget *widget, g_return_val_if_fail (event != NULL, FALSE); if (event->type == GDK_BUTTON_PRESS && - column->reorderable) + column->reorderable && + ((GdkEventButton *)event)->button == 1) { column->maybe_reordered = TRUE; - gdk_window_get_pointer (widget->window, + gdk_window_get_pointer (GTK_BUTTON (widget)->event_window, &column->drag_x, &column->drag_y, NULL); gtk_widget_grab_focus (widget); } - if (event->type == GDK_BUTTON_RELEASE && - column->maybe_reordered) + if (event->type == GDK_BUTTON_RELEASE || + event->type == GDK_LEAVE_NOTIFY) column->maybe_reordered = FALSE; - + if (event->type == GDK_MOTION_NOTIFY && - (column->maybe_reordered) && + column->maybe_reordered && (gtk_drag_check_threshold (widget, column->drag_x, column->drag_y, @@ -1071,10 +1069,6 @@ gtk_tree_view_column_button_event (GtkWidget *widget, (gint) ((GdkEventMotion *)event)->y))) { column->maybe_reordered = FALSE; - /* this is to change our drag_x to be relative to - * tree_view->priv->bin_window, instead of our window. - */ - column->drag_x -= column->button->allocation.x; _gtk_tree_view_column_start_drag (GTK_TREE_VIEW (column->tree_view), column); return TRUE; } @@ -1277,7 +1271,7 @@ _gtk_tree_view_column_realize_button (GtkTreeViewColumn *column) attr.width = TREE_VIEW_DRAG_WIDTH; attr.height = tree_view->priv->header_height; - attr.x = (column->button->allocation.x + (rtl ? 0 : column->button->allocation.width)) - 3; + attr.x = (column->button->allocation.x + (rtl ? 0 : column->button->allocation.width)) - TREE_VIEW_DRAG_WIDTH / 2; column->window = gdk_window_new (tree_view->priv->header_window, &attr, attributes_mask); gdk_window_set_user_data (column->window, tree_view); @@ -1449,12 +1443,12 @@ gtk_tree_view_column_new (void) * gtk_tree_view_column_set_attributes() on the newly created #GtkTreeViewColumn. * * Here's a simple example: - * + * |[ * enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS }; * ... * { * GtkTreeViewColumn *column; - * GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + * GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); * * column = gtk_tree_view_column_new_with_attributes ("Title", * renderer, @@ -1462,7 +1456,7 @@ gtk_tree_view_column_new (void) * "foreground", COLOR_COLUMN, * NULL); * } - * + * ]| * * Return value: A newly created #GtkTreeViewColumn. **/ @@ -1572,6 +1566,12 @@ gtk_tree_view_column_get_cell_renderers (GtkTreeViewColumn *tree_column) return retval; } +static GList * +gtk_tree_view_column_cell_layout_get_cells (GtkCellLayout *layout) +{ + return gtk_tree_view_column_get_cell_renderers (GTK_TREE_VIEW_COLUMN (layout)); +} + /** * gtk_tree_view_column_add_attribute: * @tree_column: A #GtkTreeViewColumn. @@ -1917,7 +1917,7 @@ gtk_tree_view_column_set_fixed_width (GtkTreeViewColumn *tree_column, gtk_widget_queue_resize (tree_column->tree_view); } - g_object_notify (G_OBJECT (tree_column), "fixed_width"); + g_object_notify (G_OBJECT (tree_column), "fixed-width"); } /** @@ -1968,9 +1968,9 @@ gtk_tree_view_column_set_min_width (GtkTreeViewColumn *tree_column, if (tree_column->max_width != -1 && tree_column->max_width < min_width) { tree_column->max_width = min_width; - g_object_notify (G_OBJECT (tree_column), "max_width"); + g_object_notify (G_OBJECT (tree_column), "max-width"); } - g_object_notify (G_OBJECT (tree_column), "min_width"); + g_object_notify (G_OBJECT (tree_column), "min-width"); g_object_thaw_notify (G_OBJECT (tree_column)); if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE) @@ -2028,9 +2028,9 @@ gtk_tree_view_column_set_max_width (GtkTreeViewColumn *tree_column, if (max_width != -1 && max_width < tree_column->min_width) { tree_column->min_width = max_width; - g_object_notify (G_OBJECT (tree_column), "min_width"); + g_object_notify (G_OBJECT (tree_column), "min-width"); } - g_object_notify (G_OBJECT (tree_column), "max_width"); + g_object_notify (G_OBJECT (tree_column), "max-width"); g_object_thaw_notify (G_OBJECT (tree_column)); if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE) @@ -2117,7 +2117,7 @@ gtk_tree_view_column_get_title (GtkTreeViewColumn *tree_column) /** * gtk_tree_view_column_set_expand: * @tree_column: A #GtkTreeViewColumn - * @expand: + * @expand: %TRUE if the column should take available extra space, %FALSE if not * * Sets the column to take available extra space. This space is shared equally * amongst all columns that have the expand set to %TRUE. If no column has this @@ -2149,7 +2149,7 @@ gtk_tree_view_column_set_expand (GtkTreeViewColumn *tree_column, /** * gtk_tree_view_column_get_expand: - * @tree_column: + * @tree_column: a #GtkTreeViewColumn * * Return %TRUE if the column expands to take any available space. * @@ -2220,10 +2220,7 @@ gtk_tree_view_column_set_widget (GtkTreeViewColumn *tree_column, g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget)); if (widget) - { - g_object_ref (widget); - gtk_object_sink (GTK_OBJECT (widget)); - } + g_object_ref_sink (widget); if (tree_column->child) g_object_unref (tree_column->child); @@ -2431,7 +2428,7 @@ gtk_tree_view_column_set_sort_indicator (GtkTreeViewColumn *tree_column, tree_column->show_sort_indicator = setting; gtk_tree_view_column_update_button (tree_column); - g_object_notify (G_OBJECT (tree_column), "sort_indicator"); + g_object_notify (G_OBJECT (tree_column), "sort-indicator"); } /** @@ -2478,7 +2475,7 @@ gtk_tree_view_column_set_sort_order (GtkTreeViewColumn *tree_column, tree_column->sort_order = order; gtk_tree_view_column_update_button (tree_column); - g_object_notify (G_OBJECT (tree_column), "sort_order"); + g_object_notify (G_OBJECT (tree_column), "sort-order"); } /** @@ -2536,10 +2533,10 @@ gtk_tree_view_column_cell_set_cell_data (GtkTreeViewColumn *tree_column, g_object_freeze_notify (cell); if (info->cell->is_expander != is_expander) - g_object_set (cell, "is_expander", is_expander, NULL); + g_object_set (cell, "is-expander", is_expander, NULL); if (info->cell->is_expanded != is_expanded) - g_object_set (cell, "is_expanded", is_expanded, NULL); + g_object_set (cell, "is-expanded", is_expanded, NULL); while (list && list->next) { @@ -2652,6 +2649,7 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, GdkRectangle real_cell_area; GdkRectangle real_background_area; GdkRectangle real_expose_area = *cell_area; + gint depth = 0; gint expand_cell_count = 0; gint full_requested_width = 0; gint extra_space; @@ -2660,6 +2658,7 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, gint special_cells; gint horizontal_separator; gboolean cursor_row = FALSE; + gboolean first_cell = TRUE; gboolean rtl; /* If we have rtl text, we need to transform our areas */ GdkRectangle rtl_cell_area; @@ -2707,7 +2706,15 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, real_cell_area = *cell_area; real_background_area = *background_area; + real_cell_area.x += focus_line_width; + real_cell_area.y += focus_line_width; + real_cell_area.height -= 2 * focus_line_width; + + if (rtl) + depth = real_background_area.width - real_cell_area.width; + else + depth = real_cell_area.x - real_background_area.x; /* Find out how much extra space we have to allocate */ for (list = tree_column->cell_list; list; list = list->next) @@ -2720,7 +2727,11 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, if (info->expand == TRUE) expand_cell_count ++; full_requested_width += info->requested_width; - /* FIXME: We prolly need to include tree_column->spacing here */ + + if (!first_cell) + full_requested_width += tree_column->spacing; + + first_cell = FALSE; } extra_space = cell_area->width - full_requested_width; @@ -2748,7 +2759,7 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, info->real_width = info->requested_width + (info->expand?extra_space:0); /* We constrain ourselves to only the width available */ - if (real_cell_area.x + info->real_width > cell_area->x + cell_area->width) + if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width) { info->real_width = cell_area->x + cell_area->width - real_cell_area.x; } @@ -2757,15 +2768,20 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, break; real_cell_area.width = info->real_width; - - real_background_area.width= - real_cell_area.x + real_cell_area.width - real_background_area.x; real_cell_area.width -= 2 * focus_line_width; + if (list->next) + { + real_background_area.width = info->real_width + depth; + } + else + { + /* fill the rest of background for the last cell */ + real_background_area.width = background_area->x + background_area->width - real_background_area.x; + } + rtl_cell_area = real_cell_area; rtl_background_area = real_background_area; - - if (rtl) { @@ -2784,7 +2800,6 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, &real_expose_area, flags); } - /* FOCUS */ else if (action == CELL_ACTION_FOCUS) { @@ -2893,8 +2908,11 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, flags &= ~GTK_CELL_RENDERER_FOCUSED; - real_cell_area.x += (real_cell_area.width + tree_column->spacing); - real_background_area.x += (real_background_area.width + tree_column->spacing); + real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing); + real_background_area.x += real_background_area.width + tree_column->spacing; + + /* Only needed for first cell */ + depth = 0; } /* iterate list for PACK_END cells */ @@ -2916,7 +2934,7 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, info->real_width = info->requested_width + (info->expand?extra_space:0); /* We constrain ourselves to only the width available */ - if (real_cell_area.x + info->real_width > cell_area->x + cell_area->width) + if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width) { info->real_width = cell_area->x + cell_area->width - real_cell_area.x; } @@ -2925,9 +2943,8 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, break; real_cell_area.width = info->real_width; - real_background_area.width = - real_cell_area.x + real_cell_area.width - real_background_area.x; real_cell_area.width -= 2 * focus_line_width; + real_background_area.width = info->real_width + depth; rtl_cell_area = real_cell_area; rtl_background_area = real_background_area; @@ -2995,8 +3012,8 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, cell_area->x + cell_area->width > ((GdkEventButton *)event)->x) try_event = TRUE; } - else if (real_cell_area.x <= ((GdkEventButton *)event)->x && - real_cell_area.x + real_cell_area.width > ((GdkEventButton *)event)->x) + else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x && + rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x) /* only activate cell if the user clicked on an individual * cell */ @@ -3055,8 +3072,11 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, flags &= ~GTK_CELL_RENDERER_FOCUSED; - real_cell_area.x += (real_cell_area.width + tree_column->spacing); + real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing); real_background_area.x += (real_background_area.width + tree_column->spacing); + + /* Only needed for first cell */ + depth = 0; } /* fill focus_rectangle when required */ @@ -3138,6 +3158,24 @@ _gtk_tree_view_column_cell_event (GtkTreeViewColumn *tree_column, path_string); } +void +_gtk_tree_view_column_get_focus_area (GtkTreeViewColumn *tree_column, + GdkRectangle *background_area, + GdkRectangle *cell_area, + GdkRectangle *focus_area) +{ + gtk_tree_view_column_cell_process_action (tree_column, + NULL, + background_area, + cell_area, + 0, + CELL_ACTION_FOCUS, + NULL, + focus_area, + NULL, NULL, NULL); +} + + /* cell list manipulation */ static GList * gtk_tree_view_column_cell_first (GtkTreeViewColumn *tree_column) @@ -3270,8 +3308,10 @@ _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column, gboolean right) { gint count; + gboolean rtl; count = _gtk_tree_view_column_count_special_cells (tree_column); + rtl = gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL; /* if we are the current focus column and have multiple editable cells, * try to select the next one, else move the focus to the next column @@ -3296,8 +3336,16 @@ _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column, if (!list || !info || !info->has_focus) return FALSE; - next = gtk_tree_view_column_cell_next (tree_column, list); - prev = gtk_tree_view_column_cell_prev (tree_column, list); + if (rtl) + { + prev = gtk_tree_view_column_cell_next (tree_column, list); + next = gtk_tree_view_column_cell_prev (tree_column, list); + } + else + { + next = gtk_tree_view_column_cell_next (tree_column, list); + prev = gtk_tree_view_column_cell_prev (tree_column, list); + } info->has_focus = FALSE; if (direction > 0 && next) @@ -3308,8 +3356,12 @@ _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column, } else if (direction > 0 && !next && !right) { - /* keep focus on latest cell */ - info = gtk_tree_view_column_cell_last (tree_column)->data; + /* keep focus on last cell */ + if (rtl) + info = gtk_tree_view_column_cell_first (tree_column)->data; + else + info = gtk_tree_view_column_cell_last (tree_column)->data; + info->has_focus = TRUE; return TRUE; } @@ -3322,7 +3374,11 @@ _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column, else if (direction < 0 && !prev && !left) { /* keep focus on first cell */ - info = gtk_tree_view_column_cell_first (tree_column)->data; + if (rtl) + info = gtk_tree_view_column_cell_last (tree_column)->data; + else + info = gtk_tree_view_column_cell_first (tree_column)->data; + info->has_focus = TRUE; return TRUE; } @@ -3345,11 +3401,26 @@ _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column, info->has_focus = FALSE; } - if (direction > 0) - ((GtkTreeViewColumnCellInfo *)gtk_tree_view_column_cell_first (tree_column)->data)->has_focus = TRUE; - else if (direction < 0) - ((GtkTreeViewColumnCellInfo *)gtk_tree_view_column_cell_last (tree_column)->data)->has_focus = TRUE; + list = NULL; + if (rtl) + { + if (direction > 0) + list = gtk_tree_view_column_cell_last (tree_column); + else if (direction < 0) + list = gtk_tree_view_column_cell_first (tree_column); + } + else + { + if (direction > 0) + list = gtk_tree_view_column_cell_first (tree_column); + else if (direction < 0) + list = gtk_tree_view_column_cell_last (tree_column); + } + + if (list) + ((GtkTreeViewColumnCellInfo *) list->data)->has_focus = TRUE; } + return TRUE; } @@ -3503,7 +3574,6 @@ _gtk_tree_view_column_cell_set_dirty (GtkTreeViewColumn *tree_column, info->requested_width = 0; } tree_column->dirty = TRUE; - tree_column->resized_width = MAX (tree_column->requested_width, tree_column->button_request); tree_column->requested_width = -1; tree_column->width = 0; @@ -3546,68 +3616,43 @@ _gtk_tree_view_column_get_neighbor_sizes (GtkTreeViewColumn *column, gint *right) { GList *list; - gint *rtl_left, *rtl_right; + GtkTreeViewColumnCellInfo *info; + gint l, r; + gboolean rtl; - if (gtk_widget_get_direction (GTK_WIDGET (column->tree_view)) == GTK_TEXT_DIR_RTL) - { - rtl_left = right; - rtl_right = left; - } - else - { - rtl_left = left; - rtl_right = right; - } + l = r = 0; - if (rtl_left) - { - *rtl_left = 0; - list = gtk_tree_view_column_cell_first (column); + list = gtk_tree_view_column_cell_first (column); - for (; list; list = gtk_tree_view_column_cell_next (column, list)) - { - GtkTreeViewColumnCellInfo *info = - (GtkTreeViewColumnCellInfo *)list->data; - - if (info->cell == cell) - break; + while (list) + { + info = (GtkTreeViewColumnCellInfo *)list->data; + + list = gtk_tree_view_column_cell_next (column, list); - if (info->cell->visible) - *rtl_left += info->real_width; - } + if (info->cell == cell) + break; + + if (info->cell->visible) + l += info->real_width + column->spacing; } - if (rtl_right) + while (list) { - GList *next; - - *rtl_right = 0; - list = gtk_tree_view_column_cell_first (column); - - for (; list; list = gtk_tree_view_column_cell_next (column, list)) - { - GtkTreeViewColumnCellInfo *info = - (GtkTreeViewColumnCellInfo *)list->data; + info = (GtkTreeViewColumnCellInfo *)list->data; + + list = gtk_tree_view_column_cell_next (column, list); - if (info->cell == cell) - break; - } + if (info->cell->visible) + r += info->real_width + column->spacing; + } - /* skip cell */ - next = gtk_tree_view_column_cell_next (column, list); - if (list && next) - { - list = next; - for ( ; list; list = gtk_tree_view_column_cell_next (column, list)) - { - GtkTreeViewColumnCellInfo *info = - (GtkTreeViewColumnCellInfo *)list->data; + rtl = (gtk_widget_get_direction (GTK_WIDGET (column->tree_view)) == GTK_TEXT_DIR_RTL); + if (left) + *left = rtl ? r : l; - if (info->cell->visible) - *rtl_right += info->real_width; - } - } - } + if (right) + *right = rtl ? l : r; } /** @@ -3660,3 +3705,44 @@ gtk_tree_view_column_cell_get_position (GtkTreeViewColumn *tree_column, return found_cell; } +/** + * gtk_tree_view_column_queue_resize: + * @tree_column: A #GtkTreeViewColumn + * + * Flags the column, and the cell renderers added to this column, to have + * their sizes renegotiated. + * + * Since: 2.8 + **/ +void +gtk_tree_view_column_queue_resize (GtkTreeViewColumn *tree_column) +{ + g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column)); + + if (tree_column->tree_view) + _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE); +} + +/** + * gtk_tree_view_column_get_tree_view: + * @tree_column: A #GtkTreeViewColumn + * + * Returns the #GtkTreeView wherein @tree_column has been inserted. If + * @column is currently not inserted in any tree view, %NULL is + * returned. + * + * Return value: The tree view wherein @column has been inserted if any, + * %NULL otherwise. + * + * Since: 2.12 + */ +GtkWidget * +gtk_tree_view_column_get_tree_view (GtkTreeViewColumn *tree_column) +{ + g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL); + + return tree_column->tree_view; +} + +#define __GTK_TREE_VIEW_COLUMN_C__ +#include "gtkaliasdef.c"