]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprintoperation.c
Bug 457086 - numpad does not work when the Thai-Lao input method is used
[~andy/gtk] / gtk / gtkprintoperation.c
index 321240d82e3e138468b4ed84481abf12b8bc36b4..05b8b9e4a7f5d44aa96fc4196391aea3a5bdab9c 100644 (file)
@@ -160,6 +160,8 @@ gtk_print_operation_init (GtkPrintOperation *operation)
   priv->track_print_status = FALSE;
   priv->is_sync = FALSE;
 
+  priv->page_drawing_state = GTK_PAGE_DRAWING_STATE_READY;
+
   priv->rloop = NULL;
   priv->unit = GTK_UNIT_PIXEL;
 
@@ -417,19 +419,31 @@ preview_print_idle (gpointer data)
   GtkPrintOperation *op;
   gboolean retval = TRUE;
   cairo_t *cr;
+  GtkPrintOperationPrivate *priv; 
 
   pop = (PreviewOp *) data;
   op = GTK_PRINT_OPERATION (pop->preview);
+  priv = op->priv;
 
-  gtk_print_operation_preview_render_page (pop->preview, pop->page_nr);
-  
-  cr = gtk_print_context_get_cairo_context (pop->print_context);
-  _gtk_print_operation_platform_backend_preview_end_page (op, pop->surface, cr);
-  
-  /* TODO: print out sheets not pages and follow ranges */
-  pop->page_nr++;
-  if (op->priv->nr_of_pages <= pop->page_nr)
-    retval = FALSE;
+
+  if (priv->page_drawing_state == GTK_PAGE_DRAWING_STATE_READY)
+    {
+      /* TODO: print out sheets not pages and follow ranges */
+      if (pop->page_nr >= op->priv->nr_of_pages)
+        retval = FALSE;
+
+      if (pop->page_nr > 0)
+        {
+          cr = gtk_print_context_get_cairo_context (pop->print_context);
+          _gtk_print_operation_platform_backend_preview_end_page (op, pop->surface, cr);
+        }
+
+      if (retval)
+        {
+          gtk_print_operation_preview_render_page (pop->preview, pop->page_nr);
+          pop->page_nr++;
+        }
+    }
 
   return retval;
 }
@@ -646,7 +660,7 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class)
    * GtkPrintOperation::request-page-setup:
    * @operation: the #GtkPrintOperation on which the signal was emitted
    * @context: the #GtkPrintContext for the current operation
-   * @page_nr: the number of the currently printed page
+   * @page_nr: the number of the currently printed page (0-based)
    * @setup: the #GtkPageSetup 
    * 
    * Emitted once for every page that is printed, to give
@@ -671,7 +685,7 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class)
    * GtkPrintOperation::draw-page:
    * @operation: the #GtkPrintOperation on which the signal was emitted
    * @context: the #GtkPrintContext for the current operation
-   * @page_nr: the number of the currently printed page
+   * @page_nr: the number of the currently printed page (0-based)
    *
    * Emitted for every page that is printed. The signal handler
    * must render the @page_nr's page onto the cairo context obtained
@@ -1500,31 +1514,22 @@ _gtk_print_operation_set_status (GtkPrintOperation *op,
 {
   GtkPrintOperationPrivate *priv = op->priv;
   static const gchar *status_strs[] = {
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Initial state"),
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Preparing to print"),
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Generating data"),
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Sending data"),
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Waiting"),
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Blocking on issue"),
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Printing"),
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Finished"),
-    /* translators, strip the prefix up to and including the first | */
-    N_("print operation status|Finished with error")
+    NC_("print operation status", "Initial state"),
+    NC_("print operation status", "Preparing to print"),
+    NC_("print operation status", "Generating data"),
+    NC_("print operation status", "Sending data"),
+    NC_("print operation status", "Waiting"),
+    NC_("print operation status", "Blocking on issue"),
+    NC_("print operation status", "Printing"),
+    NC_("print operation status", "Finished"),
+    NC_("print operation status", "Finished with error")
   };
 
   if (status < 0 || status > GTK_PRINT_STATUS_FINISHED_ABORTED)
     status = GTK_PRINT_STATUS_FINISHED_ABORTED;
 
   if (string == NULL)
-    string = g_strip_context (status_strs[status], _(status_strs[status]));
+    string = g_dpgettext2 (GETTEXT_PACKAGE, "print operation status", status_strs[status]);
   
   if (priv->status == status &&
       strcmp (string, priv->status_string) == 0)
@@ -1848,10 +1853,10 @@ run_pdf (GtkPrintOperation  *op,
                                      width, height);
   if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
     {
-      g_set_error (&priv->error,
-                  GTK_PRINT_ERROR,
-                  GTK_PRINT_ERROR_GENERAL,
-                  cairo_status_to_string (cairo_surface_status (surface)));
+      g_set_error_literal (&priv->error,
+                           GTK_PRINT_ERROR,
+                           GTK_PRINT_ERROR_GENERAL,
+                           cairo_status_to_string (cairo_surface_status (surface)));
       *do_print = FALSE;
       return GTK_PRINT_OPERATION_RESULT_ERROR;
     }
@@ -2055,6 +2060,64 @@ update_progress (PrintPagesData *data)
     }
  }
 
+/**
+ * gtk_print_operation_set_defer_drawing:
+ * @op: a #GtkPrintOperation
+ * 
+ * Sets up the #GtkPrintOperation to wait for calling of
+ * gtk_print_operation_draw_page_finish() from application. It can
+ * be used for drawing page in another thread.
+ *
+ * This function must be called in the callback of "draw-page" signal.
+ *
+ * Since: 2.16
+ **/
+void
+gtk_print_operation_set_defer_drawing (GtkPrintOperation *op)
+{
+  GtkPrintOperationPrivate *priv = op->priv;
+
+  g_return_if_fail (priv->page_drawing_state == GTK_PAGE_DRAWING_STATE_DRAWING);
+
+  priv->page_drawing_state = GTK_PAGE_DRAWING_STATE_DEFERRED_DRAWING;
+}
+
+/**
+ * gtk_print_operation_draw_page_finish:
+ * @op: a #GtkPrintOperation
+ * 
+ * Signalize that drawing of particular page is complete.
+ *
+ * It is called after completion of page drawing (e.g. drawing in another
+ * thread).
+ * If gtk_print_operation_set_defer_drawing() was called before, then this function
+ * has to be called by application. In another case it is called by the library
+ * itself.
+ *
+ * Since: 2.16
+ **/
+void
+gtk_print_operation_draw_page_finish (GtkPrintOperation *op)
+{
+  GtkPrintOperationPrivate *priv = op->priv;
+  GtkPageSetup *page_setup;
+  GtkPrintContext *print_context;
+  cairo_t *cr;
+  
+  print_context = priv->print_context;
+  page_setup = gtk_print_context_get_page_setup (print_context);
+
+  cr = gtk_print_context_get_cairo_context (print_context);
+
+  priv->end_page (op, print_context);
+  
+  cairo_restore (cr);
+
+  g_object_unref (page_setup);
+
+  priv->page_drawing_state = GTK_PAGE_DRAWING_STATE_READY;
+}
+
 static void
 common_render_page (GtkPrintOperation *op,
                    gint               page_nr)
@@ -2089,161 +2152,178 @@ common_render_page (GtkPrintOperation *op,
   if (!priv->use_full_page)
     _gtk_print_context_translate_into_margin (print_context);
   
+  priv->page_drawing_state = GTK_PAGE_DRAWING_STATE_DRAWING;
+
   g_signal_emit (op, signals[DRAW_PAGE], 0, 
                 print_context, page_nr);
 
-  priv->end_page (op, print_context);
-  
-  cairo_restore (cr);
-
-  g_object_unref (page_setup);
+  if (priv->page_drawing_state == GTK_PAGE_DRAWING_STATE_DRAWING)
+    gtk_print_operation_draw_page_finish (op);
 }
 
-static gboolean
-print_pages_idle (gpointer user_data)
+static void
+prepare_data (PrintPagesData *data)
 {
-  PrintPagesData *data; 
-  GtkPrintOperationPrivate *priv; 
-  GtkPageSetup *page_setup;
-  gboolean done = FALSE;
-  gint i;
+  GtkPrintOperationPrivate *priv;
+  GtkPageSetup             *page_setup;
+  gint                      i;
 
-  data = (PrintPagesData*)user_data;
   priv = data->op->priv;
 
-  if (priv->status == GTK_PRINT_STATUS_PREPARING)
+  if (!data->initialized)
     {
-      if (!data->initialized)
-       {
-         data->initialized = TRUE;
-         page_setup = create_page_setup (data->op);
-         _gtk_print_context_set_page_setup (priv->print_context, 
-                                            page_setup);
-         g_object_unref (page_setup);
-      
-         g_signal_emit (data->op, signals[BEGIN_PRINT], 0, priv->print_context);
-      
-         if (priv->manual_collation)
-           {
-             data->uncollated_copies = priv->manual_num_copies;
-             data->collated_copies = 1;
-           }
-         else
-           {
-             data->uncollated_copies = 1;
-             data->collated_copies = priv->manual_num_copies;
-           }
-
-         goto out;
-       }
-      
-      if (g_signal_has_handler_pending (data->op, signals[PAGINATE], 0, FALSE))
-       {
-         gboolean paginated = FALSE;
+      data->initialized = TRUE;
+      page_setup = create_page_setup (data->op);
+      _gtk_print_context_set_page_setup (priv->print_context, 
+                                 page_setup);
+      g_object_unref (page_setup);
 
-         g_signal_emit (data->op, signals[PAGINATE], 0, priv->print_context, &paginated);
-         if (!paginated)
-           goto out;
-       }
+      g_signal_emit (data->op, signals[BEGIN_PRINT], 0, priv->print_context);
 
-      /* Initialize parts of PrintPagesData that depend on nr_of_pages
-       */
-      if (priv->print_pages == GTK_PRINT_PAGES_RANGES)
-       {
-          if (priv->page_ranges == NULL) 
-            {
-              g_warning ("no pages to print");
-              priv->cancelled = TRUE;
-              goto out;
-         }
-         data->ranges = priv->page_ranges;
-         data->num_ranges = priv->num_page_ranges;
-          for (i = 0; i < data->num_ranges; i++)
-            if (data->ranges[i].end == -1 || 
-                data->ranges[i].end >= priv->nr_of_pages)
-              data->ranges[i].end = priv->nr_of_pages - 1;
-       }
-      else if (priv->print_pages == GTK_PRINT_PAGES_CURRENT &&
-              priv->current_page != -1)
-       {
-         data->ranges = &data->one_range;
-         data->num_ranges = 1;
-         data->ranges[0].start = priv->current_page;
-         data->ranges[0].end = priv->current_page;
-       }
+      if (priv->manual_collation)
+        {
+          data->uncollated_copies = priv->manual_num_copies;
+          data->collated_copies = 1;
+        }
       else
-       {
-         data->ranges = &data->one_range;
-         data->num_ranges = 1;
-         data->ranges[0].start = 0;
-         data->ranges[0].end = priv->nr_of_pages - 1;
-       }
-      
-      clamp_page_ranges (data);
+        {
+          data->uncollated_copies = 1;
+          data->collated_copies = priv->manual_num_copies;
+        }
 
-      if (priv->manual_reverse)
-       {
-         data->range = data->num_ranges - 1;
-         data->inc = -1;      
-       }
-      else
-       {
-         data->range = 0;
-         data->inc = 1;      
-       }
-      find_range (data);
-     
-      /* go back one page, since we preincrement below */
-      data->page = data->start - data->inc;
-      data->collated = data->collated_copies - 1;
+      return;
+    }
 
-      _gtk_print_operation_set_status (data->op, 
-                                      GTK_PRINT_STATUS_GENERATING_DATA, 
-                                      NULL);
+  if (g_signal_has_handler_pending (data->op, signals[PAGINATE], 0, FALSE))
+    {
+      gboolean paginated = FALSE;
 
-      goto out;
+      g_signal_emit (data->op, signals[PAGINATE], 0, priv->print_context, &paginated);
+      if (!paginated)
+        return;
     }
 
-  data->total++;
-  data->collated++;
-  if (data->collated == data->collated_copies)
+  /* Initialize parts of PrintPagesData that depend on nr_of_pages
+   */
+  if (priv->print_pages == GTK_PRINT_PAGES_RANGES)
     {
-      data->collated = 0;
-      if (!increment_page_sequence (data))
-       {
-         done = TRUE;
-
-         goto out;
-       }
+      if (priv->page_ranges == NULL) 
+        {
+          g_warning ("no pages to print");
+          priv->cancelled = TRUE;
+          return;
+        }
+      data->ranges = priv->page_ranges;
+      data->num_ranges = priv->num_page_ranges;
+      for (i = 0; i < data->num_ranges; i++)
+        if (data->ranges[i].end == -1 || 
+            data->ranges[i].end >= priv->nr_of_pages)
+          data->ranges[i].end = priv->nr_of_pages - 1;
     }
-  if (data->is_preview && !priv->cancelled)
+  else if (priv->print_pages == GTK_PRINT_PAGES_CURRENT &&
+   priv->current_page != -1)
     {
-      done = TRUE;
-
-      g_signal_emit_by_name (data->op, "ready", priv->print_context);
-      goto out;
+      data->ranges = &data->one_range;
+      data->num_ranges = 1;
+      data->ranges[0].start = priv->current_page;
+      data->ranges[0].end = priv->current_page;
+    }
+  else
+    {
+      data->ranges = &data->one_range;
+      data->num_ranges = 1;
+      data->ranges[0].start = 0;
+      data->ranges[0].end = priv->nr_of_pages - 1;
     }
 
-  common_render_page (data->op, data->page);
-
- out:
+  clamp_page_ranges (data);
 
-  if (priv->cancelled)
+  if (data->num_ranges < 1) 
     {
-      _gtk_print_operation_set_status (data->op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
-      
-      data->is_preview = FALSE;
-      done = TRUE;
+      priv->cancelled = TRUE;
+      return;
     }
 
-  if (done && !data->is_preview)
+  if (priv->manual_reverse)
+    {
+      data->range = data->num_ranges - 1;
+      data->inc = -1;      
+    }
+  else
     {
-      g_signal_emit (data->op, signals[END_PRINT], 0, priv->print_context);
-      priv->end_run (data->op, priv->is_sync, priv->cancelled);
+      data->range = 0;
+      data->inc = 1;      
     }
+  find_range (data);
+
+  /* go back one page, since we preincrement below */
+  data->page = data->start - data->inc;
+  data->collated = data->collated_copies - 1;
+
+  _gtk_print_operation_set_status (data->op, 
+                                   GTK_PRINT_STATUS_GENERATING_DATA, 
+                                   NULL);
+}
+
+static gboolean
+print_pages_idle (gpointer user_data)
+{
+  PrintPagesData *data; 
+  GtkPrintOperationPrivate *priv; 
+  gboolean done = FALSE;
+
+  data = (PrintPagesData*)user_data;
+  priv = data->op->priv;
+
+  if (priv->page_drawing_state == GTK_PAGE_DRAWING_STATE_READY)
+    {
+      if (priv->status == GTK_PRINT_STATUS_PREPARING)
+        {
+          prepare_data (data);
+          goto out;
+        }
+
+      data->total++;
+      data->collated++;
+      if (data->collated == data->collated_copies)
+        {
+          data->collated = 0;
+          if (!increment_page_sequence (data))
+            {
+              done = TRUE;
+
+              goto out;
+            }
+        }
+
+      if (data->is_preview && !priv->cancelled)
+        {
+          done = TRUE;
+
+          g_signal_emit_by_name (data->op, "ready", priv->print_context);
+          goto out;
+        }
+
+      common_render_page (data->op, data->page);
 
-  update_progress (data);
+ out:
+
+      if (priv->cancelled)
+        {
+          _gtk_print_operation_set_status (data->op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
+
+          data->is_preview = FALSE;
+          done = TRUE;
+        }
+
+      if (done && !data->is_preview)
+        {
+          g_signal_emit (data->op, signals[END_PRINT], 0, priv->print_context);
+          priv->end_run (data->op, priv->is_sync, priv->cancelled);
+        }
+
+      update_progress (data);
+    }
 
   return !done;
 }