]> Pileus Git - ~andy/gtk/blobdiff - tests/gtkoffscreenbox.c
gtkmenubutton: Add menu button widget
[~andy/gtk] / tests / gtkoffscreenbox.c
index 5374c07484e6946034d18e760ea8eceb460b12cd..7aeb82cdfd397931dfee78f0bb742c790b4b3e04 100644 (file)
 
 static void        gtk_offscreen_box_realize       (GtkWidget       *widget);
 static void        gtk_offscreen_box_unrealize     (GtkWidget       *widget);
-static void        gtk_offscreen_box_size_request  (GtkWidget       *widget,
-                                                    GtkRequisition  *requisition);
+static void        gtk_offscreen_box_get_preferred_width  (GtkWidget *widget,
+                                                           gint      *minimum,
+                                                           gint      *natural);
+static void        gtk_offscreen_box_get_preferred_height (GtkWidget *widget,
+                                                           gint      *minimum,
+                                                           gint      *natural);
 static void        gtk_offscreen_box_size_allocate (GtkWidget       *widget,
                                                     GtkAllocation   *allocation);
 static gboolean    gtk_offscreen_box_damage        (GtkWidget       *widget,
@@ -47,9 +51,11 @@ to_child_2 (GtkOffscreenBox *offscreen_box,
   x = widget_x;
   y = widget_y;
 
-  gtk_widget_get_allocation (offscreen_box->child1, &child_area);
   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
-    y -= child_area.height;
+    {
+      gtk_widget_get_allocation (offscreen_box->child1, &child_area);
+      y -= child_area.height;
+    }
 
   gtk_widget_get_allocation (offscreen_box->child2, &child_area);
 
@@ -99,9 +105,11 @@ to_parent_2 (GtkOffscreenBox *offscreen_box,
   x += child_area.width / 2;
   y += child_area.height / 2;
 
-  gtk_widget_get_allocation (offscreen_box->child1, &child_area);
   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
-    y += child_area.height;
+    {
+      gtk_widget_get_allocation (offscreen_box->child1, &child_area);
+      y += child_area.height;
+    }
 
   *x_out = x;
   *y_out = y;
@@ -115,7 +123,8 @@ gtk_offscreen_box_class_init (GtkOffscreenBoxClass *klass)
 
   widget_class->realize = gtk_offscreen_box_realize;
   widget_class->unrealize = gtk_offscreen_box_unrealize;
-  widget_class->size_request = gtk_offscreen_box_size_request;
+  widget_class->get_preferred_width = gtk_offscreen_box_get_preferred_width;
+  widget_class->get_preferred_height = gtk_offscreen_box_get_preferred_height;
   widget_class->size_allocate = gtk_offscreen_box_size_allocate;
   widget_class->draw = gtk_offscreen_box_draw;
 
@@ -230,12 +239,20 @@ offscreen_window_from_parent2 (GdkWindow       *window,
              offscreen_x, offscreen_y);
 }
 
+static cairo_surface_t *
+gdk_offscreen_box_create_alpha_image_surface (GdkWindow *offscreen,
+                                              gint       width,
+                                              gint       height)
+{
+  return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+}
+
 static void
 gtk_offscreen_box_realize (GtkWidget *widget)
 {
   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
   GtkAllocation allocation, child_area;
-  GtkStyle *style;
+  GtkStyleContext *context;
   GdkWindow *window;
   GdkWindowAttr attributes;
   gint attributes_mask;
@@ -319,16 +336,19 @@ gtk_offscreen_box_realize (GtkWidget *widget)
     gtk_widget_set_parent_window (offscreen_box->child2, offscreen_box->offscreen_window2);
   gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window2,
                                     window);
+
+  g_signal_connect (offscreen_box->offscreen_window2, "create-surface",
+                    G_CALLBACK (gdk_offscreen_box_create_alpha_image_surface),
+                    offscreen_box);
   g_signal_connect (offscreen_box->offscreen_window2, "to-embedder",
                    G_CALLBACK (offscreen_window_to_parent2), offscreen_box);
   g_signal_connect (offscreen_box->offscreen_window2, "from-embedder",
                    G_CALLBACK (offscreen_window_from_parent2), offscreen_box);
 
-  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, offscreen_box->offscreen_window1, GTK_STATE_NORMAL);
-  gtk_style_set_background (style, offscreen_box->offscreen_window2, GTK_STATE_NORMAL);
+  context = gtk_widget_get_style_context (widget);
+  gtk_style_context_set_background (context, window);
+  gtk_style_context_set_background (context, offscreen_box->offscreen_window1);
+  gtk_style_context_set_background (context, offscreen_box->offscreen_window2);
 
   gdk_window_show (offscreen_box->offscreen_window1);
   gdk_window_show (offscreen_box->offscreen_window2);
@@ -478,7 +498,7 @@ gtk_offscreen_box_size_request (GtkWidget      *widget,
     {
       GtkRequisition child_requisition;
 
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child1),
+      gtk_widget_get_preferred_size ( (offscreen_box->child1),
                                  &child_requisition, NULL);
 
       w = MAX (w, CHILD1_SIZE_SCALE * child_requisition.width);
@@ -489,7 +509,7 @@ gtk_offscreen_box_size_request (GtkWidget      *widget,
     {
       GtkRequisition child_requisition;
 
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child2),
+      gtk_widget_get_preferred_size ( (offscreen_box->child2),
                                  &child_requisition, NULL);
 
       w = MAX (w, CHILD2_SIZE_SCALE * child_requisition.width);
@@ -501,6 +521,30 @@ gtk_offscreen_box_size_request (GtkWidget      *widget,
   requisition->height = border_width * 2 + h;
 }
 
+static void
+gtk_offscreen_box_get_preferred_width (GtkWidget *widget,
+                                       gint      *minimum,
+                                       gint      *natural)
+{
+  GtkRequisition requisition;
+
+  gtk_offscreen_box_size_request (widget, &requisition);
+
+  *minimum = *natural = requisition.width;
+}
+
+static void
+gtk_offscreen_box_get_preferred_height (GtkWidget *widget,
+                                        gint      *minimum,
+                                        gint      *natural)
+{
+  GtkRequisition requisition;
+
+  gtk_offscreen_box_size_request (widget, &requisition);
+
+  *minimum = *natural = requisition.height;
+}
+
 static void
 gtk_offscreen_box_size_allocate (GtkWidget     *widget,
                                 GtkAllocation *allocation)
@@ -529,8 +573,8 @@ gtk_offscreen_box_size_allocate (GtkWidget     *widget,
       GtkRequisition child_requisition;
       GtkAllocation child_allocation;
 
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child1),
-                                 &child_requisition, NULL);
+      gtk_widget_get_preferred_size (offscreen_box->child1,
+                                     &child_requisition, NULL);
       child_allocation.x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2;
       child_allocation.y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2;
       child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
@@ -554,8 +598,8 @@ gtk_offscreen_box_size_allocate (GtkWidget     *widget,
       GtkRequisition child_requisition;
       GtkAllocation child_allocation;
 
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child2),
-                                 &child_requisition, NULL);
+      gtk_widget_get_preferred_size (offscreen_box->child2,
+                                     &child_requisition, NULL);
       child_allocation.x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2;
       child_allocation.y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2;
       child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
@@ -612,6 +656,7 @@ gtk_offscreen_box_draw (GtkWidget *widget,
       if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
         {
           surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2);
+
           gtk_widget_get_allocation (offscreen_box->child2, &child_area);
 
           /* transform */
@@ -626,13 +671,11 @@ gtk_offscreen_box_draw (GtkWidget *widget,
     }
   else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window1))
     {
-      gint w, h;
+      gtk_render_background (gtk_widget_get_style_context (widget), cr,
+                             0, 0,
 
-      gdk_drawable_get_size (offscreen_box->offscreen_window1, &w, &h);
-      gtk_cairo_paint_flat_box (gtk_widget_get_style (widget), cr,
-                          GTK_STATE_NORMAL, GTK_SHADOW_NONE,
-                          widget, "blah",
-                          0, 0, w, h);
+                             gdk_window_get_width (offscreen_box->offscreen_window1),
+                             gdk_window_get_height (offscreen_box->offscreen_window1));
 
       if (offscreen_box->child1)
         gtk_container_propagate_draw (GTK_CONTAINER (widget),
@@ -641,13 +684,10 @@ gtk_offscreen_box_draw (GtkWidget *widget,
     }
   else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window2))
     {
-      gint w, h;
-
-      gdk_drawable_get_size (offscreen_box->offscreen_window2, &w, &h);
-      gtk_cairo_paint_flat_box (gtk_widget_get_style (widget), cr,
-                          GTK_STATE_NORMAL, GTK_SHADOW_NONE,
-                          widget, "blah",
-                          0, 0, w, h);
+      gtk_render_background (gtk_widget_get_style_context (widget), cr,
+                             0, 0,
+                             gdk_window_get_width (offscreen_box->offscreen_window2),
+                             gdk_window_get_height (offscreen_box->offscreen_window2));
 
       if (offscreen_box->child2)
         gtk_container_propagate_draw (GTK_CONTAINER (widget),