aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-03-12 15:59:42 +0800
committerChris Lahey <clahey@src.gnome.org>2000-03-12 15:59:42 +0800
commit1f7ba945b16cd5f8c01641dd864a9671d791a651 (patch)
treeb673bc2f8f4b07554ca42cbd714ccc98efd14f9b
parentf669ff481f57cf5b609ea2e8fe30cfb8dece8587 (diff)
downloadgsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.tar.gz
gsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.tar.zst
gsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.zip
Rearranged SUBDIRS for dependencies.
2000-03-12 Christopher James Lahey <clahey@helixcode.com> * widgets/Makefile.am: Rearranged SUBDIRS for dependencies. * widgets/e-text/e-text-model.c, widgets/e-text-model.h: New object which stores a piece of text data. All methods are virtual. * widgets/e-text/e-text.c, widgets/e-text/e-text.h: Modified this to use an ETextModel for its data. * widgets/e-text/Makefile.am: Added e-text-model.c and e-text-model.h. * widgets/e-minicard/test-minicard-label.c: Made this work again. * widgets/e-minicard/e-minicard.c, widgets/e-minicard/e-minicard.h: Made this use an ETableModel to get its data. * widgets/e-minicard/e-minicard-label.c, widgets/e-minicard/e-minicard-label.h: Added the ability to set the text model used for the contained text widget. * widgets/e-minicard/Makefile.am: Added e-table since e-minicard is now dependent on an e-table-model for its data. * e-util/e-canvas.c, e-util/e-canvas.h: Fixed some bugs here to speed up reflow and to make it fail less often. * addressbook/demo, addressbook/demo/.cvsignore, addressbook/demo/Makefile.am, addressbook/demo/demo.c, addressbook/demo/spec: A new program to test ETable and EMinicard integration. * configure.in: Added addressbook/demo/Makefile. * addressbook/Makefile.am: Added the demo/ subdirectory. in widgets/e-table/: 2000-03-12 Christopher James Lahey <clahey@helixcode.com> * e-table.c: Made this use an ECanvas. Fixed a bug where e_table_new_from_spec_file was calling e_table_construct instead of e_table_construct_from_spec_file. * e-table-item.c, e-table-header-item.c, e-table-column-item.c: Switched these to use GTK_TYPE_OBJECT and GTK_VALUE_OBJECT instead of GTK_TYPE_POINTER and GTK_TYPE_OBJECT. * e-cell-text.c: Got rid of a crashing bug. * e-table-text-model.c, e-table-text-model.h: A new object which is an e-text-model which uses an e-table-model for its data. * Makefile.am: Added e-table-text-model.c and e-table-text-model.h. * .cvsignore: Added table-example-1 and table-example-2. svn path=/trunk/; revision=2101
-rw-r--r--ChangeLog38
-rw-r--r--addressbook/Makefile.am2
-rw-r--r--addressbook/demo/.cvsignore7
-rw-r--r--addressbook/demo/Makefile.am23
-rw-r--r--addressbook/demo/demo.c608
-rw-r--r--addressbook/demo/spec12
-rw-r--r--addressbook/gui/minicard/Makefile.am10
-rw-r--r--addressbook/gui/minicard/e-minicard-label.c162
-rw-r--r--addressbook/gui/minicard/e-minicard-label.h4
-rw-r--r--addressbook/gui/minicard/e-minicard.c140
-rw-r--r--addressbook/gui/minicard/e-minicard.h9
-rw-r--r--addressbook/gui/minicard/test-minicard-label.c21
-rw-r--r--addressbook/gui/widgets/Makefile.am10
-rw-r--r--addressbook/gui/widgets/e-minicard-label.c162
-rw-r--r--addressbook/gui/widgets/e-minicard-label.h4
-rw-r--r--addressbook/gui/widgets/e-minicard.c140
-rw-r--r--addressbook/gui/widgets/e-minicard.h9
-rw-r--r--addressbook/gui/widgets/test-minicard-label.c21
-rw-r--r--configure.in1
-rw-r--r--e-util/e-canvas.c39
-rw-r--r--e-util/e-canvas.h6
-rw-r--r--widgets/Makefile.am2
-rw-r--r--widgets/e-minicard/Makefile.am10
-rw-r--r--widgets/e-minicard/e-minicard-label.c162
-rw-r--r--widgets/e-minicard/e-minicard-label.h4
-rw-r--r--widgets/e-minicard/e-minicard.c140
-rw-r--r--widgets/e-minicard/e-minicard.h9
-rw-r--r--widgets/e-minicard/test-minicard-label.c21
-rw-r--r--widgets/e-table/.cvsignore2
-rw-r--r--widgets/e-table/ChangeLog20
-rw-r--r--widgets/e-table/Makefile.am4
-rw-r--r--widgets/e-table/e-cell-text.c10
-rw-r--r--widgets/e-table/e-table-column-item.c4
-rw-r--r--widgets/e-table/e-table-header-item.c4
-rw-r--r--widgets/e-table/e-table-item.c8
-rw-r--r--widgets/e-table/e-table-text-model.c217
-rw-r--r--widgets/e-table/e-table-text-model.h61
-rw-r--r--widgets/e-table/e-table.c4
-rw-r--r--widgets/e-text/Makefile.am8
-rw-r--r--widgets/e-text/e-text-model.c241
-rw-r--r--widgets/e-text/e-text-model.h72
-rw-r--r--widgets/e-text/e-text.c138
-rw-r--r--widgets/e-text/e-text.h4
-rw-r--r--widgets/misc/e-canvas.c39
-rw-r--r--widgets/misc/e-canvas.h6
-rw-r--r--widgets/table/.cvsignore2
-rw-r--r--widgets/table/e-cell-text.c10
-rw-r--r--widgets/table/e-table-column-item.c4
-rw-r--r--widgets/table/e-table-header-item.c4
-rw-r--r--widgets/table/e-table-item.c8
-rw-r--r--widgets/table/e-table-text-model.c217
-rw-r--r--widgets/table/e-table-text-model.h61
-rw-r--r--widgets/table/e-table.c4
-rw-r--r--widgets/text/e-table-text-model.c217
-rw-r--r--widgets/text/e-table-text-model.h61
-rw-r--r--widgets/text/e-text-model.c241
-rw-r--r--widgets/text/e-text-model.h72
-rw-r--r--widgets/text/e-text.c138
-rw-r--r--widgets/text/e-text.h4
59 files changed, 3102 insertions, 559 deletions
diff --git a/ChangeLog b/ChangeLog
index 27c3e01135..d694b46246 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,41 @@
+2000-03-12 Christopher James Lahey <clahey@helixcode.com>
+
+ * widgets/Makefile.am: Rearranged SUBDIRS for dependencies.
+
+ * widgets/e-text/e-text-model.c, widgets/e-text-model.h: New
+ object which stores a piece of text data. All methods are
+ virtual.
+
+ * widgets/e-text/e-text.c, widgets/e-text/e-text.h: Modified this
+ to use an ETextModel for its data.
+
+ * widgets/e-text/Makefile.am: Added e-text-model.c and e-text-model.h.
+
+ * widgets/e-minicard/test-minicard-label.c: Made this work again.
+
+ * widgets/e-minicard/e-minicard.c,
+ widgets/e-minicard/e-minicard.h: Made this use an ETableModel to
+ get its data.
+
+ * widgets/e-minicard/e-minicard-label.c,
+ widgets/e-minicard/e-minicard-label.h: Added the ability to set
+ the text model used for the contained text widget.
+
+ * widgets/e-minicard/Makefile.am: Added e-table since e-minicard
+ is now dependent on an e-table-model for its data.
+
+ * e-util/e-canvas.c, e-util/e-canvas.h: Fixed some bugs here to
+ speed up reflow and to make it fail less often.
+
+ * addressbook/demo, addressbook/demo/.cvsignore,
+ addressbook/demo/Makefile.am, addressbook/demo/demo.c,
+ addressbook/demo/spec: A new program to test ETable and EMinicard
+ integration.
+
+ * configure.in: Added addressbook/demo/Makefile.
+
+ * addressbook/Makefile.am: Added the demo/ subdirectory.
+
2000-03-12 bertrand <bertrand@helixcode.com>
* shell/e-folder.h: add a field refering to a
diff --git a/addressbook/Makefile.am b/addressbook/Makefile.am
index 2b588a0738..545fcc97f5 100644
--- a/addressbook/Makefile.am
+++ b/addressbook/Makefile.am
@@ -1,2 +1,2 @@
SUBDIRS = \
- contact-editor printing
+ contact-editor printing demo
diff --git a/addressbook/demo/.cvsignore b/addressbook/demo/.cvsignore
new file mode 100644
index 0000000000..d4bfaff068
--- /dev/null
+++ b/addressbook/demo/.cvsignore
@@ -0,0 +1,7 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.lo
+*.la
+evolution-addressbook \ No newline at end of file
diff --git a/addressbook/demo/Makefile.am b/addressbook/demo/Makefile.am
new file mode 100644
index 0000000000..728f66d201
--- /dev/null
+++ b/addressbook/demo/Makefile.am
@@ -0,0 +1,23 @@
+INCLUDES = \
+ $(EXTRA_GNOME_CFLAGS) \
+ $(GNOME_INCLUDEDIR) \
+ -I$(top_srcdir)/widgets/e-text \
+ -I$(top_srcdir)/e-util \
+ -I$(top_srcdir)/widgets/e-table \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/widgets/e-minicard
+
+noinst_PROGRAMS = \
+ evolution-addressbook
+
+evolution_addressbook_SOURCES = \
+ demo.c
+
+evolution_addressbook_LDADD = \
+ $(EXTRA_GNOME_LIBS) \
+ $(top_builddir)/widgets/e-minicard/libeminicard.a \
+ $(top_builddir)/widgets/e-table/libetable.a \
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/e-util/libeutil.la
+
+evolution_addressbook_LDFLAGS = `gnome-config --libs gdk_pixbuf`
diff --git a/addressbook/demo/demo.c b/addressbook/demo/demo.c
new file mode 100644
index 0000000000..4a45b50870
--- /dev/null
+++ b/addressbook/demo/demo.c
@@ -0,0 +1,608 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#include <stdio.h>
+#include <string.h>
+#include <gnome.h>
+#include <gnome-xml/tree.h>
+#include <gnome-xml/parser.h>
+#include <gnome-xml/xmlmemory.h>
+#include "e-util/e-cursors.h"
+#include "e-canvas.h"
+#include "e-table-simple.h"
+#include "e-table-header.h"
+#include "e-table-header-item.h"
+#include "e-table-item.h"
+#include "e-cell-text.h"
+#include "e-cell-checkbox.h"
+#include "e-table.h"
+#include "e-reflow.h"
+#include "e-minicard.h"
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include "table-test.h"
+
+#define COLS 4
+
+/* Here we define the initial layout of the table. This is an xml
+ format that allows you to change the initial ordering of the
+ columns or to do sorting or grouping initially. This specification
+ shows all 5 columns, but moves the importance column nearer to the
+ front. It also sorts by the "Full Name" column (ascending.)
+ Sorting and grouping take the model column as their arguments
+ (sorting is specified by the "column" argument to the leaf elemnt. */
+#define INITIAL_SPEC "<ETableSpecification> \
+ <columns-shown> \
+ <column> 0 </column> \
+ <column> 1 </column> \
+ <column> 2 </column> \
+ <column> 3 </column> \
+ </columns-shown> \
+ <grouping> <leaf column=\"1\" ascending=\"1\"/> </grouping> \
+</ETableSpecification>"
+
+char *headers[COLS] = {
+ "Email",
+ "Full Name",
+ "Address",
+ "Phone"
+};
+
+typedef struct _address address;
+typedef enum _rows rows;
+
+struct _address {
+ gchar *email;
+ gchar *full_name;
+ gchar *street;
+ gchar *phone;
+};
+
+enum _rows {
+ EMAIL,
+ FULL_NAME,
+ STREET,
+ PHONE,
+ LAST_COL
+};
+
+/* Virtual Column list:
+ 0 Email
+ 1 Full Name
+ 2 Street
+ 3 Phone
+*/
+
+
+
+static address **data;
+static int data_count;
+static ETableModel *e_table_model = NULL;
+static GtkWidget *e_table;
+static int window_count = 0;
+
+/*
+ * ETableSimple callbacks
+ * These are the callbacks that define the behavior of our custom model.
+ */
+
+/* Since our model is a constant size, we can just return its size in
+ the column and row count fields. */
+
+/* This function returns the number of columns in our ETableModel. */
+static int
+my_col_count (ETableModel *etc, void *data)
+{
+ return COLS;
+}
+
+/* This function returns the number of rows in our ETableModel. */
+static int
+my_row_count (ETableModel *etc, void *data)
+{
+ return data_count;
+}
+
+/* This function returns the value at a particular point in our ETableModel. */
+static void *
+my_value_at (ETableModel *etc, int col, int row, void *unused)
+{
+ if ( col >= LAST_COL || row >= data_count )
+ return NULL;
+ switch (col) {
+ case EMAIL:
+ return data[row]->email;
+ case FULL_NAME:
+ return data[row]->full_name;
+ case STREET:
+ return data[row]->street;
+ case PHONE:
+ return data[row]->phone;
+ default:
+ return NULL;
+ }
+}
+
+/* This function sets the value at a particular point in our ETableModel. */
+static void
+my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *unused)
+{
+ if ( col >= LAST_COL || row >= data_count )
+ return;
+ switch (col) {
+ case EMAIL:
+ g_free (data[row]->email);
+ data[row]->email = g_strdup (val);
+ break;
+ case FULL_NAME:
+ g_free (data[row]->full_name);
+ data[row]->full_name = g_strdup (val);
+ break;
+ case STREET:
+ g_free (data[row]->street);
+ data[row]->street = g_strdup (val);
+ break;
+ case PHONE:
+ g_free (data[row]->phone);
+ data[row]->phone = g_strdup (val);
+ break;
+ default:
+ return;
+ }
+}
+
+/* This function returns whether a particular cell is editable. */
+static gboolean
+my_is_cell_editable (ETableModel *etc, int col, int row, void *data)
+{
+ return TRUE;
+}
+
+/* This function duplicates the value passed to it. */
+static void *
+my_duplicate_value (ETableModel *etc, int col, const void *value, void *data)
+{
+ return g_strdup(value);
+}
+
+/* This function frees the value passed to it. */
+static void
+my_free_value (ETableModel *etc, int col, void *value, void *data)
+{
+ g_free(value);
+}
+
+/* This function is for when the model is unfrozen. This can mostly
+ be ignored for simple models. */
+static void
+my_thaw (ETableModel *etc, void *data)
+{
+}
+
+static int idle;
+
+static gboolean
+save(gpointer unused)
+{
+ int i;
+ xmlDoc *document = xmlNewDoc("1.0");
+ xmlNode *root;
+ root = xmlNewDocNode(document, NULL, "address-book", NULL);
+ xmlDocSetRootElement(document, root);
+ for ( i = 0; i < data_count; i++ ) {
+ xmlNode *xml_address = xmlNewChild(root, NULL, "address", NULL);
+ if ( data[i]->email && *data[i]->email )
+ xmlSetProp(xml_address, "email", data[i]->email);
+ if ( data[i]->email && *data[i]->street )
+ xmlSetProp(xml_address, "street", data[i]->street);
+ if ( data[i]->email && *data[i]->full_name )
+ xmlSetProp(xml_address, "full-name", data[i]->full_name);
+ if ( data[i]->email && *data[i]->phone )
+ xmlSetProp(xml_address, "phone", data[i]->phone);
+ }
+ xmlSaveFile ("addressbook.xml", document);
+ idle = 0;
+ /* e_table_save_specification(E_TABLE(e_table), "spec"); */
+ return FALSE;
+}
+
+static void
+queue_save()
+{
+ if ( !idle )
+ idle = g_idle_add(save, NULL);
+}
+
+static void
+add_column (ETableModel *etc, address *newadd)
+{
+ data = g_realloc(data, (++data_count) * sizeof(address *));
+ data[data_count - 1] = newadd;
+ queue_save();
+ if ( etc )
+ e_table_model_changed(etc);
+}
+
+
+static void
+init_data()
+{
+ data = NULL;
+ data_count = 0;
+}
+
+static void
+create_model()
+{
+ xmlDoc *document;
+ xmlNode *xml_addressbook;
+ xmlNode *xml_address;
+
+ /* First we fill in the simple data. */
+ init_data();
+ if ( g_file_exists("addressbook.xml") ) {
+ document = xmlParseFile("addressbook.xml");
+ xml_addressbook = xmlDocGetRootElement(document);
+ for (xml_address = xml_addressbook->childs; xml_address; xml_address = xml_address->next) {
+ char *datum;
+ address *newadd;
+
+ newadd = g_new(address, 1);
+
+ datum = xmlGetProp(xml_address, "email");
+ if ( datum ) {
+ newadd->email = g_strdup(datum);
+ xmlFree(datum);
+ } else
+ newadd->email = g_strdup("");
+
+ datum = xmlGetProp(xml_address, "street");
+ if ( datum ) {
+ newadd->street = g_strdup(datum);
+ xmlFree(datum);
+ } else
+ newadd->street = g_strdup("");
+
+ datum = xmlGetProp(xml_address, "full-name");
+ if ( datum ) {
+ newadd->full_name = g_strdup(datum);
+ xmlFree(datum);
+ } else
+ newadd->full_name = g_strdup("");
+
+ datum = xmlGetProp(xml_address, "phone");
+ if ( datum ) {
+ newadd->phone = g_strdup(datum);
+ xmlFree(datum);
+ } else
+ newadd->phone = g_strdup("");
+ add_column (NULL, newadd);
+ }
+ xmlFreeDoc(document);
+ }
+
+
+ e_table_model = e_table_simple_new (
+ my_col_count, my_row_count, my_value_at,
+ my_set_value_at, my_is_cell_editable,
+ my_duplicate_value, my_free_value, my_thaw, NULL);
+
+ gtk_signal_connect(GTK_OBJECT(e_table_model), "model_changed",
+ GTK_SIGNAL_FUNC(queue_save), NULL);
+ gtk_signal_connect(GTK_OBJECT(e_table_model), "model_row_changed",
+ GTK_SIGNAL_FUNC(queue_save), NULL);
+ gtk_signal_connect(GTK_OBJECT(e_table_model), "model_cell_changed",
+ GTK_SIGNAL_FUNC(queue_save), NULL);
+}
+
+static void
+add_address_cb(GtkWidget *button, gpointer data)
+{
+ address *newadd = g_new(address, 1);
+ newadd->email = g_strdup("");
+ newadd->phone = g_strdup("");
+ newadd->full_name = g_strdup("");
+ newadd->street = g_strdup("");
+ add_column (e_table_model, newadd);
+}
+
+typedef struct {
+ GtkAllocation last_alloc;
+ GnomeCanvasItem *reflow;
+ GtkWidget *canvas;
+ GnomeCanvasItem *rect;
+} reflow_demo;
+
+static void
+rebuild_reflow(ETableModel *model, gpointer data)
+{
+ int i;
+ reflow_demo *demo = (reflow_demo *)data;
+ gtk_object_destroy(GTK_OBJECT(demo->reflow));
+ demo->reflow = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( demo->canvas ) ),
+ e_reflow_get_type(),
+ "x", (double) 0,
+ "y", (double) 0,
+ "height", (double) 100,
+ "minimum_width", (double) 100,
+ NULL );
+
+ for ( i = 0; i < data_count; i++ )
+ {
+ GnomeCanvasItem *item;
+ item = gnome_canvas_item_new( GNOME_CANVAS_GROUP(demo->reflow),
+ e_minicard_get_type(),
+ "model", e_table_model,
+ "row", i,
+ NULL);
+ e_reflow_add_item(E_REFLOW(demo->reflow), item);
+ }
+ e_canvas_item_request_reflow(demo->reflow);
+}
+
+static void destroy_callback(GtkWidget *app, gpointer data)
+{
+ reflow_demo *demo = (reflow_demo *)data;
+ g_free(demo);
+ window_count --;
+ if ( window_count <= 0 )
+ exit(0);
+}
+
+static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data)
+{
+ double width;
+ reflow_demo *demo = (reflow_demo *)data;
+ demo->last_alloc = *allocation;
+ gnome_canvas_item_set( demo->reflow,
+ "height", (double) allocation->height,
+ NULL );
+ gnome_canvas_item_set( demo->reflow,
+ "minimum_width", (double) allocation->width,
+ NULL );
+ gtk_object_get(GTK_OBJECT(demo->reflow),
+ "width", &width,
+ NULL);
+ width = MAX(width, allocation->width);
+ gnome_canvas_set_scroll_region(GNOME_CANVAS( demo->canvas ), 0, 0, width, allocation->height );
+ gnome_canvas_item_set( demo->rect,
+ "x2", (double) width,
+ "y2", (double) allocation->height,
+ NULL );
+}
+
+static void resize(ECanvas *canvas, gpointer data)
+{
+ double width;
+ reflow_demo *demo = (reflow_demo *)data;
+ gtk_object_get(GTK_OBJECT(demo->reflow),
+ "width", &width,
+ NULL);
+ width = MAX(width, demo->last_alloc.width);
+ gnome_canvas_set_scroll_region(GNOME_CANVAS(demo->canvas), 0, 0, width, demo->last_alloc.height );
+ gnome_canvas_item_set( demo->rect,
+ "x2", (double) width,
+ "y2", (double) demo->last_alloc.height,
+ NULL );
+}
+
+static void
+create_reflow()
+{
+ GtkWidget *window, *frame;
+ GtkWidget *button;
+ GtkWidget *vbox;
+ GtkWidget *inner_vbox;
+ GtkWidget *scrollbar;
+ int i;
+ reflow_demo *demo = g_new(reflow_demo, 1);
+
+ /* Next we create our model. This uses the functions we defined
+ earlier. */
+ if ( e_table_model == NULL )
+ create_model();
+
+ /* Here we create a window for our new table. This window
+ will get shown and the person will be able to test their
+ item. */
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ /* This frame is simply to get a bevel around our table. */
+ frame = gtk_frame_new (NULL);
+ /* Here we create the table. We give it the three pieces of
+ the table we've created, the header, the model, and the
+ initial layout. It does the rest. */
+ inner_vbox = gtk_vbox_new(FALSE, 0);
+ demo->canvas = e_canvas_new();
+ demo->rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( demo->canvas ) ),
+ gnome_canvas_rect_get_type(),
+ "x1", (double) 0,
+ "y1", (double) 0,
+ "x2", (double) 100,
+ "y2", (double) 100,
+ "fill_color", "white",
+ NULL );
+ demo->reflow = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( demo->canvas ) ),
+ e_reflow_get_type(),
+ "x", (double) 0,
+ "y", (double) 0,
+ "height", (double) 100,
+ "minimum_width", (double) 100,
+ NULL );
+
+ gtk_signal_connect( GTK_OBJECT( demo->canvas ), "reflow",
+ GTK_SIGNAL_FUNC( resize ),
+ ( gpointer ) demo);
+
+ for ( i = 0; i < data_count; i++ )
+ {
+ GnomeCanvasItem *item;
+ item = gnome_canvas_item_new( GNOME_CANVAS_GROUP(demo->reflow),
+ e_minicard_get_type(),
+ "model", e_table_model,
+ "row", i,
+ NULL);
+ e_reflow_add_item(E_REFLOW(demo->reflow), item);
+ }
+ gnome_canvas_set_scroll_region ( GNOME_CANVAS( demo->canvas ),
+ 0, 0,
+ 100, 100 );
+
+ scrollbar = gtk_hscrollbar_new(gtk_layout_get_hadjustment(GTK_LAYOUT(demo->canvas)));
+
+ /* Connect the signals */
+ gtk_signal_connect( GTK_OBJECT( window ), "destroy",
+ GTK_SIGNAL_FUNC( destroy_callback ),
+ ( gpointer ) demo );
+
+ gtk_signal_connect( GTK_OBJECT( demo->canvas ), "size_allocate",
+ GTK_SIGNAL_FUNC( allocate_callback ),
+ ( gpointer ) demo );
+
+ gdk_window_set_back_pixmap( GTK_LAYOUT(demo->canvas)->bin_window, NULL, FALSE);
+
+ vbox = gtk_vbox_new(FALSE, 0);
+
+ button = gtk_button_new_with_label("Add address");
+ gtk_signal_connect(GTK_OBJECT(button), "clicked",
+ GTK_SIGNAL_FUNC(add_address_cb), demo);
+
+ gtk_signal_connect(GTK_OBJECT( e_table_model), "model_changed",
+ GTK_SIGNAL_FUNC(rebuild_reflow), demo);
+
+ /* Build the gtk widget hierarchy. */
+ gtk_box_pack_start(GTK_BOX(inner_vbox), demo->canvas, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(inner_vbox), scrollbar, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (frame), inner_vbox);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ /* Size the initial window. */
+ gtk_widget_set_usize (window, 200, 200);
+ /* Show it all. */
+ gtk_widget_show_all (window);
+ window_count ++;
+}
+
+static void e_table_destroy_callback(GtkWidget *app, gpointer data)
+{
+ window_count --;
+ if ( window_count <= 0 )
+ exit(0);
+}
+
+/* We create a window containing our new table. */
+static void
+create_table()
+{
+ GtkWidget *window, *frame;
+ ECell *cell_left_just;
+ ETableHeader *e_table_header;
+ GtkWidget *button;
+ GtkWidget *vbox;
+ int i;
+ /* Next we create our model. This uses the functions we defined
+ earlier. */
+ if ( e_table_model == NULL )
+ create_model();
+ /*
+ Next we create a header. The ETableHeader is used in two
+ different way. The first is the full_header. This is the
+ list of possible columns in the view. The second use is
+ completely internal. Many of the ETableHeader functions are
+ for that purpose. The only functions we really need are
+ e_table_header_new and e_table_header_add_col.
+
+ First we create the header. */
+ e_table_header = e_table_header_new ();
+
+ /* Next we have to build renderers for all of the columns.
+ Since all our columns are text columns, we can simply use
+ the same renderer over and over again. If we had different
+ types of columns, we could use a different renderer for
+ each column. */
+ cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT, TRUE);
+
+ /* Next we create a column object for each view column and add
+ them to the header. We don't create a column object for
+ the importance column since it will not be shown. */
+ for (i = 0; i < COLS; i++){
+ /* Create the column. */
+ ETableCol *ecol = e_table_col_new (
+ i, headers [i],
+ 80, 20, cell_left_just,
+ g_str_compare, TRUE);
+ /* Add it to the header. */
+ e_table_header_add_column (e_table_header, ecol, i);
+ }
+
+ /* Here we create a window for our new table. This window
+ will get shown and the person will be able to test their
+ item. */
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ /* This frame is simply to get a bevel around our table. */
+ frame = gtk_frame_new (NULL);
+ /* Here we create the table. We give it the three pieces of
+ the table we've created, the header, the model, and the
+ initial layout. It does the rest. */
+ e_table = e_table_new_from_spec_file (e_table_header, e_table_model, "spec");
+
+ gtk_signal_connect(GTK_OBJECT(E_TABLE(e_table)->sort_info), "sort_info_changed",
+ GTK_SIGNAL_FUNC(queue_save), NULL);
+
+ gtk_signal_connect(GTK_OBJECT(E_TABLE(e_table)->header), "structure_change",
+ GTK_SIGNAL_FUNC(queue_save), NULL);
+ gtk_signal_connect(GTK_OBJECT(E_TABLE(e_table)->header), "dimension_change",
+ GTK_SIGNAL_FUNC(queue_save), NULL);
+
+ gtk_signal_connect( GTK_OBJECT( window ), "destroy",
+ GTK_SIGNAL_FUNC( e_table_destroy_callback ),
+ NULL );
+
+ vbox = gtk_vbox_new(FALSE, 0);
+
+ button = gtk_button_new_with_label("Add address");
+ gtk_signal_connect(GTK_OBJECT(button), "clicked",
+ GTK_SIGNAL_FUNC(add_address_cb), NULL);
+
+ /* Build the gtk widget hierarchy. */
+ gtk_container_add (GTK_CONTAINER (frame), e_table);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ /* Size the initial window. */
+ gtk_widget_set_usize (window, 200, 200);
+ /* Show it all. */
+ gtk_widget_show_all (window);
+ window_count ++;
+}
+
+/* This is the main function which just initializes gnome and call our create_table function */
+
+int
+main (int argc, char *argv [])
+{
+ gnome_init ("TableExample", "TableExample", argc, argv);
+ e_cursors_init ();
+
+ gtk_widget_push_visual (gdk_rgb_get_visual ());
+ gtk_widget_push_colormap (gdk_rgb_get_cmap ());
+
+ create_table();
+ create_table();
+ create_table();
+ create_reflow();
+ create_reflow();
+
+ gtk_main ();
+
+ e_cursors_shutdown ();
+ return 0;
+}
+
+
+
+
+
+
+
diff --git a/addressbook/demo/spec b/addressbook/demo/spec
new file mode 100644
index 0000000000..2d366ed75f
--- /dev/null
+++ b/addressbook/demo/spec
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<ETableSpecification>
+ <columns-shown>
+ <column>1</column>
+ <column>0</column>
+ <column>2</column>
+ <column>3</column>
+ </columns-shown>
+ <grouping>
+ <leaf column="2" ascending="1"/>
+ </grouping>
+</ETableSpecification>
diff --git a/addressbook/gui/minicard/Makefile.am b/addressbook/gui/minicard/Makefile.am
index 65253e06f1..e1b130bc2a 100644
--- a/addressbook/gui/minicard/Makefile.am
+++ b/addressbook/gui/minicard/Makefile.am
@@ -1,6 +1,7 @@
INCLUDES = \
-I$(top_srcdir)/widgets/e-text \
-I$(top_srcdir)/e-util \
+ -I$(top_srcdir)/widgets/e-table \
$(GNOME_INCLUDEDIR)
noinst_LIBRARIES = \
@@ -26,7 +27,8 @@ minicard_label_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
minicard_test_SOURCES = \
test-minicard.c
@@ -35,7 +37,8 @@ minicard_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
reflow_test_SOURCES = \
test-reflow.c
@@ -44,4 +47,5 @@ reflow_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
diff --git a/addressbook/gui/minicard/e-minicard-label.c b/addressbook/gui/minicard/e-minicard-label.c
index 25f7f939fc..799eb87cd1 100644
--- a/addressbook/gui/minicard/e-minicard-label.c
+++ b/addressbook/gui/minicard/e-minicard-label.c
@@ -46,7 +46,8 @@ enum {
ARG_HEIGHT,
ARG_HAS_FOCUS,
ARG_FIELD,
- ARG_FIELDNAME
+ ARG_FIELDNAME,
+ ARG_TEXT_MODEL
};
GtkType
@@ -95,6 +96,8 @@ e_minicard_label_class_init (EMinicardLabelClass *klass)
GTK_ARG_READWRITE, ARG_FIELD);
gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING,
GTK_ARG_READWRITE, ARG_FIELDNAME);
+ gtk_object_add_arg_type ("EMinicardLabel::text_model", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_TEXT_MODEL);
object_class->set_arg = e_minicard_label_set_arg;
object_class->get_arg = e_minicard_label_get_arg;
@@ -114,8 +117,6 @@ e_minicard_label_init (EMinicardLabel *minicard_label)
minicard_label->rect = NULL;
minicard_label->fieldname = NULL;
minicard_label->field = NULL;
- minicard_label->fieldname_text = NULL;
- minicard_label->field_text = NULL;
e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard_label), e_minicard_label_reflow);
}
@@ -131,26 +132,23 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_WIDTH:
- e_minicard_label->width = GTK_VALUE_DOUBLE (*arg);
- e_minicard_label_resize_children(e_minicard_label);
- e_canvas_item_request_reflow (item);
- break;
+ e_minicard_label->width = GTK_VALUE_DOUBLE (*arg);
+ e_minicard_label_resize_children(e_minicard_label);
+ e_canvas_item_request_reflow (item);
+ break;
case ARG_HAS_FOCUS:
if (e_minicard_label->field && (GTK_VALUE_ENUM(*arg) != E_FOCUS_NONE))
e_canvas_item_grab_focus(e_minicard_label->field);
break;
case ARG_FIELD:
- if ( e_minicard_label->field )
- gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL );
- else
- e_minicard_label->field_text = g_strdup( GTK_VALUE_STRING (*arg) );
- break;
+ gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL );
+ break;
case ARG_FIELDNAME:
- if ( e_minicard_label->fieldname )
- gnome_canvas_item_set( e_minicard_label->fieldname, "text", GTK_VALUE_STRING (*arg), NULL );
- else
- e_minicard_label->fieldname_text = g_strdup( GTK_VALUE_STRING (*arg) );
- break;
+ gnome_canvas_item_set( e_minicard_label->fieldname, "text", GTK_VALUE_STRING (*arg), NULL );
+ break;
+ case ARG_TEXT_MODEL:
+ gnome_canvas_item_set( e_minicard_label->field, "model", GTK_VALUE_OBJECT (*arg), NULL);
+ break;
}
}
@@ -159,32 +157,31 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
EMinicardLabel *e_minicard_label;
char *temp;
+ ETextModel *tempmodel;
e_minicard_label = E_MINICARD_LABEL (object);
switch (arg_id) {
case ARG_WIDTH:
- GTK_VALUE_DOUBLE (*arg) = e_minicard_label->width;
- break;
+ GTK_VALUE_DOUBLE (*arg) = e_minicard_label->width;
+ break;
case ARG_HEIGHT:
- GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height;
- break;
+ GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height;
+ break;
case ARG_HAS_FOCUS:
GTK_VALUE_ENUM (*arg) = e_minicard_label->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE;
break;
case ARG_FIELD:
- if ( e_minicard_label->field ) {
- gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "text", &temp, NULL );
- GTK_VALUE_STRING (*arg) = temp;
- } else
- GTK_VALUE_STRING (*arg) = g_strdup( e_minicard_label->field_text );
+ gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "text", &temp, NULL );
+ GTK_VALUE_STRING (*arg) = temp;
break;
case ARG_FIELDNAME:
- if ( e_minicard_label->fieldname ) {
- gtk_object_get( GTK_OBJECT( e_minicard_label->fieldname ), "text", &temp, NULL );
- GTK_VALUE_STRING (*arg) = temp;
- } else
- GTK_VALUE_STRING (*arg) = g_strdup( e_minicard_label->fieldname_text );
+ gtk_object_get( GTK_OBJECT( e_minicard_label->fieldname ), "text", &temp, NULL );
+ GTK_VALUE_STRING (*arg) = temp;
+ break;
+ case ARG_TEXT_MODEL:
+ gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "model", &tempmodel, NULL );
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(tempmodel);
break;
default:
arg->type = GTK_TYPE_INVALID;
@@ -195,6 +192,19 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
static void
e_minicard_label_realize (GnomeCanvasItem *item)
{
+ if (GNOME_CANVAS_ITEM_CLASS( parent_class )->realize)
+ (* GNOME_CANVAS_ITEM_CLASS( parent_class )->realize) (item);
+
+ e_canvas_item_request_reflow(item);
+
+ if (!item->canvas->aa)
+ {
+ }
+}
+
+void
+e_minicard_label_construct (GnomeCanvasItem *item)
+{
EMinicardLabel *e_minicard_label;
GnomeCanvasGroup *group;
static GdkFont *font = NULL;
@@ -206,9 +216,6 @@ e_minicard_label_realize (GnomeCanvasItem *item)
e_minicard_label = E_MINICARD_LABEL (item);
group = GNOME_CANVAS_GROUP( item );
- if (GNOME_CANVAS_ITEM_CLASS( parent_class )->realize)
- (* GNOME_CANVAS_ITEM_CLASS( parent_class )->realize) (item);
-
e_minicard_label->rect =
gnome_canvas_item_new( group,
gnome_canvas_rect_get_type(),
@@ -229,13 +236,6 @@ e_minicard_label_realize (GnomeCanvasItem *item)
"fill_color", "black",
NULL );
e_canvas_item_move_absolute(e_minicard_label->fieldname, 2, 1);
- if ( e_minicard_label->fieldname_text )
- {
- gnome_canvas_item_set( e_minicard_label->fieldname,
- "text", e_minicard_label->fieldname_text,
- NULL );
- g_free( e_minicard_label->fieldname_text );
- }
e_minicard_label->field =
gnome_canvas_item_new( group,
@@ -249,20 +249,8 @@ e_minicard_label_realize (GnomeCanvasItem *item)
"editable", TRUE,
NULL );
e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
- if ( e_minicard_label->field_text )
- {
- gnome_canvas_item_set( e_minicard_label->field,
- "text", e_minicard_label->field_text,
- NULL );
- g_free( e_minicard_label->field_text );
- }
e_canvas_item_request_reflow(item);
-
- if (!item->canvas->aa)
- {
- }
-
}
static void
@@ -379,49 +367,53 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event)
static void
e_minicard_label_resize_children(EMinicardLabel *e_minicard_label)
{
- if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED ) {
- gnome_canvas_item_set( e_minicard_label->fieldname,
- "clip_width", (double) ( e_minicard_label->width / 2 - 4 ),
- NULL );
- gnome_canvas_item_set( e_minicard_label->field,
- "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ),
- NULL );
- }
+ gnome_canvas_item_set( e_minicard_label->fieldname,
+ "clip_width", (double) ( e_minicard_label->width / 2 - 4 ),
+ NULL );
+ gnome_canvas_item_set( e_minicard_label->field,
+ "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ),
+ NULL );
}
static void
e_minicard_label_reflow(GnomeCanvasItem *item, int flags)
{
EMinicardLabel *e_minicard_label = E_MINICARD_LABEL(item);
- if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED )
- {
- gint old_height;
- gdouble text_height;
- old_height = e_minicard_label->height;
+
+ gint old_height;
+ gdouble text_height;
+ old_height = e_minicard_label->height;
- gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname),
- "text_height", &text_height,
- NULL);
+ gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname),
+ "text_height", &text_height,
+ NULL);
- e_minicard_label->height = text_height;
+ e_minicard_label->height = text_height;
- gtk_object_get(GTK_OBJECT(e_minicard_label->field),
- "text_height", &text_height,
- NULL);
+ gtk_object_get(GTK_OBJECT(e_minicard_label->field),
+ "text_height", &text_height,
+ NULL);
- if (e_minicard_label->height < text_height)
- e_minicard_label->height = text_height;
- e_minicard_label->height += 3;
+ if (e_minicard_label->height < text_height)
+ e_minicard_label->height = text_height;
+ e_minicard_label->height += 3;
- gnome_canvas_item_set( e_minicard_label->rect,
- "x2", (double) e_minicard_label->width - 1,
- "y2", (double) e_minicard_label->height - 1,
- NULL );
- e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
+ gnome_canvas_item_set( e_minicard_label->rect,
+ "x2", (double) e_minicard_label->width - 1,
+ "y2", (double) e_minicard_label->height - 1,
+ NULL );
+ e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
- if (old_height != e_minicard_label->height)
- e_canvas_item_request_parent_reflow(item);
-
- }
+ if (old_height != e_minicard_label->height)
+ e_canvas_item_request_parent_reflow(item);
}
+
+GnomeCanvasItem *
+e_minicard_label_new(GnomeCanvasGroup *parent)
+{
+ GnomeCanvasItem *item = gnome_canvas_item_new(parent, e_minicard_label_get_type(), NULL);
+ e_minicard_label_construct(item);
+ return item;
+}
+
diff --git a/addressbook/gui/minicard/e-minicard-label.h b/addressbook/gui/minicard/e-minicard-label.h
index b439c53f9d..1790414a54 100644
--- a/addressbook/gui/minicard/e-minicard-label.h
+++ b/addressbook/gui/minicard/e-minicard-label.h
@@ -60,8 +60,6 @@ struct _EMinicardLabel
GnomeCanvasItem *fieldname;
GnomeCanvasItem *field;
GnomeCanvasItem *rect;
- char *fieldname_text;
- char *field_text;
gboolean has_focus;
};
@@ -73,6 +71,8 @@ struct _EMinicardLabelClass
GtkType e_minicard_label_get_type (void);
+GnomeCanvasItem *e_minicard_label_new(GnomeCanvasGroup *parent);
+void e_minicard_label_construct (GnomeCanvasItem *item);
#ifdef __cplusplus
}
diff --git a/addressbook/gui/minicard/e-minicard.c b/addressbook/gui/minicard/e-minicard.c
index 79668b6507..b7b9a4c10e 100644
--- a/addressbook/gui/minicard/e-minicard.c
+++ b/addressbook/gui/minicard/e-minicard.c
@@ -24,6 +24,7 @@
#include "e-minicard.h"
#include "e-minicard-label.h"
#include "e-text.h"
+#include "e-table-text-model.h"
#include "e-canvas.h"
#include "e-util.h"
#include "e-canvas-utils.h"
@@ -37,6 +38,7 @@ static void e_minicard_unrealize (GnomeCanvasItem *item);
static void e_minicard_reflow ( GnomeCanvasItem *item, int flags );
static void e_minicard_resize_children( EMinicard *e_minicard );
+static void remodel( EMinicard *e_minicard );
static GnomeCanvasGroupClass *parent_class = NULL;
@@ -46,7 +48,9 @@ enum {
ARG_WIDTH,
ARG_HEIGHT,
ARG_HAS_FOCUS,
- ARG_CARD
+ ARG_CARD,
+ ARG_MODEL,
+ ARG_ROW
};
GtkType
@@ -93,6 +97,10 @@ e_minicard_class_init (EMinicardClass *klass)
GTK_ARG_READWRITE, ARG_HAS_FOCUS);
gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT,
GTK_ARG_READWRITE, ARG_CARD);
+ gtk_object_add_arg_type ("EMinicard::model", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_MODEL);
+ gtk_object_add_arg_type ("EMinicard::row", GTK_TYPE_INT,
+ GTK_ARG_READWRITE, ARG_ROW);
object_class->set_arg = e_minicard_set_arg;
object_class->get_arg = e_minicard_get_arg;
@@ -113,6 +121,9 @@ e_minicard_init (EMinicard *minicard)
minicard->width = 10;
minicard->height = 10;
minicard->has_focus = FALSE;
+
+ minicard->model = NULL;
+ minicard->row = 0;
e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard), e_minicard_reflow);
}
@@ -131,7 +142,8 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
if (e_minicard->width != GTK_VALUE_DOUBLE (*arg)) {
e_minicard->width = GTK_VALUE_DOUBLE (*arg);
e_minicard_resize_children(e_minicard);
- e_canvas_item_request_reflow(item);
+ if ( GTK_OBJECT_FLAGS( e_minicard ) & GNOME_CANVAS_ITEM_REALIZED )
+ e_canvas_item_request_reflow(item);
}
break;
case ARG_HAS_FOCUS:
@@ -148,13 +160,23 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
}
}
else
- e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard));
+ e_canvas_item_grab_focus(item);
break;
case ARG_CARD:
- /* e_minicard->card = GTK_VALUE_POINTER (*arg);
+ /* e_minicard->card = GTK_VALUE_OBJECT (*arg);
_update_card(e_minicard);
gnome_canvas_item_request_update (item);*/
break;
+ case ARG_MODEL:
+ e_minicard->model = E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg));
+ remodel(e_minicard);
+ e_canvas_item_request_reflow(item);
+ break;
+ case ARG_ROW:
+ e_minicard->row = GTK_VALUE_INT (*arg);
+ remodel(e_minicard);
+ e_canvas_item_request_reflow(item);
+ break;
}
}
@@ -176,8 +198,14 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
GTK_VALUE_ENUM (*arg) = e_minicard->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE;
break;
case ARG_CARD:
- /* GTK_VALUE_POINTER (*arg) = e_minicard->card; */
+ /* GTK_VALUE_OBJECT (*arg) = e_minicard->card; */
break;
+ case ARG_MODEL:
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard->model);
+ break;
+ case ARG_ROW:
+ GTK_VALUE_INT (*arg) = e_minicard->row;
+ break;
default:
arg->type = GTK_TYPE_INVALID;
break;
@@ -229,41 +257,46 @@ e_minicard_realize (GnomeCanvasItem *item)
"text", "Chris Lahey",
NULL );
e_canvas_item_move_absolute(e_minicard->header_text, 6, 6);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4.0,
+ "fieldname", "Email:",
+ "field", "clahey@address.com",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Full Name:",
+ "field", "Christopher James Lahey",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- if ( rand() % 2 ) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4,
- "fieldname", "Full Name:",
- "field", "Christopher James Lahey",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
-
- if (rand() % 2) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4,
- "fieldname", "Address:",
- "field", "100 Main St\nHome town, USA",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
-
- if (rand() % 2) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4.0,
- "fieldname", "Email:",
- "field", "clahey@address.com",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Street Address:",
+ "field", "100 Main St\nHome town, USA",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Phone:",
+ "field", "000-0000",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ remodel(e_minicard);
e_canvas_item_request_reflow(item);
-
+
if (!item->canvas->aa) {
}
}
@@ -384,6 +417,35 @@ e_minicard_resize_children( EMinicard *e_minicard )
}
static void
+remodel( EMinicard *e_minicard )
+{
+ GnomeCanvasGroup *group;
+
+ group = GNOME_CANVAS_GROUP( e_minicard );
+
+ if ( e_minicard->model ) {
+ gint column = 0;
+ GList *list = e_minicard->fields;
+ ETableTextModel *model;
+ for ( ; list; list = list->next, column++ ) {
+ ETableTextModel *model = e_table_text_model_new(e_minicard->model, e_minicard->row, column);
+ gnome_canvas_item_set(GNOME_CANVAS_ITEM(list->data),
+ "text_model", model,
+ NULL);
+ gtk_object_sink(GTK_OBJECT(model));
+ }
+ if ( e_minicard->header_text ) {
+ model = e_table_text_model_new(e_minicard->model, e_minicard->row, 1);
+ gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->header_text),
+ "model", model,
+ NULL);
+ gtk_object_sink(GTK_OBJECT(model));
+ }
+
+ }
+}
+
+static void
e_minicard_reflow( GnomeCanvasItem *item, int flags )
{
EMinicard *e_minicard = E_MINICARD(item);
@@ -391,7 +453,7 @@ e_minicard_reflow( GnomeCanvasItem *item, int flags )
GList *list;
gdouble text_height;
gint old_height;
-
+
old_height = e_minicard->height;
gtk_object_get( GTK_OBJECT( e_minicard->header_text ),
diff --git a/addressbook/gui/minicard/e-minicard.h b/addressbook/gui/minicard/e-minicard.h
index 3be80c1586..05d95a743e 100644
--- a/addressbook/gui/minicard/e-minicard.h
+++ b/addressbook/gui/minicard/e-minicard.h
@@ -22,6 +22,7 @@
#define __E_MINICARD_H__
#include <gnome.h>
+#include "e-table-model.h"
#ifdef __cplusplus
extern "C" {
@@ -36,6 +37,10 @@ extern "C" {
* --------------------------------------------------------------------------------
* width double RW width of the card
* height double R height of the card
+ * model ETableModel RW model to read from
+ * row int RW ETableModel row to read from
+ *
+ * Later:
* card ECard* RW Pointer to the ECard
*/
@@ -66,6 +71,10 @@ struct _EMinicard
GnomeCanvasItem *header_rect;
GnomeCanvasItem *header_text;
GList *fields; /* Of type GnomeCanvasItem. */
+
+ ETableModel *model;
+ int row;
+ guint needs_remodeling : 1;
gboolean has_focus;
diff --git a/addressbook/gui/minicard/test-minicard-label.c b/addressbook/gui/minicard/test-minicard-label.c
index 8da34e6f22..727d709925 100644
--- a/addressbook/gui/minicard/test-minicard-label.c
+++ b/addressbook/gui/minicard/test-minicard-label.c
@@ -21,6 +21,7 @@
#include <gnome.h>
#include "e-minicard-label.h"
+#include "e-canvas.h"
/* This is a horrible thing to do, but it is just a test. */
GnomeCanvasItem *label;
@@ -80,7 +81,7 @@ int main( int argc, char *argv[] )
gnome_init( "Minicard Label Test", VERSION, argc, argv);
app = gnome_app_new("Minicard Label Test", NULL);
- canvas = gnome_canvas_new();
+ canvas = e_canvas_new();
rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ),
gnome_canvas_rect_get_type(),
"x1", (double) 0,
@@ -89,15 +90,15 @@ int main( int argc, char *argv[] )
"y2", (double) 100,
"fill_color", "white",
NULL );
- label = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ),
- e_minicard_label_get_type(),
- "x", (double) 0,
- "y", (double) 0,
- "width", (double) 100,
- "height", (double) 100,
- "fieldname", "Full Name:",
- "field", "Christopher James Lahey",
- NULL );
+ label = e_minicard_label_new(gnome_canvas_root( GNOME_CANVAS( canvas ) ));
+ gnome_canvas_item_set( label,
+ "x", (double) 0,
+ "y", (double) 0,
+ "width", (double) 100,
+ "height", (double) 100,
+ "fieldname", "Full Name:",
+ "field", "Christopher James Lahey",
+ NULL );
gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ),
0, 0,
100, 100 );
diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am
index 65253e06f1..e1b130bc2a 100644
--- a/addressbook/gui/widgets/Makefile.am
+++ b/addressbook/gui/widgets/Makefile.am
@@ -1,6 +1,7 @@
INCLUDES = \
-I$(top_srcdir)/widgets/e-text \
-I$(top_srcdir)/e-util \
+ -I$(top_srcdir)/widgets/e-table \
$(GNOME_INCLUDEDIR)
noinst_LIBRARIES = \
@@ -26,7 +27,8 @@ minicard_label_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
minicard_test_SOURCES = \
test-minicard.c
@@ -35,7 +37,8 @@ minicard_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
reflow_test_SOURCES = \
test-reflow.c
@@ -44,4 +47,5 @@ reflow_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
diff --git a/addressbook/gui/widgets/e-minicard-label.c b/addressbook/gui/widgets/e-minicard-label.c
index 25f7f939fc..799eb87cd1 100644
--- a/addressbook/gui/widgets/e-minicard-label.c
+++ b/addressbook/gui/widgets/e-minicard-label.c
@@ -46,7 +46,8 @@ enum {
ARG_HEIGHT,
ARG_HAS_FOCUS,
ARG_FIELD,
- ARG_FIELDNAME
+ ARG_FIELDNAME,
+ ARG_TEXT_MODEL
};
GtkType
@@ -95,6 +96,8 @@ e_minicard_label_class_init (EMinicardLabelClass *klass)
GTK_ARG_READWRITE, ARG_FIELD);
gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING,
GTK_ARG_READWRITE, ARG_FIELDNAME);
+ gtk_object_add_arg_type ("EMinicardLabel::text_model", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_TEXT_MODEL);
object_class->set_arg = e_minicard_label_set_arg;
object_class->get_arg = e_minicard_label_get_arg;
@@ -114,8 +117,6 @@ e_minicard_label_init (EMinicardLabel *minicard_label)
minicard_label->rect = NULL;
minicard_label->fieldname = NULL;
minicard_label->field = NULL;
- minicard_label->fieldname_text = NULL;
- minicard_label->field_text = NULL;
e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard_label), e_minicard_label_reflow);
}
@@ -131,26 +132,23 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_WIDTH:
- e_minicard_label->width = GTK_VALUE_DOUBLE (*arg);
- e_minicard_label_resize_children(e_minicard_label);
- e_canvas_item_request_reflow (item);
- break;
+ e_minicard_label->width = GTK_VALUE_DOUBLE (*arg);
+ e_minicard_label_resize_children(e_minicard_label);
+ e_canvas_item_request_reflow (item);
+ break;
case ARG_HAS_FOCUS:
if (e_minicard_label->field && (GTK_VALUE_ENUM(*arg) != E_FOCUS_NONE))
e_canvas_item_grab_focus(e_minicard_label->field);
break;
case ARG_FIELD:
- if ( e_minicard_label->field )
- gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL );
- else
- e_minicard_label->field_text = g_strdup( GTK_VALUE_STRING (*arg) );
- break;
+ gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL );
+ break;
case ARG_FIELDNAME:
- if ( e_minicard_label->fieldname )
- gnome_canvas_item_set( e_minicard_label->fieldname, "text", GTK_VALUE_STRING (*arg), NULL );
- else
- e_minicard_label->fieldname_text = g_strdup( GTK_VALUE_STRING (*arg) );
- break;
+ gnome_canvas_item_set( e_minicard_label->fieldname, "text", GTK_VALUE_STRING (*arg), NULL );
+ break;
+ case ARG_TEXT_MODEL:
+ gnome_canvas_item_set( e_minicard_label->field, "model", GTK_VALUE_OBJECT (*arg), NULL);
+ break;
}
}
@@ -159,32 +157,31 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
EMinicardLabel *e_minicard_label;
char *temp;
+ ETextModel *tempmodel;
e_minicard_label = E_MINICARD_LABEL (object);
switch (arg_id) {
case ARG_WIDTH:
- GTK_VALUE_DOUBLE (*arg) = e_minicard_label->width;
- break;
+ GTK_VALUE_DOUBLE (*arg) = e_minicard_label->width;
+ break;
case ARG_HEIGHT:
- GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height;
- break;
+ GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height;
+ break;
case ARG_HAS_FOCUS:
GTK_VALUE_ENUM (*arg) = e_minicard_label->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE;
break;
case ARG_FIELD:
- if ( e_minicard_label->field ) {
- gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "text", &temp, NULL );
- GTK_VALUE_STRING (*arg) = temp;
- } else
- GTK_VALUE_STRING (*arg) = g_strdup( e_minicard_label->field_text );
+ gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "text", &temp, NULL );
+ GTK_VALUE_STRING (*arg) = temp;
break;
case ARG_FIELDNAME:
- if ( e_minicard_label->fieldname ) {
- gtk_object_get( GTK_OBJECT( e_minicard_label->fieldname ), "text", &temp, NULL );
- GTK_VALUE_STRING (*arg) = temp;
- } else
- GTK_VALUE_STRING (*arg) = g_strdup( e_minicard_label->fieldname_text );
+ gtk_object_get( GTK_OBJECT( e_minicard_label->fieldname ), "text", &temp, NULL );
+ GTK_VALUE_STRING (*arg) = temp;
+ break;
+ case ARG_TEXT_MODEL:
+ gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "model", &tempmodel, NULL );
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(tempmodel);
break;
default:
arg->type = GTK_TYPE_INVALID;
@@ -195,6 +192,19 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
static void
e_minicard_label_realize (GnomeCanvasItem *item)
{
+ if (GNOME_CANVAS_ITEM_CLASS( parent_class )->realize)
+ (* GNOME_CANVAS_ITEM_CLASS( parent_class )->realize) (item);
+
+ e_canvas_item_request_reflow(item);
+
+ if (!item->canvas->aa)
+ {
+ }
+}
+
+void
+e_minicard_label_construct (GnomeCanvasItem *item)
+{
EMinicardLabel *e_minicard_label;
GnomeCanvasGroup *group;
static GdkFont *font = NULL;
@@ -206,9 +216,6 @@ e_minicard_label_realize (GnomeCanvasItem *item)
e_minicard_label = E_MINICARD_LABEL (item);
group = GNOME_CANVAS_GROUP( item );
- if (GNOME_CANVAS_ITEM_CLASS( parent_class )->realize)
- (* GNOME_CANVAS_ITEM_CLASS( parent_class )->realize) (item);
-
e_minicard_label->rect =
gnome_canvas_item_new( group,
gnome_canvas_rect_get_type(),
@@ -229,13 +236,6 @@ e_minicard_label_realize (GnomeCanvasItem *item)
"fill_color", "black",
NULL );
e_canvas_item_move_absolute(e_minicard_label->fieldname, 2, 1);
- if ( e_minicard_label->fieldname_text )
- {
- gnome_canvas_item_set( e_minicard_label->fieldname,
- "text", e_minicard_label->fieldname_text,
- NULL );
- g_free( e_minicard_label->fieldname_text );
- }
e_minicard_label->field =
gnome_canvas_item_new( group,
@@ -249,20 +249,8 @@ e_minicard_label_realize (GnomeCanvasItem *item)
"editable", TRUE,
NULL );
e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
- if ( e_minicard_label->field_text )
- {
- gnome_canvas_item_set( e_minicard_label->field,
- "text", e_minicard_label->field_text,
- NULL );
- g_free( e_minicard_label->field_text );
- }
e_canvas_item_request_reflow(item);
-
- if (!item->canvas->aa)
- {
- }
-
}
static void
@@ -379,49 +367,53 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event)
static void
e_minicard_label_resize_children(EMinicardLabel *e_minicard_label)
{
- if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED ) {
- gnome_canvas_item_set( e_minicard_label->fieldname,
- "clip_width", (double) ( e_minicard_label->width / 2 - 4 ),
- NULL );
- gnome_canvas_item_set( e_minicard_label->field,
- "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ),
- NULL );
- }
+ gnome_canvas_item_set( e_minicard_label->fieldname,
+ "clip_width", (double) ( e_minicard_label->width / 2 - 4 ),
+ NULL );
+ gnome_canvas_item_set( e_minicard_label->field,
+ "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ),
+ NULL );
}
static void
e_minicard_label_reflow(GnomeCanvasItem *item, int flags)
{
EMinicardLabel *e_minicard_label = E_MINICARD_LABEL(item);
- if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED )
- {
- gint old_height;
- gdouble text_height;
- old_height = e_minicard_label->height;
+
+ gint old_height;
+ gdouble text_height;
+ old_height = e_minicard_label->height;
- gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname),
- "text_height", &text_height,
- NULL);
+ gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname),
+ "text_height", &text_height,
+ NULL);
- e_minicard_label->height = text_height;
+ e_minicard_label->height = text_height;
- gtk_object_get(GTK_OBJECT(e_minicard_label->field),
- "text_height", &text_height,
- NULL);
+ gtk_object_get(GTK_OBJECT(e_minicard_label->field),
+ "text_height", &text_height,
+ NULL);
- if (e_minicard_label->height < text_height)
- e_minicard_label->height = text_height;
- e_minicard_label->height += 3;
+ if (e_minicard_label->height < text_height)
+ e_minicard_label->height = text_height;
+ e_minicard_label->height += 3;
- gnome_canvas_item_set( e_minicard_label->rect,
- "x2", (double) e_minicard_label->width - 1,
- "y2", (double) e_minicard_label->height - 1,
- NULL );
- e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
+ gnome_canvas_item_set( e_minicard_label->rect,
+ "x2", (double) e_minicard_label->width - 1,
+ "y2", (double) e_minicard_label->height - 1,
+ NULL );
+ e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
- if (old_height != e_minicard_label->height)
- e_canvas_item_request_parent_reflow(item);
-
- }
+ if (old_height != e_minicard_label->height)
+ e_canvas_item_request_parent_reflow(item);
}
+
+GnomeCanvasItem *
+e_minicard_label_new(GnomeCanvasGroup *parent)
+{
+ GnomeCanvasItem *item = gnome_canvas_item_new(parent, e_minicard_label_get_type(), NULL);
+ e_minicard_label_construct(item);
+ return item;
+}
+
diff --git a/addressbook/gui/widgets/e-minicard-label.h b/addressbook/gui/widgets/e-minicard-label.h
index b439c53f9d..1790414a54 100644
--- a/addressbook/gui/widgets/e-minicard-label.h
+++ b/addressbook/gui/widgets/e-minicard-label.h
@@ -60,8 +60,6 @@ struct _EMinicardLabel
GnomeCanvasItem *fieldname;
GnomeCanvasItem *field;
GnomeCanvasItem *rect;
- char *fieldname_text;
- char *field_text;
gboolean has_focus;
};
@@ -73,6 +71,8 @@ struct _EMinicardLabelClass
GtkType e_minicard_label_get_type (void);
+GnomeCanvasItem *e_minicard_label_new(GnomeCanvasGroup *parent);
+void e_minicard_label_construct (GnomeCanvasItem *item);
#ifdef __cplusplus
}
diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c
index 79668b6507..b7b9a4c10e 100644
--- a/addressbook/gui/widgets/e-minicard.c
+++ b/addressbook/gui/widgets/e-minicard.c
@@ -24,6 +24,7 @@
#include "e-minicard.h"
#include "e-minicard-label.h"
#include "e-text.h"
+#include "e-table-text-model.h"
#include "e-canvas.h"
#include "e-util.h"
#include "e-canvas-utils.h"
@@ -37,6 +38,7 @@ static void e_minicard_unrealize (GnomeCanvasItem *item);
static void e_minicard_reflow ( GnomeCanvasItem *item, int flags );
static void e_minicard_resize_children( EMinicard *e_minicard );
+static void remodel( EMinicard *e_minicard );
static GnomeCanvasGroupClass *parent_class = NULL;
@@ -46,7 +48,9 @@ enum {
ARG_WIDTH,
ARG_HEIGHT,
ARG_HAS_FOCUS,
- ARG_CARD
+ ARG_CARD,
+ ARG_MODEL,
+ ARG_ROW
};
GtkType
@@ -93,6 +97,10 @@ e_minicard_class_init (EMinicardClass *klass)
GTK_ARG_READWRITE, ARG_HAS_FOCUS);
gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT,
GTK_ARG_READWRITE, ARG_CARD);
+ gtk_object_add_arg_type ("EMinicard::model", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_MODEL);
+ gtk_object_add_arg_type ("EMinicard::row", GTK_TYPE_INT,
+ GTK_ARG_READWRITE, ARG_ROW);
object_class->set_arg = e_minicard_set_arg;
object_class->get_arg = e_minicard_get_arg;
@@ -113,6 +121,9 @@ e_minicard_init (EMinicard *minicard)
minicard->width = 10;
minicard->height = 10;
minicard->has_focus = FALSE;
+
+ minicard->model = NULL;
+ minicard->row = 0;
e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard), e_minicard_reflow);
}
@@ -131,7 +142,8 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
if (e_minicard->width != GTK_VALUE_DOUBLE (*arg)) {
e_minicard->width = GTK_VALUE_DOUBLE (*arg);
e_minicard_resize_children(e_minicard);
- e_canvas_item_request_reflow(item);
+ if ( GTK_OBJECT_FLAGS( e_minicard ) & GNOME_CANVAS_ITEM_REALIZED )
+ e_canvas_item_request_reflow(item);
}
break;
case ARG_HAS_FOCUS:
@@ -148,13 +160,23 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
}
}
else
- e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard));
+ e_canvas_item_grab_focus(item);
break;
case ARG_CARD:
- /* e_minicard->card = GTK_VALUE_POINTER (*arg);
+ /* e_minicard->card = GTK_VALUE_OBJECT (*arg);
_update_card(e_minicard);
gnome_canvas_item_request_update (item);*/
break;
+ case ARG_MODEL:
+ e_minicard->model = E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg));
+ remodel(e_minicard);
+ e_canvas_item_request_reflow(item);
+ break;
+ case ARG_ROW:
+ e_minicard->row = GTK_VALUE_INT (*arg);
+ remodel(e_minicard);
+ e_canvas_item_request_reflow(item);
+ break;
}
}
@@ -176,8 +198,14 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
GTK_VALUE_ENUM (*arg) = e_minicard->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE;
break;
case ARG_CARD:
- /* GTK_VALUE_POINTER (*arg) = e_minicard->card; */
+ /* GTK_VALUE_OBJECT (*arg) = e_minicard->card; */
break;
+ case ARG_MODEL:
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard->model);
+ break;
+ case ARG_ROW:
+ GTK_VALUE_INT (*arg) = e_minicard->row;
+ break;
default:
arg->type = GTK_TYPE_INVALID;
break;
@@ -229,41 +257,46 @@ e_minicard_realize (GnomeCanvasItem *item)
"text", "Chris Lahey",
NULL );
e_canvas_item_move_absolute(e_minicard->header_text, 6, 6);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4.0,
+ "fieldname", "Email:",
+ "field", "clahey@address.com",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Full Name:",
+ "field", "Christopher James Lahey",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- if ( rand() % 2 ) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4,
- "fieldname", "Full Name:",
- "field", "Christopher James Lahey",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
-
- if (rand() % 2) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4,
- "fieldname", "Address:",
- "field", "100 Main St\nHome town, USA",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
-
- if (rand() % 2) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4.0,
- "fieldname", "Email:",
- "field", "clahey@address.com",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Street Address:",
+ "field", "100 Main St\nHome town, USA",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Phone:",
+ "field", "000-0000",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ remodel(e_minicard);
e_canvas_item_request_reflow(item);
-
+
if (!item->canvas->aa) {
}
}
@@ -384,6 +417,35 @@ e_minicard_resize_children( EMinicard *e_minicard )
}
static void
+remodel( EMinicard *e_minicard )
+{
+ GnomeCanvasGroup *group;
+
+ group = GNOME_CANVAS_GROUP( e_minicard );
+
+ if ( e_minicard->model ) {
+ gint column = 0;
+ GList *list = e_minicard->fields;
+ ETableTextModel *model;
+ for ( ; list; list = list->next, column++ ) {
+ ETableTextModel *model = e_table_text_model_new(e_minicard->model, e_minicard->row, column);
+ gnome_canvas_item_set(GNOME_CANVAS_ITEM(list->data),
+ "text_model", model,
+ NULL);
+ gtk_object_sink(GTK_OBJECT(model));
+ }
+ if ( e_minicard->header_text ) {
+ model = e_table_text_model_new(e_minicard->model, e_minicard->row, 1);
+ gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->header_text),
+ "model", model,
+ NULL);
+ gtk_object_sink(GTK_OBJECT(model));
+ }
+
+ }
+}
+
+static void
e_minicard_reflow( GnomeCanvasItem *item, int flags )
{
EMinicard *e_minicard = E_MINICARD(item);
@@ -391,7 +453,7 @@ e_minicard_reflow( GnomeCanvasItem *item, int flags )
GList *list;
gdouble text_height;
gint old_height;
-
+
old_height = e_minicard->height;
gtk_object_get( GTK_OBJECT( e_minicard->header_text ),
diff --git a/addressbook/gui/widgets/e-minicard.h b/addressbook/gui/widgets/e-minicard.h
index 3be80c1586..05d95a743e 100644
--- a/addressbook/gui/widgets/e-minicard.h
+++ b/addressbook/gui/widgets/e-minicard.h
@@ -22,6 +22,7 @@
#define __E_MINICARD_H__
#include <gnome.h>
+#include "e-table-model.h"
#ifdef __cplusplus
extern "C" {
@@ -36,6 +37,10 @@ extern "C" {
* --------------------------------------------------------------------------------
* width double RW width of the card
* height double R height of the card
+ * model ETableModel RW model to read from
+ * row int RW ETableModel row to read from
+ *
+ * Later:
* card ECard* RW Pointer to the ECard
*/
@@ -66,6 +71,10 @@ struct _EMinicard
GnomeCanvasItem *header_rect;
GnomeCanvasItem *header_text;
GList *fields; /* Of type GnomeCanvasItem. */
+
+ ETableModel *model;
+ int row;
+ guint needs_remodeling : 1;
gboolean has_focus;
diff --git a/addressbook/gui/widgets/test-minicard-label.c b/addressbook/gui/widgets/test-minicard-label.c
index 8da34e6f22..727d709925 100644
--- a/addressbook/gui/widgets/test-minicard-label.c
+++ b/addressbook/gui/widgets/test-minicard-label.c
@@ -21,6 +21,7 @@
#include <gnome.h>
#include "e-minicard-label.h"
+#include "e-canvas.h"
/* This is a horrible thing to do, but it is just a test. */
GnomeCanvasItem *label;
@@ -80,7 +81,7 @@ int main( int argc, char *argv[] )
gnome_init( "Minicard Label Test", VERSION, argc, argv);
app = gnome_app_new("Minicard Label Test", NULL);
- canvas = gnome_canvas_new();
+ canvas = e_canvas_new();
rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ),
gnome_canvas_rect_get_type(),
"x1", (double) 0,
@@ -89,15 +90,15 @@ int main( int argc, char *argv[] )
"y2", (double) 100,
"fill_color", "white",
NULL );
- label = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ),
- e_minicard_label_get_type(),
- "x", (double) 0,
- "y", (double) 0,
- "width", (double) 100,
- "height", (double) 100,
- "fieldname", "Full Name:",
- "field", "Christopher James Lahey",
- NULL );
+ label = e_minicard_label_new(gnome_canvas_root( GNOME_CANVAS( canvas ) ));
+ gnome_canvas_item_set( label,
+ "x", (double) 0,
+ "y", (double) 0,
+ "width", (double) 100,
+ "height", (double) 100,
+ "fieldname", "Full Name:",
+ "field", "Christopher James Lahey",
+ NULL );
gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ),
0, 0,
100, 100 );
diff --git a/configure.in b/configure.in
index 602080afc5..dddf223a12 100644
--- a/configure.in
+++ b/configure.in
@@ -264,6 +264,7 @@ widgets/shortcut-bar/Makefile
widgets/e-table/Makefile
addressbook/Makefile
addressbook/contact-editor/Makefile
+addressbook/demo/Makefile
addressbook/printing/Makefile
shell/Makefile
mail/Makefile
diff --git a/e-util/e-canvas.c b/e-util/e-canvas.c
index 68f1b0f9f3..76b9286156 100644
--- a/e-util/e-canvas.c
+++ b/e-util/e-canvas.c
@@ -93,7 +93,7 @@ e_canvas_class_init (ECanvasClass *klass)
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ECanvasClass, reflow),
- gtk_marshal_NONE__INT_INT,
+ gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, e_canvas_signals, LAST_SIGNAL);
@@ -321,39 +321,39 @@ e_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event)
static void
-e_canvas_item_invoke_update (GnomeCanvasItem *item, int flags)
+e_canvas_item_invoke_reflow (GnomeCanvasItem *item, int flags)
{
GnomeCanvasGroup *group;
GList *list;
GnomeCanvasItem *child;
- if ( ! gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::descendent_needs_reflow") )
- return;
if ( GNOME_IS_CANVAS_GROUP( item ) ) {
group = GNOME_CANVAS_GROUP( item );
for ( list = group->item_list; list; list = list->next ) {
child = GNOME_CANVAS_ITEM(list->data);
- e_canvas_item_invoke_update(child, flags);
+ if ( child->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW )
+ e_canvas_item_invoke_reflow(child, flags);
}
}
-
- if ( gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::needs_reflow") ) {
+
+ if ( item->object.flags & E_CANVAS_ITEM_NEEDS_REFLOW ) {
ECanvasItemReflowFunc func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::reflow_callback");
if ( func )
func(item, flags);
}
- gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::needs_reflow", (gpointer) 0);
- gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::descendent_needs_reflow", (gpointer) 0);
+ item->object.flags &= ~E_CANVAS_ITEM_NEEDS_REFLOW;
+ item->object.flags &= ~E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW;
}
static void
-do_update (ECanvas *canvas)
+do_reflow (ECanvas *canvas)
{
- e_canvas_item_invoke_update (GNOME_CANVAS(canvas)->root, 0);
+ if ( GNOME_CANVAS(canvas)->root->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW )
+ e_canvas_item_invoke_reflow (GNOME_CANVAS(canvas)->root, 0);
}
-/* Idle handler for the canvas. It deals with pending updates and redraws. */
+/* Idle handler for the e-canvas. It deals with pending reflows. */
static gint
idle_handler (gpointer data)
{
@@ -362,7 +362,7 @@ idle_handler (gpointer data)
GDK_THREADS_ENTER ();
canvas = E_CANVAS (data);
- do_update (canvas);
+ do_reflow (canvas);
/* Reset idle id */
canvas->idle_id = 0;
@@ -388,9 +388,10 @@ add_idle (ECanvas *canvas)
static void
e_canvas_item_descendent_needs_reflow (GnomeCanvasItem *item)
{
- if ( gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::descendent_needs_reflow") )
+ if ( item->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW )
return;
- gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::descendent_needs_reflow", (gpointer) 1);
+
+ item->object.flags |= E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW;
if ( item->parent )
e_canvas_item_descendent_needs_reflow(item->parent);
}
@@ -398,9 +399,11 @@ e_canvas_item_descendent_needs_reflow (GnomeCanvasItem *item)
void
e_canvas_item_request_reflow (GnomeCanvasItem *item)
{
- gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::needs_reflow", (gpointer) 1);
- e_canvas_item_descendent_needs_reflow(item);
- add_idle(E_CANVAS(item->canvas));
+ if ( item->object.flags & GNOME_CANVAS_ITEM_REALIZED ) {
+ item->object.flags |= E_CANVAS_ITEM_NEEDS_REFLOW;
+ e_canvas_item_descendent_needs_reflow(item);
+ add_idle(E_CANVAS(item->canvas));
+ }
}
void
diff --git a/e-util/e-canvas.h b/e-util/e-canvas.h
index e70957b6d7..f1ff1195c9 100644
--- a/e-util/e-canvas.h
+++ b/e-util/e-canvas.h
@@ -44,6 +44,12 @@ typedef void (*ECanvasItemReflowFunc) (GnomeCanvasItem *item,
typedef struct _ECanvas ECanvas;
typedef struct _ECanvasClass ECanvasClass;
+/* Object flags for items */
+enum {
+ E_CANVAS_ITEM_NEEDS_REFLOW = 1 << 13,
+ E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW = 1 << 14
+};
+
struct _ECanvas
{
GnomeCanvas parent;
diff --git a/widgets/Makefile.am b/widgets/Makefile.am
index 5d052b11a0..73f2805d32 100644
--- a/widgets/Makefile.am
+++ b/widgets/Makefile.am
@@ -1,3 +1,3 @@
SUBDIRS = \
- e-text e-minicard meeting-time-sel shortcut-bar e-table
+ e-text meeting-time-sel shortcut-bar e-table e-minicard
diff --git a/widgets/e-minicard/Makefile.am b/widgets/e-minicard/Makefile.am
index 65253e06f1..e1b130bc2a 100644
--- a/widgets/e-minicard/Makefile.am
+++ b/widgets/e-minicard/Makefile.am
@@ -1,6 +1,7 @@
INCLUDES = \
-I$(top_srcdir)/widgets/e-text \
-I$(top_srcdir)/e-util \
+ -I$(top_srcdir)/widgets/e-table \
$(GNOME_INCLUDEDIR)
noinst_LIBRARIES = \
@@ -26,7 +27,8 @@ minicard_label_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
minicard_test_SOURCES = \
test-minicard.c
@@ -35,7 +37,8 @@ minicard_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
reflow_test_SOURCES = \
test-reflow.c
@@ -44,4 +47,5 @@ reflow_test_LDADD = \
$(EXTRA_GNOME_LIBS) \
libeminicard.a \
$(top_builddir)/e-util/libeutil.la \
- $(top_builddir)/widgets/e-text/libetext.a
+ $(top_builddir)/widgets/e-text/libetext.a \
+ $(top_builddir)/widgets/e-table/libetable.a
diff --git a/widgets/e-minicard/e-minicard-label.c b/widgets/e-minicard/e-minicard-label.c
index 25f7f939fc..799eb87cd1 100644
--- a/widgets/e-minicard/e-minicard-label.c
+++ b/widgets/e-minicard/e-minicard-label.c
@@ -46,7 +46,8 @@ enum {
ARG_HEIGHT,
ARG_HAS_FOCUS,
ARG_FIELD,
- ARG_FIELDNAME
+ ARG_FIELDNAME,
+ ARG_TEXT_MODEL
};
GtkType
@@ -95,6 +96,8 @@ e_minicard_label_class_init (EMinicardLabelClass *klass)
GTK_ARG_READWRITE, ARG_FIELD);
gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING,
GTK_ARG_READWRITE, ARG_FIELDNAME);
+ gtk_object_add_arg_type ("EMinicardLabel::text_model", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_TEXT_MODEL);
object_class->set_arg = e_minicard_label_set_arg;
object_class->get_arg = e_minicard_label_get_arg;
@@ -114,8 +117,6 @@ e_minicard_label_init (EMinicardLabel *minicard_label)
minicard_label->rect = NULL;
minicard_label->fieldname = NULL;
minicard_label->field = NULL;
- minicard_label->fieldname_text = NULL;
- minicard_label->field_text = NULL;
e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard_label), e_minicard_label_reflow);
}
@@ -131,26 +132,23 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_WIDTH:
- e_minicard_label->width = GTK_VALUE_DOUBLE (*arg);
- e_minicard_label_resize_children(e_minicard_label);
- e_canvas_item_request_reflow (item);
- break;
+ e_minicard_label->width = GTK_VALUE_DOUBLE (*arg);
+ e_minicard_label_resize_children(e_minicard_label);
+ e_canvas_item_request_reflow (item);
+ break;
case ARG_HAS_FOCUS:
if (e_minicard_label->field && (GTK_VALUE_ENUM(*arg) != E_FOCUS_NONE))
e_canvas_item_grab_focus(e_minicard_label->field);
break;
case ARG_FIELD:
- if ( e_minicard_label->field )
- gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL );
- else
- e_minicard_label->field_text = g_strdup( GTK_VALUE_STRING (*arg) );
- break;
+ gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL );
+ break;
case ARG_FIELDNAME:
- if ( e_minicard_label->fieldname )
- gnome_canvas_item_set( e_minicard_label->fieldname, "text", GTK_VALUE_STRING (*arg), NULL );
- else
- e_minicard_label->fieldname_text = g_strdup( GTK_VALUE_STRING (*arg) );
- break;
+ gnome_canvas_item_set( e_minicard_label->fieldname, "text", GTK_VALUE_STRING (*arg), NULL );
+ break;
+ case ARG_TEXT_MODEL:
+ gnome_canvas_item_set( e_minicard_label->field, "model", GTK_VALUE_OBJECT (*arg), NULL);
+ break;
}
}
@@ -159,32 +157,31 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
EMinicardLabel *e_minicard_label;
char *temp;
+ ETextModel *tempmodel;
e_minicard_label = E_MINICARD_LABEL (object);
switch (arg_id) {
case ARG_WIDTH:
- GTK_VALUE_DOUBLE (*arg) = e_minicard_label->width;
- break;
+ GTK_VALUE_DOUBLE (*arg) = e_minicard_label->width;
+ break;
case ARG_HEIGHT:
- GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height;
- break;
+ GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height;
+ break;
case ARG_HAS_FOCUS:
GTK_VALUE_ENUM (*arg) = e_minicard_label->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE;
break;
case ARG_FIELD:
- if ( e_minicard_label->field ) {
- gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "text", &temp, NULL );
- GTK_VALUE_STRING (*arg) = temp;
- } else
- GTK_VALUE_STRING (*arg) = g_strdup( e_minicard_label->field_text );
+ gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "text", &temp, NULL );
+ GTK_VALUE_STRING (*arg) = temp;
break;
case ARG_FIELDNAME:
- if ( e_minicard_label->fieldname ) {
- gtk_object_get( GTK_OBJECT( e_minicard_label->fieldname ), "text", &temp, NULL );
- GTK_VALUE_STRING (*arg) = temp;
- } else
- GTK_VALUE_STRING (*arg) = g_strdup( e_minicard_label->fieldname_text );
+ gtk_object_get( GTK_OBJECT( e_minicard_label->fieldname ), "text", &temp, NULL );
+ GTK_VALUE_STRING (*arg) = temp;
+ break;
+ case ARG_TEXT_MODEL:
+ gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "model", &tempmodel, NULL );
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(tempmodel);
break;
default:
arg->type = GTK_TYPE_INVALID;
@@ -195,6 +192,19 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
static void
e_minicard_label_realize (GnomeCanvasItem *item)
{
+ if (GNOME_CANVAS_ITEM_CLASS( parent_class )->realize)
+ (* GNOME_CANVAS_ITEM_CLASS( parent_class )->realize) (item);
+
+ e_canvas_item_request_reflow(item);
+
+ if (!item->canvas->aa)
+ {
+ }
+}
+
+void
+e_minicard_label_construct (GnomeCanvasItem *item)
+{
EMinicardLabel *e_minicard_label;
GnomeCanvasGroup *group;
static GdkFont *font = NULL;
@@ -206,9 +216,6 @@ e_minicard_label_realize (GnomeCanvasItem *item)
e_minicard_label = E_MINICARD_LABEL (item);
group = GNOME_CANVAS_GROUP( item );
- if (GNOME_CANVAS_ITEM_CLASS( parent_class )->realize)
- (* GNOME_CANVAS_ITEM_CLASS( parent_class )->realize) (item);
-
e_minicard_label->rect =
gnome_canvas_item_new( group,
gnome_canvas_rect_get_type(),
@@ -229,13 +236,6 @@ e_minicard_label_realize (GnomeCanvasItem *item)
"fill_color", "black",
NULL );
e_canvas_item_move_absolute(e_minicard_label->fieldname, 2, 1);
- if ( e_minicard_label->fieldname_text )
- {
- gnome_canvas_item_set( e_minicard_label->fieldname,
- "text", e_minicard_label->fieldname_text,
- NULL );
- g_free( e_minicard_label->fieldname_text );
- }
e_minicard_label->field =
gnome_canvas_item_new( group,
@@ -249,20 +249,8 @@ e_minicard_label_realize (GnomeCanvasItem *item)
"editable", TRUE,
NULL );
e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
- if ( e_minicard_label->field_text )
- {
- gnome_canvas_item_set( e_minicard_label->field,
- "text", e_minicard_label->field_text,
- NULL );
- g_free( e_minicard_label->field_text );
- }
e_canvas_item_request_reflow(item);
-
- if (!item->canvas->aa)
- {
- }
-
}
static void
@@ -379,49 +367,53 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event)
static void
e_minicard_label_resize_children(EMinicardLabel *e_minicard_label)
{
- if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED ) {
- gnome_canvas_item_set( e_minicard_label->fieldname,
- "clip_width", (double) ( e_minicard_label->width / 2 - 4 ),
- NULL );
- gnome_canvas_item_set( e_minicard_label->field,
- "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ),
- NULL );
- }
+ gnome_canvas_item_set( e_minicard_label->fieldname,
+ "clip_width", (double) ( e_minicard_label->width / 2 - 4 ),
+ NULL );
+ gnome_canvas_item_set( e_minicard_label->field,
+ "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ),
+ NULL );
}
static void
e_minicard_label_reflow(GnomeCanvasItem *item, int flags)
{
EMinicardLabel *e_minicard_label = E_MINICARD_LABEL(item);
- if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED )
- {
- gint old_height;
- gdouble text_height;
- old_height = e_minicard_label->height;
+
+ gint old_height;
+ gdouble text_height;
+ old_height = e_minicard_label->height;
- gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname),
- "text_height", &text_height,
- NULL);
+ gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname),
+ "text_height", &text_height,
+ NULL);
- e_minicard_label->height = text_height;
+ e_minicard_label->height = text_height;
- gtk_object_get(GTK_OBJECT(e_minicard_label->field),
- "text_height", &text_height,
- NULL);
+ gtk_object_get(GTK_OBJECT(e_minicard_label->field),
+ "text_height", &text_height,
+ NULL);
- if (e_minicard_label->height < text_height)
- e_minicard_label->height = text_height;
- e_minicard_label->height += 3;
+ if (e_minicard_label->height < text_height)
+ e_minicard_label->height = text_height;
+ e_minicard_label->height += 3;
- gnome_canvas_item_set( e_minicard_label->rect,
- "x2", (double) e_minicard_label->width - 1,
- "y2", (double) e_minicard_label->height - 1,
- NULL );
- e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
+ gnome_canvas_item_set( e_minicard_label->rect,
+ "x2", (double) e_minicard_label->width - 1,
+ "y2", (double) e_minicard_label->height - 1,
+ NULL );
+ e_canvas_item_move_absolute(e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1);
- if (old_height != e_minicard_label->height)
- e_canvas_item_request_parent_reflow(item);
-
- }
+ if (old_height != e_minicard_label->height)
+ e_canvas_item_request_parent_reflow(item);
}
+
+GnomeCanvasItem *
+e_minicard_label_new(GnomeCanvasGroup *parent)
+{
+ GnomeCanvasItem *item = gnome_canvas_item_new(parent, e_minicard_label_get_type(), NULL);
+ e_minicard_label_construct(item);
+ return item;
+}
+
diff --git a/widgets/e-minicard/e-minicard-label.h b/widgets/e-minicard/e-minicard-label.h
index b439c53f9d..1790414a54 100644
--- a/widgets/e-minicard/e-minicard-label.h
+++ b/widgets/e-minicard/e-minicard-label.h
@@ -60,8 +60,6 @@ struct _EMinicardLabel
GnomeCanvasItem *fieldname;
GnomeCanvasItem *field;
GnomeCanvasItem *rect;
- char *fieldname_text;
- char *field_text;
gboolean has_focus;
};
@@ -73,6 +71,8 @@ struct _EMinicardLabelClass
GtkType e_minicard_label_get_type (void);
+GnomeCanvasItem *e_minicard_label_new(GnomeCanvasGroup *parent);
+void e_minicard_label_construct (GnomeCanvasItem *item);
#ifdef __cplusplus
}
diff --git a/widgets/e-minicard/e-minicard.c b/widgets/e-minicard/e-minicard.c
index 79668b6507..b7b9a4c10e 100644
--- a/widgets/e-minicard/e-minicard.c
+++ b/widgets/e-minicard/e-minicard.c
@@ -24,6 +24,7 @@
#include "e-minicard.h"
#include "e-minicard-label.h"
#include "e-text.h"
+#include "e-table-text-model.h"
#include "e-canvas.h"
#include "e-util.h"
#include "e-canvas-utils.h"
@@ -37,6 +38,7 @@ static void e_minicard_unrealize (GnomeCanvasItem *item);
static void e_minicard_reflow ( GnomeCanvasItem *item, int flags );
static void e_minicard_resize_children( EMinicard *e_minicard );
+static void remodel( EMinicard *e_minicard );
static GnomeCanvasGroupClass *parent_class = NULL;
@@ -46,7 +48,9 @@ enum {
ARG_WIDTH,
ARG_HEIGHT,
ARG_HAS_FOCUS,
- ARG_CARD
+ ARG_CARD,
+ ARG_MODEL,
+ ARG_ROW
};
GtkType
@@ -93,6 +97,10 @@ e_minicard_class_init (EMinicardClass *klass)
GTK_ARG_READWRITE, ARG_HAS_FOCUS);
gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT,
GTK_ARG_READWRITE, ARG_CARD);
+ gtk_object_add_arg_type ("EMinicard::model", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_MODEL);
+ gtk_object_add_arg_type ("EMinicard::row", GTK_TYPE_INT,
+ GTK_ARG_READWRITE, ARG_ROW);
object_class->set_arg = e_minicard_set_arg;
object_class->get_arg = e_minicard_get_arg;
@@ -113,6 +121,9 @@ e_minicard_init (EMinicard *minicard)
minicard->width = 10;
minicard->height = 10;
minicard->has_focus = FALSE;
+
+ minicard->model = NULL;
+ minicard->row = 0;
e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard), e_minicard_reflow);
}
@@ -131,7 +142,8 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
if (e_minicard->width != GTK_VALUE_DOUBLE (*arg)) {
e_minicard->width = GTK_VALUE_DOUBLE (*arg);
e_minicard_resize_children(e_minicard);
- e_canvas_item_request_reflow(item);
+ if ( GTK_OBJECT_FLAGS( e_minicard ) & GNOME_CANVAS_ITEM_REALIZED )
+ e_canvas_item_request_reflow(item);
}
break;
case ARG_HAS_FOCUS:
@@ -148,13 +160,23 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
}
}
else
- e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard));
+ e_canvas_item_grab_focus(item);
break;
case ARG_CARD:
- /* e_minicard->card = GTK_VALUE_POINTER (*arg);
+ /* e_minicard->card = GTK_VALUE_OBJECT (*arg);
_update_card(e_minicard);
gnome_canvas_item_request_update (item);*/
break;
+ case ARG_MODEL:
+ e_minicard->model = E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg));
+ remodel(e_minicard);
+ e_canvas_item_request_reflow(item);
+ break;
+ case ARG_ROW:
+ e_minicard->row = GTK_VALUE_INT (*arg);
+ remodel(e_minicard);
+ e_canvas_item_request_reflow(item);
+ break;
}
}
@@ -176,8 +198,14 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
GTK_VALUE_ENUM (*arg) = e_minicard->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE;
break;
case ARG_CARD:
- /* GTK_VALUE_POINTER (*arg) = e_minicard->card; */
+ /* GTK_VALUE_OBJECT (*arg) = e_minicard->card; */
break;
+ case ARG_MODEL:
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard->model);
+ break;
+ case ARG_ROW:
+ GTK_VALUE_INT (*arg) = e_minicard->row;
+ break;
default:
arg->type = GTK_TYPE_INVALID;
break;
@@ -229,41 +257,46 @@ e_minicard_realize (GnomeCanvasItem *item)
"text", "Chris Lahey",
NULL );
e_canvas_item_move_absolute(e_minicard->header_text, 6, 6);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4.0,
+ "fieldname", "Email:",
+ "field", "clahey@address.com",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Full Name:",
+ "field", "Christopher James Lahey",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- if ( rand() % 2 ) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4,
- "fieldname", "Full Name:",
- "field", "Christopher James Lahey",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
-
- if (rand() % 2) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4,
- "fieldname", "Address:",
- "field", "100 Main St\nHome town, USA",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
-
- if (rand() % 2) {
- new_item = gnome_canvas_item_new( group,
- e_minicard_label_get_type(),
- "width", e_minicard->width - 4.0,
- "fieldname", "Email:",
- "field", "clahey@address.com",
- NULL );
- e_minicard->fields = g_list_append( e_minicard->fields, new_item);
- e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
- }
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Street Address:",
+ "field", "100 Main St\nHome town, USA",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ new_item = e_minicard_label_new(group);
+ gnome_canvas_item_set( new_item,
+ "width", e_minicard->width - 4,
+ "fieldname", "Phone:",
+ "field", "000-0000",
+ NULL );
+ e_minicard->fields = g_list_append( e_minicard->fields, new_item);
+ e_canvas_item_move_absolute(new_item, 2, e_minicard->height);
+
+ remodel(e_minicard);
e_canvas_item_request_reflow(item);
-
+
if (!item->canvas->aa) {
}
}
@@ -384,6 +417,35 @@ e_minicard_resize_children( EMinicard *e_minicard )
}
static void
+remodel( EMinicard *e_minicard )
+{
+ GnomeCanvasGroup *group;
+
+ group = GNOME_CANVAS_GROUP( e_minicard );
+
+ if ( e_minicard->model ) {
+ gint column = 0;
+ GList *list = e_minicard->fields;
+ ETableTextModel *model;
+ for ( ; list; list = list->next, column++ ) {
+ ETableTextModel *model = e_table_text_model_new(e_minicard->model, e_minicard->row, column);
+ gnome_canvas_item_set(GNOME_CANVAS_ITEM(list->data),
+ "text_model", model,
+ NULL);
+ gtk_object_sink(GTK_OBJECT(model));
+ }
+ if ( e_minicard->header_text ) {
+ model = e_table_text_model_new(e_minicard->model, e_minicard->row, 1);
+ gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->header_text),
+ "model", model,
+ NULL);
+ gtk_object_sink(GTK_OBJECT(model));
+ }
+
+ }
+}
+
+static void
e_minicard_reflow( GnomeCanvasItem *item, int flags )
{
EMinicard *e_minicard = E_MINICARD(item);
@@ -391,7 +453,7 @@ e_minicard_reflow( GnomeCanvasItem *item, int flags )
GList *list;
gdouble text_height;
gint old_height;
-
+
old_height = e_minicard->height;
gtk_object_get( GTK_OBJECT( e_minicard->header_text ),
diff --git a/widgets/e-minicard/e-minicard.h b/widgets/e-minicard/e-minicard.h
index 3be80c1586..05d95a743e 100644
--- a/widgets/e-minicard/e-minicard.h
+++ b/widgets/e-minicard/e-minicard.h
@@ -22,6 +22,7 @@
#define __E_MINICARD_H__
#include <gnome.h>
+#include "e-table-model.h"
#ifdef __cplusplus
extern "C" {
@@ -36,6 +37,10 @@ extern "C" {
* --------------------------------------------------------------------------------
* width double RW width of the card
* height double R height of the card
+ * model ETableModel RW model to read from
+ * row int RW ETableModel row to read from
+ *
+ * Later:
* card ECard* RW Pointer to the ECard
*/
@@ -66,6 +71,10 @@ struct _EMinicard
GnomeCanvasItem *header_rect;
GnomeCanvasItem *header_text;
GList *fields; /* Of type GnomeCanvasItem. */
+
+ ETableModel *model;
+ int row;
+ guint needs_remodeling : 1;
gboolean has_focus;
diff --git a/widgets/e-minicard/test-minicard-label.c b/widgets/e-minicard/test-minicard-label.c
index 8da34e6f22..727d709925 100644
--- a/widgets/e-minicard/test-minicard-label.c
+++ b/widgets/e-minicard/test-minicard-label.c
@@ -21,6 +21,7 @@
#include <gnome.h>
#include "e-minicard-label.h"
+#include "e-canvas.h"
/* This is a horrible thing to do, but it is just a test. */
GnomeCanvasItem *label;
@@ -80,7 +81,7 @@ int main( int argc, char *argv[] )
gnome_init( "Minicard Label Test", VERSION, argc, argv);
app = gnome_app_new("Minicard Label Test", NULL);
- canvas = gnome_canvas_new();
+ canvas = e_canvas_new();
rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ),
gnome_canvas_rect_get_type(),
"x1", (double) 0,
@@ -89,15 +90,15 @@ int main( int argc, char *argv[] )
"y2", (double) 100,
"fill_color", "white",
NULL );
- label = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ),
- e_minicard_label_get_type(),
- "x", (double) 0,
- "y", (double) 0,
- "width", (double) 100,
- "height", (double) 100,
- "fieldname", "Full Name:",
- "field", "Christopher James Lahey",
- NULL );
+ label = e_minicard_label_new(gnome_canvas_root( GNOME_CANVAS( canvas ) ));
+ gnome_canvas_item_set( label,
+ "x", (double) 0,
+ "y", (double) 0,
+ "width", (double) 100,
+ "height", (double) 100,
+ "fieldname", "Full Name:",
+ "field", "Christopher James Lahey",
+ NULL );
gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ),
0, 0,
100, 100 );
diff --git a/widgets/e-table/.cvsignore b/widgets/e-table/.cvsignore
index 0963d457d9..ca61202868 100644
--- a/widgets/e-table/.cvsignore
+++ b/widgets/e-table/.cvsignore
@@ -5,3 +5,5 @@ Makefile.in
*.lo
*.la
table-test
+table-example-1
+table-example-2
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog
index 9b81185f1d..24500392b0 100644
--- a/widgets/e-table/ChangeLog
+++ b/widgets/e-table/ChangeLog
@@ -1,3 +1,23 @@
+2000-03-12 Christopher James Lahey <clahey@helixcode.com>
+
+ * e-table.c: Made this use an ECanvas. Fixed a bug where
+ e_table_new_from_spec_file was calling e_table_construct instead
+ of e_table_construct_from_spec_file.
+
+ * e-table-item.c, e-table-header-item.c, e-table-column-item.c:
+ Switched these to use GTK_TYPE_OBJECT and GTK_VALUE_OBJECT instead
+ of GTK_TYPE_POINTER and GTK_TYPE_OBJECT.
+
+ * e-cell-text.c: Got rid of a crashing bug.
+
+ * e-table-text-model.c, e-table-text-model.h: A new object which
+ is an e-text-model which uses an e-table-model for its data.
+
+ * Makefile.am: Added e-table-text-model.c and
+ e-table-text-model.h.
+
+ * .cvsignore: Added table-example-1 and table-example-2.
+
2000-03-08 Christopher James Lahey <clahey@helixcode.com>
* e-table.c: Changed the destroy function to disconnect from
diff --git a/widgets/e-table/Makefile.am b/widgets/e-table/Makefile.am
index a7d9c28d57..8780789977 100644
--- a/widgets/e-table/Makefile.am
+++ b/widgets/e-table/Makefile.am
@@ -46,7 +46,9 @@ libetable_a_SOURCES = \
e-table-subset.c \
e-table-subset.h \
e-table-subset-variable.c \
- e-table-subset-variable.h
+ e-table-subset-variable.h \
+ e-table-text-model.c \
+ e-table-text-model.h
noinst_PROGRAMS = \
table-test table-example-1 table-example-2
diff --git a/widgets/e-table/e-cell-text.c b/widgets/e-table/e-cell-text.c
index 191ac86023..422b27ff93 100644
--- a/widgets/e-table/e-cell-text.c
+++ b/widgets/e-table/e-cell-text.c
@@ -319,8 +319,8 @@ static void
ect_kill_view (ECellView *ecv)
{
ECellTextView *text_view = (ECellTextView *) ecv;
-
- g_free (text_view);
+
+ g_free(text_view);
}
/*
@@ -351,7 +351,11 @@ ect_unrealize (ECellView *ecv)
gdk_gc_unref (text_view->gc);
text_view->gc = NULL;
-
+
+ if ( text_view->edit ) {
+ ect_cancel_edit (text_view);
+ }
+
if (text_view->font)
gdk_font_unref (text_view->font);
diff --git a/widgets/e-table/e-table-column-item.c b/widgets/e-table/e-table-column-item.c
index 0616327a93..1138c4afe4 100644
--- a/widgets/e-table/e-table-column-item.c
+++ b/widgets/e-table/e-table-column-item.c
@@ -55,7 +55,7 @@ etci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_COLUMN:
- etci->etci = GTK_VALUE_POINTER (*arg);
+ etci->etci = GTK_VALUE_OBJECT (*arg);
break;
}
etci_update (item, NULL, NULL, 0);
@@ -159,7 +159,7 @@ etci_class_init (GtkObjectClass *object_class)
item_class->point = etci_point;
item_class->event = etci_event;
- gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_POINTER,
+ gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_OBJECT,
GTK_ARG_WRITABLE, ARG_TABLE_COLUMN);
}
diff --git a/widgets/e-table/e-table-header-item.c b/widgets/e-table/e-table-header-item.c
index e6001d24de..b079debb1a 100644
--- a/widgets/e-table/e-table-header-item.c
+++ b/widgets/e-table/e-table-header-item.c
@@ -191,7 +191,7 @@ ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_HEADER:
ethi_drop_table_header (ethi);
- ethi_add_table_header (ethi, GTK_VALUE_POINTER (*arg));
+ ethi_add_table_header (ethi, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg)));
break;
case ARG_TABLE_X:
@@ -990,7 +990,7 @@ ethi_class_init (GtkObjectClass *object_class)
item_class->point = ethi_point;
item_class->event = ethi_event;
- gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_POINTER,
+ gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_OBJECT,
GTK_ARG_WRITABLE, ARG_TABLE_HEADER);
gtk_object_add_arg_type ("ETableHeaderItem::x", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_TABLE_X);
diff --git a/widgets/e-table/e-table-item.c b/widgets/e-table/e-table-item.c
index 095a14ea90..59df09e5bb 100644
--- a/widgets/e-table/e-table-item.c
+++ b/widgets/e-table/e-table-item.c
@@ -545,12 +545,12 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_HEADER:
eti_remove_header_model (eti);
- eti_add_header_model (eti, GTK_VALUE_POINTER (*arg));
+ eti_add_header_model (eti, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg)));
break;
case ARG_TABLE_MODEL:
eti_remove_table_model (eti);
- eti_add_table_model (eti, GTK_VALUE_POINTER (*arg));
+ eti_add_table_model (eti, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg)));
break;
case ARG_LENGHT_THRESHOLD:
@@ -1137,9 +1137,9 @@ eti_class_init (GtkObjectClass *object_class)
eti_class->row_selection = eti_row_selection;
- gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_POINTER,
+ gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_OBJECT,
GTK_ARG_WRITABLE, ARG_TABLE_HEADER);
- gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_POINTER,
+ gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_OBJECT,
GTK_ARG_WRITABLE, ARG_TABLE_MODEL);
gtk_object_add_arg_type ("ETableItem::drawgrid", GTK_TYPE_BOOL,
GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID);
diff --git a/widgets/e-table/e-table-text-model.c b/widgets/e-table/e-table-text-model.c
new file mode 100644
index 0000000000..69ffdc3568
--- /dev/null
+++ b/widgets/e-table/e-table-text-model.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETableTextModel - Text item model for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#include <config.h>
+#include <ctype.h>
+#include "e-table-text-model.h"
+
+static void e_table_text_model_class_init (ETableTextModelClass *class);
+static void e_table_text_model_init (ETableTextModel *model);
+static void e_table_text_model_destroy (GtkObject *object);
+
+static gchar *e_table_text_model_get_text(ETextModel *model);
+static void e_table_text_model_set_text(ETextModel *model, gchar *text);
+static void e_table_text_model_insert(ETextModel *model, gint postion, gchar *text);
+static void e_table_text_model_insert_length(ETextModel *model, gint postion, gchar *text, gint length);
+static void e_table_text_model_delete(ETextModel *model, gint postion, gint length);
+
+static GtkObject *parent_class;
+
+
+
+/**
+ * e_table_text_model_get_type:
+ * @void:
+ *
+ * Registers the &ETableTextModel class if necessary, and returns the type ID
+ * associated to it.
+ *
+ * Return value: The type ID of the &ETableTextModel class.
+ **/
+GtkType
+e_table_text_model_get_type (void)
+{
+ static GtkType model_type = 0;
+
+ if (!model_type) {
+ GtkTypeInfo model_info = {
+ "ETableTextModel",
+ sizeof (ETableTextModel),
+ sizeof (ETableTextModelClass),
+ (GtkClassInitFunc) e_table_text_model_class_init,
+ (GtkObjectInitFunc) e_table_text_model_init,
+ NULL, /* reserved_1 */
+ NULL, /* reserved_2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ model_type = gtk_type_unique (e_text_model_get_type (), &model_info);
+ }
+
+ return model_type;
+}
+
+/* Class initialization function for the text item */
+static void
+e_table_text_model_class_init (ETableTextModelClass *klass)
+{
+ GtkObjectClass *object_class;
+ ETextModelClass *model_class;
+
+ object_class = (GtkObjectClass *) klass;
+ model_class = (ETextModelClass *) klass;
+
+ parent_class = gtk_type_class (e_text_model_get_type ());
+
+ model_class->get_text = e_table_text_model_get_text;
+ model_class->set_text = e_table_text_model_set_text;
+ model_class->insert = e_table_text_model_insert;
+ model_class->insert_length = e_table_text_model_insert_length;
+ model_class->delete = e_table_text_model_delete;
+
+ object_class->destroy = e_table_text_model_destroy;
+}
+
+/* Object initialization function for the text item */
+static void
+e_table_text_model_init (ETableTextModel *model)
+{
+ model->model = NULL;
+ model->row = 0;
+ model->model_col = 0;
+ model->cell_changed_signal_id = 0;
+ model->row_changed_signal_id = 0;
+}
+
+/* Destroy handler for the text item */
+static void
+e_table_text_model_destroy (GtkObject *object)
+{
+ ETableTextModel *model;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (object));
+
+ model = E_TABLE_TEXT_MODEL (object);
+
+ if (model->cell_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(model->model),
+ model->cell_changed_signal_id);
+
+ if (model->row_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(model->model),
+ model->row_changed_signal_id);
+
+ if (model->model)
+ gtk_object_unref(GTK_OBJECT(model->model));
+
+ if (GTK_OBJECT_CLASS (parent_class)->destroy)
+ (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+static gchar *
+e_table_text_model_get_text(ETextModel *text_model)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model )
+ return (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ else
+ return "";
+}
+
+static void
+e_table_text_model_set_text(ETextModel *text_model, gchar *text)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model )
+ e_table_model_set_value_at(model->model, model->model_col, model->row, (void *) text);
+}
+
+static void
+e_table_text_model_insert(ETextModel *text_model, gint position, gchar *text)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%s%s", position, temp, text, temp + position);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+e_table_text_model_insert_length(ETextModel *text_model, gint position, gchar *text, gint length)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%.*s%s", position, temp, length, text, temp + position);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+e_table_text_model_delete(ETextModel *text_model, gint position, gint length)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%s", position, temp, temp + position + length);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+cell_changed(ETableModel *table_model, int model_col, int row, ETableTextModel *model)
+{
+ if (model->model_col == model_col &&
+ model->row == row)
+ e_text_model_changed(E_TEXT_MODEL(model));
+}
+
+static void
+row_changed(ETableModel *table_model, int row, ETableTextModel *model)
+{
+ if (model->row == row)
+ e_text_model_changed(E_TEXT_MODEL(model));
+}
+
+ETableTextModel *
+e_table_text_model_new(ETableModel *table_model, int row, int model_col)
+{
+ ETableTextModel *model = gtk_type_new (e_table_text_model_get_type ());
+ model->model = table_model;
+ if ( model->model ) {
+ gtk_object_ref(GTK_OBJECT(model->model));
+ model->cell_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(model->model),
+ "model_cell_changed",
+ GTK_SIGNAL_FUNC(cell_changed),
+ model);
+ model->row_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(model->model),
+ "model_row_changed",
+ GTK_SIGNAL_FUNC(row_changed),
+ model);
+ }
+ model->row = row;
+ model->model_col = model_col;
+ return model;
+}
+
diff --git a/widgets/e-table/e-table-text-model.h b/widgets/e-table/e-table-text-model.h
new file mode 100644
index 0000000000..43c82b6bcc
--- /dev/null
+++ b/widgets/e-table/e-table-text-model.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETableTextModel - Text item for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#ifndef E_TABLE_TEXT_MODEL_H
+#define E_TABLE_TEXT_MODEL_H
+
+#include <gnome.h>
+#include "e-text-model.h"
+#include "e-table-model.h"
+
+
+BEGIN_GNOME_DECLS
+
+#define E_TYPE_TABLE_TEXT_MODEL (e_table_text_model_get_type ())
+#define E_TABLE_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TABLE_TEXT_MODEL, ETableTextModel))
+#define E_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TABLE_TEXT_MODEL, ETableTextModelClass))
+#define E_IS_TABLE_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TABLE_TEXT_MODEL))
+#define E_IS_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TABLE_TEXT_MODEL))
+
+typedef struct _ETableTextModel ETableTextModel;
+typedef struct _ETableTextModelClass ETableTextModelClass;
+
+struct _ETableTextModel {
+ ETextModel parent;
+
+ ETableModel *model;
+ int row;
+ int model_col;
+
+ int cell_changed_signal_id;
+ int row_changed_signal_id;
+};
+
+struct _ETableTextModelClass {
+ ETextModelClass parent_class;
+
+};
+
+
+/* Standard Gtk function */
+GtkType e_table_text_model_get_type (void);
+ETableTextModel *e_table_text_model_new(ETableModel *table_model, int row, int model_col);
+
+END_GNOME_DECLS
+
+#endif
diff --git a/widgets/e-table/e-table.c b/widgets/e-table/e-table.c
index 36f7d5a776..ed1260fa44 100644
--- a/widgets/e-table/e-table.c
+++ b/widgets/e-table/e-table.c
@@ -675,7 +675,7 @@ et_table_cell_changed (ETableModel *table_model, int view_col, int row, ETable *
static void
e_table_setup_table (ETable *e_table, ETableHeader *full_header, ETableHeader *header, ETableModel *model, xmlNode *xml_grouping)
{
- e_table->table_canvas = GNOME_CANVAS(gnome_canvas_new ());
+ e_table->table_canvas = GNOME_CANVAS(e_canvas_new ());
gtk_signal_connect (
GTK_OBJECT (e_table->table_canvas), "size_allocate",
GTK_SIGNAL_FUNC (table_canvas_size_allocate), e_table);
@@ -809,7 +809,7 @@ e_table_new_from_spec_file (ETableHeader *full_header, ETableModel *etm, const c
e_table = gtk_type_new (e_table_get_type ());
- e_table_construct (e_table, full_header, etm, filename);
+ e_table_construct_from_spec_file (e_table, full_header, etm, filename);
return (GtkWidget *) e_table;
}
diff --git a/widgets/e-text/Makefile.am b/widgets/e-text/Makefile.am
index d0ee56e5e1..60963c9727 100644
--- a/widgets/e-text/Makefile.am
+++ b/widgets/e-text/Makefile.am
@@ -10,13 +10,15 @@ libetext_a_SOURCES = \
e-text-event-processor.c \
e-text-event-processor.h \
e-text-event-processor-emacs-like.c \
- e-text-event-processor-emacs-like.h
+ e-text-event-processor-emacs-like.h \
+ e-text-model.c \
+ e-text-model.h
noinst_PROGRAMS = \
- e-text-test
+ e-text-test
e_text_test_SOURCES = \
- e-text-test.c
+ e-text-test.c
e_text_test_LDADD = \
libetext.a \
diff --git a/widgets/e-text/e-text-model.c b/widgets/e-text/e-text-model.c
new file mode 100644
index 0000000000..d571e87791
--- /dev/null
+++ b/widgets/e-text/e-text-model.c
@@ -0,0 +1,241 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETextModel - Text item model for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#include <config.h>
+#include <ctype.h>
+#include "e-text-model.h"
+
+enum {
+ E_TEXT_MODEL_CHANGED,
+ E_TEXT_MODEL_LAST_SIGNAL
+};
+
+static guint e_text_model_signals[E_TEXT_MODEL_LAST_SIGNAL] = { 0 };
+
+static void e_text_model_class_init (ETextModelClass *class);
+static void e_text_model_init (ETextModel *model);
+static void e_text_model_destroy (GtkObject *object);
+
+static gchar *e_text_model_real_get_text(ETextModel *model);
+static void e_text_model_real_set_text(ETextModel *model, gchar *text);
+static void e_text_model_real_insert(ETextModel *model, gint postion, gchar *text);
+static void e_text_model_real_insert_length(ETextModel *model, gint postion, gchar *text, gint length);
+static void e_text_model_real_delete(ETextModel *model, gint postion, gint length);
+
+static GtkObject *parent_class;
+
+
+
+/**
+ * e_text_model_get_type:
+ * @void:
+ *
+ * Registers the &ETextModel class if necessary, and returns the type ID
+ * associated to it.
+ *
+ * Return value: The type ID of the &ETextModel class.
+ **/
+GtkType
+e_text_model_get_type (void)
+{
+ static GtkType model_type = 0;
+
+ if (!model_type) {
+ GtkTypeInfo model_info = {
+ "ETextModel",
+ sizeof (ETextModel),
+ sizeof (ETextModelClass),
+ (GtkClassInitFunc) e_text_model_class_init,
+ (GtkObjectInitFunc) e_text_model_init,
+ NULL, /* reserved_1 */
+ NULL, /* reserved_2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ model_type = gtk_type_unique (gtk_object_get_type (), &model_info);
+ }
+
+ return model_type;
+}
+
+/* Class initialization function for the text item */
+static void
+e_text_model_class_init (ETextModelClass *klass)
+{
+ GtkObjectClass *object_class;
+
+ object_class = (GtkObjectClass *) klass;
+
+ parent_class = gtk_type_class (gtk_object_get_type ());
+
+ e_text_model_signals[E_TEXT_MODEL_CHANGED] =
+ gtk_signal_new ("changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (ETextModelClass, changed),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+
+ gtk_object_class_add_signals (object_class, e_text_model_signals, E_TEXT_MODEL_LAST_SIGNAL);
+
+ klass->changed = NULL;
+ klass->get_text = e_text_model_real_get_text;
+ klass->set_text = e_text_model_real_set_text;
+ klass->insert = e_text_model_real_insert;
+ klass->insert_length = e_text_model_real_insert_length;
+ klass->delete = e_text_model_real_delete;
+
+ object_class->destroy = e_text_model_destroy;
+}
+
+/* Object initialization function for the text item */
+static void
+e_text_model_init (ETextModel *model)
+{
+ model->text = NULL;
+}
+
+/* Destroy handler for the text item */
+static void
+e_text_model_destroy (GtkObject *object)
+{
+ ETextModel *model;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (object));
+
+ model = E_TEXT_MODEL (object);
+
+ if (model->text)
+ g_free (model->text);
+
+ if (GTK_OBJECT_CLASS (parent_class)->destroy)
+ (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+
+static gchar *
+e_text_model_real_get_text(ETextModel *model)
+{
+ return model->text;
+}
+
+static void
+e_text_model_real_set_text(ETextModel *model, gchar *text)
+{
+ if (model->text)
+ g_free(model->text);
+ model->text = g_strdup(text);
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_insert(ETextModel *model, gint position, gchar *text)
+{
+ gchar *temp = g_strdup_printf("%.*s%s%s", position, model->text, text, model->text + position);
+ if (model->text)
+ g_free(model->text);
+ model->text = temp;
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_insert_length(ETextModel *model, gint position, gchar *text, gint length)
+{
+ gchar *temp = g_strdup_printf("%.*s%.*s%s", position, model->text, length, text, model->text + position);
+ if (model->text)
+ g_free(model->text);
+ model->text = temp;
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_delete(ETextModel *model, gint position, gint length)
+{
+ memmove(model->text + position, model->text + position + length, strlen(model->text + position + length) + 1);
+ e_text_model_changed(model);
+}
+
+void
+e_text_model_changed(ETextModel *model)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ gtk_signal_emit (GTK_OBJECT (model),
+ e_text_model_signals [E_TEXT_MODEL_CHANGED]);
+}
+
+gchar *
+e_text_model_get_text(ETextModel *model)
+{
+ g_return_val_if_fail (model != NULL, NULL);
+ g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL);
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text )
+ return E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text(model);
+ else
+ return "";
+}
+
+void
+e_text_model_set_text(ETextModel *model, gchar *text)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text(model, text);
+}
+
+void
+e_text_model_insert(ETextModel *model, gint position, gchar *text)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert(model, position, text);
+}
+
+void
+e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length(model, position, text, length);
+}
+
+void
+e_text_model_delete(ETextModel *model, gint position, gint length)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete(model, position, length);
+}
+
+ETextModel *
+e_text_model_new(void)
+{
+ ETextModel *model = gtk_type_new (e_text_model_get_type ());
+ model->text = g_strdup("");
+ return model;
+}
diff --git a/widgets/e-text/e-text-model.h b/widgets/e-text/e-text-model.h
new file mode 100644
index 0000000000..5b15ccb117
--- /dev/null
+++ b/widgets/e-text/e-text-model.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETextModel - Text item for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#ifndef E_TEXT_MODEL_H
+#define E_TEXT_MODEL_H
+
+#include <gnome.h>
+
+
+BEGIN_GNOME_DECLS
+
+#define E_TYPE_TEXT_MODEL (e_text_model_get_type ())
+#define E_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT_MODEL, ETextModel))
+#define E_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT_MODEL, ETextModelClass))
+#define E_IS_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT_MODEL))
+#define E_IS_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT_MODEL))
+
+typedef struct _ETextModel ETextModel;
+typedef struct _ETextModelClass ETextModelClass;
+
+struct _ETextModel {
+ GtkObject item;
+
+ char *text; /* Text to display */
+ int length;
+};
+
+struct _ETextModelClass {
+ GtkObjectClass parent_class;
+
+ /* Signal */
+ void (* changed) (ETextModel *model);
+
+ /* Virtual methods */
+ char *(* get_text) (ETextModel *model);
+ void (* set_text) (ETextModel *model, gchar *text);
+ void (* insert) (ETextModel *model, gint position, gchar *text);
+ void (* insert_length) (ETextModel *model, gint position, gchar *text, gint length);
+ void (* delete) (ETextModel *model, gint position, gint length);
+};
+
+
+/* Standard Gtk function */
+GtkType e_text_model_get_type (void);
+ETextModel *e_text_model_new(void);
+
+void e_text_model_changed(ETextModel *model);
+gchar *e_text_model_get_text(ETextModel *model);
+void e_text_model_set_text(ETextModel *model, gchar *text);
+void e_text_model_insert(ETextModel *model, gint position, gchar *text);
+void e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length);
+void e_text_model_delete(ETextModel *model, gint position, gint length);
+
+
+END_GNOME_DECLS
+
+#endif
diff --git a/widgets/e-text/e-text.c b/widgets/e-text/e-text.c
index ca41dc1d96..85950f149a 100644
--- a/widgets/e-text/e-text.c
+++ b/widgets/e-text/e-text.c
@@ -52,6 +52,7 @@ struct line {
/* Object argument IDs */
enum {
ARG_0,
+ ARG_MODEL,
ARG_TEXT,
ARG_X,
ARG_Y,
@@ -117,6 +118,8 @@ static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand
static void e_text_get_selection(EText *text, GdkAtom selection, guint32 time);
static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length);
+static void e_text_text_model_changed(ETextModel *model, EText *text);
+
static GtkWidget *e_text_get_invisible(EText *text);
static void _selection_clear_event (GtkInvisible *invisible,
GdkEventSelection *event,
@@ -133,6 +136,7 @@ static void _selection_received (GtkInvisible *invisible,
static ETextSuckFont *e_suck_font (GdkFont *font);
static void e_suck_font_free (ETextSuckFont *suckfont);
+static void e_text_free_lines(EText *text);
static GnomeCanvasItemClass *parent_class;
@@ -203,7 +207,9 @@ e_text_class_init (ETextClass *klass)
gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL);
-
+
+ gtk_object_add_arg_type ("EText::model",
+ GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL);
gtk_object_add_arg_type ("EText::text",
GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT);
gtk_object_add_arg_type ("EText::x",
@@ -285,6 +291,16 @@ e_text_class_init (ETextClass *klass)
static void
e_text_init (EText *text)
{
+ text->text = NULL;
+ text->model = e_text_model_new();
+ gtk_object_ref(GTK_OBJECT(text->model));
+ gtk_object_sink(GTK_OBJECT(text->model));
+ text->model_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(text->model),
+ "changed",
+ GTK_SIGNAL_FUNC(e_text_text_model_changed),
+ text);
+
text->x = 0.0;
text->y = 0.0;
text->anchor = GTK_ANCHOR_CENTER;
@@ -348,8 +364,12 @@ e_text_destroy (GtkObject *object)
text = E_TEXT (object);
- if (text->text)
- g_free (text->text);
+ if (text->model_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(text->model),
+ text->model_changed_signal_id);
+
+ if (text->model)
+ gtk_object_unref(GTK_OBJECT(text->model));
if (text->tep)
gtk_object_unref (GTK_OBJECT(text->tep));
@@ -374,6 +394,15 @@ e_text_destroy (GtkObject *object)
}
static void
+e_text_text_model_changed (ETextModel *model, EText *text)
+{
+ text->text = e_text_model_get_text(model);
+ e_text_free_lines(text);
+ text->needs_split_into_lines = 1;
+ e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
+}
+
+static void
get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2)
{
GnomeCanvasItem *item;
@@ -663,8 +692,6 @@ split_into_lines (EText *text)
/* Free old array of lines */
e_text_free_lines(text);
- text->num_lines = 0;
-
if (!text->text)
return;
@@ -870,16 +897,31 @@ e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
have_pixel = FALSE;
switch (arg_id) {
- case ARG_TEXT:
- if (text->text)
- g_free (text->text);
+ case ARG_MODEL:
+ if ( text->model_changed_signal_id )
+ gtk_signal_disconnect(GTK_OBJECT(text->model),
+ text->model_changed_signal_id);
+ gtk_object_unref(GTK_OBJECT(text->model));
+ text->model = E_TEXT_MODEL(GTK_VALUE_OBJECT (*arg));
+ gtk_object_ref(GTK_OBJECT(text->model));
+
+ text->model_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(text->model),
+ "changed",
+ GTK_SIGNAL_FUNC(e_text_text_model_changed),
+ text);
- text->text = g_strdup (GTK_VALUE_STRING (*arg));
e_text_free_lines(text);
+ text->text = e_text_model_get_text(text->model);
+
text->needs_split_into_lines = 1;
needs_reflow = 1;
break;
+ case ARG_TEXT:
+ e_text_model_set_text(text->model, GTK_VALUE_STRING (*arg));
+ break;
+
case ARG_X:
text->x = GTK_VALUE_DOUBLE (*arg);
text->needs_recalc_bounds = 1;
@@ -1134,6 +1176,10 @@ e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
text = E_TEXT (object);
switch (arg_id) {
+ case ARG_MODEL:
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->model);
+ break;
+
case ARG_TEXT:
GTK_VALUE_STRING (*arg) = g_strdup (text->text);
break;
@@ -1253,10 +1299,36 @@ e_text_reflow (GnomeCanvasItem *item, int flags)
text->needs_calc_line_widths = 1;
}
if ( text->needs_calc_line_widths ) {
+ int x;
+ int i;
+ struct line *lines;
calc_line_widths(text);
text->needs_calc_line_widths = 0;
text->needs_calc_height = 1;
text->needs_redraw = 1;
+
+ lines = text->lines;
+ if ( !lines )
+ return;
+
+ for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) {
+ if (lines->text - text->text > text->selection_end) {
+ break;
+ }
+ }
+ lines --;
+ x = gdk_text_width(text->font,
+ lines->text,
+ text->selection_end - (lines->text - text->text));
+
+
+ if (x < text->xofs_edit) {
+ text->xofs_edit = x;
+ }
+
+ if (2 + x - text->clip_width > text->xofs_edit) {
+ text->xofs_edit = 2 + x - text->clip_width;
+ }
}
if ( text->needs_calc_height ) {
calc_height (text);
@@ -1489,8 +1561,10 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
return;
lines = text->lines;
- if ( !lines )
- return;
+ if ( !lines ) {
+ text->needs_split_into_lines = 1;
+ e_canvas_item_request_reflow (item);
+ }
clip_rect = NULL;
if (text->clip) {
@@ -2159,6 +2233,7 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
gtk_widget_destroy (text->tooltip_window);
text->tooltip_window = NULL;
}
+#if 0
if ((!text->editing)
&& text->editable
&& event->type == GDK_BUTTON_RELEASE
@@ -2177,6 +2252,13 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
&e_tep_event);
e_tep_event.type = GDK_BUTTON_RELEASE;
}
+#else
+ if ((!text->editing)
+ && text->editable
+ && event->button.button == 1) {
+ gnome_canvas_item_grab_focus (item);
+ }
+#endif
if (text->editing) {
GdkEventButton button = event->button;
e_tep_event.button.time = button.time;
@@ -2346,33 +2428,21 @@ _get_position(EText *text, ETextEventProcessorCommand *command)
static void
_delete_selection(EText *text)
{
- gint length = strlen(text->text);
- if (text->selection_end == text->selection_start)
- return;
- if (text->selection_end < text->selection_start) {
- text->selection_end ^= text->selection_start;
- text->selection_start ^= text->selection_end;
- text->selection_end ^= text->selection_start;
+ if ( text->selection_start < text->selection_end ) {
+ e_text_model_delete(text->model, text->selection_start, text->selection_end - text->selection_start);
+ text->selection_end = text->selection_start;
+ } else {
+ e_text_model_delete(text->model, text->selection_end, text->selection_start - text->selection_end);
+ text->selection_start = text->selection_end;
}
- memmove( text->text + text->selection_start,
- text->text + text->selection_end,
- length - text->selection_end + 1 );
- length -= text->selection_end - text->selection_start;
- text->selection_end = text->selection_start;
}
static void
_insert(EText *text, char *string, int value)
{
if (value > 0) {
- char *temp;
- gint length = strlen(text->text);
- temp = g_new(gchar, length + value + 1);
- strncpy(temp, text->text, text->selection_start);
- strncpy(temp + text->selection_start, string, value);
- strcpy(temp + text->selection_start + value, text->text + text->selection_start);
- g_free(text->text);
- text->text = temp;
+ e_text_model_insert_length(text->model, text->selection_start, string, value);
+
text->selection_start += value;
text->selection_end = text->selection_start;
}
@@ -2406,9 +2476,6 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp
text->selection_end = _get_position(text, command);
}
_delete_selection(text);
- e_text_free_lines(text);
- text->needs_split_into_lines = 1;
- e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
if (text->timer) {
g_timer_reset(text->timer);
}
@@ -2419,9 +2486,6 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp
_delete_selection(text);
}
_insert(text, command->string, command->value);
- e_text_free_lines(text);
- text->needs_split_into_lines = 1;
- e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
if (text->timer) {
g_timer_reset(text->timer);
}
diff --git a/widgets/e-text/e-text.h b/widgets/e-text/e-text.h
index 52fb951bc2..a4bc06d820 100644
--- a/widgets/e-text/e-text.h
+++ b/widgets/e-text/e-text.h
@@ -21,6 +21,7 @@
#include <gnome.h>
#include "e-text-event-processor.h"
+#include "e-text-model.h"
BEGIN_GNOME_DECLS
@@ -101,6 +102,9 @@ struct _ETextSuckFont {
struct _EText {
GnomeCanvasItem item;
+
+ ETextModel *model;
+ gint model_changed_signal_id;
char *text; /* Text to display */
gpointer lines; /* Text split into lines (private field) */
diff --git a/widgets/misc/e-canvas.c b/widgets/misc/e-canvas.c
index 68f1b0f9f3..76b9286156 100644
--- a/widgets/misc/e-canvas.c
+++ b/widgets/misc/e-canvas.c
@@ -93,7 +93,7 @@ e_canvas_class_init (ECanvasClass *klass)
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ECanvasClass, reflow),
- gtk_marshal_NONE__INT_INT,
+ gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, e_canvas_signals, LAST_SIGNAL);
@@ -321,39 +321,39 @@ e_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event)
static void
-e_canvas_item_invoke_update (GnomeCanvasItem *item, int flags)
+e_canvas_item_invoke_reflow (GnomeCanvasItem *item, int flags)
{
GnomeCanvasGroup *group;
GList *list;
GnomeCanvasItem *child;
- if ( ! gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::descendent_needs_reflow") )
- return;
if ( GNOME_IS_CANVAS_GROUP( item ) ) {
group = GNOME_CANVAS_GROUP( item );
for ( list = group->item_list; list; list = list->next ) {
child = GNOME_CANVAS_ITEM(list->data);
- e_canvas_item_invoke_update(child, flags);
+ if ( child->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW )
+ e_canvas_item_invoke_reflow(child, flags);
}
}
-
- if ( gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::needs_reflow") ) {
+
+ if ( item->object.flags & E_CANVAS_ITEM_NEEDS_REFLOW ) {
ECanvasItemReflowFunc func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::reflow_callback");
if ( func )
func(item, flags);
}
- gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::needs_reflow", (gpointer) 0);
- gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::descendent_needs_reflow", (gpointer) 0);
+ item->object.flags &= ~E_CANVAS_ITEM_NEEDS_REFLOW;
+ item->object.flags &= ~E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW;
}
static void
-do_update (ECanvas *canvas)
+do_reflow (ECanvas *canvas)
{
- e_canvas_item_invoke_update (GNOME_CANVAS(canvas)->root, 0);
+ if ( GNOME_CANVAS(canvas)->root->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW )
+ e_canvas_item_invoke_reflow (GNOME_CANVAS(canvas)->root, 0);
}
-/* Idle handler for the canvas. It deals with pending updates and redraws. */
+/* Idle handler for the e-canvas. It deals with pending reflows. */
static gint
idle_handler (gpointer data)
{
@@ -362,7 +362,7 @@ idle_handler (gpointer data)
GDK_THREADS_ENTER ();
canvas = E_CANVAS (data);
- do_update (canvas);
+ do_reflow (canvas);
/* Reset idle id */
canvas->idle_id = 0;
@@ -388,9 +388,10 @@ add_idle (ECanvas *canvas)
static void
e_canvas_item_descendent_needs_reflow (GnomeCanvasItem *item)
{
- if ( gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::descendent_needs_reflow") )
+ if ( item->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW )
return;
- gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::descendent_needs_reflow", (gpointer) 1);
+
+ item->object.flags |= E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW;
if ( item->parent )
e_canvas_item_descendent_needs_reflow(item->parent);
}
@@ -398,9 +399,11 @@ e_canvas_item_descendent_needs_reflow (GnomeCanvasItem *item)
void
e_canvas_item_request_reflow (GnomeCanvasItem *item)
{
- gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::needs_reflow", (gpointer) 1);
- e_canvas_item_descendent_needs_reflow(item);
- add_idle(E_CANVAS(item->canvas));
+ if ( item->object.flags & GNOME_CANVAS_ITEM_REALIZED ) {
+ item->object.flags |= E_CANVAS_ITEM_NEEDS_REFLOW;
+ e_canvas_item_descendent_needs_reflow(item);
+ add_idle(E_CANVAS(item->canvas));
+ }
}
void
diff --git a/widgets/misc/e-canvas.h b/widgets/misc/e-canvas.h
index e70957b6d7..f1ff1195c9 100644
--- a/widgets/misc/e-canvas.h
+++ b/widgets/misc/e-canvas.h
@@ -44,6 +44,12 @@ typedef void (*ECanvasItemReflowFunc) (GnomeCanvasItem *item,
typedef struct _ECanvas ECanvas;
typedef struct _ECanvasClass ECanvasClass;
+/* Object flags for items */
+enum {
+ E_CANVAS_ITEM_NEEDS_REFLOW = 1 << 13,
+ E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW = 1 << 14
+};
+
struct _ECanvas
{
GnomeCanvas parent;
diff --git a/widgets/table/.cvsignore b/widgets/table/.cvsignore
index 0963d457d9..ca61202868 100644
--- a/widgets/table/.cvsignore
+++ b/widgets/table/.cvsignore
@@ -5,3 +5,5 @@ Makefile.in
*.lo
*.la
table-test
+table-example-1
+table-example-2
diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c
index 191ac86023..422b27ff93 100644
--- a/widgets/table/e-cell-text.c
+++ b/widgets/table/e-cell-text.c
@@ -319,8 +319,8 @@ static void
ect_kill_view (ECellView *ecv)
{
ECellTextView *text_view = (ECellTextView *) ecv;
-
- g_free (text_view);
+
+ g_free(text_view);
}
/*
@@ -351,7 +351,11 @@ ect_unrealize (ECellView *ecv)
gdk_gc_unref (text_view->gc);
text_view->gc = NULL;
-
+
+ if ( text_view->edit ) {
+ ect_cancel_edit (text_view);
+ }
+
if (text_view->font)
gdk_font_unref (text_view->font);
diff --git a/widgets/table/e-table-column-item.c b/widgets/table/e-table-column-item.c
index 0616327a93..1138c4afe4 100644
--- a/widgets/table/e-table-column-item.c
+++ b/widgets/table/e-table-column-item.c
@@ -55,7 +55,7 @@ etci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_COLUMN:
- etci->etci = GTK_VALUE_POINTER (*arg);
+ etci->etci = GTK_VALUE_OBJECT (*arg);
break;
}
etci_update (item, NULL, NULL, 0);
@@ -159,7 +159,7 @@ etci_class_init (GtkObjectClass *object_class)
item_class->point = etci_point;
item_class->event = etci_event;
- gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_POINTER,
+ gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_OBJECT,
GTK_ARG_WRITABLE, ARG_TABLE_COLUMN);
}
diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c
index e6001d24de..b079debb1a 100644
--- a/widgets/table/e-table-header-item.c
+++ b/widgets/table/e-table-header-item.c
@@ -191,7 +191,7 @@ ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_HEADER:
ethi_drop_table_header (ethi);
- ethi_add_table_header (ethi, GTK_VALUE_POINTER (*arg));
+ ethi_add_table_header (ethi, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg)));
break;
case ARG_TABLE_X:
@@ -990,7 +990,7 @@ ethi_class_init (GtkObjectClass *object_class)
item_class->point = ethi_point;
item_class->event = ethi_event;
- gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_POINTER,
+ gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_OBJECT,
GTK_ARG_WRITABLE, ARG_TABLE_HEADER);
gtk_object_add_arg_type ("ETableHeaderItem::x", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_TABLE_X);
diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c
index 095a14ea90..59df09e5bb 100644
--- a/widgets/table/e-table-item.c
+++ b/widgets/table/e-table-item.c
@@ -545,12 +545,12 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_HEADER:
eti_remove_header_model (eti);
- eti_add_header_model (eti, GTK_VALUE_POINTER (*arg));
+ eti_add_header_model (eti, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg)));
break;
case ARG_TABLE_MODEL:
eti_remove_table_model (eti);
- eti_add_table_model (eti, GTK_VALUE_POINTER (*arg));
+ eti_add_table_model (eti, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg)));
break;
case ARG_LENGHT_THRESHOLD:
@@ -1137,9 +1137,9 @@ eti_class_init (GtkObjectClass *object_class)
eti_class->row_selection = eti_row_selection;
- gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_POINTER,
+ gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_OBJECT,
GTK_ARG_WRITABLE, ARG_TABLE_HEADER);
- gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_POINTER,
+ gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_OBJECT,
GTK_ARG_WRITABLE, ARG_TABLE_MODEL);
gtk_object_add_arg_type ("ETableItem::drawgrid", GTK_TYPE_BOOL,
GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID);
diff --git a/widgets/table/e-table-text-model.c b/widgets/table/e-table-text-model.c
new file mode 100644
index 0000000000..69ffdc3568
--- /dev/null
+++ b/widgets/table/e-table-text-model.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETableTextModel - Text item model for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#include <config.h>
+#include <ctype.h>
+#include "e-table-text-model.h"
+
+static void e_table_text_model_class_init (ETableTextModelClass *class);
+static void e_table_text_model_init (ETableTextModel *model);
+static void e_table_text_model_destroy (GtkObject *object);
+
+static gchar *e_table_text_model_get_text(ETextModel *model);
+static void e_table_text_model_set_text(ETextModel *model, gchar *text);
+static void e_table_text_model_insert(ETextModel *model, gint postion, gchar *text);
+static void e_table_text_model_insert_length(ETextModel *model, gint postion, gchar *text, gint length);
+static void e_table_text_model_delete(ETextModel *model, gint postion, gint length);
+
+static GtkObject *parent_class;
+
+
+
+/**
+ * e_table_text_model_get_type:
+ * @void:
+ *
+ * Registers the &ETableTextModel class if necessary, and returns the type ID
+ * associated to it.
+ *
+ * Return value: The type ID of the &ETableTextModel class.
+ **/
+GtkType
+e_table_text_model_get_type (void)
+{
+ static GtkType model_type = 0;
+
+ if (!model_type) {
+ GtkTypeInfo model_info = {
+ "ETableTextModel",
+ sizeof (ETableTextModel),
+ sizeof (ETableTextModelClass),
+ (GtkClassInitFunc) e_table_text_model_class_init,
+ (GtkObjectInitFunc) e_table_text_model_init,
+ NULL, /* reserved_1 */
+ NULL, /* reserved_2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ model_type = gtk_type_unique (e_text_model_get_type (), &model_info);
+ }
+
+ return model_type;
+}
+
+/* Class initialization function for the text item */
+static void
+e_table_text_model_class_init (ETableTextModelClass *klass)
+{
+ GtkObjectClass *object_class;
+ ETextModelClass *model_class;
+
+ object_class = (GtkObjectClass *) klass;
+ model_class = (ETextModelClass *) klass;
+
+ parent_class = gtk_type_class (e_text_model_get_type ());
+
+ model_class->get_text = e_table_text_model_get_text;
+ model_class->set_text = e_table_text_model_set_text;
+ model_class->insert = e_table_text_model_insert;
+ model_class->insert_length = e_table_text_model_insert_length;
+ model_class->delete = e_table_text_model_delete;
+
+ object_class->destroy = e_table_text_model_destroy;
+}
+
+/* Object initialization function for the text item */
+static void
+e_table_text_model_init (ETableTextModel *model)
+{
+ model->model = NULL;
+ model->row = 0;
+ model->model_col = 0;
+ model->cell_changed_signal_id = 0;
+ model->row_changed_signal_id = 0;
+}
+
+/* Destroy handler for the text item */
+static void
+e_table_text_model_destroy (GtkObject *object)
+{
+ ETableTextModel *model;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (object));
+
+ model = E_TABLE_TEXT_MODEL (object);
+
+ if (model->cell_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(model->model),
+ model->cell_changed_signal_id);
+
+ if (model->row_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(model->model),
+ model->row_changed_signal_id);
+
+ if (model->model)
+ gtk_object_unref(GTK_OBJECT(model->model));
+
+ if (GTK_OBJECT_CLASS (parent_class)->destroy)
+ (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+static gchar *
+e_table_text_model_get_text(ETextModel *text_model)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model )
+ return (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ else
+ return "";
+}
+
+static void
+e_table_text_model_set_text(ETextModel *text_model, gchar *text)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model )
+ e_table_model_set_value_at(model->model, model->model_col, model->row, (void *) text);
+}
+
+static void
+e_table_text_model_insert(ETextModel *text_model, gint position, gchar *text)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%s%s", position, temp, text, temp + position);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+e_table_text_model_insert_length(ETextModel *text_model, gint position, gchar *text, gint length)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%.*s%s", position, temp, length, text, temp + position);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+e_table_text_model_delete(ETextModel *text_model, gint position, gint length)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%s", position, temp, temp + position + length);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+cell_changed(ETableModel *table_model, int model_col, int row, ETableTextModel *model)
+{
+ if (model->model_col == model_col &&
+ model->row == row)
+ e_text_model_changed(E_TEXT_MODEL(model));
+}
+
+static void
+row_changed(ETableModel *table_model, int row, ETableTextModel *model)
+{
+ if (model->row == row)
+ e_text_model_changed(E_TEXT_MODEL(model));
+}
+
+ETableTextModel *
+e_table_text_model_new(ETableModel *table_model, int row, int model_col)
+{
+ ETableTextModel *model = gtk_type_new (e_table_text_model_get_type ());
+ model->model = table_model;
+ if ( model->model ) {
+ gtk_object_ref(GTK_OBJECT(model->model));
+ model->cell_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(model->model),
+ "model_cell_changed",
+ GTK_SIGNAL_FUNC(cell_changed),
+ model);
+ model->row_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(model->model),
+ "model_row_changed",
+ GTK_SIGNAL_FUNC(row_changed),
+ model);
+ }
+ model->row = row;
+ model->model_col = model_col;
+ return model;
+}
+
diff --git a/widgets/table/e-table-text-model.h b/widgets/table/e-table-text-model.h
new file mode 100644
index 0000000000..43c82b6bcc
--- /dev/null
+++ b/widgets/table/e-table-text-model.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETableTextModel - Text item for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#ifndef E_TABLE_TEXT_MODEL_H
+#define E_TABLE_TEXT_MODEL_H
+
+#include <gnome.h>
+#include "e-text-model.h"
+#include "e-table-model.h"
+
+
+BEGIN_GNOME_DECLS
+
+#define E_TYPE_TABLE_TEXT_MODEL (e_table_text_model_get_type ())
+#define E_TABLE_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TABLE_TEXT_MODEL, ETableTextModel))
+#define E_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TABLE_TEXT_MODEL, ETableTextModelClass))
+#define E_IS_TABLE_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TABLE_TEXT_MODEL))
+#define E_IS_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TABLE_TEXT_MODEL))
+
+typedef struct _ETableTextModel ETableTextModel;
+typedef struct _ETableTextModelClass ETableTextModelClass;
+
+struct _ETableTextModel {
+ ETextModel parent;
+
+ ETableModel *model;
+ int row;
+ int model_col;
+
+ int cell_changed_signal_id;
+ int row_changed_signal_id;
+};
+
+struct _ETableTextModelClass {
+ ETextModelClass parent_class;
+
+};
+
+
+/* Standard Gtk function */
+GtkType e_table_text_model_get_type (void);
+ETableTextModel *e_table_text_model_new(ETableModel *table_model, int row, int model_col);
+
+END_GNOME_DECLS
+
+#endif
diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c
index 36f7d5a776..ed1260fa44 100644
--- a/widgets/table/e-table.c
+++ b/widgets/table/e-table.c
@@ -675,7 +675,7 @@ et_table_cell_changed (ETableModel *table_model, int view_col, int row, ETable *
static void
e_table_setup_table (ETable *e_table, ETableHeader *full_header, ETableHeader *header, ETableModel *model, xmlNode *xml_grouping)
{
- e_table->table_canvas = GNOME_CANVAS(gnome_canvas_new ());
+ e_table->table_canvas = GNOME_CANVAS(e_canvas_new ());
gtk_signal_connect (
GTK_OBJECT (e_table->table_canvas), "size_allocate",
GTK_SIGNAL_FUNC (table_canvas_size_allocate), e_table);
@@ -809,7 +809,7 @@ e_table_new_from_spec_file (ETableHeader *full_header, ETableModel *etm, const c
e_table = gtk_type_new (e_table_get_type ());
- e_table_construct (e_table, full_header, etm, filename);
+ e_table_construct_from_spec_file (e_table, full_header, etm, filename);
return (GtkWidget *) e_table;
}
diff --git a/widgets/text/e-table-text-model.c b/widgets/text/e-table-text-model.c
new file mode 100644
index 0000000000..69ffdc3568
--- /dev/null
+++ b/widgets/text/e-table-text-model.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETableTextModel - Text item model for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#include <config.h>
+#include <ctype.h>
+#include "e-table-text-model.h"
+
+static void e_table_text_model_class_init (ETableTextModelClass *class);
+static void e_table_text_model_init (ETableTextModel *model);
+static void e_table_text_model_destroy (GtkObject *object);
+
+static gchar *e_table_text_model_get_text(ETextModel *model);
+static void e_table_text_model_set_text(ETextModel *model, gchar *text);
+static void e_table_text_model_insert(ETextModel *model, gint postion, gchar *text);
+static void e_table_text_model_insert_length(ETextModel *model, gint postion, gchar *text, gint length);
+static void e_table_text_model_delete(ETextModel *model, gint postion, gint length);
+
+static GtkObject *parent_class;
+
+
+
+/**
+ * e_table_text_model_get_type:
+ * @void:
+ *
+ * Registers the &ETableTextModel class if necessary, and returns the type ID
+ * associated to it.
+ *
+ * Return value: The type ID of the &ETableTextModel class.
+ **/
+GtkType
+e_table_text_model_get_type (void)
+{
+ static GtkType model_type = 0;
+
+ if (!model_type) {
+ GtkTypeInfo model_info = {
+ "ETableTextModel",
+ sizeof (ETableTextModel),
+ sizeof (ETableTextModelClass),
+ (GtkClassInitFunc) e_table_text_model_class_init,
+ (GtkObjectInitFunc) e_table_text_model_init,
+ NULL, /* reserved_1 */
+ NULL, /* reserved_2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ model_type = gtk_type_unique (e_text_model_get_type (), &model_info);
+ }
+
+ return model_type;
+}
+
+/* Class initialization function for the text item */
+static void
+e_table_text_model_class_init (ETableTextModelClass *klass)
+{
+ GtkObjectClass *object_class;
+ ETextModelClass *model_class;
+
+ object_class = (GtkObjectClass *) klass;
+ model_class = (ETextModelClass *) klass;
+
+ parent_class = gtk_type_class (e_text_model_get_type ());
+
+ model_class->get_text = e_table_text_model_get_text;
+ model_class->set_text = e_table_text_model_set_text;
+ model_class->insert = e_table_text_model_insert;
+ model_class->insert_length = e_table_text_model_insert_length;
+ model_class->delete = e_table_text_model_delete;
+
+ object_class->destroy = e_table_text_model_destroy;
+}
+
+/* Object initialization function for the text item */
+static void
+e_table_text_model_init (ETableTextModel *model)
+{
+ model->model = NULL;
+ model->row = 0;
+ model->model_col = 0;
+ model->cell_changed_signal_id = 0;
+ model->row_changed_signal_id = 0;
+}
+
+/* Destroy handler for the text item */
+static void
+e_table_text_model_destroy (GtkObject *object)
+{
+ ETableTextModel *model;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (object));
+
+ model = E_TABLE_TEXT_MODEL (object);
+
+ if (model->cell_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(model->model),
+ model->cell_changed_signal_id);
+
+ if (model->row_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(model->model),
+ model->row_changed_signal_id);
+
+ if (model->model)
+ gtk_object_unref(GTK_OBJECT(model->model));
+
+ if (GTK_OBJECT_CLASS (parent_class)->destroy)
+ (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+static gchar *
+e_table_text_model_get_text(ETextModel *text_model)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model )
+ return (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ else
+ return "";
+}
+
+static void
+e_table_text_model_set_text(ETextModel *text_model, gchar *text)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model )
+ e_table_model_set_value_at(model->model, model->model_col, model->row, (void *) text);
+}
+
+static void
+e_table_text_model_insert(ETextModel *text_model, gint position, gchar *text)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%s%s", position, temp, text, temp + position);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+e_table_text_model_insert_length(ETextModel *text_model, gint position, gchar *text, gint length)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%.*s%s", position, temp, length, text, temp + position);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+e_table_text_model_delete(ETextModel *text_model, gint position, gint length)
+{
+ ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
+ if ( model->model ) {
+ gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row);
+ temp = g_strdup_printf("%.*s%s", position, temp, temp + position + length);
+ e_table_model_set_value_at(model->model, model->model_col, model->row, temp);
+ g_free(temp);
+ }
+}
+
+static void
+cell_changed(ETableModel *table_model, int model_col, int row, ETableTextModel *model)
+{
+ if (model->model_col == model_col &&
+ model->row == row)
+ e_text_model_changed(E_TEXT_MODEL(model));
+}
+
+static void
+row_changed(ETableModel *table_model, int row, ETableTextModel *model)
+{
+ if (model->row == row)
+ e_text_model_changed(E_TEXT_MODEL(model));
+}
+
+ETableTextModel *
+e_table_text_model_new(ETableModel *table_model, int row, int model_col)
+{
+ ETableTextModel *model = gtk_type_new (e_table_text_model_get_type ());
+ model->model = table_model;
+ if ( model->model ) {
+ gtk_object_ref(GTK_OBJECT(model->model));
+ model->cell_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(model->model),
+ "model_cell_changed",
+ GTK_SIGNAL_FUNC(cell_changed),
+ model);
+ model->row_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(model->model),
+ "model_row_changed",
+ GTK_SIGNAL_FUNC(row_changed),
+ model);
+ }
+ model->row = row;
+ model->model_col = model_col;
+ return model;
+}
+
diff --git a/widgets/text/e-table-text-model.h b/widgets/text/e-table-text-model.h
new file mode 100644
index 0000000000..43c82b6bcc
--- /dev/null
+++ b/widgets/text/e-table-text-model.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETableTextModel - Text item for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#ifndef E_TABLE_TEXT_MODEL_H
+#define E_TABLE_TEXT_MODEL_H
+
+#include <gnome.h>
+#include "e-text-model.h"
+#include "e-table-model.h"
+
+
+BEGIN_GNOME_DECLS
+
+#define E_TYPE_TABLE_TEXT_MODEL (e_table_text_model_get_type ())
+#define E_TABLE_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TABLE_TEXT_MODEL, ETableTextModel))
+#define E_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TABLE_TEXT_MODEL, ETableTextModelClass))
+#define E_IS_TABLE_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TABLE_TEXT_MODEL))
+#define E_IS_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TABLE_TEXT_MODEL))
+
+typedef struct _ETableTextModel ETableTextModel;
+typedef struct _ETableTextModelClass ETableTextModelClass;
+
+struct _ETableTextModel {
+ ETextModel parent;
+
+ ETableModel *model;
+ int row;
+ int model_col;
+
+ int cell_changed_signal_id;
+ int row_changed_signal_id;
+};
+
+struct _ETableTextModelClass {
+ ETextModelClass parent_class;
+
+};
+
+
+/* Standard Gtk function */
+GtkType e_table_text_model_get_type (void);
+ETableTextModel *e_table_text_model_new(ETableModel *table_model, int row, int model_col);
+
+END_GNOME_DECLS
+
+#endif
diff --git a/widgets/text/e-text-model.c b/widgets/text/e-text-model.c
new file mode 100644
index 0000000000..d571e87791
--- /dev/null
+++ b/widgets/text/e-text-model.c
@@ -0,0 +1,241 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETextModel - Text item model for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#include <config.h>
+#include <ctype.h>
+#include "e-text-model.h"
+
+enum {
+ E_TEXT_MODEL_CHANGED,
+ E_TEXT_MODEL_LAST_SIGNAL
+};
+
+static guint e_text_model_signals[E_TEXT_MODEL_LAST_SIGNAL] = { 0 };
+
+static void e_text_model_class_init (ETextModelClass *class);
+static void e_text_model_init (ETextModel *model);
+static void e_text_model_destroy (GtkObject *object);
+
+static gchar *e_text_model_real_get_text(ETextModel *model);
+static void e_text_model_real_set_text(ETextModel *model, gchar *text);
+static void e_text_model_real_insert(ETextModel *model, gint postion, gchar *text);
+static void e_text_model_real_insert_length(ETextModel *model, gint postion, gchar *text, gint length);
+static void e_text_model_real_delete(ETextModel *model, gint postion, gint length);
+
+static GtkObject *parent_class;
+
+
+
+/**
+ * e_text_model_get_type:
+ * @void:
+ *
+ * Registers the &ETextModel class if necessary, and returns the type ID
+ * associated to it.
+ *
+ * Return value: The type ID of the &ETextModel class.
+ **/
+GtkType
+e_text_model_get_type (void)
+{
+ static GtkType model_type = 0;
+
+ if (!model_type) {
+ GtkTypeInfo model_info = {
+ "ETextModel",
+ sizeof (ETextModel),
+ sizeof (ETextModelClass),
+ (GtkClassInitFunc) e_text_model_class_init,
+ (GtkObjectInitFunc) e_text_model_init,
+ NULL, /* reserved_1 */
+ NULL, /* reserved_2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ model_type = gtk_type_unique (gtk_object_get_type (), &model_info);
+ }
+
+ return model_type;
+}
+
+/* Class initialization function for the text item */
+static void
+e_text_model_class_init (ETextModelClass *klass)
+{
+ GtkObjectClass *object_class;
+
+ object_class = (GtkObjectClass *) klass;
+
+ parent_class = gtk_type_class (gtk_object_get_type ());
+
+ e_text_model_signals[E_TEXT_MODEL_CHANGED] =
+ gtk_signal_new ("changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (ETextModelClass, changed),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+
+ gtk_object_class_add_signals (object_class, e_text_model_signals, E_TEXT_MODEL_LAST_SIGNAL);
+
+ klass->changed = NULL;
+ klass->get_text = e_text_model_real_get_text;
+ klass->set_text = e_text_model_real_set_text;
+ klass->insert = e_text_model_real_insert;
+ klass->insert_length = e_text_model_real_insert_length;
+ klass->delete = e_text_model_real_delete;
+
+ object_class->destroy = e_text_model_destroy;
+}
+
+/* Object initialization function for the text item */
+static void
+e_text_model_init (ETextModel *model)
+{
+ model->text = NULL;
+}
+
+/* Destroy handler for the text item */
+static void
+e_text_model_destroy (GtkObject *object)
+{
+ ETextModel *model;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (object));
+
+ model = E_TEXT_MODEL (object);
+
+ if (model->text)
+ g_free (model->text);
+
+ if (GTK_OBJECT_CLASS (parent_class)->destroy)
+ (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+
+static gchar *
+e_text_model_real_get_text(ETextModel *model)
+{
+ return model->text;
+}
+
+static void
+e_text_model_real_set_text(ETextModel *model, gchar *text)
+{
+ if (model->text)
+ g_free(model->text);
+ model->text = g_strdup(text);
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_insert(ETextModel *model, gint position, gchar *text)
+{
+ gchar *temp = g_strdup_printf("%.*s%s%s", position, model->text, text, model->text + position);
+ if (model->text)
+ g_free(model->text);
+ model->text = temp;
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_insert_length(ETextModel *model, gint position, gchar *text, gint length)
+{
+ gchar *temp = g_strdup_printf("%.*s%.*s%s", position, model->text, length, text, model->text + position);
+ if (model->text)
+ g_free(model->text);
+ model->text = temp;
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_delete(ETextModel *model, gint position, gint length)
+{
+ memmove(model->text + position, model->text + position + length, strlen(model->text + position + length) + 1);
+ e_text_model_changed(model);
+}
+
+void
+e_text_model_changed(ETextModel *model)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ gtk_signal_emit (GTK_OBJECT (model),
+ e_text_model_signals [E_TEXT_MODEL_CHANGED]);
+}
+
+gchar *
+e_text_model_get_text(ETextModel *model)
+{
+ g_return_val_if_fail (model != NULL, NULL);
+ g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL);
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text )
+ return E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text(model);
+ else
+ return "";
+}
+
+void
+e_text_model_set_text(ETextModel *model, gchar *text)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text(model, text);
+}
+
+void
+e_text_model_insert(ETextModel *model, gint position, gchar *text)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert(model, position, text);
+}
+
+void
+e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length(model, position, text, length);
+}
+
+void
+e_text_model_delete(ETextModel *model, gint position, gint length)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete(model, position, length);
+}
+
+ETextModel *
+e_text_model_new(void)
+{
+ ETextModel *model = gtk_type_new (e_text_model_get_type ());
+ model->text = g_strdup("");
+ return model;
+}
diff --git a/widgets/text/e-text-model.h b/widgets/text/e-text-model.h
new file mode 100644
index 0000000000..5b15ccb117
--- /dev/null
+++ b/widgets/text/e-text-model.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETextModel - Text item for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * A majority of code taken from:
+ *
+ * Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget. Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998 The Free Software Foundation
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx> */
+
+#ifndef E_TEXT_MODEL_H
+#define E_TEXT_MODEL_H
+
+#include <gnome.h>
+
+
+BEGIN_GNOME_DECLS
+
+#define E_TYPE_TEXT_MODEL (e_text_model_get_type ())
+#define E_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT_MODEL, ETextModel))
+#define E_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT_MODEL, ETextModelClass))
+#define E_IS_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT_MODEL))
+#define E_IS_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT_MODEL))
+
+typedef struct _ETextModel ETextModel;
+typedef struct _ETextModelClass ETextModelClass;
+
+struct _ETextModel {
+ GtkObject item;
+
+ char *text; /* Text to display */
+ int length;
+};
+
+struct _ETextModelClass {
+ GtkObjectClass parent_class;
+
+ /* Signal */
+ void (* changed) (ETextModel *model);
+
+ /* Virtual methods */
+ char *(* get_text) (ETextModel *model);
+ void (* set_text) (ETextModel *model, gchar *text);
+ void (* insert) (ETextModel *model, gint position, gchar *text);
+ void (* insert_length) (ETextModel *model, gint position, gchar *text, gint length);
+ void (* delete) (ETextModel *model, gint position, gint length);
+};
+
+
+/* Standard Gtk function */
+GtkType e_text_model_get_type (void);
+ETextModel *e_text_model_new(void);
+
+void e_text_model_changed(ETextModel *model);
+gchar *e_text_model_get_text(ETextModel *model);
+void e_text_model_set_text(ETextModel *model, gchar *text);
+void e_text_model_insert(ETextModel *model, gint position, gchar *text);
+void e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length);
+void e_text_model_delete(ETextModel *model, gint position, gint length);
+
+
+END_GNOME_DECLS
+
+#endif
diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c
index ca41dc1d96..85950f149a 100644
--- a/widgets/text/e-text.c
+++ b/widgets/text/e-text.c
@@ -52,6 +52,7 @@ struct line {
/* Object argument IDs */
enum {
ARG_0,
+ ARG_MODEL,
ARG_TEXT,
ARG_X,
ARG_Y,
@@ -117,6 +118,8 @@ static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand
static void e_text_get_selection(EText *text, GdkAtom selection, guint32 time);
static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length);
+static void e_text_text_model_changed(ETextModel *model, EText *text);
+
static GtkWidget *e_text_get_invisible(EText *text);
static void _selection_clear_event (GtkInvisible *invisible,
GdkEventSelection *event,
@@ -133,6 +136,7 @@ static void _selection_received (GtkInvisible *invisible,
static ETextSuckFont *e_suck_font (GdkFont *font);
static void e_suck_font_free (ETextSuckFont *suckfont);
+static void e_text_free_lines(EText *text);
static GnomeCanvasItemClass *parent_class;
@@ -203,7 +207,9 @@ e_text_class_init (ETextClass *klass)
gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL);
-
+
+ gtk_object_add_arg_type ("EText::model",
+ GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL);
gtk_object_add_arg_type ("EText::text",
GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT);
gtk_object_add_arg_type ("EText::x",
@@ -285,6 +291,16 @@ e_text_class_init (ETextClass *klass)
static void
e_text_init (EText *text)
{
+ text->text = NULL;
+ text->model = e_text_model_new();
+ gtk_object_ref(GTK_OBJECT(text->model));
+ gtk_object_sink(GTK_OBJECT(text->model));
+ text->model_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(text->model),
+ "changed",
+ GTK_SIGNAL_FUNC(e_text_text_model_changed),
+ text);
+
text->x = 0.0;
text->y = 0.0;
text->anchor = GTK_ANCHOR_CENTER;
@@ -348,8 +364,12 @@ e_text_destroy (GtkObject *object)
text = E_TEXT (object);
- if (text->text)
- g_free (text->text);
+ if (text->model_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(text->model),
+ text->model_changed_signal_id);
+
+ if (text->model)
+ gtk_object_unref(GTK_OBJECT(text->model));
if (text->tep)
gtk_object_unref (GTK_OBJECT(text->tep));
@@ -374,6 +394,15 @@ e_text_destroy (GtkObject *object)
}
static void
+e_text_text_model_changed (ETextModel *model, EText *text)
+{
+ text->text = e_text_model_get_text(model);
+ e_text_free_lines(text);
+ text->needs_split_into_lines = 1;
+ e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
+}
+
+static void
get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2)
{
GnomeCanvasItem *item;
@@ -663,8 +692,6 @@ split_into_lines (EText *text)
/* Free old array of lines */
e_text_free_lines(text);
- text->num_lines = 0;
-
if (!text->text)
return;
@@ -870,16 +897,31 @@ e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
have_pixel = FALSE;
switch (arg_id) {
- case ARG_TEXT:
- if (text->text)
- g_free (text->text);
+ case ARG_MODEL:
+ if ( text->model_changed_signal_id )
+ gtk_signal_disconnect(GTK_OBJECT(text->model),
+ text->model_changed_signal_id);
+ gtk_object_unref(GTK_OBJECT(text->model));
+ text->model = E_TEXT_MODEL(GTK_VALUE_OBJECT (*arg));
+ gtk_object_ref(GTK_OBJECT(text->model));
+
+ text->model_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(text->model),
+ "changed",
+ GTK_SIGNAL_FUNC(e_text_text_model_changed),
+ text);
- text->text = g_strdup (GTK_VALUE_STRING (*arg));
e_text_free_lines(text);
+ text->text = e_text_model_get_text(text->model);
+
text->needs_split_into_lines = 1;
needs_reflow = 1;
break;
+ case ARG_TEXT:
+ e_text_model_set_text(text->model, GTK_VALUE_STRING (*arg));
+ break;
+
case ARG_X:
text->x = GTK_VALUE_DOUBLE (*arg);
text->needs_recalc_bounds = 1;
@@ -1134,6 +1176,10 @@ e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
text = E_TEXT (object);
switch (arg_id) {
+ case ARG_MODEL:
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->model);
+ break;
+
case ARG_TEXT:
GTK_VALUE_STRING (*arg) = g_strdup (text->text);
break;
@@ -1253,10 +1299,36 @@ e_text_reflow (GnomeCanvasItem *item, int flags)
text->needs_calc_line_widths = 1;
}
if ( text->needs_calc_line_widths ) {
+ int x;
+ int i;
+ struct line *lines;
calc_line_widths(text);
text->needs_calc_line_widths = 0;
text->needs_calc_height = 1;
text->needs_redraw = 1;
+
+ lines = text->lines;
+ if ( !lines )
+ return;
+
+ for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) {
+ if (lines->text - text->text > text->selection_end) {
+ break;
+ }
+ }
+ lines --;
+ x = gdk_text_width(text->font,
+ lines->text,
+ text->selection_end - (lines->text - text->text));
+
+
+ if (x < text->xofs_edit) {
+ text->xofs_edit = x;
+ }
+
+ if (2 + x - text->clip_width > text->xofs_edit) {
+ text->xofs_edit = 2 + x - text->clip_width;
+ }
}
if ( text->needs_calc_height ) {
calc_height (text);
@@ -1489,8 +1561,10 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
return;
lines = text->lines;
- if ( !lines )
- return;
+ if ( !lines ) {
+ text->needs_split_into_lines = 1;
+ e_canvas_item_request_reflow (item);
+ }
clip_rect = NULL;
if (text->clip) {
@@ -2159,6 +2233,7 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
gtk_widget_destroy (text->tooltip_window);
text->tooltip_window = NULL;
}
+#if 0
if ((!text->editing)
&& text->editable
&& event->type == GDK_BUTTON_RELEASE
@@ -2177,6 +2252,13 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
&e_tep_event);
e_tep_event.type = GDK_BUTTON_RELEASE;
}
+#else
+ if ((!text->editing)
+ && text->editable
+ && event->button.button == 1) {
+ gnome_canvas_item_grab_focus (item);
+ }
+#endif
if (text->editing) {
GdkEventButton button = event->button;
e_tep_event.button.time = button.time;
@@ -2346,33 +2428,21 @@ _get_position(EText *text, ETextEventProcessorCommand *command)
static void
_delete_selection(EText *text)
{
- gint length = strlen(text->text);
- if (text->selection_end == text->selection_start)
- return;
- if (text->selection_end < text->selection_start) {
- text->selection_end ^= text->selection_start;
- text->selection_start ^= text->selection_end;
- text->selection_end ^= text->selection_start;
+ if ( text->selection_start < text->selection_end ) {
+ e_text_model_delete(text->model, text->selection_start, text->selection_end - text->selection_start);
+ text->selection_end = text->selection_start;
+ } else {
+ e_text_model_delete(text->model, text->selection_end, text->selection_start - text->selection_end);
+ text->selection_start = text->selection_end;
}
- memmove( text->text + text->selection_start,
- text->text + text->selection_end,
- length - text->selection_end + 1 );
- length -= text->selection_end - text->selection_start;
- text->selection_end = text->selection_start;
}
static void
_insert(EText *text, char *string, int value)
{
if (value > 0) {
- char *temp;
- gint length = strlen(text->text);
- temp = g_new(gchar, length + value + 1);
- strncpy(temp, text->text, text->selection_start);
- strncpy(temp + text->selection_start, string, value);
- strcpy(temp + text->selection_start + value, text->text + text->selection_start);
- g_free(text->text);
- text->text = temp;
+ e_text_model_insert_length(text->model, text->selection_start, string, value);
+
text->selection_start += value;
text->selection_end = text->selection_start;
}
@@ -2406,9 +2476,6 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp
text->selection_end = _get_position(text, command);
}
_delete_selection(text);
- e_text_free_lines(text);
- text->needs_split_into_lines = 1;
- e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
if (text->timer) {
g_timer_reset(text->timer);
}
@@ -2419,9 +2486,6 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp
_delete_selection(text);
}
_insert(text, command->string, command->value);
- e_text_free_lines(text);
- text->needs_split_into_lines = 1;
- e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
if (text->timer) {
g_timer_reset(text->timer);
}
diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h
index 52fb951bc2..a4bc06d820 100644
--- a/widgets/text/e-text.h
+++ b/widgets/text/e-text.h
@@ -21,6 +21,7 @@
#include <gnome.h>
#include "e-text-event-processor.h"
+#include "e-text-model.h"
BEGIN_GNOME_DECLS
@@ -101,6 +102,9 @@ struct _ETextSuckFont {
struct _EText {
GnomeCanvasItem item;
+
+ ETextModel *model;
+ gint model_changed_signal_id;
char *text; /* Text to display */
gpointer lines; /* Text split into lines (private field) */