[perl-Gtk2] Wrap the offscreen window functions



commit d1ea6bf5cd626fbcd2d48e4c2447af876c9686f4
Author: Quentin Sculo <squentin free fr>
Date:   Wed May 12 00:35:00 2010 +0200

    Wrap the offscreen window functions
    
    Specifically, wrap gdk_offscreen_window_get_pixmap,
    gdk_offscreen_window_set_embedder and gdk_offscreen_window_get_embedder.  And
    provide a custom marshaller for the 'from-embedder' and 'to-embedder' signals.

 t/GdkWindow.t   |   12 ++++++-
 xs/GdkWindow.xs |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 106 insertions(+), 4 deletions(-)
---
diff --git a/t/GdkWindow.t b/t/GdkWindow.t
index 4b58b68..546a816 100644
--- a/t/GdkWindow.t
+++ b/t/GdkWindow.t
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 use strict;
-use Gtk2::TestHelper tests => 43;
+use Gtk2::TestHelper tests => 45;
 
 # $Id$
 
@@ -327,7 +327,7 @@ SKIP: {
 }
 
 SKIP: {
-  skip 'new 2.18 stuff', 3
+  skip 'new 2.18 stuff', 5
     unless Gtk2->CHECK_VERSION(2, 18, 0);
 
   my $window = Gtk2::Gdk::Window -> new(undef, { window_type => 'toplevel' });
@@ -342,6 +342,14 @@ SKIP: {
   my $sibling = Gtk2::Gdk::Window -> new(undef, { window_type => 'toplevel' });
   $window -> restack(undef, TRUE);
   $window -> restack($sibling, TRUE);
+
+  my $gtkwindow= Gtk2::Window->new;
+  $gtkwindow->show_all;
+  $gtkwindow->realize;
+  my $offscreen= Gtk2::Gdk::Window->new(undef, { window_type	=> 'offscreen', });
+  $offscreen->set_embedder($gtkwindow->window);
+  isa_ok($offscreen->get_pixmap,  'Gtk2::Gdk::Pixmap');
+  isa_ok($offscreen->get_embedder,'Gtk2::Gdk::Window');
 }
 
 $window -> hide();
diff --git a/xs/GdkWindow.xs b/xs/GdkWindow.xs
index 8ceea10..22a2ec9 100644
--- a/xs/GdkWindow.xs
+++ b/xs/GdkWindow.xs
@@ -20,6 +20,7 @@
  */
 
 #include "gtk2perl.h"
+#include <gperl_marshal.h>
 
 /* ------------------------------------------------------------------------- */
 
@@ -99,6 +100,60 @@ SvGdkWindowAttrReal (SV *object, GdkWindowAttributesType *mask)
 	return attr;
 }
 
+#if GTK_CHECK_VERSION (2, 18, 0)
+
+static void
+gtk2perl_offscreen_coord_translate_marshal (GClosure * closure,
+                                            GValue * return_value,
+                                            guint n_param_values,
+                                            const GValue * param_values,
+                                            gpointer invocation_hint,
+                                            gpointer marshal_data)
+
+{
+	gdouble * return_x, * return_y;
+	dGPERL_CLOSURE_MARSHAL_ARGS;
+
+	GPERL_CLOSURE_MARSHAL_INIT (closure, marshal_data);
+
+	PERL_UNUSED_VAR (return_value);
+	PERL_UNUSED_VAR (n_param_values);
+	PERL_UNUSED_VAR (invocation_hint);
+
+	ENTER;
+	SAVETMPS;
+
+	PUSHMARK (SP);
+
+	GPERL_CLOSURE_MARSHAL_PUSH_INSTANCE (param_values);
+
+	XPUSHs (sv_2mortal (newSVnv (g_value_get_double (param_values+1))));
+	XPUSHs (sv_2mortal (newSVnv (g_value_get_double (param_values+2))));
+	return_x = g_value_get_pointer (param_values+3);
+	return_y = g_value_get_pointer (param_values+4);
+
+	GPERL_CLOSURE_MARSHAL_PUSH_DATA;
+
+	PUTBACK;
+
+	GPERL_CLOSURE_MARSHAL_CALL (G_ARRAY);
+
+	if (count == 2) {
+		*return_y = POPn;
+		*return_x = POPn;
+	} else {
+		/* NOTE: croaking here can cause bad things to happen to the
+		 * app, because croaking in signal handlers is bad juju. */
+		croak ("callback must return 2 values : x and y");
+	}
+
+	PUTBACK;
+	FREETMPS;
+	LEAVE;
+}
+#endif
+
+
 #if 0 /* not used at the moment */
 static GdkWindowAttr *
 SvGdkWindowAttr (SV *object)
@@ -138,6 +193,20 @@ gtk2perl_gdk_window_invalidate_maybe_recurse_func (GdkWindow *window,
 
 MODULE = Gtk2::Gdk::Window	PACKAGE = Gtk2::Gdk::Window	PREFIX = gdk_window_
 
+
+BOOT:
+	gperl_signal_set_marshaller_for (GDK_TYPE_WINDOW, "from-embedder", gtk2perl_offscreen_coord_translate_marshal);
+	gperl_signal_set_marshaller_for (GDK_TYPE_WINDOW, "to-embedder", gtk2perl_offscreen_coord_translate_marshal);
+
+=for position post_signals
+
+from-embedder, to-embedder and pick-embedded-child signals are for offscreen windows only.
+
+from-embedder and to-embedder receive the x and y coordinates to translate, and must return the translated x and y coordinate.
+
+=cut
+
+
  ## GdkWindow* gdk_window_new (GdkWindow *parent, GdkWindowAttr *attributes, gint attributes_mask)
 =for apidoc
 Create and return a new window.  parent can be undef to mean the root
@@ -956,12 +1025,37 @@ void gdk_window_flush (GdkWindow *window);
 
 gboolean gdk_window_ensure_native (GdkWindow *window);
 
-void gdk_window_geometry_changed (GdkWindow *window);
-
 GdkCursor_ornull * gdk_window_get_cursor (GdkWindow *window);
 
 void gdk_window_restack (GdkWindow *window, GdkWindow_ornull *sibling, gboolean above);
 
+=for apidoc
+Only useful for offscreen C<Gtk2::Gdk::Windows>.
+=cut
+void gdk_window_geometry_changed (GdkWindow *window);
+
+#endif /* 2.18 */
+
+
+#if GTK_CHECK_VERSION (2, 18, 0)
+
+MODULE = Gtk2::Gdk::Window	PACKAGE = Gtk2::Gdk::Window	PREFIX = gdk_offscreen_window_
+
+=for apidoc
+Only for offscreen C<Gtk2::Gdk::Windows>.
+=cut
+GdkPixmap_ornull * gdk_offscreen_window_get_pixmap (GdkWindow *offscreen_window);
+
+=for apidoc
+Only for offscreen C<Gtk2::Gdk::Windows>.
+=cut
+void gdk_offscreen_window_set_embedder (GdkWindow *offscreen_window, GdkWindow *embedder);
+
+=for apidoc
+Only for offscreen C<Gtk2::Gdk::Windows>.
+=cut
+GdkWindow_ornull * gdk_offscreen_window_get_embedder (GdkWindow *offscreen_window);
+
 #endif /* 2.18 */
 
 MODULE = Gtk2::Gdk::Window	PACKAGE = Gtk2::Gdk	PREFIX = gdk_



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