diff options
Diffstat (limited to 'widgets')
27 files changed, 249 insertions, 162 deletions
diff --git a/widgets/e-cell-text.c b/widgets/e-cell-text.c index 1b3f524a2e..49ffa153a7 100644 --- a/widgets/e-cell-text.c +++ b/widgets/e-cell-text.c @@ -54,6 +54,7 @@ static void ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1, int y1, int x2, int y2) { ECellText *ect = E_CELL_TEXT (ecell_view->ecell); + ECellTextView *text_view = (ECellTextView *) ecell_view; GdkRectangle rect; const char *str = e_table_model_value_at (ecell_view->ecell->table_model, col, row); int selected = e_table_model_get_selected_row (ecell_view->ecell->table_model) == row; @@ -64,20 +65,22 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 rect.width = x2 - x1; rect.height = y2 - y1; - gdk_gc_set_clip_rectangle (ect->gc, &rect); + gdk_gc_set_clip_rectangle (text_view->gc, &rect); + printf ("String is: [%s]\n", str); + switch (ect->justify){ case GTK_JUSTIFY_LEFT: xoff = 1; break; case GTK_JUSTIFY_RIGHT: - w = 1 + gdk_text_width (ect->font, str, strlen (str)); + w = 1 + gdk_text_width (text_view->font, str, strlen (str)); xoff = (x2 - x1) - w; break; case GTK_JUSTIFY_CENTER: - xoff = ((x2 - x1) - gdk_text_width (ect->font, str, strlen (str))) / 2; + xoff = ((x2 - x1) - gdk_text_width (text_view->font, str, strlen (str))) / 2; break; default: g_warning ("Can not handle GTK_JUSTIFY_FILL"); @@ -86,7 +89,7 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 /* Draw now */ { - GtkWidget *w = GTK_WIDGET (ect->canvas); + GtkWidget *w = GTK_WIDGET (text_view->canvas); GdkColor *background; int idx; @@ -95,10 +98,12 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 else idx = GTK_STATE_NORMAL; - gdk_gc_set_foreground (ect->gc, &w->style->bg [idx]); - gdk_draw_rectangle (drawable, ect->gc, TRUE, rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (ect->gc, &w->style->fg [idx]); - gdk_draw_string (drawable, ect->font, ect->gc, x1 + xoff, y2 + ect->font->descent, str); + gdk_gc_set_foreground (text_view->gc, &w->style->bg [idx]); + gdk_draw_rectangle (drawable, text_view->gc, TRUE, + rect.x, rect.y, rect.width, rect.height); + gdk_gc_set_foreground (text_view->gc, &w->style->fg [idx]); + gdk_draw_string (drawable, text_view->font, text_view->gc, + x1 + xoff, y2 - text_view->font->descent, str); } } @@ -152,12 +157,13 @@ e_cell_text_class_init (GtkObjectClass *object_class) E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, NULL, PARENT_TYPE); ECell * -e_cell_text_new (const char *fontname, GtkJustification justify) +e_cell_text_new (ETableModel *etm, const char *fontname, GtkJustification justify) { ECellText *ect = gtk_type_new (e_cell_text_get_type ()); ect->font_name = g_strdup (fontname); ect->justify = justify; - + E_CELL (ect)->table_model = etm; + return (ECell *) ect; } diff --git a/widgets/e-cell-text.h b/widgets/e-cell-text.h index 24def9f0f8..de9629b97b 100644 --- a/widgets/e-cell-text.h +++ b/widgets/e-cell-text.h @@ -13,12 +13,8 @@ typedef struct { ECell parent; - GdkGC *gc; - GdkFont *font; GtkJustification justify; - char *font_name; - GnomeCanvas *canvas; } ECellText; typedef struct { @@ -26,6 +22,7 @@ typedef struct { } ECellTextClass; GtkType e_cell_text_get_type (void); -ECell *e_cell_text_new (const char *fontname, GtkJustification justify); +ECell *e_cell_text_new (ETableModel *model, const char *fontname, GtkJustification justify); #endif /* _E_CELL_TEXT_H_ */ + diff --git a/widgets/e-cell.h b/widgets/e-cell.h index 0cafe0fff4..08efaa6649 100644 --- a/widgets/e-cell.h +++ b/widgets/e-cell.h @@ -15,7 +15,6 @@ typedef struct _ECellView ECellView; struct _ECell { GtkObject object; - ETableModel *table_model; }; diff --git a/widgets/e-table-col.h b/widgets/e-table-col.h index 950bf23352..582c4eb383 100644 --- a/widgets/e-table-col.h +++ b/widgets/e-table-col.h @@ -1,8 +1,9 @@ #ifndef _E_TABLE_COL_H_ #define _E_TABLE_COL_H_ +#include "e-cell.h" + typedef struct _ETableCol ETableCol; -typedef struct _ECell ECell; /* * Information about a single column diff --git a/widgets/e-table-header-item.c b/widgets/e-table-header-item.c index ab59d9a01c..1092874b9e 100644 --- a/widgets/e-table-header-item.c +++ b/widgets/e-table-header-item.c @@ -157,7 +157,6 @@ ethi_realize (GnomeCanvasItem *item) ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); GdkWindow *window; GdkColor c; - int i; if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)-> realize) (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->realize)(item); @@ -172,26 +171,12 @@ ethi_realize (GnomeCanvasItem *item) if (!ethi->font) ethi_font_load (ethi, "fixed"); - - /* - * Now realize the various ECells - */ - ethi->n_cells = e_table_header_count (ethi->eth); - ethi->cell_views = g_new (ECellView *, ethi->n_cells); - - for (i = 0; i < ethi->n_cells; i++){ - ETableCol *col = e_table_header_get_column (ethi->eth, i); - - ethi->cell_views [i] = e_cell_realize (col->ecell, item->canvas); - } - } static void ethi_unrealize (GnomeCanvasItem *item) { ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - int i; gdk_gc_unref (ethi->gc); ethi->gc = NULL; @@ -202,14 +187,6 @@ ethi_unrealize (GnomeCanvasItem *item) gdk_cursor_destroy (ethi->normal_cursor); ethi->normal_cursor = NULL; - for (i = 0; i < ethi->n_cells; i++){ - ETableCol *col = e_table_header_get_column (ethi->eth, i); - - e_cell_unrealize (col->ecell, ethi->cell_views [i]); - ethi->cell_views = NULL; - } - g_free (ethi->cell_views); - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); } diff --git a/widgets/e-table-header-item.h b/widgets/e-table-header-item.h index 10b84e1897..d6b7d64a9f 100644 --- a/widgets/e-table-header-item.h +++ b/widgets/e-table-header-item.h @@ -10,8 +10,6 @@ #define E_IS_TABLE_HEADER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_ITEM_TYPE)) #define E_IS_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_ITEM_TYPE)) -typedef struct _ECellView ECellView; - typedef struct { GnomeCanvasItem parent; ETableHeader *eth; @@ -30,9 +28,6 @@ typedef struct { int resize_start_pos; GtkObject *resize_guide; - ECellView **cell_views; - int n_cells; - /* * Ids */ diff --git a/widgets/e-table-item.c b/widgets/e-table-item.c index 5bf1e24fd0..387bb520bd 100644 --- a/widgets/e-table-item.c +++ b/widgets/e-table-item.c @@ -8,6 +8,7 @@ */ #include <config.h> #include "e-table-item.h" +#include "e-cell.h" #define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () @@ -22,6 +23,41 @@ enum { }; static void +eti_realize_cell_views (ETableItem *eti) +{ + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); + int i; + + /* + * Now realize the various ECells + */ + eti->n_cells = e_table_header_count (eti->header); + eti->cell_views = g_new (ECellView *, eti->n_cells); + + for (i = 0; i < eti->n_cells; i++){ + ETableCol *col = e_table_header_get_column (eti->header, i); + + eti->cell_views [i] = e_cell_realize (col->ecell, item->canvas); + } +} + +static void +eti_unrealize_cell_views (ETableItem *eti) +{ + int i; + + for (i = 0; i < eti->n_cells; i++){ + ETableCol *col = e_table_header_get_column (eti->header, i); + + e_cell_unrealize (eti->cell_views [i]); + eti->cell_views [i] = NULL; + } + g_free (eti->cell_views); + eti->n_cells = 0; + +} + +static void eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) { ETableItem *eti = E_TABLE_ITEM (item); @@ -124,6 +160,8 @@ eti_header_structure_changed (ETableHeader *eth, ETableItem *eti) eti_request_redraw (eti); eti->width = e_table_header_total_width (eti->header); + eti_unrealize_cell_views (eti); + eti_realize_cell_views (eti); eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); eti_request_redraw (eti); @@ -210,7 +248,7 @@ eti_realize (GnomeCanvasItem *item) ETableItem *eti = E_TABLE_ITEM (item); GtkWidget *canvas_widget = GTK_WIDGET (item->canvas); GdkWindow *window; - + if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); @@ -221,17 +259,20 @@ eti_realize (GnomeCanvasItem *item) eti->grid_gc = gdk_gc_new (window); gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); + eti_realize_cell_views (eti); } static void eti_unrealize (GnomeCanvasItem *item) { ETableItem *eti = E_TABLE_ITEM (item); - + gdk_gc_unref (eti->fill_gc); eti->fill_gc = NULL; gdk_gc_unref (eti->grid_gc); eti->grid_gc = NULL; + + eti_unrealize_cell_views (eti); if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); @@ -242,16 +283,23 @@ draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row, int x1, int y1, int x2, int y2) { GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; + ECellView *ecell_view; GdkFont *font; char text [40]; font = GTK_WIDGET (canvas)->style->font; - - sprintf (text, "%d:%d\n", col, row); + + ecell_view = eti->cell_views [col]; + + e_cell_draw (ecell_view, drawable, col, row, x1, y1, x2, y2); + gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2); gdk_draw_line (drawable, eti->grid_gc, x1, y2, x2, y1); +#if 0 + sprintf (text, "%d:%d\n", col, row); gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text)); +#endif } static void @@ -344,7 +392,7 @@ static int eti_event (GnomeCanvasItem *item, GdkEvent *e) { ETableItem *eti = E_TABLE_ITEM (item); - ETableCol *etc; + ECellView *ecell_view; switch (e->type){ case GDK_BUTTON_PRESS: @@ -356,9 +404,9 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) if (eti->focused_col == -1) return FALSE; - etc = e_table_header_get_column (eti->header, eti->focused_col); + ecell_view = eti->cell_views [eti->focused_col]; - e_cell_event (etc->ecell, e, eti->focused_col, eti->focused_row); + e_cell_event (ecell_view, e, eti->focused_col, eti->focused_row); break; } diff --git a/widgets/e-table-item.h b/widgets/e-table-item.h index fefa221227..d694e62d68 100644 --- a/widgets/e-table-item.h +++ b/widgets/e-table-item.h @@ -35,6 +35,12 @@ typedef struct { unsigned int draw_grid:1; int focused_col, focused_row; + + /* + * Realized views, per column + */ + ECellView **cell_views; + int n_cells; } ETableItem; typedef struct { diff --git a/widgets/e-table/e-cell-text.c b/widgets/e-table/e-cell-text.c index 1b3f524a2e..49ffa153a7 100644 --- a/widgets/e-table/e-cell-text.c +++ b/widgets/e-table/e-cell-text.c @@ -54,6 +54,7 @@ static void ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1, int y1, int x2, int y2) { ECellText *ect = E_CELL_TEXT (ecell_view->ecell); + ECellTextView *text_view = (ECellTextView *) ecell_view; GdkRectangle rect; const char *str = e_table_model_value_at (ecell_view->ecell->table_model, col, row); int selected = e_table_model_get_selected_row (ecell_view->ecell->table_model) == row; @@ -64,20 +65,22 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 rect.width = x2 - x1; rect.height = y2 - y1; - gdk_gc_set_clip_rectangle (ect->gc, &rect); + gdk_gc_set_clip_rectangle (text_view->gc, &rect); + printf ("String is: [%s]\n", str); + switch (ect->justify){ case GTK_JUSTIFY_LEFT: xoff = 1; break; case GTK_JUSTIFY_RIGHT: - w = 1 + gdk_text_width (ect->font, str, strlen (str)); + w = 1 + gdk_text_width (text_view->font, str, strlen (str)); xoff = (x2 - x1) - w; break; case GTK_JUSTIFY_CENTER: - xoff = ((x2 - x1) - gdk_text_width (ect->font, str, strlen (str))) / 2; + xoff = ((x2 - x1) - gdk_text_width (text_view->font, str, strlen (str))) / 2; break; default: g_warning ("Can not handle GTK_JUSTIFY_FILL"); @@ -86,7 +89,7 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 /* Draw now */ { - GtkWidget *w = GTK_WIDGET (ect->canvas); + GtkWidget *w = GTK_WIDGET (text_view->canvas); GdkColor *background; int idx; @@ -95,10 +98,12 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 else idx = GTK_STATE_NORMAL; - gdk_gc_set_foreground (ect->gc, &w->style->bg [idx]); - gdk_draw_rectangle (drawable, ect->gc, TRUE, rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (ect->gc, &w->style->fg [idx]); - gdk_draw_string (drawable, ect->font, ect->gc, x1 + xoff, y2 + ect->font->descent, str); + gdk_gc_set_foreground (text_view->gc, &w->style->bg [idx]); + gdk_draw_rectangle (drawable, text_view->gc, TRUE, + rect.x, rect.y, rect.width, rect.height); + gdk_gc_set_foreground (text_view->gc, &w->style->fg [idx]); + gdk_draw_string (drawable, text_view->font, text_view->gc, + x1 + xoff, y2 - text_view->font->descent, str); } } @@ -152,12 +157,13 @@ e_cell_text_class_init (GtkObjectClass *object_class) E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, NULL, PARENT_TYPE); ECell * -e_cell_text_new (const char *fontname, GtkJustification justify) +e_cell_text_new (ETableModel *etm, const char *fontname, GtkJustification justify) { ECellText *ect = gtk_type_new (e_cell_text_get_type ()); ect->font_name = g_strdup (fontname); ect->justify = justify; - + E_CELL (ect)->table_model = etm; + return (ECell *) ect; } diff --git a/widgets/e-table/e-cell-text.h b/widgets/e-table/e-cell-text.h index 24def9f0f8..de9629b97b 100644 --- a/widgets/e-table/e-cell-text.h +++ b/widgets/e-table/e-cell-text.h @@ -13,12 +13,8 @@ typedef struct { ECell parent; - GdkGC *gc; - GdkFont *font; GtkJustification justify; - char *font_name; - GnomeCanvas *canvas; } ECellText; typedef struct { @@ -26,6 +22,7 @@ typedef struct { } ECellTextClass; GtkType e_cell_text_get_type (void); -ECell *e_cell_text_new (const char *fontname, GtkJustification justify); +ECell *e_cell_text_new (ETableModel *model, const char *fontname, GtkJustification justify); #endif /* _E_CELL_TEXT_H_ */ + diff --git a/widgets/e-table/e-cell.h b/widgets/e-table/e-cell.h index 0cafe0fff4..08efaa6649 100644 --- a/widgets/e-table/e-cell.h +++ b/widgets/e-table/e-cell.h @@ -15,7 +15,6 @@ typedef struct _ECellView ECellView; struct _ECell { GtkObject object; - ETableModel *table_model; }; diff --git a/widgets/e-table/e-table-col.h b/widgets/e-table/e-table-col.h index 950bf23352..582c4eb383 100644 --- a/widgets/e-table/e-table-col.h +++ b/widgets/e-table/e-table-col.h @@ -1,8 +1,9 @@ #ifndef _E_TABLE_COL_H_ #define _E_TABLE_COL_H_ +#include "e-cell.h" + typedef struct _ETableCol ETableCol; -typedef struct _ECell ECell; /* * Information about a single column diff --git a/widgets/e-table/e-table-header-item.c b/widgets/e-table/e-table-header-item.c index ab59d9a01c..1092874b9e 100644 --- a/widgets/e-table/e-table-header-item.c +++ b/widgets/e-table/e-table-header-item.c @@ -157,7 +157,6 @@ ethi_realize (GnomeCanvasItem *item) ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); GdkWindow *window; GdkColor c; - int i; if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)-> realize) (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->realize)(item); @@ -172,26 +171,12 @@ ethi_realize (GnomeCanvasItem *item) if (!ethi->font) ethi_font_load (ethi, "fixed"); - - /* - * Now realize the various ECells - */ - ethi->n_cells = e_table_header_count (ethi->eth); - ethi->cell_views = g_new (ECellView *, ethi->n_cells); - - for (i = 0; i < ethi->n_cells; i++){ - ETableCol *col = e_table_header_get_column (ethi->eth, i); - - ethi->cell_views [i] = e_cell_realize (col->ecell, item->canvas); - } - } static void ethi_unrealize (GnomeCanvasItem *item) { ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - int i; gdk_gc_unref (ethi->gc); ethi->gc = NULL; @@ -202,14 +187,6 @@ ethi_unrealize (GnomeCanvasItem *item) gdk_cursor_destroy (ethi->normal_cursor); ethi->normal_cursor = NULL; - for (i = 0; i < ethi->n_cells; i++){ - ETableCol *col = e_table_header_get_column (ethi->eth, i); - - e_cell_unrealize (col->ecell, ethi->cell_views [i]); - ethi->cell_views = NULL; - } - g_free (ethi->cell_views); - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); } diff --git a/widgets/e-table/e-table-header-item.h b/widgets/e-table/e-table-header-item.h index 10b84e1897..d6b7d64a9f 100644 --- a/widgets/e-table/e-table-header-item.h +++ b/widgets/e-table/e-table-header-item.h @@ -10,8 +10,6 @@ #define E_IS_TABLE_HEADER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_ITEM_TYPE)) #define E_IS_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_ITEM_TYPE)) -typedef struct _ECellView ECellView; - typedef struct { GnomeCanvasItem parent; ETableHeader *eth; @@ -30,9 +28,6 @@ typedef struct { int resize_start_pos; GtkObject *resize_guide; - ECellView **cell_views; - int n_cells; - /* * Ids */ diff --git a/widgets/e-table/e-table-item.c b/widgets/e-table/e-table-item.c index 5bf1e24fd0..387bb520bd 100644 --- a/widgets/e-table/e-table-item.c +++ b/widgets/e-table/e-table-item.c @@ -8,6 +8,7 @@ */ #include <config.h> #include "e-table-item.h" +#include "e-cell.h" #define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () @@ -22,6 +23,41 @@ enum { }; static void +eti_realize_cell_views (ETableItem *eti) +{ + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); + int i; + + /* + * Now realize the various ECells + */ + eti->n_cells = e_table_header_count (eti->header); + eti->cell_views = g_new (ECellView *, eti->n_cells); + + for (i = 0; i < eti->n_cells; i++){ + ETableCol *col = e_table_header_get_column (eti->header, i); + + eti->cell_views [i] = e_cell_realize (col->ecell, item->canvas); + } +} + +static void +eti_unrealize_cell_views (ETableItem *eti) +{ + int i; + + for (i = 0; i < eti->n_cells; i++){ + ETableCol *col = e_table_header_get_column (eti->header, i); + + e_cell_unrealize (eti->cell_views [i]); + eti->cell_views [i] = NULL; + } + g_free (eti->cell_views); + eti->n_cells = 0; + +} + +static void eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) { ETableItem *eti = E_TABLE_ITEM (item); @@ -124,6 +160,8 @@ eti_header_structure_changed (ETableHeader *eth, ETableItem *eti) eti_request_redraw (eti); eti->width = e_table_header_total_width (eti->header); + eti_unrealize_cell_views (eti); + eti_realize_cell_views (eti); eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); eti_request_redraw (eti); @@ -210,7 +248,7 @@ eti_realize (GnomeCanvasItem *item) ETableItem *eti = E_TABLE_ITEM (item); GtkWidget *canvas_widget = GTK_WIDGET (item->canvas); GdkWindow *window; - + if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); @@ -221,17 +259,20 @@ eti_realize (GnomeCanvasItem *item) eti->grid_gc = gdk_gc_new (window); gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); + eti_realize_cell_views (eti); } static void eti_unrealize (GnomeCanvasItem *item) { ETableItem *eti = E_TABLE_ITEM (item); - + gdk_gc_unref (eti->fill_gc); eti->fill_gc = NULL; gdk_gc_unref (eti->grid_gc); eti->grid_gc = NULL; + + eti_unrealize_cell_views (eti); if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); @@ -242,16 +283,23 @@ draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row, int x1, int y1, int x2, int y2) { GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; + ECellView *ecell_view; GdkFont *font; char text [40]; font = GTK_WIDGET (canvas)->style->font; - - sprintf (text, "%d:%d\n", col, row); + + ecell_view = eti->cell_views [col]; + + e_cell_draw (ecell_view, drawable, col, row, x1, y1, x2, y2); + gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2); gdk_draw_line (drawable, eti->grid_gc, x1, y2, x2, y1); +#if 0 + sprintf (text, "%d:%d\n", col, row); gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text)); +#endif } static void @@ -344,7 +392,7 @@ static int eti_event (GnomeCanvasItem *item, GdkEvent *e) { ETableItem *eti = E_TABLE_ITEM (item); - ETableCol *etc; + ECellView *ecell_view; switch (e->type){ case GDK_BUTTON_PRESS: @@ -356,9 +404,9 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) if (eti->focused_col == -1) return FALSE; - etc = e_table_header_get_column (eti->header, eti->focused_col); + ecell_view = eti->cell_views [eti->focused_col]; - e_cell_event (etc->ecell, e, eti->focused_col, eti->focused_row); + e_cell_event (ecell_view, e, eti->focused_col, eti->focused_row); break; } diff --git a/widgets/e-table/e-table-item.h b/widgets/e-table/e-table-item.h index fefa221227..d694e62d68 100644 --- a/widgets/e-table/e-table-item.h +++ b/widgets/e-table/e-table-item.h @@ -35,6 +35,12 @@ typedef struct { unsigned int draw_grid:1; int focused_col, focused_row; + + /* + * Realized views, per column + */ + ECellView **cell_views; + int n_cells; } ETableItem; typedef struct { diff --git a/widgets/e-table/table-test.c b/widgets/e-table/table-test.c index e646b44655..4917511261 100644 --- a/widgets/e-table/table-test.c +++ b/widgets/e-table/table-test.c @@ -145,7 +145,7 @@ value_at (ETableModel *etc, int col, int row, void *data) g_assert (col < cols); g_assert (row < lines); - return (void *) &table_data [row][col]; + return (void *) table_data [row][col]; } static void @@ -203,7 +203,7 @@ main (int argc, char *argv []) * Header */ e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new ("fixed", GTK_JUSTIFY_LEFT); + cell_left_just = e_cell_text_new (e_table_model, "fixed", GTK_JUSTIFY_LEFT); for (i = 0; i < cols; i++){ ETableCol *ecol = e_table_col_new ( diff --git a/widgets/table-test.c b/widgets/table-test.c index e646b44655..4917511261 100644 --- a/widgets/table-test.c +++ b/widgets/table-test.c @@ -145,7 +145,7 @@ value_at (ETableModel *etc, int col, int row, void *data) g_assert (col < cols); g_assert (row < lines); - return (void *) &table_data [row][col]; + return (void *) table_data [row][col]; } static void @@ -203,7 +203,7 @@ main (int argc, char *argv []) * Header */ e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new ("fixed", GTK_JUSTIFY_LEFT); + cell_left_just = e_cell_text_new (e_table_model, "fixed", GTK_JUSTIFY_LEFT); for (i = 0; i < cols; i++){ ETableCol *ecol = e_table_col_new ( diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c index 1b3f524a2e..49ffa153a7 100644 --- a/widgets/table/e-cell-text.c +++ b/widgets/table/e-cell-text.c @@ -54,6 +54,7 @@ static void ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1, int y1, int x2, int y2) { ECellText *ect = E_CELL_TEXT (ecell_view->ecell); + ECellTextView *text_view = (ECellTextView *) ecell_view; GdkRectangle rect; const char *str = e_table_model_value_at (ecell_view->ecell->table_model, col, row); int selected = e_table_model_get_selected_row (ecell_view->ecell->table_model) == row; @@ -64,20 +65,22 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 rect.width = x2 - x1; rect.height = y2 - y1; - gdk_gc_set_clip_rectangle (ect->gc, &rect); + gdk_gc_set_clip_rectangle (text_view->gc, &rect); + printf ("String is: [%s]\n", str); + switch (ect->justify){ case GTK_JUSTIFY_LEFT: xoff = 1; break; case GTK_JUSTIFY_RIGHT: - w = 1 + gdk_text_width (ect->font, str, strlen (str)); + w = 1 + gdk_text_width (text_view->font, str, strlen (str)); xoff = (x2 - x1) - w; break; case GTK_JUSTIFY_CENTER: - xoff = ((x2 - x1) - gdk_text_width (ect->font, str, strlen (str))) / 2; + xoff = ((x2 - x1) - gdk_text_width (text_view->font, str, strlen (str))) / 2; break; default: g_warning ("Can not handle GTK_JUSTIFY_FILL"); @@ -86,7 +89,7 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 /* Draw now */ { - GtkWidget *w = GTK_WIDGET (ect->canvas); + GtkWidget *w = GTK_WIDGET (text_view->canvas); GdkColor *background; int idx; @@ -95,10 +98,12 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 else idx = GTK_STATE_NORMAL; - gdk_gc_set_foreground (ect->gc, &w->style->bg [idx]); - gdk_draw_rectangle (drawable, ect->gc, TRUE, rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (ect->gc, &w->style->fg [idx]); - gdk_draw_string (drawable, ect->font, ect->gc, x1 + xoff, y2 + ect->font->descent, str); + gdk_gc_set_foreground (text_view->gc, &w->style->bg [idx]); + gdk_draw_rectangle (drawable, text_view->gc, TRUE, + rect.x, rect.y, rect.width, rect.height); + gdk_gc_set_foreground (text_view->gc, &w->style->fg [idx]); + gdk_draw_string (drawable, text_view->font, text_view->gc, + x1 + xoff, y2 - text_view->font->descent, str); } } @@ -152,12 +157,13 @@ e_cell_text_class_init (GtkObjectClass *object_class) E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, NULL, PARENT_TYPE); ECell * -e_cell_text_new (const char *fontname, GtkJustification justify) +e_cell_text_new (ETableModel *etm, const char *fontname, GtkJustification justify) { ECellText *ect = gtk_type_new (e_cell_text_get_type ()); ect->font_name = g_strdup (fontname); ect->justify = justify; - + E_CELL (ect)->table_model = etm; + return (ECell *) ect; } diff --git a/widgets/table/e-cell-text.h b/widgets/table/e-cell-text.h index 24def9f0f8..de9629b97b 100644 --- a/widgets/table/e-cell-text.h +++ b/widgets/table/e-cell-text.h @@ -13,12 +13,8 @@ typedef struct { ECell parent; - GdkGC *gc; - GdkFont *font; GtkJustification justify; - char *font_name; - GnomeCanvas *canvas; } ECellText; typedef struct { @@ -26,6 +22,7 @@ typedef struct { } ECellTextClass; GtkType e_cell_text_get_type (void); -ECell *e_cell_text_new (const char *fontname, GtkJustification justify); +ECell *e_cell_text_new (ETableModel *model, const char *fontname, GtkJustification justify); #endif /* _E_CELL_TEXT_H_ */ + diff --git a/widgets/table/e-cell.h b/widgets/table/e-cell.h index 0cafe0fff4..08efaa6649 100644 --- a/widgets/table/e-cell.h +++ b/widgets/table/e-cell.h @@ -15,7 +15,6 @@ typedef struct _ECellView ECellView; struct _ECell { GtkObject object; - ETableModel *table_model; }; diff --git a/widgets/table/e-table-col.h b/widgets/table/e-table-col.h index 950bf23352..582c4eb383 100644 --- a/widgets/table/e-table-col.h +++ b/widgets/table/e-table-col.h @@ -1,8 +1,9 @@ #ifndef _E_TABLE_COL_H_ #define _E_TABLE_COL_H_ +#include "e-cell.h" + typedef struct _ETableCol ETableCol; -typedef struct _ECell ECell; /* * Information about a single column diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c index ab59d9a01c..1092874b9e 100644 --- a/widgets/table/e-table-header-item.c +++ b/widgets/table/e-table-header-item.c @@ -157,7 +157,6 @@ ethi_realize (GnomeCanvasItem *item) ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); GdkWindow *window; GdkColor c; - int i; if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)-> realize) (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->realize)(item); @@ -172,26 +171,12 @@ ethi_realize (GnomeCanvasItem *item) if (!ethi->font) ethi_font_load (ethi, "fixed"); - - /* - * Now realize the various ECells - */ - ethi->n_cells = e_table_header_count (ethi->eth); - ethi->cell_views = g_new (ECellView *, ethi->n_cells); - - for (i = 0; i < ethi->n_cells; i++){ - ETableCol *col = e_table_header_get_column (ethi->eth, i); - - ethi->cell_views [i] = e_cell_realize (col->ecell, item->canvas); - } - } static void ethi_unrealize (GnomeCanvasItem *item) { ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - int i; gdk_gc_unref (ethi->gc); ethi->gc = NULL; @@ -202,14 +187,6 @@ ethi_unrealize (GnomeCanvasItem *item) gdk_cursor_destroy (ethi->normal_cursor); ethi->normal_cursor = NULL; - for (i = 0; i < ethi->n_cells; i++){ - ETableCol *col = e_table_header_get_column (ethi->eth, i); - - e_cell_unrealize (col->ecell, ethi->cell_views [i]); - ethi->cell_views = NULL; - } - g_free (ethi->cell_views); - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); } diff --git a/widgets/table/e-table-header-item.h b/widgets/table/e-table-header-item.h index 10b84e1897..d6b7d64a9f 100644 --- a/widgets/table/e-table-header-item.h +++ b/widgets/table/e-table-header-item.h @@ -10,8 +10,6 @@ #define E_IS_TABLE_HEADER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_ITEM_TYPE)) #define E_IS_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_ITEM_TYPE)) -typedef struct _ECellView ECellView; - typedef struct { GnomeCanvasItem parent; ETableHeader *eth; @@ -30,9 +28,6 @@ typedef struct { int resize_start_pos; GtkObject *resize_guide; - ECellView **cell_views; - int n_cells; - /* * Ids */ diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c index 5bf1e24fd0..387bb520bd 100644 --- a/widgets/table/e-table-item.c +++ b/widgets/table/e-table-item.c @@ -8,6 +8,7 @@ */ #include <config.h> #include "e-table-item.h" +#include "e-cell.h" #define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () @@ -22,6 +23,41 @@ enum { }; static void +eti_realize_cell_views (ETableItem *eti) +{ + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); + int i; + + /* + * Now realize the various ECells + */ + eti->n_cells = e_table_header_count (eti->header); + eti->cell_views = g_new (ECellView *, eti->n_cells); + + for (i = 0; i < eti->n_cells; i++){ + ETableCol *col = e_table_header_get_column (eti->header, i); + + eti->cell_views [i] = e_cell_realize (col->ecell, item->canvas); + } +} + +static void +eti_unrealize_cell_views (ETableItem *eti) +{ + int i; + + for (i = 0; i < eti->n_cells; i++){ + ETableCol *col = e_table_header_get_column (eti->header, i); + + e_cell_unrealize (eti->cell_views [i]); + eti->cell_views [i] = NULL; + } + g_free (eti->cell_views); + eti->n_cells = 0; + +} + +static void eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) { ETableItem *eti = E_TABLE_ITEM (item); @@ -124,6 +160,8 @@ eti_header_structure_changed (ETableHeader *eth, ETableItem *eti) eti_request_redraw (eti); eti->width = e_table_header_total_width (eti->header); + eti_unrealize_cell_views (eti); + eti_realize_cell_views (eti); eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); eti_request_redraw (eti); @@ -210,7 +248,7 @@ eti_realize (GnomeCanvasItem *item) ETableItem *eti = E_TABLE_ITEM (item); GtkWidget *canvas_widget = GTK_WIDGET (item->canvas); GdkWindow *window; - + if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); @@ -221,17 +259,20 @@ eti_realize (GnomeCanvasItem *item) eti->grid_gc = gdk_gc_new (window); gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); + eti_realize_cell_views (eti); } static void eti_unrealize (GnomeCanvasItem *item) { ETableItem *eti = E_TABLE_ITEM (item); - + gdk_gc_unref (eti->fill_gc); eti->fill_gc = NULL; gdk_gc_unref (eti->grid_gc); eti->grid_gc = NULL; + + eti_unrealize_cell_views (eti); if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); @@ -242,16 +283,23 @@ draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row, int x1, int y1, int x2, int y2) { GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; + ECellView *ecell_view; GdkFont *font; char text [40]; font = GTK_WIDGET (canvas)->style->font; - - sprintf (text, "%d:%d\n", col, row); + + ecell_view = eti->cell_views [col]; + + e_cell_draw (ecell_view, drawable, col, row, x1, y1, x2, y2); + gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2); gdk_draw_line (drawable, eti->grid_gc, x1, y2, x2, y1); +#if 0 + sprintf (text, "%d:%d\n", col, row); gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text)); +#endif } static void @@ -344,7 +392,7 @@ static int eti_event (GnomeCanvasItem *item, GdkEvent *e) { ETableItem *eti = E_TABLE_ITEM (item); - ETableCol *etc; + ECellView *ecell_view; switch (e->type){ case GDK_BUTTON_PRESS: @@ -356,9 +404,9 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) if (eti->focused_col == -1) return FALSE; - etc = e_table_header_get_column (eti->header, eti->focused_col); + ecell_view = eti->cell_views [eti->focused_col]; - e_cell_event (etc->ecell, e, eti->focused_col, eti->focused_row); + e_cell_event (ecell_view, e, eti->focused_col, eti->focused_row); break; } diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h index fefa221227..d694e62d68 100644 --- a/widgets/table/e-table-item.h +++ b/widgets/table/e-table-item.h @@ -35,6 +35,12 @@ typedef struct { unsigned int draw_grid:1; int focused_col, focused_row; + + /* + * Realized views, per column + */ + ECellView **cell_views; + int n_cells; } ETableItem; typedef struct { diff --git a/widgets/table/table-test.c b/widgets/table/table-test.c index e646b44655..4917511261 100644 --- a/widgets/table/table-test.c +++ b/widgets/table/table-test.c @@ -145,7 +145,7 @@ value_at (ETableModel *etc, int col, int row, void *data) g_assert (col < cols); g_assert (row < lines); - return (void *) &table_data [row][col]; + return (void *) table_data [row][col]; } static void @@ -203,7 +203,7 @@ main (int argc, char *argv []) * Header */ e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new ("fixed", GTK_JUSTIFY_LEFT); + cell_left_just = e_cell_text_new (e_table_model, "fixed", GTK_JUSTIFY_LEFT); for (i = 0; i < cols; i++){ ETableCol *ecol = e_table_col_new ( |