2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2006-04-21 15:09:32 +00:00
|
|
|
* gtkpagesetup.c: Page Setup
|
|
|
|
* Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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/>.
|
2006-04-21 15:09:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkpagesetup.h"
|
2006-04-23 05:48:04 +00:00
|
|
|
#include "gtkprintutils.h"
|
2007-04-29 06:23:58 +00:00
|
|
|
#include "gtkprintoperation.h" /* for GtkPrintError */
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtktypebuiltins.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2010-11-08 17:36:38 +00:00
|
|
|
/**
|
2021-02-27 15:53:36 +00:00
|
|
|
* GtkPageSetup:
|
|
|
|
*
|
|
|
|
* A `GtkPageSetup` object stores the page size, orientation and margins.
|
2010-11-08 17:36:38 +00:00
|
|
|
*
|
|
|
|
* The idea is that you can get one of these from the page setup dialog
|
2021-02-27 15:53:36 +00:00
|
|
|
* and then pass it to the `GtkPrintOperation` when printing.
|
|
|
|
* The benefit of splitting this out of the `GtkPrintSettings` is that
|
2010-11-08 17:36:38 +00:00
|
|
|
* these affect the actual layout of the page, and thus need to be set
|
|
|
|
* long before user prints.
|
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* ## Margins
|
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
* The margins specified in this object are the “print margins”, i.e. the
|
2010-11-08 17:36:38 +00:00
|
|
|
* parts of the page that the printer cannot print on. These are different
|
|
|
|
* from the layout margins that a word processor uses; they are typically
|
2021-02-27 15:53:36 +00:00
|
|
|
* used to determine the minimal size for the layout margins.
|
2010-11-08 17:36:38 +00:00
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* To obtain a `GtkPageSetup` use [ctor@Gtk.PageSetup.new] to get the defaults,
|
|
|
|
* or use [func@Gtk.print_run_page_setup_dialog] to show the page setup dialog
|
2010-11-08 17:36:38 +00:00
|
|
|
* and receive the resulting page setup.
|
|
|
|
*
|
2014-02-04 21:57:57 +00:00
|
|
|
* ## A page setup dialog
|
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* ```c
|
2010-11-08 17:36:38 +00:00
|
|
|
* static GtkPrintSettings *settings = NULL;
|
|
|
|
* static GtkPageSetup *page_setup = NULL;
|
|
|
|
*
|
|
|
|
* static void
|
|
|
|
* do_page_setup (void)
|
|
|
|
* {
|
|
|
|
* GtkPageSetup *new_page_setup;
|
|
|
|
*
|
|
|
|
* if (settings == NULL)
|
2014-02-09 22:24:06 +00:00
|
|
|
* settings = gtk_print_settings_new ();
|
2010-11-08 17:36:38 +00:00
|
|
|
*
|
|
|
|
* new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window),
|
|
|
|
* page_setup, settings);
|
|
|
|
*
|
|
|
|
* if (page_setup)
|
|
|
|
* g_object_unref (page_setup);
|
|
|
|
*
|
|
|
|
* page_setup = new_page_setup;
|
|
|
|
* }
|
2021-02-27 15:53:36 +00:00
|
|
|
* ```
|
2010-11-08 17:36:38 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-29 06:23:58 +00:00
|
|
|
#define KEYFILE_GROUP_NAME "Page Setup"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
typedef struct _GtkPageSetupClass GtkPageSetupClass;
|
|
|
|
|
|
|
|
#define GTK_IS_PAGE_SETUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PAGE_SETUP))
|
|
|
|
#define GTK_PAGE_SETUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PAGE_SETUP, GtkPageSetupClass))
|
|
|
|
#define GTK_PAGE_SETUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PAGE_SETUP, GtkPageSetupClass))
|
|
|
|
|
|
|
|
struct _GtkPageSetup
|
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
|
|
GtkPageOrientation orientation;
|
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
/* These are stored in mm */
|
|
|
|
double top_margin, bottom_margin, left_margin, right_margin;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkPageSetupClass
|
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkPageSetup, gtk_page_setup, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_page_setup_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkPageSetup *setup = GTK_PAGE_SETUP (object);
|
|
|
|
|
|
|
|
gtk_paper_size_free (setup->paper_size);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_page_setup_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_page_setup_init (GtkPageSetup *setup)
|
|
|
|
{
|
|
|
|
setup->paper_size = gtk_paper_size_new (NULL);
|
|
|
|
setup->orientation = GTK_PAGE_ORIENTATION_PORTRAIT;
|
|
|
|
setup->top_margin = gtk_paper_size_get_default_top_margin (setup->paper_size, GTK_UNIT_MM);
|
|
|
|
setup->bottom_margin = gtk_paper_size_get_default_bottom_margin (setup->paper_size, GTK_UNIT_MM);
|
|
|
|
setup->left_margin = gtk_paper_size_get_default_left_margin (setup->paper_size, GTK_UNIT_MM);
|
|
|
|
setup->right_margin = gtk_paper_size_get_default_right_margin (setup->paper_size, GTK_UNIT_MM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_page_setup_class_init (GtkPageSetupClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *)class;
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_page_setup_finalize;
|
|
|
|
}
|
2006-04-23 05:48:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_page_setup_new:
|
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* Creates a new `GtkPageSetup`.
|
|
|
|
*
|
|
|
|
* Returns: a new `GtkPageSetup`.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPageSetup *
|
|
|
|
gtk_page_setup_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_PAGE_SETUP, NULL);
|
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_copy:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @other: the `GtkPageSetup` to copy
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* Copies a `GtkPageSetup`.
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: (transfer full): a copy of @other
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPageSetup *
|
|
|
|
gtk_page_setup_copy (GtkPageSetup *other)
|
|
|
|
{
|
|
|
|
GtkPageSetup *copy;
|
|
|
|
|
|
|
|
copy = gtk_page_setup_new ();
|
|
|
|
copy->orientation = other->orientation;
|
2008-03-12 16:37:51 +00:00
|
|
|
gtk_paper_size_free (copy->paper_size);
|
2006-04-21 15:09:32 +00:00
|
|
|
copy->paper_size = gtk_paper_size_copy (other->paper_size);
|
|
|
|
copy->top_margin = other->top_margin;
|
|
|
|
copy->bottom_margin = other->bottom_margin;
|
|
|
|
copy->left_margin = other->left_margin;
|
|
|
|
copy->right_margin = other->right_margin;
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_orientation:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
|
|
|
*
|
|
|
|
* Gets the page orientation of the `GtkPageSetup`.
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the page orientation
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPageOrientation
|
|
|
|
gtk_page_setup_get_orientation (GtkPageSetup *setup)
|
|
|
|
{
|
|
|
|
return setup->orientation;
|
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_set_orientation:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2021-05-20 13:17:04 +00:00
|
|
|
* @orientation: a `GtkPageOrientation` value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Sets the page orientation of the `GtkPageSetup`.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
void
|
2006-04-23 05:48:04 +00:00
|
|
|
gtk_page_setup_set_orientation (GtkPageSetup *setup,
|
|
|
|
GtkPageOrientation orientation)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
setup->orientation = orientation;
|
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_paper_size:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
|
|
|
*
|
|
|
|
* Gets the paper size of the `GtkPageSetup`.
|
|
|
|
*
|
2014-05-26 16:42:23 +00:00
|
|
|
* Returns: (transfer none): the paper size
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPaperSize *
|
|
|
|
gtk_page_setup_get_paper_size (GtkPageSetup *setup)
|
|
|
|
{
|
2006-12-04 17:54:48 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), NULL);
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
return setup->paper_size;
|
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_set_paper_size:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2021-05-20 13:17:04 +00:00
|
|
|
* @size: a `GtkPaperSize`
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Sets the paper size of the `GtkPageSetup` without
|
|
|
|
* changing the margins.
|
|
|
|
*
|
|
|
|
* See [method@Gtk.PageSetup.set_paper_size_and_default_margins].
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
void
|
|
|
|
gtk_page_setup_set_paper_size (GtkPageSetup *setup,
|
|
|
|
GtkPaperSize *size)
|
|
|
|
{
|
2006-12-04 17:54:48 +00:00
|
|
|
GtkPaperSize *old_size;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_PAGE_SETUP (setup));
|
|
|
|
g_return_if_fail (size != NULL);
|
|
|
|
|
|
|
|
old_size = setup->paper_size;
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
setup->paper_size = gtk_paper_size_copy (size);
|
2006-12-04 17:54:48 +00:00
|
|
|
|
|
|
|
if (old_size)
|
|
|
|
gtk_paper_size_free (old_size);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_set_paper_size_and_default_margins:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2021-05-20 13:17:04 +00:00
|
|
|
* @size: a `GtkPaperSize`
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Sets the paper size of the `GtkPageSetup` and modifies
|
2006-04-23 05:48:04 +00:00
|
|
|
* the margins according to the new paper size.
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
void
|
|
|
|
gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
|
|
|
|
GtkPaperSize *size)
|
|
|
|
{
|
2007-01-23 21:28:29 +00:00
|
|
|
gtk_page_setup_set_paper_size (setup, size);
|
2006-04-21 15:09:32 +00:00
|
|
|
setup->top_margin = gtk_paper_size_get_default_top_margin (setup->paper_size, GTK_UNIT_MM);
|
|
|
|
setup->bottom_margin = gtk_paper_size_get_default_bottom_margin (setup->paper_size, GTK_UNIT_MM);
|
|
|
|
setup->left_margin = gtk_paper_size_get_default_left_margin (setup->paper_size, GTK_UNIT_MM);
|
|
|
|
setup->right_margin = gtk_paper_size_get_default_right_margin (setup->paper_size, GTK_UNIT_MM);
|
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_top_margin:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @unit: the unit for the return value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2006-04-23 05:48:04 +00:00
|
|
|
* Gets the top margin in units of @unit.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the top margin
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
double
|
2006-04-21 15:09:32 +00:00
|
|
|
gtk_page_setup_get_top_margin (GtkPageSetup *setup,
|
|
|
|
GtkUnit unit)
|
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
return _gtk_print_convert_from_mm (setup->top_margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_set_top_margin:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @margin: the new top margin in units of @unit
|
|
|
|
* @unit: the units for @margin
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Sets the top margin of the `GtkPageSetup`.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
void
|
|
|
|
gtk_page_setup_set_top_margin (GtkPageSetup *setup,
|
2020-07-24 20:32:16 +00:00
|
|
|
double margin,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkUnit unit)
|
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
setup->top_margin = _gtk_print_convert_to_mm (margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_bottom_margin:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @unit: the unit for the return value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2006-04-23 05:48:04 +00:00
|
|
|
* Gets the bottom margin in units of @unit.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the bottom margin
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
double
|
2006-04-21 15:09:32 +00:00
|
|
|
gtk_page_setup_get_bottom_margin (GtkPageSetup *setup,
|
|
|
|
GtkUnit unit)
|
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
return _gtk_print_convert_from_mm (setup->bottom_margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_set_bottom_margin:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @margin: the new bottom margin in units of @unit
|
|
|
|
* @unit: the units for @margin
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Sets the bottom margin of the `GtkPageSetup`.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
void
|
|
|
|
gtk_page_setup_set_bottom_margin (GtkPageSetup *setup,
|
2020-07-24 20:32:16 +00:00
|
|
|
double margin,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkUnit unit)
|
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
setup->bottom_margin = _gtk_print_convert_to_mm (margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_left_margin:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @unit: the unit for the return value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2006-04-23 05:48:04 +00:00
|
|
|
* Gets the left margin in units of @unit.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the left margin
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
double
|
2006-04-23 05:48:04 +00:00
|
|
|
gtk_page_setup_get_left_margin (GtkPageSetup *setup,
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
return _gtk_print_convert_from_mm (setup->left_margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_set_left_margin:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @margin: the new left margin in units of @unit
|
|
|
|
* @unit: the units for @margin
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Sets the left margin of the `GtkPageSetup`.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
void
|
2006-04-23 05:48:04 +00:00
|
|
|
gtk_page_setup_set_left_margin (GtkPageSetup *setup,
|
2020-07-24 20:32:16 +00:00
|
|
|
double margin,
|
2006-04-23 05:48:04 +00:00
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
setup->left_margin = _gtk_print_convert_to_mm (margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_right_margin:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @unit: the unit for the return value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2006-04-23 05:48:04 +00:00
|
|
|
* Gets the right margin in units of @unit.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the right margin
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
double
|
2006-04-23 05:48:04 +00:00
|
|
|
gtk_page_setup_get_right_margin (GtkPageSetup *setup,
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
return _gtk_print_convert_from_mm (setup->right_margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_set_right_margin:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @margin: the new right margin in units of @unit
|
|
|
|
* @unit: the units for @margin
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Sets the right margin of the `GtkPageSetup`.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
void
|
2006-04-23 05:48:04 +00:00
|
|
|
gtk_page_setup_set_right_margin (GtkPageSetup *setup,
|
2020-07-24 20:32:16 +00:00
|
|
|
double margin,
|
2006-04-23 05:48:04 +00:00
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
setup->right_margin = _gtk_print_convert_to_mm (margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_paper_width:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @unit: the unit for the return value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2006-04-23 05:48:04 +00:00
|
|
|
* Returns the paper width in units of @unit.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Note that this function takes orientation,
|
|
|
|
* but not margins into consideration.
|
|
|
|
* See [method@Gtk.PageSetup.get_page_width].
|
2006-04-23 05:48:04 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the paper width.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
double
|
2006-04-21 15:09:32 +00:00
|
|
|
gtk_page_setup_get_paper_width (GtkPageSetup *setup,
|
|
|
|
GtkUnit unit)
|
|
|
|
{
|
|
|
|
if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
|
|
|
|
setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
|
|
|
|
return gtk_paper_size_get_width (setup->paper_size, unit);
|
|
|
|
else
|
|
|
|
return gtk_paper_size_get_height (setup->paper_size, unit);
|
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_paper_height:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @unit: the unit for the return value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2006-04-23 05:48:04 +00:00
|
|
|
* Returns the paper height in units of @unit.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Note that this function takes orientation,
|
|
|
|
* but not margins into consideration.
|
|
|
|
* See [method@Gtk.PageSetup.get_page_height].
|
2006-04-23 05:48:04 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the paper height.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
double
|
2006-04-23 05:48:04 +00:00
|
|
|
gtk_page_setup_get_paper_height (GtkPageSetup *setup,
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
|
|
|
|
setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
|
|
|
|
return gtk_paper_size_get_height (setup->paper_size, unit);
|
|
|
|
else
|
|
|
|
return gtk_paper_size_get_width (setup->paper_size, unit);
|
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_page_width:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @unit: the unit for the return value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2006-04-23 05:48:04 +00:00
|
|
|
* Returns the page width in units of @unit.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Note that this function takes orientation
|
|
|
|
* and margins into consideration.
|
|
|
|
* See [method@Gtk.PageSetup.get_paper_width].
|
2006-04-23 05:48:04 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the page width.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
double
|
2006-04-23 05:48:04 +00:00
|
|
|
gtk_page_setup_get_page_width (GtkPageSetup *setup,
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double width;
|
2014-12-18 15:25:50 +00:00
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM);
|
2014-12-18 15:25:50 +00:00
|
|
|
if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
|
|
|
|
setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
|
|
|
|
width -= setup->left_margin + setup->right_margin;
|
|
|
|
else
|
|
|
|
width -= setup->top_margin + setup->bottom_margin;
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
return _gtk_print_convert_from_mm (width, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_get_page_height:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2006-04-23 05:48:04 +00:00
|
|
|
* @unit: the unit for the return value
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2006-04-23 05:48:04 +00:00
|
|
|
* Returns the page height in units of @unit.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* Note that this function takes orientation
|
|
|
|
* and margins into consideration.
|
|
|
|
* See [method@Gtk.PageSetup.get_paper_height].
|
2006-04-23 05:48:04 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the page height.
|
2006-04-23 05:48:04 +00:00
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
double
|
2006-04-23 05:48:04 +00:00
|
|
|
gtk_page_setup_get_page_height (GtkPageSetup *setup,
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double height;
|
2014-12-18 15:25:50 +00:00
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM);
|
2014-12-18 15:25:50 +00:00
|
|
|
if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
|
|
|
|
setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
|
|
|
|
height -= setup->top_margin + setup->bottom_margin;
|
|
|
|
else
|
|
|
|
height -= setup->left_margin + setup->right_margin;
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
return _gtk_print_convert_from_mm (height, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2007-12-14 09:02:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_load_file:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2011-01-18 05:42:31 +00:00
|
|
|
* @file_name: (type filename): the filename to read the page setup from
|
2021-05-21 00:45:06 +00:00
|
|
|
* @error: (nullable): return location for an error
|
2007-12-14 09:02:54 +00:00
|
|
|
*
|
|
|
|
* Reads the page setup from the file @file_name.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
|
|
|
* See [method@Gtk.PageSetup.to_file].
|
2007-12-14 09:02:54 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: %TRUE on success
|
2007-12-14 09:02:54 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_page_setup_load_file (GtkPageSetup *setup,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *file_name,
|
2007-12-14 09:02:54 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gboolean retval = FALSE;
|
|
|
|
GKeyFile *key_file;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
|
|
|
|
g_return_val_if_fail (file_name != NULL, FALSE);
|
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
|
|
|
|
|
|
|
if (g_key_file_load_from_file (key_file, file_name, 0, error) &&
|
|
|
|
gtk_page_setup_load_key_file (setup, key_file, NULL, error))
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2007-04-29 06:23:58 +00:00
|
|
|
/**
|
|
|
|
* gtk_page_setup_new_from_file:
|
2011-01-18 05:42:31 +00:00
|
|
|
* @file_name: (type filename): the filename to read the page setup from
|
2021-05-21 00:45:06 +00:00
|
|
|
* @error: (nullable): return location for an error
|
2007-04-29 06:23:58 +00:00
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* Reads the page setup from the file @file_name.
|
|
|
|
*
|
|
|
|
* Returns a new `GtkPageSetup` object with the restored
|
|
|
|
* page setup, or %NULL if an error occurred.
|
|
|
|
* See [method@Gtk.PageSetup.to_file].
|
|
|
|
*
|
|
|
|
* Returns: the restored `GtkPageSetup`
|
2007-04-29 06:23:58 +00:00
|
|
|
*/
|
|
|
|
GtkPageSetup *
|
2020-07-24 18:40:36 +00:00
|
|
|
gtk_page_setup_new_from_file (const char *file_name,
|
2007-04-29 06:23:58 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2007-12-14 09:02:54 +00:00
|
|
|
GtkPageSetup *setup = gtk_page_setup_new ();
|
2007-04-29 06:23:58 +00:00
|
|
|
|
2007-12-14 09:02:54 +00:00
|
|
|
if (!gtk_page_setup_load_file (setup, file_name, error))
|
2007-04-29 06:23:58 +00:00
|
|
|
{
|
2007-12-14 09:02:54 +00:00
|
|
|
g_object_unref (setup);
|
|
|
|
setup = NULL;
|
2007-04-29 06:23:58 +00:00
|
|
|
}
|
|
|
|
|
2007-12-14 09:02:54 +00:00
|
|
|
return setup;
|
2007-04-29 06:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* something like this should really be in gobject! */
|
|
|
|
static guint
|
|
|
|
string_to_enum (GType type,
|
|
|
|
const char *enum_string)
|
|
|
|
{
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
const GEnumValue *value;
|
|
|
|
guint retval = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (enum_string != NULL, 0);
|
|
|
|
|
|
|
|
enum_class = g_type_class_ref (type);
|
|
|
|
value = g_enum_get_value_by_nick (enum_class, enum_string);
|
|
|
|
if (value)
|
|
|
|
retval = value->value;
|
|
|
|
|
|
|
|
g_type_class_unref (enum_class);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-12-14 09:02:54 +00:00
|
|
|
* gtk_page_setup_load_key_file:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
|
|
|
* @key_file: the `GKeyFile` to retrieve the page_setup from
|
2021-05-21 00:45:06 +00:00
|
|
|
* @group_name: (nullable): the name of the group in the key_file to read
|
2021-05-18 21:05:26 +00:00
|
|
|
* to use the default name “Page Setup”
|
2021-05-21 00:45:06 +00:00
|
|
|
* @error: (nullable): return location for an error
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2007-04-29 06:23:58 +00:00
|
|
|
* Reads the page setup from the group @group_name in the key file
|
2007-12-14 09:02:54 +00:00
|
|
|
* @key_file.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: %TRUE on success
|
2007-04-29 06:23:58 +00:00
|
|
|
*/
|
2007-12-14 09:02:54 +00:00
|
|
|
gboolean
|
|
|
|
gtk_page_setup_load_key_file (GtkPageSetup *setup,
|
|
|
|
GKeyFile *key_file,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *group_name,
|
2007-12-14 09:02:54 +00:00
|
|
|
GError **error)
|
2007-04-29 06:23:58 +00:00
|
|
|
{
|
|
|
|
GtkPaperSize *paper_size;
|
2020-07-24 20:32:16 +00:00
|
|
|
double top, bottom, left, right;
|
2007-04-29 06:23:58 +00:00
|
|
|
char *orientation = NULL, *freeme = NULL;
|
2007-12-14 09:02:54 +00:00
|
|
|
gboolean retval = FALSE;
|
2007-04-29 06:23:58 +00:00
|
|
|
GError *err = NULL;
|
|
|
|
|
2007-12-14 09:02:54 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
|
|
|
|
g_return_val_if_fail (key_file != NULL, FALSE);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
|
|
|
if (!group_name)
|
|
|
|
group_name = KEYFILE_GROUP_NAME;
|
|
|
|
|
|
|
|
if (!g_key_file_has_group (key_file, group_name))
|
|
|
|
{
|
2008-06-19 12:47:48 +00:00
|
|
|
g_set_error_literal (error,
|
|
|
|
GTK_PRINT_ERROR,
|
|
|
|
GTK_PRINT_ERROR_INVALID_FILE,
|
|
|
|
_("Not a valid page setup file"));
|
2007-04-29 06:23:58 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_DOUBLE(kf, group, name, v) \
|
|
|
|
v = g_key_file_get_double (kf, group, name, &err); \
|
|
|
|
if (err != NULL) \
|
|
|
|
{ \
|
|
|
|
g_propagate_error (error, err);\
|
|
|
|
goto out;\
|
|
|
|
}
|
|
|
|
|
|
|
|
GET_DOUBLE (key_file, group_name, "MarginTop", top);
|
|
|
|
GET_DOUBLE (key_file, group_name, "MarginBottom", bottom);
|
|
|
|
GET_DOUBLE (key_file, group_name, "MarginLeft", left);
|
|
|
|
GET_DOUBLE (key_file, group_name, "MarginRight", right);
|
|
|
|
|
|
|
|
#undef GET_DOUBLE
|
|
|
|
|
|
|
|
paper_size = gtk_paper_size_new_from_key_file (key_file, group_name, &err);
|
|
|
|
if (!paper_size)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, err);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-12-14 09:02:54 +00:00
|
|
|
gtk_page_setup_set_paper_size (setup, paper_size);
|
2007-04-29 06:23:58 +00:00
|
|
|
gtk_paper_size_free (paper_size);
|
|
|
|
|
2007-12-14 09:02:54 +00:00
|
|
|
gtk_page_setup_set_top_margin (setup, top, GTK_UNIT_MM);
|
|
|
|
gtk_page_setup_set_bottom_margin (setup, bottom, GTK_UNIT_MM);
|
|
|
|
gtk_page_setup_set_left_margin (setup, left, GTK_UNIT_MM);
|
|
|
|
gtk_page_setup_set_right_margin (setup, right, GTK_UNIT_MM);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
|
|
|
orientation = g_key_file_get_string (key_file, group_name,
|
|
|
|
"Orientation", NULL);
|
|
|
|
if (orientation)
|
|
|
|
{
|
2007-12-14 09:02:54 +00:00
|
|
|
gtk_page_setup_set_orientation (setup,
|
2007-04-29 06:23:58 +00:00
|
|
|
string_to_enum (GTK_TYPE_PAGE_ORIENTATION,
|
|
|
|
orientation));
|
|
|
|
g_free (orientation);
|
|
|
|
}
|
|
|
|
|
2007-12-14 09:02:54 +00:00
|
|
|
retval = TRUE;
|
|
|
|
|
2007-04-29 06:23:58 +00:00
|
|
|
out:
|
|
|
|
g_free (freeme);
|
2007-12-14 09:02:54 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_page_setup_new_from_key_file:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @key_file: the `GKeyFile` to retrieve the page_setup from
|
2021-05-21 00:45:06 +00:00
|
|
|
* @group_name: (nullable): the name of the group in the key_file to read
|
2021-05-18 21:05:26 +00:00
|
|
|
* to use the default name “Page Setup”
|
2021-05-21 00:45:06 +00:00
|
|
|
* @error: (nullable): return location for an error
|
2007-12-14 09:02:54 +00:00
|
|
|
*
|
|
|
|
* Reads the page setup from the group @group_name in the key file
|
2021-02-27 15:53:36 +00:00
|
|
|
* @key_file.
|
|
|
|
*
|
|
|
|
* Returns a new `GtkPageSetup` object with the restored
|
2007-12-14 09:02:54 +00:00
|
|
|
* page setup, or %NULL if an error occurred.
|
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* Returns: the restored `GtkPageSetup`
|
2007-12-14 09:02:54 +00:00
|
|
|
*/
|
|
|
|
GtkPageSetup *
|
|
|
|
gtk_page_setup_new_from_key_file (GKeyFile *key_file,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *group_name,
|
2007-12-14 09:02:54 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GtkPageSetup *setup = gtk_page_setup_new ();
|
|
|
|
|
|
|
|
if (!gtk_page_setup_load_key_file (setup, key_file, group_name, error))
|
|
|
|
{
|
|
|
|
g_object_unref (setup);
|
|
|
|
setup = NULL;
|
|
|
|
}
|
2007-04-29 06:23:58 +00:00
|
|
|
|
2007-12-14 09:02:54 +00:00
|
|
|
return setup;
|
2007-04-29 06:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_page_setup_to_file:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2011-01-18 05:42:31 +00:00
|
|
|
* @file_name: (type filename): the file to save to
|
2021-05-21 00:45:06 +00:00
|
|
|
* @error: (nullable): return location for errors
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2007-05-26 18:53:50 +00:00
|
|
|
* This function saves the information from @setup to @file_name.
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: %TRUE on success
|
2007-04-29 06:23:58 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2007-05-26 18:53:50 +00:00
|
|
|
gtk_page_setup_to_file (GtkPageSetup *setup,
|
2007-04-29 06:23:58 +00:00
|
|
|
const char *file_name,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GKeyFile *key_file;
|
|
|
|
gboolean retval = FALSE;
|
|
|
|
char *data = NULL;
|
|
|
|
gsize len;
|
|
|
|
|
2007-05-26 18:53:50 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
|
2007-04-29 06:23:58 +00:00
|
|
|
g_return_val_if_fail (file_name != NULL, FALSE);
|
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
2007-05-26 18:53:50 +00:00
|
|
|
gtk_page_setup_to_key_file (setup, key_file, NULL);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
|
|
|
data = g_key_file_to_data (key_file, &len, error);
|
|
|
|
if (!data)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retval = g_file_set_contents (file_name, data, len, error);
|
|
|
|
|
|
|
|
out:
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* something like this should really be in gobject! */
|
|
|
|
static char *
|
|
|
|
enum_to_string (GType type,
|
|
|
|
guint enum_value)
|
|
|
|
{
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *value;
|
|
|
|
char *retval = NULL;
|
|
|
|
|
|
|
|
enum_class = g_type_class_ref (type);
|
|
|
|
|
|
|
|
value = g_enum_get_value (enum_class, enum_value);
|
|
|
|
if (value)
|
|
|
|
retval = g_strdup (value->value_nick);
|
|
|
|
|
|
|
|
g_type_class_unref (enum_class);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_page_setup_to_key_file:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
|
|
|
* @key_file: the `GKeyFile` to save the page setup to
|
2018-11-18 12:36:50 +00:00
|
|
|
* @group_name: (nullable): the group to add the settings to in @key_file,
|
2021-05-18 21:05:26 +00:00
|
|
|
* or %NULL to use the default name “Page Setup”
|
2021-02-27 15:53:36 +00:00
|
|
|
*
|
2007-05-26 18:53:50 +00:00
|
|
|
* This function adds the page setup from @setup to @key_file.
|
2007-04-29 06:23:58 +00:00
|
|
|
*/
|
|
|
|
void
|
2007-05-26 18:53:50 +00:00
|
|
|
gtk_page_setup_to_key_file (GtkPageSetup *setup,
|
2007-04-29 06:23:58 +00:00
|
|
|
GKeyFile *key_file,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *group_name)
|
2007-04-29 06:23:58 +00:00
|
|
|
{
|
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
char *orientation;
|
|
|
|
|
2007-05-26 18:53:50 +00:00
|
|
|
g_return_if_fail (GTK_IS_PAGE_SETUP (setup));
|
2007-04-29 06:23:58 +00:00
|
|
|
g_return_if_fail (key_file != NULL);
|
|
|
|
|
|
|
|
if (!group_name)
|
|
|
|
group_name = KEYFILE_GROUP_NAME;
|
|
|
|
|
2007-05-26 18:53:50 +00:00
|
|
|
paper_size = gtk_page_setup_get_paper_size (setup);
|
2007-04-29 06:23:58 +00:00
|
|
|
g_assert (paper_size != NULL);
|
|
|
|
|
|
|
|
gtk_paper_size_to_key_file (paper_size, key_file, group_name);
|
|
|
|
|
|
|
|
g_key_file_set_double (key_file, group_name,
|
2007-05-26 18:53:50 +00:00
|
|
|
"MarginTop", gtk_page_setup_get_top_margin (setup, GTK_UNIT_MM));
|
2007-04-29 06:23:58 +00:00
|
|
|
g_key_file_set_double (key_file, group_name,
|
2007-05-26 18:53:50 +00:00
|
|
|
"MarginBottom", gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_MM));
|
2007-04-29 06:23:58 +00:00
|
|
|
g_key_file_set_double (key_file, group_name,
|
2007-05-26 18:53:50 +00:00
|
|
|
"MarginLeft", gtk_page_setup_get_left_margin (setup, GTK_UNIT_MM));
|
2007-04-29 06:23:58 +00:00
|
|
|
g_key_file_set_double (key_file, group_name,
|
2007-05-26 18:53:50 +00:00
|
|
|
"MarginRight", gtk_page_setup_get_right_margin (setup, GTK_UNIT_MM));
|
2007-04-29 06:23:58 +00:00
|
|
|
|
|
|
|
orientation = enum_to_string (GTK_TYPE_PAGE_ORIENTATION,
|
2007-05-26 18:53:50 +00:00
|
|
|
gtk_page_setup_get_orientation (setup));
|
2007-04-29 06:23:58 +00:00
|
|
|
g_key_file_set_string (key_file, group_name,
|
|
|
|
"Orientation", orientation);
|
|
|
|
g_free (orientation);
|
|
|
|
}
|
2016-07-03 00:29:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_page_setup_to_gvariant:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @setup: a `GtkPageSetup`
|
2016-07-03 00:29:51 +00:00
|
|
|
*
|
|
|
|
* Serialize page setup to an a{sv} variant.
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Return: (transfer none): a new, floating, `GVariant`
|
2016-07-03 00:29:51 +00:00
|
|
|
*/
|
|
|
|
GVariant *
|
|
|
|
gtk_page_setup_to_gvariant (GtkPageSetup *setup)
|
|
|
|
{
|
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
GVariant *variant;
|
|
|
|
int i;
|
|
|
|
GVariantBuilder builder;
|
|
|
|
char *orientation;
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
|
|
|
|
|
|
|
|
paper_size = gtk_page_setup_get_paper_size (setup);
|
|
|
|
|
|
|
|
variant = g_variant_ref_sink (gtk_paper_size_to_gvariant (paper_size));
|
|
|
|
for (i = 0; i < g_variant_n_children (variant); i++)
|
|
|
|
g_variant_builder_add_value (&builder, g_variant_get_child_value (variant, i));
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "MarginTop", g_variant_new_double (gtk_page_setup_get_top_margin (setup, GTK_UNIT_MM)));
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "MarginBottom", g_variant_new_double (gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_MM)));
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "MarginLeft", g_variant_new_double (gtk_page_setup_get_left_margin (setup, GTK_UNIT_MM)));
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "MarginRight", g_variant_new_double (gtk_page_setup_get_right_margin (setup, GTK_UNIT_MM)));
|
|
|
|
|
|
|
|
orientation = enum_to_string (GTK_TYPE_PAGE_ORIENTATION,
|
|
|
|
gtk_page_setup_get_orientation (setup));
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "Orientation", g_variant_new_take_string (orientation));
|
|
|
|
|
|
|
|
return g_variant_builder_end (&builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_page_setup_new_from_gvariant:
|
2021-02-27 15:53:36 +00:00
|
|
|
* @variant: an a{sv} `GVariant`
|
|
|
|
*
|
|
|
|
* Desrialize a page setup from an a{sv} variant.
|
2016-07-03 00:29:51 +00:00
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* The variant must be in the format produced by
|
|
|
|
* [method@Gtk.PageSetup.to_gvariant].
|
2016-07-03 00:29:51 +00:00
|
|
|
*
|
2021-02-27 15:53:36 +00:00
|
|
|
* Returns: (transfer full): a new `GtkPageSetup` object
|
2016-07-03 00:29:51 +00:00
|
|
|
*/
|
|
|
|
GtkPageSetup *
|
|
|
|
gtk_page_setup_new_from_gvariant (GVariant *variant)
|
|
|
|
{
|
|
|
|
GtkPageSetup *setup;
|
|
|
|
const char *orientation;
|
2020-07-24 20:32:16 +00:00
|
|
|
double margin;
|
2016-07-03 00:29:51 +00:00
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_VARDICT), NULL);
|
|
|
|
|
|
|
|
setup = gtk_page_setup_new ();
|
|
|
|
|
|
|
|
paper_size = gtk_paper_size_new_from_gvariant (variant);
|
2018-04-20 20:56:28 +00:00
|
|
|
if (paper_size)
|
|
|
|
{
|
|
|
|
gtk_page_setup_set_paper_size (setup, paper_size);
|
|
|
|
gtk_paper_size_free (paper_size);
|
|
|
|
}
|
2016-07-03 00:29:51 +00:00
|
|
|
|
|
|
|
if (g_variant_lookup (variant, "MarginTop", "d", &margin))
|
|
|
|
gtk_page_setup_set_top_margin (setup, margin, GTK_UNIT_MM);
|
|
|
|
if (g_variant_lookup (variant, "MarginBottom", "d", &margin))
|
|
|
|
gtk_page_setup_set_bottom_margin (setup, margin, GTK_UNIT_MM);
|
|
|
|
if (g_variant_lookup (variant, "MarginLeft", "d", &margin))
|
|
|
|
gtk_page_setup_set_left_margin (setup, margin, GTK_UNIT_MM);
|
|
|
|
if (g_variant_lookup (variant, "MarginRight", "d", &margin))
|
|
|
|
gtk_page_setup_set_right_margin (setup, margin, GTK_UNIT_MM);
|
|
|
|
|
|
|
|
if (g_variant_lookup (variant, "Orientation", "&s", &orientation))
|
|
|
|
gtk_page_setup_set_orientation (setup, string_to_enum (GTK_TYPE_PAGE_ORIENTATION,
|
|
|
|
orientation));
|
|
|
|
|
|
|
|
return setup;
|
|
|
|
}
|