summaryrefslogtreecommitdiff
path: root/gtk/gtkiconhelper.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-12-14 04:00:31 +0100
committerMatthias Clasen <mclasen@redhat.com>2015-12-15 08:41:16 -0500
commit4586503e93c8a8aad2b78602302d8ddc7b48d46b (patch)
treec442ff49bbb1c4df1710301387d29902dad7654f /gtk/gtkiconhelper.c
parente723fccaa975b710536f5073d110610344da9b17 (diff)
downloadgtk+-4586503e93c8a8aad2b78602302d8ddc7b48d46b.tar.gz
iconhelper: Finish gadget conversion
Implement missing vfuncs
Diffstat (limited to 'gtk/gtkiconhelper.c')
-rw-r--r--gtk/gtkiconhelper.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index bc82ee0a43..deac87c661 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -84,6 +84,60 @@ _gtk_icon_helper_clear (GtkIconHelper *self)
}
static void
+gtk_icon_helper_get_preferred_size (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ gint for_size,
+ gint *minimum,
+ gint *natural,
+ gint *minimum_baseline,
+ gint *natural_baseline)
+{
+ GtkIconHelper *self = GTK_ICON_HELPER (gadget);
+ int icon_width, icon_height;
+
+ _gtk_icon_helper_get_size (self, &icon_width, &icon_height);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ *minimum = *natural = icon_width;
+ else
+ *minimum = *natural = icon_height;
+
+ if (minimum_baseline)
+ *minimum_baseline = 0;
+ if (natural_baseline)
+ *natural_baseline = 0;
+}
+
+static void
+gtk_icon_helper_allocate (GtkCssGadget *gadget,
+ const GtkAllocation *allocation,
+ int baseline,
+ GtkAllocation *out_clip)
+{
+ GTK_CSS_GADGET_CLASS (gtk_icon_helper_parent_class)->allocate (gadget, allocation, baseline, out_clip);
+}
+
+static gboolean
+gtk_icon_helper_draw (GtkCssGadget *gadget,
+ cairo_t *cr,
+ int x,
+ int y,
+ int width,
+ int height)
+{
+ GtkIconHelper *self = GTK_ICON_HELPER (gadget);
+ int icon_width, icon_height;
+
+ _gtk_icon_helper_get_size (self, &icon_width, &icon_height);
+ _gtk_icon_helper_draw (self,
+ cr,
+ x + (width - icon_width) / 2,
+ y + (height - icon_height) / 2);
+
+ return FALSE;
+}
+
+static void
gtk_icon_helper_style_changed (GtkCssGadget *gadget,
GtkCssStyleChange *change)
{
@@ -128,6 +182,9 @@ gtk_icon_helper_class_init (GtkIconHelperClass *klass)
GtkCssGadgetClass *gadget_class = GTK_CSS_GADGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ gadget_class->get_preferred_size = gtk_icon_helper_get_preferred_size;
+ gadget_class->allocate = gtk_icon_helper_allocate;
+ gadget_class->draw = gtk_icon_helper_draw;
gadget_class->style_changed = gtk_icon_helper_style_changed;
object_class->constructed = gtk_icon_helper_constructed;
@@ -783,6 +840,26 @@ gtk_icon_helper_new (GtkCssNode *node,
NULL);
}
+GtkCssGadget *
+gtk_icon_helper_new_named (const char *name,
+ GtkWidget *owner)
+{
+ GtkIconHelper *result;
+ GtkCssNode *node;
+
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (owner), NULL);
+
+ node = gtk_css_node_new ();
+ gtk_css_node_set_name (node, g_intern_string (name));
+
+ result = gtk_icon_helper_new (node, owner);
+
+ g_object_unref (node);
+
+ return GTK_CSS_GADGET (result);
+}
+
void
_gtk_icon_helper_draw (GtkIconHelper *self,
cairo_t *cr,