[gtk+/refactor: 132/137] demos/gtk-demo/offscreen_window.c: Use accessor functions to access GtkWidget



commit 153c7abb080069365b41155209c1d058aad148f1
Author: Javier Jardón <jjardon gnome org>
Date:   Mon Aug 16 00:37:17 2010 +0200

    demos/gtk-demo/offscreen_window.c: Use accessor functions to access GtkWidget

 demos/gtk-demo/offscreen_window.c |   61 ++++++++++++++++++++++---------------
 1 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/demos/gtk-demo/offscreen_window.c b/demos/gtk-demo/offscreen_window.c
index 9a74776..e4b454d 100644
--- a/demos/gtk-demo/offscreen_window.c
+++ b/demos/gtk-demo/offscreen_window.c
@@ -74,7 +74,7 @@ to_child (GtkRotatedBin *bin,
 
   s = sin (bin->angle);
   c = cos (bin->angle);
-  child_area = bin->child->allocation;
+  gtk_widget_get_allocation (bin->child, &child_area);
 
   w = c * child_area.width + s * child_area.height;
   h = s * child_area.width + c * child_area.height;
@@ -114,7 +114,7 @@ to_parent (GtkRotatedBin *bin,
 
   s = sin (bin->angle);
   c = cos (bin->angle);
-  child_area = bin->child->allocation;
+  gtk_widget_get_allocation (bin->child, &child_area);
 
   w = c * child_area.width + s * child_area.height;
   h = s * child_area.width + c * child_area.height;
@@ -188,7 +188,7 @@ pick_offscreen_child (GdkWindow     *offscreen_window,
     {
       to_child (bin, widget_x, widget_y, &x, &y);
 
-      child_area = bin->child->allocation;
+      gtk_widget_get_allocation (bin->child, &child_area);
 
       if (x >= 0 && x < child_area.width &&
           y >= 0 && y < child_area.height)
@@ -224,6 +224,9 @@ static void
 gtk_rotated_bin_realize (GtkWidget *widget)
 {
   GtkRotatedBin *bin = GTK_ROTATED_BIN (widget);
+  GtkAllocation allocation;
+  GtkStyle *style;
+  GdkWindow *window;
   GdkWindowAttr attributes;
   gint attributes_mask;
   guint border_width;
@@ -231,12 +234,13 @@ gtk_rotated_bin_realize (GtkWidget *widget)
 
   gtk_widget_set_realized (widget, TRUE);
 
+  gtk_widget_get_allocation (widget, &allocation);
   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
 
-  attributes.x = widget->allocation.x + border_width;
-  attributes.y = widget->allocation.y + border_width;
-  attributes.width = widget->allocation.width - 2 * border_width;
-  attributes.height = widget->allocation.height - 2 * border_width;
+  attributes.x = allocation.x + border_width;
+  attributes.y = allocation.y + border_width;
+  attributes.width = allocation.width - 2 * border_width;
+  attributes.height = allocation.height - 2 * border_width;
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.event_mask = gtk_widget_get_events (widget)
                         | GDK_EXPOSURE_MASK
@@ -253,10 +257,11 @@ gtk_rotated_bin_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, widget);
-  g_signal_connect (widget->window, "pick-embedded-child",
+  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, widget);
+  g_signal_connect (window, "pick-embedded-child",
                     G_CALLBACK (pick_offscreen_child), bin);
 
   attributes.window_type = GDK_WINDOW_OFFSCREEN;
@@ -264,24 +269,27 @@ gtk_rotated_bin_realize (GtkWidget *widget)
   child_requisition.width = child_requisition.height = 0;
   if (bin->child && gtk_widget_get_visible (bin->child))
     {
-      attributes.width = bin->child->allocation.width;
-      attributes.height = bin->child->allocation.height;
+      GtkAllocation child_allocation;
+
+      gtk_widget_get_allocation (bin->child, &child_allocation);
+      attributes.width = child_allocation.width;
+      attributes.height = child_allocation.height;
     }
   bin->offscreen_window = gdk_window_new (gtk_widget_get_root_window (widget),
                                           &attributes, attributes_mask);
   gdk_window_set_user_data (bin->offscreen_window, widget);
   if (bin->child)
     gtk_widget_set_parent_window (bin->child, bin->offscreen_window);
-  gdk_offscreen_window_set_embedder (bin->offscreen_window, widget->window);
+  gdk_offscreen_window_set_embedder (bin->offscreen_window, window);
   g_signal_connect (bin->offscreen_window, "to-embedder",
                     G_CALLBACK (offscreen_window_to_parent), bin);
   g_signal_connect (bin->offscreen_window, "from-embedder",
                     G_CALLBACK (offscreen_window_from_parent), bin);
 
-  widget->style = gtk_style_attach (widget->style, widget->window);
-
-  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
-  gtk_style_set_background (widget->style, bin->offscreen_window, GTK_STATE_NORMAL);
+  gtk_widget_style_attach (widget);
+  style = gtk_widget_get_style (widget);
+  gtk_style_set_background (style, window, GTK_STATE_NORMAL);
+  gtk_style_set_background (style, bin->offscreen_window, GTK_STATE_NORMAL);
   gdk_window_show (bin->offscreen_window);
 }
 
@@ -405,7 +413,7 @@ gtk_rotated_bin_size_allocate (GtkWidget     *widget,
   gint w, h;
   gdouble s, c;
 
-  widget->allocation = *allocation;
+  gtk_widget_set_allocation (widget, allocation);
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
 
@@ -413,7 +421,7 @@ gtk_rotated_bin_size_allocate (GtkWidget     *widget,
   h = allocation->height - border_width * 2;
 
   if (gtk_widget_get_realized (widget))
-    gdk_window_move_resize (widget->window,
+    gdk_window_move_resize (gtk_widget_get_window (widget),
                             allocation->x + border_width,
                             allocation->y + border_width,
                             w, h);
@@ -454,7 +462,8 @@ static gboolean
 gtk_rotated_bin_damage (GtkWidget      *widget,
                         GdkEventExpose *event)
 {
-  gdk_window_invalidate_rect (widget->window, NULL, FALSE);
+  gdk_window_invalidate_rect (gtk_widget_get_window (widget),
+                              NULL, FALSE);
 
   return TRUE;
 }
@@ -464,13 +473,15 @@ gtk_rotated_bin_expose (GtkWidget      *widget,
                         GdkEventExpose *event)
 {
   GtkRotatedBin *bin = GTK_ROTATED_BIN (widget);
+  GdkWindow *window;
   gint width, height;
   gdouble s, c;
   gdouble w, h;
 
   if (gtk_widget_is_drawable (widget))
     {
-      if (event->window == widget->window)
+      window = gtk_widget_get_window (widget);
+      if (event->window == window)
         {
           GdkPixmap *pixmap;
           GtkAllocation child_area;
@@ -479,9 +490,9 @@ gtk_rotated_bin_expose (GtkWidget      *widget,
           if (bin->child && gtk_widget_get_visible (bin->child))
             {
               pixmap = gdk_offscreen_window_get_pixmap (bin->offscreen_window);
-              child_area = bin->child->allocation;
+              gtk_widget_get_allocation (bin->child, &child_area);
 
-              cr = gdk_cairo_create (widget->window);
+              cr = gdk_cairo_create (window);
 
               /* transform */
               s = sin (bin->angle);
@@ -507,7 +518,7 @@ gtk_rotated_bin_expose (GtkWidget      *widget,
         }
       else if (event->window == bin->offscreen_window)
         {
-          gtk_paint_flat_box (widget->style, event->window,
+          gtk_paint_flat_box (gtk_widget_get_style (widget), event->window,
                               GTK_STATE_NORMAL, GTK_SHADOW_NONE,
                               &event->area, widget, "blah",
                               0, 0, -1, -1);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]