+/* An internal convenience function for some containers to peek at the
+ * cell alignment in a target allocation (used to draw focus and align
+ * cells in the icon view).
+ *
+ * Note this is only a trivial 'align * (allocation - request)' operation.
+ */
+void
+_gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
+ const GdkRectangle *cell_area,
+ GtkTextDirection direction,
+ gint width,
+ gint height,
+ gint *x_offset,
+ gint *y_offset)
+{
+ GtkCellRendererPrivate *priv;
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+ g_return_if_fail (cell_area != NULL);
+ g_return_if_fail (x_offset || y_offset);
+
+ priv = cell->priv;
+
+ if (x_offset)
+ {
+ *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
+ (1.0 - priv->xalign) : priv->xalign) *
+ (cell_area->width - width));
+ *x_offset = MAX (*x_offset, 0);
+ }
+ if (y_offset)
+ {
+ *y_offset = (priv->yalign *
+ (cell_area->height - height));
+ *y_offset = MAX (*y_offset, 0);
+ }
+}
+
+/**
+ * gtk_cell_renderer_get_request_mode:
+ * @cell: a #GtkCellRenderer instance
+ *
+ * Gets whether the cell renderer prefers a height-for-width layout
+ * or a width-for-height layout.
+ *
+ * Returns: The #GtkSizeRequestMode preferred by this renderer.
+ *
+ * Since: 3.0
+ */
+GtkSizeRequestMode
+gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
+{
+ g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
+
+ return GTK_CELL_RENDERER_GET_CLASS (cell)->get_request_mode (cell);
+}
+
+/**
+ * gtk_cell_renderer_get_preferred_width:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @minimum_size: (out) (allow-none): location to store the minimum size, or %NULL
+ * @natural_size: (out) (allow-none): location to store the natural size, or %NULL
+ *
+ * Retreives a renderer's natural size when rendered to @widget.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ GtkCellRendererClass *klass;
+ gint width;
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (NULL != minimum_size || NULL != natural_size);
+
+ gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
+
+ if (width < 0)
+ {
+ klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+ klass->get_preferred_width (cell, widget, minimum_size, natural_size);
+ }
+ else
+ {
+ if (minimum_size)
+ *minimum_size = width;
+ if (natural_size)
+ *natural_size = width;
+ }
+
+#if DEBUG_CELL_SIZE_REQUEST
+ g_message ("%s returning minimum width: %d and natural width: %d",
+ G_OBJECT_TYPE_NAME (cell),
+ minimum_size ? *minimum_size : 20000,
+ natural_size ? *natural_size : 20000);
+#endif
+}
+
+
+/**
+ * gtk_cell_renderer_get_preferred_height:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @minimum_size: (out) (allow-none): location to store the minimum size, or %NULL
+ * @natural_size: (out) (allow-none): location to store the natural size, or %NULL
+ *
+ * Retreives a renderer's natural size when rendered to @widget.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ GtkCellRendererClass *klass;
+ gint height;
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (NULL != minimum_size || NULL != natural_size);
+
+ gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
+
+ if (height < 0)
+ {
+ klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+ klass->get_preferred_height (cell, widget, minimum_size, natural_size);
+ }
+ else
+ {
+ if (minimum_size)
+ *minimum_size = height;
+ if (natural_size)
+ *natural_size = height;
+ }
+
+#if DEBUG_CELL_SIZE_REQUEST
+ g_message ("%s returning minimum height: %d and natural height: %d",
+ G_OBJECT_TYPE_NAME (cell),
+ minimum_size ? *minimum_size : 20000,
+ natural_size ? *natural_size : 20000);
+#endif
+}
+
+
+/**
+ * gtk_cell_renderer_get_preferred_width_for_height:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @height: the size which is available for allocation
+ * @minimum_width: (out) (allow-none): location for storing the minimum size, or %NULL
+ * @natural_width: (out) (allow-none): location for storing the preferred size, or %NULL
+ *
+ * Retreives a cell renderers's minimum and natural width if it were rendered to
+ * @widget with the specified @height.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ gint height,
+ gint *minimum_width,
+ gint *natural_width)
+{
+ GtkCellRendererClass *klass;
+ gint width;
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (NULL != minimum_width || NULL != natural_width);
+
+ gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
+
+ if (width < 0)
+ {
+ klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+ klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
+ }
+ else
+ {
+ if (minimum_width)
+ *minimum_width = width;
+ if (natural_width)
+ *natural_width = width;
+ }
+
+#if DEBUG_CELL_SIZE_REQUEST
+ g_message ("%s width for height: %d is minimum %d and natural: %d",
+ G_OBJECT_TYPE_NAME (cell), height,
+ minimum_width ? *minimum_width : 20000,
+ natural_width ? *natural_width : 20000);
+#endif
+}
+
+/**
+ * gtk_cell_renderer_get_preferred_height_for_width:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @width: the size which is available for allocation
+ * @minimum_height: (out) (allow-none): location for storing the minimum size, or %NULL
+ * @natural_height: (out) (allow-none): location for storing the preferred size, or %NULL
+ *
+ * Retreives a cell renderers's minimum and natural height if it were rendered to
+ * @widget with the specified @width.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ gint width,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ GtkCellRendererClass *klass;
+ gint height;
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (NULL != minimum_height || NULL != natural_height);
+
+ gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
+
+ if (height < 0)
+ {
+ klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+ klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
+ }
+ else
+ {
+ if (minimum_height)
+ *minimum_height = height;
+ if (natural_height)
+ *natural_height = height;
+ }
+
+#if DEBUG_CELL_SIZE_REQUEST
+ g_message ("%s height for width: %d is minimum %d and natural: %d",
+ G_OBJECT_TYPE_NAME (cell), width,
+ minimum_height ? *minimum_height : 20000,
+ natural_height ? *natural_height : 20000);
+#endif
+}
+
+/**
+ * gtk_cell_renderer_get_preferred_size:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
+ * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
+ *
+ * Retrieves the minimum and natural size of a cell taking
+ * into account the widget's preference for height-for-width management.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ GtkRequisition *minimum_size,
+ GtkRequisition *natural_size)
+{
+ gint min_width, nat_width;
+ gint min_height, nat_height;
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+
+ if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+ {
+ gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
+
+ if (minimum_size)
+ {
+ minimum_size->width = min_width;
+ gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
+ &minimum_size->height, NULL);
+ }
+
+ if (natural_size)
+ {
+ natural_size->width = nat_width;
+ gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
+ NULL, &natural_size->height);
+ }
+ }
+ else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
+ {
+ gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
+
+ if (minimum_size)
+ {
+ minimum_size->height = min_height;
+ gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
+ &minimum_size->width, NULL);
+ }
+
+ if (natural_size)
+ {
+ natural_size->height = nat_height;
+ gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
+ NULL, &natural_size->width);
+ }
+ }
+}
+
+/**
+ * gtk_cell_renderer_get_aligned_area:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @flags: render flags
+ * @cell_area: cell area which would be passed to gtk_cell_renderer_render()
+ * @aligned_area: (out): the return location for the space inside @cell_area
+ * that would acually be used to render.
+ *
+ * Gets the aligned area used by @cell inside @cell_area. Used for finding
+ * the appropriate edit and focus rectangle.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_aligned_area (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ GtkCellRendererState flags,
+ const GdkRectangle *cell_area,
+ GdkRectangle *aligned_area)
+{
+ GtkCellRendererClass *klass;
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (cell_area != NULL);
+ g_return_if_fail (aligned_area != NULL);
+
+ klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+ klass->get_aligned_area (cell, widget, flags, cell_area, aligned_area);
+
+ g_assert (aligned_area->x >= cell_area->x && aligned_area->x <= cell_area->x + cell_area->width);
+ g_assert (aligned_area->y >= cell_area->y && aligned_area->y <= cell_area->y + cell_area->height);
+ g_assert ((aligned_area->x - cell_area->x) + aligned_area->width <= cell_area->width);
+ g_assert ((aligned_area->y - cell_area->y) + aligned_area->height <= cell_area->height);
+}
+
+/**
+ * gtk_cell_renderer_get_state:
+ * @cell: a #GtkCellRenderer, or %NULL
+ * @widget: a #GtkWidget, or %NULL
+ * @cell_state: cell renderer state
+ *
+ * Translates the cell renderer state to #GtkStateFlags,
+ * based on the cell renderer and widget sensitivity, and
+ * the given #GtkCellRendererState.
+ *
+ * Returns: the widget state flags applying to @cell
+ *
+ * Since: 3.0
+ **/
+GtkStateFlags
+gtk_cell_renderer_get_state (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ GtkCellRendererState cell_state)
+{
+ GtkStateFlags state = 0;
+
+ g_return_val_if_fail (!cell || GTK_IS_CELL_RENDERER (cell), 0);
+ g_return_val_if_fail (!widget || GTK_IS_WIDGET (widget), 0);
+
+ if (widget)
+ state |= gtk_widget_get_state_flags (widget);
+
+ state &= ~(GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED);
+
+ if ((state & GTK_STATE_FLAG_INSENSITIVE) != 0 ||
+ (cell && !gtk_cell_renderer_get_sensitive (cell)) ||
+ (cell_state & GTK_CELL_RENDERER_INSENSITIVE) != 0)
+ {
+ state |= GTK_STATE_FLAG_INSENSITIVE;
+ }
+ else
+ {
+ if ((widget && gtk_widget_has_focus (widget)) &&
+ (cell_state & GTK_CELL_RENDERER_FOCUSED) != 0)
+ state |= GTK_STATE_FLAG_FOCUSED;
+
+ if ((cell_state & GTK_CELL_RENDERER_PRELIT) != 0)
+ state |= GTK_STATE_FLAG_PRELIGHT;
+ }
+
+ if ((cell_state & GTK_CELL_RENDERER_SELECTED) != 0)
+ state |= GTK_STATE_FLAG_SELECTED;
+
+ return state;
+}
+
+/**
+ * gtk_cell_renderer_class_set_accessible_type:
+ * @renderer_class: class to set the accessible type for
+ * @type: The object type that implements the accessible for @widget_class.
+ * The type must be a subtype of #GtkRendererCellAccessible
+ *
+ * Sets the type to be used for creating accessibles for cells rendered by
+ * cell renderers of @renderer_class. Note that multiple accessibles will
+ * be created.
+ *
+ * This function should only be called from class init functions of cell
+ * renderers.
+ **/
+void
+gtk_cell_renderer_class_set_accessible_type (GtkCellRendererClass *renderer_class,
+ GType type)
+{
+ GtkCellRendererClassPrivate *priv;
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER_CLASS (renderer_class));
+ g_return_if_fail (g_type_is_a (type, GTK_TYPE_RENDERER_CELL_ACCESSIBLE));
+
+ priv = renderer_class->priv;
+
+ priv->accessible_type = type;
+}
+
+GType
+_gtk_cell_renderer_get_accessible_type (GtkCellRenderer *renderer)
+{
+ g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), GTK_TYPE_RENDERER_CELL_ACCESSIBLE);
+
+ return GTK_CELL_RENDERER_GET_CLASS (renderer)->priv->accessible_type;
+}
+