2011-08-28 04:35:51 +00:00
|
|
|
|
/* GtkPageSetupUnixDialog
|
2006-04-21 15:09:32 +00:00
|
|
|
|
* Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
|
2008-01-06 23:09:24 +00:00
|
|
|
|
* Copyright © 2006, 2007, 2008 Christian Persch
|
2006-04-21 15:09:32 +00:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-08-28 04:35:51 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-04-21 15:09:32 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-04-21 15:09:32 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <locale.h>
|
2006-05-10 12:21:01 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
|
|
|
|
|
#include "gtkbutton.h"
|
|
|
|
|
#include "gtkscrolledwindow.h"
|
2020-08-30 23:36:27 +00:00
|
|
|
|
#include "gtkcheckbutton.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
#include "gtklabel.h"
|
2011-08-28 04:35:51 +00:00
|
|
|
|
#include "gtkgrid.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
|
|
|
|
|
|
#include "gtkpagesetupunixdialog.h"
|
2009-07-10 09:28:31 +00:00
|
|
|
|
#include "gtkcustompaperunixdialog.h"
|
2019-05-26 21:57:23 +00:00
|
|
|
|
#include "gtkprintbackendprivate.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
#include "gtkpapersize.h"
|
2006-04-23 05:48:04 +00:00
|
|
|
|
#include "gtkprintutils.h"
|
2013-12-08 14:54:17 +00:00
|
|
|
|
#include "gtkdialogprivate.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2010-05-12 23:25:02 +00:00
|
|
|
|
/**
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* GtkPageSetupUnixDialog:
|
2010-05-12 23:25:02 +00:00
|
|
|
|
*
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* `GtkPageSetupUnixDialog` implements a page setup dialog for platforms
|
|
|
|
|
* which don’t provide a native page setup dialog, like Unix.
|
|
|
|
|
*
|
2021-02-27 23:21:52 +00:00
|
|
|
|
* ![An example GtkPageSetupUnixDialog](pagesetupdialog.png)
|
|
|
|
|
*
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* It can be used very much like any other GTK dialog, at the
|
|
|
|
|
* cost of the portability offered by the high-level printing
|
|
|
|
|
* API in [class@Gtk.PrintOperation].
|
2010-05-12 23:25:02 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2019-05-26 19:38:39 +00:00
|
|
|
|
typedef struct _GtkPageSetupUnixDialogClass GtkPageSetupUnixDialogClass;
|
|
|
|
|
|
|
|
|
|
struct _GtkPageSetupUnixDialog
|
|
|
|
|
{
|
|
|
|
|
GtkDialog parent_instance;
|
|
|
|
|
|
2020-06-16 01:57:39 +00:00
|
|
|
|
GListModel *printer_list;
|
2020-06-16 00:31:27 +00:00
|
|
|
|
GListStore *page_setup_list;
|
|
|
|
|
GListStore *custom_paper_list;
|
|
|
|
|
GListStore *manage_papers_list;
|
|
|
|
|
GListStore *paper_size_list;
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GList *print_backends;
|
|
|
|
|
|
|
|
|
|
GtkWidget *printer_combo;
|
|
|
|
|
GtkWidget *paper_size_combo;
|
|
|
|
|
GtkWidget *paper_size_label;
|
|
|
|
|
|
|
|
|
|
GtkWidget *portrait_radio;
|
2006-12-24 11:30:22 +00:00
|
|
|
|
GtkWidget *reverse_portrait_radio;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkWidget *landscape_radio;
|
|
|
|
|
GtkWidget *reverse_landscape_radio;
|
|
|
|
|
|
2010-10-08 00:37:23 +00:00
|
|
|
|
gulong request_details_tag;
|
2006-05-31 13:43:42 +00:00
|
|
|
|
GtkPrinter *request_details_printer;
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPrintSettings *print_settings;
|
|
|
|
|
|
2020-08-29 20:29:28 +00:00
|
|
|
|
gboolean internal_change;
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
/* Save last setup so we can re-set it after selecting manage custom sizes */
|
|
|
|
|
GtkPageSetup *last_setup;
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
struct _GtkPageSetupUnixDialogClass
|
|
|
|
|
{
|
|
|
|
|
GtkDialogClass parent_class;
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-26 19:43:41 +00:00
|
|
|
|
|
2013-03-26 15:02:25 +00:00
|
|
|
|
/* Keep these in line with GtkListStores defined in gtkpagesetupunixprintdialog.ui */
|
2006-04-21 15:09:32 +00:00
|
|
|
|
enum {
|
|
|
|
|
PRINTER_LIST_COL_NAME,
|
|
|
|
|
PRINTER_LIST_COL_PRINTER,
|
|
|
|
|
PRINTER_LIST_N_COLS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PAGE_SETUP_LIST_COL_PAGE_SETUP,
|
|
|
|
|
PAGE_SETUP_LIST_COL_IS_SEPARATOR,
|
|
|
|
|
PAGE_SETUP_LIST_N_COLS
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
G_DEFINE_TYPE (GtkPageSetupUnixDialog, gtk_page_setup_unix_dialog, GTK_TYPE_DIALOG)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
static void gtk_page_setup_unix_dialog_finalize (GObject *object);
|
|
|
|
|
static void fill_paper_sizes_from_printer (GtkPageSetupUnixDialog *dialog,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkPrinter *printer);
|
2020-06-16 01:57:39 +00:00
|
|
|
|
static void printer_changed_callback (GtkDropDown *combo_box,
|
|
|
|
|
GParamSpec *pspec,
|
2020-06-16 00:31:27 +00:00
|
|
|
|
GtkPageSetupUnixDialog *dialog);
|
|
|
|
|
static void paper_size_changed (GtkDropDown *combo_box,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GtkPageSetupUnixDialog *dialog);
|
2013-03-26 15:02:25 +00:00
|
|
|
|
static void load_print_backends (GtkPageSetupUnixDialog *dialog);
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static const char common_paper_sizes[][16] = {
|
2006-04-21 15:09:32 +00:00
|
|
|
|
"na_letter",
|
|
|
|
|
"na_legal",
|
|
|
|
|
"iso_a4",
|
|
|
|
|
"iso_a5",
|
|
|
|
|
"roc_16k",
|
|
|
|
|
"iso_b5",
|
|
|
|
|
"jis_b5",
|
|
|
|
|
"na_number-10",
|
|
|
|
|
"iso_dl",
|
|
|
|
|
"jpn_chou3",
|
|
|
|
|
"na_ledger",
|
2014-08-21 21:01:54 +00:00
|
|
|
|
"iso_a3"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_page_setup_unix_dialog_class_init (GtkPageSetupUnixDialogClass *class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class;
|
2013-03-26 15:02:25 +00:00
|
|
|
|
GtkWidgetClass *widget_class;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2013-03-26 15:02:25 +00:00
|
|
|
|
object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
widget_class = GTK_WIDGET_CLASS (class);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
object_class->finalize = gtk_page_setup_unix_dialog_finalize;
|
|
|
|
|
|
2013-03-26 15:02:25 +00:00
|
|
|
|
/* Bind class to template
|
|
|
|
|
*/
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class,
|
2020-06-16 00:31:27 +00:00
|
|
|
|
"/org/gtk/libgtk/ui/gtkpagesetupunixdialog.ui");
|
2013-03-26 15:02:25 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkPageSetupUnixDialog, printer_combo);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkPageSetupUnixDialog, paper_size_combo);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkPageSetupUnixDialog, paper_size_label);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkPageSetupUnixDialog, portrait_radio);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkPageSetupUnixDialog, reverse_portrait_radio);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkPageSetupUnixDialog, landscape_radio);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkPageSetupUnixDialog, reverse_landscape_radio);
|
2013-07-26 17:49:49 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, printer_changed_callback);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, paper_size_changed);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
static void
|
|
|
|
|
setup_paper_size_item (GtkSignalListItemFactory *factory,
|
|
|
|
|
GtkListItem *item)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
|
gtk_list_item_set_child (item, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bind_paper_size_list_item (GtkSignalListItemFactory *factory,
|
|
|
|
|
GtkListItem *item,
|
|
|
|
|
GtkPageSetupUnixDialog *self)
|
|
|
|
|
{
|
|
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
guint pos;
|
|
|
|
|
GListModel *papers;
|
|
|
|
|
GListModel *model;
|
|
|
|
|
gpointer first;
|
|
|
|
|
|
|
|
|
|
page_setup = gtk_list_item_get_item (item);
|
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
|
|
|
|
|
|
pos = gtk_list_item_get_position (item);
|
|
|
|
|
papers = gtk_drop_down_get_model (GTK_DROP_DOWN (self->paper_size_combo));
|
|
|
|
|
model = gtk_flatten_list_model_get_model_for_item (GTK_FLATTEN_LIST_MODEL (papers), pos);
|
|
|
|
|
if (model != G_LIST_MODEL (self->manage_papers_list))
|
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *paper_size = gtk_page_setup_get_paper_size (page_setup);
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (label), gtk_paper_size_get_display_name (paper_size));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (label), _("Manage Custom Sizes…"));
|
|
|
|
|
|
|
|
|
|
first = g_list_model_get_item (model, 0);
|
|
|
|
|
g_object_unref (first);
|
|
|
|
|
if (pos != 0 &&
|
|
|
|
|
page_setup == GTK_PAGE_SETUP (first))
|
|
|
|
|
gtk_widget_add_css_class (gtk_widget_get_parent (label), "separator");
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_remove_css_class (gtk_widget_get_parent (label), "separator");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bind_paper_size_item (GtkSignalListItemFactory *factory,
|
|
|
|
|
GtkListItem *item,
|
|
|
|
|
GtkPageSetupUnixDialog *self)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
|
|
bind_paper_size_list_item (factory, item, self);
|
|
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
|
gtk_widget_remove_css_class (label, "separator-before");
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 01:57:39 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
match_func (gpointer item, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
return !gtk_printer_is_virtual (GTK_PRINTER (item));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
setup_printer_item (GtkSignalListItemFactory *factory,
|
|
|
|
|
GtkListItem *item)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
|
gtk_list_item_set_child (item, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bind_printer_item (GtkSignalListItemFactory *factory,
|
|
|
|
|
GtkListItem *item,
|
|
|
|
|
GtkPageSetupUnixDialog *self)
|
|
|
|
|
{
|
|
|
|
|
GtkPrinter *printer;
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
const char *location;
|
|
|
|
|
const char *name;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
printer = gtk_list_item_get_item (item);
|
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
|
|
|
|
|
|
name = gtk_printer_get_name (printer);
|
|
|
|
|
location = gtk_printer_get_location (printer);
|
|
|
|
|
str = g_strdup_printf ("<b>%s</b>\n%s", name, location ? location : "");
|
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label), str);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
|
|
|
|
|
{
|
2020-06-16 00:31:27 +00:00
|
|
|
|
GtkListItemFactory *factory;
|
|
|
|
|
GListStore *store;
|
|
|
|
|
GListModel *paper_size_list;
|
2020-06-16 01:57:39 +00:00
|
|
|
|
GtkPrinter *printer;
|
|
|
|
|
GListStore *printer_list;
|
|
|
|
|
GListStore *printer_list_list;
|
|
|
|
|
GListModel *full_list;
|
|
|
|
|
GtkFilter *filter;
|
2020-06-16 00:31:27 +00:00
|
|
|
|
GtkPageSetup *page_setup;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-08-29 20:29:28 +00:00
|
|
|
|
dialog->internal_change = TRUE;
|
2020-06-15 20:33:11 +00:00
|
|
|
|
dialog->print_backends = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2013-03-26 15:02:25 +00:00
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (dialog));
|
2013-12-08 14:54:17 +00:00
|
|
|
|
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
|
|
|
|
|
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
|
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
|
_("_Apply"), GTK_RESPONSE_OK,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
dialog->page_setup_list = g_list_store_new (GTK_TYPE_PAGE_SETUP);
|
|
|
|
|
dialog->custom_paper_list = g_list_store_new (GTK_TYPE_PAGE_SETUP);
|
|
|
|
|
dialog->manage_papers_list = g_list_store_new (GTK_TYPE_PAGE_SETUP);
|
|
|
|
|
page_setup = gtk_page_setup_new ();
|
|
|
|
|
g_list_store_append (dialog->manage_papers_list, page_setup);
|
|
|
|
|
g_object_unref (page_setup);
|
|
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_paper_size_item), dialog);
|
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_paper_size_item), dialog);
|
|
|
|
|
gtk_drop_down_set_factory (GTK_DROP_DOWN (dialog->paper_size_combo), factory);
|
|
|
|
|
g_object_unref (factory);
|
|
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_paper_size_item), dialog);
|
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_paper_size_list_item), dialog);
|
|
|
|
|
gtk_drop_down_set_list_factory (GTK_DROP_DOWN (dialog->paper_size_combo), factory);
|
|
|
|
|
g_object_unref (factory);
|
|
|
|
|
|
|
|
|
|
store = g_list_store_new (G_TYPE_LIST_MODEL);
|
|
|
|
|
g_list_store_append (store, dialog->page_setup_list);
|
|
|
|
|
g_list_store_append (store, dialog->custom_paper_list);
|
|
|
|
|
g_list_store_append (store, dialog->manage_papers_list);
|
2020-07-04 19:47:48 +00:00
|
|
|
|
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
|
2020-06-16 00:31:27 +00:00
|
|
|
|
gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
|
|
|
|
|
g_object_unref (paper_size_list);
|
|
|
|
|
|
2020-06-16 01:57:39 +00:00
|
|
|
|
/* Do this in code, we want the translatable strings without the markup */
|
|
|
|
|
printer_list_list = g_list_store_new (G_TYPE_LIST_MODEL);
|
|
|
|
|
printer_list = g_list_store_new (GTK_TYPE_PRINTER);
|
|
|
|
|
printer = gtk_printer_new (_("Any Printer"), NULL, FALSE);
|
|
|
|
|
gtk_printer_set_location (printer, _("For portable documents"));
|
|
|
|
|
g_list_store_append (printer_list, printer);
|
|
|
|
|
g_object_unref (printer);
|
|
|
|
|
g_list_store_append (printer_list_list, printer_list);
|
|
|
|
|
g_object_unref (printer_list);
|
|
|
|
|
|
2020-07-04 19:47:48 +00:00
|
|
|
|
full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list)));
|
2020-06-16 01:57:39 +00:00
|
|
|
|
|
2020-08-03 19:04:33 +00:00
|
|
|
|
filter = GTK_FILTER (gtk_custom_filter_new (match_func, NULL, NULL));
|
2020-06-16 01:57:39 +00:00
|
|
|
|
dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter));
|
|
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_printer_item), dialog);
|
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_printer_item), dialog);
|
|
|
|
|
gtk_drop_down_set_factory (GTK_DROP_DOWN (dialog->printer_combo), factory);
|
|
|
|
|
g_object_unref (factory);
|
|
|
|
|
|
|
|
|
|
gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->printer_combo), dialog->printer_list);
|
|
|
|
|
printer_changed_callback (GTK_DROP_DOWN (dialog->printer_combo), NULL, dialog);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2013-03-26 15:02:25 +00:00
|
|
|
|
/* Load data */
|
2020-06-16 00:31:27 +00:00
|
|
|
|
gtk_print_load_custom_papers (dialog->custom_paper_list);
|
2013-03-26 15:02:25 +00:00
|
|
|
|
load_print_backends (dialog);
|
2020-08-29 20:29:28 +00:00
|
|
|
|
dialog->internal_change = FALSE;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_page_setup_unix_dialog_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkPageSetupUnixDialog *dialog = GTK_PAGE_SETUP_UNIX_DIALOG (object);
|
2006-05-04 13:43:32 +00:00
|
|
|
|
GList *node;
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
if (dialog->request_details_tag)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-06-15 20:33:11 +00:00
|
|
|
|
g_signal_handler_disconnect (dialog->request_details_printer,
|
|
|
|
|
dialog->request_details_tag);
|
|
|
|
|
g_object_unref (dialog->request_details_printer);
|
|
|
|
|
dialog->request_details_printer = NULL;
|
|
|
|
|
dialog->request_details_tag = 0;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-06-16 01:57:39 +00:00
|
|
|
|
g_clear_object (&dialog->printer_list);
|
2020-06-16 00:31:27 +00:00
|
|
|
|
g_clear_object (&dialog->page_setup_list);
|
|
|
|
|
g_clear_object (&dialog->custom_paper_list);
|
|
|
|
|
g_clear_object (&dialog->manage_papers_list);
|
2007-04-29 05:06:06 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
if (dialog->print_settings)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-06-15 20:33:11 +00:00
|
|
|
|
g_object_unref (dialog->print_settings);
|
|
|
|
|
dialog->print_settings = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
for (node = dialog->print_backends; node != NULL; node = node->next)
|
2020-06-16 01:57:39 +00:00
|
|
|
|
gtk_print_backend_destroy (GTK_PRINT_BACKEND (node->data));
|
|
|
|
|
g_list_free_full (dialog->print_backends, g_object_unref);
|
2020-06-15 20:33:11 +00:00
|
|
|
|
dialog->print_backends = NULL;
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_page_setup_unix_dialog_parent_class)->finalize (object);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
load_print_backends (GtkPageSetupUnixDialog *dialog)
|
|
|
|
|
{
|
2020-06-16 01:57:39 +00:00
|
|
|
|
GListModel *full_list;
|
|
|
|
|
GListStore *printer_list_list;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GList *node;
|
|
|
|
|
|
2020-06-16 01:57:39 +00:00
|
|
|
|
full_list = gtk_filter_list_model_get_model (GTK_FILTER_LIST_MODEL (dialog->printer_list));
|
|
|
|
|
printer_list_list = G_LIST_STORE (gtk_flatten_list_model_get_model (GTK_FLATTEN_LIST_MODEL (full_list)));
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
if (g_module_supported ())
|
2020-06-15 20:33:11 +00:00
|
|
|
|
dialog->print_backends = gtk_print_backend_load_modules ();
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
for (node = dialog->print_backends; node != NULL; node = node->next)
|
2020-06-16 01:57:39 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPrintBackend *backend = node->data;
|
|
|
|
|
g_list_store_append (printer_list_list, gtk_print_backend_get_printers (backend));
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkPageSetup *
|
|
|
|
|
get_current_page_setup (GtkPageSetupUnixDialog *dialog)
|
|
|
|
|
{
|
2020-06-16 00:31:27 +00:00
|
|
|
|
guint selected;
|
|
|
|
|
GListModel *model;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
selected = gtk_drop_down_get_selected (GTK_DROP_DOWN (dialog->paper_size_combo));
|
|
|
|
|
model = gtk_drop_down_get_model (GTK_DROP_DOWN (dialog->paper_size_combo));
|
|
|
|
|
if (selected != GTK_INVALID_LIST_POSITION)
|
|
|
|
|
return g_list_model_get_item (model, selected);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return gtk_page_setup_new ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-08-28 04:35:51 +00:00
|
|
|
|
page_setup_is_equal (GtkPageSetup *a,
|
|
|
|
|
GtkPageSetup *b)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
|
2011-08-28 04:35:51 +00:00
|
|
|
|
gtk_page_setup_get_paper_size (b)) &&
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gtk_page_setup_get_top_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_top_margin (b, GTK_UNIT_MM) &&
|
|
|
|
|
gtk_page_setup_get_bottom_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_bottom_margin (b, GTK_UNIT_MM) &&
|
|
|
|
|
gtk_page_setup_get_left_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_left_margin (b, GTK_UNIT_MM) &&
|
|
|
|
|
gtk_page_setup_get_right_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_right_margin (b, GTK_UNIT_MM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2006-06-12 04:39:55 +00:00
|
|
|
|
page_setup_is_same_size (GtkPageSetup *a,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkPageSetup *b)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
return gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
|
2011-08-28 04:35:51 +00:00
|
|
|
|
gtk_page_setup_get_paper_size (b));
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
set_paper_size (GtkPageSetupUnixDialog *dialog,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
|
gboolean size_only,
|
|
|
|
|
gboolean add_item)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-06-16 00:31:27 +00:00
|
|
|
|
GListModel *model;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPageSetup *list_page_setup;
|
2020-06-16 00:31:27 +00:00
|
|
|
|
guint i;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
if (page_setup == NULL)
|
|
|
|
|
return FALSE;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
model = gtk_drop_down_get_model (GTK_DROP_DOWN (dialog->paper_size_combo));
|
|
|
|
|
for (i = 0; i < g_list_model_get_n_items (model); i++)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-06-16 00:31:27 +00:00
|
|
|
|
list_page_setup = g_list_model_get_item (model, i);
|
|
|
|
|
if (list_page_setup == NULL)
|
|
|
|
|
continue;
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
if ((size_only && page_setup_is_same_size (page_setup, list_page_setup)) ||
|
|
|
|
|
(!size_only && page_setup_is_equal (page_setup, list_page_setup)))
|
|
|
|
|
{
|
|
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (dialog->paper_size_combo), i);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
g_object_unref (list_page_setup);
|
2020-06-16 00:31:27 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
g_object_unref (list_page_setup);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (add_item)
|
|
|
|
|
{
|
2020-06-16 00:31:27 +00:00
|
|
|
|
i = g_list_model_get_n_items (model);
|
|
|
|
|
g_list_store_append (dialog->page_setup_list, page_setup);
|
|
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (dialog->paper_size_combo), i);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fill_paper_sizes_from_printer (GtkPageSetupUnixDialog *dialog,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkPrinter *printer)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
GList *list, *l;
|
|
|
|
|
GtkPageSetup *current_page_setup, *page_setup;
|
|
|
|
|
GtkPaperSize *paper_size;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
g_list_store_remove_all (dialog->page_setup_list);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
if (printer == NULL)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (common_paper_sizes); i++)
|
2011-08-28 04:35:51 +00:00
|
|
|
|
{
|
|
|
|
|
page_setup = gtk_page_setup_new ();
|
|
|
|
|
paper_size = gtk_paper_size_new (common_paper_sizes[i]);
|
|
|
|
|
gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size);
|
|
|
|
|
gtk_paper_size_free (paper_size);
|
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
g_list_store_append (dialog->page_setup_list, page_setup);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
g_object_unref (page_setup);
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-12-24 13:16:05 +00:00
|
|
|
|
list = gtk_printer_list_papers (printer);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
/* TODO: We should really sort this list so interesting size
|
2011-08-28 04:35:51 +00:00
|
|
|
|
are at the top */
|
2006-04-21 15:09:32 +00:00
|
|
|
|
for (l = list; l != NULL; l = l->next)
|
2011-08-28 04:35:51 +00:00
|
|
|
|
{
|
|
|
|
|
page_setup = l->data;
|
2020-06-16 00:31:27 +00:00
|
|
|
|
g_list_store_append (dialog->page_setup_list, page_setup);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
g_object_unref (page_setup);
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
g_list_free (list);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-21 02:17:30 +00:00
|
|
|
|
current_page_setup = NULL;
|
|
|
|
|
|
|
|
|
|
/* When selecting a different printer, select its default paper size */
|
|
|
|
|
if (printer != NULL)
|
|
|
|
|
current_page_setup = gtk_printer_get_default_page_size (printer);
|
|
|
|
|
|
|
|
|
|
if (current_page_setup == NULL)
|
|
|
|
|
current_page_setup = get_current_page_setup (dialog);
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
if (!set_paper_size (dialog, current_page_setup, FALSE, FALSE))
|
|
|
|
|
set_paper_size (dialog, current_page_setup, TRUE, TRUE);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
if (current_page_setup)
|
|
|
|
|
g_object_unref (current_page_setup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-06-01 03:14:27 +00:00
|
|
|
|
printer_changed_finished_callback (GtkPrinter *printer,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
gboolean success,
|
|
|
|
|
GtkPageSetupUnixDialog *dialog)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-06-15 20:33:11 +00:00
|
|
|
|
g_signal_handler_disconnect (dialog->request_details_printer,
|
|
|
|
|
dialog->request_details_tag);
|
|
|
|
|
g_object_unref (dialog->request_details_printer);
|
|
|
|
|
dialog->request_details_tag = 0;
|
|
|
|
|
dialog->request_details_printer = NULL;
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
if (success)
|
|
|
|
|
fill_paper_sizes_from_printer (dialog, printer);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-06-16 01:57:39 +00:00
|
|
|
|
printer_changed_callback (GtkDropDown *combo_box,
|
|
|
|
|
GParamSpec *pspec,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkPageSetupUnixDialog *dialog)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPrinter *printer;
|
2020-06-16 01:57:39 +00:00
|
|
|
|
guint selected;
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
if (dialog->request_details_tag)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-06-15 20:33:11 +00:00
|
|
|
|
g_signal_handler_disconnect (dialog->request_details_printer,
|
|
|
|
|
dialog->request_details_tag);
|
|
|
|
|
g_object_unref (dialog->request_details_printer);
|
|
|
|
|
dialog->request_details_printer = NULL;
|
|
|
|
|
dialog->request_details_tag = 0;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-06-16 01:57:39 +00:00
|
|
|
|
selected = gtk_drop_down_get_selected (GTK_DROP_DOWN (dialog->printer_combo));
|
|
|
|
|
if (selected != GTK_INVALID_LIST_POSITION)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-06-16 01:57:39 +00:00
|
|
|
|
GListModel *model;
|
|
|
|
|
|
|
|
|
|
model = gtk_drop_down_get_model (GTK_DROP_DOWN (dialog->printer_combo));
|
|
|
|
|
printer = g_list_model_get_item (model, selected);
|
|
|
|
|
if (strcmp (gtk_printer_get_name (printer), _("Any Printer")) == 0)
|
|
|
|
|
g_clear_object (&printer);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-16 01:57:39 +00:00
|
|
|
|
if (printer == NULL ||
|
|
|
|
|
gtk_printer_has_details (printer))
|
2011-08-28 04:35:51 +00:00
|
|
|
|
fill_paper_sizes_from_printer (dialog, printer);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
else
|
2011-08-28 04:35:51 +00:00
|
|
|
|
{
|
2020-06-15 20:33:11 +00:00
|
|
|
|
dialog->request_details_printer = g_object_ref (printer);
|
|
|
|
|
dialog->request_details_tag =
|
2011-08-28 04:35:51 +00:00
|
|
|
|
g_signal_connect (printer, "details-acquired",
|
|
|
|
|
G_CALLBACK (printer_changed_finished_callback), dialog);
|
|
|
|
|
gtk_printer_request_details (printer);
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
if (printer)
|
2011-08-28 04:35:51 +00:00
|
|
|
|
g_object_unref (printer);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
if (dialog->print_settings)
|
2011-08-28 04:35:51 +00:00
|
|
|
|
{
|
|
|
|
|
const char *name = NULL;
|
|
|
|
|
|
|
|
|
|
if (printer)
|
|
|
|
|
name = gtk_printer_get_name (printer);
|
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
gtk_print_settings_set (dialog->print_settings,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
"format-for-printer", name);
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We do this munging because we don't want to show zero digits
|
|
|
|
|
after the decimal point, and not to many such digits if they
|
|
|
|
|
are nonzero. I wish printf let you specify max precision for %f... */
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static char *
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double_to_string (double d,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *val, *p;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
struct lconv *locale_data;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *decimal_point;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int decimal_point_len;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
locale_data = localeconv ();
|
|
|
|
|
decimal_point = locale_data->decimal_point;
|
|
|
|
|
decimal_point_len = strlen (decimal_point);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
/* Max two decimal digits for inch, max one for mm */
|
|
|
|
|
if (unit == GTK_UNIT_INCH)
|
|
|
|
|
val = g_strdup_printf ("%.2f", d);
|
|
|
|
|
else
|
|
|
|
|
val = g_strdup_printf ("%.1f", d);
|
|
|
|
|
|
|
|
|
|
if (strstr (val, decimal_point))
|
|
|
|
|
{
|
|
|
|
|
p = val + strlen (val) - 1;
|
|
|
|
|
while (*p == '0')
|
|
|
|
|
p--;
|
|
|
|
|
if (p - val + 1 >= decimal_point_len &&
|
2011-08-28 04:35:51 +00:00
|
|
|
|
strncmp (p - (decimal_point_len - 1), decimal_point, decimal_point_len) == 0)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
p -= decimal_point_len;
|
|
|
|
|
p[1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
custom_paper_dialog_response_cb (GtkDialog *custom_paper_dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int response_id,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
gpointer user_data)
|
2009-07-10 09:28:31 +00:00
|
|
|
|
{
|
2019-05-26 19:43:41 +00:00
|
|
|
|
GtkPageSetupUnixDialog *dialog = GTK_PAGE_SETUP_UNIX_DIALOG (user_data);
|
2020-08-29 20:29:28 +00:00
|
|
|
|
GtkPageSetup *last_page_setup;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
2020-08-29 20:29:28 +00:00
|
|
|
|
dialog->internal_change = TRUE;
|
2020-06-16 00:31:27 +00:00
|
|
|
|
gtk_print_load_custom_papers (dialog->custom_paper_list);
|
2020-06-16 01:57:39 +00:00
|
|
|
|
printer_changed_callback (GTK_DROP_DOWN (dialog->printer_combo), NULL, dialog);
|
2020-08-29 20:29:28 +00:00
|
|
|
|
dialog->internal_change = FALSE;
|
|
|
|
|
|
|
|
|
|
if (dialog->last_setup)
|
|
|
|
|
last_page_setup = g_object_ref (dialog->last_setup);
|
|
|
|
|
else
|
|
|
|
|
last_page_setup = gtk_page_setup_new (); /* "good" default */
|
|
|
|
|
set_paper_size (dialog, last_page_setup, FALSE, TRUE);
|
|
|
|
|
g_object_unref (last_page_setup);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
|
gtk_window_destroy (GTK_WINDOW (custom_paper_dialog));
|
2009-07-10 09:28:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
static void
|
2020-06-16 00:31:27 +00:00
|
|
|
|
paper_size_changed (GtkDropDown *combo_box,
|
|
|
|
|
GParamSpec *pspec,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkPageSetupUnixDialog *dialog)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPageSetup *page_setup, *last_page_setup;
|
2020-06-16 00:31:27 +00:00
|
|
|
|
guint selected;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkUnit unit;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *str, *w, *h;
|
|
|
|
|
char *top, *bottom, *left, *right;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkLabel *label;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *unit_str;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-08-29 20:29:28 +00:00
|
|
|
|
if (dialog->internal_change)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
label = GTK_LABEL (dialog->paper_size_label);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
selected = gtk_drop_down_get_selected (GTK_DROP_DOWN (combo_box));
|
|
|
|
|
if (selected != GTK_INVALID_LIST_POSITION)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-06-16 00:31:27 +00:00
|
|
|
|
GListModel *papers, *model;
|
|
|
|
|
|
|
|
|
|
papers = gtk_drop_down_get_model (GTK_DROP_DOWN (dialog->paper_size_combo));
|
|
|
|
|
page_setup = g_list_model_get_item (papers, selected);
|
|
|
|
|
model = gtk_flatten_list_model_get_model_for_item (GTK_FLATTEN_LIST_MODEL (papers), selected);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-16 00:31:27 +00:00
|
|
|
|
if (model == G_LIST_MODEL (dialog->manage_papers_list))
|
2011-08-28 04:35:51 +00:00
|
|
|
|
{
|
2009-07-10 09:28:31 +00:00
|
|
|
|
GtkWidget *custom_paper_dialog;
|
|
|
|
|
|
2006-05-31 04:45:37 +00:00
|
|
|
|
/* Change from "manage" menu item to last value */
|
2020-06-15 20:33:11 +00:00
|
|
|
|
if (dialog->last_setup)
|
|
|
|
|
last_page_setup = g_object_ref (dialog->last_setup);
|
2006-05-31 04:45:37 +00:00
|
|
|
|
else
|
2011-08-28 04:35:51 +00:00
|
|
|
|
last_page_setup = gtk_page_setup_new (); /* "good" default */
|
|
|
|
|
set_paper_size (dialog, last_page_setup, FALSE, TRUE);
|
2006-05-31 04:45:37 +00:00
|
|
|
|
g_object_unref (last_page_setup);
|
|
|
|
|
|
|
|
|
|
/* And show the custom paper dialog */
|
2009-07-10 09:28:31 +00:00
|
|
|
|
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));
|
2006-05-31 04:45:37 +00:00
|
|
|
|
|
2020-11-10 14:07:54 +00:00
|
|
|
|
g_object_unref (page_setup);
|
|
|
|
|
|
2006-05-31 04:45:37 +00:00
|
|
|
|
return;
|
2011-08-28 04:35:51 +00:00
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
if (dialog->last_setup)
|
|
|
|
|
g_object_unref (dialog->last_setup);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
dialog->last_setup = g_object_ref (page_setup);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
|
unit = _gtk_print_get_default_user_units ();
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
if (unit == GTK_UNIT_MM)
|
2011-08-28 04:35:51 +00:00
|
|
|
|
unit_str = _("mm");
|
2006-04-21 15:09:32 +00:00
|
|
|
|
else
|
2011-08-28 04:35:51 +00:00
|
|
|
|
unit_str = _("inch");
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
w = double_to_string (gtk_page_setup_get_paper_width (page_setup, unit),
|
2011-08-28 04:35:51 +00:00
|
|
|
|
unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
h = double_to_string (gtk_page_setup_get_paper_height (page_setup, unit),
|
2011-08-28 04:35:51 +00:00
|
|
|
|
unit);
|
2014-08-21 21:01:54 +00:00
|
|
|
|
str = g_strdup_printf ("%s × %s %s", w, h, unit_str);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
g_free (w);
|
|
|
|
|
g_free (h);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gtk_label_set_text (label, str);
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
|
|
top = double_to_string (gtk_page_setup_get_top_margin (page_setup, unit), unit);
|
|
|
|
|
bottom = double_to_string (gtk_page_setup_get_bottom_margin (page_setup, unit), unit);
|
|
|
|
|
left = double_to_string (gtk_page_setup_get_left_margin (page_setup, unit), unit);
|
|
|
|
|
right = double_to_string (gtk_page_setup_get_right_margin (page_setup, unit), unit);
|
|
|
|
|
|
|
|
|
|
str = g_strdup_printf (_("Margins:\n"
|
2011-08-28 04:35:51 +00:00
|
|
|
|
" Left: %s %s\n"
|
|
|
|
|
" Right: %s %s\n"
|
|
|
|
|
" Top: %s %s\n"
|
|
|
|
|
" Bottom: %s %s"
|
|
|
|
|
),
|
|
|
|
|
left, unit_str,
|
|
|
|
|
right, unit_str,
|
|
|
|
|
top, unit_str,
|
|
|
|
|
bottom, unit_str);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
g_free (top);
|
|
|
|
|
g_free (bottom);
|
|
|
|
|
g_free (left);
|
|
|
|
|
g_free (right);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
gtk_widget_set_tooltip_text (dialog->paper_size_label, str);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
g_free (str);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
g_object_unref (page_setup);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gtk_label_set_text (label, "");
|
2020-06-15 20:33:11 +00:00
|
|
|
|
gtk_widget_set_tooltip_text (dialog->paper_size_label, NULL);
|
|
|
|
|
if (dialog->last_setup)
|
|
|
|
|
g_object_unref (dialog->last_setup);
|
|
|
|
|
dialog->last_setup = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 03:14:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_page_setup_unix_dialog_new:
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* @title: (nullable): the title of the dialog
|
|
|
|
|
* @parent: (nullable): transient parent of the dialog
|
2006-06-01 03:14:27 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates a new page setup dialog.
|
|
|
|
|
*
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* Returns: the new `GtkPageSetupUnixDialog`
|
2006-06-01 03:14:27 +00:00
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkWidget *
|
2020-07-24 18:40:36 +00:00
|
|
|
|
gtk_page_setup_unix_dialog_new (const char *title,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkWindow *parent)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *result;
|
|
|
|
|
|
|
|
|
|
if (title == NULL)
|
|
|
|
|
title = _("Page Setup");
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
result = g_object_new (GTK_TYPE_PAGE_SETUP_UNIX_DIALOG,
|
|
|
|
|
"title", title,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (result), parent);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkPageOrientation
|
|
|
|
|
get_orientation (GtkPageSetupUnixDialog *dialog)
|
|
|
|
|
{
|
2020-08-30 23:36:27 +00:00
|
|
|
|
if (gtk_check_button_get_active (GTK_CHECK_BUTTON (dialog->portrait_radio)))
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return GTK_PAGE_ORIENTATION_PORTRAIT;
|
2020-08-30 23:36:27 +00:00
|
|
|
|
if (gtk_check_button_get_active (GTK_CHECK_BUTTON (dialog->landscape_radio)))
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return GTK_PAGE_ORIENTATION_LANDSCAPE;
|
2020-08-30 23:36:27 +00:00
|
|
|
|
if (gtk_check_button_get_active (GTK_CHECK_BUTTON (dialog->reverse_landscape_radio)))
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE;
|
2006-12-24 11:30:22 +00:00
|
|
|
|
return GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-08-28 04:35:51 +00:00
|
|
|
|
set_orientation (GtkPageSetupUnixDialog *dialog,
|
|
|
|
|
GtkPageOrientation orientation)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
switch (orientation)
|
|
|
|
|
{
|
|
|
|
|
case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
|
2020-08-30 23:36:27 +00:00
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (dialog->reverse_portrait_radio), TRUE);
|
2006-12-24 11:30:22 +00:00
|
|
|
|
break;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
case GTK_PAGE_ORIENTATION_PORTRAIT:
|
2020-08-30 23:36:27 +00:00
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (dialog->portrait_radio), TRUE);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_PAGE_ORIENTATION_LANDSCAPE:
|
2020-08-30 23:36:27 +00:00
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (dialog->landscape_radio), TRUE);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
|
2020-08-30 23:36:27 +00:00
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (dialog->reverse_landscape_radio), TRUE);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 03:14:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_page_setup_unix_dialog_set_page_setup:
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* @dialog: a `GtkPageSetupUnixDialog`
|
|
|
|
|
* @page_setup: a `GtkPageSetup`
|
2011-08-28 04:35:51 +00:00
|
|
|
|
*
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* Sets the `GtkPageSetup` from which the page setup
|
2006-06-01 03:14:27 +00:00
|
|
|
|
* dialog takes its values.
|
2021-02-27 15:53:52 +00:00
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_page_setup_unix_dialog_set_page_setup (GtkPageSetupUnixDialog *dialog,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkPageSetup *page_setup)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (page_setup)
|
|
|
|
|
{
|
|
|
|
|
set_paper_size (dialog, page_setup, FALSE, TRUE);
|
|
|
|
|
set_orientation (dialog, gtk_page_setup_get_orientation (page_setup));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 03:14:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_page_setup_unix_dialog_get_page_setup:
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* @dialog: a `GtkPageSetupUnixDialog`
|
2011-08-28 04:35:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the currently selected page setup from the dialog.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer none): the current page setup
|
2021-02-27 15:53:52 +00:00
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPageSetup *
|
|
|
|
|
gtk_page_setup_unix_dialog_get_page_setup (GtkPageSetupUnixDialog *dialog)
|
|
|
|
|
{
|
|
|
|
|
GtkPageSetup *page_setup;
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
page_setup = get_current_page_setup (dialog);
|
|
|
|
|
|
|
|
|
|
gtk_page_setup_set_orientation (page_setup, get_orientation (dialog));
|
|
|
|
|
|
|
|
|
|
return page_setup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
set_active_printer (GtkPageSetupUnixDialog *dialog,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *printer_name)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-08-04 00:23:59 +00:00
|
|
|
|
guint i, n;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPrinter *printer;
|
|
|
|
|
|
2020-08-04 00:23:59 +00:00
|
|
|
|
if (!printer_name)
|
|
|
|
|
return FALSE;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-08-04 00:23:59 +00:00
|
|
|
|
for (i = 0, n = g_list_model_get_n_items (dialog->printer_list); i < n; i++)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-08-04 00:23:59 +00:00
|
|
|
|
printer = g_list_model_get_item (dialog->printer_list, i);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2020-08-04 00:23:59 +00:00
|
|
|
|
if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
|
|
|
|
|
{
|
|
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (dialog->printer_combo), i);
|
2011-08-28 04:35:51 +00:00
|
|
|
|
g_object_unref (printer);
|
|
|
|
|
|
2020-08-04 00:23:59 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (printer);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
2011-08-28 04:35:51 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 03:14:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_page_setup_unix_dialog_set_print_settings:
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* @dialog: a `GtkPageSetupUnixDialog`
|
2022-02-11 11:07:54 +00:00
|
|
|
|
* @print_settings: (nullable): a `GtkPrintSettings`
|
2011-08-28 04:35:51 +00:00
|
|
|
|
*
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* Sets the `GtkPrintSettings` from which the page setup dialog
|
2006-06-01 03:14:27 +00:00
|
|
|
|
* takes its values.
|
2021-02-27 15:53:52 +00:00
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_page_setup_unix_dialog_set_print_settings (GtkPageSetupUnixDialog *dialog,
|
2011-08-28 04:35:51 +00:00
|
|
|
|
GtkPrintSettings *print_settings)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *format_for_printer;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
if (dialog->print_settings == print_settings) return;
|
2006-05-03 17:09:39 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
if (dialog->print_settings)
|
|
|
|
|
g_object_unref (dialog->print_settings);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2020-06-15 20:33:11 +00:00
|
|
|
|
dialog->print_settings = print_settings;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
if (print_settings)
|
|
|
|
|
{
|
|
|
|
|
g_object_ref (print_settings);
|
|
|
|
|
|
|
|
|
|
format_for_printer = gtk_print_settings_get (print_settings, "format-for-printer");
|
|
|
|
|
|
2011-08-28 04:35:51 +00:00
|
|
|
|
/* Set printer if in list, otherwise set when
|
|
|
|
|
* that printer is added
|
2006-06-01 03:14:27 +00:00
|
|
|
|
*/
|
2020-06-16 01:57:39 +00:00
|
|
|
|
set_active_printer (dialog, format_for_printer);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 03:14:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_page_setup_unix_dialog_get_print_settings:
|
2021-02-27 15:53:52 +00:00
|
|
|
|
* @dialog: a `GtkPageSetupUnixDialog`
|
2011-08-28 04:35:51 +00:00
|
|
|
|
*
|
2006-06-01 03:14:27 +00:00
|
|
|
|
* Gets the current print settings from the dialog.
|
2011-08-28 04:35:51 +00:00
|
|
|
|
*
|
2022-02-11 11:07:54 +00:00
|
|
|
|
* Returns: (transfer none) (nullable): the current print settings
|
2006-06-01 03:14:27 +00:00
|
|
|
|
**/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPrintSettings *
|
|
|
|
|
gtk_page_setup_unix_dialog_get_print_settings (GtkPageSetupUnixDialog *dialog)
|
|
|
|
|
{
|
2020-06-15 20:33:11 +00:00
|
|
|
|
return dialog->print_settings;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|