]> Pileus Git - ~andy/gtk/blobdiff - demos/gtk-demo/offscreen_window.c
Use gtk_box_new() instead gtk_[v|h]box_new()
[~andy/gtk] / demos / gtk-demo / offscreen_window.c
index b1d766e5a0aad3bce4c9d3de76faabbf2453402a..6a11786b8598b72f58f02f0df4e3f84140b01b21 100644 (file)
@@ -45,8 +45,8 @@ static void     gtk_rotated_bin_size_allocate (GtkWidget       *widget,
                                                GtkAllocation   *allocation);
 static gboolean gtk_rotated_bin_damage        (GtkWidget       *widget,
                                                GdkEventExpose  *event);
-static gboolean gtk_rotated_bin_expose        (GtkWidget       *widget,
-                                               GdkEventExpose  *offscreen);
+static gboolean gtk_rotated_bin_draw          (GtkWidget       *widget,
+                                               cairo_t         *cr);
 
 static void     gtk_rotated_bin_add           (GtkContainer    *container,
                                                GtkWidget       *child);
@@ -150,7 +150,7 @@ gtk_rotated_bin_class_init (GtkRotatedBinClass *klass)
   widget_class->unrealize = gtk_rotated_bin_unrealize;
   widget_class->size_request = gtk_rotated_bin_size_request;
   widget_class->size_allocate = gtk_rotated_bin_size_allocate;
-  widget_class->expose_event = gtk_rotated_bin_expose;
+  widget_class->draw = gtk_rotated_bin_draw;
 
   g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
                                    GTK_TYPE_ROTATED_BIN,
@@ -252,10 +252,9 @@ gtk_rotated_bin_realize (GtkWidget *widget)
                         | GDK_LEAVE_NOTIFY_MASK;
 
   attributes.visual = gtk_widget_get_visual (widget);
-  attributes.colormap = gtk_widget_get_colormap (widget);
   attributes.wclass = GDK_INPUT_OUTPUT;
 
-  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
 
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
@@ -392,7 +391,7 @@ gtk_rotated_bin_size_request (GtkWidget      *widget,
   child_requisition.height = 0;
 
   if (bin->child && gtk_widget_get_visible (bin->child))
-    gtk_size_request_get_size (GTK_SIZE_REQUEST (bin->child),
+    gtk_widget_get_preferred_size ( (bin->child),
                                &child_requisition, NULL);
 
   s = sin (bin->angle);
@@ -435,8 +434,8 @@ gtk_rotated_bin_size_allocate (GtkWidget     *widget,
       s = sin (bin->angle);
       c = cos (bin->angle);
 
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (bin->child),
-                                 &child_requisition, NULL);
+      gtk_widget_get_preferred_size (bin->child,
+                                     &child_requisition, NULL);
       child_allocation.x = 0;
       child_allocation.y = 0;
       child_allocation.height = child_requisition.height;
@@ -471,66 +470,61 @@ gtk_rotated_bin_damage (GtkWidget      *widget,
 }
 
 static gboolean
-gtk_rotated_bin_expose (GtkWidget      *widget,
-                        GdkEventExpose *event)
+gtk_rotated_bin_draw (GtkWidget *widget,
+                      cairo_t   *cr)
 {
   GtkRotatedBin *bin = GTK_ROTATED_BIN (widget);
   GdkWindow *window;
-  gint width, height;
   gdouble s, c;
   gdouble w, h;
 
-  if (gtk_widget_is_drawable (widget))
+  window = gtk_widget_get_window (widget);
+  if (gtk_cairo_should_draw_window (cr, window))
     {
-      window = gtk_widget_get_window (widget);
-      if (event->window == window)
-        {
-          cairo_surface_t *surface;
-          GtkAllocation child_area;
-          cairo_t *cr;
-
-          if (bin->child && gtk_widget_get_visible (bin->child))
-            {
-              surface = gdk_offscreen_window_get_surface (bin->offscreen_window);
-              gtk_widget_get_allocation (bin->child, &child_area);
-
-              cr = gdk_cairo_create (window);
-
-              /* transform */
-              s = sin (bin->angle);
-              c = cos (bin->angle);
-              w = c * child_area.width + s * child_area.height;
-              h = s * child_area.width + c * child_area.height;
-
-              cairo_translate (cr, (w - child_area.width) / 2, (h - child_area.height) / 2);
-              cairo_translate (cr, child_area.width / 2, child_area.height / 2);
-              cairo_rotate (cr, bin->angle);
-              cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
-
-              /* clip */
-              gdk_drawable_get_size (bin->offscreen_window, &width, &height);
-              cairo_rectangle (cr, 0, 0, width, height);
-              cairo_clip (cr);
-              /* paint */
-              cairo_set_source_surface (cr, surface, 0, 0);
-              cairo_paint (cr);
-
-              cairo_destroy (cr);
-            }
-        }
-      else if (event->window == bin->offscreen_window)
+      cairo_surface_t *surface;
+      GtkAllocation child_area;
+
+      if (bin->child && gtk_widget_get_visible (bin->child))
         {
-          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);
-
-          if (bin->child)
-            gtk_container_propagate_expose (GTK_CONTAINER (widget),
-                                            bin->child,
-                                            event);
+          surface = gdk_offscreen_window_get_surface (bin->offscreen_window);
+          gtk_widget_get_allocation (bin->child, &child_area);
+
+          /* transform */
+          s = sin (bin->angle);
+          c = cos (bin->angle);
+          w = c * child_area.width + s * child_area.height;
+          h = s * child_area.width + c * child_area.height;
+
+          cairo_translate (cr, (w - child_area.width) / 2, (h - child_area.height) / 2);
+          cairo_translate (cr, child_area.width / 2, child_area.height / 2);
+          cairo_rotate (cr, bin->angle);
+          cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
+
+          /* clip */
+          cairo_rectangle (cr,
+                           0, 0,
+                           gdk_window_get_width (bin->offscreen_window),
+                           gdk_window_get_height (bin->offscreen_window));
+          cairo_clip (cr);
+          /* paint */
+          cairo_set_source_surface (cr, surface, 0, 0);
+          cairo_paint (cr);
         }
     }
+  if (gtk_cairo_should_draw_window (cr, bin->offscreen_window))
+    {
+      gtk_paint_flat_box (gtk_widget_get_style (widget), cr,
+                          GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+                          widget, "blah",
+                          0, 0,
+                          gdk_window_get_width (bin->offscreen_window),
+                          gdk_window_get_height (bin->offscreen_window));
+
+      if (bin->child)
+        gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                                      bin->child,
+                                      cr);
+    }
 
   return FALSE;
 }
@@ -566,8 +560,9 @@ do_offscreen_window (GtkWidget *do_widget)
       gtk_widget_modify_bg (window, GTK_STATE_NORMAL, &black);
       gtk_container_set_border_width (GTK_CONTAINER (window), 10);
 
-      vbox = gtk_vbox_new (0, FALSE);
-      scale = gtk_hscale_new_with_range (0, G_PI/2, 0.01);
+      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0, FALSE);
+      scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
+                                        0, G_PI/2, 0.01);
       gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
 
       button = gtk_button_new_with_label ("A Button");