[gtk+] cellview: Convert to gadgets
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cellview: Convert to gadgets
- Date: Thu, 17 Dec 2015 00:07:42 +0000 (UTC)
commit 7778c237e65eaebfc0659c1436e3136faca9397b
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 16 19:07:26 2015 -0500
cellview: Convert to gadgets
gtk/gtkcellview.c | 364 ++++++++++++++++++++++++++++++----------------------
1 files changed, 210 insertions(+), 154 deletions(-)
---
diff --git a/gtk/gtkcellview.c b/gtk/gtkcellview.c
index 190f895..f76bac9 100644
--- a/gtk/gtkcellview.c
+++ b/gtk/gtkcellview.c
@@ -26,6 +26,8 @@
#include "gtkprivate.h"
#include "gtkorientableprivate.h"
#include "gtkrender.h"
+#include "gtkcsscustomgadgetprivate.h"
+#include "gtkwidgetprivate.h"
#include <gobject/gmarshal.h>
#include "gtkbuildable.h"
@@ -118,6 +120,26 @@ static void row_changed_cb (GtkTreeModel
GtkTreeIter *iter,
GtkCellView *view);
+static void gtk_cell_view_measure (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline,
+ gpointer data);
+static void gtk_cell_view_allocate (GtkCssGadget *gadget,
+ const GtkAllocation *allocation,
+ int baseline,
+ GtkAllocation *out_clip,
+ gpointer data);
+static gboolean gtk_cell_view_render (GtkCssGadget *gadget,
+ cairo_t *cr,
+ int x,
+ int y,
+ int width,
+ int height,
+ gpointer data);
struct _GtkCellViewPrivate
{
@@ -127,6 +149,8 @@ struct _GtkCellViewPrivate
GtkCellArea *area;
GtkCellAreaContext *context;
+ GtkCssGadget *gadget;
+
GdkRGBA background;
gulong size_changed_id;
@@ -533,10 +557,21 @@ gtk_cell_view_set_property (GObject *object,
static void
gtk_cell_view_init (GtkCellView *cellview)
{
+ GtkCssNode *widget_node;
+
cellview->priv = gtk_cell_view_get_instance_private (cellview);
cellview->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
gtk_widget_set_has_window (GTK_WIDGET (cellview), FALSE);
+
+ widget_node = gtk_widget_get_css_node (GTK_WIDGET (cellview));
+ cellview->priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
+ GTK_WIDGET (cellview),
+ gtk_cell_view_measure,
+ gtk_cell_view_allocate,
+ gtk_cell_view_render,
+ NULL,
+ NULL);
}
static void
@@ -547,6 +582,8 @@ gtk_cell_view_finalize (GObject *object)
if (cellview->priv->displayed_row)
gtk_tree_row_reference_free (cellview->priv->displayed_row);
+ g_clear_object (&cellview->priv->gadget);
+
G_OBJECT_CLASS (gtk_cell_view_parent_class)->finalize (object);
}
@@ -576,46 +613,48 @@ gtk_cell_view_dispose (GObject *object)
}
static void
-get_padding_and_border (GtkWidget *widget,
- GtkBorder *border)
+gtk_cell_view_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
{
- GtkStyleContext *context;
- GtkStateFlags state;
- GtkBorder tmp;
-
- context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
-
- gtk_style_context_get_padding (context, state, border);
- gtk_style_context_get_border (context, state, &tmp);
- border->top += tmp.top;
- border->right += tmp.right;
- border->bottom += tmp.bottom;
- border->left += tmp.left;
+ GtkAllocation clip;
+
+ gtk_widget_set_allocation (widget, allocation);
+
+ gtk_css_gadget_allocate (GTK_CELL_VIEW (widget)->priv->gadget,
+ allocation,
+ gtk_widget_get_allocated_baseline (widget),
+ &clip);
+
+ gtk_widget_set_clip (widget, &clip);
}
static void
-gtk_cell_view_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+gtk_cell_view_allocate (GtkCssGadget *gadget,
+ const GtkAllocation *allocation,
+ int baseline,
+ GtkAllocation *out_clip,
+ gpointer data)
{
- GtkCellView *cellview = GTK_CELL_VIEW (widget);
- GtkCellViewPrivate *priv = cellview->priv;
- gint alloc_width, alloc_height, width, height;
- GtkBorder border;
+ GtkWidget *widget;
+ GtkCellView *cellview;
+ GtkCellViewPrivate *priv;
+ gint alloc_width, alloc_height, width, height;
- get_padding_and_border (widget, &border);
- gtk_widget_set_allocation (widget, allocation);
+ widget = gtk_css_gadget_get_owner (gadget);
+ cellview = GTK_CELL_VIEW (widget);
+ priv = cellview->priv;
- width = allocation->width - border.left - border.right;
- height = allocation->height - border.top - border.bottom;
+ width = allocation->width;
+ height = allocation->height;
gtk_cell_area_context_get_allocation (priv->context, &alloc_width, &alloc_height);
- /* The first cell view in context is responsible for allocating the context at allocate time
- * (or the cellview has its own context and is not grouped with any other cell views)
+ /* The first cell view in context is responsible for allocating the context at
+ * allocate time (or the cellview has its own context and is not grouped with
+ * any other cell views)
*
- * If the cellview is in "fit model" mode, we assume it's not in context and needs to
- * allocate every time.
+ * If the cellview is in "fit model" mode, we assume it's not in context and
+ * needs to allocate every time.
*/
if (priv->fit_model)
gtk_cell_area_context_allocate (priv->context, width, height);
@@ -623,6 +662,8 @@ gtk_cell_view_size_allocate (GtkWidget *widget,
gtk_cell_area_context_allocate (priv->context, width, -1);
else if (alloc_height != allocation->height && priv->orientation == GTK_ORIENTATION_VERTICAL)
gtk_cell_area_context_allocate (priv->context, -1, height);
+
+ *out_clip = *allocation;
}
static void
@@ -686,167 +727,182 @@ gtk_cell_view_get_request_mode (GtkWidget *widget)
}
static void
-gtk_cell_view_get_preferred_width (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
+gtk_cell_view_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
{
- GtkCellView *cellview = GTK_CELL_VIEW (widget);
- GtkCellViewPrivate *priv = cellview->priv;
- GtkBorder border;
-
- get_padding_and_border (widget, &border);
- g_signal_handler_block (priv->context, priv->size_changed_id);
-
- if (priv->fit_model)
- {
- gint min = 0, nat = 0;
- gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_HORIZONTAL, -1, &min, &nat);
- }
- else
- {
- if (cellview->priv->displayed_row)
- gtk_cell_view_set_cell_data (cellview);
-
- gtk_cell_area_get_preferred_width (priv->area, priv->context, widget, NULL, NULL);
- }
-
- gtk_cell_area_context_get_preferred_width (priv->context, minimum_size, natural_size);
-
- g_signal_handler_unblock (priv->context, priv->size_changed_id);
+ gtk_css_gadget_get_preferred_size (GTK_CELL_VIEW (widget)->priv->gadget,
+ GTK_ORIENTATION_HORIZONTAL,
+ -1,
+ minimum, natural,
+ NULL, NULL);
+}
- *minimum_size += border.left + border.right;
- *natural_size += border.left + border.right;
+static void
+gtk_cell_view_get_preferred_width_for_height (GtkWidget *widget,
+ gint height,
+ gint *minimum,
+ gint *natural)
+{
+ gtk_css_gadget_get_preferred_size (GTK_CELL_VIEW (widget)->priv->gadget,
+ GTK_ORIENTATION_HORIZONTAL,
+ height,
+ minimum, natural,
+ NULL, NULL);
}
-static void
+static void
gtk_cell_view_get_preferred_height (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
+ gint *minimum,
+ gint *natural)
{
- GtkCellView *cellview = GTK_CELL_VIEW (widget);
- GtkCellViewPrivate *priv = cellview->priv;
- GtkBorder border;
-
- get_padding_and_border (widget, &border);
-
- g_signal_handler_block (priv->context, priv->size_changed_id);
-
- if (priv->fit_model)
- {
- gint min = 0, nat = 0;
- gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_VERTICAL, -1, &min, &nat);
- }
- else
- {
- if (cellview->priv->displayed_row)
- gtk_cell_view_set_cell_data (cellview);
-
- gtk_cell_area_get_preferred_height (priv->area, priv->context, widget, NULL, NULL);
- }
-
- gtk_cell_area_context_get_preferred_height (priv->context, minimum_size, natural_size);
-
- g_signal_handler_unblock (priv->context, priv->size_changed_id);
+ gtk_css_gadget_get_preferred_size (GTK_CELL_VIEW (widget)->priv->gadget,
+ GTK_ORIENTATION_VERTICAL,
+ -1,
+ minimum, natural,
+ NULL, NULL);
+}
- *minimum_size += border.top + border.bottom;
- *natural_size += border.top + border.bottom;
+static void
+gtk_cell_view_get_preferred_height_for_width (GtkWidget *widget,
+ gint width,
+ gint *minimum,
+ gint *natural)
+{
+ gtk_css_gadget_get_preferred_size (GTK_CELL_VIEW (widget)->priv->gadget,
+ GTK_ORIENTATION_VERTICAL,
+ width,
+ minimum, natural,
+ NULL, NULL);
}
-static void
-gtk_cell_view_get_preferred_width_for_height (GtkWidget *widget,
- gint for_size,
- gint *minimum_size,
- gint *natural_size)
+static void
+gtk_cell_view_measure (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline,
+ gpointer data)
{
- GtkCellView *cellview = GTK_CELL_VIEW (widget);
- GtkCellViewPrivate *priv = cellview->priv;
- GtkBorder border;
+ GtkWidget *widget;
+ GtkCellView *cellview;
+ GtkCellViewPrivate *priv;
- get_padding_and_border (widget, &border);
- for_size -= border.top + border.bottom;
+ widget = gtk_css_gadget_get_owner (gadget);
+ cellview = GTK_CELL_VIEW (widget);
+ priv = cellview->priv;
- if (priv->fit_model)
- {
- gint min = 0, nat = 0;
- gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_HORIZONTAL, for_size, &min, &nat);
+ g_signal_handler_block (priv->context, priv->size_changed_id);
- *minimum_size = min;
- *natural_size = nat;
- }
- else
+ if (orientation == GTK_ORIENTATION_HORIZONTAL && for_size == -1)
{
- if (cellview->priv->displayed_row)
- gtk_cell_view_set_cell_data (cellview);
-
- gtk_cell_area_get_preferred_width_for_height (priv->area, priv->context, widget,
- for_size, minimum_size, natural_size);
- }
+ if (priv->fit_model)
+ {
+ gint min = 0, nat = 0;
+ gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_HORIZONTAL, -1, &min, &nat);
+ }
+ else
+ {
+ if (cellview->priv->displayed_row)
+ gtk_cell_view_set_cell_data (cellview);
- *minimum_size += border.left + border.right;
- *natural_size += border.left + border.right;
-}
+ gtk_cell_area_get_preferred_width (priv->area, priv->context, widget, NULL, NULL);
+ }
-static void
-gtk_cell_view_get_preferred_height_for_width (GtkWidget *widget,
- gint for_size,
- gint *minimum_size,
- gint *natural_size)
-{
- GtkCellView *cellview = GTK_CELL_VIEW (widget);
- GtkCellViewPrivate *priv = cellview->priv;
- GtkBorder border;
+ gtk_cell_area_context_get_preferred_width (priv->context, minimum, natural);
+ }
+ else if (orientation == GTK_ORIENTATION_VERTICAL && for_size == -1)
+ {
+ if (priv->fit_model)
+ {
+ gint min = 0, nat = 0;
+ gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_VERTICAL, -1, &min, &nat);
+ }
+ else
+ {
+ if (cellview->priv->displayed_row)
+ gtk_cell_view_set_cell_data (cellview);
- get_padding_and_border (widget, &border);
- for_size -= border.left + border.right;
+ gtk_cell_area_get_preferred_height (priv->area, priv->context, widget, NULL, NULL);
+ }
- if (priv->fit_model)
+ gtk_cell_area_context_get_preferred_height (priv->context, minimum, natural);
+ }
+ else if (orientation == GTK_ORIENTATION_HORIZONTAL && for_size >= 0)
{
- gint min = 0, nat = 0;
- gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_VERTICAL, for_size, &min, &nat);
+ if (priv->fit_model)
+ {
+ gint min = 0, nat = 0;
+ gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_HORIZONTAL, for_size, &min, &nat);
- *minimum_size = min;
- *natural_size = nat;
+ *minimum = min;
+ *natural = nat;
+ }
+ else
+ {
+ if (cellview->priv->displayed_row)
+ gtk_cell_view_set_cell_data (cellview);
+
+ gtk_cell_area_get_preferred_width_for_height (priv->area, priv->context, widget,
+ for_size, minimum, natural);
+ }
}
else
- {
- if (cellview->priv->displayed_row)
- gtk_cell_view_set_cell_data (cellview);
+ {
+ if (priv->fit_model)
+ {
+ gint min = 0, nat = 0;
+ gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_VERTICAL, for_size, &min, &nat);
- gtk_cell_area_get_preferred_height_for_width (priv->area, priv->context, widget,
- for_size, minimum_size, natural_size);
+ *minimum = min;
+ *natural = nat;
+ }
+ else
+ {
+ if (cellview->priv->displayed_row)
+ gtk_cell_view_set_cell_data (cellview);
+
+ gtk_cell_area_get_preferred_height_for_width (priv->area, priv->context, widget,
+ for_size, minimum, natural);
+ }
}
- *minimum_size += border.top + border.bottom;
- *natural_size += border.top + border.bottom;
+ g_signal_handler_unblock (priv->context, priv->size_changed_id);
}
static gboolean
gtk_cell_view_draw (GtkWidget *widget,
cairo_t *cr)
{
+ gtk_css_gadget_draw (GTK_CELL_VIEW (widget)->priv->gadget, cr);
+
+ return FALSE;
+}
+
+static gboolean
+gtk_cell_view_render (GtkCssGadget *gadget,
+ cairo_t *cr,
+ int x,
+ int y,
+ int width,
+ int height,
+ gpointer data)
+{
+ GtkWidget *widget;
GtkCellView *cellview;
GdkRectangle area;
GtkCellRendererState state;
- GtkBorder border;
- GtkStyleContext *context;
+ widget = gtk_css_gadget_get_owner (gadget);
cellview = GTK_CELL_VIEW (widget);
- context = gtk_widget_get_style_context (widget);
-
- get_padding_and_border (widget, &border);
/* render cells */
- area.x = border.left;
- area.y = border.top;
- area.width = gtk_widget_get_allocated_width (widget) - border.left - border.right;
- area.height = gtk_widget_get_allocated_height (widget) - border.top - border.bottom;
-
- gtk_render_background (context, cr,
- 0, 0,
- gtk_widget_get_allocated_width (widget), gtk_widget_get_allocated_height (widget));
- gtk_render_frame (context, cr,
- 0, 0,
- gtk_widget_get_allocated_width (widget), gtk_widget_get_allocated_height (widget));
+ area.x = x;
+ area.y = y;
+ area.width = width;
+ area.height = height;
/* "blank" background */
if (cellview->priv->background_set)
@@ -866,9 +922,9 @@ gtk_cell_view_draw (GtkWidget *widget,
state = GTK_CELL_RENDERER_PRELIT;
else
state = 0;
-
+
/* Render the cells */
- gtk_cell_area_render (cellview->priv->area, cellview->priv->context,
+ gtk_cell_area_render (cellview->priv->area, cellview->priv->context,
widget, cr, &area, &area, state, FALSE);
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]