mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-24 12:41:16 +00:00
Clean up APIs: Make async a setting instead of separate calls. Combine
2006-06-07 Alexander Larsson <alexl@redhat.com> * gtk/gtk.symbols: * gtk/gtkprintoperation-private.h: * gtk/gtkprintoperation-unix.c: * gtk/gtkprintoperation.[ch]: Clean up APIs: Make async a setting instead of separate calls. Combine settings like show_dialog, show_preview and pdf_target into an action enum that you pass to gtk_print_dialog_run(). * tests/print-editor.c: * tests/testnouiprint.c: * tests/testprint.c: * demos/gtk-demo/printing.c: Update to new APIs
This commit is contained in:
parent
36f7ed300a
commit
9bea38595f
17
ChangeLog
17
ChangeLog
@ -1,3 +1,20 @@
|
||||
2006-06-07 Alexander Larsson <alexl@redhat.com>
|
||||
|
||||
* gtk/gtk.symbols:
|
||||
* gtk/gtkprintoperation-private.h:
|
||||
* gtk/gtkprintoperation-unix.c:
|
||||
* gtk/gtkprintoperation.[ch]:
|
||||
Clean up APIs:
|
||||
Make async a setting instead of separate calls.
|
||||
Combine settings like show_dialog, show_preview and pdf_target into
|
||||
an action enum that you pass to gtk_print_dialog_run().
|
||||
|
||||
* tests/print-editor.c:
|
||||
* tests/testnouiprint.c:
|
||||
* tests/testprint.c:
|
||||
* demos/gtk-demo/printing.c:
|
||||
Update to new APIs
|
||||
|
||||
2006-06-07 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* configure.in: Update the ATK requirements (#344148)
|
||||
|
@ -1,3 +1,20 @@
|
||||
2006-06-07 Alexander Larsson <alexl@redhat.com>
|
||||
|
||||
* gtk/gtk.symbols:
|
||||
* gtk/gtkprintoperation-private.h:
|
||||
* gtk/gtkprintoperation-unix.c:
|
||||
* gtk/gtkprintoperation.[ch]:
|
||||
Clean up APIs:
|
||||
Make async a setting instead of separate calls.
|
||||
Combine settings like show_dialog, show_preview and pdf_target into
|
||||
an action enum that you pass to gtk_print_dialog_run().
|
||||
|
||||
* tests/print-editor.c:
|
||||
* tests/testnouiprint.c:
|
||||
* tests/testprint.c:
|
||||
* demos/gtk-demo/printing.c:
|
||||
Update to new APIs
|
||||
|
||||
2006-06-07 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* configure.in: Update the ATK requirements (#344148)
|
||||
|
@ -156,7 +156,7 @@ do_printing (GtkWidget *do_widget)
|
||||
g_signal_connect (G_OBJECT (operation), "end-print",
|
||||
G_CALLBACK (end_print), data);
|
||||
|
||||
gtk_print_operation_run (operation, GTK_WINDOW (do_widget), &error);
|
||||
gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (do_widget), &error);
|
||||
|
||||
g_object_unref (operation);
|
||||
|
||||
|
@ -2697,14 +2697,12 @@ gtk_print_operation_set_n_pages
|
||||
gtk_print_operation_set_current_page
|
||||
gtk_print_operation_set_use_full_page
|
||||
gtk_print_operation_set_unit
|
||||
gtk_print_operation_set_show_dialog
|
||||
gtk_print_operation_set_pdf_target
|
||||
gtk_print_operation_set_track_print_status
|
||||
gtk_print_operation_set_show_progress
|
||||
gtk_print_operation_set_show_preview
|
||||
gtk_print_operation_set_custom_tab_label
|
||||
gtk_print_operation_get_error
|
||||
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
|
||||
|
@ -27,7 +27,9 @@ G_BEGIN_DECLS
|
||||
|
||||
struct _GtkPrintOperationPrivate
|
||||
{
|
||||
GtkPrintOperationAction action;
|
||||
GtkPrintStatus status;
|
||||
GError *error;
|
||||
gchar *status_string;
|
||||
GtkPageSetup *default_page_setup;
|
||||
GtkPrintSettings *print_settings;
|
||||
@ -37,11 +39,10 @@ struct _GtkPrintOperationPrivate
|
||||
GtkUnit unit;
|
||||
gchar *pdf_target;
|
||||
guint use_full_page : 1;
|
||||
guint show_dialog : 1;
|
||||
guint show_preview : 1;
|
||||
guint track_print_status : 1;
|
||||
guint show_progress : 1;
|
||||
guint cancelled : 1;
|
||||
guint allow_async : 1;
|
||||
guint is_sync : 1;
|
||||
|
||||
guint print_pages_idle_id;
|
||||
@ -84,13 +85,15 @@ struct _GtkPrintOperationPrivate
|
||||
|
||||
typedef void (* GtkPrintOperationPrintFunc) (GtkPrintOperation *op,
|
||||
GtkWindow *parent,
|
||||
gboolean is_preview);
|
||||
gboolean do_print,
|
||||
GtkPrintOperationResult result);
|
||||
|
||||
GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *operation,
|
||||
gboolean show_dialog,
|
||||
GtkWindow *parent,
|
||||
gboolean *do_print,
|
||||
GError **error);
|
||||
gboolean *do_print);
|
||||
void _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
|
||||
gboolean show_dialog,
|
||||
GtkWindow *parent,
|
||||
GtkPrintOperationPrintFunc print_cb);
|
||||
void _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
|
||||
|
@ -350,7 +350,6 @@ typedef struct
|
||||
{
|
||||
GtkPrintOperation *op;
|
||||
gboolean do_print;
|
||||
GError **error;
|
||||
GtkPrintOperationResult result;
|
||||
GtkPrintOperationPrintFunc print_cb;
|
||||
GDestroyNotify destroy;
|
||||
@ -391,7 +390,7 @@ finish_print (PrintResponseData *rdata,
|
||||
GtkPrintOperationUnix *op_unix;
|
||||
cairo_t *cr;
|
||||
|
||||
op_unix = g_new0 (GtkPrintOperationUnix, 1);
|
||||
op_unix = g_new0 (GtkPrintOperationUnix, 1);
|
||||
priv->platform_data = op_unix;
|
||||
priv->free_platform_data = (GDestroyNotify) op_unix_free;
|
||||
op_unix->parent = rdata->parent;
|
||||
@ -404,9 +403,10 @@ finish_print (PrintResponseData *rdata,
|
||||
op_unix->job = job;
|
||||
gtk_print_job_set_track_print_status (job, priv->track_print_status);
|
||||
|
||||
op_unix->surface = gtk_print_job_get_surface (job, rdata->error);
|
||||
op_unix->surface = gtk_print_job_get_surface (job, &priv->error);
|
||||
if (op_unix->surface == NULL)
|
||||
{
|
||||
rdata->result = GTK_PRINT_OPERATION_RESULT_ERROR;
|
||||
rdata->do_print = FALSE;
|
||||
goto out;
|
||||
}
|
||||
@ -435,12 +435,7 @@ finish_print (PrintResponseData *rdata,
|
||||
}
|
||||
out:
|
||||
if (rdata->print_cb)
|
||||
{
|
||||
if (rdata->do_print)
|
||||
rdata->print_cb (op, rdata->parent, is_preview);
|
||||
else
|
||||
_gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
|
||||
}
|
||||
rdata->print_cb (op, rdata->do_print, rdata->parent, rdata->result);
|
||||
|
||||
if (rdata->destroy)
|
||||
rdata->destroy (rdata);
|
||||
@ -504,10 +499,7 @@ found_printer (GtkPrinter *printer,
|
||||
|
||||
if (printer != NULL)
|
||||
{
|
||||
if (priv->show_preview)
|
||||
rdata->result = GTK_PRINT_OPERATION_RESULT_PREVIEW;
|
||||
else
|
||||
rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY;
|
||||
rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY;
|
||||
|
||||
rdata->do_print = TRUE;
|
||||
|
||||
@ -536,6 +528,7 @@ found_printer (GtkPrinter *printer,
|
||||
|
||||
void
|
||||
_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
|
||||
gboolean show_dialog,
|
||||
GtkWindow *parent,
|
||||
GtkPrintOperationPrintFunc print_cb)
|
||||
{
|
||||
@ -547,13 +540,12 @@ _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation
|
||||
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->parent = parent;
|
||||
rdata->loop = NULL;
|
||||
rdata->destroy = print_response_data_free;
|
||||
|
||||
if (op->priv->show_dialog)
|
||||
if (show_dialog)
|
||||
{
|
||||
pd = get_print_dialog (op, parent);
|
||||
gtk_window_set_modal (GTK_WINDOW (pd), TRUE);
|
||||
@ -608,9 +600,9 @@ _gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation
|
||||
|
||||
GtkPrintOperationResult
|
||||
_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
|
||||
gboolean show_dialog,
|
||||
GtkWindow *parent,
|
||||
gboolean *do_print,
|
||||
GError **error)
|
||||
gboolean *do_print)
|
||||
{
|
||||
GtkWidget *pd;
|
||||
PrintResponseData rdata;
|
||||
@ -620,13 +612,12 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
|
||||
rdata.op = op;
|
||||
rdata.do_print = FALSE;
|
||||
rdata.result = GTK_PRINT_OPERATION_RESULT_CANCEL;
|
||||
rdata.error = error;
|
||||
rdata.print_cb = NULL;
|
||||
rdata.destroy = NULL;
|
||||
rdata.parent = parent;
|
||||
rdata.loop = NULL;
|
||||
|
||||
if (op->priv->show_dialog)
|
||||
if (show_dialog)
|
||||
{
|
||||
pd = get_print_dialog (op, parent);
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#define GTK_PRINT_OPERATION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_PRINT_OPERATION, GtkPrintOperationPrivate))
|
||||
|
||||
enum {
|
||||
DONE,
|
||||
BEGIN_PRINT,
|
||||
PAGINATE,
|
||||
REQUEST_PAGE_SETUP,
|
||||
@ -59,9 +60,8 @@ enum {
|
||||
PROP_USE_FULL_PAGE,
|
||||
PROP_TRACK_PRINT_STATUS,
|
||||
PROP_UNIT,
|
||||
PROP_SHOW_DIALOG,
|
||||
PROP_SHOW_PREVIEW,
|
||||
PROP_SHOW_PROGRESS,
|
||||
PROP_ALLOW_ASYNC,
|
||||
PROP_PDF_TARGET,
|
||||
PROP_STATUS,
|
||||
PROP_STATUS_STRING,
|
||||
@ -128,6 +128,9 @@ gtk_print_operation_finalize (GObject *object)
|
||||
if (priv->show_progress_timeout_id > 0)
|
||||
g_source_remove (priv->show_progress_timeout_id);
|
||||
|
||||
if (priv->error)
|
||||
g_error_free (priv->error);
|
||||
|
||||
G_OBJECT_CLASS (gtk_print_operation_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
@ -146,8 +149,6 @@ gtk_print_operation_init (GtkPrintOperation *operation)
|
||||
priv->nr_of_pages = -1;
|
||||
priv->current_page = -1;
|
||||
priv->use_full_page = FALSE;
|
||||
priv->show_dialog = TRUE;
|
||||
priv->show_preview = FALSE;
|
||||
priv->show_progress = FALSE;
|
||||
priv->pdf_target = NULL;
|
||||
priv->track_print_status = FALSE;
|
||||
@ -183,6 +184,9 @@ preview_iface_end_preview (GtkPrintOperationPreview *preview)
|
||||
g_main_loop_quit (op->priv->rloop);
|
||||
|
||||
op->priv->end_run (op, op->priv->is_sync, TRUE);
|
||||
|
||||
g_signal_emit (op, signals[DONE], 0,
|
||||
GTK_PRINT_OPERATION_RESULT_APPLY);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -282,11 +286,8 @@ gtk_print_operation_set_property (GObject *object,
|
||||
case PROP_UNIT:
|
||||
gtk_print_operation_set_unit (op, g_value_get_enum (value));
|
||||
break;
|
||||
case PROP_SHOW_DIALOG:
|
||||
gtk_print_operation_set_show_dialog (op, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_SHOW_PREVIEW:
|
||||
gtk_print_operation_set_show_preview (op, g_value_get_boolean (value));
|
||||
case PROP_ALLOW_ASYNC:
|
||||
gtk_print_operation_set_allow_async (op, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_SHOW_PROGRESS:
|
||||
gtk_print_operation_set_show_progress (op, g_value_get_boolean (value));
|
||||
@ -338,11 +339,8 @@ gtk_print_operation_get_property (GObject *object,
|
||||
case PROP_UNIT:
|
||||
g_value_set_enum (value, priv->unit);
|
||||
break;
|
||||
case PROP_SHOW_DIALOG:
|
||||
g_value_set_boolean (value, priv->show_dialog);
|
||||
break;
|
||||
case PROP_SHOW_PREVIEW:
|
||||
g_value_set_boolean (value, priv->show_preview);
|
||||
case PROP_ALLOW_ASYNC:
|
||||
g_value_set_boolean (value, priv->allow_async);
|
||||
break;
|
||||
case PROP_SHOW_PROGRESS:
|
||||
g_value_set_boolean (value, priv->show_progress);
|
||||
@ -547,6 +545,31 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class)
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (GtkPrintOperationPrivate));
|
||||
|
||||
/**
|
||||
* GtkPrintOperation::done:
|
||||
* @operation: the #GtkPrintOperation on which the signal was emitted
|
||||
* @result: the result of the print operation
|
||||
*
|
||||
* Gets emitted when the print operation run has finished doing
|
||||
* everything required for printing. @result gives you information
|
||||
* about what happened during the run. If @result is
|
||||
* GTK_PRINT_OPERATION_RESULT_ERROR then you can call
|
||||
* gtk_print_operation_get_error() for more information.
|
||||
*
|
||||
* If you enabled print status tracking then gtk_print_operation_is_finished()
|
||||
* may still return false after this was emitted.
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
signals[DONE] =
|
||||
g_signal_new (I_("done"),
|
||||
G_TYPE_FROM_CLASS (gobject_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GtkPrintOperationClass, done),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__INT,
|
||||
G_TYPE_NONE, 1, G_TYPE_INT);
|
||||
|
||||
/**
|
||||
* GtkPrintOperation::begin-print:
|
||||
* @operation: the #GtkPrintOperation on which the signal was emitted
|
||||
@ -980,38 +1003,6 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class)
|
||||
GTK_UNIT_PIXEL,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
|
||||
/**
|
||||
* GtkPrintOperation:show-dialog:
|
||||
*
|
||||
* Determines whether calling gtk_print_operation_run() will present
|
||||
* a print dialog to the user, or just print to the default printer.
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_SHOW_DIALOG,
|
||||
g_param_spec_boolean ("show-dialog",
|
||||
P_("Show Dialog"),
|
||||
P_("TRUE if gtk_print_operation_run() should show the print dialog."),
|
||||
TRUE,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkPrintOperation:show-preview:
|
||||
*
|
||||
* Determines whether calling gtk_print_operation_run() will present
|
||||
* the print preview to the user.
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_SHOW_PREVIEW,
|
||||
g_param_spec_boolean ("show-preview",
|
||||
P_("Show Preview"),
|
||||
P_("TRUE if gtk_print_operation_run() should show the print preview."),
|
||||
TRUE,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkPrintOperation:show-progress:
|
||||
@ -1028,7 +1019,24 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class)
|
||||
P_("TRUE if a progress dialog is shown while printing."),
|
||||
FALSE,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
|
||||
/**
|
||||
* GtkPrintOperation:allow-async:
|
||||
*
|
||||
* Determines whether the print operation may run asynchronous or not.
|
||||
* Some systems don't support asynchronous printing, but those that do
|
||||
* will return GTK_PRINT_OPERATION_RESULT_IN_PROGRESS as the status, and
|
||||
* emit the done signal when the operation is actually done.
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ALLOW_ASYNC,
|
||||
g_param_spec_boolean ("allow-async",
|
||||
P_("Allow Async"),
|
||||
P_("TRUE if print process may run asynchronous."),
|
||||
FALSE,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkPrintOperation:pdf-target:
|
||||
@ -1548,6 +1556,10 @@ gtk_print_operation_get_status_string (GtkPrintOperation *op)
|
||||
* is finished, either successfully (%GTK_PRINT_STATUS_FINISHED)
|
||||
* or unsuccessfully (%GTK_PRINT_STATUS_FINISHED_ABORTED).
|
||||
*
|
||||
* Note: when you enable print status tracking the print operation
|
||||
* can be in a non-finished state even after done has been called, as
|
||||
* the operation status then tracks the print job status on the printer.
|
||||
*
|
||||
* Return value: %TRUE, if the print operation is finished.
|
||||
*
|
||||
* Since: 2.10
|
||||
@ -1565,67 +1577,6 @@ gtk_print_operation_is_finished (GtkPrintOperation *op)
|
||||
priv->status == GTK_PRINT_STATUS_FINISHED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gtk_print_operation_set_show_dialog:
|
||||
* @op: a #GtkPrintOperation
|
||||
* @show_dialog: %TRUE to show the print dialog
|
||||
*
|
||||
* Sets whether calling gtk_print_operation_run() will present
|
||||
* a print dialog to the user, or just print to the default printer.
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
void
|
||||
gtk_print_operation_set_show_dialog (GtkPrintOperation *op,
|
||||
gboolean show_dialog)
|
||||
{
|
||||
GtkPrintOperationPrivate *priv;
|
||||
|
||||
g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
|
||||
|
||||
priv = op->priv;
|
||||
|
||||
show_dialog = show_dialog != FALSE;
|
||||
|
||||
if (priv->show_dialog != show_dialog)
|
||||
{
|
||||
priv->show_dialog = show_dialog;
|
||||
|
||||
g_object_notify (G_OBJECT (op), "show-dialog");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_print_operation_set_show_preview:
|
||||
* @op: a #GtkPrintOperation
|
||||
* @show_preview: %TRUE to show the print preview
|
||||
*
|
||||
* Sets whether calling gtk_print_operation_run() will present
|
||||
* the print preview to the user.
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
void
|
||||
gtk_print_operation_set_show_preview (GtkPrintOperation *op,
|
||||
gboolean show_preview)
|
||||
{
|
||||
GtkPrintOperationPrivate *priv;
|
||||
|
||||
g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
|
||||
|
||||
priv = op->priv;
|
||||
|
||||
show_preview = show_preview != FALSE;
|
||||
|
||||
if (priv->show_preview != show_preview)
|
||||
{
|
||||
priv->show_preview = show_preview;
|
||||
|
||||
g_object_notify (G_OBJECT (op), "show-preview");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_print_operation_set_show_progress:
|
||||
* @op: a #GtkPrintOperation
|
||||
@ -1656,6 +1607,27 @@ gtk_print_operation_set_show_progress (GtkPrintOperation *op,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_print_operation_set_allow_async (GtkPrintOperation *op,
|
||||
gboolean allow_async)
|
||||
{
|
||||
GtkPrintOperationPrivate *priv;
|
||||
|
||||
g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
|
||||
|
||||
priv = op->priv;
|
||||
|
||||
allow_async = allow_async != FALSE;
|
||||
|
||||
if (priv->allow_async != allow_async)
|
||||
{
|
||||
priv->allow_async = allow_async;
|
||||
|
||||
g_object_notify (G_OBJECT (op), "allow-async");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gtk_print_operation_set_custom_tag_label:
|
||||
* @op: a #GtkPrintOperation
|
||||
@ -1801,18 +1773,21 @@ pdf_end_run (GtkPrintOperation *op,
|
||||
static GtkPrintOperationResult
|
||||
run_pdf (GtkPrintOperation *op,
|
||||
GtkWindow *parent,
|
||||
gboolean *do_print,
|
||||
GError **error)
|
||||
gboolean *do_print)
|
||||
{
|
||||
GtkPrintOperationPrivate *priv = op->priv;
|
||||
GtkPageSetup *page_setup;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
double width, height;
|
||||
/* This will be overwritten later by the non-default size, but
|
||||
we need to pass some size: */
|
||||
|
||||
priv->print_context = _gtk_print_context_new (op);
|
||||
|
||||
page_setup = create_page_setup (op);
|
||||
_gtk_print_context_set_page_setup (priv->print_context, page_setup);
|
||||
|
||||
/* This will be overwritten later by the non-default size, but
|
||||
we need to pass some size: */
|
||||
width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
|
||||
height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
|
||||
g_object_unref (page_setup);
|
||||
@ -1939,11 +1914,17 @@ print_pages_idle_done (gpointer user_data)
|
||||
if (data->progress)
|
||||
gtk_widget_destroy (data->progress);
|
||||
|
||||
g_object_unref (data->op);
|
||||
|
||||
if (priv->rloop && !data->is_preview)
|
||||
if (priv->rloop && !data->is_preview)
|
||||
g_main_loop_quit (priv->rloop);
|
||||
|
||||
if (!data->is_preview)
|
||||
g_signal_emit (data->op, signals[DONE], 0,
|
||||
priv->cancelled ?
|
||||
GTK_PRINT_OPERATION_RESULT_CANCEL :
|
||||
GTK_PRINT_OPERATION_RESULT_APPLY);
|
||||
|
||||
g_object_unref (data->op);
|
||||
|
||||
g_free (data);
|
||||
|
||||
GDK_THREADS_LEAVE ();
|
||||
@ -2194,16 +2175,23 @@ show_progress_timeout (PrintPagesData *data)
|
||||
static void
|
||||
print_pages (GtkPrintOperation *op,
|
||||
GtkWindow *parent,
|
||||
gboolean is_preview)
|
||||
gboolean do_print,
|
||||
GtkPrintOperationResult result)
|
||||
{
|
||||
GtkPrintOperationPrivate *priv = op->priv;
|
||||
PrintPagesData *data;
|
||||
|
||||
if (!do_print) {
|
||||
_gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
|
||||
g_signal_emit (op, signals[DONE], 0, result);
|
||||
return;
|
||||
}
|
||||
|
||||
_gtk_print_operation_set_status (op, GTK_PRINT_STATUS_PREPARING, NULL);
|
||||
|
||||
data = g_new0 (PrintPagesData, 1);
|
||||
data->op = g_object_ref (op);
|
||||
data->is_preview = is_preview;
|
||||
data->is_preview = (result == GTK_PRINT_OPERATION_RESULT_PREVIEW);
|
||||
|
||||
if (priv->show_progress)
|
||||
{
|
||||
@ -2224,7 +2212,7 @@ print_pages (GtkPrintOperation *op,
|
||||
data->progress = progress;
|
||||
}
|
||||
|
||||
if (is_preview)
|
||||
if (data->is_preview)
|
||||
{
|
||||
gboolean handled;
|
||||
|
||||
@ -2259,10 +2247,8 @@ print_pages (GtkPrintOperation *op,
|
||||
print_pages_idle,
|
||||
data,
|
||||
print_pages_idle_done);
|
||||
|
||||
/* Recursive main loop to make sure we don't exit
|
||||
* on sync operations
|
||||
*/
|
||||
|
||||
/* Recursive main loop to make sure we don't exit on sync operations */
|
||||
if (priv->is_sync)
|
||||
{
|
||||
priv->rloop = g_main_loop_new (NULL, FALSE);
|
||||
@ -2276,9 +2262,32 @@ print_pages (GtkPrintOperation *op,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_print_operation_get_error:
|
||||
* @op: a #GtkPrintOperation
|
||||
*
|
||||
* Call this when the result of a print operation is
|
||||
* GTK_PRINT_OPERATION_RESULT_ERROR, either as returned by gtk_print_operation_run (),
|
||||
* or in the ::done signal handler. The returned #GError will contain more details
|
||||
* on what went wrong.
|
||||
*
|
||||
* Return value: a GError representing the error, or NULL
|
||||
*
|
||||
* Since: 2.10
|
||||
**/
|
||||
GError *
|
||||
gtk_print_operation_get_error (GtkPrintOperation *op)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), NULL);
|
||||
|
||||
return op->priv->error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gtk_print_operation_run:
|
||||
* @op: a #GtkPrintOperation
|
||||
* @action: the action to start
|
||||
* @parent: Transient parent of the dialog, or %NULL
|
||||
* @error: Return location for errors, or %NULL
|
||||
*
|
||||
@ -2286,11 +2295,16 @@ print_pages (GtkPrintOperation *op,
|
||||
* print settings in the print dialog, and then print the
|
||||
* document.
|
||||
*
|
||||
* Note that this function does not return until the rendering of all
|
||||
* Normally 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.
|
||||
*
|
||||
* If you call gtk_print_operation_set_allow_async () or set the allow-async
|
||||
* property the operation will run asyncronously if this is supported on the
|
||||
* platform. The ::done signal will be emitted with the operation results when
|
||||
* the operation is done (i.e. when the dialog is canceled, or when the print
|
||||
* succeeds or fails).
|
||||
*
|
||||
* <informalexample><programlisting>
|
||||
* if (settings != NULL)
|
||||
@ -2304,7 +2318,7 @@ print_pages (GtkPrintOperation *op,
|
||||
* g_signal_connect (print, "draw-page",
|
||||
* G_CALLBACK (draw_page), &data);
|
||||
*
|
||||
* res = gtk_print_operation_run (print, parent, &error);
|
||||
* res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, parent, &error);
|
||||
*
|
||||
* if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
|
||||
* {
|
||||
@ -2331,85 +2345,78 @@ print_pages (GtkPrintOperation *op,
|
||||
* %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.
|
||||
* and store them for reuse with the next print operation. A value of
|
||||
* %GTK_PRINT_OPERATION_RESULT_IN_PROGRESS means the operation is running
|
||||
* asynchronously, and will emit the ::done signal when done.
|
||||
*
|
||||
* Since: 2.10
|
||||
**/
|
||||
GtkPrintOperationResult
|
||||
gtk_print_operation_run (GtkPrintOperation *op,
|
||||
GtkPrintOperationAction action,
|
||||
GtkWindow *parent,
|
||||
GError **error)
|
||||
GError **opt_error)
|
||||
{
|
||||
GtkPrintOperationPrivate *priv;
|
||||
GtkPrintOperationResult result;
|
||||
GtkPageSetup *page_setup;
|
||||
gboolean do_print;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op),
|
||||
GTK_PRINT_OPERATION_RESULT_ERROR);
|
||||
|
||||
priv = op->priv;
|
||||
priv->is_sync = TRUE;
|
||||
|
||||
if (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, parent, result == GTK_PRINT_OPERATION_RESULT_PREVIEW);
|
||||
else
|
||||
_gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
|
||||
do_print = FALSE;
|
||||
priv->error = NULL;
|
||||
priv->action = action;
|
||||
|
||||
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)
|
||||
{
|
||||
GtkPrintOperationPrivate *priv;
|
||||
gboolean do_print;
|
||||
|
||||
g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
|
||||
|
||||
priv = op->priv;
|
||||
priv->is_sync = FALSE;
|
||||
|
||||
if (priv->pdf_target != NULL)
|
||||
if (priv->print_settings == NULL)
|
||||
priv->print_settings = gtk_print_settings_new ();
|
||||
|
||||
if (action == GTK_PRINT_OPERATION_ACTION_EXPORT)
|
||||
{
|
||||
run_pdf (op, parent, &do_print, NULL);
|
||||
if (do_print)
|
||||
print_pages (op, parent, FALSE);
|
||||
else
|
||||
_gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
|
||||
priv->is_sync = TRUE;
|
||||
g_return_val_if_fail (priv->pdf_target != NULL, GTK_PRINT_OPERATION_RESULT_ERROR);
|
||||
result = run_pdf (op, parent, &do_print);
|
||||
}
|
||||
else if (action == GTK_PRINT_OPERATION_ACTION_PREVIEW)
|
||||
{
|
||||
priv->print_context = _gtk_print_context_new (op);
|
||||
page_setup = create_page_setup (op);
|
||||
_gtk_print_context_set_page_setup (priv->print_context, page_setup);
|
||||
g_object_unref (page_setup);
|
||||
do_print = TRUE;
|
||||
result = GTK_PRINT_OPERATION_RESULT_PREVIEW;
|
||||
|
||||
priv->is_sync = !priv->allow_async;
|
||||
}
|
||||
else if (priv->allow_async)
|
||||
{
|
||||
priv->is_sync = FALSE;
|
||||
_gtk_print_operation_platform_backend_run_dialog_async (op,
|
||||
action == GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
|
||||
parent,
|
||||
print_pages);
|
||||
result = GTK_PRINT_OPERATION_RESULT_IN_PROGRESS;
|
||||
}
|
||||
else
|
||||
_gtk_print_operation_platform_backend_run_dialog_async (op,
|
||||
parent,
|
||||
print_pages);
|
||||
}
|
||||
{
|
||||
priv->is_sync = TRUE;
|
||||
result = _gtk_print_operation_platform_backend_run_dialog (op,
|
||||
action == GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
|
||||
parent,
|
||||
&do_print);
|
||||
}
|
||||
|
||||
if (result != GTK_PRINT_OPERATION_RESULT_IN_PROGRESS)
|
||||
print_pages (op, parent, do_print, result);
|
||||
|
||||
if (priv->error && opt_error)
|
||||
*opt_error = g_error_copy (priv->error);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_print_operation_cancel:
|
||||
|
@ -56,6 +56,22 @@ typedef enum {
|
||||
GTK_PRINT_STATUS_FINISHED_ABORTED
|
||||
} GtkPrintStatus;
|
||||
|
||||
typedef enum {
|
||||
GTK_PRINT_OPERATION_RESULT_ERROR,
|
||||
GTK_PRINT_OPERATION_RESULT_APPLY,
|
||||
GTK_PRINT_OPERATION_RESULT_CANCEL,
|
||||
GTK_PRINT_OPERATION_RESULT_PREVIEW,
|
||||
GTK_PRINT_OPERATION_RESULT_IN_PROGRESS
|
||||
} GtkPrintOperationResult;
|
||||
|
||||
typedef enum {
|
||||
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
|
||||
GTK_PRINT_OPERATION_ACTION_PRINT,
|
||||
GTK_PRINT_OPERATION_ACTION_PREVIEW,
|
||||
GTK_PRINT_OPERATION_ACTION_EXPORT,
|
||||
} GtkPrintOperationAction;
|
||||
|
||||
|
||||
struct _GtkPrintOperation
|
||||
{
|
||||
GObject parent_instance;
|
||||
@ -67,6 +83,8 @@ struct _GtkPrintOperationClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*done) (GtkPrintOperation *operation,
|
||||
GtkPrintOperationResult result);
|
||||
void (*begin_print) (GtkPrintOperation *operation,
|
||||
GtkPrintContext *context);
|
||||
gboolean (*paginate) (GtkPrintOperation *operation,
|
||||
@ -102,13 +120,6 @@ struct _GtkPrintOperationClass
|
||||
void (*_gtk_reserved7) (void);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
GTK_PRINT_OPERATION_RESULT_ERROR,
|
||||
GTK_PRINT_OPERATION_RESULT_APPLY,
|
||||
GTK_PRINT_OPERATION_RESULT_CANCEL,
|
||||
GTK_PRINT_OPERATION_RESULT_PREVIEW
|
||||
} GtkPrintOperationResult;
|
||||
|
||||
#define GTK_PRINT_ERROR gtk_print_error_quark ()
|
||||
|
||||
typedef enum
|
||||
@ -138,23 +149,21 @@ void gtk_print_operation_set_use_full_page (GtkPrintOper
|
||||
gboolean full_page);
|
||||
void gtk_print_operation_set_unit (GtkPrintOperation *op,
|
||||
GtkUnit unit);
|
||||
void gtk_print_operation_set_show_dialog (GtkPrintOperation *op,
|
||||
gboolean show_dialog);
|
||||
void gtk_print_operation_set_show_preview (GtkPrintOperation *op,
|
||||
gboolean show_preview);
|
||||
void gtk_print_operation_set_pdf_target (GtkPrintOperation *op,
|
||||
const gchar *filename);
|
||||
void gtk_print_operation_set_track_print_status (GtkPrintOperation *op,
|
||||
gboolean track_status);
|
||||
void gtk_print_operation_set_show_progress (GtkPrintOperation *op,
|
||||
gboolean show_progress);
|
||||
void gtk_print_operation_set_allow_async (GtkPrintOperation *op,
|
||||
gboolean allow_async);
|
||||
void gtk_print_operation_set_custom_tab_label (GtkPrintOperation *op,
|
||||
const gchar *label);
|
||||
GtkPrintOperationResult gtk_print_operation_run (GtkPrintOperation *op,
|
||||
GtkPrintOperationAction action,
|
||||
GtkWindow *parent,
|
||||
GError **error);
|
||||
void gtk_print_operation_run_preview (GtkPrintOperation *op,
|
||||
GtkWindow *parent);
|
||||
GError * gtk_print_operation_get_error (GtkPrintOperation *op);
|
||||
GtkPrintStatus gtk_print_operation_get_status (GtkPrintOperation *op);
|
||||
G_CONST_RETURN gchar * gtk_print_operation_get_status_string (GtkPrintOperation *op);
|
||||
gboolean gtk_print_operation_is_finished (GtkPrintOperation *op);
|
||||
|
@ -603,18 +603,57 @@ do_preview (GtkPrintOperation *op,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* FIXME had to move this to the heap, since previewing
|
||||
* returns too early from the sync api
|
||||
*/
|
||||
PrintData *print_data;
|
||||
static void
|
||||
print_done (GtkPrintOperation *op,
|
||||
GtkPrintOperationResult res,
|
||||
PrintData *print_data)
|
||||
{
|
||||
GError *error;
|
||||
|
||||
if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
|
||||
{
|
||||
|
||||
GtkWidget *error_dialog;
|
||||
|
||||
error = gtk_print_operation_get_error (op);
|
||||
|
||||
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Error printing file:\n%s",
|
||||
error ? error->message : "no details");
|
||||
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
gtk_widget_show (error_dialog);
|
||||
}
|
||||
else if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
|
||||
{
|
||||
if (settings != NULL)
|
||||
g_object_unref (settings);
|
||||
settings = g_object_ref (gtk_print_operation_get_print_settings (op));
|
||||
}
|
||||
|
||||
g_free (print_data->text);
|
||||
g_free (print_data->font);
|
||||
g_free (print_data);
|
||||
|
||||
if (!gtk_print_operation_is_finished (op))
|
||||
{
|
||||
g_object_ref (op);
|
||||
active_prints = g_list_append (active_prints, op);
|
||||
update_statusbar ();
|
||||
|
||||
/* This ref is unref:ed when we get the final state change */
|
||||
g_signal_connect (op, "status_changed",
|
||||
G_CALLBACK (status_changed_cb), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_print (GtkAction *action)
|
||||
{
|
||||
GtkWidget *error_dialog;
|
||||
GtkPrintOperation *print;
|
||||
GtkPrintOperationResult res;
|
||||
GError *error;
|
||||
PrintData *print_data;
|
||||
|
||||
print_data = g_new0 (PrintData, 1);
|
||||
|
||||
@ -637,49 +676,16 @@ do_print (GtkAction *action)
|
||||
g_signal_connect (print, "custom_widget_apply", G_CALLBACK (custom_widget_apply), print_data);
|
||||
g_signal_connect (print, "preview", G_CALLBACK (do_preview), print_data);
|
||||
|
||||
error = NULL;
|
||||
g_signal_connect (print, "done", G_CALLBACK (print_done), print_data);
|
||||
|
||||
#if 1
|
||||
res = gtk_print_operation_run (print, GTK_WINDOW (main_window), &error);
|
||||
gtk_print_operation_set_pdf_target (print, "test.pdf");
|
||||
|
||||
if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
|
||||
{
|
||||
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Error printing file:\n%s",
|
||||
error ? error->message : "no details");
|
||||
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
gtk_widget_show (error_dialog);
|
||||
g_error_free (error);
|
||||
}
|
||||
else if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
|
||||
{
|
||||
if (settings != NULL)
|
||||
g_object_unref (settings);
|
||||
settings = g_object_ref (gtk_print_operation_get_print_settings (print));
|
||||
}
|
||||
|
||||
if (!gtk_print_operation_is_finished (print))
|
||||
{
|
||||
g_object_ref (print);
|
||||
active_prints = g_list_append (active_prints, print);
|
||||
update_statusbar ();
|
||||
|
||||
/* This ref is unref:ed when we get the final state change */
|
||||
g_signal_connect (print, "status_changed",
|
||||
G_CALLBACK (status_changed_cb), NULL);
|
||||
}
|
||||
#else
|
||||
gtk_print_operation_run_async (print, GTK_WINDOW (main_window));
|
||||
#if 0
|
||||
gtk_print_operation_set_allow_async (print, TRUE);
|
||||
#endif
|
||||
gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PREVIEW, GTK_WINDOW (main_window), NULL);
|
||||
|
||||
g_object_unref (print);
|
||||
#if 0
|
||||
g_free (print_data.text);
|
||||
g_free (print_data.font);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -99,9 +99,8 @@ main (int argc, char **argv)
|
||||
gtk_print_operation_set_print_settings (print, settings);
|
||||
gtk_print_operation_set_n_pages (print, 1);
|
||||
gtk_print_operation_set_unit (print, GTK_UNIT_MM);
|
||||
gtk_print_operation_set_show_dialog (print, FALSE);
|
||||
g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
|
||||
res = gtk_print_operation_run (print, NULL, NULL);
|
||||
res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT, NULL, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -111,13 +111,13 @@ main (int argc, char **argv)
|
||||
gtk_print_operation_set_pdf_target (print, "test.pdf");
|
||||
g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
|
||||
g_signal_connect (print, "request_page_setup", G_CALLBACK (request_page_setup), NULL);
|
||||
res = gtk_print_operation_run (print, NULL, NULL);
|
||||
res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL);
|
||||
|
||||
/* Test subclassing of GtkPrintOperation */
|
||||
print_file = test_print_file_operation_new ("testprint.c");
|
||||
test_print_file_operation_set_font_size (print_file, 12.0);
|
||||
gtk_print_operation_set_pdf_target (GTK_PRINT_OPERATION (print_file), "test2.pdf");
|
||||
res = gtk_print_operation_run (GTK_PRINT_OPERATION (print_file), NULL, NULL);
|
||||
res = gtk_print_operation_run (GTK_PRINT_OPERATION (print_file), GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user