* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkprintoperation.h" /* for GtkPrintError */
#include "gtkintl.h"
#include "gtktypebuiltins.h"
-#include "gtkalias.h"
+
+/**
+ * SECTION:gtkpagesetup
+ * @Short_description: Stores page setup information
+ * @Title: GtkPageSetup
+ *
+ * A GtkPageSetup object stores the page size, orientation and margins.
+ * The idea is that you can get one of these from the page setup dialog
+ * and then pass it to the #GtkPrintOperation when printing.
+ * The benefit of splitting this out of the #GtkPrintSettings is that
+ * these affect the actual layout of the page, and thus need to be set
+ * long before user prints.
+ *
+ * <para id="print-margins">
+ * The margins specified in this object are the "print margins", i.e. the
+ * 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
+ * used to determine the <emphasis>minimal</emphasis> size for the layout
+ * margins.
+ * </para>
+ *
+ * To obtain a #GtkPageSetup use gtk_page_setup_new() to get the defaults,
+ * or use gtk_print_run_page_setup_dialog() to show the page setup dialog
+ * and receive the resulting page setup.
+ *
+ * <example>
+ * <title>A page setup dialog</title>
+ * <programlisting>
+ * static GtkPrintSettings *settings = NULL;
+ * static GtkPageSetup *page_setup = NULL;
+ *
+ * static void
+ * do_page_setup (void)
+ * {
+ * GtkPageSetup *new_page_setup;
+ *
+ * if (settings == NULL)
+ * settings = gtk_print_settings_new (<!-- -->);
+ *
+ * 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;
+ * }
+ * </programlisting>
+ * </example>
+ *
+ * Printing support was added in GTK+ 2.10.
+ */
#define KEYFILE_GROUP_NAME "Page Setup"
/**
* gtk_page_setup_copy:
* @other: the #GtkPageSetup to copy
- *
+ *
* Copies a #GtkPageSetup.
- *
- * Return value: a copy of @other
+ *
+ * Return value: (transfer full): a copy of @other
*
* Since: 2.10
*/
copy = gtk_page_setup_new ();
copy->orientation = other->orientation;
+ gtk_paper_size_free (copy->paper_size);
copy->paper_size = gtk_paper_size_copy (other->paper_size);
copy->top_margin = other->top_margin;
copy->bottom_margin = other->bottom_margin;
return _gtk_print_convert_from_mm (height, unit);
}
+/**
+ * gtk_page_setup_load_file:
+ * @setup: a #GtkPageSetup
+ * @file_name: (type filename): the filename to read the page setup from
+ * @error: (allow-none): return location for an error, or %NULL
+ *
+ * Reads the page setup from the file @file_name.
+ * See gtk_page_setup_to_file().
+ *
+ * Return value: %TRUE on success
+ *
+ * Since: 2.14
+ */
+gboolean
+gtk_page_setup_load_file (GtkPageSetup *setup,
+ const gchar *file_name,
+ 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;
+}
/**
* gtk_page_setup_new_from_file:
- * @file_name: the filename to read the page setup from
- * @error: return location for an error, or %NULL
+ * @file_name: (type filename): the filename to read the page setup from
+ * @error: (allow-none): return location for an error, or %NULL
*
* Reads the page setup from the file @file_name. Returns a
* new #GtkPageSetup object with the restored page setup,
gtk_page_setup_new_from_file (const gchar *file_name,
GError **error)
{
- GtkPageSetup *page_setup;
- GKeyFile *key_file;
- GError *err = NULL;
-
- g_return_val_if_fail (file_name != NULL, NULL);
+ GtkPageSetup *setup = gtk_page_setup_new ();
- key_file = g_key_file_new ();
- if (!g_key_file_load_from_file (key_file, file_name, 0, &err))
+ if (!gtk_page_setup_load_file (setup, file_name, error))
{
- g_key_file_free (key_file);
- g_propagate_error (error, err);
- return NULL;
+ g_object_unref (setup);
+ setup = NULL;
}
- page_setup = gtk_page_setup_new_from_key_file (key_file, NULL, error);
- g_key_file_free (key_file);
-
- return page_setup;
+ return setup;
}
/* something like this should really be in gobject! */
}
/**
- * gtk_page_setup_new_from_key_file:
+ * gtk_page_setup_load_key_file:
+ * @setup: a #GtkPageSetup
* @key_file: the #GKeyFile to retrieve the page_setup from
- * @group_name: the name of the group in the key_file to read, or %NULL
+ * @group_name: (allow-none): the name of the group in the key_file to read, or %NULL
* to use the default name "Page Setup"
- * @error: return location for an error, or %NULL
+ * @error: (allow-none): return location for an error, or %NULL
*
* Reads the page setup from the group @group_name in the key file
- * @key_file. Returns a new #GtkPageSetup object with the restored
- * page setup, or %NULL if an error occurred.
- *
- * Return value: the restored #GtkPageSetup
+ * @key_file.
*
- * Since: 2.12
+ * Return value: %TRUE on success
+ *
+ * Since: 2.14
*/
-GtkPageSetup *
-gtk_page_setup_new_from_key_file (GKeyFile *key_file,
- const gchar *group_name,
- GError **error)
+gboolean
+gtk_page_setup_load_key_file (GtkPageSetup *setup,
+ GKeyFile *key_file,
+ const gchar *group_name,
+ GError **error)
{
- GtkPageSetup *page_setup = NULL;
GtkPaperSize *paper_size;
gdouble top, bottom, left, right;
char *orientation = NULL, *freeme = NULL;
- gboolean retval = TRUE;
+ gboolean retval = FALSE;
GError *err = NULL;
- g_return_val_if_fail (key_file != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
+ g_return_val_if_fail (key_file != NULL, FALSE);
if (!group_name)
group_name = KEYFILE_GROUP_NAME;
if (!g_key_file_has_group (key_file, group_name))
{
- g_set_error (error,
- GTK_PRINT_ERROR,
- GTK_PRINT_ERROR_INVALID_FILE,
- _("Not a valid page setup file"));
- retval = FALSE;
+ g_set_error_literal (error,
+ GTK_PRINT_ERROR,
+ GTK_PRINT_ERROR_INVALID_FILE,
+ _("Not a valid page setup file"));
goto out;
}
if (err != NULL) \
{ \
g_propagate_error (error, err);\
- retval = FALSE;\
goto out;\
}
goto out;
}
- page_setup = gtk_page_setup_new ();
- gtk_page_setup_set_paper_size (page_setup, paper_size);
+ gtk_page_setup_set_paper_size (setup, paper_size);
gtk_paper_size_free (paper_size);
- 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);
+ 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);
orientation = g_key_file_get_string (key_file, group_name,
"Orientation", NULL);
if (orientation)
{
- gtk_page_setup_set_orientation (page_setup,
+ gtk_page_setup_set_orientation (setup,
string_to_enum (GTK_TYPE_PAGE_ORIENTATION,
orientation));
g_free (orientation);
}
+ retval = TRUE;
+
out:
g_free (freeme);
+ return retval;
+}
- return page_setup;
+/**
+ * gtk_page_setup_new_from_key_file:
+ * @key_file: the #GKeyFile to retrieve the page_setup from
+ * @group_name: (allow-none): the name of the group in the key_file to read, or %NULL
+ * to use the default name "Page Setup"
+ * @error: (allow-none): return location for an error, or %NULL
+ *
+ * Reads the page setup from the group @group_name in the key file
+ * @key_file. Returns a new #GtkPageSetup object with the restored
+ * page setup, or %NULL if an error occurred.
+ *
+ * Return value: the restored #GtkPageSetup
+ *
+ * Since: 2.12
+ */
+GtkPageSetup *
+gtk_page_setup_new_from_key_file (GKeyFile *key_file,
+ const gchar *group_name,
+ 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;
+ }
+
+ return setup;
}
/**
* gtk_page_setup_to_file:
- * @page_setup: a #GtkPageSetup
- * @file_name: the file to save to
- * @error: return location for errors, or %NULL
+ * @setup: a #GtkPageSetup
+ * @file_name: (type filename): the file to save to
+ * @error: (allow-none): return location for errors, or %NULL
*
- * This function saves the print page_setup from @page_setup
- * to @file_name.
+ * This function saves the information from @setup to @file_name.
*
* Return value: %TRUE on success
*
* Since: 2.12
*/
gboolean
-gtk_page_setup_to_file (GtkPageSetup *page_setup,
+gtk_page_setup_to_file (GtkPageSetup *setup,
const char *file_name,
GError **error)
{
char *data = NULL;
gsize len;
- g_return_val_if_fail (GTK_IS_PAGE_SETUP (page_setup), FALSE);
+ 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 ();
- gtk_page_setup_to_key_file (page_setup, key_file, NULL);
+ gtk_page_setup_to_key_file (setup, key_file, NULL);
data = g_key_file_to_data (key_file, &len, error);
if (!data)
/**
* gtk_page_setup_to_key_file:
- * @page_setup: a #GtkPageSetup
+ * @setup: a #GtkPageSetup
* @key_file: the #GKeyFile to save the page setup to
* @group_name: the group to add the settings to in @key_file,
* or %NULL to use the default name "Page Setup"
*
- * This function adds the page setup from @page_setup to @key_file.
+ * This function adds the page setup from @setup to @key_file.
*
* Since: 2.12
*/
void
-gtk_page_setup_to_key_file (GtkPageSetup *page_setup,
+gtk_page_setup_to_key_file (GtkPageSetup *setup,
GKeyFile *key_file,
const gchar *group_name)
{
GtkPaperSize *paper_size;
char *orientation;
- g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
+ g_return_if_fail (GTK_IS_PAGE_SETUP (setup));
g_return_if_fail (key_file != NULL);
if (!group_name)
group_name = KEYFILE_GROUP_NAME;
- paper_size = gtk_page_setup_get_paper_size (page_setup);
+ paper_size = gtk_page_setup_get_paper_size (setup);
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,
- "MarginTop", gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
+ "MarginTop", gtk_page_setup_get_top_margin (setup, GTK_UNIT_MM));
g_key_file_set_double (key_file, group_name,
- "MarginBottom", gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
+ "MarginBottom", gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_MM));
g_key_file_set_double (key_file, group_name,
- "MarginLeft", gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
+ "MarginLeft", gtk_page_setup_get_left_margin (setup, GTK_UNIT_MM));
g_key_file_set_double (key_file, group_name,
- "MarginRight", gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
+ "MarginRight", gtk_page_setup_get_right_margin (setup, GTK_UNIT_MM));
orientation = enum_to_string (GTK_TYPE_PAGE_ORIENTATION,
- gtk_page_setup_get_orientation (page_setup));
+ gtk_page_setup_get_orientation (setup));
g_key_file_set_string (key_file, group_name,
"Orientation", orientation);
g_free (orientation);
}
-
-#define __GTK_PAGE_SETUP_C__
-#include "gtkaliasdef.c"