aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/ChangeLog18
-rw-r--r--calendar/gui/Makefile.am5
-rw-r--r--calendar/gui/calendar-commands.c60
-rw-r--r--calendar/gui/e-day-view.c15
-rw-r--r--calendar/gui/e-week-view.c7
-rw-r--r--calendar/gui/print.c194
-rw-r--r--calendar/gui/print.h2
7 files changed, 170 insertions, 131 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index f7a0268510..9a384b3337 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,5 +1,23 @@
2000-06-02 Federico Mena Quintero <federico@helixcode.com>
+ * gui/calendar-commands.c (print): New function to call the print
+ engine.
+ (calendar_toolbar): Added the Print button.
+ (calendar_control_activate): Added the File/Print item.
+
+ * gui/e-day-view.c (e_day_view_get_selected_time_range): Allow
+ start_time and end_time to be NULL.
+
+ * gui/e-week-view.c (e_week_view_get_selected_time_range):
+ Likewise.
+
+ * gui/print.c (range_selector_new): Show the range selector
+ widgets. Use the correct radio group for all of them!
+ (print_calendar): Do the dialog box here. We may want to split
+ this function later into smaller chunks.
+
+2000-06-02 Federico Mena Quintero <federico@helixcode.com>
+
* gui/event-editor.c (tb_save_and_close_cb): Implemented.
(toolbar): Added an icon for the Save and Close command.
(save_ical_object): Recompute the title of the window here. Maybe
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index 6da0812b23..c1e06b53ac 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -82,11 +82,10 @@ evolution_calendar_SOURCES = \
mark.h \
popup-menu.c \
popup-menu.h \
+ print.c \
+ print.h \
prop.c
-# print.c \
-# print.h \
-
# FIXME We should make a libeshell library instead of this gross hack.
SHELL_OBJS = \
$(top_builddir)/shell/Evolution-common.o \
diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c
index 96896810e6..49bb023875 100644
--- a/calendar/gui/calendar-commands.c
+++ b/calendar/gui/calendar-commands.c
@@ -22,6 +22,7 @@
#include <cal-util/timeutil.h>
#include "gnome-cal.h"
#include "calendar-commands.h"
+#include "print.h"
#include "dayview.xpm"
#include "workweekview.xpm"
@@ -224,6 +225,51 @@ display_objedit_today (BonoboUIHandler *uih, void *user_data, const char *path)
ical_object_unref (ico);
}
+/* Prints the calendar at its current view and time range */
+static void
+print (GnomeCalendar *gcal, gboolean preview)
+{
+ time_t start;
+ const char *view;
+ PrintView print_view;
+
+ gnome_calendar_get_current_time_range (gcal, &start, NULL);
+ view = gnome_calendar_get_current_view_name (gcal);
+
+ if (strcmp (view, "dayview") == 0)
+ print_view = PRINT_VIEW_DAY;
+ else if (strcmp (view, "workweekview") == 0 || strcmp (view, "weekview") == 0)
+ print_view = PRINT_VIEW_WEEK;
+ else if (strcmp (view, "monthview") == 0)
+ print_view = PRINT_VIEW_MONTH;
+ else {
+ g_assert_not_reached ();
+ print_view = PRINT_VIEW_DAY;
+ }
+
+ print_calendar (gcal, preview, start, print_view);
+}
+
+/* Toolbar/Print callback */
+static void
+tb_print_cb (GtkWidget *widget, gpointer data)
+{
+ GnomeCalendar *gcal;
+
+ gcal = GNOME_CALENDAR (data);
+ print (gcal, FALSE);
+}
+
+/* File/Print callback */
+static void
+file_print_cb (BonoboUIHandler *uih, void *data, const char *path)
+{
+ GnomeCalendar *gcal;
+
+ gcal = GNOME_CALENDAR (data);
+ print (gcal, FALSE);
+}
+
void
time_format_changed (void)
{
@@ -494,11 +540,15 @@ static GnomeUIInfo gnome_toolbar_view_buttons [] = {
};
-static GnomeUIInfo gnome_toolbar [] = {
+static GnomeUIInfo calendar_toolbar [] = {
GNOMEUIINFO_ITEM_STOCK (N_("New"), N_("Create a new appointment"), display_objedit, GNOME_STOCK_PIXMAP_NEW),
GNOMEUIINFO_SEPARATOR,
+ GNOMEUIINFO_ITEM_STOCK (N_("Print"), N_("Print this calendar"), tb_print_cb, GNOME_STOCK_PIXMAP_PRINT),
+
+ GNOMEUIINFO_SEPARATOR,
+
GNOMEUIINFO_ITEM_STOCK (N_("Prev"), N_("Go back in time"), previous_clicked, GNOME_STOCK_PIXMAP_BACK),
GNOMEUIINFO_ITEM_STOCK (N_("Today"), N_("Go to present time"), today_clicked, GNOME_STOCK_PIXMAP_HOME),
GNOMEUIINFO_ITEM_STOCK (N_("Next"), N_("Go forward in time"), next_clicked, GNOME_STOCK_PIXMAP_FORWARD),
@@ -561,7 +611,7 @@ calendar_control_activate (BonoboControl *control,
toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL,
GTK_TOOLBAR_BOTH);
gnome_app_fill_toolbar_custom (GTK_TOOLBAR (toolbar),
- gnome_toolbar, &uibdata,
+ calendar_toolbar, &uibdata,
/*app->accel_group*/ NULL);
/*gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));*/
@@ -617,6 +667,12 @@ calendar_control_activate (BonoboControl *control,
-1,
BONOBO_UI_HANDLER_PIXMAP_NONE, NULL,
0, 0, save_as_calendar_cmd, cal);
+ bonobo_ui_handler_menu_new_item (uih, "/File/Print", N_("Print..."),
+ N_("Print this calendar"), -1,
+ BONOBO_UI_HANDLER_PIXMAP_STOCK,
+ GNOME_STOCK_PIXMAP_PRINT,
+ 'p', GDK_CONTROL_MASK,
+ file_print_cb, cal);
bonobo_ui_handler_menu_new_item (uih, "/File/Close", N_("_Close Calendar"),
N_("Close current calendar"),
-1, BONOBO_UI_HANDLER_PIXMAP_NONE, NULL,
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index 66fd908afd..891c378816 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -1566,6 +1566,7 @@ e_day_view_get_selected_time_range (EDayView *day_view,
time_t *end_time)
{
gint start_col, start_row, end_col, end_row;
+ time_t start, end;
start_col = day_view->selection_start_day;
start_row = day_view->selection_start_row;
@@ -1582,13 +1583,19 @@ e_day_view_get_selected_time_range (EDayView *day_view,
/* Check if the selection is only in the top canvas, in which case
we can simply use the day_starts array. */
if (day_view->selection_in_top_canvas) {
- *start_time = day_view->day_starts[start_col];
- *end_time = day_view->day_starts[end_col + 1];
+ start = day_view->day_starts[start_col];
+ end = day_view->day_starts[end_col + 1];
} else {
/* Convert the start col + row into a time. */
- *start_time = e_day_view_convert_grid_position_to_time (day_view, start_col, start_row);
- *end_time = e_day_view_convert_grid_position_to_time (day_view, end_col, end_row + 1);
+ start = e_day_view_convert_grid_position_to_time (day_view, start_col, start_row);
+ end = e_day_view_convert_grid_position_to_time (day_view, end_col, end_row + 1);
}
+
+ if (start_time)
+ *start_time = start;
+
+ if (end_time)
+ *end_time = end;
}
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index d756fd7a51..8eb053e28b 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -847,8 +847,11 @@ e_week_view_get_selected_time_range (EWeekView *week_view,
end_day = 0;
}
- *start_time = week_view->day_starts[start_day];
- *end_time = week_view->day_starts[end_day + 1];
+ if (start_time)
+ *start_time = week_view->day_starts[start_day];
+
+ if (end_time)
+ *end_time = week_view->day_starts[end_day + 1];
}
diff --git a/calendar/gui/print.c b/calendar/gui/print.c
index d3cf5015cf..436221ebc6 100644
--- a/calendar/gui/print.c
+++ b/calendar/gui/print.c
@@ -27,6 +27,7 @@
#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-copies.h>
#include <libgnomeprint/gnome-print-master.h>
+#include <libgnomeprint/gnome-print-master-preview.h>
#include <libgnomeprint/gnome-print-preview.h>
#include <libgnomeprint/gnome-printer-profile.h>
#include <libgnomeprint/gnome-printer-dialog.h>
@@ -35,11 +36,10 @@
#include "calendar-commands.h"
#include "gnome-cal.h"
#include "layout.h"
+#include "print.h"
-static void show_print_dialogue(void);
-
/* copied from gnome-month-item.c this should be shared?? */
/* Number of days in a month, for normal and leap years */
@@ -1003,7 +1003,7 @@ static GtkWidget *
range_selector_new (GtkWidget *dialog, time_t at, int *view)
{
GtkWidget *box;
- GtkWidge *radio;
+ GtkWidget *radio;
GSList *group;
char text[1024];
struct tm tm;
@@ -1024,7 +1024,7 @@ range_selector_new (GtkWidget *dialog, time_t at, int *view)
/* Week */
week_begin = time_week_begin (at);
- week_end = time_add_day (time_time_week_end (at), -1);
+ week_end = time_add_day (time_week_end (at), -1);
week_begin_tm = *localtime (&week_begin);
week_end_tm = *localtime (&week_end);
@@ -1071,103 +1071,105 @@ range_selector_new (GtkWidget *dialog, time_t at, int *view)
}
radio = gtk_radio_button_new_with_label (group, text);
+ group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio));
gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0);
/* Month */
strftime (text, sizeof (text), _("Current month (%a %Y)"), &tm);
radio = gtk_radio_button_new_with_label (group, text);
+ group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio));
gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0);
/* Year */
strftime (text, sizeof (text), _("Current year (%Y)"), &tm);
radio = gtk_radio_button_new_with_label (group, text);
+ group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio));
gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0);
/* Select default */
- e_dialog_widget_hook_value (dialog, radio, view, print_view_map);
+ e_dialog_widget_hook_value (dialog, radio, view, (gpointer) print_view_map);
+
+ gtk_widget_show_all (box);
+ return box;
}
-/* Shows the print dialog. The new values are returned in the at and view
- * variables.
- */
-static enum GnomePrintButtons
-print_dialog (GnomeCalendar *gcal, time_t *at, PrintView *view, GnomePrinter **printer)
+void
+print_calendar (GnomeCalendar *gcal, gboolean preview, time_t at, PrintView default_view)
{
- GnomePrintDialog *pd;
- GtkWidget *range;
- int int_view;
- enum GnomePrintButtons retval;
+ GnomePrinter *printer;
+ GnomePrintMaster *gpm;
+ GnomePrintContext *pc;
+ int copies, collate;
+ const GnomePaper *paper_info;
+ double l, r, t, b, todo, header;
+ char buf[100];
+ time_t when;
- pd = gnome_print_dialog_new (_("Print Calendar"),
- GNOME_PRINT_DIALOG_RANGE | GNOME_PRINT_DIALOG_COPIES);
+ g_return_if_fail (gcal != NULL);
+ g_return_if_fail (GNOME_IS_CALENDAR (gcal));
- int_view = *view;
+ printer = NULL;
+ copies = 1;
+ collate = FALSE;
- range = range_selector_new (GTK_WIDGET (pd), *at, &int_view);
- gnome_print_dialog_construct_range_custom (pd, range);
+ if (!preview) {
+ GtkWidget *gpd;
+ GtkWidget *range;
+ int view;
- gnome_dialog_set_default (GNOME_DIALOG (pd), GNOME_PRINT_PRINT);
+ gpd = gnome_print_dialog_new (_("Print Calendar"),
+ GNOME_PRINT_DIALOG_RANGE | GNOME_PRINT_DIALOG_COPIES);
- /* Run! */
+ view = (int) default_view;
+ range = range_selector_new (gpd, at, &view);
+ gnome_print_dialog_construct_range_custom (GNOME_PRINT_DIALOG (gpd), range);
- retval = gnome_dialog_run (GNOME_DIALOG (pd));
+ gnome_dialog_set_default (GNOME_DIALOG (gpd), GNOME_PRINT_PRINT);
- switch (retval) {
- case GNOME_PRINT_PRINT:
- case GNOME_PRINT_PREVIEW:
- e_dialog_get_values (GTK_WIDGET (pd));
- *view = int_view;
+ /* Run dialog */
- *printer = gnome_print_dialog_get_printer (pd);
- break;
+ switch (gnome_dialog_run (GNOME_DIALOG (gpd))) {
+ case GNOME_PRINT_PRINT:
+ break;
- default:
- retval = GNOME_PRINT_CANCEL;
- break;
- }
+ case GNOME_PRINT_PREVIEW:
+ preview = TRUE;
+ break;
- gnome_dialog_close (GNOME_DIALOG (pd));
- return retval;
-}
+ case -1:
+ return;
-void
-print_calendar (GnomeCalendar *gcal, time_t at, PrintView default_view)
-{
- GnomePrinter *printer;
- GnomePrintMaster *gpm;
- GnomePrintContext *pc;
+ default:
+ gnome_dialog_close (GNOME_DIALOG (gpd));
+ return;
+ }
- switch (print_dialog (gcal, &at, &default_view, &printer)) {
- case GNOME_PRINT_PRINT:
- break;
+ e_dialog_get_values (gpd);
+ default_view = (PrintView) view;
- case GNOME_PRINT_PREVIEW:
- /* FIXME */
- break;
+ gnome_print_dialog_get_copies (GNOME_PRINT_DIALOG (gpd), &copies, &collate);
+ printer = gnome_print_dialog_get_printer (GNOME_PRINT_DIALOG (gpd));
- default:
- return;
+ gnome_dialog_close (GNOME_DIALOG (gpd));
}
- g_assert (printer != NULL);
+ /* FIXME: allow configuration of paper size */
gpm = gnome_print_master_new ();
- gnome_print_master_set_printer (gpm, printer);
-
- const GnomePaper *paper_info;
- double l, r, t, b, todo, header;
- char buf[100];
- time_t when;
- char *paper = "A4";
- GnomePrintMaster *gpm = gnome_print_master_new ();
- pc = gnome_print_master_get_context (gpm);
- paper_info = gnome_paper_with_name (paper);
+ paper_info = gnome_paper_with_name (gnome_paper_name_default ());
gnome_print_master_set_paper (gpm, paper_info);
+ if (printer)
+ gnome_print_master_set_printer (gpm, printer);
+
+ gnome_print_master_set_copies (gpm, copies, collate);
+
+ pc = gnome_print_master_get_context (gpm);
+
l = gnome_paper_lmargin (paper_info);
r = gnome_paper_pswidth (paper_info) - gnome_paper_rmargin (paper_info);
t = gnome_paper_psheight (paper_info) - gnome_paper_tmargin (paper_info);
@@ -1175,7 +1177,7 @@ print_calendar (GnomeCalendar *gcal, time_t at, PrintView default_view)
/* depending on the view, do a different output */
switch (default_view) {
- case VIEW_DAY: {
+ case PRINT_VIEW_DAY: {
int i, days = 1;
for (i = 0; i < days; i++) {
@@ -1201,7 +1203,8 @@ print_calendar (GnomeCalendar *gcal, time_t at, PrintView default_view)
}
break;
}
- case VIEW_WEEK:
+
+ case PRINT_VIEW_WEEK:
header = t - 70;
print_week_summary (pc, gcal, at, l, r, header, b);
@@ -1230,7 +1233,7 @@ print_calendar (GnomeCalendar *gcal, time_t at, PrintView default_view)
gnome_print_showpage (pc);
break;
- case VIEW_MONTH:
+ case PRINT_VIEW_MONTH:
header = t - 70;
gnome_print_rotate (pc, 90);
gnome_print_translate (pc, 0, -gnome_paper_pswidth (paper_info));
@@ -1252,7 +1255,7 @@ print_calendar (GnomeCalendar *gcal, time_t at, PrintView default_view)
gnome_print_showpage (pc);
break;
- case VIEW_YEAR:
+ case PRINT_VIEW_YEAR:
#if 0
/* landscape */
gnome_print_rotate(pc, 90);
@@ -1278,61 +1281,14 @@ print_calendar (GnomeCalendar *gcal, time_t at, PrintView default_view)
}
gnome_print_master_close (gpm);
- gnome_print_master_print (gpm);
-}
-
-#if 0
-/*
- Load the printing dialogue box
-*/
-static void
-show_print_dialogue(void)
-{
- GtkWidget *print_dialogue;
- GtkWidget *printer_widget;
- GtkWidget *paper_widget;
- GtkWidget *print_copies;
- GtkWidget *table;
-
- print_dialogue =
- gnome_dialog_new(_("Print Calendar"),
- GNOME_STOCK_BUTTON_OK,
- _("Preview"),
- GNOME_STOCK_BUTTON_CANCEL,
- NULL);
-
- table = gtk_table_new(2, 2, FALSE);
- gtk_container_add(GTK_CONTAINER(GNOME_DIALOG (print_dialogue)->vbox), GTK_WIDGET (table));
- gtk_widget_show(table);
-
- printer_widget = gnome_printer_widget_new ();
- gtk_table_attach((GtkTable *)table, printer_widget, 1, 2, 0, 2, 0, 0, 4, 4);
- gtk_widget_show(printer_widget);
-
-#if 0
- frame = gtk_frame_new("Select Paper");
- paper_widget = gnome_paper_selector_new ();
- gtk_table_attach(table, frame, 0, 1, 0, 1, 0, 0, 4, 4);
- gtk_container_add(frame, GTK_WIDGET (paper_widget));
- gtk_widget_show(paper_widget);
- gtk_widget_show(frame);
-#else
- paper_widget = gnome_paper_selector_new ();
- gtk_table_attach((GtkTable *)table, paper_widget, 0, 1, 0, 1, GTK_SHRINK, GTK_SHRINK, 4, 4);
- gtk_widget_show(paper_widget);
-#endif
- print_copies = gnome_print_copies_new ();
- gtk_table_attach((GtkTable *)table, print_copies, 0, 1, 1, 2, 0, 0, 4, 4);
- gtk_widget_show(print_copies);
+ if (preview) {
+ GnomePrintMasterPreview *gpmp;
-#if 0
- frame = gtk_frame_new("Print Range");
- gtk_table_attach_defaults(table, frame, 0, 1, 1, 2);
- gtk_widget_show(frame);
-#endif
+ gpmp = gnome_print_master_preview_new (gpm, _("Print Preview"));
+ gtk_widget_show (GTK_WIDGET (gpmp));
+ } else
+ gnome_print_master_print (gpm);
- gnome_dialog_run_and_close (GNOME_DIALOG (print_dialogue));
+ gtk_object_unref (GTK_OBJECT (gpm));
}
-
-#endif
diff --git a/calendar/gui/print.h b/calendar/gui/print.h
index bae337225a..e88c4a8e01 100644
--- a/calendar/gui/print.h
+++ b/calendar/gui/print.h
@@ -34,7 +34,7 @@ typedef enum {
PRINT_VIEW_YEAR
} PrintView;
-void print_calendar (GnomeCalendar *gcal, time_t at, printview_t default_view);
+void print_calendar (GnomeCalendar *gcal, gboolean preview, time_t at, PrintView default_view);