]> Pileus Git - ~andy/gtk/commitdiff
Add gtk_offscreen_window_get_pixmap() and gtk_offscreen_window_get_pixbuf(), some...
authorCody Russell <crussell@canonical.com>
Fri, 18 Dec 2009 19:08:45 +0000 (20:08 +0100)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Sun, 4 Apr 2010 00:53:45 +0000 (20:53 -0400)
gtk/gtkoffscreenwindow.c
gtk/gtkoffscreenwindow.h
tests/testoffscreenwindow.c

index 22f32b25299c7c91ad01da7a76627e459bf3c60a..953a2012fe24972d9ad537afd0b0b4b39b407e21 100644 (file)
@@ -210,12 +210,72 @@ gtk_offscreen_window_init (GtkOffscreenWindow *window)
 {
 }
 
+/**
+ * gtk_offscreen_window_new:
+ *
+ * Creates a toplevel container widget that is used to retrieve
+ * snapshots of widgets without showing them on the screen.  For
+ * widgets that are on the screen and part of a normal widget
+ * hierarchy, gtk_widget_get_snapshot() can be used instead.
+ *
+ * Return value: A pointer to a #GtkWidget
+ **/
 GtkWidget *
 gtk_offscreen_window_new (void)
 {
   return g_object_new (gtk_offscreen_window_get_type (), NULL);
 }
 
+/**
+ * gtk_offscreen_window_get_pixmap:
+ *
+ * Retrieves a snapshot of the contained widget in the form of
+ * a #GdkPixmap.  If you need to keep this around over window
+ * resizes then you should add a reference to it.
+ *
+ * Returns: A #GdkPixmap pointer to the offscreen pixmap, or %NULL.
+ **/
+GdkPixmap *
+gtk_offscreen_window_get_pixmap (GtkOffscreenWindow *offscreen)
+{
+  g_return_val_if_fail (GTK_IS_OFFSCREEN_WINDOW (offscreen), NULL);
+
+  return gdk_offscreen_window_get_pixmap (GTK_WIDGET (offscreen)->window);
+}
+
+/**
+ * gtk_offscreen_window_get_pixbuf:
+ *
+ * Retrieves a snapshot of the contained widget in the form of
+ * a #GdkPixbuf.  This is a new pixbuf with a reference count of 1,
+ * and the application should unreference it once it is no longer
+ * needed.
+ *
+ * Returns: A #GdkPixbuf pointer, or %NULL.
+ **/
+GdkPixbuf *
+gtk_offscreen_window_get_pixbuf (GtkOffscreenWindow *offscreen)
+{
+  GdkPixmap *pixmap = NULL;
+  GdkPixbuf *pixbuf = NULL;
+
+  g_return_val_if_fail (GTK_IS_OFFSCREEN_WINDOW (offscreen), NULL);
+
+  pixmap = gdk_offscreen_window_get_pixmap (GTK_WIDGET (offscreen)->window);
+
+  if (pixmap != NULL)
+    {
+      gint width, height;
+
+      gdk_drawable_get_size (pixmap, &width, &height);
+
+      pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL,
+                                             0, 0, 0, 0,
+                                             width, height);
+    }
+
+  return pixbuf;
+}
 
 #define __GTK_OFFSCREEN_WINDOW_C__
 #include "gtkaliasdef.c"
index 75486f683fd625fb519488ba0bedb07a37a8c428..518b8df2619ed12f4358269caa044c9ea00ddf26 100644 (file)
@@ -52,6 +52,8 @@ struct _GtkOffscreenWindowClass
 GType      gtk_offscreen_window_get_type () G_GNUC_CONST;
 
 GtkWidget *gtk_offscreen_window_new ();
+GdkPixmap *gtk_offscreen_window_get_pixmap (GtkOffscreenWindow *offscreen);
+GdkPixbuf *gtk_offscreen_window_get_pixbuf (GtkOffscreenWindow *offscreen);
 
 G_END_DECLS
 
index 161c9c511f73745ccd14335c13dbcaa5c3d5d907..7358188fc05a289d468a5214d77c4ad05ff6bd43 100644 (file)
@@ -11,7 +11,7 @@ da_expose (GtkWidget *widget,
 
   if (GTK_WIDGET_DRAWABLE (widget))
     {
-      pixmap = gdk_offscreen_window_get_pixmap (GTK_WIDGET (offscreen)->window);
+      pixmap = gtk_offscreen_window_get_pixmap (offscreen);
 
       cr = gdk_cairo_create (widget->window);
       gdk_cairo_set_source_pixmap (cr, pixmap, 50, 50);