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

Patch GtkPrintOperation 2.16



Hi,

Here's the patch for upgrading GtkPintOperation to Gtk 2.16.

The two new methods are really tricky as set_defer_drawing() has to be called from the signal callback 'draw-page' and draw_page_finish() will cause segmentation fault if set_defer_drawing() isn't called previously.

I've documented this in the XS through POD.

Emmanuel
Index: xs/GtkPrintOperation.xs
===================================================================
--- xs/GtkPrintOperation.xs	(revision 2111)
+++ xs/GtkPrintOperation.xs	(working copy)
@@ -94,6 +94,33 @@
 
 void gtk_print_operation_cancel (GtkPrintOperation *op);
 
+#if GTK_CHECK_VERSION (2, 15, 0)
+
+=for apidoc
+
+=for signature $op->draw_page_finish ()
+
+The method draw_page_finish() can only be called if the method
+set_defer_drawing() has been called previously otherwise a segmentation fault
+will occur. This means that the application will crash and even an eval will not
+be able to recover from that error.
+
+=cut
+void gtk_print_operation_draw_page_finish (GtkPrintOperation *op);
+
+
+=for apidoc
+
+=for signature $op->set_defer_drawing ()
+
+The method set_defer_drawing() can only be called from the callback
+C<'draw-page'>.
+
+=cut
+void gtk_print_operation_set_defer_drawing (GtkPrintOperation *op);
+
+#endif /* 2.16 */
+
 MODULE = Gtk2::PrintOperation	PACKAGE = Gtk2::Print	PREFIX = gtk_print_
 
 # GtkPageSetup * gtk_print_run_page_setup_dialog (GtkWindow *parent, GtkPageSetup *page_setup, GtkPrintSettings *settings);
Index: t/GtkPrintOperation.t
===================================================================
--- t/GtkPrintOperation.t	(revision 2111)
+++ t/GtkPrintOperation.t	(working copy)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 use strict;
 use Gtk2::TestHelper
-  tests => 10,
+  tests => 13,
   at_least_version => [2, 10, 0, "GtkPrintOperation is new in 2.10"];
 
 # $Id$
@@ -51,8 +51,40 @@
 # FIXME: Don't know how to trigger an actual error.
 # warn $op -> get_error();
 
+
+SKIP: {
+  skip 'draw page finish (2.16)', 3
+    unless Gtk2->CHECK_VERSION(2, 15, 0);
+
+	# NOTE draw_page_finish() has to be called under the right conditions
+	#      otherwise the print context doesn't seem to be setup properly causing
+	#      the program to crash with a segmentation fault.
+	#
+	#      This is tricky as draw_page_finish() must be called if
+	#      set_defer_drawing() is called and the latter can be called only from
+	#      the 'draw-page' callback.
+	
+
+  # 'draw-page' is called twice because there are 2 pages see (get_op)
+	$op = get_op();
+	$op -> signal_connect('draw-page' => sub {
+		# Pretend that the drawing is asynchronous.
+		$op -> set_defer_drawing();
+
+		# Finish the drawing latter
+		Glib::Idle->add(sub {
+			ok(TRUE, "Draw page finish called"); # Called 2 times
+			$op -> draw_page_finish();
+		});
+	});
+	
+	ok(defined $op -> run("export", Gtk2::Window -> new()));
+}
+
+
 unlink "test.pdf";
 
+
 =comment
 
 # Can't non-interactively test these, I think.  I manually verified that they


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