Commit d8da15af authored by Michael Meeks's avatar Michael Meeks

New printer dialog with options,

Improved auto object sizing.
parent 4fd626f2
1999-09-16 Michael Meeks <michael@nuclecu.unam.mx>
* src/print.c (sheet_print): Update to use gnumeric_porinter_dialog_run.
(print_job_info_get): Add range parameter.
* src/dialogs/Makefile.am (libdialogs_a_SOURCES): Added dialog-printer.[ch]
* src/dialogs/dialog-printer.[ch]: New thin wrapper of GnomePrinterDialog
to handle sheet selection.
* src/sheet-object-container.c (sheet_object_container_land): Add
comments about what needs doing.
* src/sheet-object.c (sheet_object_event): renamed.
Updated various SheetObject var names to 'so'.
1999-09-15 Michael Meeks <michael@nuclecu.unam.mx>
* src/sheet-object-container.c (sheet_object_container_land): Cleaned
debug, improved sizing logic.
1999-09-16 Jody Goldberg <jgoldberg@home.com>
* src/ranges.c (range_dump) : Typo.
......
1999-09-16 Michael Meeks <michael@nuclecu.unam.mx>
* src/print.c (sheet_print): Update to use gnumeric_porinter_dialog_run.
(print_job_info_get): Add range parameter.
* src/dialogs/Makefile.am (libdialogs_a_SOURCES): Added dialog-printer.[ch]
* src/dialogs/dialog-printer.[ch]: New thin wrapper of GnomePrinterDialog
to handle sheet selection.
* src/sheet-object-container.c (sheet_object_container_land): Add
comments about what needs doing.
* src/sheet-object.c (sheet_object_event): renamed.
Updated various SheetObject var names to 'so'.
1999-09-15 Michael Meeks <michael@nuclecu.unam.mx>
* src/sheet-object-container.c (sheet_object_container_land): Cleaned
debug, improved sizing logic.
1999-09-16 Jody Goldberg <jgoldberg@home.com>
* src/ranges.c (range_dump) : Typo.
......
......@@ -28,6 +28,8 @@ libdialogs_a_SOURCES = \
dialog-define-names.c \
dialog-delete-cells.c \
dialog-paste-special.c \
dialog-printer.c \
dialog-printer.h \
dialog-printer-setup.c \
dialog-summary.c \
dialog-solver.c \
......
/*
* The gnumeric print dialog.
*
* Author:
* Michael Meeks (mmeeks@gnu.org)
*
*/
#include <config.h>
#include <libgnomeprint/gnome-print-i18n.h>
#include <gnome.h>
#include <libgnomeprint/gnome-printer.h>
#include <libgnomeprint/gnome-printer-profile.h>
#include <libgnomeprint/gnome-printer-dialog.h>
#include "sheet.h"
#include "dialog-printer.h"
static GnomePrinterDialogClass *dialog_parent_class = NULL;
static void
gnumeric_printer_dialog_class_init (GnomePrinterDialogClass *class)
{
dialog_parent_class = gtk_type_class (gnome_dialog_get_type ());
}
GtkType
gnumeric_printer_dialog_get_type (void)
{
static GtkType printer_dialog_type = 0;
if (!printer_dialog_type)
{
GtkTypeInfo printer_dialog_info =
{
"GnumericPrinterDialog",
sizeof (GnumericPrinterDialog),
sizeof (GnumericPrinterDialogClass),
(GtkClassInitFunc) gnumeric_printer_dialog_class_init,
(GtkObjectInitFunc) NULL,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
printer_dialog_type = gtk_type_unique (gnome_dialog_get_type (),
&printer_dialog_info);
}
return printer_dialog_type;
}
static void
range_clicked (GtkButton *button, GnumericPrinterDialog *pd)
{
gpointer ptr;
g_return_if_fail (pd != NULL);
g_return_if_fail (button != NULL);
ptr = gtk_object_get_data (GTK_OBJECT (button), "print_range");
pd->range = GPOINTER_TO_INT (ptr);
}
static GtkWidget *
make_range_sel_widget (GnumericPrinterDialog *pd)
{
GtkTable *tab = GTK_TABLE (gtk_table_new (2, 2, FALSE));
GtkWidget *button;
button = gtk_radio_button_new_with_label (NULL,
_("active sheet"));
gtk_object_set_data (GTK_OBJECT (button), "print_range",
GINT_TO_POINTER (PRINT_ACTIVE_SHEET));
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (range_clicked), pd);
if (pd->range == PRINT_ACTIVE_SHEET)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button),
TRUE);
gtk_table_attach_defaults (tab, button, 0, 1, 0, 1);
button = gtk_radio_button_new_with_label (
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
_("all sheets"));
gtk_object_set_data (GTK_OBJECT (button), "print_range",
GINT_TO_POINTER (PRINT_ALL_SHEETS));
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (range_clicked), pd);
if (pd->range == PRINT_ALL_SHEETS)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button),
TRUE);
gtk_table_attach_defaults (tab, button, 1, 2, 0, 1);
button = gtk_radio_button_new_with_label (
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
_("selection"));
gtk_object_set_data (GTK_OBJECT (button), "print_range",
GINT_TO_POINTER (PRINT_SHEET_SELECTION));
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (range_clicked), pd);
if (pd->range == PRINT_SHEET_SELECTION)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button),
TRUE);
gtk_table_attach_defaults (tab, button, 0, 1, 1, 2);
gtk_widget_show_all (GTK_WIDGET (tab));
return GTK_WIDGET (tab);
}
PrintRange
gnumeric_printer_dialog_get_range (GnumericPrinterDialog *pd)
{
if (!pd)
return PRINT_ACTIVE_SHEET;
else
return pd->range;
}
GtkWidget *
gnumeric_printer_dialog_new (PrintRange default_range)
{
GnumericPrinterDialog *pd;
GtkWidget *printer_dialog;
pd = gtk_type_new (gnumeric_printer_dialog_get_type ());
printer_dialog = GTK_WIDGET (pd);
pd->range = default_range;
gtk_window_set_title (GTK_WINDOW (printer_dialog), _("Select Printer"));
gnome_dialog_append_button (GNOME_DIALOG (printer_dialog),
GNOME_STOCK_BUTTON_OK);
gnome_dialog_append_button (GNOME_DIALOG (printer_dialog),
GNOME_STOCK_BUTTON_CANCEL);
gnome_dialog_set_default (GNOME_DIALOG(printer_dialog), 0);
pd->gnome_printer_widget = GNOME_PRINTER_WIDGET (gnome_printer_widget_new ());
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (printer_dialog)->vbox),
GTK_WIDGET (pd->gnome_printer_widget),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (printer_dialog)->vbox),
make_range_sel_widget (pd),
TRUE, TRUE, 0);
return GTK_WIDGET (pd);
}
/**
* gnumeric_printer_dialog_run:
* @range: pointer to the default range
*
* A convenience function.
*
* Return value: the selected range in *range.
**/
GnomePrinter *
gnumeric_printer_dialog_run (PrintRange *range)
{
int bn;
GnumericPrinterDialog *pd;
GnomePrinter *printer;
GtkWidget *printer_dialog;
printer_dialog = gnumeric_printer_dialog_new (*range);
pd = GNUMERIC_PRINTER_DIALOG (printer_dialog);
gtk_window_set_modal (GTK_WINDOW (printer_dialog), TRUE);
bn = gnome_dialog_run (GNOME_DIALOG (printer_dialog));
if (bn < 0)
return NULL;
printer = NULL;
if (bn == 0) {
printer = gnome_printer_widget_get_printer (
GNOME_PRINTER_WIDGET (pd->gnome_printer_widget));
*range = gnumeric_printer_dialog_get_range (pd);
}
gtk_widget_destroy (printer_dialog);
return printer;
}
#ifndef GNUMERIC_DIALOG_PRINT_H
#define GNUMERIC_DIALOG_PRINT_H
#include "print.h"
#define GNUMERIC_TYPE_PRINTER_DIALOG (gnumeric_printer_dialog_get_type ())
#define GNUMERIC_PRINTER_DIALOG(obj) (GTK_CHECK_CAST ((obj), GNUMERIC_TYPE_PRINTER_DIALOG, GnumericPrinterDialog))
#define GNUMERIC_PRINTER_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNUMERIC_TYPE_PRINTER_DIALOG, GnumericPrinterDialogClass))
#define GNUMERIC_IS_PRINTER_DIALOG(obj) (GTK_CHECK_TYPE ((obj), GNUMERIC_TYPE_PRINTER_DIALOG))
#define GNUMERIC_IS_PRINTER_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNUMERIC_TYPE_PRINTER_DIALOG))
typedef struct {
GnomeDialog dialog;
GnomePrinterWidget *gnome_printer_widget;
PrintRange range;
} GnumericPrinterDialog;
typedef struct {
GnomeDialogClass parent_class;
} GnumericPrinterDialogClass;
GtkType gnumeric_printer_dialog_get_type (void);
GtkWidget *gnumeric_printer_dialog_new (PrintRange default_range);
PrintRange gnumeric_printer_dialog_get_range (GnumericPrinterDialog *pd);
GnomePrinter *gnumeric_printer_dialog_run (PrintRange *range);
#endif /* GNUMERIC_DIALOG_PRINT_H */
......@@ -28,6 +28,7 @@
#include "print.h"
#include "print-cell.h"
#include "print-preview.h"
#include "dialog-printer.h"
#define MARGIN_X 1
#define MARGIN_Y 1
......@@ -498,7 +499,7 @@ workbook_print_all (Workbook *wb, PrintJobInfo *pj)
}
static PrintJobInfo *
print_job_info_get (Sheet *sheet)
print_job_info_get (Sheet *sheet, PrintRange range)
{
PrintJobInfo *pj;
PrintMargins *pm = &sheet->print_info->margins;
......@@ -517,7 +518,7 @@ print_job_info_get (Sheet *sheet)
*/
pj->start_page = 0;
pj->end_page = -1;
pj->range = PRINT_ALL_SHEETS;
pj->range = range;
pj->sorted_print = TRUE;
pj->n_copies = 1;
......@@ -583,15 +584,11 @@ sheet_print (Sheet *sheet, gboolean preview,
g_return_if_fail (sheet != NULL);
if (!preview) {
/* FIXME: we need to whack a selection/active/entire
choice in here, with a default, for now force default */
printer = gnome_printer_dialog_new_modal ();
if (!printer)
if (!(printer = gnumeric_printer_dialog_run (&default_range)))
return;
}
pj = print_job_info_get (sheet);
pj->range = default_range; /* for now */
pj = print_job_info_get (sheet, default_range);
if (pj->sorted_print) {
loop = pj->n_copies;
......
......@@ -286,7 +286,14 @@ sheet_object_container_land (SheetObject *so, const gchar *fname,
GTK_SIGNAL_FUNC (user_activation_request_cb), so);
gtk_signal_connect (GTK_OBJECT (view_frame), "view_activated",
GTK_SIGNAL_FUNC (view_activated_cb), so);
/*
* We need somehow to grab events from the wrapper in order to be able to
* move the component around easily.
*
* gtk_signal_connect (GTK_OBJECT (gnome_view_frame_get_wrapper (view_frame)),
* "event",
* GTK_SIGNAL_FUNC (sheet_object_event), so);
*/
/*
* 5. Ask the component how big it wants to be, if it is allowed.
......@@ -295,13 +302,9 @@ sheet_object_container_land (SheetObject *so, const gchar *fname,
int dx = -1, dy = -1;
gnome_view_frame_size_request (view_frame, &dx, &dy);
if (dx < 8 || dy < 8)
g_warning ("Refused to auto-size %s to %d %d",
soc->repoid?soc->repoid:"No ID!", dx, dy);
else {
if (dx > 0 && dy > 0) {
double tlx, tly, brx, bry;
printf ("Auto sizing\n");
sheet_object_get_bounds (so, &tlx, &tly, &brx, &bry);
sheet_object_set_bounds (so, tlx, tly, tlx + dx, tly + dy);
}
......
......@@ -3,7 +3,7 @@
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
* Michael Meeks (mmeeks@gnu.org)
* Michael Meeks (mmeeks@gnu.org)
*/
#include <config.h>
#include <gnome.h>
......@@ -28,12 +28,9 @@
static GtkObjectClass *sheet_object_parent_class;
static void sheet_finish_object_creation (Sheet *sheet, SheetObject *object);
static void sheet_object_start_editing (SheetObject *object);
static void sheet_object_stop_editing (SheetObject *object);
static int object_event (GnomeCanvasItem *item,
GdkEvent *event,
SheetObject *object);
static void sheet_finish_object_creation (Sheet *sheet, SheetObject *so);
static void sheet_object_start_editing (SheetObject *so);
static void sheet_object_stop_editing (SheetObject *so);
typedef struct {
gdouble x, y;
......@@ -129,17 +126,17 @@ sheet_object_get_type (void)
}
void
sheet_object_construct (SheetObject *sheet_object, Sheet *sheet)
sheet_object_construct (SheetObject *so, Sheet *sheet)
{
g_return_if_fail (sheet_object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (sheet_object));
g_return_if_fail (so != NULL);
g_return_if_fail (IS_SHEET_OBJECT (so));
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
sheet_object->sheet = sheet;
sheet_object->bbox_points = gnome_canvas_points_new (2);
so->sheet = sheet;
so->bbox_points = gnome_canvas_points_new (2);
sheet->objects = g_list_prepend (sheet->objects, sheet_object);
sheet->objects = g_list_prepend (sheet->objects, so);
}
void
......@@ -161,19 +158,19 @@ sheet_object_drop_file (GnumericSheet *gsheet, gint x, gint y, const char *fname
msg = g_strdup_printf ("no mime mapping for '%s'", mime_type);
gnome_dialog_run_and_close (GNOME_DIALOG (gnome_error_dialog (msg)));
} else {
SheetObject *obj;
SheetObject *so;
ObjectCoords pos;
gnome_canvas_window_to_world (GNOME_CANVAS (gsheet), x, y, &pos.x, &pos.y);
obj = sheet_object_container_new (gsheet->sheet_view->sheet, pos.x, pos.y,
pos.x + 100.0, pos.y + 100.0,
mime_goad_id);
if (!sheet_object_container_land (obj, fname, TRUE)) {
so = sheet_object_container_new (gsheet->sheet_view->sheet, pos.x, pos.y,
pos.x + 100.0, pos.y + 100.0,
mime_goad_id);
if (!sheet_object_container_land (so, fname, TRUE)) {
msg = g_strdup_printf ("Failed to bind or create client site for '%s'",
mime_goad_id);
gnome_dialog_run_and_close (GNOME_DIALOG (gnome_error_dialog (msg)));
gtk_object_destroy (GTK_OBJECT (obj));
gtk_object_destroy (GTK_OBJECT (so));
}
}
if (msg)
......@@ -246,16 +243,16 @@ sheet_object_set_bounds (SheetObject *so, double tlx, double tly,
* Creates the actual object on the Canvas of a SheetView
*/
static GnomeCanvasItem *
sheet_view_object_realize (SheetView *sheet_view, SheetObject *object)
sheet_view_object_realize (SheetView *sheet_view, SheetObject *so)
{
GnomeCanvasItem *item;
g_return_val_if_fail (sheet_view != NULL, NULL);
g_return_val_if_fail (IS_SHEET_VIEW (sheet_view), NULL);
g_return_val_if_fail (object != NULL, NULL);
g_return_val_if_fail (IS_SHEET_OBJECT (object), NULL);
g_return_val_if_fail (so != NULL, NULL);
g_return_val_if_fail (IS_SHEET_OBJECT (so), NULL);
item = SO_CLASS (object)->realize (object, sheet_view);
item = SO_CLASS (so)->realize (so, sheet_view);
if (item == NULL) {
g_warning ("We created an unsupported type\n");
......@@ -263,9 +260,9 @@ sheet_view_object_realize (SheetView *sheet_view, SheetObject *object)
}
gtk_signal_connect (GTK_OBJECT (item), "event",
GTK_SIGNAL_FUNC (object_event), object);
GTK_SIGNAL_FUNC (sheet_object_event), so);
object->realized_list = g_list_prepend (object->realized_list, item);
so->realized_list = g_list_prepend (so->realized_list, item);
return item;
}
......@@ -275,16 +272,16 @@ sheet_view_object_realize (SheetView *sheet_view, SheetObject *object)
* Removes the object from the canvas in the SheetView.
*/
static void
sheet_view_object_unrealize (SheetView *sheet_view, SheetObject *object)
sheet_view_object_unrealize (SheetView *sheet_view, SheetObject *so)
{
GList *l;
g_return_if_fail (sheet_view != NULL);
g_return_if_fail (IS_SHEET_VIEW (sheet_view));
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (object));
g_return_if_fail (so != NULL);
g_return_if_fail (IS_SHEET_OBJECT (so));
l = object->realized_list;
l = so->realized_list;
while (l) {
GnomeCanvasItem *item = GNOME_CANVAS_ITEM (l->data);
GnumericSheet *gsheet = GNUMERIC_SHEET (item->canvas);
......@@ -296,7 +293,7 @@ sheet_view_object_unrealize (SheetView *sheet_view, SheetObject *object)
}
gtk_object_destroy (GTK_OBJECT (item));
object->realized_list = g_list_remove (object->realized_list, item);
so->realized_list = g_list_remove (so->realized_list, item);
l = next;
break;
}
......@@ -309,19 +306,19 @@ sheet_view_object_unrealize (SheetView *sheet_view, SheetObject *object)
* on every existing SheetView)
*/
void
sheet_object_realize (SheetObject *object)
sheet_object_realize (SheetObject *so)
{
GList *l;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (object));
g_return_if_fail (so != NULL);
g_return_if_fail (IS_SHEET_OBJECT (so));
for (l = object->sheet->sheet_views; l; l = l->next){
for (l = so->sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
GnomeCanvasItem *item;
item = sheet_view_object_realize (sheet_view, object);
sheet_view->temp_item = object;
item = sheet_view_object_realize (sheet_view, so);
sheet_view->temp_item = so;
}
}
......@@ -332,17 +329,17 @@ sheet_object_realize (SheetObject *object)
* every SheetViews.
*/
void
sheet_object_unrealize (SheetObject *object)
sheet_object_unrealize (SheetObject *so)
{
GList *l;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (object));
g_return_if_fail (so != NULL);
g_return_if_fail (IS_SHEET_OBJECT (so));
for (l = object->sheet->sheet_views; l; l = l->next){
for (l = so->sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
sheet_view_object_unrealize (sheet_view, object);
sheet_view_object_unrealize (sheet_view, so);
sheet_view->temp_item = NULL;
}
}
......@@ -540,7 +537,7 @@ sheet_button_press (GnumericSheet *gsheet, GdkEventButton *event, Sheet *sheet)
{
ObjectCoords *oc;
if (sheet->current_object){
if (sheet->current_object) {
sheet_object_stop_editing (sheet->current_object);
sheet->current_object = NULL;
}
......@@ -560,7 +557,7 @@ sheet_button_press (GnumericSheet *gsheet, GdkEventButton *event, Sheet *sheet)
* If something fails during object creation,
* set the mode to the normal sheet mode
*/
if (!sheet->current_object){
if (!sheet->current_object) {
sheet_set_mode_type (sheet, SHEET_MODE_SHEET);
return 1;
}
......@@ -645,14 +642,14 @@ sheet_set_mode_type (Sheet *sheet, SheetModeType mode)
sheet->mode = mode;
if (mode == SHEET_MODE_OBJECT_SELECTED){
if (mode == SHEET_MODE_OBJECT_SELECTED) {
sheet_hide_cursor (sheet);
return;
}
if (mode == SHEET_MODE_SHEET){
if (mode == SHEET_MODE_SHEET) {
#ifdef ENABLE_BONOBO
if (sheet->active_object_frame){
if (sheet->active_object_frame) {
gnome_view_frame_view_deactivate (sheet->active_object_frame);
if (sheet->active_object_frame != NULL)
gnome_view_frame_set_covered (sheet->active_object_frame, TRUE);
......@@ -660,7 +657,7 @@ sheet_set_mode_type (Sheet *sheet, SheetModeType mode)
}
#endif
sheet_show_cursor (sheet);
if (sheet->current_object){
if (sheet->current_object) {
sheet_object_stop_editing (sheet->current_object);
sheet->current_object = NULL;
}
......@@ -713,11 +710,11 @@ sheet_object_destroy_control_points (Sheet *sheet)
}
static void
sheet_object_stop_editing (SheetObject *object)
sheet_object_stop_editing (SheetObject *so)
{
Sheet *sheet = object->sheet;
Sheet *sheet = so->sheet;
if (object == sheet->current_object)
if (so == sheet->current_object)
sheet_object_destroy_control_points (sheet);
}
......@@ -761,12 +758,12 @@ set_item_y (SheetView *sheet_view, int idx, double y)
*
**/
static void
update_bbox (SheetObject *object)
update_bbox (SheetObject *so)
{
GList *l;
const double *c = object->bbox_points->coords;
const double *c = so->bbox_points->coords;
for (l = object->sheet->sheet_views; l; l = l->next) {
for (l = so->sheet->sheet_views; l; l = l->next) {
SheetView *sheet_view = l->data;
set_item_x (sheet_view, 0, c[0]);
......@@ -895,12 +892,12 @@ control_point_handle_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject
}
/*
* object_event
* sheet_object_event
*
* Event handler for a SheetObject
*/
static int
object_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject *so)
int
sheet_object_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject *so)
{
static int last_x, last_y;
static int total_x, total_y;
......@@ -912,7 +909,7 @@ object_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject *so)
break;
case GDK_BUTTON_PRESS:
if (so->sheet->current_object){
if (so->sheet->current_object) {
sheet_object_stop_editing (so->sheet->current_object);
so->sheet->current_object = NULL;
}
......
......@@ -39,6 +39,8 @@ GtkType sheet_object_get_type (void);
void sheet_object_construct (SheetObject *sheet_object, Sheet *sheet);
void sheet_object_drop_file (GnumericSheet *gsheet, gint x, gint y,
const char *fname);
int sheet_object_event (GnomeCanvasItem *item, GdkEvent *event,
SheetObject *so);
/* b = bottom, t = top, l = left, r = right */
void sheet_object_get_bounds (SheetObject *sheet_object, double *tlx, double *tly,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment