+static void
+update_number_up_layout (GtkPrintUnixDialog *dialog)
+{
+ GtkPrintUnixDialogPrivate *priv = dialog->priv;
+ GtkPrintCapabilities caps;
+ GtkPrinterOptionSet *set;
+ GtkNumberUpLayout layout;
+ GtkPrinterOption *option;
+ GtkPrinterOption *old_option;
+ GtkPageOrientation page_orientation;
+
+ set = priv->options;
+
+ caps = priv->manual_capabilities | priv->printer_capabilities;
+
+ if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
+ {
+ if (priv->number_up_layout_n_option == NULL)
+ {
+ priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
+ if (priv->number_up_layout_n_option == NULL)
+ {
+ char *n_up_layout[] = { "lrtb", "lrbt", "rltb", "rlbt", "tblr", "tbrl", "btlr", "btrl" };
+ /* Translators: These strings name the possible arrangements of
+ * multiple pages on a sheet when printing (same as in gtkprintbackendcups.c)
+ */
+ char *n_up_layout_display[] = { N_("Left to right, top to bottom"), N_("Left to right, bottom to top"),
+ N_("Right to left, top to bottom"), N_("Right to left, bottom to top"),
+ N_("Top to bottom, left to right"), N_("Top to bottom, right to left"),
+ N_("Bottom to top, left to right"), N_("Bottom to top, right to left") };
+ int i;
+
+ priv->number_up_layout_n_option = gtk_printer_option_new ("gtk-n-up-layout",
+ _("Page Ordering"),
+ GTK_PRINTER_OPTION_TYPE_PICKONE);
+ gtk_printer_option_allocate_choices (priv->number_up_layout_n_option, 8);
+
+ for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
+ {
+ priv->number_up_layout_n_option->choices[i] = g_strdup (n_up_layout[i]);
+ priv->number_up_layout_n_option->choices_display[i] = g_strdup (_(n_up_layout_display[i]));
+ }
+ }
+ g_object_ref (priv->number_up_layout_n_option);
+
+ priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
+ _("Page Ordering"),
+ GTK_PRINTER_OPTION_TYPE_PICKONE);
+ gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
+ }
+
+ page_orientation = gtk_page_setup_get_orientation (priv->page_setup);
+ if (page_orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
+ page_orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
+ {
+ if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
+ priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[2]))
+ {
+ g_free (priv->number_up_layout_2_option->choices_display[0]);
+ g_free (priv->number_up_layout_2_option->choices_display[1]);
+ priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
+ priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
+ priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
+ priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
+ }
+ }
+ else
+ {
+ if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
+ priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[1]))
+ {
+ g_free (priv->number_up_layout_2_option->choices_display[0]);
+ g_free (priv->number_up_layout_2_option->choices_display[1]);
+ priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
+ priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[1];
+ priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Top to bottom"));
+ priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Bottom to top"));
+ }
+ }
+
+ layout = dialog_get_number_up_layout (dialog);
+
+ old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
+ if (old_option != NULL)
+ gtk_printer_option_set_remove (set, old_option);
+
+ if (dialog_get_pages_per_sheet (dialog) != 1)
+ {
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+ enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
+
+ if (dialog_get_pages_per_sheet (dialog) == 2)
+ {
+ option = priv->number_up_layout_2_option;
+
+ switch (layout)
+ {
+ case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
+ case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
+ enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
+ break;
+
+ case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
+ case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
+ enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP);
+ break;
+
+ case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
+ case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
+ enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM);
+ break;
+
+ case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
+ case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
+ enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP);
+ break;
+
+ default:
+ g_assert_not_reached();
+ enum_value = NULL;
+ }
+ }
+ else
+ {
+ option = priv->number_up_layout_n_option;
+
+ enum_value = g_enum_get_value (enum_class, layout);
+ }
+
+ g_assert (enum_value != NULL);
+ gtk_printer_option_set (option, enum_value->value_nick);
+ g_type_class_unref (enum_class);
+
+ gtk_printer_option_set_add (set, option);
+ }
+ }
+
+ setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
+
+ if (priv->number_up_layout != NULL)
+ gtk_widget_set_sensitive (GTK_WIDGET (priv->number_up_layout),
+ (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT) &&
+ (dialog_get_pages_per_sheet (dialog) > 1));
+}
+
+static void
+custom_paper_dialog_response_cb (GtkDialog *custom_paper_dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ GtkPrintUnixDialog *print_dialog = GTK_PRINT_UNIX_DIALOG (user_data);
+ GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ _gtk_print_load_custom_papers (priv->custom_paper_list);
+
+ priv->internal_page_setup_change = TRUE;
+ update_paper_sizes (print_dialog);
+ priv->internal_page_setup_change = FALSE;
+
+ if (priv->page_setup_set)
+ {
+ model = GTK_TREE_MODEL (priv->custom_paper_list);
+ if (gtk_tree_model_get_iter_first (model, &iter))
+ {
+ do
+ {
+ GtkPageSetup *page_setup;
+ gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
+
+ if (page_setup &&
+ g_strcmp0 (gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size (page_setup)),
+ gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size (priv->page_setup))) == 0)
+ gtk_print_unix_dialog_set_page_setup (print_dialog, page_setup);
+
+ g_object_unref (page_setup);
+ } while (gtk_tree_model_iter_next (model, &iter));
+ }
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (custom_paper_dialog));
+}
+
+static void
+orientation_changed (GtkComboBox *combo_box,
+ GtkPrintUnixDialog *dialog)
+{
+ GtkPrintUnixDialogPrivate *priv = dialog->priv;
+ GtkPageOrientation orientation;
+ GtkPageSetup *page_setup;
+
+ if (priv->internal_page_setup_change)
+ return;
+
+ orientation = (GtkPageOrientation) gtk_combo_box_get_active (GTK_COMBO_BOX (priv->orientation_combo));
+
+ if (priv->page_setup)
+ {
+ page_setup = gtk_page_setup_copy (priv->page_setup);
+ if (page_setup)
+ gtk_page_setup_set_orientation (page_setup, orientation);
+
+ gtk_print_unix_dialog_set_page_setup (dialog, page_setup);
+ }
+
+ redraw_page_layout_preview (dialog);
+}
+
+static void
+paper_size_changed (GtkComboBox *combo_box,
+ GtkPrintUnixDialog *dialog)
+{
+ GtkPrintUnixDialogPrivate *priv = dialog->priv;
+ GtkTreeIter iter;
+ GtkPageSetup *page_setup, *last_page_setup;
+ GtkPageOrientation orientation;
+
+ if (priv->internal_page_setup_change)
+ return;
+
+ if (gtk_combo_box_get_active_iter (combo_box, &iter))
+ {
+ gtk_tree_model_get (gtk_combo_box_get_model (combo_box),
+ &iter, PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup, -1);
+
+ if (page_setup == NULL)
+ {
+ GtkWidget *custom_paper_dialog;
+
+ /* Change from "manage" menu item to last value */
+ if (priv->page_setup)
+ last_page_setup = g_object_ref (priv->page_setup);
+ else
+ last_page_setup = gtk_page_setup_new (); /* "good" default */
+
+ if (!set_paper_size (dialog, last_page_setup, FALSE, FALSE))
+ set_paper_size (dialog, last_page_setup, TRUE, TRUE);
+ g_object_unref (last_page_setup);
+
+ /* And show the custom paper dialog */
+ custom_paper_dialog = _gtk_custom_paper_unix_dialog_new (GTK_WINDOW (dialog), _("Manage Custom Sizes"));
+ g_signal_connect (custom_paper_dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), dialog);
+ gtk_window_present (GTK_WINDOW (custom_paper_dialog));
+
+ return;
+ }
+
+ if (priv->page_setup)
+ orientation = gtk_page_setup_get_orientation (priv->page_setup);
+ else
+ orientation = GTK_PAGE_ORIENTATION_PORTRAIT;
+
+ gtk_page_setup_set_orientation (page_setup, orientation);
+ gtk_print_unix_dialog_set_page_setup (dialog, page_setup);
+
+ g_object_unref (page_setup);
+ }
+
+ redraw_page_layout_preview (dialog);
+}
+
+static gboolean
+paper_size_row_is_separator (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ gboolean separator;
+
+ gtk_tree_model_get (model, iter, PAGE_SETUP_LIST_COL_IS_SEPARATOR, &separator, -1);
+ return separator;
+}
+
+static void
+page_name_func (GtkCellLayout *cell_layout,
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GtkPageSetup *page_setup;
+ GtkPaperSize *paper_size;
+
+ gtk_tree_model_get (tree_model, iter,
+ PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup, -1);
+ if (page_setup)
+ {
+ paper_size = gtk_page_setup_get_paper_size (page_setup);
+ g_object_set (cell, "text", gtk_paper_size_get_display_name (paper_size), NULL);
+ g_object_unref (page_setup);
+ }
+ else
+ g_object_set (cell, "text", _("Manage Custom Sizes..."), NULL);
+}
+