aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@gnu.org>1999-11-21 07:37:37 +0800
committerArturo Espinosa <unammx@src.gnome.org>1999-11-21 07:37:37 +0800
commit77df46c366a3b761288db21b2593e963c4590207 (patch)
treedc70c4ff1d434b76654e68e0fe7f8b1e28fba81c /widgets
parent76fba2380e809d44b716343a4c7a18e907948618 (diff)
downloadgsoc2013-evolution-77df46c366a3b761288db21b2593e963c4590207.tar
gsoc2013-evolution-77df46c366a3b761288db21b2593e963c4590207.tar.gz
gsoc2013-evolution-77df46c366a3b761288db21b2593e963c4590207.tar.bz2
gsoc2013-evolution-77df46c366a3b761288db21b2593e963c4590207.tar.lz
gsoc2013-evolution-77df46c366a3b761288db21b2593e963c4590207.tar.xz
gsoc2013-evolution-77df46c366a3b761288db21b2593e963c4590207.tar.zst
gsoc2013-evolution-77df46c366a3b761288db21b2593e963c4590207.zip
Compute width, keep track of it. (ethi_add_table_header): Monitor changes
1999-11-20 Miguel de Icaza <miguel@gnu.org> * e-table-header-item.c (ethi_set_arg): Compute width, keep track of it. (ethi_add_table_header): Monitor changes to the Header model; Queue updates. (ethi_draw): Fix the redraw logic here. * table-test.c (main): Change the sample code, so we can better debug this. * e-table-item.c (eti_header_structure_changed): Keep track of width; (eti_header_dim_changed): ditto. (eti_draw): Many redraw fixes. svn path=/trunk/; revision=1425
Diffstat (limited to 'widgets')
-rw-r--r--widgets/ChangeLog16
-rw-r--r--widgets/e-table-header-item.c65
-rw-r--r--widgets/e-table-header-item.h7
-rw-r--r--widgets/e-table-item.c64
-rw-r--r--widgets/e-table-item.h2
-rw-r--r--widgets/e-table/ChangeLog16
-rw-r--r--widgets/e-table/e-table-header-item.c65
-rw-r--r--widgets/e-table/e-table-header-item.h7
-rw-r--r--widgets/e-table/e-table-item.c64
-rw-r--r--widgets/e-table/e-table-item.h2
-rw-r--r--widgets/e-table/table-test.c15
-rw-r--r--widgets/table-test.c15
-rw-r--r--widgets/table/e-table-header-item.c65
-rw-r--r--widgets/table/e-table-header-item.h7
-rw-r--r--widgets/table/e-table-item.c64
-rw-r--r--widgets/table/e-table-item.h2
-rw-r--r--widgets/table/table-test.c15
17 files changed, 395 insertions, 96 deletions
diff --git a/widgets/ChangeLog b/widgets/ChangeLog
index c77c3b22dd..107b2ee4a8 100644
--- a/widgets/ChangeLog
+++ b/widgets/ChangeLog
@@ -1,3 +1,19 @@
+1999-11-20 Miguel de Icaza <miguel@gnu.org>
+
+ * e-table-header-item.c (ethi_set_arg): Compute width, keep track
+ of it.
+ (ethi_add_table_header): Monitor changes to the Header model;
+ Queue updates.
+ (ethi_draw): Fix the redraw logic here.
+
+ * table-test.c (main): Change the sample code, so we can better
+ debug this.
+
+ * e-table-item.c (eti_header_structure_changed): Keep track of
+ width;
+ (eti_header_dim_changed): ditto.
+ (eti_draw): Many redraw fixes.
+
1999-11-19 Miguel de Icaza <miguel@gnu.org>
* e-table-item.c (eti_realize): Hook up; Load gcs.
diff --git a/widgets/e-table-header-item.c b/widgets/e-table-header-item.c
index b46f8511b0..dab5d3d71d 100644
--- a/widgets/e-table-header-item.c
+++ b/widgets/e-table-header-item.c
@@ -52,8 +52,8 @@ ethi_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags
item->x1 = ethi->x1;
item->y1 = ethi->y1;
- item->x2 = INT_MAX;
- item->y2 = ethi->x1 + ethi->height;
+ item->x2 = ethi->x1 + ethi->width;
+ item->y2 = ethi->y1 + ethi->height;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
}
@@ -72,6 +72,54 @@ ethi_font_load (ETableHeaderItem *ethi, char *font)
}
static void
+ethi_drop_table_header (ETableHeaderItem *ethi)
+{
+ GtkObject *header;
+
+ if (!ethi->eth)
+ return;
+
+ header = GTK_OBJECT (ethi->eth);
+ gtk_signal_disconnect (header, ethi->structure_change_id);
+ gtk_signal_disconnect (header, ethi->dimension_change_id);
+
+ gtk_object_unref (header);
+ ethi->eth = NULL;
+ ethi->width = 0;
+}
+
+static void
+structure_changed (ETableHeader *header, ETableHeaderItem *ethi)
+{
+ ethi->width = e_table_header_total_width (header);
+
+ ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0);
+}
+
+static void
+dimension_changed (ETableHeader *header, int col, ETableHeaderItem *ethi)
+{
+ ethi->width = e_table_header_total_width (header);
+
+ ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0);
+}
+
+static void
+ethi_add_table_header (ETableHeaderItem *ethi, ETableHeader *header)
+{
+ ethi->eth = header;
+ gtk_object_ref (GTK_OBJECT (ethi->eth));
+ ethi->width = e_table_header_total_width (header);
+
+ ethi->structure_change_id = gtk_signal_connect (
+ GTK_OBJECT (header), "structure_change",
+ GTK_SIGNAL_FUNC(structure_changed), ethi);
+ ethi->dimension_change_id = gtk_signal_connect (
+ GTK_OBJECT (header), "dimension_change",
+ GTK_SIGNAL_FUNC(dimension_changed), ethi);
+}
+
+static void
ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
GnomeCanvasItem *item;
@@ -83,8 +131,8 @@ ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_HEADER:
- ethi->eth = GTK_VALUE_POINTER (*arg);
- gtk_object_ref (GTK_OBJECT (ethi->eth));
+ ethi_drop_table_header (ethi);
+ ethi_add_table_header (ethi, GTK_VALUE_POINTER (*arg));
break;
case ARG_TABLE_X:
@@ -196,6 +244,9 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
total = 0;
x = -x1;
+ printf ("My coords are: %g %g %g %g\n",
+ item->x1, item->y1, item->x2, item->y2);
+
for (col = 0; col < cols; col++){
ETableCol *ecol = e_table_header_get_column (ethi->eth, col);
int col_width;
@@ -206,6 +257,7 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
col_width = ecol->width;
if (x1 > total + col_width){
+ total += col_width;
x += col_width;
continue;
}
@@ -217,9 +269,10 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
draw_button (ethi, ecol, drawable, gc,
GTK_WIDGET (canvas)->style,
- x, -y1, col_width, ethi->height);
+ x, ethi->y1 - y1, col_width, ethi->height);
x += col_width;
+ total += col_width;
}
}
@@ -292,7 +345,7 @@ ethi_request_redraw (ETableHeaderItem *ethi)
* request a redraw
*/
gnome_canvas_request_redraw (
- canvas, ethi->x1, ethi->y1, INT_MAX, ethi->x1 + ethi->height);
+ canvas, ethi->x1, ethi->y1, ethi->x1 + ethi->width, ethi->x1 + ethi->height);
}
static void
diff --git a/widgets/e-table-header-item.h b/widgets/e-table-header-item.h
index 45e8f8851d..d6b7d64a9f 100644
--- a/widgets/e-table-header-item.h
+++ b/widgets/e-table-header-item.h
@@ -17,7 +17,7 @@ typedef struct {
GdkGC *gc;
GdkCursor *change_cursor, *normal_cursor;
- short x1, y1, height;
+ short x1, y1, height, width;
GdkFont *font;
/*
@@ -27,6 +27,11 @@ typedef struct {
int resize_width;
int resize_start_pos;
GtkObject *resize_guide;
+
+ /*
+ * Ids
+ */
+ int structure_change_id, dimension_change_id;
} ETableHeaderItem;
typedef struct {
diff --git a/widgets/e-table-item.c b/widgets/e-table-item.c
index 8f7fa73725..7ddfc10405 100644
--- a/widgets/e-table-item.c
+++ b/widgets/e-table-item.c
@@ -31,8 +31,8 @@ eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
item->x1 = eti->x1;
item->y1 = eti->y1;
- item->x2 = INT_MAX;
- item->y2 = eti->x1 + eti->height;
+ item->x2 = eti->x1 + eti->width;
+ item->y2 = eti->y1 + eti->height;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
}
@@ -86,15 +86,29 @@ eti_add_table_model (ETableItem *eti, ETableModel *table_model)
}
static void
+eti_request_redraw (ETableItem *eti)
+{
+ GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas;
+
+ gnome_canvas_request_redraw (canvas, eti->x1, eti->y1, eti->x1 + eti->width, eti->y1 + eti->height);
+}
+
+static void
eti_header_dim_changed (ETableHeader *eth, int col, ETableItem *eti)
{
- printf ("NOTIFY: Dimension changed");
+ eti->width = e_table_header_total_width (eti->header);
+
+ eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0);
+ eti_request_redraw (eti);
}
static void
eti_header_structure_changed (ETableHeader *eth, ETableItem *eti)
{
- printf ("NOTIFY: Structure changed");
+ eti->width = e_table_header_total_width (eti->header);
+
+ eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0);
+ eti_request_redraw (eti);
}
static void
@@ -104,6 +118,8 @@ eti_add_header_model (ETableItem *eti, ETableHeader *header)
eti->header = header;
gtk_object_ref (GTK_OBJECT (header));
+
+ eti->width = e_table_header_total_width (header);
eti->header_dim_change_id = gtk_signal_connect (
GTK_OBJECT (header), "dimension_change",
@@ -203,7 +219,17 @@ static void
draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row,
int x1, int y1, int x2, int y2)
{
- gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2-x1, y2-y1);
+ GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas;
+ GdkFont *font;
+ char text [40];
+
+ font = GTK_WIDGET (canvas)->style->font;
+
+ sprintf (text, "%d:%d\n", col, row);
+ gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2);
+ gdk_draw_line (drawable, eti->grid_gc, x1, y2, x2, y1);
+
+ gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text));
}
static void
@@ -215,19 +241,20 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
int row, col, y1, y2;
int first_col, last_col, x_offset;
int x1, x2;
-
+
/*
* Clear the background
*/
gdk_draw_rectangle (
- drawable, eti->fill_gc, TRUE, 0, 0, width, height);
-
+ drawable, eti->fill_gc, TRUE,
+ eti->x1 - x, eti->y1 - y, eti->width, eti->height);
+
/*
* First column to draw, last column to draw
*/
- x1 = x_offset = 0;
first_col = -1;
- last_col = 0;
+ last_col = x_offset = 0;
+ x1 = eti->x1;
for (col = 0; col < cols; col++, x1 = x2){
ETableCol *ecol = e_table_header_get_column (eti->header, col);
@@ -238,17 +265,26 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
if (x2 < x)
continue;
if (first_col == -1){
- x_offset = x - x1;
+ x_offset = x1 - x;
first_col = col;
}
}
last_col = col;
/*
+ * Nothing to paint
+ */
+ if (first_col == -1)
+ return;
+
+ printf ("Cols %d %d\n", first_col, last_col);
+ /*
* Draw individual lines
*/
- y1 = y2 = 0;
+ y1 = y2 = eti->y1;
for (row = eti->top_item; row < rows; row++, y1 = y2){
+ int xd;
+
y2 += e_table_model_row_height (eti->table_model, row) + 1;
if (y1 > y + height)
@@ -260,10 +296,12 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
if (eti->draw_grid)
gdk_draw_line (drawable, eti->grid_gc, 0, y - y2, width, y - y2);
+ xd = x_offset;
for (col = first_col; col < last_col; col++){
ETableCol *ecol = e_table_header_get_column (eti->header, col);
- draw_cell (eti, drawable, col, row, x_offset, y1 - y, x_offset + ecol->width, y2);
+ draw_cell (eti, drawable, col, row, xd, y1 - y, xd + ecol->width, y2);
+ xd += ecol->width;
}
}
}
diff --git a/widgets/e-table-item.h b/widgets/e-table-item.h
index 55893bb9ae..7e548cf49d 100644
--- a/widgets/e-table-item.h
+++ b/widgets/e-table-item.h
@@ -17,7 +17,7 @@ typedef struct {
ETableHeader *header;
int x1, y1;
- int height;
+ int width, height;
int top_item;
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog
index c77c3b22dd..107b2ee4a8 100644
--- a/widgets/e-table/ChangeLog
+++ b/widgets/e-table/ChangeLog
@@ -1,3 +1,19 @@
+1999-11-20 Miguel de Icaza <miguel@gnu.org>
+
+ * e-table-header-item.c (ethi_set_arg): Compute width, keep track
+ of it.
+ (ethi_add_table_header): Monitor changes to the Header model;
+ Queue updates.
+ (ethi_draw): Fix the redraw logic here.
+
+ * table-test.c (main): Change the sample code, so we can better
+ debug this.
+
+ * e-table-item.c (eti_header_structure_changed): Keep track of
+ width;
+ (eti_header_dim_changed): ditto.
+ (eti_draw): Many redraw fixes.
+
1999-11-19 Miguel de Icaza <miguel@gnu.org>
* e-table-item.c (eti_realize): Hook up; Load gcs.
diff --git a/widgets/e-table/e-table-header-item.c b/widgets/e-table/e-table-header-item.c
index b46f8511b0..dab5d3d71d 100644
--- a/widgets/e-table/e-table-header-item.c
+++ b/widgets/e-table/e-table-header-item.c
@@ -52,8 +52,8 @@ ethi_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags
item->x1 = ethi->x1;
item->y1 = ethi->y1;
- item->x2 = INT_MAX;
- item->y2 = ethi->x1 + ethi->height;
+ item->x2 = ethi->x1 + ethi->width;
+ item->y2 = ethi->y1 + ethi->height;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
}
@@ -72,6 +72,54 @@ ethi_font_load (ETableHeaderItem *ethi, char *font)
}
static void
+ethi_drop_table_header (ETableHeaderItem *ethi)
+{
+ GtkObject *header;
+
+ if (!ethi->eth)
+ return;
+
+ header = GTK_OBJECT (ethi->eth);
+ gtk_signal_disconnect (header, ethi->structure_change_id);
+ gtk_signal_disconnect (header, ethi->dimension_change_id);
+
+ gtk_object_unref (header);
+ ethi->eth = NULL;
+ ethi->width = 0;
+}
+
+static void
+structure_changed (ETableHeader *header, ETableHeaderItem *ethi)
+{
+ ethi->width = e_table_header_total_width (header);
+
+ ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0);
+}
+
+static void
+dimension_changed (ETableHeader *header, int col, ETableHeaderItem *ethi)
+{
+ ethi->width = e_table_header_total_width (header);
+
+ ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0);
+}
+
+static void
+ethi_add_table_header (ETableHeaderItem *ethi, ETableHeader *header)
+{
+ ethi->eth = header;
+ gtk_object_ref (GTK_OBJECT (ethi->eth));
+ ethi->width = e_table_header_total_width (header);
+
+ ethi->structure_change_id = gtk_signal_connect (
+ GTK_OBJECT (header), "structure_change",
+ GTK_SIGNAL_FUNC(structure_changed), ethi);
+ ethi->dimension_change_id = gtk_signal_connect (
+ GTK_OBJECT (header), "dimension_change",
+ GTK_SIGNAL_FUNC(dimension_changed), ethi);
+}
+
+static void
ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
GnomeCanvasItem *item;
@@ -83,8 +131,8 @@ ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_HEADER:
- ethi->eth = GTK_VALUE_POINTER (*arg);
- gtk_object_ref (GTK_OBJECT (ethi->eth));
+ ethi_drop_table_header (ethi);
+ ethi_add_table_header (ethi, GTK_VALUE_POINTER (*arg));
break;
case ARG_TABLE_X:
@@ -196,6 +244,9 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
total = 0;
x = -x1;
+ printf ("My coords are: %g %g %g %g\n",
+ item->x1, item->y1, item->x2, item->y2);
+
for (col = 0; col < cols; col++){
ETableCol *ecol = e_table_header_get_column (ethi->eth, col);
int col_width;
@@ -206,6 +257,7 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
col_width = ecol->width;
if (x1 > total + col_width){
+ total += col_width;
x += col_width;
continue;
}
@@ -217,9 +269,10 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
draw_button (ethi, ecol, drawable, gc,
GTK_WIDGET (canvas)->style,
- x, -y1, col_width, ethi->height);
+ x, ethi->y1 - y1, col_width, ethi->height);
x += col_width;
+ total += col_width;
}
}
@@ -292,7 +345,7 @@ ethi_request_redraw (ETableHeaderItem *ethi)
* request a redraw
*/
gnome_canvas_request_redraw (
- canvas, ethi->x1, ethi->y1, INT_MAX, ethi->x1 + ethi->height);
+ canvas, ethi->x1, ethi->y1, ethi->x1 + ethi->width, ethi->x1 + ethi->height);
}
static void
diff --git a/widgets/e-table/e-table-header-item.h b/widgets/e-table/e-table-header-item.h
index 45e8f8851d..d6b7d64a9f 100644
--- a/widgets/e-table/e-table-header-item.h
+++ b/widgets/e-table/e-table-header-item.h
@@ -17,7 +17,7 @@ typedef struct {
GdkGC *gc;
GdkCursor *change_cursor, *normal_cursor;
- short x1, y1, height;
+ short x1, y1, height, width;
GdkFont *font;
/*
@@ -27,6 +27,11 @@ typedef struct {
int resize_width;
int resize_start_pos;
GtkObject *resize_guide;
+
+ /*
+ * Ids
+ */
+ int structure_change_id, dimension_change_id;
} ETableHeaderItem;
typedef struct {
diff --git a/widgets/e-table/e-table-item.c b/widgets/e-table/e-table-item.c
index 8f7fa73725..7ddfc10405 100644
--- a/widgets/e-table/e-table-item.c
+++ b/widgets/e-table/e-table-item.c
@@ -31,8 +31,8 @@ eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
item->x1 = eti->x1;
item->y1 = eti->y1;
- item->x2 = INT_MAX;
- item->y2 = eti->x1 + eti->height;
+ item->x2 = eti->x1 + eti->width;
+ item->y2 = eti->y1 + eti->height;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
}
@@ -86,15 +86,29 @@ eti_add_table_model (ETableItem *eti, ETableModel *table_model)
}
static void
+eti_request_redraw (ETableItem *eti)
+{
+ GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas;
+
+ gnome_canvas_request_redraw (canvas, eti->x1, eti->y1, eti->x1 + eti->width, eti->y1 + eti->height);
+}
+
+static void
eti_header_dim_changed (ETableHeader *eth, int col, ETableItem *eti)
{
- printf ("NOTIFY: Dimension changed");
+ eti->width = e_table_header_total_width (eti->header);
+
+ eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0);
+ eti_request_redraw (eti);
}
static void
eti_header_structure_changed (ETableHeader *eth, ETableItem *eti)
{
- printf ("NOTIFY: Structure changed");
+ eti->width = e_table_header_total_width (eti->header);
+
+ eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0);
+ eti_request_redraw (eti);
}
static void
@@ -104,6 +118,8 @@ eti_add_header_model (ETableItem *eti, ETableHeader *header)
eti->header = header;
gtk_object_ref (GTK_OBJECT (header));
+
+ eti->width = e_table_header_total_width (header);
eti->header_dim_change_id = gtk_signal_connect (
GTK_OBJECT (header), "dimension_change",
@@ -203,7 +219,17 @@ static void
draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row,
int x1, int y1, int x2, int y2)
{
- gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2-x1, y2-y1);
+ GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas;
+ GdkFont *font;
+ char text [40];
+
+ font = GTK_WIDGET (canvas)->style->font;
+
+ sprintf (text, "%d:%d\n", col, row);
+ gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2);
+ gdk_draw_line (drawable, eti->grid_gc, x1, y2, x2, y1);
+
+ gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text));
}
static void
@@ -215,19 +241,20 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
int row, col, y1, y2;
int first_col, last_col, x_offset;
int x1, x2;
-
+
/*
* Clear the background
*/
gdk_draw_rectangle (
- drawable, eti->fill_gc, TRUE, 0, 0, width, height);
-
+ drawable, eti->fill_gc, TRUE,
+ eti->x1 - x, eti->y1 - y, eti->width, eti->height);
+
/*
* First column to draw, last column to draw
*/
- x1 = x_offset = 0;
first_col = -1;
- last_col = 0;
+ last_col = x_offset = 0;
+ x1 = eti->x1;
for (col = 0; col < cols; col++, x1 = x2){
ETableCol *ecol = e_table_header_get_column (eti->header, col);
@@ -238,17 +265,26 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
if (x2 < x)
continue;
if (first_col == -1){
- x_offset = x - x1;
+ x_offset = x1 - x;
first_col = col;
}
}
last_col = col;
/*
+ * Nothing to paint
+ */
+ if (first_col == -1)
+ return;
+
+ printf ("Cols %d %d\n", first_col, last_col);
+ /*
* Draw individual lines
*/
- y1 = y2 = 0;
+ y1 = y2 = eti->y1;
for (row = eti->top_item; row < rows; row++, y1 = y2){
+ int xd;
+
y2 += e_table_model_row_height (eti->table_model, row) + 1;
if (y1 > y + height)
@@ -260,10 +296,12 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
if (eti->draw_grid)
gdk_draw_line (drawable, eti->grid_gc, 0, y - y2, width, y - y2);
+ xd = x_offset;
for (col = first_col; col < last_col; col++){
ETableCol *ecol = e_table_header_get_column (eti->header, col);
- draw_cell (eti, drawable, col, row, x_offset, y1 - y, x_offset + ecol->width, y2);
+ draw_cell (eti, drawable, col, row, xd, y1 - y, xd + ecol->width, y2);
+ xd += ecol->width;
}
}
}
diff --git a/widgets/e-table/e-table-item.h b/widgets/e-table/e-table-item.h
index 55893bb9ae..7e548cf49d 100644
--- a/widgets/e-table/e-table-item.h
+++ b/widgets/e-table/e-table-item.h
@@ -17,7 +17,7 @@ typedef struct {
ETableHeader *header;
int x1, y1;
- int height;
+ int width, height;
int top_item;
diff --git a/widgets/e-table/table-test.c b/widgets/e-table/table-test.c
index 50fa8a7597..54392a73bc 100644
--- a/widgets/e-table/table-test.c
+++ b/widgets/e-table/table-test.c
@@ -226,15 +226,8 @@ main (int argc, char *argv [])
gnome_canvas_root (GNOME_CANVAS (canvas)),
e_table_header_item_get_type (),
"ETableHeader", e_table_header,
- NULL);
- gnome_canvas_item_new (
- gnome_canvas_root (GNOME_CANVAS (canvas)),
- gnome_canvas_rect_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", 10.0,
- "y2", 10.0,
- "fill_color", "red",
+ "x", 0,
+ "y", 0,
NULL);
gnome_canvas_item_new (
@@ -242,8 +235,8 @@ main (int argc, char *argv [])
e_table_item_get_type (),
"ETableHeader", e_table_header,
"ETableModel", e_table_model,
- "x", 0,
- "y", 30,
+ "x", 10,
+ "y", 30,
NULL);
gtk_main ();
diff --git a/widgets/table-test.c b/widgets/table-test.c
index 50fa8a7597..54392a73bc 100644
--- a/widgets/table-test.c
+++ b/widgets/table-test.c
@@ -226,15 +226,8 @@ main (int argc, char *argv [])
gnome_canvas_root (GNOME_CANVAS (canvas)),
e_table_header_item_get_type (),
"ETableHeader", e_table_header,
- NULL);
- gnome_canvas_item_new (
- gnome_canvas_root (GNOME_CANVAS (canvas)),
- gnome_canvas_rect_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", 10.0,
- "y2", 10.0,
- "fill_color", "red",
+ "x", 0,
+ "y", 0,
NULL);
gnome_canvas_item_new (
@@ -242,8 +235,8 @@ main (int argc, char *argv [])
e_table_item_get_type (),
"ETableHeader", e_table_header,
"ETableModel", e_table_model,
- "x", 0,
- "y", 30,
+ "x", 10,
+ "y", 30,
NULL);
gtk_main ();
diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c
index b46f8511b0..dab5d3d71d 100644
--- a/widgets/table/e-table-header-item.c
+++ b/widgets/table/e-table-header-item.c
@@ -52,8 +52,8 @@ ethi_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags
item->x1 = ethi->x1;
item->y1 = ethi->y1;
- item->x2 = INT_MAX;
- item->y2 = ethi->x1 + ethi->height;
+ item->x2 = ethi->x1 + ethi->width;
+ item->y2 = ethi->y1 + ethi->height;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
}
@@ -72,6 +72,54 @@ ethi_font_load (ETableHeaderItem *ethi, char *font)
}
static void
+ethi_drop_table_header (ETableHeaderItem *ethi)
+{
+ GtkObject *header;
+
+ if (!ethi->eth)
+ return;
+
+ header = GTK_OBJECT (ethi->eth);
+ gtk_signal_disconnect (header, ethi->structure_change_id);
+ gtk_signal_disconnect (header, ethi->dimension_change_id);
+
+ gtk_object_unref (header);
+ ethi->eth = NULL;
+ ethi->width = 0;
+}
+
+static void
+structure_changed (ETableHeader *header, ETableHeaderItem *ethi)
+{
+ ethi->width = e_table_header_total_width (header);
+
+ ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0);
+}
+
+static void
+dimension_changed (ETableHeader *header, int col, ETableHeaderItem *ethi)
+{
+ ethi->width = e_table_header_total_width (header);
+
+ ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0);
+}
+
+static void
+ethi_add_table_header (ETableHeaderItem *ethi, ETableHeader *header)
+{
+ ethi->eth = header;
+ gtk_object_ref (GTK_OBJECT (ethi->eth));
+ ethi->width = e_table_header_total_width (header);
+
+ ethi->structure_change_id = gtk_signal_connect (
+ GTK_OBJECT (header), "structure_change",
+ GTK_SIGNAL_FUNC(structure_changed), ethi);
+ ethi->dimension_change_id = gtk_signal_connect (
+ GTK_OBJECT (header), "dimension_change",
+ GTK_SIGNAL_FUNC(dimension_changed), ethi);
+}
+
+static void
ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
GnomeCanvasItem *item;
@@ -83,8 +131,8 @@ ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_TABLE_HEADER:
- ethi->eth = GTK_VALUE_POINTER (*arg);
- gtk_object_ref (GTK_OBJECT (ethi->eth));
+ ethi_drop_table_header (ethi);
+ ethi_add_table_header (ethi, GTK_VALUE_POINTER (*arg));
break;
case ARG_TABLE_X:
@@ -196,6 +244,9 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
total = 0;
x = -x1;
+ printf ("My coords are: %g %g %g %g\n",
+ item->x1, item->y1, item->x2, item->y2);
+
for (col = 0; col < cols; col++){
ETableCol *ecol = e_table_header_get_column (ethi->eth, col);
int col_width;
@@ -206,6 +257,7 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
col_width = ecol->width;
if (x1 > total + col_width){
+ total += col_width;
x += col_width;
continue;
}
@@ -217,9 +269,10 @@ ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int wid
draw_button (ethi, ecol, drawable, gc,
GTK_WIDGET (canvas)->style,
- x, -y1, col_width, ethi->height);
+ x, ethi->y1 - y1, col_width, ethi->height);
x += col_width;
+ total += col_width;
}
}
@@ -292,7 +345,7 @@ ethi_request_redraw (ETableHeaderItem *ethi)
* request a redraw
*/
gnome_canvas_request_redraw (
- canvas, ethi->x1, ethi->y1, INT_MAX, ethi->x1 + ethi->height);
+ canvas, ethi->x1, ethi->y1, ethi->x1 + ethi->width, ethi->x1 + ethi->height);
}
static void
diff --git a/widgets/table/e-table-header-item.h b/widgets/table/e-table-header-item.h
index 45e8f8851d..d6b7d64a9f 100644
--- a/widgets/table/e-table-header-item.h
+++ b/widgets/table/e-table-header-item.h
@@ -17,7 +17,7 @@ typedef struct {
GdkGC *gc;
GdkCursor *change_cursor, *normal_cursor;
- short x1, y1, height;
+ short x1, y1, height, width;
GdkFont *font;
/*
@@ -27,6 +27,11 @@ typedef struct {
int resize_width;
int resize_start_pos;
GtkObject *resize_guide;
+
+ /*
+ * Ids
+ */
+ int structure_change_id, dimension_change_id;
} ETableHeaderItem;
typedef struct {
diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c
index 8f7fa73725..7ddfc10405 100644
--- a/widgets/table/e-table-item.c
+++ b/widgets/table/e-table-item.c
@@ -31,8 +31,8 @@ eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
item->x1 = eti->x1;
item->y1 = eti->y1;
- item->x2 = INT_MAX;
- item->y2 = eti->x1 + eti->height;
+ item->x2 = eti->x1 + eti->width;
+ item->y2 = eti->y1 + eti->height;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
}
@@ -86,15 +86,29 @@ eti_add_table_model (ETableItem *eti, ETableModel *table_model)
}
static void
+eti_request_redraw (ETableItem *eti)
+{
+ GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas;
+
+ gnome_canvas_request_redraw (canvas, eti->x1, eti->y1, eti->x1 + eti->width, eti->y1 + eti->height);
+}
+
+static void
eti_header_dim_changed (ETableHeader *eth, int col, ETableItem *eti)
{
- printf ("NOTIFY: Dimension changed");
+ eti->width = e_table_header_total_width (eti->header);
+
+ eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0);
+ eti_request_redraw (eti);
}
static void
eti_header_structure_changed (ETableHeader *eth, ETableItem *eti)
{
- printf ("NOTIFY: Structure changed");
+ eti->width = e_table_header_total_width (eti->header);
+
+ eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0);
+ eti_request_redraw (eti);
}
static void
@@ -104,6 +118,8 @@ eti_add_header_model (ETableItem *eti, ETableHeader *header)
eti->header = header;
gtk_object_ref (GTK_OBJECT (header));
+
+ eti->width = e_table_header_total_width (header);
eti->header_dim_change_id = gtk_signal_connect (
GTK_OBJECT (header), "dimension_change",
@@ -203,7 +219,17 @@ static void
draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row,
int x1, int y1, int x2, int y2)
{
- gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2-x1, y2-y1);
+ GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas;
+ GdkFont *font;
+ char text [40];
+
+ font = GTK_WIDGET (canvas)->style->font;
+
+ sprintf (text, "%d:%d\n", col, row);
+ gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2);
+ gdk_draw_line (drawable, eti->grid_gc, x1, y2, x2, y1);
+
+ gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text));
}
static void
@@ -215,19 +241,20 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
int row, col, y1, y2;
int first_col, last_col, x_offset;
int x1, x2;
-
+
/*
* Clear the background
*/
gdk_draw_rectangle (
- drawable, eti->fill_gc, TRUE, 0, 0, width, height);
-
+ drawable, eti->fill_gc, TRUE,
+ eti->x1 - x, eti->y1 - y, eti->width, eti->height);
+
/*
* First column to draw, last column to draw
*/
- x1 = x_offset = 0;
first_col = -1;
- last_col = 0;
+ last_col = x_offset = 0;
+ x1 = eti->x1;
for (col = 0; col < cols; col++, x1 = x2){
ETableCol *ecol = e_table_header_get_column (eti->header, col);
@@ -238,17 +265,26 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
if (x2 < x)
continue;
if (first_col == -1){
- x_offset = x - x1;
+ x_offset = x1 - x;
first_col = col;
}
}
last_col = col;
/*
+ * Nothing to paint
+ */
+ if (first_col == -1)
+ return;
+
+ printf ("Cols %d %d\n", first_col, last_col);
+ /*
* Draw individual lines
*/
- y1 = y2 = 0;
+ y1 = y2 = eti->y1;
for (row = eti->top_item; row < rows; row++, y1 = y2){
+ int xd;
+
y2 += e_table_model_row_height (eti->table_model, row) + 1;
if (y1 > y + height)
@@ -260,10 +296,12 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
if (eti->draw_grid)
gdk_draw_line (drawable, eti->grid_gc, 0, y - y2, width, y - y2);
+ xd = x_offset;
for (col = first_col; col < last_col; col++){
ETableCol *ecol = e_table_header_get_column (eti->header, col);
- draw_cell (eti, drawable, col, row, x_offset, y1 - y, x_offset + ecol->width, y2);
+ draw_cell (eti, drawable, col, row, xd, y1 - y, xd + ecol->width, y2);
+ xd += ecol->width;
}
}
}
diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h
index 55893bb9ae..7e548cf49d 100644
--- a/widgets/table/e-table-item.h
+++ b/widgets/table/e-table-item.h
@@ -17,7 +17,7 @@ typedef struct {
ETableHeader *header;
int x1, y1;
- int height;
+ int width, height;
int top_item;
diff --git a/widgets/table/table-test.c b/widgets/table/table-test.c
index 50fa8a7597..54392a73bc 100644
--- a/widgets/table/table-test.c
+++ b/widgets/table/table-test.c
@@ -226,15 +226,8 @@ main (int argc, char *argv [])
gnome_canvas_root (GNOME_CANVAS (canvas)),
e_table_header_item_get_type (),
"ETableHeader", e_table_header,
- NULL);
- gnome_canvas_item_new (
- gnome_canvas_root (GNOME_CANVAS (canvas)),
- gnome_canvas_rect_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", 10.0,
- "y2", 10.0,
- "fill_color", "red",
+ "x", 0,
+ "y", 0,
NULL);
gnome_canvas_item_new (
@@ -242,8 +235,8 @@ main (int argc, char *argv [])
e_table_item_get_type (),
"ETableHeader", e_table_header,
"ETableModel", e_table_model,
- "x", 0,
- "y", 30,
+ "x", 10,
+ "y", 30,
NULL);
gtk_main ();