diff options
author | Miguel de Icaza <miguel@gnu.org> | 1999-11-27 03:25:02 +0800 |
---|---|---|
committer | Arturo Espinosa <unammx@src.gnome.org> | 1999-11-27 03:25:02 +0800 |
commit | 465c8ae9a0cac78793cac6097b6bfbabc3a342de (patch) | |
tree | 6722a7709aaeccb913d73828d075301d68885cc4 /widgets | |
parent | b92f33ed1198949e1275f8b7580fa3e367a47450 (diff) | |
download | gsoc2013-evolution-465c8ae9a0cac78793cac6097b6bfbabc3a342de.tar gsoc2013-evolution-465c8ae9a0cac78793cac6097b6bfbabc3a342de.tar.gz gsoc2013-evolution-465c8ae9a0cac78793cac6097b6bfbabc3a342de.tar.bz2 gsoc2013-evolution-465c8ae9a0cac78793cac6097b6bfbabc3a342de.tar.lz gsoc2013-evolution-465c8ae9a0cac78793cac6097b6bfbabc3a342de.tar.xz gsoc2013-evolution-465c8ae9a0cac78793cac6097b6bfbabc3a342de.tar.zst gsoc2013-evolution-465c8ae9a0cac78793cac6097b6bfbabc3a342de.zip |
Compute height using the ecell methods here. (eti_get_height): new method
1999-11-26 Miguel de Icaza <miguel@gnu.org>
* e-table-item.c (eti_realize): Compute height using the ecell
methods here.
(eti_get_height): new method to compute dimensions.
* e-cursors.c: use a different cursor.
* e-table-model.h: kill height and row_height methods.
* e-cell.c (ec_height): New method.
* e-cell-text.c (ect_realize): Load the font from the canvas.
(ect_draw): New color setup.
Center in the row.
(ect_height): Implement new method.
1999-11-26 Michael Meeks <mmeeks@gnu.org>
* ROADMAP.e-table: small spelling/typo fixes.
1999-11-25 Miguel de Icaza <miguel@gnu.org>
* e-table-item.c (eti_event): Work on mouse-button event
svn path=/trunk/; revision=1439
Diffstat (limited to 'widgets')
38 files changed, 645 insertions, 236 deletions
diff --git a/widgets/ChangeLog b/widgets/ChangeLog index 15ae2a656f..8df0c6966d 100644 --- a/widgets/ChangeLog +++ b/widgets/ChangeLog @@ -1,9 +1,31 @@ +1999-11-26 Miguel de Icaza <miguel@gnu.org> + + * e-table-item.c (eti_realize): Compute height using the ecell + methods here. + (eti_get_height): new method to compute dimensions. + + * e-cursors.c: use a different cursor. + + * e-table-model.h: kill height and row_height methods. + + * e-cell.c (ec_height): New method. + + * e-cell-text.c (ect_realize): Load the font from the canvas. + (ect_draw): New color setup. + Center in the row. + (ect_height): Implement new method. + 1999-11-26 Michael Meeks <mmeeks@gnu.org> * ROADMAP.e-table: small spelling/typo fixes. 1999-11-25 Miguel de Icaza <miguel@gnu.org> + * e-table-item.c (eti_event): Work on mouse-button event + propagation to cells. + + * e-cell-text.c (ect_draw): Use CellViews now. + * e-table-item.c (eti_realize_cell_views): New routine: Realizes the cell views (eti_unrealize_cell_views): New routine: unrealizes the cell views. diff --git a/widgets/TODO b/widgets/TODO index a4bf6483a0..c6d2010be8 100644 --- a/widgets/TODO +++ b/widgets/TODO @@ -1,3 +1,10 @@ -Perhaps implement E-table-sorted in terms of e-table-subset? +Implement e-cell-height +Implement computation of heights from the e-cell-heights +Make sure we compute the height from that +Include spacing in columns and rows for the decoration lines +Add threshold to compute a "global" size +Implement the two methods for row finding: by full thing, or by a factor. -Miguel
\ No newline at end of file + +Add editing +mouse grabbing for scrolling diff --git a/widgets/e-cell-text.c b/widgets/e-cell-text.c index 49ffa153a7..da26302664 100644 --- a/widgets/e-cell-text.c +++ b/widgets/e-cell-text.c @@ -13,6 +13,8 @@ #define PARENT_TYPE e_cell_get_type() +#define TEXT_PAD 2 + typedef struct { ECellView cell_view; GdkGC *gc; @@ -26,11 +28,22 @@ static ECellView * ect_realize (ECell *ecell, GnomeCanvas *canvas) { ECellText *ect = E_CELL_TEXT (ecell); - ECellTextView *ectv = g_new (ECellTextView, 1); + ECellTextView *ectv = g_new0 (ECellTextView, 1); ectv->cell_view.ecell = ecell; ectv->gc = gdk_gc_new (GTK_WIDGET (canvas)->window); - ectv->font = gdk_fontset_load (ect->font_name ? ect->font_name : "fixed"); + if (ect->font_name){ + GdkFont *f; + + f = gdk_fontset_load (ect->font_name); + ectv->font = f; + } + if (!ectv->font){ + ectv->font = GTK_WIDGET (canvas)->style->font; + + gdk_font_ref (ectv->font); + } + ectv->canvas = canvas; return (ECellView *)ectv; @@ -67,8 +80,6 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 gdk_gc_set_clip_rectangle (text_view->gc, &rect); - printf ("String is: [%s]\n", str); - switch (ect->justify){ case GTK_JUSTIFY_LEFT: xoff = 1; @@ -90,20 +101,23 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 /* Draw now */ { GtkWidget *w = GTK_WIDGET (text_view->canvas); - GdkColor *background; - int idx; + GdkColor *background, *foreground; + const int height = text_view->font->ascent + text_view->font->descent; - if (selected) - idx = GTK_STATE_SELECTED; - else - idx = GTK_STATE_NORMAL; + if (selected){ + background = &w->style->bg [GTK_STATE_SELECTED]; + foreground = &w->style->text [GTK_STATE_SELECTED]; + } else { + background = &w->style->base [GTK_STATE_NORMAL]; + foreground = &w->style->text [GTK_STATE_NORMAL]; + } - gdk_gc_set_foreground (text_view->gc, &w->style->bg [idx]); + gdk_gc_set_foreground (text_view->gc, background); 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_gc_set_foreground (text_view->gc, foreground); gdk_draw_string (drawable, text_view->font, text_view->gc, - x1 + xoff, y2 - text_view->font->descent, str); + x1 + xoff, y2 - text_view->font->descent - ((y2-y1-height)/2), str); } } @@ -129,6 +143,14 @@ ect_event (ECellView *ecell_view, GdkEvent *event, int col, int row) } } +static int +ect_height (ECellView *ecell_view, int col, int row) +{ + ECellTextView *text_view = (ECellTextView *) ecell_view; + + return (text_view->font->ascent + text_view->font->descent) + TEXT_PAD; +} + static void ect_destroy (GtkObject *object) { @@ -150,7 +172,8 @@ e_cell_text_class_init (GtkObjectClass *object_class) ecc->unrealize = ect_unrealize; ecc->draw = ect_draw; ecc->event = ect_event; - + ecc->height = ect_height; + parent_class = gtk_type_class (PARENT_TYPE); } diff --git a/widgets/e-cell.c b/widgets/e-cell.c index bff0fb88f2..8a8897c22a 100644 --- a/widgets/e-cell.c +++ b/widgets/e-cell.c @@ -35,6 +35,13 @@ ec_event (ECellView *ecell_view, GdkEvent *event, int col, int row) g_warning ("e-cell-event invoked\n"); } +static gint +ec_height (ECellView *ecell_view, int col, int row) +{ + g_warning ("e-cell-event invoked\n"); + return 0; +} + static void ec_focus (ECellView *ecell_view, int col, int row, int x1, int y1, int x2, int y2) { @@ -68,6 +75,7 @@ e_cell_class_init (GtkObjectClass *object_class) ecc->event = ec_event; ecc->focus = ec_focus; ecc->unfocus = ec_unfocus; + ecc->height = ec_height; } static void @@ -107,3 +115,10 @@ e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, ecell_view, drawable, col, row, x1, y1, x2, y2); } +int +e_cell_height (ECellView *ecell_view, int col, int row) +{ + return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height ( + ecell_view, col, row); +} + diff --git a/widgets/e-cell.h b/widgets/e-cell.h index 08efaa6649..e57f341098 100644 --- a/widgets/e-cell.h +++ b/widgets/e-cell.h @@ -36,15 +36,17 @@ typedef struct { gint (*event) (ECellView *ecell_view, GdkEvent *event, int col, int row); void (*focus) (ECellView *ecell, int col, int row, int x1, int y1, int x2, int y2); void (*unfocus) (ECellView *ecell); + int (*height) (ECellView *ecell, int col, int row); } ECellClass; GtkType e_cell_get_type (void); void e_cell_event (ECellView *ecell_view, GdkEvent *event, int col, int row); ECellView *e_cell_realize (ECell *ecell, GnomeCanvas *canvas); -void e_cell_unrealize (ECellView *ecell); -void e_cell_draw (ECellView *ecell, GdkDrawable *dr, +void e_cell_unrealize (ECellView *ecell_view); +void e_cell_draw (ECellView *ecell_view, GdkDrawable *dr, int col, int row, int x1, int y1, int x2, int y2); -void e_cell_focus (ECellView *ecell, int col, int row, int x1, int y1, int x2, int y2); -void e_cell_unfocus (ECellView *ecell); +void e_cell_focus (ECellView *ecell_view, int col, int row, int x1, int y1, int x2, int y2); +void e_cell_unfocus (ECellView *ecell_view); +int e_cell_height (ECellView *ecell_view, int col, int row); #endif /* _E_CELL_H_ */ diff --git a/widgets/e-cursors.c b/widgets/e-cursors.c index acd69a0554..150b84b90a 100644 --- a/widgets/e-cursors.c +++ b/widgets/e-cursors.c @@ -21,7 +21,7 @@ typedef struct { static CursorDef cursors [] = { { NULL, GDK_INTERNAL_CURSOR, GDK_CROSSHAIR, NULL }, - { NULL, GDK_INTERNAL_CURSOR, GDK_ARROW, NULL }, + { NULL, GDK_INTERNAL_CURSOR, GDK_LEFT_PTR, NULL }, { NULL, GDK_INTERNAL_CURSOR, GDK_FLEUR, NULL }, { NULL, GDK_INTERNAL_CURSOR, GDK_SB_H_DOUBLE_ARROW, NULL }, { NULL, GDK_INTERNAL_CURSOR, GDK_SB_V_DOUBLE_ARROW, NULL }, diff --git a/widgets/e-table-header-item.c b/widgets/e-table-header-item.c index 1092874b9e..2ee8e2d619 100644 --- a/widgets/e-table-header-item.c +++ b/widgets/e-table-header-item.c @@ -376,6 +376,10 @@ ethi_event (GnomeCanvasItem *item, GdkEvent *e) set_cursor (ethi, x); break; + case GDK_LEAVE_NOTIFY: + e_cursor_set (GTK_WIDGET (canvas)->window, E_CURSOR_ARROW); + break; + case GDK_MOTION_NOTIFY: convert (canvas, e->motion.x, e->motion.y, &x, &y); if (resizing){ diff --git a/widgets/e-table-item.c b/widgets/e-table-item.c index 387bb520bd..16b85fab6e 100644 --- a/widgets/e-table-item.c +++ b/widgets/e-table-item.c @@ -20,6 +20,7 @@ enum { ARG_TABLE_MODEL, ARG_TABLE_X, ARG_TABLE_Y, + ARG_LENGHT_THRESHOLD }; static void @@ -103,10 +104,47 @@ eti_remove_header_model (ETableItem *eti) eti->header = NULL; } +static int +eti_row_height (ETableItem *eti, int row) +{ + const int cols = e_table_header_count (eti->header); + int col; + int h, max_h; + + max_h = 0; + + for (col = 0; col < cols; col++){ + h = e_cell_height (eti->cell_views [col], col, row); + + if (h > max_h) + max_h = h; + } + return max_h; +} + +static int +eti_get_height (ETableItem *eti) +{ + const int rows = e_table_model_row_count (eti->table_model); + int row; + int height = 0; + + if (rows > eti->length_threshold){ + height = eti_row_height (eti, 0) * rows; + + return height; + } + + for (row = 0; row < rows; row++) + height += eti_row_height (eti, row); + + return height; +} + static void eti_table_model_changed (ETableModel *table_model, ETableItem *eti) { - eti->height = e_table_model_height (eti->table_model); + eti->height = eti_get_height (eti); eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); } @@ -122,7 +160,7 @@ eti_request_redraw (ETableItem *eti) } static void -eti_table_model_row_selection (ETableModel *table_model, ETableItem *eti) +eti_table_model_row_selection (ETableModel *table_model, int row, gboolean selected, ETableItem *eti) { /* FIXME: we should optimize this to only redraw the selection change */ eti_request_redraw (eti); @@ -217,8 +255,6 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) case ARG_TABLE_MODEL: eti_remove_table_model (eti); eti_add_table_model (eti, GTK_VALUE_POINTER (*arg)); - - eti->height = e_table_model_height (eti->table_model); break; case ARG_TABLE_X: @@ -229,6 +265,10 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) eti->y1 = GTK_VALUE_INT (*arg); break; + case ARG_LENGHT_THRESHOLD: + eti->length_threshold = GTK_VALUE_INT (*arg); + break; + } eti_update (item, NULL, NULL, 0); } @@ -240,6 +280,9 @@ eti_init (GnomeCanvasItem *item) eti->focused_col = -1; eti->focused_row = -1; + eti->height = 0; + + eti->length_threshold = -1; } static void @@ -260,6 +303,9 @@ eti_realize (GnomeCanvasItem *item) gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); eti_realize_cell_views (eti); + + eti->height = eti_get_height (eti); + eti_update (item, NULL, NULL, 0); } static void @@ -273,6 +319,8 @@ eti_unrealize (GnomeCanvasItem *item) eti->grid_gc = NULL; eti_unrealize_cell_views (eti); + + eti->height = 0; if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); @@ -293,10 +341,10 @@ draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row, e_cell_draw (ecell_view, drawable, col, row, x1, y1, x2, y2); - gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2); +#if 0 + 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); -#if 0 sprintf (text, "%d:%d\n", col, row); gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text)); #endif @@ -358,7 +406,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, for (row = eti->top_item; row < rows; row++, y1 = y2){ int xd; - y2 += e_table_model_row_height (eti->table_model, row) + 1; + y2 += eti_row_height (eti, row); if (y1 > y + height) break; @@ -388,6 +436,52 @@ eti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, return 0.0; } +static gboolean +find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res) +{ + const int cols = e_table_header_count (eti->header); + const int rows = e_table_model_row_count (eti->table_model); + gdouble x1, y1, x2, y2; + int col, row; + + /* FIXME: inneficient, fix later */ + + x -= eti->x1; + y -= eti->y1; + + x1 = 0; + for (col = 0; col < cols; col++, x1 = x2){ + ETableCol *ecol = e_table_header_get_column (eti->header, col); + + if (x < x1) + return FALSE; + + x2 = x1 + ecol->width; + + if (x > x2) + continue; + + *col_res = col; + break; + } + + y1 = 0; + for (row = 0; row < rows; row++, y1 = y2){ + if (y < y1) + return FALSE; + + y2 += eti_row_height (eti, row); + + if (y > y2) + continue; + + *row_res = row; + break; + } + + return TRUE; +} + static int eti_event (GnomeCanvasItem *item, GdkEvent *e) { @@ -397,8 +491,18 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) switch (e->type){ case GDK_BUTTON_PRESS: case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: + case GDK_2BUTTON_PRESS: { + int col, row; + + if (!find_cell (eti, e->button.x, e->button.y, &col, &row)) + return TRUE; + ecell_view = eti->cell_views [col]; + printf ("Found: %d %d\n", col, row); + e_cell_event (ecell_view, e, col, row); + break; + } + case GDK_KEY_PRESS: case GDK_KEY_RELEASE: if (eti->focused_col == -1) @@ -408,9 +512,11 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) e_cell_event (ecell_view, e, eti->focused_col, eti->focused_row); break; - + + default: + return FALSE; } - return FALSE; + return TRUE; } static void diff --git a/widgets/e-table-item.h b/widgets/e-table-item.h index d694e62d68..b4b4c73361 100644 --- a/widgets/e-table-item.h +++ b/widgets/e-table-item.h @@ -41,6 +41,12 @@ typedef struct { */ ECellView **cell_views; int n_cells; + + /* + * Lengh Threshold: above this, we stop computing correctly + * the size + */ + int length_threshold; } ETableItem; typedef struct { diff --git a/widgets/e-table-model.c b/widgets/e-table-model.c index 1176b33ec7..3aa4e4be47 100644 --- a/widgets/e-table-model.c +++ b/widgets/e-table-model.c @@ -58,12 +58,6 @@ e_table_model_is_cell_editable (ETableModel *etable, int col, int row) return ETM_CLASS (etable)->is_cell_editable (etable, col, row); } -int -e_table_model_row_height (ETableModel *etable, int row) -{ - return ETM_CLASS (etable)->row_height (etable, row); -} - static void e_table_model_destroy (GtkObject *object) { @@ -101,6 +95,12 @@ e_table_model_class_init (GtkObjectClass *object_class) gtk_object_class_add_signals (object_class, etm_signals, LAST_SIGNAL); } +static void +e_table_model_init (ETableModel *etm) +{ + etm->row_selected = -1; +} + GtkType e_table_model_get_type (void) { @@ -112,7 +112,7 @@ e_table_model_get_type (void) sizeof (ETableModel), sizeof (ETableModelClass), (GtkClassInitFunc) e_table_model_class_init, - (GtkObjectInitFunc) NULL, + (GtkObjectInitFunc) e_table_model_init, NULL, /* reserved 1 */ NULL, /* reserved 2 */ (GtkClassInitFunc) NULL @@ -124,22 +124,6 @@ e_table_model_get_type (void) return type; } -int -e_table_model_height (ETableModel *etable) -{ - int rows, size, i; - - g_return_val_if_fail (etable != NULL, 0); - - rows = e_table_model_row_count (etable); - size = 0; - - for (i = 0; i < rows; i++) - size += e_table_model_row_height (etable, i) + 1; - - return size; -} - void e_table_model_changed (ETableModel *e_table_model) { diff --git a/widgets/e-table-model.h b/widgets/e-table-model.h index 2d439a0065..d8de9e819e 100644 --- a/widgets/e-table-model.h +++ b/widgets/e-table-model.h @@ -28,13 +28,12 @@ typedef struct { void *(*value_at) (ETableModel *etm, int col, int row); void (*set_value_at) (ETableModel *etm, int col, int row, void *value); gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - int (*row_height) (ETableModel *etm, int row); /* * Signals */ void (*model_changed) (ETableModel *etm); - void (*row_selection) (ETableModel *etc, int row); + void (*row_selection) (ETableModel *etc, int row, gboolean selected); } ETableModelClass; GtkType e_table_model_get_type (void); @@ -42,8 +41,6 @@ GtkType e_table_model_get_type (void); int e_table_model_column_count (ETableModel *e_table_model); const char *e_table_model_column_name (ETableModel *e_table_model, int col); int e_table_model_row_count (ETableModel *e_table_model); -int e_table_model_row_height (ETableModel *e_table_model, int row); -int e_table_model_height (ETableModel *e_table_model); void *e_table_model_value_at (ETableModel *e_table_model, int col, int row); void e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, void *data); gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row); diff --git a/widgets/e-table-simple.c b/widgets/e-table-simple.c index b23cda1220..16691e5442 100644 --- a/widgets/e-table-simple.c +++ b/widgets/e-table-simple.c @@ -62,14 +62,6 @@ simple_is_cell_editable (ETableModel *etm, int col, int row) return simple->is_cell_editable (etm, col, row, simple->data); } -static int -simple_row_height (ETableModel *etm, int row) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->row_height (etm, row, simple->data); -} - static void e_table_simple_class_init (GtkObjectClass *object_class) { @@ -81,7 +73,6 @@ e_table_simple_class_init (GtkObjectClass *object_class) model_class->value_at = simple_value_at; model_class->set_value_at = simple_set_value_at; model_class->is_cell_editable = simple_is_cell_editable; - model_class->row_height = simple_row_height; } GtkType @@ -114,7 +105,6 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleValueAtFn value_at, ETableSimpleSetValueAtFn set_value_at, ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleRowHeightFn row_height, void *data) { ETableSimple *et; @@ -127,7 +117,6 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, et->value_at = value_at; et->set_value_at = set_value_at; et->is_cell_editable = is_cell_editable; - et->row_height = row_height; return (ETableModel *) et; } diff --git a/widgets/e-table-simple.h b/widgets/e-table-simple.h index ac34d6045c..544e681a6c 100644 --- a/widgets/e-table-simple.h +++ b/widgets/e-table-simple.h @@ -9,7 +9,6 @@ typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *dat typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, void *val, void *data); typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); -typedef int (*ETableSimpleRowHeightFn) (ETableModel *etm, int row, void *data); typedef struct { ETableModel parent; @@ -20,7 +19,6 @@ typedef struct { ETableSimpleValueAtFn value_at; ETableSimpleSetValueAtFn set_value_at; ETableSimpleIsCellEditableFn is_cell_editable; - ETableSimpleRowHeightFn row_height; void *data; } ETableSimple; @@ -36,7 +34,6 @@ ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleValueAtFn value_at, ETableSimpleSetValueAtFn set_value_at, ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleRowHeightFn row_height, void *data); #endif /* _E_TABLE_SIMPLE_H_ */ diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog index 15ae2a656f..8df0c6966d 100644 --- a/widgets/e-table/ChangeLog +++ b/widgets/e-table/ChangeLog @@ -1,9 +1,31 @@ +1999-11-26 Miguel de Icaza <miguel@gnu.org> + + * e-table-item.c (eti_realize): Compute height using the ecell + methods here. + (eti_get_height): new method to compute dimensions. + + * e-cursors.c: use a different cursor. + + * e-table-model.h: kill height and row_height methods. + + * e-cell.c (ec_height): New method. + + * e-cell-text.c (ect_realize): Load the font from the canvas. + (ect_draw): New color setup. + Center in the row. + (ect_height): Implement new method. + 1999-11-26 Michael Meeks <mmeeks@gnu.org> * ROADMAP.e-table: small spelling/typo fixes. 1999-11-25 Miguel de Icaza <miguel@gnu.org> + * e-table-item.c (eti_event): Work on mouse-button event + propagation to cells. + + * e-cell-text.c (ect_draw): Use CellViews now. + * e-table-item.c (eti_realize_cell_views): New routine: Realizes the cell views (eti_unrealize_cell_views): New routine: unrealizes the cell views. diff --git a/widgets/e-table/TODO b/widgets/e-table/TODO index a4bf6483a0..c6d2010be8 100644 --- a/widgets/e-table/TODO +++ b/widgets/e-table/TODO @@ -1,3 +1,10 @@ -Perhaps implement E-table-sorted in terms of e-table-subset? +Implement e-cell-height +Implement computation of heights from the e-cell-heights +Make sure we compute the height from that +Include spacing in columns and rows for the decoration lines +Add threshold to compute a "global" size +Implement the two methods for row finding: by full thing, or by a factor. -Miguel
\ No newline at end of file + +Add editing +mouse grabbing for scrolling diff --git a/widgets/e-table/e-cell-text.c b/widgets/e-table/e-cell-text.c index 49ffa153a7..da26302664 100644 --- a/widgets/e-table/e-cell-text.c +++ b/widgets/e-table/e-cell-text.c @@ -13,6 +13,8 @@ #define PARENT_TYPE e_cell_get_type() +#define TEXT_PAD 2 + typedef struct { ECellView cell_view; GdkGC *gc; @@ -26,11 +28,22 @@ static ECellView * ect_realize (ECell *ecell, GnomeCanvas *canvas) { ECellText *ect = E_CELL_TEXT (ecell); - ECellTextView *ectv = g_new (ECellTextView, 1); + ECellTextView *ectv = g_new0 (ECellTextView, 1); ectv->cell_view.ecell = ecell; ectv->gc = gdk_gc_new (GTK_WIDGET (canvas)->window); - ectv->font = gdk_fontset_load (ect->font_name ? ect->font_name : "fixed"); + if (ect->font_name){ + GdkFont *f; + + f = gdk_fontset_load (ect->font_name); + ectv->font = f; + } + if (!ectv->font){ + ectv->font = GTK_WIDGET (canvas)->style->font; + + gdk_font_ref (ectv->font); + } + ectv->canvas = canvas; return (ECellView *)ectv; @@ -67,8 +80,6 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 gdk_gc_set_clip_rectangle (text_view->gc, &rect); - printf ("String is: [%s]\n", str); - switch (ect->justify){ case GTK_JUSTIFY_LEFT: xoff = 1; @@ -90,20 +101,23 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 /* Draw now */ { GtkWidget *w = GTK_WIDGET (text_view->canvas); - GdkColor *background; - int idx; + GdkColor *background, *foreground; + const int height = text_view->font->ascent + text_view->font->descent; - if (selected) - idx = GTK_STATE_SELECTED; - else - idx = GTK_STATE_NORMAL; + if (selected){ + background = &w->style->bg [GTK_STATE_SELECTED]; + foreground = &w->style->text [GTK_STATE_SELECTED]; + } else { + background = &w->style->base [GTK_STATE_NORMAL]; + foreground = &w->style->text [GTK_STATE_NORMAL]; + } - gdk_gc_set_foreground (text_view->gc, &w->style->bg [idx]); + gdk_gc_set_foreground (text_view->gc, background); 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_gc_set_foreground (text_view->gc, foreground); gdk_draw_string (drawable, text_view->font, text_view->gc, - x1 + xoff, y2 - text_view->font->descent, str); + x1 + xoff, y2 - text_view->font->descent - ((y2-y1-height)/2), str); } } @@ -129,6 +143,14 @@ ect_event (ECellView *ecell_view, GdkEvent *event, int col, int row) } } +static int +ect_height (ECellView *ecell_view, int col, int row) +{ + ECellTextView *text_view = (ECellTextView *) ecell_view; + + return (text_view->font->ascent + text_view->font->descent) + TEXT_PAD; +} + static void ect_destroy (GtkObject *object) { @@ -150,7 +172,8 @@ e_cell_text_class_init (GtkObjectClass *object_class) ecc->unrealize = ect_unrealize; ecc->draw = ect_draw; ecc->event = ect_event; - + ecc->height = ect_height; + parent_class = gtk_type_class (PARENT_TYPE); } diff --git a/widgets/e-table/e-cell.c b/widgets/e-table/e-cell.c index bff0fb88f2..8a8897c22a 100644 --- a/widgets/e-table/e-cell.c +++ b/widgets/e-table/e-cell.c @@ -35,6 +35,13 @@ ec_event (ECellView *ecell_view, GdkEvent *event, int col, int row) g_warning ("e-cell-event invoked\n"); } +static gint +ec_height (ECellView *ecell_view, int col, int row) +{ + g_warning ("e-cell-event invoked\n"); + return 0; +} + static void ec_focus (ECellView *ecell_view, int col, int row, int x1, int y1, int x2, int y2) { @@ -68,6 +75,7 @@ e_cell_class_init (GtkObjectClass *object_class) ecc->event = ec_event; ecc->focus = ec_focus; ecc->unfocus = ec_unfocus; + ecc->height = ec_height; } static void @@ -107,3 +115,10 @@ e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, ecell_view, drawable, col, row, x1, y1, x2, y2); } +int +e_cell_height (ECellView *ecell_view, int col, int row) +{ + return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height ( + ecell_view, col, row); +} + diff --git a/widgets/e-table/e-cell.h b/widgets/e-table/e-cell.h index 08efaa6649..e57f341098 100644 --- a/widgets/e-table/e-cell.h +++ b/widgets/e-table/e-cell.h @@ -36,15 +36,17 @@ typedef struct { gint (*event) (ECellView *ecell_view, GdkEvent *event, int col, int row); void (*focus) (ECellView *ecell, int col, int row, int x1, int y1, int x2, int y2); void (*unfocus) (ECellView *ecell); + int (*height) (ECellView *ecell, int col, int row); } ECellClass; GtkType e_cell_get_type (void); void e_cell_event (ECellView *ecell_view, GdkEvent *event, int col, int row); ECellView *e_cell_realize (ECell *ecell, GnomeCanvas *canvas); -void e_cell_unrealize (ECellView *ecell); -void e_cell_draw (ECellView *ecell, GdkDrawable *dr, +void e_cell_unrealize (ECellView *ecell_view); +void e_cell_draw (ECellView *ecell_view, GdkDrawable *dr, int col, int row, int x1, int y1, int x2, int y2); -void e_cell_focus (ECellView *ecell, int col, int row, int x1, int y1, int x2, int y2); -void e_cell_unfocus (ECellView *ecell); +void e_cell_focus (ECellView *ecell_view, int col, int row, int x1, int y1, int x2, int y2); +void e_cell_unfocus (ECellView *ecell_view); +int e_cell_height (ECellView *ecell_view, int col, int row); #endif /* _E_CELL_H_ */ diff --git a/widgets/e-table/e-table-header-item.c b/widgets/e-table/e-table-header-item.c index 1092874b9e..2ee8e2d619 100644 --- a/widgets/e-table/e-table-header-item.c +++ b/widgets/e-table/e-table-header-item.c @@ -376,6 +376,10 @@ ethi_event (GnomeCanvasItem *item, GdkEvent *e) set_cursor (ethi, x); break; + case GDK_LEAVE_NOTIFY: + e_cursor_set (GTK_WIDGET (canvas)->window, E_CURSOR_ARROW); + break; + case GDK_MOTION_NOTIFY: convert (canvas, e->motion.x, e->motion.y, &x, &y); if (resizing){ diff --git a/widgets/e-table/e-table-item.c b/widgets/e-table/e-table-item.c index 387bb520bd..16b85fab6e 100644 --- a/widgets/e-table/e-table-item.c +++ b/widgets/e-table/e-table-item.c @@ -20,6 +20,7 @@ enum { ARG_TABLE_MODEL, ARG_TABLE_X, ARG_TABLE_Y, + ARG_LENGHT_THRESHOLD }; static void @@ -103,10 +104,47 @@ eti_remove_header_model (ETableItem *eti) eti->header = NULL; } +static int +eti_row_height (ETableItem *eti, int row) +{ + const int cols = e_table_header_count (eti->header); + int col; + int h, max_h; + + max_h = 0; + + for (col = 0; col < cols; col++){ + h = e_cell_height (eti->cell_views [col], col, row); + + if (h > max_h) + max_h = h; + } + return max_h; +} + +static int +eti_get_height (ETableItem *eti) +{ + const int rows = e_table_model_row_count (eti->table_model); + int row; + int height = 0; + + if (rows > eti->length_threshold){ + height = eti_row_height (eti, 0) * rows; + + return height; + } + + for (row = 0; row < rows; row++) + height += eti_row_height (eti, row); + + return height; +} + static void eti_table_model_changed (ETableModel *table_model, ETableItem *eti) { - eti->height = e_table_model_height (eti->table_model); + eti->height = eti_get_height (eti); eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); } @@ -122,7 +160,7 @@ eti_request_redraw (ETableItem *eti) } static void -eti_table_model_row_selection (ETableModel *table_model, ETableItem *eti) +eti_table_model_row_selection (ETableModel *table_model, int row, gboolean selected, ETableItem *eti) { /* FIXME: we should optimize this to only redraw the selection change */ eti_request_redraw (eti); @@ -217,8 +255,6 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) case ARG_TABLE_MODEL: eti_remove_table_model (eti); eti_add_table_model (eti, GTK_VALUE_POINTER (*arg)); - - eti->height = e_table_model_height (eti->table_model); break; case ARG_TABLE_X: @@ -229,6 +265,10 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) eti->y1 = GTK_VALUE_INT (*arg); break; + case ARG_LENGHT_THRESHOLD: + eti->length_threshold = GTK_VALUE_INT (*arg); + break; + } eti_update (item, NULL, NULL, 0); } @@ -240,6 +280,9 @@ eti_init (GnomeCanvasItem *item) eti->focused_col = -1; eti->focused_row = -1; + eti->height = 0; + + eti->length_threshold = -1; } static void @@ -260,6 +303,9 @@ eti_realize (GnomeCanvasItem *item) gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); eti_realize_cell_views (eti); + + eti->height = eti_get_height (eti); + eti_update (item, NULL, NULL, 0); } static void @@ -273,6 +319,8 @@ eti_unrealize (GnomeCanvasItem *item) eti->grid_gc = NULL; eti_unrealize_cell_views (eti); + + eti->height = 0; if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); @@ -293,10 +341,10 @@ draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row, e_cell_draw (ecell_view, drawable, col, row, x1, y1, x2, y2); - gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2); +#if 0 + 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); -#if 0 sprintf (text, "%d:%d\n", col, row); gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text)); #endif @@ -358,7 +406,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, for (row = eti->top_item; row < rows; row++, y1 = y2){ int xd; - y2 += e_table_model_row_height (eti->table_model, row) + 1; + y2 += eti_row_height (eti, row); if (y1 > y + height) break; @@ -388,6 +436,52 @@ eti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, return 0.0; } +static gboolean +find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res) +{ + const int cols = e_table_header_count (eti->header); + const int rows = e_table_model_row_count (eti->table_model); + gdouble x1, y1, x2, y2; + int col, row; + + /* FIXME: inneficient, fix later */ + + x -= eti->x1; + y -= eti->y1; + + x1 = 0; + for (col = 0; col < cols; col++, x1 = x2){ + ETableCol *ecol = e_table_header_get_column (eti->header, col); + + if (x < x1) + return FALSE; + + x2 = x1 + ecol->width; + + if (x > x2) + continue; + + *col_res = col; + break; + } + + y1 = 0; + for (row = 0; row < rows; row++, y1 = y2){ + if (y < y1) + return FALSE; + + y2 += eti_row_height (eti, row); + + if (y > y2) + continue; + + *row_res = row; + break; + } + + return TRUE; +} + static int eti_event (GnomeCanvasItem *item, GdkEvent *e) { @@ -397,8 +491,18 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) switch (e->type){ case GDK_BUTTON_PRESS: case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: + case GDK_2BUTTON_PRESS: { + int col, row; + + if (!find_cell (eti, e->button.x, e->button.y, &col, &row)) + return TRUE; + ecell_view = eti->cell_views [col]; + printf ("Found: %d %d\n", col, row); + e_cell_event (ecell_view, e, col, row); + break; + } + case GDK_KEY_PRESS: case GDK_KEY_RELEASE: if (eti->focused_col == -1) @@ -408,9 +512,11 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) e_cell_event (ecell_view, e, eti->focused_col, eti->focused_row); break; - + + default: + return FALSE; } - return FALSE; + return TRUE; } static void diff --git a/widgets/e-table/e-table-item.h b/widgets/e-table/e-table-item.h index d694e62d68..b4b4c73361 100644 --- a/widgets/e-table/e-table-item.h +++ b/widgets/e-table/e-table-item.h @@ -41,6 +41,12 @@ typedef struct { */ ECellView **cell_views; int n_cells; + + /* + * Lengh Threshold: above this, we stop computing correctly + * the size + */ + int length_threshold; } ETableItem; typedef struct { diff --git a/widgets/e-table/e-table-model.c b/widgets/e-table/e-table-model.c index 1176b33ec7..3aa4e4be47 100644 --- a/widgets/e-table/e-table-model.c +++ b/widgets/e-table/e-table-model.c @@ -58,12 +58,6 @@ e_table_model_is_cell_editable (ETableModel *etable, int col, int row) return ETM_CLASS (etable)->is_cell_editable (etable, col, row); } -int -e_table_model_row_height (ETableModel *etable, int row) -{ - return ETM_CLASS (etable)->row_height (etable, row); -} - static void e_table_model_destroy (GtkObject *object) { @@ -101,6 +95,12 @@ e_table_model_class_init (GtkObjectClass *object_class) gtk_object_class_add_signals (object_class, etm_signals, LAST_SIGNAL); } +static void +e_table_model_init (ETableModel *etm) +{ + etm->row_selected = -1; +} + GtkType e_table_model_get_type (void) { @@ -112,7 +112,7 @@ e_table_model_get_type (void) sizeof (ETableModel), sizeof (ETableModelClass), (GtkClassInitFunc) e_table_model_class_init, - (GtkObjectInitFunc) NULL, + (GtkObjectInitFunc) e_table_model_init, NULL, /* reserved 1 */ NULL, /* reserved 2 */ (GtkClassInitFunc) NULL @@ -124,22 +124,6 @@ e_table_model_get_type (void) return type; } -int -e_table_model_height (ETableModel *etable) -{ - int rows, size, i; - - g_return_val_if_fail (etable != NULL, 0); - - rows = e_table_model_row_count (etable); - size = 0; - - for (i = 0; i < rows; i++) - size += e_table_model_row_height (etable, i) + 1; - - return size; -} - void e_table_model_changed (ETableModel *e_table_model) { diff --git a/widgets/e-table/e-table-model.h b/widgets/e-table/e-table-model.h index 2d439a0065..d8de9e819e 100644 --- a/widgets/e-table/e-table-model.h +++ b/widgets/e-table/e-table-model.h @@ -28,13 +28,12 @@ typedef struct { void *(*value_at) (ETableModel *etm, int col, int row); void (*set_value_at) (ETableModel *etm, int col, int row, void *value); gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - int (*row_height) (ETableModel *etm, int row); /* * Signals */ void (*model_changed) (ETableModel *etm); - void (*row_selection) (ETableModel *etc, int row); + void (*row_selection) (ETableModel *etc, int row, gboolean selected); } ETableModelClass; GtkType e_table_model_get_type (void); @@ -42,8 +41,6 @@ GtkType e_table_model_get_type (void); int e_table_model_column_count (ETableModel *e_table_model); const char *e_table_model_column_name (ETableModel *e_table_model, int col); int e_table_model_row_count (ETableModel *e_table_model); -int e_table_model_row_height (ETableModel *e_table_model, int row); -int e_table_model_height (ETableModel *e_table_model); void *e_table_model_value_at (ETableModel *e_table_model, int col, int row); void e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, void *data); gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row); diff --git a/widgets/e-table/e-table-simple.c b/widgets/e-table/e-table-simple.c index b23cda1220..16691e5442 100644 --- a/widgets/e-table/e-table-simple.c +++ b/widgets/e-table/e-table-simple.c @@ -62,14 +62,6 @@ simple_is_cell_editable (ETableModel *etm, int col, int row) return simple->is_cell_editable (etm, col, row, simple->data); } -static int -simple_row_height (ETableModel *etm, int row) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->row_height (etm, row, simple->data); -} - static void e_table_simple_class_init (GtkObjectClass *object_class) { @@ -81,7 +73,6 @@ e_table_simple_class_init (GtkObjectClass *object_class) model_class->value_at = simple_value_at; model_class->set_value_at = simple_set_value_at; model_class->is_cell_editable = simple_is_cell_editable; - model_class->row_height = simple_row_height; } GtkType @@ -114,7 +105,6 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleValueAtFn value_at, ETableSimpleSetValueAtFn set_value_at, ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleRowHeightFn row_height, void *data) { ETableSimple *et; @@ -127,7 +117,6 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, et->value_at = value_at; et->set_value_at = set_value_at; et->is_cell_editable = is_cell_editable; - et->row_height = row_height; return (ETableModel *) et; } diff --git a/widgets/e-table/e-table-simple.h b/widgets/e-table/e-table-simple.h index ac34d6045c..544e681a6c 100644 --- a/widgets/e-table/e-table-simple.h +++ b/widgets/e-table/e-table-simple.h @@ -9,7 +9,6 @@ typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *dat typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, void *val, void *data); typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); -typedef int (*ETableSimpleRowHeightFn) (ETableModel *etm, int row, void *data); typedef struct { ETableModel parent; @@ -20,7 +19,6 @@ typedef struct { ETableSimpleValueAtFn value_at; ETableSimpleSetValueAtFn set_value_at; ETableSimpleIsCellEditableFn is_cell_editable; - ETableSimpleRowHeightFn row_height; void *data; } ETableSimple; @@ -36,7 +34,6 @@ ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleValueAtFn value_at, ETableSimpleSetValueAtFn set_value_at, ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleRowHeightFn row_height, void *data); #endif /* _E_TABLE_SIMPLE_H_ */ diff --git a/widgets/e-table/table-test.c b/widgets/e-table/table-test.c index 4917511261..d7c14e900f 100644 --- a/widgets/e-table/table-test.c +++ b/widgets/e-table/table-test.c @@ -172,12 +172,6 @@ set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); } -static int -row_height (ETableModel *etm, int row, void *data) -{ - return row * 2 + 14; -} - int main (int argc, char *argv []) { @@ -197,13 +191,13 @@ main (int argc, char *argv []) */ e_table_model = e_table_simple_new ( col_count, col_name, row_count, value_at, - set_value_at, is_cell_editable, row_height, NULL); + set_value_at, is_cell_editable, NULL); /* * Header */ e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, "fixed", GTK_JUSTIFY_LEFT); + cell_left_just = e_cell_text_new (e_table_model, NULL, 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 4917511261..d7c14e900f 100644 --- a/widgets/table-test.c +++ b/widgets/table-test.c @@ -172,12 +172,6 @@ set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); } -static int -row_height (ETableModel *etm, int row, void *data) -{ - return row * 2 + 14; -} - int main (int argc, char *argv []) { @@ -197,13 +191,13 @@ main (int argc, char *argv []) */ e_table_model = e_table_simple_new ( col_count, col_name, row_count, value_at, - set_value_at, is_cell_editable, row_height, NULL); + set_value_at, is_cell_editable, NULL); /* * Header */ e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, "fixed", GTK_JUSTIFY_LEFT); + cell_left_just = e_cell_text_new (e_table_model, NULL, 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 49ffa153a7..da26302664 100644 --- a/widgets/table/e-cell-text.c +++ b/widgets/table/e-cell-text.c @@ -13,6 +13,8 @@ #define PARENT_TYPE e_cell_get_type() +#define TEXT_PAD 2 + typedef struct { ECellView cell_view; GdkGC *gc; @@ -26,11 +28,22 @@ static ECellView * ect_realize (ECell *ecell, GnomeCanvas *canvas) { ECellText *ect = E_CELL_TEXT (ecell); - ECellTextView *ectv = g_new (ECellTextView, 1); + ECellTextView *ectv = g_new0 (ECellTextView, 1); ectv->cell_view.ecell = ecell; ectv->gc = gdk_gc_new (GTK_WIDGET (canvas)->window); - ectv->font = gdk_fontset_load (ect->font_name ? ect->font_name : "fixed"); + if (ect->font_name){ + GdkFont *f; + + f = gdk_fontset_load (ect->font_name); + ectv->font = f; + } + if (!ectv->font){ + ectv->font = GTK_WIDGET (canvas)->style->font; + + gdk_font_ref (ectv->font); + } + ectv->canvas = canvas; return (ECellView *)ectv; @@ -67,8 +80,6 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 gdk_gc_set_clip_rectangle (text_view->gc, &rect); - printf ("String is: [%s]\n", str); - switch (ect->justify){ case GTK_JUSTIFY_LEFT: xoff = 1; @@ -90,20 +101,23 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, int col, int row, int x1 /* Draw now */ { GtkWidget *w = GTK_WIDGET (text_view->canvas); - GdkColor *background; - int idx; + GdkColor *background, *foreground; + const int height = text_view->font->ascent + text_view->font->descent; - if (selected) - idx = GTK_STATE_SELECTED; - else - idx = GTK_STATE_NORMAL; + if (selected){ + background = &w->style->bg [GTK_STATE_SELECTED]; + foreground = &w->style->text [GTK_STATE_SELECTED]; + } else { + background = &w->style->base [GTK_STATE_NORMAL]; + foreground = &w->style->text [GTK_STATE_NORMAL]; + } - gdk_gc_set_foreground (text_view->gc, &w->style->bg [idx]); + gdk_gc_set_foreground (text_view->gc, background); 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_gc_set_foreground (text_view->gc, foreground); gdk_draw_string (drawable, text_view->font, text_view->gc, - x1 + xoff, y2 - text_view->font->descent, str); + x1 + xoff, y2 - text_view->font->descent - ((y2-y1-height)/2), str); } } @@ -129,6 +143,14 @@ ect_event (ECellView *ecell_view, GdkEvent *event, int col, int row) } } +static int +ect_height (ECellView *ecell_view, int col, int row) +{ + ECellTextView *text_view = (ECellTextView *) ecell_view; + + return (text_view->font->ascent + text_view->font->descent) + TEXT_PAD; +} + static void ect_destroy (GtkObject *object) { @@ -150,7 +172,8 @@ e_cell_text_class_init (GtkObjectClass *object_class) ecc->unrealize = ect_unrealize; ecc->draw = ect_draw; ecc->event = ect_event; - + ecc->height = ect_height; + parent_class = gtk_type_class (PARENT_TYPE); } diff --git a/widgets/table/e-cell.c b/widgets/table/e-cell.c index bff0fb88f2..8a8897c22a 100644 --- a/widgets/table/e-cell.c +++ b/widgets/table/e-cell.c @@ -35,6 +35,13 @@ ec_event (ECellView *ecell_view, GdkEvent *event, int col, int row) g_warning ("e-cell-event invoked\n"); } +static gint +ec_height (ECellView *ecell_view, int col, int row) +{ + g_warning ("e-cell-event invoked\n"); + return 0; +} + static void ec_focus (ECellView *ecell_view, int col, int row, int x1, int y1, int x2, int y2) { @@ -68,6 +75,7 @@ e_cell_class_init (GtkObjectClass *object_class) ecc->event = ec_event; ecc->focus = ec_focus; ecc->unfocus = ec_unfocus; + ecc->height = ec_height; } static void @@ -107,3 +115,10 @@ e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, ecell_view, drawable, col, row, x1, y1, x2, y2); } +int +e_cell_height (ECellView *ecell_view, int col, int row) +{ + return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height ( + ecell_view, col, row); +} + diff --git a/widgets/table/e-cell.h b/widgets/table/e-cell.h index 08efaa6649..e57f341098 100644 --- a/widgets/table/e-cell.h +++ b/widgets/table/e-cell.h @@ -36,15 +36,17 @@ typedef struct { gint (*event) (ECellView *ecell_view, GdkEvent *event, int col, int row); void (*focus) (ECellView *ecell, int col, int row, int x1, int y1, int x2, int y2); void (*unfocus) (ECellView *ecell); + int (*height) (ECellView *ecell, int col, int row); } ECellClass; GtkType e_cell_get_type (void); void e_cell_event (ECellView *ecell_view, GdkEvent *event, int col, int row); ECellView *e_cell_realize (ECell *ecell, GnomeCanvas *canvas); -void e_cell_unrealize (ECellView *ecell); -void e_cell_draw (ECellView *ecell, GdkDrawable *dr, +void e_cell_unrealize (ECellView *ecell_view); +void e_cell_draw (ECellView *ecell_view, GdkDrawable *dr, int col, int row, int x1, int y1, int x2, int y2); -void e_cell_focus (ECellView *ecell, int col, int row, int x1, int y1, int x2, int y2); -void e_cell_unfocus (ECellView *ecell); +void e_cell_focus (ECellView *ecell_view, int col, int row, int x1, int y1, int x2, int y2); +void e_cell_unfocus (ECellView *ecell_view); +int e_cell_height (ECellView *ecell_view, int col, int row); #endif /* _E_CELL_H_ */ diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c index 1092874b9e..2ee8e2d619 100644 --- a/widgets/table/e-table-header-item.c +++ b/widgets/table/e-table-header-item.c @@ -376,6 +376,10 @@ ethi_event (GnomeCanvasItem *item, GdkEvent *e) set_cursor (ethi, x); break; + case GDK_LEAVE_NOTIFY: + e_cursor_set (GTK_WIDGET (canvas)->window, E_CURSOR_ARROW); + break; + case GDK_MOTION_NOTIFY: convert (canvas, e->motion.x, e->motion.y, &x, &y); if (resizing){ diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c index 387bb520bd..16b85fab6e 100644 --- a/widgets/table/e-table-item.c +++ b/widgets/table/e-table-item.c @@ -20,6 +20,7 @@ enum { ARG_TABLE_MODEL, ARG_TABLE_X, ARG_TABLE_Y, + ARG_LENGHT_THRESHOLD }; static void @@ -103,10 +104,47 @@ eti_remove_header_model (ETableItem *eti) eti->header = NULL; } +static int +eti_row_height (ETableItem *eti, int row) +{ + const int cols = e_table_header_count (eti->header); + int col; + int h, max_h; + + max_h = 0; + + for (col = 0; col < cols; col++){ + h = e_cell_height (eti->cell_views [col], col, row); + + if (h > max_h) + max_h = h; + } + return max_h; +} + +static int +eti_get_height (ETableItem *eti) +{ + const int rows = e_table_model_row_count (eti->table_model); + int row; + int height = 0; + + if (rows > eti->length_threshold){ + height = eti_row_height (eti, 0) * rows; + + return height; + } + + for (row = 0; row < rows; row++) + height += eti_row_height (eti, row); + + return height; +} + static void eti_table_model_changed (ETableModel *table_model, ETableItem *eti) { - eti->height = e_table_model_height (eti->table_model); + eti->height = eti_get_height (eti); eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); } @@ -122,7 +160,7 @@ eti_request_redraw (ETableItem *eti) } static void -eti_table_model_row_selection (ETableModel *table_model, ETableItem *eti) +eti_table_model_row_selection (ETableModel *table_model, int row, gboolean selected, ETableItem *eti) { /* FIXME: we should optimize this to only redraw the selection change */ eti_request_redraw (eti); @@ -217,8 +255,6 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) case ARG_TABLE_MODEL: eti_remove_table_model (eti); eti_add_table_model (eti, GTK_VALUE_POINTER (*arg)); - - eti->height = e_table_model_height (eti->table_model); break; case ARG_TABLE_X: @@ -229,6 +265,10 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) eti->y1 = GTK_VALUE_INT (*arg); break; + case ARG_LENGHT_THRESHOLD: + eti->length_threshold = GTK_VALUE_INT (*arg); + break; + } eti_update (item, NULL, NULL, 0); } @@ -240,6 +280,9 @@ eti_init (GnomeCanvasItem *item) eti->focused_col = -1; eti->focused_row = -1; + eti->height = 0; + + eti->length_threshold = -1; } static void @@ -260,6 +303,9 @@ eti_realize (GnomeCanvasItem *item) gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); eti_realize_cell_views (eti); + + eti->height = eti_get_height (eti); + eti_update (item, NULL, NULL, 0); } static void @@ -273,6 +319,8 @@ eti_unrealize (GnomeCanvasItem *item) eti->grid_gc = NULL; eti_unrealize_cell_views (eti); + + eti->height = 0; if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); @@ -293,10 +341,10 @@ draw_cell (ETableItem *eti, GdkDrawable *drawable, int col, int row, e_cell_draw (ecell_view, drawable, col, row, x1, y1, x2, y2); - gdk_draw_line (drawable, eti->grid_gc, x1, y1, x2, y2); +#if 0 + 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); -#if 0 sprintf (text, "%d:%d\n", col, row); gdk_draw_text (drawable, font, eti->grid_gc, x1, y2, text, strlen (text)); #endif @@ -358,7 +406,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, for (row = eti->top_item; row < rows; row++, y1 = y2){ int xd; - y2 += e_table_model_row_height (eti->table_model, row) + 1; + y2 += eti_row_height (eti, row); if (y1 > y + height) break; @@ -388,6 +436,52 @@ eti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, return 0.0; } +static gboolean +find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res) +{ + const int cols = e_table_header_count (eti->header); + const int rows = e_table_model_row_count (eti->table_model); + gdouble x1, y1, x2, y2; + int col, row; + + /* FIXME: inneficient, fix later */ + + x -= eti->x1; + y -= eti->y1; + + x1 = 0; + for (col = 0; col < cols; col++, x1 = x2){ + ETableCol *ecol = e_table_header_get_column (eti->header, col); + + if (x < x1) + return FALSE; + + x2 = x1 + ecol->width; + + if (x > x2) + continue; + + *col_res = col; + break; + } + + y1 = 0; + for (row = 0; row < rows; row++, y1 = y2){ + if (y < y1) + return FALSE; + + y2 += eti_row_height (eti, row); + + if (y > y2) + continue; + + *row_res = row; + break; + } + + return TRUE; +} + static int eti_event (GnomeCanvasItem *item, GdkEvent *e) { @@ -397,8 +491,18 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) switch (e->type){ case GDK_BUTTON_PRESS: case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: + case GDK_2BUTTON_PRESS: { + int col, row; + + if (!find_cell (eti, e->button.x, e->button.y, &col, &row)) + return TRUE; + ecell_view = eti->cell_views [col]; + printf ("Found: %d %d\n", col, row); + e_cell_event (ecell_view, e, col, row); + break; + } + case GDK_KEY_PRESS: case GDK_KEY_RELEASE: if (eti->focused_col == -1) @@ -408,9 +512,11 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e) e_cell_event (ecell_view, e, eti->focused_col, eti->focused_row); break; - + + default: + return FALSE; } - return FALSE; + return TRUE; } static void diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h index d694e62d68..b4b4c73361 100644 --- a/widgets/table/e-table-item.h +++ b/widgets/table/e-table-item.h @@ -41,6 +41,12 @@ typedef struct { */ ECellView **cell_views; int n_cells; + + /* + * Lengh Threshold: above this, we stop computing correctly + * the size + */ + int length_threshold; } ETableItem; typedef struct { diff --git a/widgets/table/e-table-model.c b/widgets/table/e-table-model.c index 1176b33ec7..3aa4e4be47 100644 --- a/widgets/table/e-table-model.c +++ b/widgets/table/e-table-model.c @@ -58,12 +58,6 @@ e_table_model_is_cell_editable (ETableModel *etable, int col, int row) return ETM_CLASS (etable)->is_cell_editable (etable, col, row); } -int -e_table_model_row_height (ETableModel *etable, int row) -{ - return ETM_CLASS (etable)->row_height (etable, row); -} - static void e_table_model_destroy (GtkObject *object) { @@ -101,6 +95,12 @@ e_table_model_class_init (GtkObjectClass *object_class) gtk_object_class_add_signals (object_class, etm_signals, LAST_SIGNAL); } +static void +e_table_model_init (ETableModel *etm) +{ + etm->row_selected = -1; +} + GtkType e_table_model_get_type (void) { @@ -112,7 +112,7 @@ e_table_model_get_type (void) sizeof (ETableModel), sizeof (ETableModelClass), (GtkClassInitFunc) e_table_model_class_init, - (GtkObjectInitFunc) NULL, + (GtkObjectInitFunc) e_table_model_init, NULL, /* reserved 1 */ NULL, /* reserved 2 */ (GtkClassInitFunc) NULL @@ -124,22 +124,6 @@ e_table_model_get_type (void) return type; } -int -e_table_model_height (ETableModel *etable) -{ - int rows, size, i; - - g_return_val_if_fail (etable != NULL, 0); - - rows = e_table_model_row_count (etable); - size = 0; - - for (i = 0; i < rows; i++) - size += e_table_model_row_height (etable, i) + 1; - - return size; -} - void e_table_model_changed (ETableModel *e_table_model) { diff --git a/widgets/table/e-table-model.h b/widgets/table/e-table-model.h index 2d439a0065..d8de9e819e 100644 --- a/widgets/table/e-table-model.h +++ b/widgets/table/e-table-model.h @@ -28,13 +28,12 @@ typedef struct { void *(*value_at) (ETableModel *etm, int col, int row); void (*set_value_at) (ETableModel *etm, int col, int row, void *value); gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - int (*row_height) (ETableModel *etm, int row); /* * Signals */ void (*model_changed) (ETableModel *etm); - void (*row_selection) (ETableModel *etc, int row); + void (*row_selection) (ETableModel *etc, int row, gboolean selected); } ETableModelClass; GtkType e_table_model_get_type (void); @@ -42,8 +41,6 @@ GtkType e_table_model_get_type (void); int e_table_model_column_count (ETableModel *e_table_model); const char *e_table_model_column_name (ETableModel *e_table_model, int col); int e_table_model_row_count (ETableModel *e_table_model); -int e_table_model_row_height (ETableModel *e_table_model, int row); -int e_table_model_height (ETableModel *e_table_model); void *e_table_model_value_at (ETableModel *e_table_model, int col, int row); void e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, void *data); gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row); diff --git a/widgets/table/e-table-simple.c b/widgets/table/e-table-simple.c index b23cda1220..16691e5442 100644 --- a/widgets/table/e-table-simple.c +++ b/widgets/table/e-table-simple.c @@ -62,14 +62,6 @@ simple_is_cell_editable (ETableModel *etm, int col, int row) return simple->is_cell_editable (etm, col, row, simple->data); } -static int -simple_row_height (ETableModel *etm, int row) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->row_height (etm, row, simple->data); -} - static void e_table_simple_class_init (GtkObjectClass *object_class) { @@ -81,7 +73,6 @@ e_table_simple_class_init (GtkObjectClass *object_class) model_class->value_at = simple_value_at; model_class->set_value_at = simple_set_value_at; model_class->is_cell_editable = simple_is_cell_editable; - model_class->row_height = simple_row_height; } GtkType @@ -114,7 +105,6 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleValueAtFn value_at, ETableSimpleSetValueAtFn set_value_at, ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleRowHeightFn row_height, void *data) { ETableSimple *et; @@ -127,7 +117,6 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, et->value_at = value_at; et->set_value_at = set_value_at; et->is_cell_editable = is_cell_editable; - et->row_height = row_height; return (ETableModel *) et; } diff --git a/widgets/table/e-table-simple.h b/widgets/table/e-table-simple.h index ac34d6045c..544e681a6c 100644 --- a/widgets/table/e-table-simple.h +++ b/widgets/table/e-table-simple.h @@ -9,7 +9,6 @@ typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *dat typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, void *val, void *data); typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); -typedef int (*ETableSimpleRowHeightFn) (ETableModel *etm, int row, void *data); typedef struct { ETableModel parent; @@ -20,7 +19,6 @@ typedef struct { ETableSimpleValueAtFn value_at; ETableSimpleSetValueAtFn set_value_at; ETableSimpleIsCellEditableFn is_cell_editable; - ETableSimpleRowHeightFn row_height; void *data; } ETableSimple; @@ -36,7 +34,6 @@ ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleValueAtFn value_at, ETableSimpleSetValueAtFn set_value_at, ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleRowHeightFn row_height, void *data); #endif /* _E_TABLE_SIMPLE_H_ */ diff --git a/widgets/table/table-test.c b/widgets/table/table-test.c index 4917511261..d7c14e900f 100644 --- a/widgets/table/table-test.c +++ b/widgets/table/table-test.c @@ -172,12 +172,6 @@ set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); } -static int -row_height (ETableModel *etm, int row, void *data) -{ - return row * 2 + 14; -} - int main (int argc, char *argv []) { @@ -197,13 +191,13 @@ main (int argc, char *argv []) */ e_table_model = e_table_simple_new ( col_count, col_name, row_count, value_at, - set_value_at, is_cell_editable, row_height, NULL); + set_value_at, is_cell_editable, NULL); /* * Header */ e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, "fixed", GTK_JUSTIFY_LEFT); + cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); for (i = 0; i < cols; i++){ ETableCol *ecol = e_table_col_new ( |