Unite report and check print settings.

If Gtk+ includes GtkPrint support, i.e. HAVE_GTK_2_10 is defined, and GtkHTML
uses it, i.e. GTKHTML_USES_GTKPRINT, then we currently save and restore print
settings in two different locations, namely static variables in gnc-html.c and
dialog-print-check.c.

Instead, add the function gnc_print_operation_{save,restore}_print_settings() to
print-session.[ch] to have a unique global location for them.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17610 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Andreas Köhler 2008-09-28 15:31:50 +00:00
parent 374231d301
commit b8aeba4079
5 changed files with 95 additions and 65 deletions

View File

@ -52,6 +52,7 @@ libgncmod_gnome_utils_la_SOURCES = \
gnc-dense-cal.c \
gnc-dense-cal-model.c \
gnc-dense-cal-store.c \
gnc-dialog.c \
gnc-druid-gnome.c \
gnc-druid-provider-edge-gnome.c \
gnc-druid-provider-file-gnome.c \
@ -94,7 +95,7 @@ libgncmod_gnome_utils_la_SOURCES = \
gncmod-gnome-utils.c \
misc-gnome-utils.c \
search-param.c \
gnc-dialog.c \
print-session.c \
swig-gnome-utils.c \
window-main-summarybar.c
@ -217,12 +218,9 @@ EXTRA_DIST = \
${gncmod_DATA} \
${gncscm_DATA}
if GTKHTML_USES_GTKPRINT
EXTRA_DIST += print-session.c
else
if !GTKHTML_USES_GTKPRINT
AM_CFLAGS += ${GNOME_PRINT_CFLAGS}
libgncmod_gnome_utils_la_LIBADD += ${GNOME_PRINT_LIBS}
libgncmod_gnome_utils_la_SOURCES += print-session.c
endif
## We borrow guile's convention and use @-...-@ as the substitution

View File

@ -53,15 +53,6 @@
#include "gnc-ui.h"
#include "gnc-ui-util.h"
/* Do not treat -Wstrict-aliasing warnings as errors because of problems of the
* G_LOCK* macros as declared by glib. See
* http://bugzilla.gnome.org/show_bug.cgi?id=316221 for additional information.
*/
#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
# pragma GCC diagnostic warning "-Wstrict-aliasing"
#endif
struct gnc_html_struct {
GtkWidget * window; /* window this html goes into */
GtkWidget * container; /* parent of the gtkhtml widget */
@ -115,11 +106,6 @@ static char error_404_title[] = N_("Not found");
static char error_404_body[] =
N_("The specified URL could not be loaded.");
#ifdef GTKHTML_USES_GTKPRINT
static GtkPrintSettings *print_settings = NULL;
G_LOCK_DEFINE_STATIC(print_settings);
#endif
static char *
extract_machine_name(const gchar * path)
@ -1248,11 +1234,7 @@ gnc_html_print(gnc_html *html)
print = gtk_print_operation_new();
G_LOCK(print_settings);
if (print_settings)
gtk_print_operation_set_print_settings(print, print_settings);
G_UNLOCK(print_settings);
gnc_print_operation_restore_print_settings(print);
gtk_print_operation_set_use_full_page(print, FALSE);
gtk_print_operation_set_unit(print, GTK_UNIT_POINTS);
gtk_print_operation_set_n_pages(print, 1);
@ -1261,13 +1243,8 @@ gnc_html_print(gnc_html *html)
res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
GTK_WINDOW(html->window), NULL);
if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
G_LOCK(print_settings);
if (print_settings)
g_object_unref(print_settings);
print_settings = g_object_ref(gtk_print_operation_get_print_settings(print));
G_UNLOCK(print_settings);
}
if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
gnc_print_operation_save_print_settings(print);
g_object_unref(print);
}

View File

@ -22,14 +22,63 @@
#include "config.h"
#include <gnome.h>
#include <glib/gi18n.h>
#include <libgnomeprint/gnome-font.h>
#include <libgnomeprintui/gnome-print-job-preview.h>
#ifdef HAVE_GTK_2_10
# include <gtk/gtkprintoperation.h>
#endif
#ifndef GTKHTML_USES_GTKPRINT
# include <gnome.h>
# include <glib/gi18n.h>
# include <libgnomeprint/gnome-font.h>
# include <libgnomeprintui/gnome-print-job-preview.h>
#endif
#include "print-session.h"
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.printing"
#ifdef HAVE_GTK_2_10
/* Do not treat -Wstrict-aliasing warnings as errors because of problems of the
* G_LOCK* macros as declared by glib. See
* http://bugzilla.gnome.org/show_bug.cgi?id=316221 for additional information.
*/
# if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
# pragma GCC diagnostic warning "-Wstrict-aliasing"
# endif
static GtkPrintSettings *print_settings = NULL;
G_LOCK_DEFINE_STATIC(print_settings);
#endif
#ifdef HAVE_GTK_2_10
void
gnc_print_operation_save_print_settings(GtkPrintOperation *op)
{
g_return_if_fail(op);
G_LOCK(print_settings);
if (print_settings)
g_object_unref(print_settings);
print_settings = g_object_ref(gtk_print_operation_get_print_settings(op));
G_UNLOCK(print_settings);
}
void
gnc_print_operation_restore_print_settings(GtkPrintOperation *op)
{
g_return_if_fail(op);
G_LOCK(print_settings);
if (print_settings)
gtk_print_operation_set_print_settings(op, print_settings);
G_UNLOCK(print_settings);
}
#endif /* HAVE_GTK_2_10 */
#ifndef GTKHTML_USES_GTKPRINT
PrintSession *
gnc_print_session_create(gboolean hand_built_pages)
{
@ -105,3 +154,4 @@ gnc_print_session_done(PrintSession * ps)
break;
}
}
#endif /* !GTKHTML_USES_GTKPRINT */

View File

@ -24,8 +24,6 @@
#ifndef PRINT_SESSION_H
#define PRINT_SESSION_H
#ifndef GTKHTML_USES_GTKPRINT
/** @addtogroup Printing
@{ */
/** @file print-session.h
@ -33,6 +31,35 @@
@author Copyright (C) 2000 Bill Gribble <grib@billgribble.com>
*/
/** @addtogroup Basic Session Functions
@{ */
#ifdef HAVE_GTK_2_10
#include <gtk/gtkprintoperation.h>
/**
* Retrieve the print settings from the GtkPrintOperation @a op and save them in
* a static variable.
*
* @param op non-NULL print operation
*/
void gnc_print_operation_save_print_settings(GtkPrintOperation *op);
/**
* If print settings have been saved by
* gnc_print_operation_save_print_settings(), then set them on the given
* GtkPrintOperation @a op.
*
* @param op non-NULL print operation
*/
void gnc_print_operation_restore_print_settings(GtkPrintOperation *op);
#endif /* HAVE_GTK_2_10 */
#ifndef GTKHTML_USES_GTKPRINT
#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-job.h>
#include <libgnomeprintui/gnome-print-dialog.h>
@ -48,9 +75,6 @@ typedef struct {
} PrintSession;
/** @addtogroup Basic Session Functions
@{ */
/** Create a new print 'session'. Once created, a series of commands
* can be issued on the session to create the output page. The
* output will be printed when the session is done. This function
@ -84,9 +108,9 @@ void gnc_print_session_destroy(PrintSession * ps);
*/
void gnc_print_session_done(PrintSession * ps);
/** @} */
/** @} */
#endif /* !GTKHTML_USES_GTKPRINT */
#endif /* GTKHTML_USES_GTKPRINT */
/** @} */
/** @} */
#endif

View File

@ -95,14 +95,6 @@
#define KF_KEY_TEXT "Text"
#define KF_KEY_FILENAME "Filename"
/* Do not treat -Wstrict-aliasing warnings as errors because of problems of the
* G_LOCK* macros as declared by glib. See
* http://bugzilla.gnome.org/show_bug.cgi?id=316221 for additional information.
*/
#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
# pragma GCC diagnostic warning "-Wstrict-aliasing"
#endif
/**< This enum specifies the columns used in the check format combobox. */
typedef enum format_combo_col_t {
COL_NAME = 0, /**< This column holds a copy of the check
@ -119,8 +111,6 @@ typedef enum format_combo_col_t {
#if USE_GTKPRINT
# define GncPrintContext GtkPrintContext
static GtkPrintSettings *print_settings = NULL;
G_LOCK_DEFINE_STATIC(print_settings);
#else
# define GncPrintContext GnomePrintContext
# define GNOMEPRINT_CLIP_EXTRA 2
@ -1988,11 +1978,7 @@ gnc_ui_print_check_dialog_ok_cb(PrintCheckDialog * pcd)
print = gtk_print_operation_new();
G_LOCK(print_settings);
if (print_settings)
gtk_print_operation_set_print_settings(print, print_settings);
G_UNLOCK(print_settings);
gnc_print_operation_restore_print_settings(print);
gtk_print_operation_set_unit(print, GTK_UNIT_POINTS);
gtk_print_operation_set_use_full_page(print, TRUE);
g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
@ -2002,13 +1988,8 @@ gnc_ui_print_check_dialog_ok_cb(PrintCheckDialog * pcd)
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
pcd->caller_window, NULL);
if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
G_LOCK(print_settings);
if (print_settings)
g_object_unref(print_settings);
print_settings = g_object_ref(gtk_print_operation_get_print_settings(print));
G_UNLOCK(print_settings);
}
if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
gnc_print_operation_save_print_settings(print);
g_object_unref(print);
}