From: Ben Pfaff Date: Sun, 4 Dec 2011 18:44:07 +0000 (-0800) Subject: gui: Fix behavior of print preview in psppire-output-window. X-Git-Tag: v0.7.9~65 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae1e48a9727327898aaf9662f53a9a1ec115ab11;p=pspp-builds.git gui: Fix behavior of print preview in psppire-output-window. Print preview only showed one page because the GtkPrintOperation emits "paginate" again even after it returns TRUE once and our "paginate" implementation was not prepared for that. Also fixes a memory leak in paginate(): the driver used for pagination was not being freed. Reported-by: John Darrington --- diff --git a/src/ui/gui/psppire-output-window.c b/src/ui/gui/psppire-output-window.c index 9d2c73f8..8c8f0768 100644 --- a/src/ui/gui/psppire-output-window.c +++ b/src/ui/gui/psppire-output-window.c @@ -999,7 +999,13 @@ paginate (GtkPrintOperation *operation, GtkPrintContext *context, PsppireOutputWindow *window) { - if ( window->print_item < window->n_items ) + if (window->paginated) + { + /* Sometimes GTK+ emits this signal again even after pagination is + complete. Don't let that screw up printing. */ + return TRUE; + } + else if ( window->print_item < window->n_items ) { xr_driver_output_item (window->print_xrd, window->items[window->print_item++]); while (xr_driver_need_new_page (window->print_xrd)) @@ -1012,8 +1018,13 @@ paginate (GtkPrintOperation *operation, else { gtk_print_operation_set_n_pages (operation, window->print_n_pages); - window->print_item = 0; + + /* Re-create the driver to do the real printing. */ + xr_driver_destroy (window->print_xrd); create_xr_print_driver (context, window); + window->print_item = 0; + window->paginated = TRUE; + return TRUE; } } @@ -1027,6 +1038,7 @@ begin_print (GtkPrintOperation *operation, window->print_item = 0; window->print_n_pages = 1; + window->paginated = FALSE; } static void diff --git a/src/ui/gui/psppire-output-window.h b/src/ui/gui/psppire-output-window.h index 7ceaee7f..54447b1d 100644 --- a/src/ui/gui/psppire-output-window.h +++ b/src/ui/gui/psppire-output-window.h @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008, 2009, 2010 Free Software Foundation + Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -67,6 +67,7 @@ struct _PsppireOutputWindow struct xr_driver *print_xrd; int print_item; int print_n_pages; + gboolean paginated; }; struct _PsppireOutputWindowClass