From 9aba4e706dd999538209aa28fe925269ef76ef85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Mon, 12 Sep 2011 19:10:13 +0100 Subject: [PATCH 5/6] util/show-traps: Use accessor functions intead direct access --- util/show-traps.c | 66 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 41 insertions(+), 25 deletions(-) diff --git a/util/show-traps.c b/util/show-traps.c index 38de9fa..040c824 100644 --- a/util/show-traps.c +++ b/util/show-traps.c @@ -101,9 +101,14 @@ _compute_intersection_point (const line_t *line, static cairo_surface_t * pixmap_create (TrapView *self, cairo_surface_t *target) { - cairo_surface_t *surface = cairo_surface_create_similar (target, CAIRO_CONTENT_COLOR, - self->widget.allocation.width, - self->widget.allocation.height); + GtkAllocation allocation; + cairo_surface_t *surface; + + gtk_widget_get_allocation (&(self->widget), &allocation); + + surface = cairo_surface_create_similar (target, CAIRO_CONTENT_COLOR, + allocation.width, + allocation.height); cairo_t *cr; traps_t *traps; edges_t *edges; @@ -135,11 +140,11 @@ pixmap_create (TrapView *self, cairo_surface_t *target) mid = (extents.p2.x + extents.p1.x) / 2.; dim = (extents.p2.x - extents.p1.x) / 2. * 1.25; - sf_x = self->widget.allocation.width / dim / 2; + sf_x = allocation.width / dim / 2; mid = (extents.p2.y + extents.p1.y) / 2.; dim = (extents.p2.y - extents.p1.y) / 2. * 1.25; - sf_y = self->widget.allocation.height / dim / 2; + sf_y = allocation.height / dim / 2; sf = MIN (sf_x, sf_y); @@ -364,6 +369,7 @@ trap_view_draw (TrapView *self, cairo_t *cr) { traps_t *traps; edges_t *edges; + GtkAllocation allocation; gdouble sf_x, sf_y, sf; gdouble mid, dim; gdouble x0, y0; @@ -372,13 +378,15 @@ trap_view_draw (TrapView *self, cairo_t *cr) box_t extents; point_t p; - if (self->pixmap_width != self->widget.allocation.width || - self->pixmap_height != self->widget.allocation.height) + gtk_widget_get_allocation (&(self->widget), &allocation); + + if (self->pixmap_width != allocation.width || + self->pixmap_height != allocation.height) { cairo_surface_destroy (self->pixmap); self->pixmap = pixmap_create (self, cairo_get_target (cr)); - self->pixmap_width = self->widget.allocation.width; - self->pixmap_height = self->widget.allocation.height; + self->pixmap_width = allocation.width; + self->pixmap_height = allocation.height; } cairo_save (cr); @@ -405,11 +413,11 @@ trap_view_draw (TrapView *self, cairo_t *cr) mid = (extents.p2.x + extents.p1.x) / 2.; dim = (extents.p2.x - extents.p1.x) / 2. * 1.25; - sf_x = self->widget.allocation.width / dim / 2; + sf_x = allocation.width / dim / 2; mid = (extents.p2.y + extents.p1.y) / 2.; dim = (extents.p2.y - extents.p1.y) / 2. * 1.25; - sf_y = self->widget.allocation.height / dim / 2; + sf_y = allocation.height / dim / 2; sf = MIN (sf_x, sf_y); @@ -697,7 +705,7 @@ trap_view_expose (GtkWidget *w, GdkEventExpose *ev) TrapView *self = (TrapView *) w; cairo_t *cr; - cr = gdk_cairo_create (w->window); + cr = gdk_cairo_create (gtk_widget_get_window (w)); gdk_cairo_region (cr, ev->region); cairo_clip (cr); @@ -868,15 +876,19 @@ trap_view_motion (GtkWidget *w, GdkEventMotion *ev) static void trap_view_realize (GtkWidget *widget) { + GtkAllocation allocation; GdkWindowAttr attributes; + GdkWindow *gdk_window; 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); @@ -889,25 +901,29 @@ trap_view_realize (GtkWidget *widget) GDK_BUTTON_MOTION_MASK | GDK_EXPOSURE_MASK; - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, - GDK_WA_X | GDK_WA_Y | - GDK_WA_VISUAL | GDK_WA_COLORMAP); - gdk_window_set_user_data (widget->window, widget); + gdk_window = gdk_window_new (gtk_widget_get_parent_window (widget), + &attributes, + GDK_WA_X | GDK_WA_Y | + GDK_WA_VISUAL | GDK_WA_COLORMAP); + gtk_widget_set_window (widget, gdk_window); + gdk_window_set_user_data (gdk_window, widget); - widget->style = gtk_style_attach (widget->style, widget->window); - gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + gtk_widget_style_attach (widget); + gtk_style_set_background (gtk_widget_get_style (widget), gdk_window, GTK_STATE_NORMAL); } static void trap_view_size_allocate (GtkWidget *w, GdkRectangle *r) { TrapView *self = (TrapView *) w; + GtkAllocation allocation; GTK_WIDGET_CLASS (trap_view_parent_class)->size_allocate (w, r); - self->mag_x = w->allocation.width - self->mag_size - 10; - self->mag_y = w->allocation.height - self->mag_size - 10; + gtk_widget_get_allocation (w, &allocation); + + self->mag_x = allocation.width - self->mag_size - 10; + self->mag_y = allocation.height - self->mag_size - 10; } static void -- 1.7.5.4