summaryrefslogtreecommitdiff
path: root/gtk/gtkpagesetupunixdialog.c
diff options
context:
space:
mode:
authorMarek Kasik <mkasik@redhat.com>2009-07-10 11:28:31 +0200
committerMarek Kasik <mkasik@redhat.com>2009-07-10 11:28:31 +0200
commit0ef74c936f7a5b36a66ea828506b4b44e25a1998 (patch)
treecd3492286b53633ee7f9dd8fa692287e1119c950 /gtk/gtkpagesetupunixdialog.c
parent6ca5430a74c86b448e96b64166d67b3268e24789 (diff)
downloadgtk+-0ef74c936f7a5b36a66ea828506b4b44e25a1998.tar.gz
Add paper size combo and orientation combo to print dialog
Paper size combo and orientation combo can be added by gtk_print_operation_set_embed_page_setup_dialog() to GtkPrinUnixDialog now. This function induce calling of gtk_print_unix_dailog_set_embed_page_setup_dialog() after creation of dialog. These two functions control embed-page-setup-dialog properties in GtkPrintOperation and in GtkPrintUnixDialog. There is also new function gtk_print_unix_dialog_get_page_setup_set() which says whether page setup was set by user. Selected page setup is stored as default page setup in GtkPrintOperation. New class is added, its name is GtkCustomPaperUnixDialog. The class manages custom sizes. It is derived from GtkPageSetupUnixDialog's CustomPaperDialog structure. Page layout preview is modified, so, it shows dimensions of current page setup (mm or inch - depends on locale). It also shows the name of actual paper if page setup dialog is not embedded (paper size combo is not visible). gtk-demo is actualized to include this new feature.
Diffstat (limited to 'gtk/gtkpagesetupunixdialog.c')
-rw-r--r--gtk/gtkpagesetupunixdialog.c919
1 files changed, 25 insertions, 894 deletions
diff --git a/gtk/gtkpagesetupunixdialog.c b/gtk/gtkpagesetupunixdialog.c
index 8d9cbc787e..0fae189579 100644
--- a/gtk/gtkpagesetupunixdialog.c
+++ b/gtk/gtkpagesetupunixdialog.c
@@ -23,10 +23,6 @@
#include <string.h>
#include <locale.h>
-#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
-#include <langinfo.h>
-#endif
-
#include "gtkintl.h"
#include "gtkprivate.h"
@@ -54,14 +50,13 @@
#include "gtkhbbox.h"
#include "gtkpagesetupunixdialog.h"
+#include "gtkcustompaperunixdialog.h"
#include "gtkprintbackend.h"
#include "gtkprinter-private.h"
#include "gtkpapersize.h"
#include "gtkprintutils.h"
#include "gtkalias.h"
-#define CUSTOM_PAPER_FILENAME ".gtk-custom-papers"
-
struct GtkPageSetupUnixDialogPrivate
{
@@ -112,7 +107,6 @@ static void gtk_page_setup_unix_dialog_finalize (GObject *object
static void populate_dialog (GtkPageSetupUnixDialog *dialog);
static void fill_paper_sizes_from_printer (GtkPageSetupUnixDialog *dialog,
GtkPrinter *printer);
-static void show_custom_paper_dialog (GtkPageSetupUnixDialog *dialog);
static void printer_added_cb (GtkPrintBackend *backend,
GtkPrinter *printer,
GtkPageSetupUnixDialog *dialog);
@@ -140,140 +134,6 @@ static const gchar const common_paper_sizes[][16] = {
"iso_a3",
};
-static GtkUnit
-get_default_user_units (void)
-{
- /* Translate to the default units to use for presenting
- * lengths to the user. Translate to default:inch if you
- * want inches, otherwise translate to default:mm.
- * Do *not* translate it to "predefinito:mm", if it
- * it isn't default:mm or default:inch it will not work
- */
- gchar *e = _("default:mm");
-
-#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
- gchar *imperial = NULL;
-
- imperial = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
- if (imperial && imperial[0] == 2 )
- return GTK_UNIT_INCH; /* imperial */
- if (imperial && imperial[0] == 1 )
- return GTK_UNIT_MM; /* metric */
-#endif
-
- if (strcmp (e, "default:inch")==0)
- return GTK_UNIT_INCH;
- else if (strcmp (e, "default:mm"))
- g_warning ("Whoever translated default:mm did so wrongly.\n");
- return GTK_UNIT_MM;
-}
-
-static char *
-custom_paper_get_filename (void)
-{
- gchar *filename;
-
- filename = g_build_filename (g_get_home_dir (),
- CUSTOM_PAPER_FILENAME, NULL);
- g_assert (filename != NULL);
- return filename;
-}
-
-GList *
-_gtk_load_custom_papers (void)
-{
- GKeyFile *keyfile;
- gchar *filename;
- gchar **groups;
- gsize n_groups, i;
- gboolean load_ok;
- GList *result = NULL;
-
- filename = custom_paper_get_filename ();
-
- keyfile = g_key_file_new ();
- load_ok = g_key_file_load_from_file (keyfile, filename, 0, NULL);
- g_free (filename);
- if (!load_ok)
- {
- g_key_file_free (keyfile);
- return NULL;
- }
-
- groups = g_key_file_get_groups (keyfile, &n_groups);
- for (i = 0; i < n_groups; ++i)
- {
- GtkPageSetup *page_setup;
-
- page_setup = gtk_page_setup_new_from_key_file (keyfile, groups[i], NULL);
- if (!page_setup)
- continue;
-
- result = g_list_prepend (result, page_setup);
- }
-
- g_strfreev (groups);
- g_key_file_free (keyfile);
-
- return g_list_reverse (result);
-}
-
-static void
-load_custom_papers (GtkListStore *store)
-{
- GtkTreeIter iter;
- GList *papers, *p;
- GtkPageSetup *page_setup;
-
- papers = _gtk_load_custom_papers ();
- for (p = papers; p; p = p->next)
- {
- page_setup = p->data;
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- 0, page_setup,
- -1);
- g_object_unref (page_setup);
- }
-
- g_list_free (papers);
-}
-
-static void
-save_custom_papers (GtkListStore *store)
-{
- GtkTreeModel *model = GTK_TREE_MODEL (store);
- GtkTreeIter iter;
- GKeyFile *keyfile;
- gchar *filename, *data;
- gsize len;
- gint i = 0;
-
- keyfile = g_key_file_new ();
-
- if (gtk_tree_model_get_iter_first (model, &iter))
- {
- do
- {
- GtkPageSetup *page_setup;
- gchar group[32];
-
- g_snprintf (group, sizeof (group), "Paper%u", i);
-
- gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
-
- gtk_page_setup_to_key_file (page_setup, keyfile, group);
-
- ++i;
- } while (gtk_tree_model_iter_next (model, &iter));
- }
-
- filename = custom_paper_get_filename ();
- data = g_key_file_to_data (keyfile, &len, NULL);
- g_file_set_contents (filename, data, len, NULL);
- g_free (data);
- g_free (filename);
-}
static void
gtk_page_setup_unix_dialog_class_init (GtkPageSetupUnixDialogClass *class)
@@ -314,7 +174,7 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
G_TYPE_BOOLEAN);
priv->custom_paper_list = gtk_list_store_new (1, G_TYPE_OBJECT);
- load_custom_papers (priv->custom_paper_list);
+ _gtk_print_load_custom_papers (priv->custom_paper_list);
populate_dialog (dialog);
@@ -847,6 +707,23 @@ double_to_string (gdouble d,
return val;
}
+
+static void
+custom_paper_dialog_response_cb (GtkDialog *custom_paper_dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ GtkPageSetupUnixDialog *page_setup_dialog = GTK_PAGE_SETUP_UNIX_DIALOG (user_data);
+ GtkPageSetupUnixDialogPrivate *priv = page_setup_dialog->priv;
+
+ _gtk_print_load_custom_papers (priv->custom_paper_list);
+
+ /* Update printer page list */
+ printer_changed_callback (GTK_COMBO_BOX (priv->printer_combo), page_setup_dialog);
+
+ gtk_widget_destroy (GTK_WIDGET (custom_paper_dialog));
+}
+
static void
paper_size_changed (GtkComboBox *combo_box,
GtkPageSetupUnixDialog *dialog)
@@ -869,6 +746,8 @@ paper_size_changed (GtkComboBox *combo_box,
if (page_setup == NULL)
{
+ GtkWidget *custom_paper_dialog;
+
/* Change from "manage" menu item to last value */
if (priv->last_setup)
last_page_setup = g_object_ref (priv->last_setup);
@@ -878,7 +757,9 @@ paper_size_changed (GtkComboBox *combo_box,
g_object_unref (last_page_setup);
/* And show the custom paper dialog */
- show_custom_paper_dialog (dialog);
+ custom_paper_dialog = _gtk_custom_paper_unix_dialog_new (GTK_WINDOW (dialog), NULL);
+ g_signal_connect (custom_paper_dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), dialog);
+ gtk_window_present (GTK_WINDOW (custom_paper_dialog));
return;
}
@@ -888,7 +769,7 @@ paper_size_changed (GtkComboBox *combo_box,
priv->last_setup = g_object_ref (page_setup);
- unit = get_default_user_units ();
+ unit = _gtk_print_get_default_user_units ();
if (unit == GTK_UNIT_MM)
unit_str = _("mm");
@@ -1311,755 +1192,5 @@ gtk_page_setup_unix_dialog_get_print_settings (GtkPageSetupUnixDialog *dialog)
return priv->print_settings;
}
-static GtkWidget *
-wrap_in_frame (const gchar *label,
- GtkWidget *child)
-{
- GtkWidget *frame, *alignment, *label_widget;
- gchar *bold_text;
-
- label_widget = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
- gtk_widget_show (label_widget);
-
- bold_text = g_markup_printf_escaped ("<b>%s</b>", label);
- gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
- g_free (bold_text);
-
- frame = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (frame), label_widget, FALSE, FALSE, 0);
-
- alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
- 0, 0, 12, 0);
- gtk_box_pack_start (GTK_BOX (frame), alignment, FALSE, FALSE, 0);
-
- gtk_container_add (GTK_CONTAINER (alignment), child);
-
- gtk_widget_show (frame);
- gtk_widget_show (alignment);
-
- return frame;
-}
-
-typedef struct
-{
- GtkUnit display_unit;
- GtkWidget *spin_button;
-} UnitWidget;
-
-typedef struct
-{
- GtkPageSetupUnixDialog *dialog;
- GtkWidget *treeview;
- GtkTreeViewColumn *text_column;
- GtkWidget *values_box;
- GtkWidget *printer_combo;
- GtkWidget *width_widget;
- GtkWidget *height_widget;
- GtkWidget *top_widget;
- GtkWidget *bottom_widget;
- GtkWidget *left_widget;
- GtkWidget *right_widget;
- gulong printer_inserted_tag;
- gulong printer_removed_tag;
- guint request_details_tag;
- GtkPrinter *request_details_printer;
- guint non_user_change : 1;
-} CustomPaperDialog;
-
-static void unit_widget_changed (CustomPaperDialog *data);
-
-static GtkWidget *
-new_unit_widget (CustomPaperDialog *dialog,
- GtkUnit unit,
- GtkWidget *mnemonic_label)
-{
- GtkWidget *hbox, *button, *label;
- UnitWidget *data;
-
- data = g_new0 (UnitWidget, 1);
- data->display_unit = unit;
-
- hbox = gtk_hbox_new (FALSE, 6);
-
- button = gtk_spin_button_new_with_range (0.0, 9999.0, 1);
- if (unit == GTK_UNIT_INCH)
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (button), 2);
- else
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (button), 1);
-
- gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
- gtk_widget_show (button);
-
- data->spin_button = button;
-
- g_signal_connect_swapped (button, "value-changed",
- G_CALLBACK (unit_widget_changed), dialog);
-
- if (unit == GTK_UNIT_INCH)
- label = gtk_label_new (_("inch"));
- else
- label = gtk_label_new (_("mm"));
-
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_widget_show (label);
- gtk_label_set_mnemonic_widget (GTK_LABEL (mnemonic_label), button);
-
- g_object_set_data_full (G_OBJECT (hbox), "unit-data", data, g_free);
-
- return hbox;
-}
-
-static double
-unit_widget_get (GtkWidget *unit_widget)
-{
- UnitWidget *data = g_object_get_data (G_OBJECT (unit_widget), "unit-data");
- return _gtk_print_convert_to_mm (gtk_spin_button_get_value (GTK_SPIN_BUTTON (data->spin_button)),
- data->display_unit);
-}
-
-static void
-unit_widget_set (GtkWidget *unit_widget,
- gdouble value)
-{
- UnitWidget *data;
-
- data = g_object_get_data (G_OBJECT (unit_widget), "unit-data");
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (data->spin_button),
- _gtk_print_convert_from_mm (value, data->display_unit));
-}
-
-static void
-custom_paper_printer_data_func (GtkCellLayout *cell_layout,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer data)
-{
- GtkPrinter *printer;
-
- gtk_tree_model_get (tree_model, iter,
- PRINTER_LIST_COL_PRINTER, &printer, -1);
-
- if (printer)
- g_object_set (cell, "text", gtk_printer_get_name (printer), NULL);
- else
- g_object_set (cell, "text", _("Margins from Printer..."), NULL);
-
- if (printer)
- g_object_unref (printer);
-}
-
-static void
-update_combo_sensitivity_from_printers (CustomPaperDialog *data)
-{
- GtkTreeIter iter;
- gboolean sensitive;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
-
- sensitive = FALSE;
- model = GTK_TREE_MODEL (data->dialog->priv->printer_list);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview));
- if (gtk_tree_model_get_iter_first (model, &iter) &&
- gtk_tree_model_iter_next (model, &iter) &&
- gtk_tree_selection_get_selected (selection, NULL, &iter))
- sensitive = TRUE;
-
- gtk_widget_set_sensitive (data->printer_combo, sensitive);
-}
-
-static void
-update_custom_widgets_from_list (CustomPaperDialog *data)
-{
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkPageSetup *page_setup;
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (data->treeview));
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview));
-
- data->non_user_change = TRUE;
- if (gtk_tree_selection_get_selected (selection, NULL, &iter))
- {
- gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
-
- unit_widget_set (data->width_widget,
- gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM));
- unit_widget_set (data->height_widget,
- gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM));
- unit_widget_set (data->top_widget,
- gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
- unit_widget_set (data->bottom_widget,
- gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
- unit_widget_set (data->left_widget,
- gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
- unit_widget_set (data->right_widget,
- gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
-
- gtk_widget_set_sensitive (data->values_box, TRUE);
- }
- else
- {
- gtk_widget_set_sensitive (data->values_box, FALSE);
- }
-
- update_combo_sensitivity_from_printers (data);
- data->non_user_change = FALSE;
-}
-
-static void
-selected_custom_paper_changed (GtkTreeSelection *selection,
- CustomPaperDialog *data)
-{
- update_custom_widgets_from_list (data);
-}
-
-static void
-unit_widget_changed (CustomPaperDialog *data)
-{
- gdouble w, h, top, bottom, left, right;
- GtkTreeSelection *selection;
- GtkTreeIter iter;
- GtkPageSetup *page_setup;
- GtkPaperSize *paper_size;
-
- if (data->non_user_change)
- return;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview));
-
- if (gtk_tree_selection_get_selected (selection, NULL, &iter))
- {
- gtk_tree_model_get (GTK_TREE_MODEL (data->dialog->priv->custom_paper_list), &iter, 0, &page_setup, -1);
-
- w = unit_widget_get (data->width_widget);
- h = unit_widget_get (data->height_widget);
-
- paper_size = gtk_page_setup_get_paper_size (page_setup);
- gtk_paper_size_set_size (paper_size, w, h, GTK_UNIT_MM);
-
- top = unit_widget_get (data->top_widget);
- bottom = unit_widget_get (data->bottom_widget);
- left = unit_widget_get (data->left_widget);
- right = unit_widget_get (data->right_widget);
-
- gtk_page_setup_set_top_margin (page_setup, top, GTK_UNIT_MM);
- gtk_page_setup_set_bottom_margin (page_setup, bottom, GTK_UNIT_MM);
- gtk_page_setup_set_left_margin (page_setup, left, GTK_UNIT_MM);
- gtk_page_setup_set_right_margin (page_setup, right, GTK_UNIT_MM);
-
- g_object_unref (page_setup);
- }
-}
-
-static gboolean
-custom_paper_name_used (CustomPaperDialog *data,
- const gchar *name)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkPageSetup *page_setup;
- GtkPaperSize *paper_size;
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (data->treeview));
-
- if (gtk_tree_model_get_iter_first (model, &iter))
- {
- do
- {
- gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
- paper_size = gtk_page_setup_get_paper_size (page_setup);
- if (strcmp (name,
- gtk_paper_size_get_name (paper_size)) == 0)
- {
- g_object_unref (page_setup);
- return TRUE;
- }
- g_object_unref (page_setup);
- } while (gtk_tree_model_iter_next (model, &iter));
- }
-
- return FALSE;
-}
-
-static void
-add_custom_paper (CustomPaperDialog *data)
-{
- GtkListStore *store;
- GtkPageSetup *page_setup;
- GtkPaperSize *paper_size;
- GtkTreeSelection *selection;
- GtkTreePath *path;
- GtkTreeIter iter;
- gchar *name;
- gint i;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview));
- store = data->dialog->priv->custom_paper_list;
-
- i = 1;
- name = NULL;
- do
- {
- g_free (name);
- name = g_strdup_printf (_("Custom Size %d"), i);
- i++;
- } while (custom_paper_name_used (data, name));
-
- page_setup = gtk_page_setup_new ();
- paper_size = gtk_paper_size_new_custom (name, name,
- gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM),
- gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM),
- GTK_UNIT_MM);
- gtk_page_setup_set_paper_size (page_setup, paper_size);
- gtk_paper_size_free (paper_size);
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, page_setup, -1);
- g_object_unref (page_setup);
-
- gtk_tree_selection_select_iter (selection, &iter);
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
- gtk_widget_grab_focus (data->treeview);
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (data->treeview), path,
- data->text_column, TRUE);
- gtk_tree_path_free (path);
- g_free (name);
-}
-
-static void
-remove_custom_paper (CustomPaperDialog *data)
-{
- GtkTreeSelection *selection;
- GtkTreeIter iter;
- GtkListStore *store;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview));
- store = data->dialog->priv->custom_paper_list;
-
- if (gtk_tree_selection_get_selected (selection, NULL, &iter))
- {
- GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
- gtk_list_store_remove (store, &iter);
-
- if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
- gtk_tree_selection_select_iter (selection, &iter);
- else if (gtk_tree_path_prev (path) && gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
- gtk_tree_selection_select_iter (selection, &iter);
-
- gtk_tree_path_free (path);
- }
-}
-
-static void
-set_margins_from_printer (CustomPaperDialog *data,
- GtkPrinter *printer)
-{
- gdouble top, bottom, left, right;
-
- top = bottom = left = right = 0;
- _gtk_printer_get_hard_margins (printer, &top, &bottom, &left, &right);
-
- data->non_user_change = TRUE;
- unit_widget_set (data->top_widget, _gtk_print_convert_to_mm (top, GTK_UNIT_POINTS));
- unit_widget_set (data->bottom_widget, _gtk_print_convert_to_mm (bottom, GTK_UNIT_POINTS));
- unit_widget_set (data->left_widget, _gtk_print_convert_to_mm (left, GTK_UNIT_POINTS));
- unit_widget_set (data->right_widget, _gtk_print_convert_to_mm (right, GTK_UNIT_POINTS));
- data->non_user_change = FALSE;
-
- /* Only send one change */
- unit_widget_changed (data);
-}
-
-static void
-get_margins_finished_callback (GtkPrinter *printer,
- gboolean success,
- CustomPaperDialog *data)
-{
- g_signal_handler_disconnect (data->request_details_printer,
- data->request_details_tag);
- g_object_unref (data->request_details_printer);
- data->request_details_tag = 0;
- data->request_details_printer = NULL;
-
- if (success)
- set_margins_from_printer (data, printer);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (data->printer_combo), 0);
-}
-
-static void
-margins_from_printer_changed (CustomPaperDialog *data)
-{
- GtkTreeIter iter;
- GtkComboBox *combo;
- GtkPrinter *printer;
-
- combo = GTK_COMBO_BOX (data->printer_combo);
-
- if (data->request_details_tag)
- {
- g_signal_handler_disconnect (data->request_details_printer,
- data->request_details_tag);
- g_object_unref (data->request_details_printer);
- data->request_details_printer = NULL;
- data->request_details_tag = 0;
- }
-
- if (gtk_combo_box_get_active_iter (combo, &iter))
- {
- gtk_tree_model_get (gtk_combo_box_get_model (combo), &iter,
- PRINTER_LIST_COL_PRINTER, &printer, -1);
-
- if (printer)
- {
- if (gtk_printer_has_details (printer))
- {
- set_margins_from_printer (data, printer);
- gtk_combo_box_set_active (combo, 0);
- }
- else
- {
- data->request_details_printer = g_object_ref (printer);
- data->request_details_tag =
- g_signal_connect (printer, "details-acquired",
- G_CALLBACK (get_margins_finished_callback), data);
- gtk_printer_request_details (printer);
- }
-
- g_object_unref (printer);
- }
- }
-}
-
-
-static void
-custom_paper_dialog_free (gpointer p)
-{
- CustomPaperDialog *data = p;
- GtkPageSetupUnixDialogPrivate *priv = data->dialog->priv;
-
- g_signal_handler_disconnect (priv->printer_list, data->printer_inserted_tag);
- g_signal_handler_disconnect (priv->printer_list, data->printer_removed_tag);
-
- if (data->request_details_tag)
- {
- g_signal_handler_disconnect (data->request_details_printer,
- data->request_details_tag);
- g_object_unref (data->request_details_printer);
- data->request_details_printer = NULL;
- data->request_details_tag = 0;
- }
-
- g_free (data);
-}
-
-static void
-custom_size_name_edited (GtkCellRenderer *cell,
- gchar *path_string,
- gchar *new_text,
- CustomPaperDialog *data)
-{
- GtkTreePath *path;
- GtkTreeIter iter;
- GtkListStore *store;
- GtkPageSetup *page_setup;
- GtkPaperSize *paper_size;
-
- store = data->dialog->priv->custom_paper_list;
- path = gtk_tree_path_new_from_string (path_string);
- gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path);
- gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, 0, &page_setup, -1);
- gtk_tree_path_free (path);
-
- paper_size = gtk_paper_size_new_custom (new_text, new_text,
- gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM),
- gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM),
- GTK_UNIT_MM);
- gtk_page_setup_set_paper_size (page_setup, paper_size);
- gtk_paper_size_free (paper_size);
-
- g_object_unref (page_setup);
-}
-
-static void
-custom_name_func (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer data)
-{
- GtkPageSetup *page_setup;
- GtkPaperSize *paper_size;
-
- gtk_tree_model_get (tree_model, iter, 0, &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);
- }
-}
-
-static void
-custom_paper_dialog_response_cb (GtkWidget *custom_dialog,
- gint response,
- CustomPaperDialog *data)
-{
- GtkPageSetupUnixDialog *dialog = data->dialog;
- GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
-
- save_custom_papers (priv->custom_paper_list);
-
- /* Update printer page list */
- printer_changed_callback (GTK_COMBO_BOX (priv->printer_combo), dialog);
-
- gtk_widget_destroy (custom_dialog);
-}
-
-static void
-show_custom_paper_dialog (GtkPageSetupUnixDialog *ps_dialog)
-{
- GtkPageSetupUnixDialogPrivate *priv = ps_dialog->priv;
- GtkWidget *custom_dialog, *image, *table, *label, *widget, *frame, *combo;
- GtkWidget *hbox, *vbox, *treeview, *scrolled, *button_box, *button;
- GtkDialog *dialog;
- GtkCellRenderer *cell;
- GtkTreeViewColumn *column;
- GtkTreeIter iter;
- GtkTreeSelection *selection;
- CustomPaperDialog *data;
- GtkUnit user_units;
-
- custom_dialog = gtk_dialog_new_with_buttons (_("Manage Custom Sizes"),
- GTK_WINDOW (ps_dialog),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
- NULL);
-
- dialog = GTK_DIALOG (custom_dialog);
-
- data = g_new0 (CustomPaperDialog, 1);
- data->dialog = ps_dialog;
- g_object_set_data_full (G_OBJECT (custom_dialog), "custom-dialog", data,
- custom_paper_dialog_free);
- g_signal_connect (dialog, "response",
- G_CALLBACK (custom_paper_dialog_response_cb), data);
-
- gtk_dialog_set_has_separator (dialog, FALSE);
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
- gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
- gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
-
- hbox = gtk_hbox_new (FALSE, 18);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
- gtk_box_pack_start (GTK_BOX (dialog->vbox), hbox, TRUE, TRUE, 0);
- gtk_widget_show (hbox);
-
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
- gtk_widget_show (vbox);
-
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
- GTK_SHADOW_IN);
- gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
- gtk_widget_show (scrolled);
-
- treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->custom_paper_list));
- data->treeview = treeview;
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
- gtk_widget_set_size_request (treeview, 140, -1);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
- g_signal_connect (selection, "changed", G_CALLBACK (selected_custom_paper_changed), data);
-
- cell = gtk_cell_renderer_text_new ();
- g_object_set (cell, "editable", TRUE, NULL);
- g_signal_connect (cell, "edited",
- G_CALLBACK (custom_size_name_edited), data);
- data->text_column = column =
- gtk_tree_view_column_new_with_attributes ("paper", cell,
- NULL);
- gtk_tree_view_column_set_cell_data_func (column, cell, custom_name_func, NULL, NULL);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
-
- gtk_container_add (GTK_CONTAINER (scrolled), treeview);
- gtk_widget_show (treeview);
-
- button_box = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), button_box, FALSE, FALSE, 0);
- gtk_widget_show (button_box);
-
- button = gtk_button_new ();
- image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
- gtk_widget_show (image);
- gtk_container_add (GTK_CONTAINER (button), image);
- gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 0);
- gtk_widget_show (button);
-
- g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_custom_paper), data);
-
- button = gtk_button_new ();
- image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON);
- gtk_widget_show (image);
- gtk_container_add (GTK_CONTAINER (button), image);
- gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 0);
- gtk_widget_show (button);
-
- g_signal_connect_swapped (button, "clicked", G_CALLBACK (remove_custom_paper), data);
-
- user_units = get_default_user_units ();
-
- vbox = gtk_vbox_new (FALSE, 18);
- data->values_box = vbox;
- gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
- gtk_widget_show (vbox);
-
- table = gtk_table_new (2, 2, FALSE);
-
- gtk_table_set_row_spacings (GTK_TABLE (table), 6);
- gtk_table_set_col_spacings (GTK_TABLE (table), 12);
-
- label = gtk_label_new_with_mnemonic (_("_Width:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_widget_show (label);
- gtk_table_attach (GTK_TABLE (table), label,
- 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
-
- widget = new_unit_widget (data, user_units, label);
- data->width_widget = widget;
- gtk_table_attach (GTK_TABLE (table), widget,
- 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
- gtk_widget_show (widget);
-
- label = gtk_label_new_with_mnemonic (_("_Height:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_widget_show (label);
- gtk_table_attach (GTK_TABLE (table), label,
- 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
-
- widget = new_unit_widget (data, user_units, label);
- data->height_widget = widget;
- gtk_table_attach (GTK_TABLE (table), widget,
- 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
- gtk_widget_show (widget);
-
- frame = wrap_in_frame (_("Paper Size"), table);
- gtk_widget_show (table);
- gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
- gtk_widget_show (frame);
-
-
- table = gtk_table_new (5, 2, FALSE);
- gtk_table_set_row_spacings (GTK_TABLE (table), 6);
- gtk_table_set_col_spacings (GTK_TABLE (table), 12);
-
- label = gtk_label_new_with_mnemonic (_("_Top:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label,
- 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
- gtk_widget_show (label);
-
- widget = new_unit_widget (data, user_units, label);
- data->top_widget = widget;
- gtk_table_attach (GTK_TABLE (table), widget,
- 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
- gtk_widget_show (widget);
-
- label = gtk_label_new_with_mnemonic (_("_Bottom:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label,
- 0, 1 , 1, 2, GTK_FILL, 0, 0, 0);
- gtk_widget_show (label);
-
- widget = new_unit_widget (data, user_units, label);
- data->bottom_widget = widget;
- gtk_table_attach (GTK_TABLE (table), widget,
- 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
- gtk_widget_show (widget);
-
- label = gtk_label_new_with_mnemonic (_("_Left:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label,
- 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
- gtk_widget_show (label);
-
- widget = new_unit_widget (data, user_units, label);
- data->left_widget = widget;
- gtk_table_attach (GTK_TABLE (table), widget,
- 1, 2, 2, 3, GTK_FILL, 0, 0, 0);
- gtk_widget_show (widget);
-
- label = gtk_label_new_with_mnemonic (_("_Right:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label,
- 0, 1, 3, 4, GTK_FILL, 0, 0, 0);
- gtk_widget_show (label);
-
- widget = new_unit_widget (data, user_units, label);
- data->right_widget = widget;
- gtk_table_attach (GTK_TABLE (table), widget,
- 1, 2, 3, 4, GTK_FILL, 0, 0, 0);
- gtk_widget_show (widget);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_table_attach (GTK_TABLE (table), hbox,
- 0, 2, 4, 5, GTK_FILL | GTK_EXPAND, 0, 0, 0);
- gtk_widget_show (hbox);
-
- combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->printer_list));
- data->printer_combo = combo;
-
- data->printer_inserted_tag =
- g_signal_connect_swapped (priv->printer_list, "row-inserted",
- G_CALLBACK (update_combo_sensitivity_from_printers), data);
- data->printer_removed_tag =
- g_signal_connect_swapped (priv->printer_list, "row-deleted",
- G_CALLBACK (update_combo_sensitivity_from_printers), data);
- update_combo_sensitivity_from_printers (data);
-
- cell = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
- gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), cell,
- custom_paper_printer_data_func,
- NULL, NULL);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
- gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
- gtk_widget_show (combo);
-
- g_signal_connect_swapped (combo, "changed",
- G_CALLBACK (margins_from_printer_changed), data);
-
- frame = wrap_in_frame (_("Paper Margins"), table);
- gtk_widget_show (table);
- gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
- gtk_widget_show (frame);
-
- update_custom_widgets_from_list (data);
-
- /* If no custom sizes, add one */
- if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->custom_paper_list),
- &iter))
- {
- /* Need to realize treeview so we can start the rename */
- gtk_widget_realize (treeview);
- add_custom_paper (data);
- }
-
- gtk_window_present (GTK_WINDOW (dialog));
-}
-
-
#define __GTK_PAGE_SETUP_UNIX_DIALOG_C__
#include "gtkaliasdef.c"