diff options
author | Paolo Borelli <pborelli@gnome.org> | 2015-08-17 18:31:15 +0200 |
---|---|---|
committer | Paolo Borelli <pborelli@gnome.org> | 2015-08-18 15:14:42 +0200 |
commit | 9f9c5ca49ada3e9345a48fd8d642883c0f7339fb (patch) | |
tree | d490b993170c9876d60430a964677ced205e02b5 /gtk/gtkprintoperation.c | |
parent | 31efc4097e51c1615d101d20b9ea75643dfb0558 (diff) | |
download | gtk+-9f9c5ca49ada3e9345a48fd8d642883c0f7339fb.tar.gz |
print operation: let subclasses use a custom paginate
GtkPrintOperation was emitting paginate only if a signal was
connected, this meant that subclassing and overriding the
paginate vfunc lead to the unexpected result that paginate did
not run.
Instead we always emit the signal and use a custom accumulator:
if there is a signal we just run that and avoid the default
handler, otherwise we run the default handler which can be the
one by the subclass or the default handler that just skips
pagination.
Patch by Yevgen Muntyan, fixes #345345
Diffstat (limited to 'gtk/gtkprintoperation.c')
-rw-r--r-- | gtk/gtkprintoperation.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c index 929cdafea6..6dc7fb2403 100644 --- a/gtk/gtkprintoperation.c +++ b/gtk/gtkprintoperation.c @@ -696,6 +696,14 @@ gtk_print_operation_create_custom_widget (GtkPrintOperation *operation) return NULL; } +static gboolean +gtk_print_operation_paginate (GtkPrintOperation *operation, + GtkPrintContext *context) +{ + /* assume the number of pages is already set and pagination is not needed */ + return TRUE; +} + static void gtk_print_operation_done (GtkPrintOperation *operation, GtkPrintOperationResult result) @@ -726,6 +734,19 @@ custom_widget_accumulator (GSignalInvocationHint *ihint, return continue_emission; } +static gboolean +paginate_accumulator (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy) +{ + *return_accu = *handler_return; + + /* Stop signal emission on first invocation, so if it's a callback then + * the default handler won't run. */ + return FALSE; +} + static void gtk_print_operation_class_init (GtkPrintOperationClass *class) { @@ -737,6 +758,7 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class) class->preview = gtk_print_operation_preview_handler; class->create_custom_widget = gtk_print_operation_create_custom_widget; + class->paginate = gtk_print_operation_paginate; class->done = gtk_print_operation_done; /** @@ -817,7 +839,7 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class) G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GtkPrintOperationClass, paginate), - _gtk_boolean_handled_accumulator, NULL, + paginate_accumulator, NULL, _gtk_marshal_BOOLEAN__OBJECT, G_TYPE_BOOLEAN, 1, GTK_TYPE_PRINT_CONTEXT); @@ -2697,6 +2719,7 @@ prepare_data (PrintPagesData *data) { GtkPrintOperationPrivate *priv; GtkPageSetup *page_setup; + gboolean paginated = FALSE; gint i, j, counter; priv = data->op->priv; @@ -2725,14 +2748,9 @@ prepare_data (PrintPagesData *data) return; } - if (g_signal_has_handler_pending (data->op, signals[PAGINATE], 0, FALSE)) - { - gboolean paginated = FALSE; - - g_signal_emit (data->op, signals[PAGINATE], 0, priv->print_context, &paginated); - if (!paginated) - return; - } + g_signal_emit (data->op, signals[PAGINATE], 0, priv->print_context, &paginated); + if (!paginated) + return; /* Initialize parts of PrintPagesData that depend on nr_of_pages */ |