diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 15 | ||||
-rw-r--r-- | gtk/gtk.symbols | 3 | ||||
-rw-r--r-- | gtk/gtkprintoperation-private.h | 12 | ||||
-rw-r--r-- | gtk/gtkprintoperation-unix.c | 292 | ||||
-rw-r--r-- | gtk/gtkprintoperation-win32.c | 28 | ||||
-rw-r--r-- | gtk/gtkprintoperation.c | 167 |
7 files changed, 407 insertions, 125 deletions
@@ -15,6 +15,21 @@ 2006-04-24 Matthias Clasen <mclasen@redhat.com> + * gtk/gtk.symbols: + * gtk/gtkprintoperation.c (gtk_print_operation_run_async): Refactor the + gtk_print_operation_run() code and add an _async version. + + * gtk/gtkprintoperation-private.h: + * gtk/gtkprintoperation-unix.c + (_gtk_print_operation_platform_backend_run_dialog_async) + (gtk_print_run_page_setup_dialog_async): Variants of the run functions + which don't call gtk_dialog_run(), but only show the dialog and return, + and handle the response in a signal handler. + + * gtk/gtkprintoperation-win32.c (gtk_print_run_page_setup_dialog_async) + (_gtk_print_operation_platform_backend_run_dialog_async): Implement these + by calling the sync versions. + * gtk/gtkprintoperation-unix.c: Cleanups. * gtk/gtkpagesetupunixdialog.c (gtk_page_setup_unix_dialog_get_page_setup): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 417c549d24..6c423b2c72 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -15,6 +15,21 @@ 2006-04-24 Matthias Clasen <mclasen@redhat.com> + * gtk/gtk.symbols: + * gtk/gtkprintoperation.c (gtk_print_operation_run_async): Refactor the + gtk_print_operation_run() code and add an _async version. + + * gtk/gtkprintoperation-private.h: + * gtk/gtkprintoperation-unix.c + (_gtk_print_operation_platform_backend_run_dialog_async) + (gtk_print_run_page_setup_dialog_async): Variants of the run functions + which don't call gtk_dialog_run(), but only show the dialog and return, + and handle the response in a signal handler. + + * gtk/gtkprintoperation-win32.c (gtk_print_run_page_setup_dialog_async) + (_gtk_print_operation_platform_backend_run_dialog_async): Implement these + by calling the sync versions. + * gtk/gtkprintoperation-unix.c: Cleanups. * gtk/gtkpagesetupunixdialog.c (gtk_page_setup_unix_dialog_get_page_setup): diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index bdeff31b59..4a2614bc02 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2643,6 +2643,7 @@ gtk_print_operation_set_unit gtk_print_operation_set_show_dialog gtk_print_operation_set_pdf_target gtk_print_operation_run +gtk_print_operation_run_async gtk_print_operation_get_status gtk_print_operation_get_status_string gtk_print_operation_is_finished @@ -2653,6 +2654,7 @@ gtk_print_operation_is_finished #if IN_FILE(__GTK_PRINT_OPERATION_UNIX_C__) #ifdef G_OS_UNIX gtk_print_run_page_setup_dialog +gtk_print_run_page_setup_dialog_async #endif #endif #endif @@ -2661,6 +2663,7 @@ gtk_print_run_page_setup_dialog #if IN_FILE(__GTK_PRINT_OPERATION_WIN32_C__) #ifdef G_OS_WIN32 gtk_print_run_page_setup_dialog +gtk_print_run_page_setup_dialog_async #endif #endif #endif diff --git a/gtk/gtkprintoperation-private.h b/gtk/gtkprintoperation-private.h index 5109e9cce5..cf38582dcc 100644 --- a/gtk/gtkprintoperation-private.h +++ b/gtk/gtkprintoperation-private.h @@ -66,9 +66,15 @@ struct _GtkPrintOperationPrivate }; GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *operation, - GtkWindow *parent, - gboolean *do_print, - GError **error); + GtkWindow *parent, + gboolean *do_print, + GError **error); + +typedef void (* GtkPrintOperationPrintFunc) (GtkPrintOperation *op); + +void _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op, + GtkWindow *parent, + GtkPrintOperationPrintFunc print_cb); void _gtk_print_operation_set_status (GtkPrintOperation *op, GtkPrintStatus status, diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c index 1ebc4bb0b6..469e81cc74 100644 --- a/gtk/gtkprintoperation-unix.c +++ b/gtk/gtkprintoperation-unix.c @@ -120,47 +120,76 @@ job_status_changed_cb (GtkPrintJob *job, _gtk_print_operation_set_status (op, gtk_print_job_get_status (job), NULL); } -GtkPrintOperationResult -_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op, - GtkWindow *parent, - gboolean *do_print, - GError **error) + +static GtkWidget * +get_print_dialog (GtkPrintOperation *op, + GtkWindow *parent) { GtkWidget *pd; - GtkPrintOperationResult result; GtkPageSetup *page_setup; - - result = GTK_PRINT_OPERATION_RESULT_CANCEL; - - if (op->priv->default_page_setup) - page_setup = gtk_page_setup_copy (op->priv->default_page_setup); - else - page_setup = gtk_page_setup_new (); pd = gtk_print_unix_dialog_new (NULL, parent); if (op->priv->print_settings) gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd), op->priv->print_settings); + if (op->priv->default_page_setup) + page_setup = gtk_page_setup_copy (op->priv->default_page_setup); + else + page_setup = gtk_page_setup_new (); + + gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd), + page_setup); + g_object_unref (page_setup); - gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd), page_setup); + return pd; +} - *do_print = FALSE; - if (gtk_dialog_run (GTK_DIALOG (pd)) == GTK_RESPONSE_OK) +typedef struct { + GtkPrintOperation *op; + gboolean do_print; + GError **error; + GtkPrintOperationResult result; + GtkPrintOperationPrintFunc print_cb; + GDestroyNotify destroy; +} PrintResponseData; + +static void +print_response_data_free (gpointer data) +{ + PrintResponseData *rdata = data; + + g_object_unref (rdata->op); + g_free (rdata); +} + +static void +handle_print_response (GtkWidget *dialog, + gint response, + gpointer data) +{ + GtkPrintUnixDialog *pd = GTK_PRINT_UNIX_DIALOG (dialog); + PrintResponseData *rdata = data; + GtkPrintOperation *op = rdata->op; + + if (response == GTK_RESPONSE_OK) { GtkPrintOperationUnix *op_unix; GtkPrinter *printer; GtkPrintSettings *settings; + GtkPageSetup *page_setup; + + rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY; - result = GTK_PRINT_OPERATION_RESULT_APPLY; - printer = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (pd)); if (printer == NULL) goto out; - *do_print = TRUE; + rdata->do_print = TRUE; settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (pd)); + page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (pd)); + gtk_print_operation_set_print_settings (op, settings); op_unix = g_new0 (GtkPrintOperationUnix, 1); @@ -169,13 +198,13 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op, settings, page_setup); g_object_unref (settings); - - op->priv->surface = gtk_print_job_get_surface (op_unix->job, error); + + rdata->op->priv->surface = gtk_print_job_get_surface (op_unix->job, rdata->error); if (op->priv->surface == NULL) { - *do_print = FALSE; + rdata->do_print = FALSE; op_unix_free (op_unix); - result = GTK_PRINT_OPERATION_RESULT_ERROR; + rdata->result = GTK_PRINT_OPERATION_RESULT_ERROR; goto out; } @@ -184,7 +213,7 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op, g_signal_connect (op_unix->job, "status_changed", G_CALLBACK (job_status_changed_cb), op); - op_unix->parent = parent; + op_unix->parent = gtk_window_get_transient_for (GTK_WINDOW (pd)); op->priv->dpi_x = 72; op->priv->dpi_y = 72; @@ -208,12 +237,126 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op, op->priv->end_page = unix_end_page; op->priv->end_run = unix_end_run; - out: - g_object_unref (page_setup); + out: + gtk_widget_destroy (GTK_WIDGET (pd)); + + if (rdata->print_cb) + { + if (rdata->do_print) + rdata->print_cb (op); + else + _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL); + } + + if (rdata->destroy) + rdata->destroy (rdata); +} + +void +_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op, + GtkWindow *parent, + GtkPrintOperationPrintFunc print_cb) +{ + GtkWidget *pd; + PrintResponseData *rdata; + + rdata = g_new (PrintResponseData, 1); + rdata->op = g_object_ref (op); + rdata->do_print = FALSE; + rdata->result = GTK_PRINT_OPERATION_RESULT_CANCEL; + rdata->error = NULL; + rdata->print_cb = print_cb; + rdata->destroy = print_response_data_free; - gtk_widget_destroy (pd); + pd = get_print_dialog (op, parent); + gtk_window_set_modal (GTK_WINDOW (pd), TRUE); + + g_signal_connect (pd, "response", + G_CALLBACK (handle_print_response), rdata); + + gtk_window_present (GTK_WINDOW (pd)); +} + +GtkPrintOperationResult +_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op, + GtkWindow *parent, + gboolean *do_print, + GError **error) + { + GtkWidget *pd; + PrintResponseData rdata; + gint response; + + rdata.op = op; + rdata.do_print = FALSE; + rdata.result = GTK_PRINT_OPERATION_RESULT_CANCEL; + rdata.error = error; + rdata.print_cb = NULL; + rdata.destroy = NULL; + + pd = get_print_dialog (op, parent); + + response = gtk_dialog_run (GTK_DIALOG (pd)); + handle_print_response (pd, response, &rdata); + + *do_print = rdata.do_print; + + return rdata.result; +} + + +typedef struct { + GtkPageSetup *page_setup; + GFunc done_cb; + gpointer data; + GDestroyNotify destroy; +} PageSetupResponseData; + +static void +page_setup_data_free (gpointer data) +{ + PageSetupResponseData *rdata = data; + + g_object_unref (rdata->page_setup); + g_free (rdata); +} + +static void +handle_page_setup_response (GtkWidget *dialog, + gint response, + gpointer data) +{ + GtkPageSetupUnixDialog *psd; + PageSetupResponseData *rdata = data; - return result; + psd = GTK_PAGE_SETUP_UNIX_DIALOG (dialog); + if (response == GTK_RESPONSE_OK) + rdata->page_setup = gtk_page_setup_unix_dialog_get_page_setup (psd); + + gtk_widget_destroy (dialog); + + if (rdata->done_cb) + rdata->done_cb (rdata->page_setup, rdata->data); + + if (rdata->destroy) + rdata->destroy (rdata); +} + +static GtkWidget * +get_page_setup_dialog (GtkWindow *parent, + GtkPageSetup *page_setup, + GtkPrintSettings *settings) +{ + GtkWidget *dialog; + + dialog = gtk_page_setup_unix_dialog_new (NULL, parent); + if (page_setup) + gtk_page_setup_unix_dialog_set_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog), + page_setup); + gtk_page_setup_unix_dialog_set_print_settings (GTK_PAGE_SETUP_UNIX_DIALOG (dialog), + settings); + + return dialog; } /** @@ -222,11 +365,14 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op, * @page_setup: an existing #GtkPageSetup, or %NULL * @settings: a #GtkPrintSettings * - * Runs a page setup dialog, letting the user modify - * the values from @page_setup. If the user cancels - * the dialog, the returned #GtkPageSetup is identical - * to the passed in @page_setup, otherwise it contains - * the modifications done in the dialog. + * Runs a page setup dialog, letting the user modify the values from + * @page_setup. If the user cancels the dialog, the returned #GtkPageSetup + * is identical to the passed in @page_setup, otherwise it contains the + * modifications done in the dialog. + * + * Note that this function may use a recursive mainloop to show the page + * setup dialog. See gtk_print_run_page_setup_dialog_async() if this is + * a problem. * * Return value: a new #GtkPageSetup * @@ -238,29 +384,69 @@ gtk_print_run_page_setup_dialog (GtkWindow *parent, GtkPrintSettings *settings) { GtkWidget *dialog; - GtkPageSetup *new_page_setup; + gint response; + PageSetupResponseData rdata; - dialog = gtk_page_setup_unix_dialog_new (NULL, parent); - if (page_setup) - gtk_page_setup_unix_dialog_set_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog), - page_setup); - gtk_page_setup_unix_dialog_set_print_settings (GTK_PAGE_SETUP_UNIX_DIALOG (dialog), - settings); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) - new_page_setup = gtk_page_setup_unix_dialog_get_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog)); - else - { - if (page_setup) - new_page_setup = gtk_page_setup_copy (page_setup); - else - new_page_setup = gtk_page_setup_new (); - } - - gtk_widget_destroy (dialog); - - return new_page_setup; + rdata.page_setup = NULL; + rdata.done_cb = NULL; + rdata.data = NULL; + rdata.destroy = NULL; + + dialog = get_page_setup_dialog (parent, page_setup, settings); + response = gtk_dialog_run (GTK_DIALOG (dialog)); + handle_page_setup_response (dialog, response, &rdata); + + if (rdata.page_setup) + return rdata.page_setup; + else if (page_setup) + return gtk_page_setup_copy (page_setup); + else + return gtk_page_setup_new (); } +/** + * gtk_print_run_page_setup_dialog_async: + * @parent: transient parent, or %NULL + * @page_setup: an existing #GtkPageSetup, or %NULL + * @settings: a #GtkPrintSettings + * @done_cb: a function to call when the user saves the modified page setup + * @data: user data to pass to @done_cb + * + * Runs a page setup dialog, letting the user modify the values from + * @page_setup. + * + * In contrast to gtk_print_run_page_setup_dialog(), this function + * returns after showing the page setup dialog on platforms that support + * this, and calls @done_cb from a signal handler for the ::response + * signal of the dialog. + * + * Since: 2.10 + */ +void +gtk_print_run_page_setup_dialog_async (GtkWindow *parent, + GtkPageSetup *page_setup, + GtkPrintSettings *settings, + GtkPageSetupDoneFunc done_cb, + gpointer data) +{ + GtkWidget *dialog; + PageSetupResponseData *rdata; + + dialog = get_page_setup_dialog (parent, page_setup, settings); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + rdata = g_new (PageSetupResponseData, 1); + rdata->page_setup = NULL; + rdata->done_cb = done_cb; + rdata->data = data; + rdata->destroy = page_setup_data_free; + + g_signal_connect (dialog, "response", + G_CALLBACK (handle_page_setup_response), rdata); + + gtk_window_present (GTK_WINDOW (dialog)); + } + #define __GTK_PRINT_OPERATION_UNIX_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkprintoperation-win32.c b/gtk/gtkprintoperation-win32.c index 7f441abc71..079ae1f229 100644 --- a/gtk/gtkprintoperation-win32.c +++ b/gtk/gtkprintoperation-win32.c @@ -1465,6 +1465,20 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op, return result; } +void +_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op, + GtkWindow *parent, + GtkPrintOperationPrintFunc print_cb) +{ + gboolean do_print; + + _gtk_print_operation_platform_backend_run_dialog (op, parent, &do_print, NULL); + if (do_print) + print_cb (op); + else + _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL); +} + GtkPageSetup * gtk_print_run_page_setup_dialog (GtkWindow *parent, GtkPageSetup *page_setup, @@ -1596,3 +1610,17 @@ gtk_print_run_page_setup_dialog (GtkWindow *parent, return page_setup; } + +void +gtk_print_run_page_setup_dialog_async (GtkWindow *parent, + GtkPageSetup *page_setup, + GtkPrintSettings *settings, + GtkPageSetupDoneFunc done_cb, + gpointer data) +{ + GtkPageSetup *page_setup; + + page_setup = gtk_print_run_page_setup_dialog (parent, page_setup, settings); + done_cb (page_setup, data); + g_object_unref (page_setup); +} diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c index 07f2e9203d..c93923ae3e 100644 --- a/gtk/gtkprintoperation.c +++ b/gtk/gtkprintoperation.c @@ -950,84 +950,19 @@ run_pdf (GtkPrintOperation *op, return GTK_PRINT_OPERATION_RESULT_APPLY; } -static GtkPrintOperationResult -run_print_dialog (GtkPrintOperation *op, - GtkWindow *parent, - gboolean *do_print, - GError **error) -{ - if (op->priv->pdf_target != NULL) - return run_pdf (op, parent, do_print, error); - - /* This does: - * Open print dialog - * set print settings on dialog - * run dialog, if show_dialog set - * extract print settings from dialog - * create cairo surface and data for print job - * return correct result val - */ - return _gtk_print_operation_platform_backend_run_dialog (op, - parent, - do_print, - error); -} - -/** - * gtk_print_operation_run: - * @op: a #GtkPrintOperation - * @parent: Transient parent of the dialog, or %NULL - * @error: Return location for errors, or %NULL - * - * Runs the print operation, by first letting the user modify - * print settings in the print dialog, and then print the - * document. - * - * Note that this function does not return until the rendering - * of all pages is complete. You can connect to the ::status-changed - * signal on @op to obtain some information about the progress - * of the print operation. - * - * <informalexample><programlisting> - * FIXME: need an example here - * </programlisting></informalexample> - * - * Return value: the result of the print operation. A return value - * of %GTK_PRINT_OPERATION_RESULT_APPLY indicates that the printing - * was completed successfully. In this case, it is a good idea - * to obtain the used print settings with - * gtk_print_operation_get_print_settings() and store them for - * reuse with the next print operation. - * - * Since: 2.10 - **/ -GtkPrintOperationResult -gtk_print_operation_run (GtkPrintOperation *op, - GtkWindow *parent, - GError **error) +static void +print_pages (GtkPrintOperation *op) { int page, range; GtkPageSetup *initial_page_setup, *page_setup; GtkPrintContext *print_context; cairo_t *cr; - gboolean do_print; int uncollated_copies, collated_copies; int i, j; GtkPageRange *ranges; GtkPageRange one_range; int num_ranges; - GtkPrintOperationResult result; - - g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), - GTK_PRINT_OPERATION_RESULT_ERROR); - result = run_print_dialog (op, parent, &do_print, error); - if (!do_print) - { - _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL); - return result; - } - if (op->priv->manual_collation) { uncollated_copies = op->priv->manual_num_copies; @@ -1047,7 +982,7 @@ gtk_print_operation_run (GtkPrintOperation *op, _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_PREPARING, NULL); g_signal_emit (op, signals[BEGIN_PRINT], 0, print_context); - g_return_val_if_fail (op->priv->nr_of_pages > 0, GTK_PRINT_OPERATION_RESULT_ERROR); + g_return_if_fail (op->priv->nr_of_pages > 0); if (op->priv->print_pages == GTK_PRINT_PAGES_RANGES) { @@ -1145,7 +1080,101 @@ gtk_print_operation_run (GtkPrintOperation *op, cairo_surface_finish (op->priv->surface); op->priv->end_run (op); - return GTK_PRINT_OPERATION_RESULT_APPLY; +} + +/** + * gtk_print_operation_run: + * @op: a #GtkPrintOperation + * @parent: Transient parent of the dialog, or %NULL + * @error: Return location for errors, or %NULL + * + * Runs the print operation, by first letting the user modify + * print settings in the print dialog, and then print the + * document. + * + * Note that this function does not return until the rendering of all + * pages is complete. You can connect to the ::status-changed signal on + * @op to obtain some information about the progress of the print operation. + * Furthermore, it may use a recursive mainloop to show the print dialog. + * See gtk_print_operation_run_async() if this is a problem. + * + * <informalexample><programlisting> + * FIXME: need an example here + * </programlisting></informalexample> + * + * Return value: the result of the print operation. A return value of + * %GTK_PRINT_OPERATION_RESULT_APPLY indicates that the printing was + * completed successfully. In this case, it is a good idea to obtain + * the used print settings with gtk_print_operation_get_print_settings() + * and store them for reuse with the next print operation. + * + * Since: 2.10 + **/ +GtkPrintOperationResult +gtk_print_operation_run (GtkPrintOperation *op, + GtkWindow *parent, + GError **error) +{ + GtkPrintOperationResult result; + gboolean do_print; + + g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), + GTK_PRINT_OPERATION_RESULT_ERROR); + + if (op->priv->pdf_target != NULL) + result = run_pdf (op, parent, &do_print, error); + else + result = _gtk_print_operation_platform_backend_run_dialog (op, + parent, + &do_print, + error); + if (do_print) + print_pages (op); + else + _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL); + + return result; +} + +/** + * gtk_print_operation_run_async: + * @op: a #GtkPrintOperation + * @parent: Transient parent of the dialog, or %NULL + * + * Runs the print operation, by first letting the user modify + * print settings in the print dialog, and then print the + * document. + * + * In contrast to gtk_print_operation_run(), this function returns after + * showing the print dialog on platforms that support this, and handles + * the printing by connecting a signal handler to the ::response signal + * of the dialog. + * + * If you use this function, it is recommended that you store the modified + * #GtkPrintSettings in a ::begin-print or ::end-print signal handler. + * + * Since: 2.10 + **/ +void +gtk_print_operation_run_async (GtkPrintOperation *op, + GtkWindow *parent) +{ + gboolean do_print; + + g_return_if_fail (GTK_IS_PRINT_OPERATION (op)); + + if (op->priv->pdf_target != NULL) + { + run_pdf (op, parent, &do_print, NULL); + if (do_print) + print_pages (op); + else + _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL); + } + else + _gtk_print_operation_platform_backend_run_dialog_async (op, + parent, + print_pages); } |