]> Pileus Git - ~andy/gtk/blobdiff - demos/gtk-demo/offscreen_window2.c
API: Change offscreen windows to use a cairo_surface_t
[~andy/gtk] / demos / gtk-demo / offscreen_window2.c
index 19ca760bda272661d4c4357e0181c7847034b015..fcc32140751290e4dedf9f7b82eeeac31c3098c5 100644 (file)
@@ -104,7 +104,7 @@ gtk_mirror_bin_class_init (GtkMirrorBinClass *klass)
 static void
 gtk_mirror_bin_init (GtkMirrorBin *bin)
 {
-  GTK_WIDGET_UNSET_FLAGS (bin, GTK_NO_WINDOW);
+  gtk_widget_set_has_window (GTK_WIDGET (bin), TRUE);
 }
 
 GtkWidget *
@@ -122,11 +122,11 @@ pick_offscreen_child (GdkWindow     *offscreen_window,
  GtkAllocation child_area;
  double x, y;
 
- if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+ if (bin->child && gtk_widget_get_visible (bin->child))
     {
       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)
@@ -162,19 +162,23 @@ static void
 gtk_mirror_bin_realize (GtkWidget *widget)
 {
   GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
+  GtkAllocation allocation;
+  GtkStyle *style;
+  GdkWindow *window;
   GdkWindowAttr attributes;
   gint attributes_mask;
-  gint border_width;
+  guint border_width;
   GtkRequisition child_requisition;
 
-  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+  gtk_widget_set_realized (widget, TRUE);
 
-  border_width = GTK_CONTAINER (widget)->border_width;
+  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
@@ -191,35 +195,39 @@ gtk_mirror_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;
 
   child_requisition.width = child_requisition.height = 0;
-  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+  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);
 }
 
@@ -269,7 +277,7 @@ gtk_mirror_bin_remove (GtkContainer *container,
   GtkMirrorBin *bin = GTK_MIRROR_BIN (container);
   gboolean was_visible;
 
-  was_visible = GTK_WIDGET_VISIBLE (widget);
+  was_visible = gtk_widget_get_visible (widget);
 
   if (bin->child == widget)
     {
@@ -277,7 +285,7 @@ gtk_mirror_bin_remove (GtkContainer *container,
 
       bin->child = NULL;
 
-      if (was_visible && GTK_WIDGET_VISIBLE (container))
+      if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
         gtk_widget_queue_resize (GTK_WIDGET (container));
     }
 }
@@ -302,15 +310,18 @@ gtk_mirror_bin_size_request (GtkWidget      *widget,
 {
   GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
   GtkRequisition child_requisition;
+  guint border_width;
 
   child_requisition.width = 0;
   child_requisition.height = 0;
 
-  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
-    gtk_widget_size_request (bin->child, &child_requisition);
+  if (bin->child && gtk_widget_get_visible (bin->child))
+    gtk_size_request_get_size (GTK_SIZE_REQUEST (bin->child),
+                               &child_requisition, NULL);
 
-  requisition->width = GTK_CONTAINER (widget)->border_width * 2 + child_requisition.width + 10;
-  requisition->height = GTK_CONTAINER (widget)->border_width * 2 + child_requisition.height * 2 + 10;
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+  requisition->width = border_width * 2 + child_requisition.width + 10;
+  requisition->height = border_width * 2 + child_requisition.height * 2 + 10;
 }
 
 static void
@@ -318,33 +329,35 @@ gtk_mirror_bin_size_allocate (GtkWidget     *widget,
                                GtkAllocation *allocation)
 {
   GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
-  gint border_width;
   gint w, h;
-  widget->allocation = *allocation;
+  guint border_width;
+
+  gtk_widget_set_allocation (widget, allocation);
 
-  border_width = GTK_CONTAINER (widget)->border_width;
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
 
   w = allocation->width - border_width * 2;
   h = allocation->height - border_width * 2;
 
-  if (GTK_WIDGET_REALIZED (widget))
-    gdk_window_move_resize (widget->window,
+  if (gtk_widget_get_realized (widget))
+    gdk_window_move_resize (gtk_widget_get_window (widget),
                             allocation->x + border_width,
                             allocation->y + border_width,
                             w, h);
 
-  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+  if (bin->child && gtk_widget_get_visible (bin->child))
     {
       GtkRequisition child_requisition;
       GtkAllocation child_allocation;
 
-      gtk_widget_get_child_requisition (bin->child, &child_requisition);
+      gtk_size_request_get_size (GTK_SIZE_REQUEST (bin->child),
+                                 &child_requisition, NULL);
       child_allocation.x = 0;
       child_allocation.y = 0;
       child_allocation.height = child_requisition.height;
       child_allocation.width = child_requisition.width;
 
-      if (GTK_WIDGET_REALIZED (widget))
+      if (gtk_widget_get_realized (widget))
         gdk_window_move_resize (bin->offscreen_window,
                                 allocation->x + border_width,
                                 allocation->y + border_width,
@@ -357,7 +370,8 @@ static gboolean
 gtk_mirror_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;
 }
@@ -367,23 +381,25 @@ gtk_mirror_bin_expose (GtkWidget      *widget,
                         GdkEventExpose *event)
 {
   GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
+  GdkWindow *window;
   gint width, height;
 
-  if (GTK_WIDGET_DRAWABLE (widget))
+  if (gtk_widget_is_drawable (widget))
     {
-      if (event->window == widget->window)
+      window = gtk_widget_get_window (widget);
+      if (event->window == window)
         {
-          GdkPixmap *pixmap;
+          cairo_surface_t *surface;
           cairo_t *cr;
           cairo_matrix_t matrix;
           cairo_pattern_t *mask;
 
-          if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+          if (bin->child && gtk_widget_get_visible (bin->child))
             {
-              pixmap = gdk_offscreen_window_get_pixmap (bin->offscreen_window);
-              gdk_drawable_get_size (pixmap, &width, &height);
+              surface = gdk_offscreen_window_get_surface (bin->offscreen_window);
+              gdk_drawable_get_size (bin->offscreen_window, &width, &height);
 
-              cr = gdk_cairo_create (widget->window);
+              cr = gdk_cairo_create (window);
 
               cairo_save (cr);
 
@@ -391,7 +407,7 @@ gtk_mirror_bin_expose (GtkWidget      *widget,
               cairo_clip (cr);
 
               /* paint the offscreen child */
-              gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+              cairo_set_source_surface (cr, surface, 0, 0);
               cairo_paint (cr);
 
               cairo_restore (cr);
@@ -404,7 +420,7 @@ gtk_mirror_bin_expose (GtkWidget      *widget,
               cairo_rectangle (cr, 0, height, width, height);
               cairo_clip (cr);
 
-              gdk_cairo_set_source_pixmap (cr, pixmap, 0, height);
+              cairo_set_source_surface (cr, surface, 0, height);
 
               /* create linear gradient as mask-pattern to fade out the source */
               mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height);
@@ -423,7 +439,7 @@ gtk_mirror_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);
@@ -487,7 +503,7 @@ do_offscreen_window2 (GtkWidget *do_widget)
       gtk_box_pack_start (GTK_BOX (hbox), applybutton, FALSE, FALSE, 0);
     }
 
-  if (!GTK_WIDGET_VISIBLE (window))
+  if (!gtk_widget_get_visible (window))
     gtk_widget_show_all (window);
   else
     {