Commit 9ffaadd1 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

Enable the print-preview buttons.



1999-08-31  Miguel de Icaza  <miguel@gnu.org>

	* src/dialogs/dialog-printer-setup.c (do_setup_main_dialog):
	Enable the print-preview buttons.

	* configure.in (have_bonobo): Test for gnome-print 0.5

	* src/print.c (workbook_print): Adapt to the new gnome-print;
	Added support for print preview.

	* src/print-preview.c: New file.  Implements the print preview
	control window.

	* src/functions/fn-financial.c: Add brace to remove ambiguity
parent 2bd56511
1999-08-31 Miguel de Icaza <miguel@gnu.org>
* src/dialogs/dialog-printer-setup.c (do_setup_main_dialog):
Enable the print-preview buttons.
* configure.in (have_bonobo): Test for gnome-print 0.5
* src/print.c (workbook_print): Adapt to the new gnome-print;
Added support for print preview.
* src/print-preview.c: New file. Implements the print preview
control window.
* src/functions/fn-financial.c: Add brace to remove ambiguity
1999-08-31 Jukka-Pekka Iivonen <iivonen@iki.fi> 1999-08-31 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented ACCRINT() and DISC(). * src/functions/fn-financial.c: Implemented ACCRINT() and DISC().
......
...@@ -5,6 +5,9 @@ Jukka: ...@@ -5,6 +5,9 @@ Jukka:
ISPMT, RECEIVED, PRICEDISC, PRICEMAT, TBILLEQ, TBILLPRICE, ISPMT, RECEIVED, PRICEDISC, PRICEMAT, TBILLEQ, TBILLPRICE,
and TBILLYIELD functions and TBILLYIELD functions
Miguel:
* Implemented Print Preview
-------------------------------------------------------------------------- --------------------------------------------------------------------------
Gnumeric 0.32 Gnumeric 0.32
......
1999-08-31 Miguel de Icaza <miguel@gnu.org>
* src/dialogs/dialog-printer-setup.c (do_setup_main_dialog):
Enable the print-preview buttons.
* configure.in (have_bonobo): Test for gnome-print 0.5
* src/print.c (workbook_print): Adapt to the new gnome-print;
Added support for print preview.
* src/print-preview.c: New file. Implements the print preview
control window.
* src/functions/fn-financial.c: Add brace to remove ambiguity
1999-08-31 Jukka-Pekka Iivonen <iivonen@iki.fi> 1999-08-31 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented ACCRINT() and DISC(). * src/functions/fn-financial.c: Implemented ACCRINT() and DISC().
......
...@@ -164,6 +164,14 @@ dnl ****************************** ...@@ -164,6 +164,14 @@ dnl ******************************
AC_MSG_CHECKING(For GnomePrint libraries) AC_MSG_CHECKING(For GnomePrint libraries)
if gnome-config --libs print > /dev/null 2>&1; then if gnome-config --libs print > /dev/null 2>&1; then
AC_MSG_RESULT(found) AC_MSG_RESULT(found)
. `gnome-config --libdir`/printConf.sh
AC_MSG_CHECKING(For GnomePrint >= 0.6)
case x$MODULE_VERSION in
gnome-print-0.[012345])
AC_MSG_ERROR(You need at least GNOME print 0.6 for this version of Gnumeric)
;;
esac
AC_MSG_RESULT(found)
else else
AC_MSG_ERROR(Did not find GnomePrint installed) AC_MSG_ERROR(Did not find GnomePrint installed)
fi fi
......
...@@ -181,11 +181,12 @@ days_monthly_basis(Value *issue_date, Value *maturity_date, int basis) ...@@ -181,11 +181,12 @@ days_monthly_basis(Value *issue_date, Value *maturity_date, int basis)
switch (basis) { switch (basis) {
case 0: case 0:
if (issue_month == 2 && maturity_month != 2 && if (issue_month == 2 && maturity_month != 2 &&
issue_year == maturity_year) issue_year == maturity_year){
if (leap_year) if (leap_year)
return months * 30 + days - 1; return months * 30 + days - 1;
else else
return months * 30 + days - 2; return months * 30 + days - 2;
}
return months * 30 + days; return months * 30 + days;
case 1: case 1:
case 2: case 2:
......
...@@ -68,6 +68,7 @@ src/number-match.c ...@@ -68,6 +68,7 @@ src/number-match.c
src/plugin-manager.c src/plugin-manager.c
src/plugin.c src/plugin.c
src/print-info.c src/print-info.c
src/print-preview.c
src/sheet-autofill.c src/sheet-autofill.c
src/sheet-object-container.c src/sheet-object-container.c
src/sheet-view.c src/sheet-view.c
......
...@@ -116,6 +116,8 @@ GNUMERIC_BASE_SOURCES = \ ...@@ -116,6 +116,8 @@ GNUMERIC_BASE_SOURCES = \
print-cell.h \ print-cell.h \
print-info.c \ print-info.c \
print-info.h \ print-info.h \
print-preview.c \
print-preview.h \
ranges.c \ ranges.c \
ranges.h \ ranges.h \
regression.c \ regression.c \
......
...@@ -653,7 +653,14 @@ static void ...@@ -653,7 +653,14 @@ static void
do_print_cb (GtkWidget *w, dialog_print_info_t *dpi) do_print_cb (GtkWidget *w, dialog_print_info_t *dpi)
{ {
fetch_settings (dpi); fetch_settings (dpi);
workbook_print (dpi->workbook); workbook_print (dpi->workbook, FALSE);
}
static void
do_print_preview_cb (GtkWidget *w, dialog_print_info_t *dpi)
{
fetch_settings (dpi);
workbook_print (dpi->workbook, TRUE);
} }
static void static void
...@@ -683,12 +690,16 @@ do_setup_main_dialog (dialog_print_info_t *dpi) ...@@ -683,12 +690,16 @@ do_setup_main_dialog (dialog_print_info_t *dpi)
for (i = 1; i < 5; i++){ for (i = 1; i < 5; i++){
GtkWidget *w; GtkWidget *w;
char *s = g_strdup_printf ("print-%d", i); char *print = g_strdup_printf ("print-%d", i);
char *preview = g_strdup_printf ("preview-%d", i);
w = glade_xml_get_widget (dpi->gui, s); w = glade_xml_get_widget (dpi->gui, print);
gtk_signal_connect (GTK_OBJECT (w), "clicked", gtk_signal_connect (GTK_OBJECT (w), "clicked",
GTK_SIGNAL_FUNC (do_print_cb), dpi); GTK_SIGNAL_FUNC (do_print_cb), dpi);
g_free (s); w = glade_xml_get_widget (dpi->gui, preview);
gtk_signal_connect (GTK_OBJECT (w), "clicked",
GTK_SIGNAL_FUNC (do_print_preview_cb), dpi);
g_free (print);
} }
/* /*
...@@ -696,16 +707,12 @@ do_setup_main_dialog (dialog_print_info_t *dpi) ...@@ -696,16 +707,12 @@ do_setup_main_dialog (dialog_print_info_t *dpi)
*/ */
for (i = 1; i < 5; i++){ for (i = 1; i < 5; i++){
char *preview = g_strdup_printf ("preview-%d", i);
char *options = g_strdup_printf ("options-%d", i); char *options = g_strdup_printf ("options-%d", i);
GtkWidget *w; GtkWidget *w;
w = glade_xml_get_widget (dpi->gui, preview);
gtk_widget_hide (w);
w = glade_xml_get_widget (dpi->gui, options); w = glade_xml_get_widget (dpi->gui, options);
gtk_widget_hide (w); gtk_widget_hide (w);
g_free (preview);
g_free (options); g_free (options);
} }
} }
......
...@@ -181,11 +181,12 @@ days_monthly_basis(Value *issue_date, Value *maturity_date, int basis) ...@@ -181,11 +181,12 @@ days_monthly_basis(Value *issue_date, Value *maturity_date, int basis)
switch (basis) { switch (basis) {
case 0: case 0:
if (issue_month == 2 && maturity_month != 2 && if (issue_month == 2 && maturity_month != 2 &&
issue_year == maturity_year) issue_year == maturity_year){
if (leap_year) if (leap_year)
return months * 30 + days - 1; return months * 30 + days - 1;
else else
return months * 30 + days - 2; return months * 30 + days - 2;
}
return months * 30 + days; return months * 30 + days;
case 1: case 1:
case 2: case 2:
......
/*
* print.c: Print Preview control for Gnumeric
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include <gnome.h>
#include <gdk/gdkkeysyms.h>
#include <libgnomeprint/gnome-printer.h>
#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-preview.h>
#include "gnumeric.h"
#include "eval.h"
#include "gnumeric-util.h"
#include "gnumeric-sheet.h"
#include "sheet-object.h"
#include "dialogs.h"
#include "main.h"
#include "print-preview.h"
#include "print-info.h"
struct _PrintPreview {
GnomeApp *toplevel;
Workbook *workbook;
GnomePrintPreviewJob *preview_control;
GnomePrintContext *context;
GtkWidget *scrolled_window;
GnomeCanvas *canvas;
int pages;
};
/*
* Padding in points around the simulated page
*/
#define PAGE_PAD 4
static void
create_preview_canvas (PrintPreview *pp)
{
GnomeCanvasItem *i;
const GnomePaper *paper;
const char *paper_name;
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
gtk_widget_push_visual (gdk_rgb_get_visual ());
pp->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
pp->canvas = GNOME_CANVAS (gnome_canvas_new_aa ());
gnome_canvas_set_pixels_per_unit (pp->canvas, 1.0);
gtk_container_add (GTK_CONTAINER (pp->scrolled_window), GTK_WIDGET (pp->canvas));
/*
* Create the preview printing context
*/
paper = pp->workbook->print_info->paper;
paper_name = gnome_paper_name (paper);
pp->context = gnome_print_preview_new (pp->canvas, paper_name);
/*
* Now add some padding above and below and put a simulated
* page on the background
*/
i = gnome_canvas_item_new (
GNOME_CANVAS_GROUP (gnome_canvas_root (pp->canvas)),
gnome_canvas_rect_get_type (),
"x1", 0.0,
"y1", 0.0,
"x2", (double) gnome_paper_pswidth (paper),
"y2", (double) gnome_paper_psheight (paper),
"fill_color", "white",
"outline_color", "black",
"width_pixels", 1,
NULL);
gnome_canvas_item_lower_to_bottom (i);
i = gnome_canvas_item_new (
GNOME_CANVAS_GROUP (gnome_canvas_root (pp->canvas)),
gnome_canvas_rect_get_type (),
"x1", 3.0,
"y1", 3.0,
"x2", (double) gnome_paper_pswidth (paper) + 3,
"y2", (double) gnome_paper_psheight (paper) + 3,
"fill_color", "black",
NULL);
gnome_canvas_item_lower_to_bottom (i);
gnome_canvas_set_scroll_region (
pp->canvas,
0 - PAGE_PAD,
0 - PAGE_PAD,
gnome_paper_pswidth (paper) + PAGE_PAD,
gnome_paper_psheight (paper) + PAGE_PAD);
gtk_widget_show_all (pp->scrolled_window);
gnome_app_set_contents (pp->toplevel, pp->scrolled_window);
return;
}
static void
preview_destroyed (void *unused, PrintPreview *pp)
{
gtk_object_unref (GTK_OBJECT (pp->context));
gtk_object_unref (GTK_OBJECT (pp->preview_control));
}
static void
preview_close_cmd (void *unused, PrintPreview *pp)
{
gtk_object_destroy (GTK_OBJECT (pp->toplevel));
}
static void
preview_file_print_cmd (void *unused, PrintPreview *pp)
{
workbook_print (pp->workbook, FALSE);
}
static void
preview_first_page_cmd (void *unused, PrintPreview *pp)
{
gnome_print_preview_job_page_show (pp->preview_control, 0);
}
static void
preview_next_page_cmd (void *unused, PrintPreview *pp)
{
int n = gnome_print_preview_job_current_page (pp->preview_control);
if (n+2 > pp->pages)
return;
gnome_print_preview_job_page_show (pp->preview_control, n+1);
}
static void
preview_prev_page_cmd (void *unused, PrintPreview *pp)
{
int n = gnome_print_preview_job_current_page (pp->preview_control);
if (n < 1)
return;
gnome_print_preview_job_page_show (pp->preview_control, n-1);
}
static void
preview_last_page_cmd (void *unused, PrintPreview *pp)
{
gnome_print_preview_job_page_show (pp->preview_control, pp->pages-1);
}
static void
preview_zoom_in_cmd (void *unused, PrintPreview *pp)
{
gnome_canvas_set_pixels_per_unit (
pp->canvas,
pp->canvas->pixels_per_unit + 0.25);
}
static void
preview_zoom_out_cmd (void *unused, PrintPreview *pp)
{
gnome_canvas_set_pixels_per_unit (
pp->canvas,
pp->canvas->pixels_per_unit - 0.25);
}
static GnomeUIInfo preview_file_menu [] = {
GNOMEUIINFO_MENU_PRINT_ITEM (preview_file_print_cmd, NULL),
GNOMEUIINFO_MENU_CLOSE_ITEM (preview_close_cmd, NULL),
GNOMEUIINFO_END
};
static GnomeUIInfo preview_edit_menu [] = {
GNOMEUIINFO_ITEM_STOCK (
N_("_First page"), N_("Shows the first page"),
preview_first_page_cmd, GNOME_STOCK_PIXMAP_FIRST),
GNOMEUIINFO_ITEM_STOCK (
N_("_Previous page"), N_("Shows the previous page"),
preview_prev_page_cmd, GNOME_STOCK_PIXMAP_BACK),
GNOMEUIINFO_ITEM_STOCK (
N_("_Next page"), N_("Shows the next page"),
preview_next_page_cmd, GNOME_STOCK_PIXMAP_FORWARD),
GNOMEUIINFO_ITEM_STOCK (
N_("_Last page"), N_("Shows the last page"),
preview_last_page_cmd, GNOME_STOCK_PIXMAP_LAST),
GNOMEUIINFO_SEPARATOR,
#if 0
/* Shame, zoom in/zoom out is fully broken */
/* Text zooms in, but it stays on the same location, very strange */
{ GNOME_APP_UI_ITEM, N_("Zoom _in"), N_("Zooms in"), preview_zoom_in_cmd },
{ GNOME_APP_UI_ITEM, N_("Zoom _out"), N_("Zooms out"), preview_zoom_out_cmd },
#endif
GNOMEUIINFO_END
};
static GnomeUIInfo top_menu [] = {
GNOMEUIINFO_MENU_FILE_TREE (preview_file_menu),
GNOMEUIINFO_MENU_EDIT_TREE (preview_edit_menu),
GNOMEUIINFO_END
};
static void
create_toplevel (PrintPreview *pp)
{
GtkWidget *toplevel;
char *name;
gint width, height;
const GnomePaper *paper;
name = g_strdup_printf (_("Preview for %s"),
pp->workbook->filename ?
pp->workbook->filename :
_("the workbook"));
toplevel = gnome_app_new ("Gnumeric", name);
g_free (name);
paper = pp->workbook->print_info->paper;
width = gnome_paper_pswidth (paper) + PAGE_PAD * 3;
height = gnome_paper_psheight (paper) + PAGE_PAD * 3;
if (width > gdk_screen_width ()-40)
width = gdk_screen_width ()-40;
if (height > gdk_screen_height ()-100)
height = gdk_screen_height ()-100;
gtk_widget_set_usize (toplevel, width, height);
gtk_window_set_policy (GTK_WINDOW (toplevel), TRUE, TRUE, FALSE);
pp->toplevel = GNOME_APP (toplevel);
gnome_app_create_menus_with_data (pp->toplevel, top_menu, pp);
gtk_signal_connect (
GTK_OBJECT (pp->toplevel), "destroy",
GTK_SIGNAL_FUNC (preview_destroyed), pp);
}
GnomePrintContext *
print_preview_get_print_context (PrintPreview *pp)
{
g_return_val_if_fail (pp != NULL, NULL);
return pp->context;
}
static void
workbook_destroyed (void *unused, PrintPreview *pp)
{
gtk_object_destroy (GTK_OBJECT (pp->toplevel));
}
PrintPreview *
print_preview_new (Workbook *wb)
{
PrintPreview *pp;
g_return_val_if_fail (wb != NULL, NULL);
g_return_val_if_fail (IS_WORKBOOK (wb), NULL);
pp = g_new0 (PrintPreview, 1);
pp->workbook = wb;
create_toplevel (pp);
create_preview_canvas (pp);
gtk_signal_connect (
GTK_OBJECT (pp->workbook), "destroy",
GTK_SIGNAL_FUNC (workbook_destroyed), pp);
{
static int warning_shown;
if (!warning_shown){
gnumeric_notice (
wb,
GNOME_MESSAGE_BOX_WARNING,
_("The Print Preview feature is being developed.\n"
"The results of the preview is not correct currently,\n"
"it might include a buggy rendering (like black\n"
"blocks or an incorrect text placement).\n\n"
"We apologize for the inconvenience"));
}
warning_shown = 1;
}
return pp;
}
void
print_preview_print_done (PrintPreview *pp)
{
g_return_if_fail (pp != NULL);
pp->preview_control = gnome_print_preview_get_job (
GNOME_PRINT_PREVIEW (pp->context));
pp->pages = gnome_print_preview_job_num_pages (pp->preview_control);
gtk_widget_show (GTK_WIDGET (pp->toplevel));
}
#ifndef GNUMERIC_PRINT_PREVIEW_H
#define GNUMERIC_PRINT_PREVIEW_H
typedef struct _PrintPreview PrintPreview;
PrintPreview *print_preview_new (Workbook *wb);
GnomePrintContext *print_preview_get_print_context (PrintPreview *preview);
void print_preview_print_done (PrintPreview *pp);
#endif /* GNUMERIC_PRINT_PREVIEW_H */
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "print-info.h" #include "print-info.h"
#include "print.h" #include "print.h"
#include "print-cell.h" #include "print-cell.h"
#include "print-preview.h"
#define MARGIN_X 1 #define MARGIN_X 1
#define MARGIN_Y 1 #define MARGIN_Y 1
...@@ -62,6 +63,11 @@ typedef struct { ...@@ -62,6 +63,11 @@ typedef struct {
PrintInformation *pi; PrintInformation *pi;
GnomePrintContext *print_context; GnomePrintContext *print_context;
/*
* Part 4: Print Preview
*/
PrintPreview *preview;
/* /*
* For headers and footers * For headers and footers
*/ */
...@@ -173,6 +179,11 @@ print_hf (PrintJobInfo *pj, const char *format, HFSide side, double y) ...@@ -173,6 +179,11 @@ print_hf (PrintJobInfo *pj, const char *format, HFSide side, double y)
text = hf_format_render (format, pj->render_info, HF_RENDER_PRINT); text = hf_format_render (format, pj->render_info, HF_RENDER_PRINT);
if (text [0] == 0){
g_free (text);
return;
}
len = gnome_font_get_width_string (pj->decoration_font, text); len = gnome_font_get_width_string (pj->decoration_font, text);
switch (side){ switch (side){
...@@ -193,7 +204,6 @@ print_hf (PrintJobInfo *pj, const char *format, HFSide side, double y) ...@@ -193,7 +204,6 @@ print_hf (PrintJobInfo *pj, const char *format, HFSide side, double y)
} }
gnome_print_moveto (pj->print_context, x, y); gnome_print_moveto (pj->print_context, x, y);
gnome_print_show (pj->print_context, text); gnome_print_show (pj->print_context, text);
gnome_print_stroke (pj->print_context);
g_free (text); g_free (text);
} }
...@@ -543,9 +553,9 @@ setup_rotation (PrintJobInfo *pj) ...@@ -543,9 +553,9 @@ setup_rotation (PrintJobInfo *pj)
} }
void void
workbook_print (Workbook *wb) workbook_print (Workbook *wb, gboolean preview)
{ {
GnomePrinter *printer; GnomePrinter *printer = NULL;
PrintJobInfo *pj; PrintJobInfo *pj;
Sheet *sheet; Sheet *sheet;
int loop, i; int loop, i;
...@@ -554,10 +564,12 @@ workbook_print (Workbook *wb) ...@@ -554,10 +564,12 @@ workbook_print (Workbook *wb)
sheet = workbook_get_current_sheet (wb); sheet = workbook_get_current_sheet (wb);
printer = gnome_printer_dialog_new_modal (); if (!preview){
if (!printer) printer = gnome_printer_dialog_new_modal ();
return; if (!printer)
return;
}
pj = print_job_info_get (wb); pj = print_job_info_get (wb);
if (pj->sorted_print){ if (pj->sorted_print){
...@@ -566,8 +578,15 @@ workbook_print (Workbook *wb) ...@@ -566,8 +578,15 @@ workbook_print (Workbook *wb)
} else { } else {
loop = 1; loop = 1;
} }
pj->print_context = gnome_print_context_new (printer); if (preview){
pj->n_copies = 1;
loop = 1;
pj->preview = print_preview_new (wb);
pj->print_context = print_preview_get_print_context (pj->preview);
} else
pj->print_context = gnome_print_context_new_with_paper_size (
printer, gnome_paper_name (pj->pi->paper));
if (pj->pi->orientation == PRINT_ORIENT_HORIZONTAL){ if (pj->pi->orientation == PRINT_ORIENT_HORIZONTAL){
setup_rotation (pj); setup_rotation (pj);
...@@ -588,11 +607,14 @@ workbook_print (Workbook *wb) ...@@ -588,11 +607,14 @@ workbook_print (Workbook *wb)
} }