diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-12-07 02:38:39 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-12-07 02:38:39 +0800 |
commit | 6dce720dc64061352041f4a55c46590c8ffcc3a0 (patch) | |
tree | aeaa4f941fc9964f0289d9078b1299d8148a4dbd /widgets | |
parent | af6115e56fddb10b0dc1dd8f38aff42754e47950 (diff) | |
download | gsoc2013-evolution-6dce720dc64061352041f4a55c46590c8ffcc3a0.tar gsoc2013-evolution-6dce720dc64061352041f4a55c46590c8ffcc3a0.tar.gz gsoc2013-evolution-6dce720dc64061352041f4a55c46590c8ffcc3a0.tar.bz2 gsoc2013-evolution-6dce720dc64061352041f4a55c46590c8ffcc3a0.tar.lz gsoc2013-evolution-6dce720dc64061352041f4a55c46590c8ffcc3a0.tar.xz gsoc2013-evolution-6dce720dc64061352041f4a55c46590c8ffcc3a0.tar.zst gsoc2013-evolution-6dce720dc64061352041f4a55c46590c8ffcc3a0.zip |
Added gal-view-collection.c, gal-view-etable.c, gal-view-factory-etable.c,
2000-12-06 Christopher James Lahey <clahey@helixcode.com>
* Makefile.am: Added gal-view-collection.c, gal-view-etable.c,
gal-view-factory-etable.c, gal-view-factory.c,
gal-view-collection.h, gal-view-etable.h,
gal-view-factory-etable.h, and gal-view-factory.h.
* gal-define-views-dialog.c, gal-define-views-dialog.h: Rewrote
this to take a GalViewCollection. This now passes its collection
to the new view dialog but still doesn't get its list of views
from the collection.
* gal-define-views-model.c: Changed this to use the gal_view_get_title
function instead of the "title" gtk argument.
* gal-define-views.glade, gal-define-views.glade.h: Changed this
dialog to be a bit cleaner.
* gal-view-collection.c, gal-view-collection.h: A collection of
views and view factories.
* gal-view-etable.c, gal-view-etable.h: An implementation of the
view class. This stores an ETableSpecification and the current
ETableState.
* gal-view-factory-etable.c, gal-view-factory-etable.h: An
implementation of the view factory class. This stores an
ETableSpecification and creates GalViewEtables when requested.
* gal-view-factory.c, gal-view-factory.h: A new virtual class.
Its primary job is to return new GalViews.
* gal-view-new-dialog.c, gal-view-new-dialog.h: Added a collection
argument to the new function here so that it can get a list of
factories to choose from.
* gal-view-new-dialog.glade, gal-view-new-dialog.glade.h: Added a
CList for the list of factories to choose from.
* gal-view.c, gal-view.h: Changed this to be a virtual class.
svn path=/trunk/; revision=6811
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/menus/gal-define-views-dialog.c | 16 | ||||
-rw-r--r-- | widgets/menus/gal-define-views-dialog.h | 3 | ||||
-rw-r--r-- | widgets/menus/gal-define-views-model.c | 15 | ||||
-rw-r--r-- | widgets/menus/gal-define-views.glade | 41 | ||||
-rw-r--r-- | widgets/menus/gal-view-collection.c | 128 | ||||
-rw-r--r-- | widgets/menus/gal-view-collection.h | 47 | ||||
-rw-r--r-- | widgets/menus/gal-view-etable.c | 115 | ||||
-rw-r--r-- | widgets/menus/gal-view-etable.h | 34 | ||||
-rw-r--r-- | widgets/menus/gal-view-factory-etable.c | 101 | ||||
-rw-r--r-- | widgets/menus/gal-view-factory-etable.h | 31 | ||||
-rw-r--r-- | widgets/menus/gal-view-factory.c | 93 | ||||
-rw-r--r-- | widgets/menus/gal-view-factory.h | 47 | ||||
-rw-r--r-- | widgets/menus/gal-view-new-dialog.c | 89 | ||||
-rw-r--r-- | widgets/menus/gal-view-new-dialog.glade | 78 | ||||
-rw-r--r-- | widgets/menus/gal-view-new-dialog.h | 11 | ||||
-rw-r--r-- | widgets/menus/gal-view.c | 148 | ||||
-rw-r--r-- | widgets/menus/gal-view.h | 28 |
17 files changed, 868 insertions, 157 deletions
diff --git a/widgets/menus/gal-define-views-dialog.c b/widgets/menus/gal-define-views-dialog.c index 97cf0eb5f2..f92f1520c7 100644 --- a/widgets/menus/gal-define-views-dialog.c +++ b/widgets/menus/gal-define-views-dialog.c @@ -111,17 +111,19 @@ gdvd_button_new_dialog_callback(GtkWidget *widget, int button, GalDefineViewsDia { gchar *name; GalView *view; + GalViewFactory *factory; switch (button) { case 0: gtk_object_get(GTK_OBJECT(widget), "name", &name, + "factory", &factory, NULL); - view = gal_view_new(); - gtk_object_set(GTK_OBJECT(view), - "name", name, - NULL); - gal_define_views_model_append(GAL_DEFINE_VIEWS_MODEL(dialog->model), view); - gtk_object_unref(GTK_OBJECT(view)); + if (name && factory) { + view = gal_view_factory_new_view(factory, + name); + gal_define_views_model_append(GAL_DEFINE_VIEWS_MODEL(dialog->model), view); + gtk_object_unref(GTK_OBJECT(view)); + } break; } gnome_dialog_close(GNOME_DIALOG(widget)); @@ -130,7 +132,7 @@ gdvd_button_new_dialog_callback(GtkWidget *widget, int button, GalDefineViewsDia static void gdvd_button_new_callback(GtkWidget *widget, GalDefineViewsDialog *dialog) { - GtkWidget *view_new_dialog = gal_view_new_dialog_new(); + GtkWidget *view_new_dialog = gal_view_new_dialog_new(dialog->collection); gtk_signal_connect(GTK_OBJECT(view_new_dialog), "clicked", GTK_SIGNAL_FUNC(gdvd_button_new_dialog_callback), dialog); gtk_widget_show(GTK_WIDGET(view_new_dialog)); diff --git a/widgets/menus/gal-define-views-dialog.h b/widgets/menus/gal-define-views-dialog.h index 7979d5042e..11daec5897 100644 --- a/widgets/menus/gal-define-views-dialog.h +++ b/widgets/menus/gal-define-views-dialog.h @@ -24,6 +24,7 @@ #include <gnome.h> #include <glade/glade.h> #include <gal/e-table/e-table-model.h> +#include <gal/menus/gal-view-collection.h> #ifdef __cplusplus extern "C" { @@ -54,6 +55,8 @@ struct _GalDefineViewsDialog /* item specific fields */ GladeXML *gui; ETableModel *model; + + GalViewCollection *collection; }; struct _GalDefineViewsDialogClass diff --git a/widgets/menus/gal-define-views-model.c b/widgets/menus/gal-define-views-model.c index 1e64857faf..79fbf56c4a 100644 --- a/widgets/menus/gal-define-views-model.c +++ b/widgets/menus/gal-define-views-model.c @@ -66,7 +66,7 @@ gdvm_value_at (ETableModel *etc, int col, int row) if (col != 0 || row < 0 || row > views->data_count) return NULL; - value = views->data[row]->name; + value = gal_view_get_title (views->data[row]); return (void *)(value ? value : ""); } @@ -96,19 +96,6 @@ gdvm_is_cell_editable (ETableModel *etc, int col, int row) static void gdvm_append_row (ETableModel *etm, ETableModel *source, gint row) { - GalDefineViewsModel *views = GAL_DEFINE_VIEWS_MODEL(etm); - GalView *view; - const void *val = e_table_model_value_at(source, 0, row); - - e_table_model_pre_change(etm); - view = gal_view_new(); - gtk_object_set(GTK_OBJECT(view), - "name", val, - NULL); - views->data = g_renew(GalView *, views->data, views->data_count + 1); - views->data[views->data_count] = view; - views->data_count++; - e_table_model_row_inserted(etm, views->data_count - 1); } /* This function duplicates the value passed to it. */ diff --git a/widgets/menus/gal-define-views.glade b/widgets/menus/gal-define-views.glade index c78d854e2d..c9a8b4ffee 100644 --- a/widgets/menus/gal-define-views.glade +++ b/widgets/menus/gal-define-views.glade @@ -201,20 +201,7 @@ <class>GtkButton</class> <name>button-modify</name> <can_focus>True</can_focus> - <label>_Modify...</label> - <relief>GTK_RELIEF_NORMAL</relief> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-rename</name> - <can_focus>True</can_focus> - <label>_Rename...</label> + <label>_Edit...</label> <relief>GTK_RELIEF_NORMAL</relief> <child> <padding>0</padding> @@ -235,32 +222,6 @@ <fill>False</fill> </child> </widget> - - <widget> - <class>GtkButton</class> - <name>button-up</name> - <can_focus>True</can_focus> - <label>Move _Up</label> - <relief>GTK_RELIEF_NORMAL</relief> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-down</name> - <can_focus>True</can_focus> - <label>Move Do_wn</label> - <relief>GTK_RELIEF_NORMAL</relief> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> </widget> </widget> diff --git a/widgets/menus/gal-view-collection.c b/widgets/menus/gal-view-collection.c new file mode 100644 index 0000000000..5b625c44f4 --- /dev/null +++ b/widgets/menus/gal-view-collection.c @@ -0,0 +1,128 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * gal-view-collection.c: a View Collection + * + * Authors: + * Chris Lahey (clahey@helixcode.com) + * + * (C) 1999, 2000 Helix Code, Inc. + */ +#include <config.h> +#include <gtk/gtksignal.h> +#include <gal/util/e-util.h> +#include "gal-view-collection.h" + +#define GVC_CLASS(e) ((GalViewCollectionClass *)((GtkObject *)e)->klass) + +#define PARENT_TYPE gtk_object_get_type () + +static GtkObjectClass *gal_view_collection_parent_class; + +enum { + DISPLAY_VIEW, + LAST_SIGNAL +}; + +static guint gal_view_collection_signals [LAST_SIGNAL] = { 0, }; + +/** + * gal_view_collection_display_view: + * @collection: The GalViewCollection to send the signal on. + * @view: The view to display. + * + */ +void +gal_view_collection_display_view (GalViewCollection *collection, + GalView *view) +{ + g_return_if_fail (collection != NULL); + g_return_if_fail (GAL_IS_VIEW_COLLECTION (collection)); + + gtk_signal_emit (GTK_OBJECT (collection), + gal_view_collection_signals [DISPLAY_VIEW], + view); +} + +static void +gal_view_collection_destroy (GtkObject *object) +{ + GalViewCollection *collection = GAL_VIEW_COLLECTION(object); + + e_free_object_list(collection->view_list); + e_free_object_list(collection->factory_list); + + if (gal_view_collection_parent_class->destroy) + (*gal_view_collection_parent_class->destroy)(object); +} + +static void +gal_view_collection_class_init (GtkObjectClass *object_class) +{ + GalViewCollectionClass *klass = GAL_VIEW_COLLECTION_CLASS(object_class); + gal_view_collection_parent_class = gtk_type_class (PARENT_TYPE); + + object_class->destroy = gal_view_collection_destroy; + + gal_view_collection_signals [DISPLAY_VIEW] = + gtk_signal_new ("display_view", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (GalViewCollectionClass, display_view), + gtk_marshal_NONE__OBJECT, + GTK_TYPE_NONE, 1, GTK_TYPE_OBJECT); + + gtk_object_class_add_signals (object_class, gal_view_collection_signals, LAST_SIGNAL); + + klass->display_view = NULL; +} + +static void +gal_view_collection_init (GalViewCollection *collection) +{ + collection->view_list = NULL; + collection->factory_list = NULL; +} + +guint +gal_view_collection_get_type (void) +{ + static guint type = 0; + + if (!type) + { + GtkTypeInfo info = + { + "GalViewCollection", + sizeof (GalViewCollection), + sizeof (GalViewCollectionClass), + (GtkClassInitFunc) gal_view_collection_class_init, + (GtkObjectInitFunc) gal_view_collection_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + type = gtk_type_unique (PARENT_TYPE, &info); + } + + return type; +} + +GalViewCollection *gal_view_collection_new (void) +{ + return gtk_type_new(gal_view_collection_get_type()); +} + +/* Set up the view collection */ +void gal_view_collection_set_storage_directories (GalViewCollection *collection, + char *system_dir, + char *local_dir) +{ +} + +void gal_view_collection_add_factory (GalViewCollection *collection, + GalViewFactory *factory) +{ + gtk_object_ref(GTK_OBJECT(factory)); + collection->factory_list = g_list_prepend(collection->factory_list, factory); +} diff --git a/widgets/menus/gal-view-collection.h b/widgets/menus/gal-view-collection.h new file mode 100644 index 0000000000..92f3b0d6b6 --- /dev/null +++ b/widgets/menus/gal-view-collection.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +#ifndef _GAL_VIEW_SET_H_ +#define _GAL_VIEW_SET_H_ + +#include <gtk/gtkobject.h> +#include <gal/util/e-list.h> +#include <gal/menus/gal-view-factory.h> + +#define GAL_VIEW_COLLECTION_TYPE (gal_view_collection_get_type ()) +#define GAL_VIEW_COLLECTION(o) (GTK_CHECK_CAST ((o), GAL_VIEW_COLLECTION_TYPE, GalViewCollection)) +#define GAL_VIEW_COLLECTION_CLASS(k) (GTK_CHECK_CLASS_CAST((k), GAL_VIEW_COLLECTION_TYPE, GalViewCollectionClass)) +#define GAL_IS_VIEW_COLLECTION(o) (GTK_CHECK_TYPE ((o), GAL_VIEW_COLLECTION_TYPE)) +#define GAL_IS_VIEW_COLLECTION_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), GAL_VIEW_COLLECTION_TYPE)) + +typedef struct { + GtkObject base; + + GList *view_list; + GList *factory_list; +} GalViewCollection; + +typedef struct { + GtkObjectClass parent_class; + + /* + * Signals + */ + void (*display_view) (GalViewCollection *collection, + GalView *view); +} GalViewCollectionClass; + +/* Standard functions */ +GtkType gal_view_collection_get_type (void); +GalViewCollection *gal_view_collection_new (void); + +/* Set up the view collection */ +void gal_view_collection_set_storage_directories (GalViewCollection *collection, + char *system_dir, + char *local_dir); +void gal_view_collection_add_factory (GalViewCollection *collection, + GalViewFactory *factory); + +/* Send the display view signal. */ +void gal_view_collection_display_view (GalViewCollection *collection, + GalView *view); + +#endif /* _GAL_VIEW_COLLECTION_H_ */ diff --git a/widgets/menus/gal-view-etable.c b/widgets/menus/gal-view-etable.c new file mode 100644 index 0000000000..d990e29ff9 --- /dev/null +++ b/widgets/menus/gal-view-etable.c @@ -0,0 +1,115 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * gal-view-etable.c: An ETable View + * + * Authors: + * Chris Lahey (clahey@helixcode.com) + * + * (C) 2000 Helix Code, Inc. + */ +#include <config.h> +#include "gal-view-etable.h" + +#define PARENT_TYPE gal_view_get_type () + +static GalViewClass *gal_view_etable_parent_class; + +static void +gal_view_etable_edit (GalView *view) +{ + +} + +static void +gal_view_etable_load_from_node (GalView *view, + xmlNode *node) +{ + +} + +static void +gal_view_etable_save_to_node (GalView *view, + xmlNode *parent) +{ + +} + +static const char * +gal_view_etable_get_title (GalView *view) +{ + return GAL_VIEW_ETABLE(view)->title; +} + +static void +gal_view_etable_destroy (GtkObject *object) +{ + GalViewEtable *view = GAL_VIEW_ETABLE(object); + g_free(view->title); + if (view->spec) + gtk_object_unref(GTK_OBJECT(view->spec)); + if (view->state) + gtk_object_unref(GTK_OBJECT(view->state)); +} + +static void +gal_view_etable_class_init (GtkObjectClass *object_class) +{ + GalViewClass *gal_view_class = GAL_VIEW_CLASS(object_class); + gal_view_etable_parent_class = gtk_type_class (PARENT_TYPE); + + gal_view_class->edit = gal_view_etable_edit ; + gal_view_class->load_from_node = gal_view_etable_load_from_node; + gal_view_class->save_to_node = gal_view_etable_save_to_node ; + gal_view_class->get_title = gal_view_etable_get_title ; + + object_class->destroy = gal_view_etable_destroy ; +} + +static void +gal_view_etable_init (GalViewEtable *gve) +{ + gve->spec = NULL; + gve->state = NULL; + gve->title = NULL; +} + +GalView * +gal_view_etable_new (ETableSpecification *spec) +{ + return gal_view_etable_construct (gtk_type_new (gal_view_etable_get_type ()), spec); +} + +GalView * +gal_view_etable_construct (GalViewEtable *view, + ETableSpecification *spec) +{ + if (spec) + gtk_object_ref(GTK_OBJECT(spec)); + view->spec = spec; + return GAL_VIEW(view); +} + +GtkType +gal_view_etable_get_type (void) +{ + static guint type = 0; + + if (!type) + { + GtkTypeInfo info = + { + "GalViewEtable", + sizeof (GalViewEtable), + sizeof (GalViewEtableClass), + (GtkClassInitFunc) gal_view_etable_class_init, + (GtkObjectInitFunc) gal_view_etable_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + type = gtk_type_unique (PARENT_TYPE, &info); + } + + return type; +} diff --git a/widgets/menus/gal-view-etable.h b/widgets/menus/gal-view-etable.h new file mode 100644 index 0000000000..5744da52ec --- /dev/null +++ b/widgets/menus/gal-view-etable.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +#ifndef _GAL_VIEW_ETABLE_H_ +#define _GAL_VIEW_ETABLE_H_ + +#include <gtk/gtkobject.h> +#include <gal/menus/gal-view.h> +#include <gal/e-table/e-table-state.h> +#include <gal/e-table/e-table-specification.h> + +#define GAL_VIEW_ETABLE_TYPE (gal_view_etable_get_type ()) +#define GAL_VIEW_ETABLE(o) (GTK_CHECK_CAST ((o), GAL_VIEW_ETABLE_TYPE, GalViewEtable)) +#define GAL_VIEW_ETABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), GAL_VIEW_ETABLE_TYPE, GalViewEtableClass)) +#define GAL_IS_VIEW_ETABLE(o) (GTK_CHECK_TYPE ((o), GAL_VIEW_ETABLE_TYPE)) +#define GAL_IS_VIEW_ETABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), GAL_VIEW_ETABLE_TYPE)) + +typedef struct { + GalView base; + + ETableSpecification *spec; + ETableState *state; + char *title; +} GalViewEtable; + +typedef struct { + GalViewClass parent_class; +} GalViewEtableClass; + +/* Standard functions */ +GtkType gal_view_etable_get_type (void); +GalView *gal_view_etable_new (ETableSpecification *spec); +GalView *gal_view_etable_construct (GalViewEtable *view, + ETableSpecification *spec); + +#endif /* _GAL_VIEW_ETABLE_H_ */ diff --git a/widgets/menus/gal-view-factory-etable.c b/widgets/menus/gal-view-factory-etable.c new file mode 100644 index 0000000000..918838050a --- /dev/null +++ b/widgets/menus/gal-view-factory-etable.c @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * gal-view-factory.c: A View Factory + * + * Authors: + * Chris Lahey (clahey@helixcode.com) + * + * (C) 2000 Helix Code, Inc. + */ +#include <config.h> +#include "gal-view-factory-etable.h" +#include "gal-view-etable.h" +#include <libgnome/gnome-defs.h> +#include <libgnome/gnome-i18n.h> + +#define GVFE_CLASS(e) ((GalViewFactoryEtableClass *)((GtkObject *)e)->klass) + +#define PARENT_TYPE gal_view_factory_get_type () + +static GalViewFactoryClass *gal_view_factory_etable_parent_class; + +static const char * +gal_view_factory_etable_get_title (GalViewFactory *factory) +{ + return _("Table"); +} + +static GalView * +gal_view_factory_etable_new_view (GalViewFactory *factory, + const char *name) +{ + return gal_view_etable_new(GAL_VIEW_FACTORY_ETABLE(factory)->spec); +} + +static void +gal_view_factory_etable_destroy (GtkObject *object) +{ + GalViewFactoryEtable *factory = GAL_VIEW_FACTORY_ETABLE(object); + + if (factory->spec) + gtk_object_unref(GTK_OBJECT(factory->spec)); +} + +static void +gal_view_factory_etable_class_init (GtkObjectClass *object_class) +{ + GalViewFactoryClass *view_factory_class = GAL_VIEW_FACTORY_CLASS(object_class); + gal_view_factory_etable_parent_class = gtk_type_class (PARENT_TYPE); + + view_factory_class->get_title = gal_view_factory_etable_get_title; + view_factory_class->new_view = gal_view_factory_etable_new_view; + + object_class->destroy = gal_view_factory_etable_destroy; +} + +static void +gal_view_factory_etable_init (GalViewFactoryEtable *factory) +{ + factory->spec = NULL; +} + +GalViewFactory * +gal_view_factory_etable_new (ETableSpecification *spec) +{ + return gal_view_factory_etable_construct (gtk_type_new (gal_view_factory_etable_get_type ()), spec); +} + +GalViewFactory * +gal_view_factory_etable_construct (GalViewFactoryEtable *factory, + ETableSpecification *spec) +{ + if (spec) + gtk_object_ref(GTK_OBJECT(spec)); + factory->spec = spec; + return GAL_VIEW_FACTORY(factory); +} + +GtkType +gal_view_factory_etable_get_type (void) +{ + static guint type = 0; + + if (!type) + { + GtkTypeInfo info = + { + "GalViewFactoryEtable", + sizeof (GalViewFactoryEtable), + sizeof (GalViewFactoryEtableClass), + (GtkClassInitFunc) gal_view_factory_etable_class_init, + (GtkObjectInitFunc) gal_view_factory_etable_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + type = gtk_type_unique (PARENT_TYPE, &info); + } + + return type; +} diff --git a/widgets/menus/gal-view-factory-etable.h b/widgets/menus/gal-view-factory-etable.h new file mode 100644 index 0000000000..226eac922a --- /dev/null +++ b/widgets/menus/gal-view-factory-etable.h @@ -0,0 +1,31 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +#ifndef _GAL_VIEW_FACTORY_ETABLE_H_ +#define _GAL_VIEW_FACTORY_ETABLE_H_ + +#include <gtk/gtkobject.h> +#include <gal/menus/gal-view-factory.h> +#include <gal/e-table/e-table-specification.h> + +#define GAL_VIEW_FACTORY_ETABLE_TYPE (gal_view_factory_etable_get_type ()) +#define GAL_VIEW_FACTORY_ETABLE(o) (GTK_CHECK_CAST ((o), GAL_VIEW_FACTORY_ETABLE_TYPE, GalViewFactoryEtable)) +#define GAL_VIEW_FACTORY_ETABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), GAL_VIEW_FACTORY_ETABLE_TYPE, GalViewFactoryEtableClass)) +#define GAL_IS_VIEW_FACTORY_ETABLE(o) (GTK_CHECK_TYPE ((o), GAL_VIEW_FACTORY_ETABLE_TYPE)) +#define GAL_IS_VIEW_FACTORY_ETABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), GAL_VIEW_FACTORY_ETABLE_TYPE)) + +typedef struct { + GalViewFactory base; + + ETableSpecification *spec; +} GalViewFactoryEtable; + +typedef struct { + GalViewFactoryClass parent_class; +} GalViewFactoryEtableClass; + +/* Standard functions */ +GtkType gal_view_factory_etable_get_type (void); +GalViewFactory *gal_view_factory_etable_new (ETableSpecification *spec); +GalViewFactory *gal_view_factory_etable_construct (GalViewFactoryEtable *factory, + ETableSpecification *spec); + +#endif /* _GAL_VIEW_FACTORY_ETABLE_H_ */ diff --git a/widgets/menus/gal-view-factory.c b/widgets/menus/gal-view-factory.c new file mode 100644 index 0000000000..e9f36d806f --- /dev/null +++ b/widgets/menus/gal-view-factory.c @@ -0,0 +1,93 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * gal-view-factory.c: A View Factory + * + * Authors: + * Chris Lahey (clahey@helixcode.com) + * + * (C) 2000 Helix Code, Inc. + */ +#include <config.h> +#include "gal-view-factory.h" + +#define GVF_CLASS(e) ((GalViewFactoryClass *)((GtkObject *)e)->klass) + +#define PARENT_TYPE gtk_object_get_type () + +#define d(x) + +d(static gint depth = 0); + +static GtkObjectClass *gal_view_factory_parent_class; + +/** + * gal_view_factory_get_title + * @factory: The factory to query. + * + * Returns: The title of the factory. + */ +const char * +gal_view_factory_get_title (GalViewFactory *factory) +{ + g_return_val_if_fail (factory != NULL, 0); + g_return_val_if_fail (GAL_IS_VIEW (factory), 0); + + if (GVF_CLASS (factory)->get_title) + return GVF_CLASS (factory)->get_title (factory); + else + return NULL; +} + +/** + * gal_view_factory_new_view + * @factory: The factory to use + * + * Returns: The new view + */ +GalView * +gal_view_factory_new_view (GalViewFactory *factory, + const char *name) +{ + g_return_val_if_fail (factory != NULL, 0); + g_return_val_if_fail (GAL_IS_VIEW (factory), 0); + + if (GVF_CLASS (factory)->new_view) + return GVF_CLASS (factory)->new_view (factory, name); + else + return NULL; +} + +static void +gal_view_factory_class_init (GtkObjectClass *object_class) +{ + GalViewFactoryClass *klass = GAL_VIEW_FACTORY_CLASS(object_class); + gal_view_factory_parent_class = gtk_type_class (PARENT_TYPE); + + klass->get_title = NULL; + klass->new_view = NULL; +} + +GtkType +gal_view_factory_get_type (void) +{ + static guint type = 0; + + if (!type) + { + GtkTypeInfo info = + { + "GalViewFactory", + sizeof (GalViewFactory), + sizeof (GalViewFactoryClass), + (GtkClassInitFunc) gal_view_factory_class_init, + NULL, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + type = gtk_type_unique (PARENT_TYPE, &info); + } + + return type; +} diff --git a/widgets/menus/gal-view-factory.h b/widgets/menus/gal-view-factory.h new file mode 100644 index 0000000000..724235d7a6 --- /dev/null +++ b/widgets/menus/gal-view-factory.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +#ifndef _GAL_VIEW_FACTORY_H_ +#define _GAL_VIEW_FACTORY_H_ + +#include <gtk/gtkobject.h> +#include <gal/menus/gal-view.h> + +#define GAL_VIEW_FACTORY_TYPE (gal_view_factory_get_type ()) +#define GAL_VIEW_FACTORY(o) (GTK_CHECK_CAST ((o), GAL_VIEW_FACTORY_TYPE, GalViewFactory)) +#define GAL_VIEW_FACTORY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), GAL_VIEW_FACTORY_TYPE, GalViewFactoryClass)) +#define GAL_IS_VIEW_FACTORY(o) (GTK_CHECK_TYPE ((o), GAL_VIEW_FACTORY_TYPE)) +#define GAL_IS_VIEW_FACTORY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), GAL_VIEW_FACTORY_TYPE)) + +typedef struct { + GtkObject base; +} GalViewFactory; + +typedef struct { + GtkObjectClass parent_class; + + /* + * Virtual methods + */ + const char *(*get_title) (GalViewFactory *factory); + const char *(*get_type_code) (GalViewFactory *factory); + GalView *(*new_view) (GalViewFactory *factory, + const char *name); +} GalViewFactoryClass; + +/* Standard functions */ +GtkType gal_view_factory_get_type (void); + +/* Query functions */ +/* Returns already translated title. */ +const char *gal_view_factory_get_title (GalViewFactory *factory); + +/* Returns the code for use in identifying this type of object in the + * view list. This identifier should identify this as being the + * unique factory for xml files which were written out with this + * identifier. Thus each factory should have a unique type code. */ +const char *gal_view_factory_get_type_code (GalViewFactory *factory); + +/* Create a new view */ +GalView *gal_view_factory_new_view (GalViewFactory *factory, + const char *name); + +#endif /* _GAL_VIEW_FACTORY_H_ */ diff --git a/widgets/menus/gal-view-new-dialog.c b/widgets/menus/gal-view-new-dialog.c index 5ab5d511d0..aee6e3f0d0 100644 --- a/widgets/menus/gal-view-new-dialog.c +++ b/widgets/menus/gal-view-new-dialog.c @@ -39,6 +39,7 @@ static GnomeDialogClass *parent_class = NULL; enum { ARG_0, ARG_NAME, + ARG_FACTORY, }; GtkType @@ -80,36 +81,18 @@ gal_view_new_dialog_class_init (GalViewNewDialogClass *klass) gtk_object_add_arg_type ("GalViewNewDialog::name", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_NAME); + gtk_object_add_arg_type ("GalViewNewDialog::factory", GTK_TYPE_OBJECT, + GTK_ARG_READABLE, ARG_FACTORY); } -#if 0 -#define SPEC "<ETableSpecification cursor-mode=\"line\" draw-grid=\"true\">" \ - "<ETableColumn model_col= \"0\" _tite=\"Name\" expansion=\"1.0\" minimum_width=\"18\" resizable=\"true\" cell=\"string\" compare=\"string\"/>" \ - "<ETableState> <column source=\"0\"/> <grouping> </grouping> </ETableState>" \ - "</ETableSpecification>" - -/* For use from libglade. */ -GtkWidget *gal_view_new_dialog_create_etable(char *name, char *string1, char *string2, int int1, int int2); - -GtkWidget * -gal_view_new_dialog_create_etable(char *name, char *string1, char *string2, int int1, int int2) -{ - GtkWidget *table; - ETableModel *model; - model = gal_define_views_model_new(); - table = e_table_scrolled_new(model, NULL, SPEC, NULL); - return table; -} -#endif - static void -gal_view_new_dialog_init (GalViewNewDialog *gal_view_new_dialog) +gal_view_new_dialog_init (GalViewNewDialog *dialog) { GladeXML *gui; GtkWidget *widget; gui = glade_xml_new (GAL_GLADEDIR "/gal-view-new-dialog.glade", NULL); - gal_view_new_dialog->gui = gui; + dialog->gui = gui; widget = glade_xml_get_widget(gui, "table-top"); if (!widget) { @@ -117,15 +100,18 @@ gal_view_new_dialog_init (GalViewNewDialog *gal_view_new_dialog) } gtk_widget_ref(widget); gtk_widget_unparent(widget); - gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(gal_view_new_dialog)->vbox), widget, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox), widget, TRUE, TRUE, 0); gtk_widget_unref(widget); - gnome_dialog_append_buttons(GNOME_DIALOG(gal_view_new_dialog), + gnome_dialog_append_buttons(GNOME_DIALOG(dialog), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); - - gtk_window_set_policy(GTK_WINDOW(gal_view_new_dialog), FALSE, TRUE, FALSE); + + gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, FALSE); + + dialog->collection = NULL; + dialog->selected_factory = NULL; } static void @@ -136,12 +122,56 @@ gal_view_new_dialog_destroy (GtkObject *object) { } GtkWidget* -gal_view_new_dialog_new (void) +gal_view_new_dialog_new (GalViewCollection *collection) { - GtkWidget *widget = GTK_WIDGET (gtk_type_new (gal_view_new_dialog_get_type ())); + GtkWidget *widget = + gal_view_new_dialog_construct(gtk_type_new (gal_view_new_dialog_get_type ()), + collection); return widget; } + +static void +gal_view_new_dialog_select_row_callback(GtkCList *list, + gint row, + gint column, + GdkEventButton *event, + GalViewNewDialog *dialog) +{ + dialog->selected_factory = gtk_clist_get_row_data(list, + row); +} + +GtkWidget* +gal_view_new_dialog_construct (GalViewNewDialog *dialog, + GalViewCollection *collection) +{ + GtkWidget *list = glade_xml_get_widget(dialog->gui, + "clist-type-list"); + GList *iterator; + dialog->collection = collection; + + iterator = dialog->collection->factory_list; + + for ( ; iterator; iterator = g_list_next(iterator) ) { + GalViewFactory *factory = iterator->data; + char *text[1]; + int row; + + gtk_object_ref(GTK_OBJECT(factory)); + text[0] = (char *) gal_view_factory_get_title(factory); + row = gtk_clist_append(GTK_CLIST(list), text); + gtk_clist_set_row_data(GTK_CLIST(list), row, factory); + } + + gtk_signal_connect(GTK_OBJECT (list), + "select_row", + GTK_SIGNAL_FUNC(gal_view_new_dialog_select_row_callback), + dialog); + + return GTK_WIDGET(dialog); +} + static void gal_view_new_dialog_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) { @@ -177,6 +207,9 @@ gal_view_new_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_STRING(*arg) = e_utf8_gtk_editable_get_text(GTK_EDITABLE(entry)); } break; + case ARG_FACTORY: + GTK_VALUE_OBJECT(*arg) = dialog->selected_factory ? GTK_OBJECT(dialog->selected_factory) : NULL; + break; default: arg->type = GTK_TYPE_INVALID; break; diff --git a/widgets/menus/gal-view-new-dialog.glade b/widgets/menus/gal-view-new-dialog.glade index aba8dc6b0f..02d9866d49 100644 --- a/widgets/menus/gal-view-new-dialog.glade +++ b/widgets/menus/gal-view-new-dialog.glade @@ -81,7 +81,7 @@ <widget> <class>GtkTable</class> <name>table-top</name> - <rows>2</rows> + <rows>4</rows> <columns>1</columns> <homogeneous>False</homogeneous> <row_spacing>6</row_spacing> @@ -95,13 +95,14 @@ <widget> <class>GtkLabel</class> <name>label1</name> - <label>_Name of new view:</label> + <label>Name of new view:</label> <justify>GTK_JUSTIFY_CENTER</justify> <wrap>False</wrap> <xalign>0</xalign> <yalign>0.5</yalign> <xpad>0</xpad> <ypad>0</ypad> + <focus_target>entry-name</focus_target> <child> <left_attach>0</left_attach> <right_attach>1</right_attach> @@ -141,6 +142,79 @@ <yfill>True</yfill> </child> </widget> + + <widget> + <class>GtkLabel</class> + <name>label2</name> + <label>Type of view:</label> + <justify>GTK_JUSTIFY_CENTER</justify> + <wrap>False</wrap> + <xalign>0</xalign> + <yalign>0.5</yalign> + <xpad>0</xpad> + <ypad>0</ypad> + <child> + <left_attach>0</left_attach> + <right_attach>1</right_attach> + <top_attach>2</top_attach> + <bottom_attach>3</bottom_attach> + <xpad>0</xpad> + <ypad>0</ypad> + <xexpand>False</xexpand> + <yexpand>False</yexpand> + <xshrink>False</xshrink> + <yshrink>False</yshrink> + <xfill>True</xfill> + <yfill>False</yfill> + </child> + </widget> + + <widget> + <class>GtkScrolledWindow</class> + <name>scrolledwindow1</name> + <hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy> + <vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy> + <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> + <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> + <child> + <left_attach>0</left_attach> + <right_attach>1</right_attach> + <top_attach>3</top_attach> + <bottom_attach>4</bottom_attach> + <xpad>0</xpad> + <ypad>0</ypad> + <xexpand>False</xexpand> + <yexpand>True</yexpand> + <xshrink>False</xshrink> + <yshrink>False</yshrink> + <xfill>True</xfill> + <yfill>True</yfill> + </child> + + <widget> + <class>GtkCList</class> + <name>clist-type-list</name> + <can_focus>True</can_focus> + <columns>1</columns> + <column_widths>80</column_widths> + <selection_mode>GTK_SELECTION_SINGLE</selection_mode> + <show_titles>False</show_titles> + <shadow_type>GTK_SHADOW_IN</shadow_type> + + <widget> + <class>GtkLabel</class> + <child_name>CList:title</child_name> + <name>label5</name> + <label>label5</label> + <justify>GTK_JUSTIFY_CENTER</justify> + <wrap>False</wrap> + <xalign>0.5</xalign> + <yalign>0.5</yalign> + <xpad>0</xpad> + <ypad>0</ypad> + </widget> + </widget> + </widget> </widget> </widget> </widget> diff --git a/widgets/menus/gal-view-new-dialog.h b/widgets/menus/gal-view-new-dialog.h index 79f04d06b4..de4fcc9387 100644 --- a/widgets/menus/gal-view-new-dialog.h +++ b/widgets/menus/gal-view-new-dialog.h @@ -23,6 +23,7 @@ #include <gnome.h> #include <glade/glade.h> +#include <gal-view-collection.h> #ifdef __cplusplus extern "C" { @@ -52,6 +53,9 @@ struct _GalViewNewDialog /* item specific fields */ GladeXML *gui; + + GalViewCollection *collection; + GalViewFactory *selected_factory; }; struct _GalViewNewDialogClass @@ -59,8 +63,11 @@ struct _GalViewNewDialogClass GnomeDialogClass parent_class; }; -GtkWidget *gal_view_new_dialog_new (void); -GtkType gal_view_new_dialog_get_type (void); +GtkWidget *gal_view_new_dialog_new (GalViewCollection *collection); +GtkType gal_view_new_dialog_get_type (void); + +GtkWidget *gal_view_new_dialog_construct (GalViewNewDialog *dialog, + GalViewCollection *collection); #ifdef __cplusplus } diff --git a/widgets/menus/gal-view.c b/widgets/menus/gal-view.c index 19c9d50f85..1ff9ffab16 100644 --- a/widgets/menus/gal-view.c +++ b/widgets/menus/gal-view.c @@ -1,97 +1,123 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * gal-view-menus.c: Savable state of a table. + * gal-view.c: A View * - * Author: - * Chris Lahey <clahey@helixcode.com> + * Authors: + * Chris Lahey (clahey@helixcode.com) * * (C) 2000 Helix Code, Inc. */ #include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> #include "gal-view.h" -#include <gal/util/e-util.h> -static void gal_view_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void gal_view_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +#define GV_CLASS(e) ((GalViewClass *)((GtkObject *)e)->klass) -#define PARENT_TYPE (gtk_object_get_type()) +#define PARENT_TYPE gtk_object_get_type () -static GtkObjectClass *gv_parent_class; +#define d(x) -enum { - ARG_0, - ARG_NAME, -}; +d(static gint depth = 0); -static void -gv_destroy (GtkObject *object) -{ - GalView *gv = GAL_VIEW (object); - g_free(gv->name); +static GtkObjectClass *gal_view_parent_class; + +/** + * gal_view_edit + * @view: The view to edit + */ +void +gal_view_edit (GalView *view) +{ + g_return_if_fail (view != NULL); + g_return_if_fail (GAL_IS_VIEW (view)); - GTK_OBJECT_CLASS (gv_parent_class)->destroy (object); + if (GV_CLASS (view)->edit) + GV_CLASS (view)->edit (view); } -static void -gal_view_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +/** + * gal_view_load_from_node + * @view: The view to load to + * @node: The xml data to load + */ +void +gal_view_load_from_node (GalView *view, + xmlNode *node) { - GalView *view; + g_return_if_fail (view != NULL); + g_return_if_fail (GAL_IS_VIEW (view)); - view = GAL_VIEW (o); - - switch (arg_id){ - case ARG_NAME: - g_free(view->name); - view->name = g_strdup(GTK_VALUE_STRING (*arg)); - break; - } + if (GV_CLASS (view)->load_from_node) + GV_CLASS (view)->load_from_node (view, node); } -static void -gal_view_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +/** + * gal_view_save_to_node + * @view: The view to save + * @parent: Save the data as a child of this node + */ +void +gal_view_save_to_node (GalView *view, + xmlNode *parent) { - GalView *view; + g_return_if_fail (view != NULL); + g_return_if_fail (GAL_IS_VIEW (view)); - view = GAL_VIEW (object); - - switch (arg_id) { - case ARG_NAME: - GTK_VALUE_STRING (*arg) = g_strdup(view->name); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } + if (GV_CLASS (view)->save_to_node) + GV_CLASS (view)->save_to_node (view, parent); } -static void -gv_init (GalView *view) +/** + * gal_view_get_title + * @view: The view to query. + * + * Returns: The title of the view. + */ +const char * +gal_view_get_title (GalView *view) { - view->name = NULL; + g_return_val_if_fail (view != NULL, NULL); + g_return_val_if_fail (GAL_IS_VIEW (view), NULL); + + if (GV_CLASS (view)->get_title) + return GV_CLASS (view)->get_title (view); + else + return NULL; } static void -gv_class_init (GtkObjectClass *klass) +gal_view_class_init (GtkObjectClass *object_class) { - gv_parent_class = gtk_type_class (PARENT_TYPE); + GalViewClass *klass = GAL_VIEW_CLASS(object_class); + gal_view_parent_class = gtk_type_class (PARENT_TYPE); - klass->destroy = gv_destroy; - klass->set_arg = gal_view_set_arg; - klass->get_arg = gal_view_get_arg; - - gtk_object_add_arg_type ("GalView::name", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_NAME); + klass->edit = NULL; + klass->load_from_node = NULL; + klass->save_to_node = NULL; + klass->get_title = NULL; } -E_MAKE_TYPE(gal_view, "GalView", GalView, gv_class_init, gv_init, PARENT_TYPE); - -GalView * -gal_view_new (void) +GtkType +gal_view_get_type (void) { - GalView *gv = gtk_type_new (GAL_VIEW_TYPE); + static guint type = 0; + + if (!type) + { + GtkTypeInfo info = + { + "GalView", + sizeof (GalView), + sizeof (GalViewClass), + (GtkClassInitFunc) gal_view_class_init, + NULL, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + type = gtk_type_unique (PARENT_TYPE, &info); + } - return (GalView *) gv; + return type; } diff --git a/widgets/menus/gal-view.h b/widgets/menus/gal-view.h index ba29e17fc7..7894e043dc 100644 --- a/widgets/menus/gal-view.h +++ b/widgets/menus/gal-view.h @@ -13,14 +13,36 @@ typedef struct { GtkObject base; - char *name; } GalView; typedef struct { GtkObjectClass parent_class; + + /* + * Virtual methods + */ + void (*edit) (GalView *view); + void (*load_from_node) (GalView *view, + xmlNode *node); + void (*save_to_node) (GalView *view, + xmlNode *parent); + const char *(*get_title) (GalView *view); } GalViewClass; -GtkType gal_view_get_type (void); -GalView *gal_view_new (void); +/* Standard functions */ +GtkType gal_view_get_type (void); + +/* Open an editor dialog for this view. */ +void gal_view_edit (GalView *view); + +/* xml load and save functions */ +void gal_view_load_from_node (GalView *view, + xmlNode *node); +void gal_view_save_to_node (GalView *view, + xmlNode *parent); + +/* Query functions */ +const char *gal_view_get_title (GalView *view); + #endif /* _GAL_VIEW_H_ */ |