[gtk+/rendering-cleanup-next: 32/153] accellabel: Port to draw vfunc
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/rendering-cleanup-next: 32/153] accellabel: Port to draw vfunc
- Date: Sat, 11 Sep 2010 04:54:07 +0000 (UTC)
commit 688a9bd94c73ad1aaf88fd0c178ba2ec14d42d1b
Author: Benjamin Otte <otte redhat com>
Date: Sun Sep 5 20:42:56 2010 +0200
accellabel: Port to draw vfunc
gtk/gtkaccellabel.c | 49 +++++++++++++++++++++++++++++--------------------
1 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index 564213c..6c7e3ba 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -120,8 +120,10 @@ static void gtk_accel_label_get_property (GObject *object,
GParamSpec *pspec);
static void gtk_accel_label_destroy (GtkObject *object);
static void gtk_accel_label_finalize (GObject *object);
-static gboolean gtk_accel_label_expose_event (GtkWidget *widget,
- GdkEventExpose *event);
+static gboolean gtk_accel_label_draw (GtkWidget *widget,
+ cairo_t *cr,
+ int width,
+ int height);
static const gchar *gtk_accel_label_get_string (GtkAccelLabel *accel_label);
@@ -152,7 +154,7 @@ gtk_accel_label_class_init (GtkAccelLabelClass *class)
object_class->destroy = gtk_accel_label_destroy;
- widget_class->expose_event = gtk_accel_label_expose_event;
+ widget_class->draw = gtk_accel_label_draw;
class->signal_quote1 = g_strdup ("<:");
class->signal_quote2 = g_strdup (":>");
@@ -388,8 +390,10 @@ get_first_baseline (PangoLayout *layout)
}
static gboolean
-gtk_accel_label_expose_event (GtkWidget *widget,
- GdkEventExpose *event)
+gtk_accel_label_draw (GtkWidget *widget,
+ cairo_t *cr,
+ int width,
+ int height)
{
GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
GtkMisc *misc = GTK_MISC (accel_label);
@@ -419,42 +423,47 @@ gtk_accel_label_expose_event (GtkWidget *widget,
label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
+ cairo_save (cr);
+
if (direction == GTK_TEXT_DIR_RTL)
- allocation.x += ac_width;
- allocation.width -= ac_width;
+ cairo_translate (cr, ac_width, 0);
if (gtk_label_get_ellipsize (label))
pango_layout_set_width (label_layout,
pango_layout_get_width (label_layout)
- ac_width * PANGO_SCALE);
- if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
- GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
- if (direction == GTK_TEXT_DIR_RTL)
- allocation.x -= ac_width;
- allocation.width += ac_width;
+ /* XXX: We cheat here.
+ * We pass a too small width to the label's draw func. We do know
+ * that the label handles this correctly, so it's fine.
+ */
+ if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget,
+ cr,
+ width - ac_width,
+ height);
if (gtk_label_get_ellipsize (label))
pango_layout_set_width (label_layout,
pango_layout_get_width (label_layout)
+ ac_width * PANGO_SCALE);
+ cairo_restore (cr);
gtk_misc_get_padding (misc, &xpad, NULL);
if (direction == GTK_TEXT_DIR_RTL)
- x = allocation.x + xpad;
+ x = xpad;
else
- x = allocation.x + allocation.width - xpad - ac_width;
+ x = width - xpad - ac_width;
gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
- y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
+ y += get_first_baseline (label_layout) - get_first_baseline (accel_layout) - allocation.y;
- gtk_paint_layout (gtk_widget_get_style (widget),
- gtk_widget_get_window (widget),
+ gtk_cairo_paint_layout (gtk_widget_get_style (widget),
+ cr,
gtk_widget_get_state (widget),
FALSE,
- &event->area,
widget,
"accellabel",
x, y,
@@ -464,8 +473,8 @@ gtk_accel_label_expose_event (GtkWidget *widget,
}
else
{
- if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
- GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
+ if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget, cr, width, height);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]