Commit 935482e3 authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Add gtkprintutils.[hc]

2006-04-23  Matthias Clasen  <mclasen@redhat.com>

	* gtk/Makefile.am: Add gtkprintutils.[hc]

	* gtk/gtkprintutils.[hc]: New files, move the unit conversion
	functions here.

	* gtk/gtkpagesetupunixdialog.c:
	* gtk/gtkprintsettings.c:
	* gtk/gtkpagesetup.c:
	* gtk/gtkpapersize.c: Replace all static copies of to_mm/from_mm
	by the copies in gtkprintutils.c.

	* gtk/gtkpagesetup.[hc]: Use g types, add documentation.
parent 46548ae5
2006-04-23 Matthias Clasen <mclasen@redhat.com> 2006-04-23 Matthias Clasen <mclasen@redhat.com>
* gtk/Makefile.am: Add gtkprintutils.[hc]
* gtk/gtkprintutils.[hc]: New files, move the unit conversion
functions here.
* gtk/gtkpagesetupunixdialog.c:
* gtk/gtkprintsettings.c:
* gtk/gtkpagesetup.c:
* gtk/gtkpapersize.c: Replace all static copies of to_mm/from_mm
by the copies in gtkprintutils.c.
* gtk/gtkpagesetup.[hc]: Use g types, add documentation.
* gtk/gtkprintsettings.c: More documentation * gtk/gtkprintsettings.c: More documentation
2006-04-22 Tor Lillqvist <tml@novell.com> 2006-04-22 Tor Lillqvist <tml@novell.com>
......
2006-04-23 Matthias Clasen <mclasen@redhat.com> 2006-04-23 Matthias Clasen <mclasen@redhat.com>
* gtk/Makefile.am: Add gtkprintutils.[hc]
* gtk/gtkprintutils.[hc]: New files, move the unit conversion
functions here.
* gtk/gtkpagesetupunixdialog.c:
* gtk/gtkprintsettings.c:
* gtk/gtkpagesetup.c:
* gtk/gtkpapersize.c: Replace all static copies of to_mm/from_mm
by the copies in gtkprintutils.c.
* gtk/gtkpagesetup.[hc]: Use g types, add documentation.
* gtk/gtkprintsettings.c: More documentation * gtk/gtkprintsettings.c: More documentation
2006-04-22 Tor Lillqvist <tml@novell.com> 2006-04-22 Tor Lillqvist <tml@novell.com>
......
...@@ -334,6 +334,7 @@ gtk_private_h_sources = \ ...@@ -334,6 +334,7 @@ gtk_private_h_sources = \
gtkpathbar.h \ gtkpathbar.h \
gtkplugprivate.h \ gtkplugprivate.h \
gtkprintoperation-private.h\ gtkprintoperation-private.h\
gtkprintutils.h \
gtkrbtree.h \ gtkrbtree.h \
gtkrecentchooserdefault.h \ gtkrecentchooserdefault.h \
gtkrecentchooserprivate.h \ gtkrecentchooserprivate.h \
...@@ -483,6 +484,7 @@ gtk_c_sources = \ ...@@ -483,6 +484,7 @@ gtk_c_sources = \
gtkprintcontext.c \ gtkprintcontext.c \
gtkprintoperation.c \ gtkprintoperation.c \
gtkprintsettings.c \ gtkprintsettings.c \
gtkprintutils.c \
gtkprogress.c \ gtkprogress.c \
gtkprogressbar.c \ gtkprogressbar.c \
gtkradioaction.c \ gtkradioaction.c \
......
...@@ -21,10 +21,9 @@ ...@@ -21,10 +21,9 @@
#include "config.h" #include "config.h"
#include "gtkpagesetup.h" #include "gtkpagesetup.h"
#include "gtkprintutils.h"
#include "gtkalias.h" #include "gtkalias.h"
#define MM_PER_INCH 25.4
#define POINTS_PER_INCH 72
typedef struct _GtkPageSetupClass GtkPageSetupClass; typedef struct _GtkPageSetupClass GtkPageSetupClass;
...@@ -49,44 +48,6 @@ struct _GtkPageSetupClass ...@@ -49,44 +48,6 @@ struct _GtkPageSetupClass
G_DEFINE_TYPE (GtkPageSetup, gtk_page_setup, G_TYPE_OBJECT) G_DEFINE_TYPE (GtkPageSetup, gtk_page_setup, G_TYPE_OBJECT)
static double
to_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len * MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len * (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static double
from_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len / MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len / (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static void static void
gtk_page_setup_finalize (GObject *object) gtk_page_setup_finalize (GObject *object)
{ {
...@@ -115,13 +76,32 @@ gtk_page_setup_class_init (GtkPageSetupClass *class) ...@@ -115,13 +76,32 @@ gtk_page_setup_class_init (GtkPageSetupClass *class)
gobject_class->finalize = gtk_page_setup_finalize; gobject_class->finalize = gtk_page_setup_finalize;
} }
/**
* gtk_page_setup_new:
*
* Creates a new #GtkPageSetup.
*
* Return value: a new #GtkPageSetup.
*
* Since: 2.10
*/
GtkPageSetup * GtkPageSetup *
gtk_page_setup_new (void) gtk_page_setup_new (void)
{ {
return g_object_new (GTK_TYPE_PAGE_SETUP, NULL); return g_object_new (GTK_TYPE_PAGE_SETUP, NULL);
} }
/**
* gtk_page_setup_copy:
* @other: the #GtkPageSetup to copy
*
* Copies a #GtkPageSetup.
*
* Return value: a copy of @other
*
* Since: 2.10
*/
GtkPageSetup * GtkPageSetup *
gtk_page_setup_copy (GtkPageSetup *other) gtk_page_setup_copy (GtkPageSetup *other)
{ {
...@@ -138,25 +118,65 @@ gtk_page_setup_copy (GtkPageSetup *other) ...@@ -138,25 +118,65 @@ gtk_page_setup_copy (GtkPageSetup *other)
return copy; return copy;
} }
/**
* gtk_page_setup_get_orientation:
* @setup: a #GtkPageSetup
*
* Gets the page orientation of the #GtkPageSetup.
*
* Return value: the page orientation
*
* Since: 2.10
*/
GtkPageOrientation GtkPageOrientation
gtk_page_setup_get_orientation (GtkPageSetup *setup) gtk_page_setup_get_orientation (GtkPageSetup *setup)
{ {
return setup->orientation; return setup->orientation;
} }
/**
* gtk_page_setup_set_orientation:
* @setup: a #GtkPageSetup
* @orientation: a #GtkPageOrientation value
*
* Sets the page orientation of the #GtkPageSetup.
*
* Since: 2.10
*/
void void
gtk_page_setup_set_orientation (GtkPageSetup *setup, gtk_page_setup_set_orientation (GtkPageSetup *setup,
GtkPageOrientation orientation) GtkPageOrientation orientation)
{ {
setup->orientation = orientation; setup->orientation = orientation;
} }
/**
* gtk_page_setup_get_paper_size:
* @setup: a #GtkPageSetup
*
* Gets the paper size of the #GtkPageSetup.
*
* Return value: the paper size
*
* Since: 2.10
*/
GtkPaperSize * GtkPaperSize *
gtk_page_setup_get_paper_size (GtkPageSetup *setup) gtk_page_setup_get_paper_size (GtkPageSetup *setup)
{ {
return setup->paper_size; return setup->paper_size;
} }
/**
* gtk_page_setup_set_paper_size:
* @setup: a #GtkPageSetup
* @size: a #GtkPaperSize
*
* Sets the paper size of the #GtkPageSetup without
* changing the margins. See
* gtk_page_setup_set_paper_size_and_default_margins().
*
* Since: 2.10
*/
void void
gtk_page_setup_set_paper_size (GtkPageSetup *setup, gtk_page_setup_set_paper_size (GtkPageSetup *setup,
GtkPaperSize *size) GtkPaperSize *size)
...@@ -164,6 +184,16 @@ gtk_page_setup_set_paper_size (GtkPageSetup *setup, ...@@ -164,6 +184,16 @@ gtk_page_setup_set_paper_size (GtkPageSetup *setup,
setup->paper_size = gtk_paper_size_copy (size); setup->paper_size = gtk_paper_size_copy (size);
} }
/**
* gtk_page_setup_set_paper_size_and_default_margins:
* @setup: a #GtkPageSetup
* @size: a #GtkPaperSize
*
* Sets the paper size of the #GtkPageSetup and modifies
* the margins according to the new paper size.
*
* Since: 2.10
*/
void void
gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup, gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
GtkPaperSize *size) GtkPaperSize *size)
...@@ -175,68 +205,166 @@ gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup, ...@@ -175,68 +205,166 @@ gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
setup->right_margin = gtk_paper_size_get_default_right_margin (setup->paper_size, GTK_UNIT_MM); setup->right_margin = gtk_paper_size_get_default_right_margin (setup->paper_size, GTK_UNIT_MM);
} }
double /**
* gtk_page_setup_get_top_margin:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Gets the top margin in units of @unit.
*
* Return value: the top margin
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_top_margin (GtkPageSetup *setup, gtk_page_setup_get_top_margin (GtkPageSetup *setup,
GtkUnit unit) GtkUnit unit)
{ {
return from_mm (setup->top_margin, unit); return _gtk_print_convert_from_mm (setup->top_margin, unit);
} }
/**
* gtk_page_setup_set_top_margin:
* @setup: a #GtkPageSetup
* @margin: the new top margin in units of @unit
* @unit: the units for @margin
*
* Sets the top margin of the #GtkPageSetup.
*
* Since: 2.10
*/
void void
gtk_page_setup_set_top_margin (GtkPageSetup *setup, gtk_page_setup_set_top_margin (GtkPageSetup *setup,
double margin, gdouble margin,
GtkUnit unit) GtkUnit unit)
{ {
setup->top_margin = to_mm (margin, unit); setup->top_margin = _gtk_print_convert_to_mm (margin, unit);
} }
double /**
* gtk_page_setup_get_bottom_margin:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Gets the bottom margin in units of @unit.
*
* Return value: the bottom margin
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_bottom_margin (GtkPageSetup *setup, gtk_page_setup_get_bottom_margin (GtkPageSetup *setup,
GtkUnit unit) GtkUnit unit)
{ {
return from_mm (setup->bottom_margin, unit); return _gtk_print_convert_from_mm (setup->bottom_margin, unit);
} }
/**
* gtk_page_setup_set_bottom_margin:
* @setup: a #GtkPageSetup
* @margin: the new bottom margin in units of @unit
* @unit: the units for @margin
*
* Sets the bottom margin of the #GtkPageSetup.
*
* Since: 2.10
*/
void void
gtk_page_setup_set_bottom_margin (GtkPageSetup *setup, gtk_page_setup_set_bottom_margin (GtkPageSetup *setup,
double margin, gdouble margin,
GtkUnit unit) GtkUnit unit)
{ {
setup->bottom_margin = to_mm (margin, unit); setup->bottom_margin = _gtk_print_convert_to_mm (margin, unit);
} }
double /**
gtk_page_setup_get_left_margin (GtkPageSetup *setup, * gtk_page_setup_get_left_margin:
GtkUnit unit) * @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Gets the left margin in units of @unit.
*
* Return value: the left margin
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_left_margin (GtkPageSetup *setup,
GtkUnit unit)
{ {
return from_mm (setup->left_margin, unit); return _gtk_print_convert_from_mm (setup->left_margin, unit);
} }
/**
* gtk_page_setup_set_left_margin:
* @setup: a #GtkPageSetup
* @margin: the new left margin in units of @unit
* @unit: the units for @margin
*
* Sets the left margin of the #GtkPageSetup.
*
* Since: 2.10
*/
void void
gtk_page_setup_set_left_margin (GtkPageSetup *setup, gtk_page_setup_set_left_margin (GtkPageSetup *setup,
double margin, gdouble margin,
GtkUnit unit) GtkUnit unit)
{ {
setup->left_margin = to_mm (margin, unit); setup->left_margin = _gtk_print_convert_to_mm (margin, unit);
} }
double /**
gtk_page_setup_get_right_margin (GtkPageSetup *setup, * gtk_page_setup_get_right_margin:
GtkUnit unit) * @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Gets the right margin in units of @unit.
*
* Return value: the right margin
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_right_margin (GtkPageSetup *setup,
GtkUnit unit)
{ {
return from_mm (setup->right_margin, unit); return _gtk_print_convert_from_mm (setup->right_margin, unit);
} }
/**
* gtk_page_setup_set_right_margin:
* @setup: a #GtkPageSetup
* @margin: the new right margin in units of @unit
* @unit: the units for @margin
*
* Sets the right margin of the #GtkPageSetup.
*
* Since: 2.10
*/
void void
gtk_page_setup_set_right_margin (GtkPageSetup *setup, gtk_page_setup_set_right_margin (GtkPageSetup *setup,
double margin, gdouble margin,
GtkUnit unit) GtkUnit unit)
{ {
setup->right_margin = to_mm (margin, unit); setup->right_margin = _gtk_print_convert_to_mm (margin, unit);
} }
/* These take orientation, but not margins into consideration */ /**
double * gtk_page_setup_get_paper_width:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Returns the paper width in units of @unit.
*
* Note that this function takes orientation, but
* not margins into consideration.
* See gtk_page_setup_get_page_width().
*
* Return value: the paper width.
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_paper_width (GtkPageSetup *setup, gtk_page_setup_get_paper_width (GtkPageSetup *setup,
GtkUnit unit) GtkUnit unit)
{ {
...@@ -247,9 +375,24 @@ gtk_page_setup_get_paper_width (GtkPageSetup *setup, ...@@ -247,9 +375,24 @@ gtk_page_setup_get_paper_width (GtkPageSetup *setup,
return gtk_paper_size_get_height (setup->paper_size, unit); return gtk_paper_size_get_height (setup->paper_size, unit);
} }
double /**
gtk_page_setup_get_paper_height (GtkPageSetup *setup, * gtk_page_setup_get_paper_height:
GtkUnit unit) * @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Returns the paper height in units of @unit.
*
* Note that this function takes orientation, but
* not margins into consideration.
* See gtk_page_setup_get_page_height().
*
* Return value: the paper height.
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_paper_height (GtkPageSetup *setup,
GtkUnit unit)
{ {
if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT || if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT) setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
...@@ -258,29 +401,58 @@ gtk_page_setup_get_paper_height (GtkPageSetup *setup, ...@@ -258,29 +401,58 @@ gtk_page_setup_get_paper_height (GtkPageSetup *setup,
return gtk_paper_size_get_width (setup->paper_size, unit); return gtk_paper_size_get_width (setup->paper_size, unit);
} }
/* These take orientation, and margins into consideration */ /**
double * gtk_page_setup_get_page_width:
gtk_page_setup_get_page_width (GtkPageSetup *setup, * @setup: a #GtkPageSetup
GtkUnit unit) * @unit: the unit for the return value
*
* Returns the page width in units of @unit.
*
* Note that this function takes orientation and
* margins into consideration.
* See gtk_page_setup_get_paper_width().
*
* Return value: the page width.
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_page_width (GtkPageSetup *setup,
GtkUnit unit)
{ {
double width; gdouble width;
width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM); width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM);
width -= setup->left_margin + setup->right_margin; width -= setup->left_margin + setup->right_margin;
return from_mm (width, unit); return _gtk_print_convert_from_mm (width, unit);
} }
double /**
gtk_page_setup_get_page_height (GtkPageSetup *setup, * gtk_page_setup_get_page_height:
GtkUnit unit) * @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Returns the page height in units of @unit.
*
* Note that this function takes orientation and
* margins into consideration.
* See gtk_page_setup_get_paper_height().
*
* Return value: the page height.
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_page_height (GtkPageSetup *setup,
GtkUnit unit)
{ {
double height; gdouble height;
height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM); height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM);
height -= setup->top_margin + setup->bottom_margin; height -= setup->top_margin + setup->bottom_margin;
return from_mm (height, unit); return _gtk_print_convert_from_mm (height, unit);
} }
......
...@@ -42,41 +42,41 @@ void gtk_page_setup_set_orientation (GtkPageSetup *setup, ...@@ -42,41 +42,41 @@ void gtk_page_setup_set_orientation (GtkPageSetup *setup,
GtkPaperSize * gtk_page_setup_get_paper_size (GtkPageSetup *setup); GtkPaperSize * gtk_page_setup_get_paper_size (GtkPageSetup *setup);
void gtk_page_setup_set_paper_size (GtkPageSetup *setup, void gtk_page_setup_set_paper_size (GtkPageSetup *setup,
GtkPaperSize *size); GtkPaperSize *size);
double gtk_page_setup_get_top_margin (GtkPageSetup *setup, gdouble gtk_page_setup_get_top_margin (GtkPageSetup *setup,
GtkUnit unit); GtkUnit unit);
void gtk_page_setup_set_top_margin (GtkPageSetup *setup, void gtk_page_setup_set_top_margin (GtkPageSetup *setup,
double margin, gdouble margin,
GtkUnit unit); GtkUnit unit);
double gtk_page_setup_get_bottom_margin (GtkPageSetup *setup, gdouble gtk_page_setup_get_bottom_margin (GtkPageSetup *setup,
GtkUnit unit); GtkUnit unit);
void gtk_page_setup_set_bottom_margin (GtkPageSetup *setup, void gtk_page_setup_set_bottom_margin (GtkPageSetup *setup,
double margin, gdouble margin,
GtkUnit unit); GtkUnit unit);
double gtk_page_setup_get_left_margin (GtkPageSetup *setup, gdouble gtk_page_setup_get_left_margin (GtkPageSetup *setup,
GtkUnit unit); GtkUnit unit);
void gtk_page_setup_set_left_margin (GtkPageSetup *setup, void gtk_page_setup_set_left_margin (GtkPageSetup *setup,
double margin, gdouble margin,
GtkUnit unit); GtkUnit unit);
double gtk_page_setup_get_right_margin (GtkPageSetup *setup, gdouble gtk_page_setup_get_right_margin (GtkPageSetup *setup,
GtkUnit unit); GtkUnit unit);
void gtk_page_setup_set_right_margin (GtkPageSetup *setup, void gtk_page_setup_set_right_margin (GtkPageSetup *setup,
double margin, gdouble margin,
GtkUnit unit); GtkUnit unit);
void gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup, void gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
GtkPaperSize *size); GtkPaperSize *size);
/* These take orientation, but not margins into consideration */ /* These take orientation, but not margins into consideration */
double gtk_page_setup_get_paper_width (GtkPageSetup *setup, gdouble gtk_page_setup_get_paper_width (GtkPageSetup *setup,
GtkUnit unit); GtkUnit unit);
double gtk_page_setup_get_paper_height (GtkPageSetup *setup, gdouble gtk_page_setup_get_paper_height (GtkPageSetup *setup,
GtkUnit unit); GtkUnit unit);
/* These take orientation, and margins into consideration */ /* These take orientation, and margins into consideration */
double gtk_page_setup_get_page_width (GtkPageSetup *setup, gdouble gtk_page_setup_get_page_width (GtkPageSetup *setup,
GtkUnit unit); GtkUnit unit);
double gtk_page_setup_get_page_height (GtkPageSetup *setup, gdouble gtk_page_setup_get_page_height (GtkPageSetup *setup,
GtkUnit unit); GtkUnit unit);
......
...@@ -52,13 +52,11 @@ ...@@ -52,13 +52,11 @@
#include "gtkprintbackend.h" #include "gtkprintbackend.h"
#include "gtkprinter-private.h" #include "gtkprinter-private.h"
#include "gtkpapersize.h" #include "gtkpapersize.h"
#include "gtkprintutils.h"
#include "gtkalias.h" #include "gtkalias.h"
#define CUSTOM_PAPER_FILENAME ".gtk-custom-papers" #define CUSTOM_PAPER_FILENAME ".gtk-custom-papers"
#define MM_PER_INCH 25.4
#define POINTS_PER_INCH 72
struct GtkPageSetupUnixDialogPrivate struct GtkPageSetupUnixDialogPrivate
{ {
...@@ -128,44 +126,6 @@ static const char * const common_paper_sizes[] = { ...@@ -128,44 +126,6 @@ static const char * const common_paper_sizes[] = {
"iso_a3", "iso_a3",
}; };
static double
to_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len * MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len * (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static double
from_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len / MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len / (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static GtkUnit static GtkUnit
get_default_user_units (void) get_default_user_units (void)
{ {
...@@ -1376,7 +1336,7 @@ static double ...@@ -1376,7 +1336,7 @@ static double
unit_widget_get (GtkWidget *unit_widget) unit_widget_get (GtkWidget *unit_widget)
{ {
UnitWidget *data = g_object_get_data (G_OBJECT (unit_widget), "unit-data"); UnitWidget *data = g_object_get_data (G_OBJECT (unit_widget), "unit-data");