[gtk+/refactor: 34/138] gtk/gtkruler.c: use accessor functions to access GtkWidget
- From: Javier Jardón <jjardon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/refactor: 34/138] gtk/gtkruler.c: use accessor functions to access GtkWidget
- Date: Mon, 16 Aug 2010 06:12:18 +0000 (UTC)
commit ff877eb8f84249e68ddba1ba3f9f25bdc432663e
Author: Javier Jardón <jjardon gnome org>
Date: Wed Aug 11 23:02:44 2010 +0200
gtk/gtkruler.c: use accessor functions to access GtkWidget
gtk/gtkruler.c | 125 +++++++++++++++++++++++++++++++++++--------------------
1 files changed, 79 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtkruler.c b/gtk/gtkruler.c
index 1e32dc6..a88965b 100644
--- a/gtk/gtkruler.c
+++ b/gtk/gtkruler.c
@@ -189,8 +189,10 @@ gtk_ruler_class_init (GtkRulerClass *class)
static void
gtk_ruler_init (GtkRuler *ruler)
{
- GtkWidget *widget = GTK_WIDGET (ruler);
+ GtkRequisition requisition;
GtkRulerPriv *priv;
+ GtkStyle *style;
+ GtkWidget *widget = GTK_WIDGET (ruler);
ruler->priv = G_TYPE_INSTANCE_GET_PRIVATE (ruler,
GTK_TYPE_RULER,
@@ -199,8 +201,10 @@ gtk_ruler_init (GtkRuler *ruler)
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
- widget->requisition.width = widget->style->xthickness * 2 + 1;
- widget->requisition.height = widget->style->ythickness * 2 + RULER_WIDTH;
+ style = gtk_widget_get_style (widget);
+ requisition.width = style->xthickness * 2 + 1;
+ requisition.height = style->ythickness * 2 + RULER_WIDTH;
+ _gtk_widget_set_requisition (widget, &requisition);
priv->backing_store = NULL;
priv->xsrc = 0;
@@ -460,7 +464,9 @@ gtk_ruler_draw_pos (GtkRuler *ruler)
static void
gtk_ruler_realize (GtkWidget *widget)
{
+ GtkAllocation allocation;
GtkRuler *ruler;
+ GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
@@ -468,11 +474,13 @@ gtk_ruler_realize (GtkWidget *widget)
gtk_widget_set_realized (widget, TRUE);
+ gtk_widget_get_allocation (widget, &allocation);
+
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
@@ -483,11 +491,14 @@ gtk_ruler_realize (GtkWidget *widget)
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
- widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
- gdk_window_set_user_data (widget->window, ruler);
+ window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gtk_widget_set_window (widget, window);
+ gdk_window_set_user_data (window, ruler);
- widget->style = gtk_style_attach (widget->style, widget->window);
- gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
+ gtk_widget_style_attach (widget);
+ gtk_style_set_background (gtk_widget_get_style (widget),
+ window, GTK_STATE_ACTIVE);
gtk_ruler_make_pixmap (ruler);
}
@@ -513,16 +524,19 @@ gtk_ruler_size_request (GtkWidget *widget,
{
GtkRuler *ruler = GTK_RULER (widget);
GtkRulerPriv *priv = ruler->priv;
+ GtkStyle *style;
+
+ style = gtk_widget_get_style (widget);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
- requisition->width = widget->style->xthickness * 2 + 1;
- requisition->height = widget->style->ythickness * 2 + RULER_WIDTH;
+ requisition->width = style->xthickness * 2 + 1;
+ requisition->height = style->ythickness * 2 + RULER_WIDTH;
}
else
{
- requisition->width = widget->style->xthickness * 2 + RULER_WIDTH;
- requisition->height = widget->style->ythickness * 2 + 1;
+ requisition->width = style->xthickness * 2 + RULER_WIDTH;
+ requisition->height = style->ythickness * 2 + 1;
}
}
@@ -532,11 +546,11 @@ gtk_ruler_size_allocate (GtkWidget *widget,
{
GtkRuler *ruler = GTK_RULER (widget);
- widget->allocation = *allocation;
+ gtk_widget_set_allocation (widget, allocation);
if (gtk_widget_get_realized (widget))
{
- gdk_window_move_resize (widget->window,
+ gdk_window_move_resize (gtk_widget_get_window (widget),
allocation->x, allocation->y,
allocation->width, allocation->height);
@@ -548,6 +562,7 @@ static gboolean
gtk_ruler_motion_notify (GtkWidget *widget,
GdkEventMotion *event)
{
+ GtkAllocation allocation;
GtkRuler *ruler = GTK_RULER (widget);
GtkRulerPriv *priv = ruler->priv;
gint x;
@@ -557,10 +572,11 @@ gtk_ruler_motion_notify (GtkWidget *widget,
x = event->x;
y = event->y;
+ gtk_widget_get_allocation (widget, &allocation);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- priv->position = priv->lower + ((priv->upper - priv->lower) * x) / widget->allocation.width;
+ priv->position = priv->lower + ((priv->upper - priv->lower) * x) / allocation.width;
else
- priv->position = priv->lower + ((priv->upper - priv->lower) * y) / widget->allocation.height;
+ priv->position = priv->lower + ((priv->upper - priv->lower) * y) / allocation.height;
g_object_notify (G_OBJECT (ruler), "position");
@@ -582,8 +598,8 @@ gtk_ruler_expose (GtkWidget *widget,
cairo_t *cr;
gtk_ruler_draw_ticks (ruler);
-
- cr = gdk_cairo_create (widget->window);
+
+ cr = gdk_cairo_create (gtk_widget_get_window (widget));
gdk_cairo_set_source_pixmap (cr, priv->backing_store, 0, 0);
gdk_cairo_rectangle (cr, &event->area);
cairo_fill (cr);
@@ -598,6 +614,7 @@ gtk_ruler_expose (GtkWidget *widget,
static void
gtk_ruler_make_pixmap (GtkRuler *ruler)
{
+ GtkAllocation allocation;
GtkRulerPriv *priv = ruler->priv;
GtkWidget *widget;
gint width;
@@ -605,19 +622,21 @@ gtk_ruler_make_pixmap (GtkRuler *ruler)
widget = GTK_WIDGET (ruler);
+ gtk_widget_get_allocation (widget, &allocation);
+
if (priv->backing_store)
{
gdk_drawable_get_size (priv->backing_store, &width, &height);
- if ((width == widget->allocation.width) &&
- (height == widget->allocation.height))
+ if ((width == allocation.width) &&
+ (height == allocation.height))
return;
g_object_unref (priv->backing_store);
}
- priv->backing_store = gdk_pixmap_new (widget->window,
- widget->allocation.width,
- widget->allocation.height,
+ priv->backing_store = gdk_pixmap_new (gtk_widget_get_window (widget),
+ allocation.width,
+ allocation.height,
-1);
priv->xsrc = 0;
@@ -627,8 +646,10 @@ gtk_ruler_make_pixmap (GtkRuler *ruler)
static void
gtk_ruler_real_draw_ticks (GtkRuler *ruler)
{
+ GtkAllocation allocation;
GtkWidget *widget = GTK_WIDGET (ruler);
GtkRulerPriv *priv = ruler->priv;
+ GtkStyle *style;
cairo_t *cr;
gint i, j;
gint width, height;
@@ -652,8 +673,11 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
if (!gtk_widget_is_drawable (widget))
return;
- xthickness = widget->style->xthickness;
- ythickness = widget->style->ythickness;
+ style = gtk_widget_get_style (widget);
+ gtk_widget_get_allocation (widget, &allocation);
+
+ xthickness = style->xthickness;
+ ythickness = style->ythickness;
layout = gtk_widget_create_pango_layout (widget, "012456789");
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
@@ -663,34 +687,34 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
- width = widget->allocation.width;
- height = widget->allocation.height - ythickness * 2;
+ width = allocation.width;
+ height = allocation.height - ythickness * 2;
}
else
{
- width = widget->allocation.height;
- height = widget->allocation.width - ythickness * 2;
+ width = allocation.height;
+ height = allocation.width - ythickness * 2;
}
#define DETAILE(private) (priv->orientation == GTK_ORIENTATION_HORIZONTAL ? "hruler" : "vruler");
- gtk_paint_box (widget->style, priv->backing_store,
+ gtk_paint_box (style, priv->backing_store,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
NULL, widget,
priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
"hruler" : "vruler",
0, 0,
- widget->allocation.width, widget->allocation.height);
+ allocation.width, allocation.height);
cr = gdk_cairo_create (priv->backing_store);
- gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
+ gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
cairo_rectangle (cr,
xthickness,
height + ythickness,
- widget->allocation.width - 2 * xthickness,
+ allocation.width - 2 * xthickness,
1);
}
else
@@ -699,7 +723,7 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
height + xthickness,
ythickness,
1,
- widget->allocation.height - 2 * ythickness);
+ allocation.height - 2 * ythickness);
}
upper = priv->upper / priv->metric->pixels_per_unit;
@@ -797,7 +821,7 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
pango_layout_set_text (layout, unit_str, -1);
pango_layout_get_extents (layout, &logical_rect, NULL);
- gtk_paint_layout (widget->style,
+ gtk_paint_layout (style,
priv->backing_store,
gtk_widget_get_state (widget),
FALSE,
@@ -814,7 +838,7 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
pango_layout_set_text (layout, unit_str + j, 1);
pango_layout_get_extents (layout, NULL, &logical_rect);
- gtk_paint_layout (widget->style,
+ gtk_paint_layout (style,
priv->backing_store,
gtk_widget_get_state (widget),
FALSE,
@@ -840,8 +864,10 @@ out:
static void
gtk_ruler_real_draw_pos (GtkRuler *ruler)
{
+ GtkAllocation allocation;
GtkWidget *widget = GTK_WIDGET (ruler);
GtkRulerPriv *priv = ruler->priv;
+ GtkStyle *style;
gint x, y;
gint width, height;
gint bs_width, bs_height;
@@ -851,10 +877,13 @@ gtk_ruler_real_draw_pos (GtkRuler *ruler)
if (gtk_widget_is_drawable (widget))
{
- xthickness = widget->style->xthickness;
- ythickness = widget->style->ythickness;
- width = widget->allocation.width;
- height = widget->allocation.height;
+ style = gtk_widget_get_style (widget);
+ gtk_widget_get_allocation (widget, &allocation);
+
+ xthickness = style->xthickness;
+ ythickness = style->ythickness;
+ width = allocation.width;
+ height = allocation.height;
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
@@ -875,11 +904,15 @@ gtk_ruler_real_draw_pos (GtkRuler *ruler)
if ((bs_width > 0) && (bs_height > 0))
{
- cairo_t *cr = gdk_cairo_create (widget->window);
+ GdkWindow *window;
+
+ window = gtk_widget_get_window (widget);
+
+ cairo_t *cr = gdk_cairo_create (window);
/* If a backing store exists, restore the ruler */
if (priv->backing_store) {
- cairo_t *cr = gdk_cairo_create (widget->window);
+ cairo_t *cr = gdk_cairo_create (window);
gdk_cairo_set_source_pixmap (cr, priv->backing_store, 0, 0);
cairo_rectangle (cr, priv->xsrc, priv->ysrc, bs_width, bs_height);
@@ -903,7 +936,7 @@ gtk_ruler_real_draw_pos (GtkRuler *ruler)
y = ROUND ((priv->position - priv->lower) * increment) + (ythickness - bs_height) / 2 - 1;
}
- gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
+ gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]);
cairo_move_to (cr, x, y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]