[gtk+/gtk-3-16] print operation: let subclasses use a custom paginate
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-16] print operation: let subclasses use a custom paginate
- Date: Fri, 18 Sep 2015 01:11:27 +0000 (UTC)
commit 47964f360fa89a567564def77141b542847527de
Author: Paolo Borelli <pborelli gnome org>
Date: Mon Aug 17 18:31:15 2015 +0200
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
gtk/gtkprintoperation.c | 36 +++++++++++++++++++++++++++---------
1 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c
index 057430b..135c8c8 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);
@@ -2698,6 +2720,7 @@ prepare_data (PrintPagesData *data)
{
GtkPrintOperationPrivate *priv;
GtkPageSetup *page_setup;
+ gboolean paginated = FALSE;
gint i, j, counter;
priv = data->op->priv;
@@ -2726,14 +2749,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
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]