-/* GTK - The GTK+ Toolkit
+/* GTK - The GIMP Toolkit
* gtkprintoperation.c: Print Operation
* Copyright (C) 2006, Red Hat, Inc.
*
&dpi_x, &dpi_y,
&pop->filename);
+ if (pop->surface == NULL)
+ {
+ g_free (pop);
+ return FALSE;
+ }
+
cr = cairo_create (pop->surface);
gtk_print_context_set_cairo_context (op->priv->print_context, cr,
dpi_x, dpi_y);
* @result: the result of the print operation
*
* Emitted when the print operation run has finished doing
- * everything required for printing. @result gives you information
- * about what happened during the run. If @result is
- * %GTK_PRINT_OPERATION_RESULT_ERROR then you can call
+ * everything required for printing.
+ *
+ * @result gives you information about what happened during the run.
+ * If @result is %GTK_PRINT_OPERATION_RESULT_ERROR then you can call
* gtk_print_operation_get_error() for more information.
*
* If you enabled print status tracking then
* @context: the #GtkPrintContext for the current operation
*
* Emitted after the #GtkPrintOperation::begin-print signal, but before
- * the actual rendering starts. It keeps getting emitted until it
- * returns %FALSE.
+ * the actual rendering starts. It keeps getting emitted until a connected
+ * signal handler returns %TRUE.
*
- * The ::paginate signal is intended to be used for paginating the document
+ * The ::paginate signal is intended to be used for paginating a document
* in small chunks, to avoid blocking the user interface for a long
* time. The signal handler should update the number of pages using
* gtk_print_operation_set_n_pages(), and return %TRUE if the document
* 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
* 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
* tab in the print dialog. You typically return a container widget
* with multiple widgets in it.
*
- * The print dialog owns the returned widget, and its lifetime
- * isn't controlled by the app. However, the widget is guaranteed
+ * The print dialog owns the returned widget, and its lifetime is not
+ * controlled by the application. However, the widget is guaranteed
* to stay around until the #GtkPrintOperation::custom-widget-apply
* signal is emitted on the operation. Then you can read out any
* information you need from the widgets.
*
* Some systems don't support asynchronous printing, but those that do
* will return %GTK_PRINT_OPERATION_RESULT_IN_PROGRESS as the status, and
- * emit the done signal when the operation is actually done.
+ * emit the #GtkPrintOperation::done signal when the operation is actually
+ * done.
*
- * The Windows port does not support asynchronous operation
- * at all (this is unlikely to change). On other platforms, all actions
- * except for %GTK_PRINT_OPERATION_ACTION_EXPORT support asynchronous
- * operation.
+ * The Windows port does not support asynchronous operation at all (this
+ * is unlikely to change). On other platforms, all actions except for
+ * %GTK_PRINT_OPERATION_ACTION_EXPORT support asynchronous operation.
*
* Since: 2.10
*/
/**
* GtkPrintOperation:export-filename:
*
- * The name of a file file to generate instead of showing
- * the print dialog. Currently, PDF is the only supported
- * format.
+ * The name of a file to generate instead of showing the print dialog.
+ * Currently, PDF is the only supported format.
*
* The intended use of this property is for implementing
* "Export to PDF" actions.
* The string is translated and suitable for displaying the print
* status e.g. in a #GtkStatusbar.
*
- * See the ::status property for a status value that is suitable
- * for programmatic use.
+ * See the #GtkPrintOperation:status property for a status value that
+ * is suitable for programmatic use.
*
* Since: 2.10
*/
{
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)
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;
}
}
}
+static void
+clamp_page_ranges (PrintPagesData *data)
+{
+ GtkPrintOperationPrivate *priv;
+ gint num_of_correct_ranges;
+ gint i;
+
+ priv = data->op->priv;
+
+ num_of_correct_ranges = 0;
+
+ for (i = 0; i < data->num_ranges; i++)
+ if ((data->ranges[i].start >= 0) &&
+ (data->ranges[i].start < priv->nr_of_pages) &&
+ (data->ranges[i].end >= 0) &&
+ (data->ranges[i].end < priv->nr_of_pages))
+ {
+ data->ranges[num_of_correct_ranges] = data->ranges[i];
+ num_of_correct_ranges++;
+ }
+ else if ((data->ranges[i].start >= 0) &&
+ (data->ranges[i].start < priv->nr_of_pages) &&
+ (data->ranges[i].end >= priv->nr_of_pages))
+ {
+ data->ranges[i].end = priv->nr_of_pages - 1;
+ data->ranges[num_of_correct_ranges] = data->ranges[i];
+ num_of_correct_ranges++;
+ }
+ else if ((data->ranges[i].end >= 0) &&
+ (data->ranges[i].end < priv->nr_of_pages) &&
+ (data->ranges[i].start < 0))
+ {
+ data->ranges[i].start = 0;
+ data->ranges[num_of_correct_ranges] = data->ranges[i];
+ num_of_correct_ranges++;
+ }
+
+ data->num_ranges = num_of_correct_ranges;
+}
+
static gboolean
increment_page_sequence (PrintPagesData *data)
{
data->ranges[0].end = priv->nr_of_pages - 1;
}
+ clamp_page_ranges (data);
+
if (priv->manual_reverse)
{
data->range = data->num_ranges - 1;
priv->print_context,
parent,
&handled);
-
- if (!handled ||
- gtk_print_context_get_cairo_context (priv->print_context) == NULL)
- {
- /* Programmer error */
- g_error ("You must set a cairo context on the print context");
- }
+
+ if (!handled)
+ {
+ GtkWidget *error_dialog;
+
+ error_dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Error creating print preview"));
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
+ _("The most probable reason is that a temporary file could not be created."));
+
+ if (parent && parent->group)
+ gtk_window_group_add_window (parent->group, GTK_WINDOW (error_dialog));
+
+ g_signal_connect (error_dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_widget_show (error_dialog);
+
+ print_pages_idle_done (data);
+
+ return;
+ }
+
+ if (gtk_print_context_get_cairo_context (priv->print_context) == NULL)
+ {
+ /* Programmer error */
+ g_error ("You must set a cairo context on the print context");
+ }
priv->start_page = preview_start_page;
priv->end_page = preview_end_page;
* information about the progress of the print operation.
* Furthermore, it may use a recursive mainloop to show the print dialog.
*
- * If you call gtk_print_operation_set_allow_async() or set the allow-async
- * property the operation will run asyncronously if this is supported on the
- * platform. The #GtkPrintOperation::done signal will be emitted with the
- * operation results when the operation is done (i.e. when the dialog is
- * canceled, or when the print succeeds or fails).
+ * If you call gtk_print_operation_set_allow_async() or set the
+ * #GtkPrintOperation:allow-async property the operation will run
+ * asynchronously if this is supported on the platform. The
+ * #GtkPrintOperation::done signal will be emitted with the result of the
+ * operation when the it is done (i.e. when the dialog is canceled, or when
+ * the print succeeds or fails).
* |[
* if (settings != NULL)
* gtk_print_operation_set_print_settings (print, settings);
* the used print settings with gtk_print_operation_get_print_settings()
* and store them for reuse with the next print operation. A value of
* %GTK_PRINT_OPERATION_RESULT_IN_PROGRESS means the operation is running
- * asynchronously, and will emit the ::done signal when done.
+ * asynchronously, and will emit the #GtkPrintOperation::done signal when
+ * done.
*
* Since: 2.10
**/