[gtk+/wip/matthiasc/gadget: 3/34] spinner: Use a gadget
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/gadget: 3/34] spinner: Use a gadget
- Date: Mon, 14 Dec 2015 06:30:53 +0000 (UTC)
commit 0f31cdc3c97b66ad31cb3e400c527a0398469d47
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Nov 26 14:59:57 2015 -0500
spinner: Use a gadget
This gives us min-width/height support. Currently, the spinner
still has a hardcoded minimum size of 16 and doesn't grow beyond
32. We may want to revisit that at some point.
gtk/gtkspinner.c | 142 ++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 118 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkspinner.c b/gtk/gtkspinner.c
index 6916f72..b97f78b 100644
--- a/gtk/gtkspinner.c
+++ b/gtk/gtkspinner.c
@@ -38,6 +38,7 @@
#include "gtkstylecontextprivate.h"
#include "gtkwidgetprivate.h"
#include "a11y/gtkspinneraccessible.h"
+#include "gtkcsscustomgadgetprivate.h"
/**
@@ -59,8 +60,6 @@
*/
-#define SPINNER_SIZE 16
-
enum {
PROP_0,
PROP_ACTIVE
@@ -68,13 +67,11 @@ enum {
struct _GtkSpinnerPrivate
{
+ GtkCssGadget *gadget;
gboolean active;
};
-static gboolean gtk_spinner_draw (GtkWidget *widget,
- cairo_t *cr);
-static void gtk_spinner_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
+static void gtk_spinner_finalize (GObject *object);
static void gtk_spinner_get_property (GObject *object,
guint param_id,
GValue *value,
@@ -83,15 +80,39 @@ static void gtk_spinner_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
-static void gtk_spinner_set_active (GtkSpinner *spinner,
- gboolean active);
+static gboolean gtk_spinner_draw (GtkWidget *widget,
+ cairo_t *cr);
+static void gtk_spinner_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
static void gtk_spinner_get_preferred_width (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
static void gtk_spinner_get_preferred_height (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
+static void gtk_spinner_set_active (GtkSpinner *spinner,
+ gboolean active);
+static void gtk_spinner_get_content_size (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ gint for_size,
+ gint *minimum,
+ gint *natural,
+ gint *minimum_baseline,
+ gint *natural_baseline,
+ gpointer data);
+static void gtk_spinner_allocate_contents (GtkCssGadget *gadget,
+ const GtkAllocation *allocation,
+ gint baseline,
+ GtkAllocation *out_clip,
+ gpointer data);
+static gboolean gtk_spinner_render_contents (GtkCssGadget *gadget,
+ cairo_t *cr,
+ gint x,
+ gint y,
+ gint width,
+ gint height,
+ gpointer data);
G_DEFINE_TYPE_WITH_PRIVATE (GtkSpinner, gtk_spinner, GTK_TYPE_WIDGET)
@@ -102,6 +123,7 @@ gtk_spinner_class_init (GtkSpinnerClass *klass)
GtkWidgetClass *widget_class;
gobject_class = G_OBJECT_CLASS(klass);
+ gobject_class->finalize = gtk_spinner_finalize;
gobject_class->get_property = gtk_spinner_get_property;
gobject_class->set_property = gtk_spinner_set_property;
@@ -168,49 +190,108 @@ gtk_spinner_set_property (GObject *object,
static void
gtk_spinner_init (GtkSpinner *spinner)
{
+ GtkCssNode *widget_node;
+
spinner->priv = gtk_spinner_get_instance_private (spinner);
gtk_widget_set_has_window (GTK_WIDGET (spinner), FALSE);
+
+ widget_node = gtk_widget_get_css_node (GTK_WIDGET (spinner));
+ spinner->priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
+ GTK_WIDGET (spinner),
+ gtk_spinner_get_content_size,
+ gtk_spinner_allocate_contents,
+ gtk_spinner_render_contents,
+ NULL,
+ NULL);
+}
+
+static void
+gtk_spinner_finalize (GObject *object)
+{
+ GtkSpinner *spinner = GTK_SPINNER (object);
+
+ g_clear_object (&spinner->priv->gadget);
+
+ G_OBJECT_CLASS (gtk_spinner_parent_class)->finalize (object);
+}
+
+static void
+gtk_spinner_get_content_size (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ gint for_size,
+ gint *minimum,
+ gint *natural,
+ gint *minimum_baseline,
+ gint *natural_baseline,
+ gpointer data)
+{
+ *minimum = *natural = 16;
}
static void
gtk_spinner_get_preferred_width (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
+ gint *minimum,
+ gint *natural)
{
- *minimum_size = SPINNER_SIZE;
- *natural_size = SPINNER_SIZE;
+ gtk_css_gadget_get_preferred_size (GTK_SPINNER (widget)->priv->gadget,
+ GTK_ORIENTATION_HORIZONTAL,
+ -1,
+ minimum, natural,
+ NULL, NULL);
}
static void
gtk_spinner_get_preferred_height (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
+ gint *minimum,
+ gint *natural)
{
- *minimum_size = SPINNER_SIZE;
- *natural_size = SPINNER_SIZE;
+ gtk_css_gadget_get_preferred_size (GTK_SPINNER (widget)->priv->gadget,
+ GTK_ORIENTATION_VERTICAL,
+ -1,
+ minimum, natural,
+ NULL, NULL);
}
static void
-gtk_spinner_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+gtk_spinner_allocate_contents (GtkCssGadget *gadget,
+ const GtkAllocation *allocation,
+ gint baseline,
+ GtkAllocation *out_clip,
+ gpointer data)
{
+ GtkWidget *widget;
GtkStyleContext *context;
- GtkAllocation clip;
gint size;
+ widget = gtk_css_gadget_get_owner (gadget);
context = gtk_widget_get_style_context (widget);
size = MIN (allocation->width, allocation->height);
+ gtk_widget_set_allocation (widget, allocation);
+
_gtk_style_context_get_icon_extents (context,
- &clip,
+ out_clip,
allocation->x + (allocation->width - size) / 2,
allocation->y + (allocation->height - size) / 2,
size, size);
- gdk_rectangle_union (&clip, allocation, &clip);
+ gdk_rectangle_union (out_clip, allocation, out_clip);
+}
+
+static void
+gtk_spinner_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkAllocation clip;
gtk_widget_set_allocation (widget, allocation);
+
+ gtk_css_gadget_allocate (GTK_SPINNER (widget)->priv->gadget,
+ allocation,
+ gtk_widget_get_allocated_baseline (widget),
+ &clip);
+
gtk_widget_set_clip (widget, &clip);
}
@@ -218,14 +299,27 @@ static gboolean
gtk_spinner_draw (GtkWidget *widget,
cairo_t *cr)
{
+ gtk_css_gadget_draw (GTK_SPINNER (widget)->priv->gadget, cr);
+
+ return FALSE;
+}
+
+static gboolean
+gtk_spinner_render_contents (GtkCssGadget *gadget,
+ cairo_t *cr,
+ gint x,
+ gint y,
+ gint width,
+ gint height,
+ gpointer data)
+{
+ GtkWidget *widget;
GtkStyleContext *context;
- gint width, height;
gint size;
+ widget = gtk_css_gadget_get_owner (gadget);
context = gtk_widget_get_style_context (widget);
- width = gtk_widget_get_allocated_width (widget);
- height = gtk_widget_get_allocated_height (widget);
size = MIN (width, height);
gtk_render_activity (context, cr,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]