Commit 2e9cc2f6 authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Refactor the gtk_print_operation_run() code and add an _async version.

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.
parent 7261cff2
......@@ -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):
......
......@@ -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):
......
......@@ -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
......
......@@ -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,
......
This diff is collapsed.
......@@ -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);
}
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment