2009-07-10 09:28:31 +00:00
|
|
|
/* GtkCustomPaperUnixDialog
|
|
|
|
* Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
|
|
|
|
* Copyright © 2006, 2007, 2008 Christian Persch
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* 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/>.
|
2009-07-10 09:28:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <locale.h>
|
|
|
|
|
|
|
|
#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
|
|
|
|
#include <langinfo.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
|
|
|
#include "gtkliststore.h"
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
#include "gtksignallistitemfactory.h"
|
2009-07-10 09:28:31 +00:00
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkspinbutton.h"
|
|
|
|
|
|
|
|
#include "gtkcustompaperunixdialog.h"
|
2019-05-26 21:57:23 +00:00
|
|
|
#include "gtkprintbackendprivate.h"
|
2009-07-10 09:28:31 +00:00
|
|
|
#include "gtkprintutils.h"
|
2013-12-08 14:58:00 +00:00
|
|
|
#include "gtkdialogprivate.h"
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2012-04-27 16:23:38 +00:00
|
|
|
#define LEGACY_CUSTOM_PAPER_FILENAME ".gtk-custom-papers"
|
|
|
|
#define CUSTOM_PAPER_FILENAME "custom-papers"
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkUnit display_unit;
|
|
|
|
GtkWidget *spin_button;
|
|
|
|
} UnitWidget;
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
struct _GtkCustomPaperUnixDialog
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +00:00
|
|
|
GtkDialog parent_instance;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
GtkWidget *listview;
|
2009-07-10 09:28:31 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
guint request_details_tag;
|
|
|
|
GtkPrinter *request_details_printer;
|
|
|
|
|
|
|
|
guint non_user_change : 1;
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
GListStore *custom_paper_list;
|
2020-06-14 12:30:54 +00:00
|
|
|
GListModel *printer_list;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
GList *print_backends;
|
|
|
|
};
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
typedef struct _GtkCustomPaperUnixDialogClass GtkCustomPaperUnixDialogClass;
|
|
|
|
|
|
|
|
struct _GtkCustomPaperUnixDialogClass
|
|
|
|
{
|
|
|
|
GtkDialogClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
enum {
|
|
|
|
PRINTER_LIST_COL_NAME,
|
|
|
|
PRINTER_LIST_COL_PRINTER,
|
|
|
|
PRINTER_LIST_N_COLS
|
|
|
|
};
|
|
|
|
|
2010-06-02 03:31:23 +00:00
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
G_DEFINE_TYPE (GtkCustomPaperUnixDialog, gtk_custom_paper_unix_dialog, GTK_TYPE_DIALOG)
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
static void gtk_custom_paper_unix_dialog_constructed (GObject *object);
|
2009-07-10 09:28:31 +00:00
|
|
|
static void gtk_custom_paper_unix_dialog_finalize (GObject *object);
|
|
|
|
static void populate_dialog (GtkCustomPaperUnixDialog *dialog);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GtkUnit
|
|
|
|
_gtk_print_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
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
char *e = _("default:mm");
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
|
2020-07-24 18:40:36 +00:00
|
|
|
char *imperial = NULL;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
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"))
|
2016-02-28 16:06:25 +00:00
|
|
|
g_warning ("Whoever translated default:mm did so wrongly.");
|
2009-07-10 09:28:31 +00:00
|
|
|
return GTK_UNIT_MM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2012-04-27 16:23:38 +00:00
|
|
|
custom_paper_get_legacy_filename (void)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +00:00
|
|
|
char *filename;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
filename = g_build_filename (g_get_home_dir (),
|
2020-06-12 16:52:47 +00:00
|
|
|
LEGACY_CUSTOM_PAPER_FILENAME, NULL);
|
2012-04-27 16:23:38 +00:00
|
|
|
g_assert (filename != NULL);
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
custom_paper_get_filename (void)
|
|
|
|
{
|
2020-06-12 16:52:47 +00:00
|
|
|
char *filename;
|
2012-04-27 16:23:38 +00:00
|
|
|
|
|
|
|
filename = g_build_filename (g_get_user_config_dir (),
|
2016-10-23 18:06:33 +00:00
|
|
|
"gtk-4.0",
|
2020-06-12 16:52:47 +00:00
|
|
|
CUSTOM_PAPER_FILENAME, NULL);
|
2009-07-10 09:28:31 +00:00
|
|
|
g_assert (filename != NULL);
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
|
|
|
_gtk_load_custom_papers (void)
|
|
|
|
{
|
|
|
|
GKeyFile *keyfile;
|
2020-06-12 16:52:47 +00:00
|
|
|
char *filename;
|
|
|
|
char **groups;
|
2009-07-10 09:28:31 +00:00
|
|
|
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);
|
2012-04-27 16:23:38 +00:00
|
|
|
if (!load_ok)
|
|
|
|
{
|
|
|
|
/* try legacy file */
|
|
|
|
filename = custom_paper_get_legacy_filename ();
|
|
|
|
load_ok = g_key_file_load_from_file (keyfile, filename, 0, NULL);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
2009-07-10 09:28:31 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_print_load_custom_papers (GtkListStore *store)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GList *papers, *p;
|
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
|
|
|
|
gtk_list_store_clear (store);
|
|
|
|
|
|
|
|
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,
|
2020-06-12 16:52:47 +00:00
|
|
|
0, page_setup,
|
|
|
|
-1);
|
2020-06-12 12:28:59 +00:00
|
|
|
g_object_unref (page_setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (papers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_print_load_custom_papers (GListStore *store)
|
|
|
|
{
|
|
|
|
GList *papers, *p;
|
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
|
|
|
|
g_list_store_remove_all (store);
|
|
|
|
|
|
|
|
papers = _gtk_load_custom_papers ();
|
|
|
|
for (p = papers; p; p = p->next)
|
|
|
|
{
|
|
|
|
page_setup = p->data;
|
|
|
|
g_list_store_append (store, page_setup);
|
2009-07-10 09:28:31 +00:00
|
|
|
g_object_unref (page_setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (papers);
|
|
|
|
}
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
static void
|
|
|
|
gtk_print_save_custom_papers (GListStore *store)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
|
|
|
GKeyFile *keyfile;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *filename, *data, *parentdir;
|
2009-07-10 09:28:31 +00:00
|
|
|
gsize len;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i = 0;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
keyfile = g_key_file_new ();
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (store)); i++)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 18:11:16 +00:00
|
|
|
GtkPageSetup *page_setup;
|
2020-07-24 18:40:36 +00:00
|
|
|
char group[32];
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
page_setup = g_list_model_get_item (G_LIST_MODEL (store), i);
|
|
|
|
g_snprintf (group, sizeof (group), "Paper%u", i);
|
|
|
|
gtk_page_setup_to_key_file (page_setup, keyfile, group);
|
|
|
|
g_object_unref (page_setup);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
filename = custom_paper_get_filename ();
|
2012-04-27 16:23:38 +00:00
|
|
|
parentdir = g_build_filename (g_get_user_config_dir (),
|
2016-10-23 18:06:33 +00:00
|
|
|
"gtk-4.0",
|
2012-04-27 16:23:38 +00:00
|
|
|
NULL);
|
|
|
|
if (g_mkdir_with_parents (parentdir, 0700) == 0)
|
|
|
|
{
|
|
|
|
data = g_key_file_to_data (keyfile, &len, NULL);
|
|
|
|
g_file_set_contents (filename, data, len, NULL);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
g_free (parentdir);
|
2009-07-10 09:28:31 +00:00
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_custom_paper_unix_dialog_class_init (GtkCustomPaperUnixDialogClass *class)
|
|
|
|
{
|
2014-06-26 22:22:42 +00:00
|
|
|
G_OBJECT_CLASS (class)->constructed = gtk_custom_paper_unix_dialog_constructed;
|
2013-06-27 19:02:52 +00:00
|
|
|
G_OBJECT_CLASS (class)->finalize = gtk_custom_paper_unix_dialog_finalize;
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
custom_paper_dialog_response_cb (GtkDialog *dialog,
|
2020-06-12 16:52:47 +00:00
|
|
|
int response,
|
|
|
|
gpointer user_data)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +00:00
|
|
|
GtkCustomPaperUnixDialog *self = GTK_CUSTOM_PAPER_UNIX_DIALOG (dialog);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
gtk_print_save_custom_papers (self->custom_paper_list);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
static gboolean
|
|
|
|
match_func (gpointer item, gpointer user_data)
|
|
|
|
{
|
|
|
|
return !gtk_printer_is_virtual (GTK_PRINTER (item));
|
|
|
|
}
|
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
static void
|
|
|
|
gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
2020-06-14 12:30:54 +00:00
|
|
|
GtkPrinter *printer;
|
|
|
|
GListStore *printer_list;
|
|
|
|
GListStore *printer_list_list;
|
|
|
|
GListModel *full_list;
|
|
|
|
GtkFilter *filter;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2013-12-08 14:58:00 +00:00
|
|
|
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->print_backends = NULL;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->request_details_printer = NULL;
|
|
|
|
dialog->request_details_tag = 0;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
printer_list_list = g_list_store_new (G_TYPE_LIST_MODEL);
|
|
|
|
printer_list = g_list_store_new (GTK_TYPE_PRINTER);
|
|
|
|
printer = gtk_printer_new (_("Margins from Printer…"), NULL, FALSE);
|
|
|
|
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)));
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-08-03 19:04:33 +00:00
|
|
|
filter = GTK_FILTER (gtk_custom_filter_new (match_func, NULL, NULL));
|
2020-06-14 12:30:54 +00:00
|
|
|
dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter));
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
dialog->custom_paper_list = g_list_store_new (GTK_TYPE_PAGE_SETUP);
|
|
|
|
gtk_print_load_custom_papers (dialog->custom_paper_list);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
populate_dialog (dialog);
|
|
|
|
|
2013-12-08 14:58:00 +00:00
|
|
|
g_signal_connect (dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), NULL);
|
|
|
|
}
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
static void
|
|
|
|
gtk_custom_paper_unix_dialog_constructed (GObject *object)
|
2013-12-08 14:58:00 +00:00
|
|
|
{
|
|
|
|
gboolean use_header;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
G_OBJECT_CLASS (gtk_custom_paper_unix_dialog_parent_class)->constructed (object);
|
2013-12-08 14:58:00 +00:00
|
|
|
|
|
|
|
g_object_get (object, "use-header-bar", &use_header, NULL);
|
|
|
|
if (!use_header)
|
|
|
|
{
|
|
|
|
gtk_dialog_add_buttons (GTK_DIALOG (object),
|
|
|
|
_("_Close"), GTK_RESPONSE_CLOSE,
|
|
|
|
NULL);
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_CLOSE);
|
|
|
|
}
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_custom_paper_unix_dialog_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkCustomPaperUnixDialog *dialog = GTK_CUSTOM_PAPER_UNIX_DIALOG (object);
|
|
|
|
GList *node;
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
if (dialog->printer_list)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +00:00
|
|
|
g_signal_handler_disconnect (dialog->printer_list, dialog->printer_inserted_tag);
|
|
|
|
g_object_unref (dialog->printer_list);
|
|
|
|
dialog->printer_list = NULL;
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
if (dialog->request_details_tag)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +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;
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
g_clear_object (&dialog->custom_paper_list);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
for (node = dialog->print_backends; node; node = node->next)
|
|
|
|
gtk_print_backend_destroy (GTK_PRINT_BACKEND (node->data));
|
|
|
|
g_list_free_full (dialog->print_backends, g_object_unref);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->print_backends = NULL;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_custom_paper_unix_dialog_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_custom_paper_unix_dialog_new:
|
2010-02-19 16:53:17 +00:00
|
|
|
* @title: (allow-none): the title of the dialog, or %NULL
|
|
|
|
* @parent: (allow-none): transient parent of the dialog, or %NULL
|
2009-07-10 09:28:31 +00:00
|
|
|
*
|
|
|
|
* Creates a new custom paper dialog.
|
|
|
|
*
|
|
|
|
* Returns: the new #GtkCustomPaperUnixDialog
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
_gtk_custom_paper_unix_dialog_new (GtkWindow *parent,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *title)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
|
|
|
GtkWidget *result;
|
|
|
|
|
|
|
|
if (title == NULL)
|
|
|
|
title = _("Manage Custom Sizes");
|
|
|
|
|
|
|
|
result = g_object_new (GTK_TYPE_CUSTOM_PAPER_UNIX_DIALOG,
|
|
|
|
"title", title,
|
2009-09-08 23:39:52 +00:00
|
|
|
"transient-for", parent,
|
|
|
|
"modal", parent != NULL,
|
|
|
|
"destroy-with-parent", TRUE,
|
2011-06-10 04:15:10 +00:00
|
|
|
"resizable", FALSE,
|
2009-07-10 09:28:31 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_print_backends (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
2020-06-14 12:30:54 +00:00
|
|
|
GListModel *full_list;
|
|
|
|
GListStore *printer_list_list;
|
2009-07-10 09:28:31 +00:00
|
|
|
GList *node;
|
|
|
|
|
2020-06-14 12:30:54 +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)));
|
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
if (g_module_supported ())
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->print_backends = gtk_print_backend_load_modules ();
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
for (node = dialog->print_backends; node != NULL; node = node->next)
|
2020-06-14 12:30:54 +00:00
|
|
|
{
|
|
|
|
GtkPrintBackend *backend = GTK_PRINT_BACKEND (node->data);
|
|
|
|
g_list_store_append (printer_list_list, gtk_print_backend_get_printers (backend));
|
|
|
|
}
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void unit_widget_changed (GtkCustomPaperUnixDialog *dialog);
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
new_unit_widget (GtkCustomPaperUnixDialog *dialog,
|
2020-06-12 16:52:47 +00:00
|
|
|
GtkUnit unit,
|
|
|
|
GtkWidget *mnemonic_label)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
|
|
|
GtkWidget *hbox, *button, *label;
|
|
|
|
UnitWidget *data;
|
|
|
|
|
|
|
|
data = g_new0 (UnitWidget, 1);
|
|
|
|
data->display_unit = unit;
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
button = gtk_spin_button_new_with_range (0.0, 9999.0, 1);
|
2014-01-28 04:29:34 +00:00
|
|
|
gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
|
2009-07-10 09:28:31 +00:00
|
|
|
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);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
data->spin_button = button;
|
|
|
|
|
|
|
|
g_signal_connect_swapped (button, "value-changed",
|
2020-06-12 16:52:47 +00:00
|
|
|
G_CALLBACK (unit_widget_changed), dialog);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
if (unit == GTK_UNIT_INCH)
|
|
|
|
label = gtk_label_new (_("inch"));
|
|
|
|
else
|
|
|
|
label = gtk_label_new (_("mm"));
|
2014-01-28 04:29:34 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), label);
|
2009-07-10 09:28:31 +00:00
|
|
|
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)),
|
2020-06-12 16:52:47 +00:00
|
|
|
data->display_unit);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unit_widget_set (GtkWidget *unit_widget,
|
2020-07-24 20:32:16 +00:00
|
|
|
double value)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
|
|
|
UnitWidget *data;
|
|
|
|
|
|
|
|
data = g_object_get_data (G_OBJECT (unit_widget), "unit-data");
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (data->spin_button),
|
2020-06-12 16:52:47 +00:00
|
|
|
_gtk_print_convert_from_mm (value, data->display_unit));
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_combo_sensitivity_from_printers (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
2020-06-12 18:11:16 +00:00
|
|
|
gboolean sensitive = FALSE;
|
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
if (g_list_model_get_n_items (dialog->printer_list) > 1)
|
2009-07-10 09:28:31 +00:00
|
|
|
sensitive = TRUE;
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
gtk_widget_set_sensitive (dialog->printer_combo, sensitive);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_custom_widgets_from_list (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
2020-06-12 18:11:16 +00:00
|
|
|
GListModel *model;
|
2009-07-10 09:28:31 +00:00
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
|
2020-08-31 21:06:48 +00:00
|
|
|
model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)));
|
2020-06-12 18:11:16 +00:00
|
|
|
page_setup = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (model));
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->non_user_change = TRUE;
|
2020-06-12 18:11:16 +00:00
|
|
|
if (page_setup != NULL)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +00:00
|
|
|
unit_widget_set (dialog->width_widget,
|
|
|
|
gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM));
|
|
|
|
unit_widget_set (dialog->height_widget,
|
|
|
|
gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM));
|
|
|
|
unit_widget_set (dialog->top_widget,
|
|
|
|
gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
|
|
|
|
unit_widget_set (dialog->bottom_widget,
|
|
|
|
gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
|
|
|
|
unit_widget_set (dialog->left_widget,
|
|
|
|
gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
|
|
|
|
unit_widget_set (dialog->right_widget,
|
|
|
|
gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (dialog->values_box, TRUE);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-12 16:52:47 +00:00
|
|
|
gtk_widget_set_sensitive (dialog->values_box, FALSE);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
if (dialog->printer_list)
|
2009-07-10 09:28:31 +00:00
|
|
|
update_combo_sensitivity_from_printers (dialog);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->non_user_change = FALSE;
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-06-12 18:11:16 +00:00
|
|
|
selected_custom_paper_changed (GObject *list,
|
|
|
|
GParamSpec *pspec,
|
2020-06-12 16:52:47 +00:00
|
|
|
GtkCustomPaperUnixDialog *dialog)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
|
|
|
update_custom_widgets_from_list (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unit_widget_changed (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
2020-06-12 18:11:16 +00:00
|
|
|
double w, h, top, bottom, left, right;
|
|
|
|
GListModel *model;
|
2009-07-10 09:28:31 +00:00
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
if (dialog->non_user_change)
|
2009-07-10 09:28:31 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-31 21:06:48 +00:00
|
|
|
model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)));
|
2020-06-12 18:11:16 +00:00
|
|
|
page_setup = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (model));
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
if (page_setup != NULL)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +00:00
|
|
|
w = unit_widget_get (dialog->width_widget);
|
|
|
|
h = unit_widget_get (dialog->height_widget);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
paper_size = gtk_page_setup_get_paper_size (page_setup);
|
|
|
|
gtk_paper_size_set_size (paper_size, w, h, GTK_UNIT_MM);
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
top = unit_widget_get (dialog->top_widget);
|
|
|
|
bottom = unit_widget_get (dialog->bottom_widget);
|
|
|
|
left = unit_widget_get (dialog->left_widget);
|
|
|
|
right = unit_widget_get (dialog->right_widget);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
custom_paper_name_used (GtkCustomPaperUnixDialog *dialog,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
GtkPaperSize *paper_size;
|
2020-06-12 18:11:16 +00:00
|
|
|
guint i;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (dialog->custom_paper_list)); i++)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 18:11:16 +00:00
|
|
|
page_setup = g_list_model_get_item (G_LIST_MODEL (dialog->custom_paper_list), i);
|
|
|
|
paper_size = gtk_page_setup_get_paper_size (page_setup);
|
|
|
|
if (strcmp (name, gtk_paper_size_get_name (paper_size)) == 0)
|
2020-06-12 16:52:47 +00:00
|
|
|
{
|
|
|
|
g_object_unref (page_setup);
|
2020-06-12 18:11:16 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
g_object_unref (page_setup);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_custom_paper (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
GtkPaperSize *paper_size;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
i = 1;
|
|
|
|
name = NULL;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
g_free (name);
|
|
|
|
name = g_strdup_printf (_("Custom Size %d"), i);
|
|
|
|
i++;
|
|
|
|
} while (custom_paper_name_used (dialog, name));
|
|
|
|
|
|
|
|
page_setup = gtk_page_setup_new ();
|
|
|
|
paper_size = gtk_paper_size_new_custom (name, name,
|
2020-06-12 16:52:47 +00:00
|
|
|
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);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_page_setup_set_paper_size (page_setup, paper_size);
|
|
|
|
gtk_paper_size_free (paper_size);
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
g_list_store_append (dialog->custom_paper_list, page_setup);
|
2009-07-10 09:28:31 +00:00
|
|
|
g_object_unref (page_setup);
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
/* FIXME start editing */
|
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_custom_paper (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
2020-06-12 18:11:16 +00:00
|
|
|
GListModel *model;
|
|
|
|
guint selected;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-08-31 21:06:48 +00:00
|
|
|
model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)));
|
2020-06-12 18:11:16 +00:00
|
|
|
selected = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (model));
|
|
|
|
if (selected != GTK_INVALID_LIST_POSITION)
|
|
|
|
g_list_store_remove (dialog->custom_paper_list, selected);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_margins_from_printer (GtkCustomPaperUnixDialog *dialog,
|
2020-06-12 16:52:47 +00:00
|
|
|
GtkPrinter *printer)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 18:11:16 +00:00
|
|
|
double top, bottom, left, right;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
top = bottom = left = right = 0;
|
2008-02-06 22:58:47 +00:00
|
|
|
if (!gtk_printer_get_hard_margins (printer, &top, &bottom, &left, &right))
|
|
|
|
return;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->non_user_change = TRUE;
|
|
|
|
unit_widget_set (dialog->top_widget, _gtk_print_convert_to_mm (top, GTK_UNIT_POINTS));
|
|
|
|
unit_widget_set (dialog->bottom_widget, _gtk_print_convert_to_mm (bottom, GTK_UNIT_POINTS));
|
|
|
|
unit_widget_set (dialog->left_widget, _gtk_print_convert_to_mm (left, GTK_UNIT_POINTS));
|
|
|
|
unit_widget_set (dialog->right_widget, _gtk_print_convert_to_mm (right, GTK_UNIT_POINTS));
|
|
|
|
dialog->non_user_change = FALSE;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
/* Only send one change */
|
|
|
|
unit_widget_changed (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_margins_finished_callback (GtkPrinter *printer,
|
2020-06-12 16:52:47 +00:00
|
|
|
gboolean success,
|
|
|
|
GtkCustomPaperUnixDialog *dialog)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +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;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
set_margins_from_printer (dialog, printer);
|
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (dialog->printer_combo), 0);
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
margins_from_printer_changed (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
2020-06-14 12:30:54 +00:00
|
|
|
guint selected;
|
2009-07-10 09:28:31 +00:00
|
|
|
GtkPrinter *printer;
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
if (dialog->request_details_tag)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-12 16:52:47 +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;
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
selected = gtk_drop_down_get_selected (GTK_DROP_DOWN (dialog->printer_combo));
|
|
|
|
if (selected != 0)
|
2009-07-10 09:28:31 +00:00
|
|
|
{
|
2020-06-14 12:30:54 +00:00
|
|
|
GListModel *model;
|
|
|
|
|
|
|
|
model = gtk_drop_down_get_model (GTK_DROP_DOWN (dialog->printer_combo));
|
|
|
|
printer = g_list_model_get_item (model, selected);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
if (printer)
|
2020-06-12 16:52:47 +00:00
|
|
|
{
|
|
|
|
if (gtk_printer_has_details (printer))
|
|
|
|
{
|
|
|
|
set_margins_from_printer (dialog, printer);
|
2020-06-14 12:30:54 +00:00
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (dialog->printer_combo), 0);
|
2020-06-12 16:52:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dialog->request_details_printer = g_object_ref (printer);
|
|
|
|
dialog->request_details_tag =
|
|
|
|
g_signal_connect (printer, "details-acquired",
|
|
|
|
G_CALLBACK (get_margins_finished_callback), dialog);
|
|
|
|
gtk_printer_request_details (printer);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (printer);
|
|
|
|
}
|
2009-07-10 09:28:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
2020-07-24 18:40:36 +00:00
|
|
|
wrap_in_frame (const char *label,
|
2009-07-10 09:28:31 +00:00
|
|
|
GtkWidget *child)
|
|
|
|
{
|
2011-06-07 02:31:31 +00:00
|
|
|
GtkWidget *frame, *label_widget;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *bold_text;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
label_widget = gtk_label_new (NULL);
|
2011-05-21 17:30:33 +00:00
|
|
|
gtk_widget_set_halign (label_widget, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label_widget, GTK_ALIGN_CENTER);
|
2009-07-10 09:28:31 +00:00
|
|
|
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);
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2020-06-12 12:46:18 +00:00
|
|
|
gtk_box_append (GTK_BOX (frame), label_widget);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2013-11-14 22:31:17 +00:00
|
|
|
gtk_widget_set_margin_start (child, 12);
|
2011-06-07 02:31:31 +00:00
|
|
|
gtk_widget_set_halign (child, GTK_ALIGN_FILL);
|
|
|
|
gtk_widget_set_valign (child, GTK_ALIGN_FILL);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 12:46:18 +00:00
|
|
|
gtk_box_append (GTK_BOX (frame), child);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
static void
|
|
|
|
setup_item (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
gtk_list_item_set_child (item, gtk_editable_label_new (""));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
label_changed (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
const char *new_text;
|
|
|
|
|
|
|
|
page_setup = gtk_list_item_get_item (item);
|
|
|
|
|
|
|
|
new_text = gtk_editable_get_text (GTK_EDITABLE (object));
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
state_changed (GtkWidget *item,
|
|
|
|
GtkStateFlags old_state,
|
|
|
|
GtkWidget *label)
|
|
|
|
{
|
|
|
|
gboolean selected;
|
|
|
|
|
|
|
|
selected = (gtk_widget_get_state_flags (item) & GTK_STATE_FLAG_SELECTED) != 0;
|
|
|
|
gtk_editable_set_editable (GTK_EDITABLE (label), selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_item (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
page_setup = gtk_list_item_get_item (item);
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
|
|
|
|
paper_size = gtk_page_setup_get_paper_size (page_setup);
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (label),
|
|
|
|
gtk_paper_size_get_display_name (paper_size));
|
|
|
|
g_signal_connect (label, "notify::text",
|
|
|
|
G_CALLBACK (label_changed), item);
|
|
|
|
g_signal_connect (gtk_widget_get_parent (label), "state-flags-changed",
|
|
|
|
G_CALLBACK (state_changed), label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unbind_item (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
g_signal_handlers_disconnect_by_func (label, label_changed, item);
|
|
|
|
g_signal_handlers_disconnect_by_func (gtk_widget_get_parent (label), state_changed, label);
|
|
|
|
}
|
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
static void
|
|
|
|
setup_printer_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_printer_item (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkPrinter *printer;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
printer = gtk_list_item_get_item (item);
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), gtk_printer_get_name (printer));
|
|
|
|
}
|
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
static void
|
|
|
|
populate_dialog (GtkCustomPaperUnixDialog *dialog)
|
|
|
|
{
|
2010-06-03 07:36:39 +00:00
|
|
|
GtkDialog *cpu_dialog = GTK_DIALOG (dialog);
|
2016-10-09 00:32:00 +00:00
|
|
|
GtkWidget *content_area;
|
2011-09-28 01:02:19 +00:00
|
|
|
GtkWidget *grid, *label, *widget, *frame, *combo;
|
2020-06-12 18:11:16 +00:00
|
|
|
GtkWidget *hbox, *vbox, *listview, *scrolled, *toolbar, *button;
|
2009-07-10 09:28:31 +00:00
|
|
|
GtkUnit user_units;
|
2020-08-31 21:06:48 +00:00
|
|
|
GtkSelectionModel *model;
|
2020-06-12 18:11:16 +00:00
|
|
|
GtkListItemFactory *factory;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2010-06-03 07:36:39 +00:00
|
|
|
content_area = gtk_dialog_get_content_area (cpu_dialog);
|
|
|
|
gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (hbox, 20);
|
|
|
|
gtk_widget_set_margin_end (hbox, 20);
|
|
|
|
gtk_widget_set_margin_top (hbox, 20);
|
|
|
|
gtk_widget_set_margin_bottom (hbox, 20);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (content_area), hbox);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2011-06-02 01:36:50 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
scrolled = gtk_scrolled_window_new ();
|
2020-06-12 12:46:18 +00:00
|
|
|
gtk_widget_set_vexpand (scrolled, TRUE);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
|
2011-06-02 01:36:50 +00:00
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
2020-04-17 03:25:06 +00:00
|
|
|
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (scrolled), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), scrolled);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (scrolled);
|
|
|
|
|
2020-08-31 21:06:48 +00:00
|
|
|
model = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (dialog->custom_paper_list))));
|
2020-06-12 18:11:16 +00:00
|
|
|
g_signal_connect (model, "notify::selected", G_CALLBACK (selected_custom_paper_changed), dialog);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_item), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
|
|
|
|
g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
|
2020-07-26 22:27:23 +00:00
|
|
|
|
2020-09-01 16:24:06 +00:00
|
|
|
listview = gtk_list_view_new (model, factory);
|
2020-07-26 22:27:23 +00:00
|
|
|
gtk_widget_set_size_request (listview, 140, -1);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
dialog->listview = listview;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled), listview);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-02-03 00:10:55 +00:00
|
|
|
toolbar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-04-10 16:08:16 +00:00
|
|
|
gtk_widget_add_css_class (toolbar, "linked");
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), toolbar);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-02-03 00:10:55 +00:00
|
|
|
button = gtk_button_new_from_icon_name ("list-add-symbolic");
|
|
|
|
g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_custom_paper), dialog);
|
2011-06-02 01:36:50 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (toolbar), button);
|
2011-06-02 01:36:50 +00:00
|
|
|
|
2020-02-03 00:10:55 +00:00
|
|
|
button = gtk_button_new_from_icon_name ("list-remove-symbolic");
|
|
|
|
g_signal_connect_swapped (button, "clicked", G_CALLBACK (remove_custom_paper), dialog);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (toolbar), button);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
user_units = _gtk_print_get_default_user_units ();
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->values_box = vbox;
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2011-09-28 01:02:19 +00:00
|
|
|
grid = gtk_grid_new ();
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Width:"));
|
2011-05-21 17:30:33 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2014-01-28 04:29:34 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (label);
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
widget = new_unit_widget (dialog, user_units, label);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->width_widget = widget;
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), widget, 1, 0, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (widget);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Height:"));
|
2011-05-21 17:30:33 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2014-01-28 04:29:34 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (label);
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
widget = new_unit_widget (dialog, user_units, label);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->height_widget = widget;
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), widget, 1, 1, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (widget);
|
|
|
|
|
2011-09-28 01:02:19 +00:00
|
|
|
frame = wrap_in_frame (_("Paper Size"), grid);
|
|
|
|
gtk_widget_show (grid);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2011-09-28 01:02:19 +00:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Top:"));
|
2011-05-21 17:30:33 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2014-01-28 04:29:34 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
widget = new_unit_widget (dialog, user_units, label);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->top_widget = widget;
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), widget, 1, 0, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (widget);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Bottom:"));
|
2011-05-21 17:30:33 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2014-01-28 04:29:34 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
widget = new_unit_widget (dialog, user_units, label);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->bottom_widget = widget;
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), widget, 1, 1, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (widget);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Left:"));
|
2011-05-21 17:30:33 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2014-01-28 04:29:34 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
widget = new_unit_widget (dialog, user_units, label);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->left_widget = widget;
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), widget, 1, 2, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (widget);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Right:"));
|
2011-05-21 17:30:33 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2014-01-28 04:29:34 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
widget = new_unit_widget (dialog, user_units, label);
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->right_widget = widget;
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), widget, 1, 3, 1, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (widget);
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2011-09-28 01:02:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), hbox, 0, 4, 2, 1);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2020-07-26 13:34:08 +00:00
|
|
|
combo = gtk_drop_down_new (g_object_ref (dialog->printer_list), NULL);
|
2020-06-14 12:30:54 +00:00
|
|
|
|
|
|
|
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 (combo), factory);
|
|
|
|
g_object_unref (factory);
|
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->printer_combo = combo;
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-12 16:52:47 +00:00
|
|
|
dialog->printer_inserted_tag =
|
2020-06-14 12:30:54 +00:00
|
|
|
g_signal_connect_swapped (dialog->printer_list, "items-changed",
|
2020-06-12 16:52:47 +00:00
|
|
|
G_CALLBACK (update_combo_sensitivity_from_printers), dialog);
|
2009-07-10 09:28:31 +00:00
|
|
|
update_combo_sensitivity_from_printers (dialog);
|
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (combo), 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), combo);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2020-06-14 12:30:54 +00:00
|
|
|
g_signal_connect_swapped (combo, "notify::selected",
|
2020-06-12 16:52:47 +00:00
|
|
|
G_CALLBACK (margins_from_printer_changed), dialog);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2011-09-28 01:02:19 +00:00
|
|
|
frame = wrap_in_frame (_("Paper Margins"), grid);
|
|
|
|
gtk_widget_show (grid);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
update_custom_widgets_from_list (dialog);
|
|
|
|
|
2020-06-12 18:11:16 +00:00
|
|
|
if (g_list_model_get_n_items (G_LIST_MODEL (dialog->custom_paper_list)) == 0)
|
|
|
|
add_custom_paper (dialog);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
|
|
|
load_print_backends (dialog);
|
|
|
|
}
|