#include "gtkbutton.h"
#include "gtkalignment.h"
#include "gtklabel.h"
-#include "gtkhbox.h"
+#include "gtkbox.h"
#include "gtkmarshalers.h"
#include "gtkarrow.h"
#include "gtkcellareacontext.h"
#include "gtkcellareabox.h"
#include "gtkprivate.h"
#include "gtkintl.h"
+#include "gtktypebuiltins.h"
/**
GObjectConstructParam *construct_properties);
/* GtkCellLayout implementation */
+static void gtk_tree_view_column_ensure_cell_area (GtkTreeViewColumn *column,
+ GtkCellArea *cell_area);
+
static GtkCellArea *gtk_tree_view_column_cell_layout_get_area (GtkCellLayout *cell_layout);
/* Button handling code */
GtkTreeViewColumnSizing column_type;
gint padding;
gint resized_width;
+ gint x_offset;
gint width;
gint fixed_width;
gint min_width;
PROP_0,
PROP_VISIBLE,
PROP_RESIZABLE,
+ PROP_X_OFFSET,
PROP_WIDTH,
PROP_SPACING,
PROP_SIZING,
FALSE,
GTK_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_X_OFFSET,
+ g_param_spec_int ("x-offset",
+ P_("X position"),
+ P_("Current X position of the column"),
+ -G_MAXINT,
+ G_MAXINT,
+ 0,
+ GTK_PARAM_READABLE));
+
g_object_class_install_property (object_class,
PROP_WIDTH,
g_param_spec_int ("width",
*
* The #GtkCellArea used to layout cell renderers for this column.
*
+ * If no area is specified when creating the tree view column with gtk_tree_view_column_new_with_area()
+ * a horizontally oriented #GtkCellAreaBox will be used.
+ *
* Since: 3.0
*/
g_object_class_install_property (object_class,
}
static GObject *
-gtk_tree_view_column_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_properties)
+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);
- }
- 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 =
- g_signal_connect (priv->cell_area_context, "notify",
- G_CALLBACK (gtk_tree_view_column_context_changed), tree_column);
+ gtk_tree_view_column_ensure_cell_area (tree_column, NULL);
return object;
}
GtkTreeViewColumn *tree_column = (GtkTreeViewColumn *) object;
GtkTreeViewColumnPrivate *priv = tree_column->priv;
+ /* Remove this column from its treeview,
+ * in case this column is destroyed before its treeview.
+ */
+ if (priv->tree_view)
+ gtk_tree_view_remove_column (GTK_TREE_VIEW (priv->tree_view), tree_column);
+
if (priv->cell_area_context)
{
g_signal_handler_disconnect (priv->cell_area_context,
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;
area = g_value_get_object (value);
if (area)
- tree_column->priv->cell_area = g_object_ref_sink (area);
+ {
+ if (tree_column->priv->cell_area != NULL)
+ {
+ g_warning ("cell-area has already been set, ignoring construct property");
+ g_object_ref_sink (area);
+ g_object_unref (area);
+ }
+ else
+ gtk_tree_view_column_ensure_cell_area (tree_column, area);
+ }
break;
-
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
gtk_tree_view_column_get_resizable (tree_column));
break;
+ case PROP_X_OFFSET:
+ g_value_set_int (value,
+ gtk_tree_view_column_get_x_offset (tree_column));
+ break;
+
case PROP_WIDTH:
g_value_set_int (value,
gtk_tree_view_column_get_width (tree_column));
/* Implementation of GtkCellLayout interface
*/
+
+static void
+gtk_tree_view_column_ensure_cell_area (GtkTreeViewColumn *column,
+ GtkCellArea *cell_area)
+{
+ GtkTreeViewColumnPrivate *priv = column->priv;
+
+ if (priv->cell_area)
+ return;
+
+ if (cell_area)
+ priv->cell_area = cell_area;
+ else
+ priv->cell_area = gtk_cell_area_box_new ();
+
+ g_object_ref_sink (priv->cell_area);
+
+ 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->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
+
+ priv->context_changed_signal =
+ g_signal_connect (priv->cell_area_context, "notify",
+ G_CALLBACK (gtk_tree_view_column_context_changed),
+ column);
+}
+
static GtkCellArea *
gtk_tree_view_column_cell_layout_get_area (GtkCellLayout *cell_layout)
{
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (cell_layout);
GtkTreeViewColumnPrivate *priv = column->priv;
+ if (G_UNLIKELY (!priv->cell_area))
+ gtk_tree_view_column_ensure_cell_area (column, NULL);
+
return priv->cell_area;
}
{
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)
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));
return match;
}
+gboolean
+_gtk_tree_view_column_is_blank_at_pos (GtkTreeViewColumn *column,
+ GdkRectangle *cell_area,
+ GdkRectangle *background_area,
+ gint x,
+ gint y)
+{
+ GtkCellRenderer *match;
+ GdkRectangle cell_alloc, aligned_area, inner_area;
+ GtkTreeViewColumnPrivate *priv = column->priv;
+
+ match = _gtk_tree_view_column_get_cell_at_pos (column,
+ cell_area,
+ background_area,
+ x, y);
+ if (!match)
+ return FALSE;
+
+ gtk_cell_area_get_cell_allocation (priv->cell_area,
+ priv->cell_area_context,
+ priv->tree_view,
+ match,
+ cell_area,
+ &cell_alloc);
+
+ gtk_cell_area_inner_cell_area (priv->cell_area, priv->tree_view,
+ &cell_alloc, &inner_area);
+ gtk_cell_renderer_get_aligned_area (match, priv->tree_view, 0,
+ &inner_area, &aligned_area);
+
+ if (x < aligned_area.x ||
+ x > aligned_area.x + aligned_area.width ||
+ y < aligned_area.y ||
+ y > aligned_area.y + aligned_area.height)
+ return TRUE;
+
+ return FALSE;
+}
+
/* Public Functions */
* 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.
+ * Creates a new #GtkTreeViewColumn using @area to render its cells.
*
* Return value: A newly created #GtkTreeViewColumn.
*
/**
* gtk_tree_view_column_new_with_attributes:
- * @title: The title to set the header to.
- * @cell: The #GtkCellRenderer.
- * @Varargs: A %NULL-terminated list of attributes.
- *
- * Creates a new #GtkTreeViewColumn with a number of default values. This is
- * equivalent to calling gtk_tree_view_column_set_title(),
+ * @title: The title to set the header to
+ * @cell: The #GtkCellRenderer
+ * @...: A %NULL-terminated list of attributes
+ *
+ * Creates a new #GtkTreeViewColumn with a number of default values.
+ * This is equivalent to calling gtk_tree_view_column_set_title(),
* gtk_tree_view_column_pack_start(), and
* gtk_tree_view_column_set_attributes() on the newly created #GtkTreeViewColumn.
*
/**
* gtk_tree_view_column_set_attributes:
- * @tree_column: A #GtkTreeViewColumn.
+ * @tree_column: A #GtkTreeViewColumn
* @cell_renderer: the #GtkCellRenderer we're setting the attributes of
- * @Varargs: A %NULL-terminated list of attributes.
- *
+ * @...: A %NULL-terminated list of attributes
+ *
* Sets the attributes in the list as the attributes of @tree_column.
* The attributes should be in attribute/column order, as in
* gtk_tree_view_column_add_attribute(). All existing attributes
* are removed, and replaced with the new attributes.
- **/
+ */
void
gtk_tree_view_column_set_attributes (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell_renderer,
* gtk_tree_view_column_set_cell_data_func:
* @tree_column: A #GtkTreeViewColumn
* @cell_renderer: A #GtkCellRenderer
- * @func: The #GtkTreeViewColumnFunc to use.
+ * @func: (allow-none): The #GtkTreeViewColumnFunc to use.
* @func_data: The user data for @func.
* @destroy: The destroy notification for @func_data
*
* @visible: %TRUE if the @tree_column is visible.
*
* Sets the visibility of @tree_column.
- **/
+ */
void
gtk_tree_view_column_set_visible (GtkTreeViewColumn *tree_column,
- gboolean visible)
+ gboolean visible)
{
GtkTreeViewColumnPrivate *priv;
priv = tree_column->priv;
visible = !! visible;
-
+
if (priv->visible == visible)
return;
if (priv->visible)
_gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
+ if (priv->tree_view)
+ _gtk_tree_view_reset_header_styles (GTK_TREE_VIEW (priv->tree_view));
+
gtk_tree_view_column_update_button (tree_column);
g_object_notify (G_OBJECT (tree_column), "visible");
}
return tree_column->priv->width;
}
+/**
+ * gtk_tree_view_column_get_x_offset:
+ * @tree_column: A #GtkTreeViewColumn.
+ *
+ * Returns the current X offset of @tree_column in pixels.
+ *
+ * Return value: The current X offset of @tree_column.
+ *
+ * Since: 3.2
+ */
+gint
+gtk_tree_view_column_get_x_offset (GtkTreeViewColumn *tree_column)
+{
+ g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
+
+ return tree_column->priv->x_offset;
+}
+
gint
_gtk_tree_view_column_request_width (GtkTreeViewColumn *tree_column)
{
int width)
{
GtkTreeViewColumnPrivate *priv;
- GtkAllocation allocation;
gboolean rtl;
+ GtkAllocation allocation = { 0, 0, 0, 0 };
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
priv = tree_column->priv;
+ if (priv->width != width)
+ gtk_widget_queue_draw (priv->tree_view);
+
+ priv->x_offset = x_offset;
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));
+ if (gtk_tree_view_get_headers_visible (GTK_TREE_VIEW (priv->tree_view)))
+ {
+ 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);
+ gtk_widget_size_allocate (priv->button, &allocation);
+ }
if (priv->window)
{
TREE_VIEW_DRAG_WIDTH, allocation.height);
}
+ g_object_notify (G_OBJECT (tree_column), "x-offset");
g_object_notify (G_OBJECT (tree_column), "width");
}
* Return value: the title of the column. This string should not be
* modified or freed.
**/
-G_CONST_RETURN gchar *
+const gchar *
gtk_tree_view_column_get_title (GtkTreeViewColumn *tree_column)
{
g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);
* gtk_tree_view_column_cell_get_size:
* @tree_column: A #GtkTreeViewColumn.
* @cell_area: (allow-none): The area a cell in the column will be allocated, or %NULL
- * @x_offset: (allow-none): location to return x offset of a cell relative to @cell_area, or %NULL
- * @y_offset: (allow-none): location to return y offset of a cell relative to @cell_area, or %NULL
- * @width: (allow-none): location to return width needed to render a cell, or %NULL
- * @height: (allow-none): location to return height needed to render a cell, or %NULL
+ * @x_offset: (out) (allow-none): location to return x offset of a cell relative to @cell_area, or %NULL
+ * @y_offset: (out) (allow-none): location to return y offset of a cell relative to @cell_area, or %NULL
+ * @width: (out) (allow-none): location to return width needed to render a cell, or %NULL
+ * @height: (out) (allow-none): 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.
* gtk_tree_view_column_cell_get_position:
* @tree_column: a #GtkTreeViewColumn
* @cell_renderer: a #GtkCellRenderer
- * @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
+ * @x_offset: (out) (allow-none): return location for the horizontal
+ * position of @cell within @tree_column, may be %NULL
+ * @width: (out) (allow-none): return location for the width of @cell,
+ * may be %NULL
*
* Obtains the horizontal position and size of a cell in a column. If the
* cell is not found in the column, @start_pos and @width are not changed and
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 */
+ if (! gtk_cell_area_has_renderer (priv->cell_area, cell_renderer))
+ return FALSE;
+
+ 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 (x_offset)
- *x_offset = allocation.x;
+ *x_offset = allocation.x - cell_area.x;
+
if (width)
*width = allocation.width;