mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-16 21:50:34 +00:00
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:
parent
31efc4097e
commit
9f9c5ca49a
@ -696,6 +696,14 @@ gtk_print_operation_create_custom_widget (GtkPrintOperation *operation)
|
|||||||
return NULL;
|
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
|
static void
|
||||||
gtk_print_operation_done (GtkPrintOperation *operation,
|
gtk_print_operation_done (GtkPrintOperation *operation,
|
||||||
GtkPrintOperationResult result)
|
GtkPrintOperationResult result)
|
||||||
@ -726,6 +734,19 @@ custom_widget_accumulator (GSignalInvocationHint *ihint,
|
|||||||
return continue_emission;
|
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
|
static void
|
||||||
gtk_print_operation_class_init (GtkPrintOperationClass *class)
|
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->preview = gtk_print_operation_preview_handler;
|
||||||
class->create_custom_widget = gtk_print_operation_create_custom_widget;
|
class->create_custom_widget = gtk_print_operation_create_custom_widget;
|
||||||
|
class->paginate = gtk_print_operation_paginate;
|
||||||
class->done = gtk_print_operation_done;
|
class->done = gtk_print_operation_done;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -817,7 +839,7 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class)
|
|||||||
G_TYPE_FROM_CLASS (gobject_class),
|
G_TYPE_FROM_CLASS (gobject_class),
|
||||||
G_SIGNAL_RUN_LAST,
|
G_SIGNAL_RUN_LAST,
|
||||||
G_STRUCT_OFFSET (GtkPrintOperationClass, paginate),
|
G_STRUCT_OFFSET (GtkPrintOperationClass, paginate),
|
||||||
_gtk_boolean_handled_accumulator, NULL,
|
paginate_accumulator, NULL,
|
||||||
_gtk_marshal_BOOLEAN__OBJECT,
|
_gtk_marshal_BOOLEAN__OBJECT,
|
||||||
G_TYPE_BOOLEAN, 1, GTK_TYPE_PRINT_CONTEXT);
|
G_TYPE_BOOLEAN, 1, GTK_TYPE_PRINT_CONTEXT);
|
||||||
|
|
||||||
@ -2697,6 +2719,7 @@ prepare_data (PrintPagesData *data)
|
|||||||
{
|
{
|
||||||
GtkPrintOperationPrivate *priv;
|
GtkPrintOperationPrivate *priv;
|
||||||
GtkPageSetup *page_setup;
|
GtkPageSetup *page_setup;
|
||||||
|
gboolean paginated = FALSE;
|
||||||
gint i, j, counter;
|
gint i, j, counter;
|
||||||
|
|
||||||
priv = data->op->priv;
|
priv = data->op->priv;
|
||||||
@ -2725,14 +2748,9 @@ prepare_data (PrintPagesData *data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_signal_has_handler_pending (data->op, signals[PAGINATE], 0, FALSE))
|
g_signal_emit (data->op, signals[PAGINATE], 0, priv->print_context, &paginated);
|
||||||
{
|
if (!paginated)
|
||||||
gboolean paginated = FALSE;
|
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
|
/* Initialize parts of PrintPagesData that depend on nr_of_pages
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user