#include "gtkcellareabox.h"
#include "gtkprivate.h"
#include "gtkintl.h"
+#include "gtktypebuiltins.h"
/**
/* Sizing fields */
/* see gtk+/doc/tree-column-sizing.txt for more information on them */
GtkTreeViewColumnSizing column_type;
- gint requested_width;
+ gint padding;
gint resized_width;
gint width;
gint fixed_width;
PROP_REORDERABLE,
PROP_SORT_INDICATOR,
PROP_SORT_ORDER,
- PROP_SORT_COLUMN_ID
+ PROP_SORT_COLUMN_ID,
+ PROP_CELL_AREA
};
enum
-1,
GTK_PARAM_READWRITE));
+ /**
+ * GtkTreeViewColumn:cell-area:
+ *
+ * The #GtkCellArea used to layout cell renderers for this column.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (object_class,
+ PROP_CELL_AREA,
+ g_param_spec_object ("cell-area",
+ P_("Cell Area"),
+ P_("The GtkCellArea used to layout cells"),
+ GTK_TYPE_CELL_AREA,
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
g_type_class_add_private (class, sizeof (GtkTreeViewColumnPrivate));
}
priv->button = NULL;
priv->xalign = 0.0;
priv->width = 0;
- priv->requested_width = -1;
+ priv->padding = -1;
priv->min_width = -1;
priv->max_width = -1;
priv->resized_width = 0;
priv->fixed_width = 1;
priv->use_resized_width = FALSE;
priv->title = g_strdup ("");
+}
+
+static GObject *
+gtk_tree_view_column_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
+{
+ GtkTreeViewColumn *tree_column;
+ GtkTreeViewColumnPrivate *priv;
+ GObject *object;
+
+ object = G_OBJECT_CLASS (gtk_tree_view_column_parent_class)->constructor
+ (type, n_construct_properties, construct_properties);
+
+ tree_column = (GtkTreeViewColumn *) object;
+ priv = tree_column->priv;
+
+ if (!priv->cell_area)
+ {
+ priv->cell_area = gtk_cell_area_box_new ();
+ g_object_ref_sink (priv->cell_area);
+ }
- priv->cell_area = gtk_cell_area_box_new ();
gtk_cell_area_set_style_detail (priv->cell_area, "treeview");
+
+ priv->add_editable_signal =
+ g_signal_connect (priv->cell_area, "add-editable",
+ G_CALLBACK (gtk_tree_view_column_add_editable_callback),
+ tree_column);
+ priv->remove_editable_signal =
+ g_signal_connect (priv->cell_area, "remove-editable",
+ G_CALLBACK (gtk_tree_view_column_remove_editable_callback),
+ tree_column);
+
priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
priv->context_changed_signal =
if (priv->cell_area)
{
+ g_signal_handler_disconnect (priv->cell_area,
+ priv->add_editable_signal);
+ g_signal_handler_disconnect (priv->cell_area,
+ priv->remove_editable_signal);
+
g_object_unref (priv->cell_area);
priv->cell_area = NULL;
+ priv->add_editable_signal = 0;
+ priv->remove_editable_signal = 0;
}
if (priv->child)
area = g_value_get_object (value);
if (area)
- tree_column->cell_area = g_object_ref_sink (area);
+ tree_column->priv->cell_area = g_object_ref_sink (area);
break;
default:
break;
case PROP_CELL_AREA:
- g_value_set_object (value, tree_column->cell_area);
+ g_value_set_object (value, tree_column->priv->cell_area);
break;
default:
{
if (priv->visible)
{
- gtk_widget_show_now (priv->button);
+ if (gdk_window_is_visible (_gtk_tree_view_get_header_window (GTK_TREE_VIEW (priv->tree_view))))
+ gtk_widget_show_now (priv->button);
+
if (priv->window)
{
if (priv->resizable)
GParamSpec *pspec,
GtkTreeViewColumn *tree_column)
{
+ /* Here we want the column re-requested if the underlying context was
+ * actually reset for any reason, this can happen if the underlying
+ * area/cell configuration changes (i.e. cell packing properties
+ * or cell spacing and the like)
+ *
+ * Note that we block this handler while requesting for sizes
+ * so there is no need to check for the new context size being -1,
+ * we also block the handler when explicitly resetting the context
+ * so as to avoid some infinite stack recursion.
+ */
if (!strcmp (pspec->name, "minimum-width") ||
!strcmp (pspec->name, "natural-width") ||
!strcmp (pspec->name, "minimum-height") ||
!strcmp (pspec->name, "natural-height"))
- {
- /* XXX We want to do something specific if the size actually got cleared
- * or if it just grew a little bit because of a data change and we
- * are in GROW_ONLY mode.
- */
- _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
- }
+ _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
}
static void
GtkTreeViewColumnPrivate *priv = column->priv;
GtkTreePath *path;
- path = gtk_tree_path_new_from_string (path_string);
-
- _gtk_tree_view_add_editable (GTK_TREE_VIEW (priv->tree_view),
- column,
- path,
- edit_widget,
- cell_area);
-
- gtk_tree_path_free (path);
+ if (priv->tree_view)
+ {
+ path = gtk_tree_path_new_from_string (path_string);
+
+ _gtk_tree_view_add_editable (GTK_TREE_VIEW (priv->tree_view),
+ column,
+ path,
+ edit_widget,
+ cell_area);
+
+ gtk_tree_path_free (path);
+ }
}
static void
GtkTreeViewColumn *column = user_data;
GtkTreeViewColumnPrivate *priv = column->priv;
- _gtk_tree_view_remove_editable (GTK_TREE_VIEW (priv->tree_view),
- column,
- edit_widget);
+ if (priv->tree_view)
+ _gtk_tree_view_remove_editable (GTK_TREE_VIEW (priv->tree_view),
+ column,
+ edit_widget);
}
/* Exported Private Functions.
g_return_if_fail (_gtk_tree_view_get_header_window (tree_view) != NULL);
gtk_widget_set_parent_window (priv->button, _gtk_tree_view_get_header_window (tree_view));
- if (priv->visible)
- gtk_widget_show (priv->button);
-
attr.window_type = GDK_WINDOW_CHILD;
attr.wclass = GDK_INPUT_ONLY;
attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
gtk_tree_view_column_update_button (column);
- gdk_cursor_unref (attr.cursor);
+ g_object_unref (attr.cursor);
}
void
priv->tree_view = GTK_WIDGET (tree_view);
gtk_tree_view_column_create_button (column);
- priv->add_editable_signal =
- g_signal_connect (priv->cell_area, "add-editable",
- G_CALLBACK (gtk_tree_view_column_add_editable_callback),
- column);
- priv->remove_editable_signal =
- g_signal_connect (priv->cell_area, "remove-editable",
- G_CALLBACK (gtk_tree_view_column_remove_editable_callback),
- column);
-
priv->property_changed_signal =
g_signal_connect_swapped (tree_view,
"notify::model",
return gtk_cell_area_get_edited_cell (priv->cell_area);
}
+GtkCellRenderer *
+_gtk_tree_view_column_get_cell_at_pos (GtkTreeViewColumn *column,
+ GdkRectangle *cell_area,
+ GdkRectangle *background_area,
+ gint x,
+ gint y)
+{
+ GtkCellRenderer *match = NULL;
+ GtkTreeViewColumnPrivate *priv = column->priv;
+
+ /* If (x, y) is outside of the background area, immediately return */
+ if (x < background_area->x ||
+ x > background_area->x + background_area->width ||
+ y < background_area->y ||
+ y > background_area->y + background_area->height)
+ return NULL;
+
+ /* If (x, y) is inside the background area, clamp it to the cell_area
+ * so that a cell is still returned. The main reason for doing this
+ * (on the x axis) is for handling clicks in the indentation area
+ * (either at the left or right depending on RTL setting). Another
+ * reason is for handling clicks on the area where the focus rectangle
+ * is drawn (this is outside of cell area), this manifests itself
+ * mainly when a large setting is used for focus-line-width.
+ */
+ if (x < cell_area->x)
+ x = cell_area->x;
+ else if (x > cell_area->x + cell_area->width)
+ x = cell_area->x + cell_area->width;
+
+ if (y < cell_area->y)
+ y = cell_area->y;
+ else if (y > cell_area->y + cell_area->height)
+ y = cell_area->y + cell_area->height;
+
+ match = gtk_cell_area_get_cell_at_position (priv->cell_area,
+ priv->cell_area_context,
+ priv->tree_view,
+ cell_area,
+ x, y,
+ NULL);
+
+ return match;
+}
+
/* Public Functions */
return tree_column;
}
+/**
+ * gtk_tree_view_column_new_with_area:
+ * @area: the #GtkCellArea that the newly created column should use to layout cells.
+ *
+ * Creates a new #GtkTreeViewColumn using @area to render it's cells.
+ *
+ * Return value: A newly created #GtkTreeViewColumn.
+ *
+ * Since: 3.0
+ */
+GtkTreeViewColumn *
+gtk_tree_view_column_new_with_area (GtkCellArea *area)
+{
+ GtkTreeViewColumn *tree_column;
+
+ tree_column = g_object_new (GTK_TYPE_TREE_VIEW_COLUMN, "cell-area", area, NULL);
+
+ return tree_column;
+}
+
+
/**
* gtk_tree_view_column_new_with_attributes:
* @title: The title to set the header to.
if (type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
gtk_tree_view_column_set_resizable (tree_column, FALSE);
-#if 0
- /* I was clearly on crack when I wrote this. I'm not sure what's supposed to
- * be below so I'll leave it until I figure it out.
- */
- if (priv->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE &&
- priv->requested_width != -1)
- {
- gtk_tree_view_column_set_sizing (tree_column, priv->requested_width);
- }
-#endif
priv->column_type = type;
gtk_tree_view_column_update_button (tree_column);
return tree_column->priv->width;
}
+gint
+_gtk_tree_view_column_request_width (GtkTreeViewColumn *tree_column)
+{
+ GtkTreeViewColumnPrivate *priv;
+ gint real_requested_width;
+
+ priv = tree_column->priv;
+
+ if (priv->use_resized_width)
+ {
+ real_requested_width = priv->resized_width;
+ }
+ else if (priv->column_type == GTK_TREE_VIEW_COLUMN_FIXED)
+ {
+ real_requested_width = priv->fixed_width;
+ }
+ else if (gtk_tree_view_get_headers_visible (GTK_TREE_VIEW (priv->tree_view)))
+ {
+ gint button_request;
+ gint requested_width;
+
+ gtk_cell_area_context_get_preferred_width (priv->cell_area_context, &requested_width, NULL);
+ requested_width += priv->padding;
+
+ gtk_widget_get_preferred_width (priv->button, &button_request, NULL);
+ real_requested_width = MAX (requested_width, button_request);
+ }
+ else
+ {
+ gint requested_width;
+
+ gtk_cell_area_context_get_preferred_width (priv->cell_area_context, &requested_width, NULL);
+ requested_width += priv->padding;
+
+ real_requested_width = requested_width;
+ if (real_requested_width < 0)
+ real_requested_width = 0;
+ }
+
+ if (priv->min_width != -1)
+ real_requested_width = MAX (real_requested_width, priv->min_width);
+
+ if (priv->max_width != -1)
+ real_requested_width = MIN (real_requested_width, priv->max_width);
+
+ return real_requested_width;
+}
+
void
-_gtk_tree_view_column_set_width (GtkTreeViewColumn *tree_column,
- int width,
- int internal_width)
+_gtk_tree_view_column_allocate (GtkTreeViewColumn *tree_column,
+ int x_offset,
+ int width)
{
GtkTreeViewColumnPrivate *priv;
+ GtkAllocation allocation;
+ gboolean rtl;
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
priv = tree_column->priv;
- gtk_cell_area_context_allocate (priv->cell_area_context, internal_width, -1);
priv->width = width;
+ gtk_cell_area_context_allocate (priv->cell_area_context, priv->width - priv->padding, -1);
+
+ allocation.x = x_offset;
+ allocation.y = 0;
+ allocation.width = width;
+ allocation.height = _gtk_tree_view_get_header_height (GTK_TREE_VIEW (priv->tree_view));
+
+ gtk_widget_size_allocate (priv->button, &allocation);
+
+ if (priv->window)
+ {
+ rtl = (gtk_widget_get_direction (priv->tree_view) == GTK_TEXT_DIR_RTL);
+ gdk_window_move_resize (priv->window,
+ allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
+ allocation.y,
+ TREE_VIEW_DRAG_WIDTH, allocation.height);
+ }
+
g_object_notify (G_OBJECT (tree_column), "width");
}
gint *height)
{
GtkTreeViewColumnPrivate *priv;
- int focus_line_width;
+ gint min_width = 0, min_height = 0;
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
priv = tree_column->priv;
- if (height)
- * height = 0;
- if (width)
- * width = 0;
-
- /* FIXME: This is a temporary hack to get things to allocate mostly right.
- *
- * We will add twice the focus-line-width to the for-width
- * parameter below. If we do not do this, the height returned is the
- * height for two lines of text instead of one. It feels like some lines
- * get less width than expected (due to subtraction of focus_line_width?)
- * and will unnecessarily wrap.
- */
- gtk_widget_style_get (priv->tree_view,
- "focus-line-width", &focus_line_width,
- NULL);
-
g_signal_handler_block (priv->cell_area_context,
priv->context_changed_signal);
gtk_cell_area_get_preferred_width (priv->cell_area,
priv->cell_area_context,
priv->tree_view,
- width, NULL);
+ NULL, NULL);
+
+ gtk_cell_area_context_get_preferred_width (priv->cell_area_context, &min_width, NULL);
+
gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
priv->cell_area_context,
priv->tree_view,
- *width + focus_line_width * 2,
- height,
+ min_width,
+ &min_height,
NULL);
g_signal_handler_unblock (priv->cell_area_context,
gboolean
_gtk_tree_view_column_cell_event (GtkTreeViewColumn *tree_column,
- GtkCellEditable **editable_widget,
GdkEvent *event,
- gchar *path_string,
- const GdkRectangle *background_area,
const GdkRectangle *cell_area,
guint flags)
{
priv = tree_column->priv;
- /* FIXME: Should we pass background area here as well?
- * What will happen to the path_string and editable widget
- * variables?
- *
- * Answer, No dont pass background area... editable widgets
- * grab the pointer and keyboard so the treeview doesnt
- * recieve these events while editable widgets are editing.
- *
- * Also it's important that gtk_cell_area_apply_attributes be
- * called before passing the event to the cell (maybe we need to
- * instead use the path_string here to apply the attributes ?,
- * if the attributes are applied, the underlying CellArea knows
- * the path string, which is expected when handling events).
- */
return gtk_cell_area_event (priv->cell_area,
priv->cell_area_context,
priv->tree_view,
flags);
}
-void
-_gtk_tree_view_column_get_focus_area (GtkTreeViewColumn *tree_column,
- const GdkRectangle *background_area,
- const GdkRectangle *cell_area,
- GdkRectangle *focus_area)
-{
- /* FIXME */
-#if 0
- gtk_tree_view_column_cell_process_action (tree_column,
- NULL,
- background_area,
- cell_area,
- 0,
- CELL_ACTION_FOCUS,
- focus_area,
- NULL, NULL, NULL);
-#endif
-}
-
-
-gboolean
-_gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column,
- gint count,
- gboolean left,
- gboolean right)
-{
- gboolean rtl;
- GtkDirectionType direction = 0;
- GtkTreeViewColumnPrivate *priv = tree_column->priv;
-
- rtl = gtk_widget_get_direction (priv->tree_view) == GTK_TEXT_DIR_RTL;
-
- switch (count)
- {
- case -1:
- direction = GTK_DIR_LEFT;
- break;
-
- case 1:
- direction = GTK_DIR_RIGHT;
- break;
- }
-
- /* 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
- */
- if (_gtk_tree_view_get_focus_column (GTK_TREE_VIEW (priv->tree_view)) == tree_column)
- {
- if (gtk_cell_area_focus (priv->cell_area, direction))
- /* Focus stays in this column, so we are done */
- return TRUE;
-
- /* FIXME: RTL support for the following: */
- if (count == -1 && !left)
- {
- direction = GTK_DIR_RIGHT;
- gtk_cell_area_focus (priv->cell_area, direction);
- }
- else if (count == 1 && !right)
- {
- direction = GTK_DIR_LEFT;
- gtk_cell_area_focus (priv->cell_area, direction);
- }
-
- return FALSE;
- }
-
- return gtk_cell_area_focus (priv->cell_area, direction);
-}
-
/**
* gtk_tree_view_column_cell_is_visible:
* @tree_column: A #GtkTreeViewColumn
GtkTreeViewColumnPrivate *priv = tree_column->priv;
priv->dirty = TRUE;
- priv->requested_width = -1;
+ priv->padding = 0;
priv->width = 0;
+ /* Issue a manual reset on the context to have all
+ * sizes re-requested for the context.
+ */
+ g_signal_handler_block (priv->cell_area_context,
+ priv->context_changed_signal);
+ gtk_cell_area_context_reset (priv->cell_area_context);
+ g_signal_handler_unblock (priv->cell_area_context,
+ priv->context_changed_signal);
+
if (priv->tree_view &&
gtk_widget_get_realized (priv->tree_view))
{
* gtk_tree_view_column_cell_get_position:
* @tree_column: a #GtkTreeViewColumn
* @cell_renderer: a #GtkCellRenderer
- * @start_pos: return location for the horizontal position of @cell within
+ * @x_offset: return location for the horizontal position of @cell within
* @tree_column, may be %NULL
* @width: return location for the width of @cell, may be %NULL
*
gboolean
gtk_tree_view_column_cell_get_position (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell_renderer,
- gint *start_pos,
+ gint *x_offset,
gint *width)
{
GtkTreeViewColumnPrivate *priv;
- GdkRectangle zero_cell_area = { 0, };
+ GdkRectangle cell_area;
GdkRectangle allocation;
g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
priv = tree_column->priv;
- /* FIXME: Could use a boolean return value for invalid cells */
+ gtk_tree_view_get_background_area (GTK_TREE_VIEW (priv->tree_view),
+ NULL, tree_column, &cell_area);
+
gtk_cell_area_get_cell_allocation (priv->cell_area,
priv->cell_area_context,
priv->tree_view,
cell_renderer,
- &zero_cell_area,
+ &cell_area,
&allocation);
- if (start_pos)
- *start_pos = allocation.x;
+ if (x_offset)
+ {
+ GdkRectangle button_allocation;
+
+ /* Retrieve column offset */
+ gtk_widget_get_allocation (priv->button, &button_allocation);
+ *x_offset = allocation.x - button_allocation.x;
+ }
if (width)
*width = allocation.width;
}
void
-_gtk_tree_view_column_set_requested_width (GtkTreeViewColumn *column,
- gint width)
+_gtk_tree_view_column_push_padding (GtkTreeViewColumn *column,
+ gint padding)
{
- column->priv->requested_width = width;
+ column->priv->padding = MAX (column->priv->padding, padding);
}
gint
_gtk_tree_view_column_get_requested_width (GtkTreeViewColumn *column)
{
- return column->priv->requested_width;
+ gint requested_width;
+
+ gtk_cell_area_context_get_preferred_width (column->priv->cell_area_context, &requested_width, NULL);
+
+ return requested_width + column->priv->padding;
}
+
void
_gtk_tree_view_column_set_resized_width (GtkTreeViewColumn *column,
gint width)