summaryrefslogtreecommitdiff
path: root/gtk/gtkspinner.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2014-05-19 15:33:28 +0200
committerBenjamin Otte <otte@redhat.com>2014-05-24 16:12:20 +0200
commit434f91feff8e59d78d4b9bdb5b17d520a6236fe1 (patch)
treee14b69880cb33b2d4b5cc142843dd0084cd6662c /gtk/gtkspinner.c
parent4f89eb05cf8a09a1ce1de4870fdc4395645a0bdf (diff)
downloadgtk+-434f91feff8e59d78d4b9bdb5b17d520a6236fe1.tar.gz
spinner: Implement clip
We now allow you to gtk-icon-transform() the spinner outside of the spinners allocation.
Diffstat (limited to 'gtk/gtkspinner.c')
-rw-r--r--gtk/gtkspinner.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gtk/gtkspinner.c b/gtk/gtkspinner.c
index fa6933ef73..d6ac9b8616 100644
--- a/gtk/gtkspinner.c
+++ b/gtk/gtkspinner.c
@@ -35,6 +35,7 @@
#include "gtkintl.h"
#include "gtkstylecontext.h"
#include "gtkstylecontextprivate.h"
+#include "gtkwidgetprivate.h"
#include "a11y/gtkspinneraccessible.h"
@@ -67,6 +68,8 @@ struct _GtkSpinnerPrivate
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_property (GObject *object,
guint param_id,
GValue *value,
@@ -98,6 +101,7 @@ gtk_spinner_class_init (GtkSpinnerClass *klass)
gobject_class->set_property = gtk_spinner_set_property;
widget_class = GTK_WIDGET_CLASS(klass);
+ widget_class->size_allocate = gtk_spinner_size_allocate;
widget_class->draw = gtk_spinner_draw;
widget_class->get_preferred_width = gtk_spinner_get_preferred_width;
widget_class->get_preferred_height = gtk_spinner_get_preferred_height;
@@ -186,6 +190,29 @@ gtk_spinner_get_preferred_height (GtkWidget *widget,
*natural_size = SPINNER_SIZE;
}
+static void
+gtk_spinner_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkStyleContext *context;
+ GtkAllocation clip;
+ gint size;
+
+ context = gtk_widget_get_style_context (widget);
+ size = MIN (allocation->width, allocation->height);
+
+ _gtk_style_context_get_icon_extents (context,
+ &clip,
+ allocation->x + (allocation->width - size) / 2,
+ allocation->y + (allocation->height - size) / 2,
+ size, size);
+
+ gdk_rectangle_union (&clip, allocation, &clip);
+
+ gtk_widget_set_allocation (widget, allocation);
+ gtk_widget_set_clip (widget, &clip);
+}
+
static gboolean
gtk_spinner_draw (GtkWidget *widget,
cairo_t *cr)