aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/e-table/e-cell-text.c
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@gnu.org>1999-11-25 16:02:13 +0800
committerArturo Espinosa <unammx@src.gnome.org>1999-11-25 16:02:13 +0800
commit385ccbd512c4c43305dee900f86d0f51f94b1200 (patch)
tree81920b9b2281f21a55ccd417895d0bd3a271cff7 /widgets/e-table/e-cell-text.c
parent858500c40a2bf4485e75e1a056d0310b92625929 (diff)
downloadgsoc2013-evolution-385ccbd512c4c43305dee900f86d0f51f94b1200.tar
gsoc2013-evolution-385ccbd512c4c43305dee900f86d0f51f94b1200.tar.gz
gsoc2013-evolution-385ccbd512c4c43305dee900f86d0f51f94b1200.tar.bz2
gsoc2013-evolution-385ccbd512c4c43305dee900f86d0f51f94b1200.tar.lz
gsoc2013-evolution-385ccbd512c4c43305dee900f86d0f51f94b1200.tar.xz
gsoc2013-evolution-385ccbd512c4c43305dee900f86d0f51f94b1200.tar.zst
gsoc2013-evolution-385ccbd512c4c43305dee900f86d0f51f94b1200.zip
Realize cells.
1999-11-25 Miguel de Icaza <miguel@gnu.org> * e-table-header-item.c (ethi_realize): Realize cells. * e-table-item.c (eti_header_dim_changed): redraw before and after. * e-table-header-item.c (ethi_event): Add continuous resizing. 1999-11-24 Miguel de Icaza <miguel@gnu.org> * e-table-subset.h, e-table-subset.c: New files, used to implement subset tables. * e-table-sorted.h, e-table-sorted.c: Now they derive from e-table-subset. * e-cell.c, e-cell.h: realize method now return per view instance data. svn path=/trunk/; revision=1434
Diffstat (limited to 'widgets/e-table/e-cell-text.c')
-rw-r--r--widgets/e-table/e-cell-text.c139
1 files changed, 127 insertions, 12 deletions
diff --git a/widgets/e-table/e-cell-text.c b/widgets/e-table/e-cell-text.c
index c30e42cfd3..1b3f524a2e 100644
--- a/widgets/e-table/e-cell-text.c
+++ b/widgets/e-table/e-cell-text.c
@@ -7,42 +7,157 @@
* (C) 1999 Helix Code, Inc
*/
#include <config.h>
+#include <gtk/gtkenums.h>
#include "e-cell-text.h"
#include "e-util.h"
-#define PARENT_TYPE gtk_object_get_type()
+#define PARENT_TYPE e_cell_get_type()
+
+typedef struct {
+ ECellView cell_view;
+ GdkGC *gc;
+ GdkFont *font;
+ GnomeCanvas *canvas;
+} ECellTextView;
+
+static ECellClass *parent_class;
+
+static ECellView *
+ect_realize (ECell *ecell, GnomeCanvas *canvas)
+{
+ ECellText *ect = E_CELL_TEXT (ecell);
+ ECellTextView *ectv = g_new (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");
+ ectv->canvas = canvas;
+
+ return (ECellView *)ectv;
+}
static void
-ec_realize (ECell *e_cell, GnomeCanvas *canvas)
+ect_unrealize (ECellView *ecv)
{
+ ECellTextView *ectv = (ECellTextView *) ecv;
+
+ gdk_gc_unref (ectv->gc);
+ ectv->gc = NULL;
+
+ gdk_font_unref (ectv->font);
+ ectv->font = NULL;
+
+ g_free (ectv);
}
static void
-ec_unrealize (ECell *e_cell)
+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);
+ 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;
+ int xoff, w;
+
+ rect.x = x1;
+ rect.y = y1;
+ rect.width = x2 - x1;
+ rect.height = y2 - y1;
+
+ gdk_gc_set_clip_rectangle (ect->gc, &rect);
+
+ switch (ect->justify){
+ case GTK_JUSTIFY_LEFT:
+ xoff = 1;
+ break;
+
+ case GTK_JUSTIFY_RIGHT:
+ w = 1 + gdk_text_width (ect->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;
+ break;
+ default:
+ g_warning ("Can not handle GTK_JUSTIFY_FILL");
+ break;
+ }
+
+ /* Draw now */
+ {
+ GtkWidget *w = GTK_WIDGET (ect->canvas);
+ GdkColor *background;
+ int idx;
+
+ if (selected)
+ idx = GTK_STATE_SELECTED;
+ 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);
+ }
}
static void
-ec_draw (ECell *ecell, int x1, int y1, int x2, int y2)
+e_cell_text_start_editing (ECellText *ect, int col, int row)
{
+ printf ("Starting to edit %d %d\n", col, row);
}
static gint
-ec_event (ECell *ecell, GdkEvent *event)
+ect_event (ECellView *ecell_view, GdkEvent *event, int col, int row)
{
+ ECell *ecell = ecell_view->ecell;
+ ECellText *ect = E_CELL_TEXT (ecell);
+
+ switch (event->type){
+ case GDK_BUTTON_PRESS:
+ if (e_table_model_get_selected_row (ecell->table_model) == row)
+ e_cell_text_start_editing (ect, col, row);
+ else
+ e_table_model_select_row (ecell->table_model, row);
+ return TRUE;
+ }
}
static void
-e_cell_class_init (GtkObjectClass *object_class)
+ect_destroy (GtkObject *object)
{
- ECellClass *ecc = (ECellClass *) object_class;
+ ECellText *ect = E_CELL_TEXT (object);
+
+ g_free (ect->font_name);
- ecc->realize = ec_realize;
- ecc->unrealize = ec_unrealize;
- ecc->draw = ec_draw;
- ecc->event = ec_event;
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
-E_MAKE_TYPE(e_cell, "ECell", ECell, e_cell_class_init, NULL, PARENT_TYPE);
+static void
+e_cell_text_class_init (GtkObjectClass *object_class)
+{
+ ECellClass *ecc = (ECellClass *) object_class;
+ object_class->destroy = ect_destroy;
+ ecc->realize = ect_realize;
+ ecc->unrealize = ect_unrealize;
+ ecc->draw = ect_draw;
+ ecc->event = ect_event;
+
+ parent_class = gtk_type_class (PARENT_TYPE);
+}
+
+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)
+{
+ ECellText *ect = gtk_type_new (e_cell_text_get_type ());
+
+ ect->font_name = g_strdup (fontname);
+ ect->justify = justify;
+
+ return (ECell *) ect;
+}