aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-11-06 09:06:09 +0800
committerChris Lahey <clahey@src.gnome.org>2000-11-06 09:06:09 +0800
commitac26ccfbdc8390cce592621407a26457c05f90b1 (patch)
tree3b56e03a6e688e43ddbe5c0416daa96520b48e87 /addressbook
parent9ca299b427db9febb37208a33d238463f7a9b3bd (diff)
downloadgsoc2013-evolution-ac26ccfbdc8390cce592621407a26457c05f90b1.tar
gsoc2013-evolution-ac26ccfbdc8390cce592621407a26457c05f90b1.tar.gz
gsoc2013-evolution-ac26ccfbdc8390cce592621407a26457c05f90b1.tar.bz2
gsoc2013-evolution-ac26ccfbdc8390cce592621407a26457c05f90b1.tar.lz
gsoc2013-evolution-ac26ccfbdc8390cce592621407a26457c05f90b1.tar.xz
gsoc2013-evolution-ac26ccfbdc8390cce592621407a26457c05f90b1.tar.zst
gsoc2013-evolution-ac26ccfbdc8390cce592621407a26457c05f90b1.zip
Add menus items to the envelope printing stuff.
2000-11-05 Christopher James Lahey <clahey@helixcode.com> * contact-editor/e-contact-editor.c, gui/widgets/e-addressbook-view.c, gui/widgets/e-minicard.c: Add menus items to the envelope printing stuff. * gui/component/addressbook.c: Hook up the search menu. * gui/widgets/e-addressbook-search.c, gui/widgets/e-addressbook-search.h: Add the search menu. * printing/Makefile.am: Add e-contact-print-envelope.c and e-contact-print-envelope.h. * printing/e-contact-print-envelope.c, printing/e-contact-print-envelope.h: Added envelope printing. svn path=/trunk/; revision=6408
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/ChangeLog17
-rw-r--r--addressbook/contact-editor/e-contact-editor.c16
-rw-r--r--addressbook/gui/component/addressbook.c21
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.c16
-rw-r--r--addressbook/gui/widgets/e-addressbook-search.c92
-rw-r--r--addressbook/gui/widgets/e-addressbook-search.h6
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.c9
-rw-r--r--addressbook/gui/widgets/e-minicard.c13
-rw-r--r--addressbook/printing/Makefile.am8
-rw-r--r--addressbook/printing/e-contact-print-envelope.c212
-rw-r--r--addressbook/printing/e-contact-print-envelope.h32
11 files changed, 432 insertions, 10 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 8603fbf57c..d18c824e5d 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,20 @@
+2000-11-05 Christopher James Lahey <clahey@helixcode.com>
+
+ * contact-editor/e-contact-editor.c,
+ gui/widgets/e-addressbook-view.c, gui/widgets/e-minicard.c: Add
+ menus items to the envelope printing stuff.
+
+ * gui/component/addressbook.c: Hook up the search menu.
+
+ * gui/widgets/e-addressbook-search.c,
+ gui/widgets/e-addressbook-search.h: Add the search menu.
+
+ * printing/Makefile.am: Add e-contact-print-envelope.c and
+ e-contact-print-envelope.h.
+
+ * printing/e-contact-print-envelope.c,
+ printing/e-contact-print-envelope.h: Added envelope printing.
+
2000-11-03 Federico Mena Quintero <federico@helixcode.com>
* gui/component/select-names/Makefile.am: Clean the idl-generated
diff --git a/addressbook/contact-editor/e-contact-editor.c b/addressbook/contact-editor/e-contact-editor.c
index aa2f4cffc2..c4e8ed8640 100644
--- a/addressbook/contact-editor/e-contact-editor.c
+++ b/addressbook/contact-editor/e-contact-editor.c
@@ -33,6 +33,7 @@
#include <gal/widgets/e-unicode.h>
#include <e-contact-save-as.h>
#include "addressbook/printing/e-contact-print.h"
+#include "addressbook/printing/e-contact-print-envelope.h"
/* Signal IDs */
enum {
@@ -713,6 +714,20 @@ print_cb (BonoboUIComponent *uih, void *data, const char *path)
gtk_widget_show(e_contact_print_card_dialog_new(ce->card));
}
+/* Emits the signal to request printing a card */
+static void
+print_envelope_cb (BonoboUIComponent *uih, void *data, const char *path)
+{
+ EContactEditor *ce;
+
+ ce = E_CONTACT_EDITOR (data);
+
+ extract_info (ce);
+ e_card_simple_sync_card (ce->simple);
+
+ gtk_widget_show(e_contact_print_envelope_dialog_new(ce->card));
+}
+
/* Toolbar/Save and Close callback */
static void
tb_save_and_close_cb (BonoboUIComponent *uih, void *data, const char *path)
@@ -731,6 +746,7 @@ BonoboUIVerb verbs [] = {
BONOBO_UI_UNSAFE_VERB ("ContactEditorSaveClose", tb_save_and_close_cb),
BONOBO_UI_UNSAFE_VERB ("ContactEditorDelete", delete_cb),
BONOBO_UI_UNSAFE_VERB ("ContactEditorPrint", print_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactEditorPrintEnvelope", print_envelope_cb),
/* BONOBO_UI_UNSAFE_VERB ("ContactEditorPageSetup", file_page_setup_menu), */
BONOBO_UI_UNSAFE_VERB ("ContactEditorClose", file_close_cb),
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c
index 8a0d03cd05..1645dd849b 100644
--- a/addressbook/gui/component/addressbook.c
+++ b/addressbook/gui/component/addressbook.c
@@ -532,6 +532,25 @@ addressbook_query_changed (EAddressbookSearch *eas, AddressbookView *view)
g_free (search_word);
}
+static void
+addressbook_menu_activated (EAddressbookSearch *eas, int id, AddressbookView *view)
+{
+ EBook *book;
+ switch (id) {
+ case 0:
+ e_addressbook_view_show_all(view->view);
+ break;
+ case 1:
+ gtk_object_get(GTK_OBJECT(view->view),
+ "book", &book,
+ NULL);
+ g_assert (E_IS_BOOK (book));
+
+ gtk_widget_show(e_addressbook_search_dialog_new(book));
+ break;
+ }
+}
+
BonoboControl *
addressbook_factory_new_control (void)
{
@@ -555,6 +574,8 @@ addressbook_factory_new_control (void)
FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (view->search), "query_changed",
GTK_SIGNAL_FUNC (addressbook_query_changed), view);
+ gtk_signal_connect (GTK_OBJECT (view->search), "menu_activated",
+ GTK_SIGNAL_FUNC (addressbook_menu_activated), view);
view->view = E_ADDRESSBOOK_VIEW(e_addressbook_view_new());
gtk_box_pack_start(GTK_BOX(view->vbox), GTK_WIDGET(view->view),
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c
index aa2f4cffc2..c4e8ed8640 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/addressbook/gui/contact-editor/e-contact-editor.c
@@ -33,6 +33,7 @@
#include <gal/widgets/e-unicode.h>
#include <e-contact-save-as.h>
#include "addressbook/printing/e-contact-print.h"
+#include "addressbook/printing/e-contact-print-envelope.h"
/* Signal IDs */
enum {
@@ -713,6 +714,20 @@ print_cb (BonoboUIComponent *uih, void *data, const char *path)
gtk_widget_show(e_contact_print_card_dialog_new(ce->card));
}
+/* Emits the signal to request printing a card */
+static void
+print_envelope_cb (BonoboUIComponent *uih, void *data, const char *path)
+{
+ EContactEditor *ce;
+
+ ce = E_CONTACT_EDITOR (data);
+
+ extract_info (ce);
+ e_card_simple_sync_card (ce->simple);
+
+ gtk_widget_show(e_contact_print_envelope_dialog_new(ce->card));
+}
+
/* Toolbar/Save and Close callback */
static void
tb_save_and_close_cb (BonoboUIComponent *uih, void *data, const char *path)
@@ -731,6 +746,7 @@ BonoboUIVerb verbs [] = {
BONOBO_UI_UNSAFE_VERB ("ContactEditorSaveClose", tb_save_and_close_cb),
BONOBO_UI_UNSAFE_VERB ("ContactEditorDelete", delete_cb),
BONOBO_UI_UNSAFE_VERB ("ContactEditorPrint", print_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactEditorPrintEnvelope", print_envelope_cb),
/* BONOBO_UI_UNSAFE_VERB ("ContactEditorPageSetup", file_page_setup_menu), */
BONOBO_UI_UNSAFE_VERB ("ContactEditorClose", file_close_cb),
diff --git a/addressbook/gui/widgets/e-addressbook-search.c b/addressbook/gui/widgets/e-addressbook-search.c
index c03b8fc096..e58e72d560 100644
--- a/addressbook/gui/widgets/e-addressbook-search.c
+++ b/addressbook/gui/widgets/e-addressbook-search.c
@@ -34,6 +34,7 @@ static void e_addressbook_search_destroy (GtkObject *object);
enum {
QUERY_CHANGED,
+ MENU_ACTIVATED,
LAST_SIGNAL
};
@@ -99,6 +100,14 @@ e_addressbook_search_class_init (EAddressbookSearchClass *klass)
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
+ eas_signals [MENU_ACTIVATED] =
+ gtk_signal_new ("menu_activated",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (EAddressbookSearchClass, menu_activated),
+ gtk_marshal_NONE__INT,
+ GTK_TYPE_NONE, 1, GTK_TYPE_INT);
+
gtk_object_class_add_signals (object_class, eas_signals, LAST_SIGNAL);
}
@@ -109,6 +118,70 @@ eas_query_changed(EAddressbookSearch *eas)
eas_signals [QUERY_CHANGED]);
}
+static void
+eas_menu_activated(EAddressbookSearch *eas, int item)
+{
+ gtk_signal_emit(GTK_OBJECT (eas),
+ eas_signals [MENU_ACTIVATED],
+ item);
+}
+
+static void
+eas_menubar_activated(GtkWidget *widget, EAddressbookSearch *eas)
+{
+ int id = GPOINTER_TO_INT(gtk_object_get_data (GTK_OBJECT (widget), "EasMenuId"));
+
+ eas_menu_activated(eas, id);
+}
+
+typedef enum {
+ EAS_CLEAR = 0,
+} EasMenuId;
+
+
+typedef struct {
+ char *text;
+ char *name;
+ int id;
+} EasMenuItem;
+
+static EasMenuItem eas_menu_items[] = {
+ { N_("Show All"), "all", 0 },
+ { NULL, "sep", -1 },
+ { N_("Advanced"), "advanced", 1},
+ { NULL, NULL, 0 }
+};
+
+static void
+eas_pack_menubar(EAddressbookSearch *eas)
+{
+ GtkWidget *menu, *menuitem;
+ int i;
+
+ menu = gtk_menu_new ();
+ for (i = 0; eas_menu_items[i].name; i++) {
+ GtkWidget *item;
+
+ item = gtk_menu_item_new_with_label (_(eas_menu_items[i].text));
+
+ gtk_menu_append (GTK_MENU (menu), item);
+
+ gtk_object_set_data (GTK_OBJECT (item), "EasMenuId", GINT_TO_POINTER(eas_menu_items[i].id));
+
+ gtk_signal_connect (GTK_OBJECT (item), "activate",
+ GTK_SIGNAL_FUNC (eas_menubar_activated),
+ eas);
+ }
+ gtk_widget_show_all (menu);
+
+ menuitem = gtk_menu_item_new_with_label(_("Search"));
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
+
+ gtk_widget_show (menuitem);
+
+ gtk_menu_bar_append (GTK_MENU_BAR(eas->menubar), menuitem);
+ gtk_widget_set_sensitive (eas->menubar, TRUE);
+}
typedef enum {
EAS_ANY = 0,
@@ -148,19 +221,18 @@ eas_entry_activated(GtkWidget *widget, EAddressbookSearch *eas)
static void
eas_pack_option_menu(EAddressbookSearch *eas)
{
- GtkWidget *menu, *item, *firstitem = NULL;
+ GtkWidget *menu;
int i;
menu = gtk_menu_new ();
for (i = 0; eas_choices[i].name; i++) {
+ GtkWidget *item;
item = gtk_menu_item_new_with_label (_(eas_choices[i].text));
- if (!firstitem)
- firstitem = item;
gtk_menu_append (GTK_MENU (menu), item);
- gtk_object_set_data (GTK_OBJECT (item), "EasChoiceId", GINT_TO_POINTER(i));
+ gtk_object_set_data (GTK_OBJECT (item), "EasChoiceId", GINT_TO_POINTER(eas_choices[i].id));
gtk_signal_connect (GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (eas_option_activated),
@@ -177,8 +249,15 @@ eas_pack_option_menu(EAddressbookSearch *eas)
static void
e_addressbook_search_init (EAddressbookSearch *eas)
{
+ GtkWidget *spacer;
+
gtk_box_set_spacing(GTK_BOX(eas), GNOME_PAD);
+ eas->menubar = gtk_menu_bar_new();
+ eas_pack_menubar(eas);
+ gtk_widget_show(eas->menubar);
+ gtk_box_pack_start(GTK_BOX(eas), eas->menubar, FALSE, FALSE, 0);
+
eas->option = gtk_option_menu_new();
eas_pack_option_menu(eas);
gtk_widget_show(eas->option);
@@ -190,6 +269,11 @@ e_addressbook_search_init (EAddressbookSearch *eas)
gtk_widget_show(eas->entry);
gtk_box_pack_start(GTK_BOX(eas), eas->entry, TRUE, TRUE, 0);
eas->option_choice = 0;
+
+ spacer = gtk_drawing_area_new();
+ gtk_widget_show(spacer);
+ gtk_box_pack_start(GTK_BOX(eas), spacer, FALSE, FALSE, 0);
+ gtk_widget_set_usize(spacer, 100, 1);
}
static void
diff --git a/addressbook/gui/widgets/e-addressbook-search.h b/addressbook/gui/widgets/e-addressbook-search.h
index 5216aa7ee5..5b229ee03e 100644
--- a/addressbook/gui/widgets/e-addressbook-search.h
+++ b/addressbook/gui/widgets/e-addressbook-search.h
@@ -58,8 +58,9 @@ struct _EAddressbookSearch
GtkHBox parent;
/* item specific fields */
- GtkWidget *entry;
+ GtkWidget *menubar;
GtkWidget *option;
+ GtkWidget *entry;
int option_choice;
};
@@ -67,7 +68,8 @@ struct _EAddressbookSearchClass
{
GtkHBoxClass parent_class;
- void (*query_changed) (EAddressbookSearch *search);
+ void (*query_changed) (EAddressbookSearch *search);
+ void (*menu_activated) (EAddressbookSearch *search, int item);
};
GtkWidget *e_addressbook_search_new (void);
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c
index 186cd7ce31..3d081ab14c 100644
--- a/addressbook/gui/widgets/e-addressbook-view.c
+++ b/addressbook/gui/widgets/e-addressbook-view.c
@@ -37,6 +37,7 @@
#include "e-contact-editor.h"
#include "e-contact-save-as.h"
#include "addressbook/printing/e-contact-print.h"
+#include "addressbook/printing/e-contact-print-envelope.h"
#include "e-card-simple.h"
#include "e-card.h"
#include "e-book.h"
@@ -423,6 +424,13 @@ print (GtkWidget *widget, CardAndBook *card_and_book)
}
static void
+print_envelope (GtkWidget *widget, CardAndBook *card_and_book)
+{
+ gtk_widget_show(e_contact_print_envelope_dialog_new(card_and_book->card));
+ card_and_book_free(card_and_book);
+}
+
+static void
delete (GtkWidget *widget, CardAndBook *card_and_book)
{
if (e_contact_editor_confirm_delete(GTK_WINDOW(gtk_widget_get_toplevel(card_and_book->widget)))) {
@@ -445,6 +453,7 @@ table_right_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, EA
EPopupMenu menu[] = {
{"Save as VCard", NULL, GTK_SIGNAL_FUNC(save_as), 0},
{"Print", NULL, GTK_SIGNAL_FUNC(print), 0},
+ {"Print Envelope", NULL, GTK_SIGNAL_FUNC(print_envelope), 0},
{"Delete", NULL, GTK_SIGNAL_FUNC(delete), 0},
{NULL, NULL, NULL, 0}
};
diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c
index c57e7adde7..4dda2cee1d 100644
--- a/addressbook/gui/widgets/e-minicard.c
+++ b/addressbook/gui/widgets/e-minicard.c
@@ -31,6 +31,7 @@
#include <gal/widgets/e-canvas.h>
#include <gal/widgets/e-popup-menu.h>
#include "addressbook/printing/e-contact-print.h"
+#include "addressbook/printing/e-contact-print-envelope.h"
#include "e-contact-editor.h"
#include "e-contact-save-as.h"
#include "e-minicard-view.h"
@@ -361,10 +362,18 @@ static void
print (GtkWidget *widget, EMinicard *minicard)
{
e_card_simple_sync_card(minicard->simple);
-
+
gtk_widget_show(e_contact_print_card_dialog_new(minicard->card));
}
+static void
+print_envelope (GtkWidget *widget, EMinicard *minicard)
+{
+ e_card_simple_sync_card(minicard->simple);
+
+ gtk_widget_show(e_contact_print_envelope_dialog_new(minicard->card));
+}
+
/* Callback for the add_card signal from the contact editor */
static void
add_card_cb (EContactEditor *ce, ECard *card, gpointer data)
@@ -477,11 +486,13 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event)
if (E_IS_MINICARD_VIEW(item->parent)) {
EPopupMenu menu[] = { {"Save as VCard", NULL, GTK_SIGNAL_FUNC(save_as), 0},
{"Print", NULL, GTK_SIGNAL_FUNC(print), 0},
+ {"Print Envelope", NULL, GTK_SIGNAL_FUNC(print_envelope), 0},
{"Delete", NULL, GTK_SIGNAL_FUNC(delete), 0},
{NULL, NULL, NULL, 0}};
e_popup_menu_run (menu, (GdkEventButton *)event, 0, 0, e_minicard);
} else {
EPopupMenu menu[] = { {"Save as VCard", NULL, GTK_SIGNAL_FUNC(save_as), 0},
+ {"Print Envelope", NULL, GTK_SIGNAL_FUNC(print_envelope), 0},
{"Print", NULL, GTK_SIGNAL_FUNC(print), 0},
{NULL, NULL, NULL, 0}};
e_popup_menu_run (menu, (GdkEventButton *)event, 0, 0, e_minicard);
diff --git a/addressbook/printing/Makefile.am b/addressbook/printing/Makefile.am
index c020aac676..a28f8bf7c1 100644
--- a/addressbook/printing/Makefile.am
+++ b/addressbook/printing/Makefile.am
@@ -26,11 +26,13 @@ noinst_LIBRARIES = \
libecontactprint.a
libecontactprint_a_SOURCES = \
- e-contact-print.c \
- e-contact-print.h \
+ e-contact-print-envelope.c \
+ e-contact-print-envelope.h \
e-contact-print-style-editor.c \
e-contact-print-style-editor.h \
- e-contact-print-types.h
+ e-contact-print-types.h \
+ e-contact-print.c \
+ e-contact-print.h
noinst_PROGRAMS = \
contact-print-test \
diff --git a/addressbook/printing/e-contact-print-envelope.c b/addressbook/printing/e-contact-print-envelope.c
new file mode 100644
index 0000000000..c702728e4e
--- /dev/null
+++ b/addressbook/printing/e-contact-print-envelope.c
@@ -0,0 +1,212 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * e-contact-print-envelope.c
+ * Copyright (C) 2000 Helix Code, Inc.
+ * Author: Chris Lahey <clahey@helixcode.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#include "e-contact-print-envelope.h"
+#include <libgnomeprint/gnome-print.h>
+#include <libgnomeprint/gnome-print-dialog.h>
+#include <libgnomeprint/gnome-print-master.h>
+#include <libgnomeprint/gnome-print-master-preview.h>
+#include <addressbook/backend/ebook/e-card.h>
+#include <addressbook/backend/ebook/e-card-simple.h>
+
+
+#define ENVELOPE_HEIGHT (72.0 * 4.0)
+#define ENVELOPE_WIDTH (72.0 * 10.0)
+
+typedef struct {
+ int start;
+ int length;
+} EcpeLine;
+
+static void
+startset(void *pointer, EcpeLine **iterator)
+{
+ (*iterator)--;
+ (*iterator)->start = GPOINTER_TO_INT(pointer);
+}
+
+static void
+lengthset(void *pointer, EcpeLine **iterator)
+{
+ (*iterator)--;
+ (*iterator)->length = GPOINTER_TO_INT(pointer);
+}
+
+static EcpeLine *
+ecpe_break(char *address)
+{
+ int i;
+ int length = 0;
+ int laststart = 0;
+ GList *startlist = NULL;
+ GList *lengthlist = NULL;
+ EcpeLine *ret_val;
+ EcpeLine *iterator;
+
+ for (i = 0; address[i]; i++) {
+ if (address[i] == '\n') {
+ startlist = g_list_prepend (startlist, GINT_TO_POINTER(laststart));
+ lengthlist = g_list_prepend (lengthlist, GINT_TO_POINTER(i - laststart));
+ length ++;
+ laststart = i + 1;
+ }
+ }
+ startlist = g_list_prepend (startlist, GINT_TO_POINTER(laststart));
+ lengthlist = g_list_prepend (lengthlist, GINT_TO_POINTER(i - laststart));
+ length ++;
+
+ ret_val = g_new(EcpeLine, length + 1);
+
+ iterator = ret_val + length;
+ g_list_foreach(startlist, (GFunc) startset, &iterator);
+ g_list_free(startlist);
+
+ iterator = ret_val + length;
+ g_list_foreach(lengthlist, (GFunc) lengthset, &iterator);
+ g_list_free(lengthlist);
+
+ ret_val[length].start = -1;
+ ret_val[length].length = -1;
+
+ return ret_val;
+}
+
+static void
+ecpe_linelist_dimensions(GnomeFont *font, char *address, EcpeLine *linelist, double *widthp, double *heightp)
+{
+ double width = 0;
+ int i;
+ if (widthp) {
+ for (i = 0; linelist[i].length != -1; i++) {
+ width = MAX(width, gnome_font_get_width_string_n (font, address + linelist[i].start, linelist[i].length));
+ }
+ *widthp = width;
+ } else {
+ for (i = 0; linelist[i].length != -1; i++)
+ /* Intentionally empty */;
+ }
+ if (heightp) {
+ *heightp = gnome_font_get_size(font) * i;
+ }
+}
+
+static void
+ecpe_linelist_print(GnomePrintContext *pc, GnomeFont *font, char *address, EcpeLine *linelist, double x, double y)
+{
+ int i;
+ for (i = 0; linelist[i].length != -1; i++) {
+ gnome_print_moveto(pc, x, y + gnome_font_get_ascender(font));
+ gnome_print_show_sized (pc, address + linelist[i].start, linelist[i].length);
+ y -= gnome_font_get_size(font);
+ }
+}
+
+static gint
+e_contact_print_envelope_close(GnomeDialog *dialog, gpointer data)
+{
+ return FALSE;
+}
+
+static void
+ecpe_print(GnomePrintContext *pc, ECard *ecard)
+{
+ ECardSimple *card = e_card_simple_new(ecard);
+ char *address;
+ EcpeLine *linelist;
+ double x;
+ double y;
+ GnomeFont *font;
+
+
+ gnome_print_rotate(pc, 90);
+ gnome_print_translate(pc, 72.0 * 11.0 - ENVELOPE_WIDTH, -72.0 * 8.5 + (72.0 * 8.5 - ENVELOPE_HEIGHT) / 2);
+
+ address = e_card_simple_get(card, E_CARD_SIMPLE_FIELD_ADDRESS_BUSINESS);
+ linelist = ecpe_break(address);
+ font = gnome_font_new("Helvetica", 12);
+ ecpe_linelist_dimensions(font, address, linelist, &x, &y);
+ x = (ENVELOPE_WIDTH - x) / 2;
+ y = (ENVELOPE_HEIGHT - y) / 2;
+ ecpe_linelist_print(pc, font, address, linelist, x, y);
+ gtk_object_unref(GTK_OBJECT(font));
+ g_free(linelist);
+
+ g_free(address);
+
+ gnome_print_showpage(pc);
+ gnome_print_context_close(pc);
+
+ gtk_object_unref(GTK_OBJECT(card));
+}
+
+static void
+e_contact_print_envelope_button(GnomeDialog *dialog, gint button, gpointer data)
+{
+ GnomePrintMaster *master;
+ GnomePrintContext *pc;
+ ECard *card = NULL;
+ GtkWidget *preview;
+
+ card = gtk_object_get_data(GTK_OBJECT(dialog), "card");
+
+ switch( button ) {
+ case GNOME_PRINT_PRINT:
+ master = gnome_print_master_new_from_dialog( GNOME_PRINT_DIALOG(dialog) );
+ pc = gnome_print_master_get_context( master );
+
+ ecpe_print(pc, card);
+
+ gnome_print_master_print(master);
+ gnome_dialog_close(dialog);
+ break;
+ case GNOME_PRINT_PREVIEW:
+ master = gnome_print_master_new_from_dialog( GNOME_PRINT_DIALOG(dialog) );
+ pc = gnome_print_master_get_context( master );
+
+ ecpe_print(pc, card);
+
+ preview = GTK_WIDGET(gnome_print_master_preview_new(master, "Print Preview"));
+ gtk_widget_show_all(preview);
+ break;
+ case GNOME_PRINT_CANCEL:
+ gtk_object_unref(GTK_OBJECT(card));
+ gnome_dialog_close(dialog);
+ break;
+ }
+}
+
+GtkWidget *
+e_contact_print_envelope_dialog_new(ECard *card)
+{
+ GtkWidget *dialog;
+
+ dialog = gnome_print_dialog_new("Print envelope", GNOME_PRINT_DIALOG_COPIES);
+
+ card = e_card_duplicate(card);
+ gtk_object_set_data(GTK_OBJECT(dialog), "card", card);
+ gtk_signal_connect(GTK_OBJECT(dialog),
+ "clicked", GTK_SIGNAL_FUNC(e_contact_print_envelope_button), NULL);
+ gtk_signal_connect(GTK_OBJECT(dialog),
+ "close", GTK_SIGNAL_FUNC(e_contact_print_envelope_close), NULL);
+ return dialog;
+}
diff --git a/addressbook/printing/e-contact-print-envelope.h b/addressbook/printing/e-contact-print-envelope.h
new file mode 100644
index 0000000000..45aa051401
--- /dev/null
+++ b/addressbook/printing/e-contact-print-envelope.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * e-contact-print-envelope.h
+ * Copyright (C) 2000 Helix Code, Inc.
+ * Author: Chris Lahey <clahey@helixcode.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef E_CONTACT_PRINT_ENVELOPE_H
+#define E_CONTACT_PRINT_ENVELOPE_H
+
+#include <gnome.h>
+#include <addressbook/backend/ebook/e-card.h>
+#include "e-contact-print-types.h"
+
+GtkWidget *e_contact_print_envelope_dialog_new(ECard *card);
+
+#endif /* E_CONTACT_PRINT_ENVELOPE_H */