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
This commit is contained in:
Paolo Borelli 2015-08-17 18:31:15 +02:00
parent 31efc4097e
commit 9f9c5ca49a

View File

@ -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
*/