diff options
Diffstat (limited to 'addressbook/gui')
-rw-r--r-- | addressbook/gui/component/addressbook.c | 118 | ||||
-rw-r--r-- | addressbook/gui/minicard/Makefile.am | 2 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard-view-widget.c | 267 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard-view-widget.h | 73 | ||||
-rw-r--r-- | addressbook/gui/search/e-addressbook-search-dialog.c | 46 | ||||
-rw-r--r-- | addressbook/gui/widgets/Makefile.am | 2 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view-widget.c | 267 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view-widget.h | 73 |
8 files changed, 753 insertions, 95 deletions
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index 2e484ee1ff..5834d2f857 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -17,10 +17,9 @@ #include "addressbook.h" #include <ebook/e-book.h> -#include <e-util/e-canvas.h> #include <e-util/e-util.h> #include <e-util/e-popup-menu.h> -#include "e-minicard-view.h" +#include "e-minicard-view-widget.h" #include <e-table.h> #include <e-cell-text.h> @@ -61,9 +60,7 @@ typedef struct { EBook *book; GtkWidget *vbox; GtkWidget *minicard_hbox; - GtkWidget *canvas; - GnomeCanvasItem *view; - GnomeCanvasItem *rect; + GtkWidget *minicard_view; GtkWidget *table; ETableModel *model; ECardSimple *simple; @@ -154,8 +151,8 @@ new_contact_cb (BonoboUIHandler *uih, void *user_data, const char *path) card = e_card_new(""); - if (view->view) - object = GTK_OBJECT(view->view); + if (view->minicard_view) + object = GTK_OBJECT(view->minicard_view); else object = GTK_OBJECT(view->model); @@ -210,8 +207,8 @@ new_server_cb (BonoboUIHandler *uih, void *user_data, const char *path) server->uri = g_strdup_printf ("ldap://%s:%s/%s", server->host, server->port, server->rootdn); e_ldap_server_editor_show (server); - if (view->view) - object = GTK_OBJECT(view->view); + if (view->minicard_view) + object = GTK_OBJECT(view->minicard_view); else object = GTK_OBJECT(view->model); gtk_object_get(object, "book", &book, NULL); @@ -234,8 +231,8 @@ get_query (AddressbookView *view) GtkObject *object; char *query = NULL; - if (view->view) - object = GTK_OBJECT(view->view); + if (view->minicard_view) + object = GTK_OBJECT(view->minicard_view); else object = GTK_OBJECT(view->model); @@ -250,8 +247,8 @@ set_query (AddressbookView *view, char *query) { GtkObject *object; - if (view->view) - object = GTK_OBJECT(view->view); + if (view->minicard_view) + object = GTK_OBJECT(view->minicard_view); else object = GTK_OBJECT(view->model); @@ -264,7 +261,7 @@ static void set_book(AddressbookView *view) { if (view->book) - gtk_object_set(view->view ? GTK_OBJECT(view->view) : GTK_OBJECT(view->model), + gtk_object_set(view->minicard_view ? GTK_OBJECT(view->minicard_view) : GTK_OBJECT(view->model), "book", view->book, NULL); } @@ -310,8 +307,8 @@ static void delete_contact_cb (BonoboUIHandler *uih, void *user_data, const char *path) { AddressbookView *view = (AddressbookView *) user_data; - if (view->view) - e_minicard_view_remove_selection (E_MINICARD_VIEW(view->view), card_deleted_cb, NULL); + if (view->minicard_view) + e_minicard_view_widget_remove_selection (E_MINICARD_VIEW_WIDGET(view->minicard_view), card_deleted_cb, NULL); } static void @@ -389,7 +386,7 @@ static void print_cb (BonoboUIHandler *uih, void *user_data, const char *path) { AddressbookView *view = (AddressbookView *) user_data; - if (view->view) { + if (view->minicard_view) { char *query = get_query(view); GtkWidget *print = e_contact_print_dialog_new(view->book, query); g_free(query); @@ -638,43 +635,6 @@ static void destroy_callback(GtkWidget *widget, gpointer data) addressbook_view_free(view); } -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) -{ - double width; - AddressbookView *view = data; - view->last_alloc = *allocation; - gnome_canvas_item_set( view->view, - "height", (double) allocation->height, - NULL ); - gnome_canvas_item_set( view->view, - "minimum_width", (double) allocation->width, - NULL ); - gtk_object_get(GTK_OBJECT(view->view), - "width", &width, - NULL); - width = MAX(width, allocation->width); - gnome_canvas_set_scroll_region(GNOME_CANVAS( view->canvas ), 0, 0, width - 1, allocation->height - 1); - gnome_canvas_item_set( view->rect, - "x2", (double) width, - "y2", (double) allocation->height, - NULL ); -} - -static void resize(GnomeCanvas *canvas, gpointer data) -{ - double width; - AddressbookView *view = data; - gtk_object_get(GTK_OBJECT(view->view), - "width", &width, - NULL); - width = MAX(width, view->last_alloc.width); - gnome_canvas_set_scroll_region(GNOME_CANVAS(view->canvas), 0, 0, width - 1, view->last_alloc.height - 1); - gnome_canvas_item_set( view->rect, - "x2", (double) width, - "y2", (double) view->last_alloc.height, - NULL ); -} - static void get_prop (BonoboPropertyBag *bag, BonoboArg *arg, @@ -757,16 +717,13 @@ set_prop (BonoboPropertyBag *bag, static void teardown_minicard_view (AddressbookView *view) { - if (view->view) { - gtk_object_destroy(GTK_OBJECT(view->view)); - view->view = NULL; + if (view->minicard_view) { + view->minicard_view = NULL; } if (view->minicard_hbox) { gtk_widget_destroy(view->minicard_hbox); view->minicard_hbox = NULL; } - - view->canvas = NULL; } typedef struct { @@ -777,8 +734,8 @@ typedef struct { static void jump_to_letter(GtkWidget *button, LetterClosure *closure) { - if (closure->view->view) - e_minicard_view_jump_to_letter(E_MINICARD_VIEW(closure->view->view), closure->letter); + if (closure->view->minicard_view) + e_minicard_view_widget_jump_to_letter(E_MINICARD_VIEW_WIDGET(closure->view->minicard_view), closure->letter); } static void @@ -839,39 +796,15 @@ create_minicard_view (AddressbookView *view, char *initial_query) view->minicard_hbox = gtk_hbox_new(FALSE, 0); - view->canvas = e_canvas_new(); - view->rect = gnome_canvas_item_new( - gnome_canvas_root( GNOME_CANVAS( view->canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - - view->view = gnome_canvas_item_new( - gnome_canvas_root( GNOME_CANVAS( view->canvas ) ), - e_minicard_view_get_type(), - "height", (double) 100, - "minimum_width", (double) 100, - NULL ); - - gtk_signal_connect( GTK_OBJECT( view->canvas ), "reflow", - GTK_SIGNAL_FUNC( resize ), - view); - - gnome_canvas_set_scroll_region ( GNOME_CANVAS( view->canvas ), - 0, 0, - 100, 100 ); + view->minicard_view = e_minicard_view_widget_new(); scrollframe = e_scroll_frame_new (NULL, NULL); e_scroll_frame_set_policy (E_SCROLL_FRAME (scrollframe), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); - - gtk_container_add (GTK_CONTAINER (scrollframe), view->canvas); - + + gtk_container_add (GTK_CONTAINER (scrollframe), view->minicard_view); + gtk_box_pack_start(GTK_BOX(view->minicard_hbox), scrollframe, TRUE, TRUE, 0); alphabet = create_alphabet(view); @@ -886,11 +819,6 @@ create_minicard_view (AddressbookView *view, char *initial_query) gtk_widget_show_all( GTK_WIDGET(view->minicard_hbox) ); - /* Connect the signals */ - gtk_signal_connect( GTK_OBJECT( view->canvas ), "size_allocate", - GTK_SIGNAL_FUNC( allocate_callback ), - ( gpointer ) view ); - #if 0 gdk_window_set_back_pixmap( GTK_LAYOUT(view->canvas)->bin_window, NULL, FALSE); @@ -1085,7 +1013,7 @@ addressbook_factory_new_control (void) view->control = bonobo_control_new(view->vbox); view->model = NULL; - view->view = NULL; + view->minicard_view = NULL; /* create the initial view */ change_view_type (view, ADDRESSBOOK_VIEW_MINICARD); diff --git a/addressbook/gui/minicard/Makefile.am b/addressbook/gui/minicard/Makefile.am index b337754531..edd000539b 100644 --- a/addressbook/gui/minicard/Makefile.am +++ b/addressbook/gui/minicard/Makefile.am @@ -16,6 +16,8 @@ libeminicard_a_SOURCES = \ e-minicard-control.h \ e-minicard-label.c \ e-minicard-label.h \ + e-minicard-view-widget.c \ + e-minicard-view-widget.h \ e-minicard-view.c \ e-minicard-view.h \ e-minicard-widget.c \ diff --git a/addressbook/gui/minicard/e-minicard-view-widget.c b/addressbook/gui/minicard/e-minicard-view-widget.c new file mode 100644 index 0000000000..cd1a999f14 --- /dev/null +++ b/addressbook/gui/minicard/e-minicard-view-widget.c @@ -0,0 +1,267 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-minicard-view-widget.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 <config.h> +#include <gnome.h> +#include <e-util/e-canvas.h> +#include "e-minicard-view-widget.h" +static void e_minicard_view_widget_init (EMinicardViewWidget *widget); +static void e_minicard_view_widget_class_init (EMinicardViewWidgetClass *klass); +static void e_minicard_view_widget_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_minicard_view_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static void e_minicard_view_widget_destroy (GtkObject *object); +static void e_minicard_view_widget_reflow (ECanvas *canvas); +static void e_minicard_view_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation); +static void e_minicard_view_widget_realize (GtkWidget *widget); + +static ECanvasClass *parent_class = NULL; + +/* The arguments we take */ +enum { + ARG_0, + ARG_BOOK, + ARG_QUERY +}; + +GtkType +e_minicard_view_widget_get_type (void) +{ + static GtkType type = 0; + + if (!type) + { + static const GtkTypeInfo info = + { + "EMinicardViewWidget", + sizeof (EMinicardViewWidget), + sizeof (EMinicardViewWidgetClass), + (GtkClassInitFunc) e_minicard_view_widget_class_init, + (GtkObjectInitFunc) e_minicard_view_widget_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + type = gtk_type_unique (e_canvas_get_type (), &info); + } + + return type; +} + +static void +e_minicard_view_widget_class_init (EMinicardViewWidgetClass *klass) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + ECanvasClass *canvas_class; + + object_class = (GtkObjectClass*) klass; + widget_class = GTK_WIDGET_CLASS (klass); + canvas_class = E_CANVAS_CLASS (klass); + + parent_class = gtk_type_class (e_canvas_get_type ()); + + gtk_object_add_arg_type ("EMinicardViewWidget::book", GTK_TYPE_OBJECT, + GTK_ARG_READWRITE, ARG_BOOK); + gtk_object_add_arg_type ("EMinicardViewWidget::query", GTK_TYPE_STRING, + GTK_ARG_READWRITE, ARG_QUERY); + + object_class->set_arg = e_minicard_view_widget_set_arg; + object_class->get_arg = e_minicard_view_widget_get_arg; + object_class->destroy = e_minicard_view_widget_destroy; + + widget_class->realize = e_minicard_view_widget_realize; + widget_class->size_allocate = e_minicard_view_widget_size_allocate; + + canvas_class->reflow = e_minicard_view_widget_reflow; +} + +static void +e_minicard_view_widget_init (EMinicardViewWidget *view) +{ + view->emv = NULL; + view->rect = NULL; + + view->book = NULL; + view->query = NULL; +} + +GtkWidget * +e_minicard_view_widget_new (void) +{ + return GTK_WIDGET (gtk_type_new (e_minicard_view_widget_get_type ())); +} + +static void +e_minicard_view_widget_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + EMinicardViewWidget *emvw; + + emvw = E_MINICARD_VIEW_WIDGET (o); + + switch (arg_id){ + case ARG_BOOK: + if (emvw->book) + gtk_object_unref(GTK_OBJECT(emvw->book)); + emvw->book = E_BOOK(GTK_VALUE_OBJECT (*arg)); + if (emvw->book) + gtk_object_ref(GTK_OBJECT(emvw->book)); + if (emvw->emv) + gtk_object_set(GTK_OBJECT(emvw->emv), + "book", emvw->book, + NULL); + break; + case ARG_QUERY: + emvw->query = g_strdup(GTK_VALUE_STRING (*arg)); + if (emvw->emv) + gtk_object_set(GTK_OBJECT(emvw->emv), + "query", emvw->query, + NULL); + break; + } +} + +static void +e_minicard_view_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + EMinicardViewWidget *emvw; + + emvw = E_MINICARD_VIEW_WIDGET (object); + + switch (arg_id) { + case ARG_BOOK: + GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(emvw->book); + break; + case ARG_QUERY: + GTK_VALUE_STRING (*arg) = g_strdup(emvw->query); + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +static void +e_minicard_view_widget_destroy (GtkObject *object) +{ + EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(object); + + if (view->book) + gtk_object_unref(GTK_OBJECT(view->book)); + g_free(view->query); + + GTK_OBJECT_CLASS(parent_class)->destroy (object); +} + +static void +e_minicard_view_widget_realize (GtkWidget *widget) +{ + EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(widget); + + view->rect = gnome_canvas_item_new( + gnome_canvas_root( GNOME_CANVAS(view) ), + gnome_canvas_rect_get_type(), + "x1", (double) 0, + "y1", (double) 0, + "x2", (double) 100, + "y2", (double) 100, + "fill_color", "white", + NULL ); + + view->emv = gnome_canvas_item_new( + gnome_canvas_root( GNOME_CANVAS(view) ), + e_minicard_view_get_type(), + "height", (double) 100, + "minimum_width", (double) 100, + NULL ); + gtk_object_set(GTK_OBJECT(view->emv), + "book", view->book, + "query", view->query, + NULL); + + if (GTK_WIDGET_CLASS(parent_class)->realize) + GTK_WIDGET_CLASS(parent_class)->realize (widget); +} + +static void +e_minicard_view_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) +{ + if (GTK_WIDGET_CLASS(parent_class)->size_allocate) + GTK_WIDGET_CLASS(parent_class)->size_allocate (widget, allocation); + + if (GTK_WIDGET_REALIZED(widget)) { + double width; + EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(widget); + + gnome_canvas_item_set( view->emv, + "height", (double) allocation->height, + NULL ); + gnome_canvas_item_set( view->emv, + "minimum_width", (double) allocation->width, + NULL ); + gtk_object_get(GTK_OBJECT(view->emv), + "width", &width, + NULL); + width = MAX(width, allocation->width); + gnome_canvas_set_scroll_region (GNOME_CANVAS (view), 0, 0, width - 1, allocation->height - 1); + gnome_canvas_item_set( view->rect, + "x2", (double) width, + "y2", (double) allocation->height, + NULL ); + } +} + +static void +e_minicard_view_widget_reflow(ECanvas *canvas) +{ + double width; + EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(canvas); + + if (E_CANVAS_CLASS(parent_class)->reflow) + E_CANVAS_CLASS(parent_class)->reflow (canvas); + + gtk_object_get(GTK_OBJECT(view->emv), + "width", &width, + NULL); + width = MAX(width, GTK_WIDGET(canvas)->allocation.width); + gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0, width - 1, GTK_WIDGET(canvas)->allocation.width - 1); + gnome_canvas_item_set( view->rect, + "x2", (double) width, + "y2", (double) GTK_WIDGET(canvas)->allocation.height, + NULL ); +} + +void +e_minicard_view_widget_remove_selection(EMinicardViewWidget *view, + EBookCallback cb, + gpointer closure) +{ + if (view->emv) + e_minicard_view_remove_selection(E_MINICARD_VIEW(view->emv), cb, closure); +} + +void e_minicard_view_widget_jump_to_letter (EMinicardViewWidget *view, + char letter) +{ + if (view->emv) + e_minicard_view_jump_to_letter(E_MINICARD_VIEW(view->emv), letter); +} diff --git a/addressbook/gui/minicard/e-minicard-view-widget.h b/addressbook/gui/minicard/e-minicard-view-widget.h new file mode 100644 index 0000000000..340fb1e03c --- /dev/null +++ b/addressbook/gui/minicard/e-minicard-view-widget.h @@ -0,0 +1,73 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-minicard-view-widget.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_MINICARD_VIEW_WIDGET_H__ +#define __E_MINICARD_VIEW_WIDGET_H__ + +#include <gnome.h> +#include "e-minicard-view.h" +#include "e-util/e-canvas.h" +#include <ebook/e-book.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_MINICARD_VIEW_WIDGET_TYPE (e_minicard_view_widget_get_type ()) +#define E_MINICARD_VIEW_WIDGET(obj) (GTK_CHECK_CAST ((obj), E_MINICARD_VIEW_WIDGET_TYPE, EMinicardViewWidget)) +#define E_MINICARD_VIEW_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_MINICARD_VIEW_WIDGET_TYPE, EMinicardViewWidgetClass)) +#define E_IS_MINICARD_VIEW_WIDGET(obj) (GTK_CHECK_TYPE ((obj), E_MINICARD_VIEW_WIDGET_TYPE)) +#define E_IS_MINICARD_VIEW_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_MINICARD_VIEW_WIDGET_TYPE)) + + +typedef struct _EMinicardViewWidget EMinicardViewWidget; +typedef struct _EMinicardViewWidgetClass EMinicardViewWidgetClass; + +struct _EMinicardViewWidget +{ + ECanvas parent; + + GnomeCanvasItem *rect; + GnomeCanvasItem *emv; + + EBook *book; + char *query; +}; + +struct _EMinicardViewWidgetClass +{ + ECanvasClass parent_class; +}; + +GtkType e_minicard_view_widget_get_type (void); +void e_minicard_view_widget_remove_selection (EMinicardViewWidget *view, + EBookCallback cb, + gpointer closure); +void e_minicard_view_widget_jump_to_letter (EMinicardViewWidget *view, + char letter); + +GtkWidget *e_minicard_view_widget_new (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __E_MINICARD_VIEW_WIDGET_H__ */ diff --git a/addressbook/gui/search/e-addressbook-search-dialog.c b/addressbook/gui/search/e-addressbook-search-dialog.c new file mode 100644 index 0000000000..a7e0f0e1a8 --- /dev/null +++ b/addressbook/gui/search/e-addressbook-search-dialog.c @@ -0,0 +1,46 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +struct _EAddressBookSearchDialog { + GtkWidget *search; + GtkWidget *view; +}; + +static void +button_press (GtkWidget *widget, EAddressBookSearchDialog *dialog) +{ + char *query; + gtk_widget_show(dialog->view); + query = get_query(); + gtk_object_set(GTK_OBJECT(dialog->view), + "query", query, + NULL); + g_free(query); +} + +GtkWidget * +get_addressbook_search_dialog(EBook *book) +{ + GtkWidget *vbox; + GtkWidget *search; + GtkWidget *search_button; + GtkWidget *view; + + vbox = gtk_vbox_new(FALSE, 0); + + search = get_widget(); + gtk_box_pack_start(GTK_BOX(vbox), search, TRUE, TRUE, 0); + gtk_widget_show(search); + + button = gtk_button_new_with_label(_("Search")); + gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); + gtk_widget_show(button); + + view = e_minicard_view_widget_new(); + gtk_box_pack_start(GTK_BOX(vbox), view, TRUE, TRUE, 0); + gtk_object_set(GTK_OBJECT(dialog->view), + "book", book, + NULL); + + gtk_widget_show(vbox); + return vbox; +} diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am index b337754531..edd000539b 100644 --- a/addressbook/gui/widgets/Makefile.am +++ b/addressbook/gui/widgets/Makefile.am @@ -16,6 +16,8 @@ libeminicard_a_SOURCES = \ e-minicard-control.h \ e-minicard-label.c \ e-minicard-label.h \ + e-minicard-view-widget.c \ + e-minicard-view-widget.h \ e-minicard-view.c \ e-minicard-view.h \ e-minicard-widget.c \ diff --git a/addressbook/gui/widgets/e-minicard-view-widget.c b/addressbook/gui/widgets/e-minicard-view-widget.c new file mode 100644 index 0000000000..cd1a999f14 --- /dev/null +++ b/addressbook/gui/widgets/e-minicard-view-widget.c @@ -0,0 +1,267 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-minicard-view-widget.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 <config.h> +#include <gnome.h> +#include <e-util/e-canvas.h> +#include "e-minicard-view-widget.h" +static void e_minicard_view_widget_init (EMinicardViewWidget *widget); +static void e_minicard_view_widget_class_init (EMinicardViewWidgetClass *klass); +static void e_minicard_view_widget_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_minicard_view_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static void e_minicard_view_widget_destroy (GtkObject *object); +static void e_minicard_view_widget_reflow (ECanvas *canvas); +static void e_minicard_view_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation); +static void e_minicard_view_widget_realize (GtkWidget *widget); + +static ECanvasClass *parent_class = NULL; + +/* The arguments we take */ +enum { + ARG_0, + ARG_BOOK, + ARG_QUERY +}; + +GtkType +e_minicard_view_widget_get_type (void) +{ + static GtkType type = 0; + + if (!type) + { + static const GtkTypeInfo info = + { + "EMinicardViewWidget", + sizeof (EMinicardViewWidget), + sizeof (EMinicardViewWidgetClass), + (GtkClassInitFunc) e_minicard_view_widget_class_init, + (GtkObjectInitFunc) e_minicard_view_widget_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + type = gtk_type_unique (e_canvas_get_type (), &info); + } + + return type; +} + +static void +e_minicard_view_widget_class_init (EMinicardViewWidgetClass *klass) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + ECanvasClass *canvas_class; + + object_class = (GtkObjectClass*) klass; + widget_class = GTK_WIDGET_CLASS (klass); + canvas_class = E_CANVAS_CLASS (klass); + + parent_class = gtk_type_class (e_canvas_get_type ()); + + gtk_object_add_arg_type ("EMinicardViewWidget::book", GTK_TYPE_OBJECT, + GTK_ARG_READWRITE, ARG_BOOK); + gtk_object_add_arg_type ("EMinicardViewWidget::query", GTK_TYPE_STRING, + GTK_ARG_READWRITE, ARG_QUERY); + + object_class->set_arg = e_minicard_view_widget_set_arg; + object_class->get_arg = e_minicard_view_widget_get_arg; + object_class->destroy = e_minicard_view_widget_destroy; + + widget_class->realize = e_minicard_view_widget_realize; + widget_class->size_allocate = e_minicard_view_widget_size_allocate; + + canvas_class->reflow = e_minicard_view_widget_reflow; +} + +static void +e_minicard_view_widget_init (EMinicardViewWidget *view) +{ + view->emv = NULL; + view->rect = NULL; + + view->book = NULL; + view->query = NULL; +} + +GtkWidget * +e_minicard_view_widget_new (void) +{ + return GTK_WIDGET (gtk_type_new (e_minicard_view_widget_get_type ())); +} + +static void +e_minicard_view_widget_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + EMinicardViewWidget *emvw; + + emvw = E_MINICARD_VIEW_WIDGET (o); + + switch (arg_id){ + case ARG_BOOK: + if (emvw->book) + gtk_object_unref(GTK_OBJECT(emvw->book)); + emvw->book = E_BOOK(GTK_VALUE_OBJECT (*arg)); + if (emvw->book) + gtk_object_ref(GTK_OBJECT(emvw->book)); + if (emvw->emv) + gtk_object_set(GTK_OBJECT(emvw->emv), + "book", emvw->book, + NULL); + break; + case ARG_QUERY: + emvw->query = g_strdup(GTK_VALUE_STRING (*arg)); + if (emvw->emv) + gtk_object_set(GTK_OBJECT(emvw->emv), + "query", emvw->query, + NULL); + break; + } +} + +static void +e_minicard_view_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + EMinicardViewWidget *emvw; + + emvw = E_MINICARD_VIEW_WIDGET (object); + + switch (arg_id) { + case ARG_BOOK: + GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(emvw->book); + break; + case ARG_QUERY: + GTK_VALUE_STRING (*arg) = g_strdup(emvw->query); + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +static void +e_minicard_view_widget_destroy (GtkObject *object) +{ + EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(object); + + if (view->book) + gtk_object_unref(GTK_OBJECT(view->book)); + g_free(view->query); + + GTK_OBJECT_CLASS(parent_class)->destroy (object); +} + +static void +e_minicard_view_widget_realize (GtkWidget *widget) +{ + EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(widget); + + view->rect = gnome_canvas_item_new( + gnome_canvas_root( GNOME_CANVAS(view) ), + gnome_canvas_rect_get_type(), + "x1", (double) 0, + "y1", (double) 0, + "x2", (double) 100, + "y2", (double) 100, + "fill_color", "white", + NULL ); + + view->emv = gnome_canvas_item_new( + gnome_canvas_root( GNOME_CANVAS(view) ), + e_minicard_view_get_type(), + "height", (double) 100, + "minimum_width", (double) 100, + NULL ); + gtk_object_set(GTK_OBJECT(view->emv), + "book", view->book, + "query", view->query, + NULL); + + if (GTK_WIDGET_CLASS(parent_class)->realize) + GTK_WIDGET_CLASS(parent_class)->realize (widget); +} + +static void +e_minicard_view_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) +{ + if (GTK_WIDGET_CLASS(parent_class)->size_allocate) + GTK_WIDGET_CLASS(parent_class)->size_allocate (widget, allocation); + + if (GTK_WIDGET_REALIZED(widget)) { + double width; + EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(widget); + + gnome_canvas_item_set( view->emv, + "height", (double) allocation->height, + NULL ); + gnome_canvas_item_set( view->emv, + "minimum_width", (double) allocation->width, + NULL ); + gtk_object_get(GTK_OBJECT(view->emv), + "width", &width, + NULL); + width = MAX(width, allocation->width); + gnome_canvas_set_scroll_region (GNOME_CANVAS (view), 0, 0, width - 1, allocation->height - 1); + gnome_canvas_item_set( view->rect, + "x2", (double) width, + "y2", (double) allocation->height, + NULL ); + } +} + +static void +e_minicard_view_widget_reflow(ECanvas *canvas) +{ + double width; + EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(canvas); + + if (E_CANVAS_CLASS(parent_class)->reflow) + E_CANVAS_CLASS(parent_class)->reflow (canvas); + + gtk_object_get(GTK_OBJECT(view->emv), + "width", &width, + NULL); + width = MAX(width, GTK_WIDGET(canvas)->allocation.width); + gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0, width - 1, GTK_WIDGET(canvas)->allocation.width - 1); + gnome_canvas_item_set( view->rect, + "x2", (double) width, + "y2", (double) GTK_WIDGET(canvas)->allocation.height, + NULL ); +} + +void +e_minicard_view_widget_remove_selection(EMinicardViewWidget *view, + EBookCallback cb, + gpointer closure) +{ + if (view->emv) + e_minicard_view_remove_selection(E_MINICARD_VIEW(view->emv), cb, closure); +} + +void e_minicard_view_widget_jump_to_letter (EMinicardViewWidget *view, + char letter) +{ + if (view->emv) + e_minicard_view_jump_to_letter(E_MINICARD_VIEW(view->emv), letter); +} diff --git a/addressbook/gui/widgets/e-minicard-view-widget.h b/addressbook/gui/widgets/e-minicard-view-widget.h new file mode 100644 index 0000000000..340fb1e03c --- /dev/null +++ b/addressbook/gui/widgets/e-minicard-view-widget.h @@ -0,0 +1,73 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-minicard-view-widget.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_MINICARD_VIEW_WIDGET_H__ +#define __E_MINICARD_VIEW_WIDGET_H__ + +#include <gnome.h> +#include "e-minicard-view.h" +#include "e-util/e-canvas.h" +#include <ebook/e-book.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_MINICARD_VIEW_WIDGET_TYPE (e_minicard_view_widget_get_type ()) +#define E_MINICARD_VIEW_WIDGET(obj) (GTK_CHECK_CAST ((obj), E_MINICARD_VIEW_WIDGET_TYPE, EMinicardViewWidget)) +#define E_MINICARD_VIEW_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_MINICARD_VIEW_WIDGET_TYPE, EMinicardViewWidgetClass)) +#define E_IS_MINICARD_VIEW_WIDGET(obj) (GTK_CHECK_TYPE ((obj), E_MINICARD_VIEW_WIDGET_TYPE)) +#define E_IS_MINICARD_VIEW_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_MINICARD_VIEW_WIDGET_TYPE)) + + +typedef struct _EMinicardViewWidget EMinicardViewWidget; +typedef struct _EMinicardViewWidgetClass EMinicardViewWidgetClass; + +struct _EMinicardViewWidget +{ + ECanvas parent; + + GnomeCanvasItem *rect; + GnomeCanvasItem *emv; + + EBook *book; + char *query; +}; + +struct _EMinicardViewWidgetClass +{ + ECanvasClass parent_class; +}; + +GtkType e_minicard_view_widget_get_type (void); +void e_minicard_view_widget_remove_selection (EMinicardViewWidget *view, + EBookCallback cb, + gpointer closure); +void e_minicard_view_widget_jump_to_letter (EMinicardViewWidget *view, + char letter); + +GtkWidget *e_minicard_view_widget_new (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __E_MINICARD_VIEW_WIDGET_H__ */ |