diff options
Diffstat (limited to 'widgets/e-table')
-rw-r--r-- | widgets/e-table/ChangeLog | 13 | ||||
-rw-r--r-- | widgets/e-table/Makefile.am | 15 | ||||
-rw-r--r-- | widgets/e-table/e-cell-checkbox.c | 157 | ||||
-rw-r--r-- | widgets/e-table/e-cell-checkbox.h | 7 | ||||
-rw-r--r-- | widgets/e-table/e-cell-toggle.c | 68 | ||||
-rw-r--r-- | widgets/e-table/image1.png | bin | 0 -> 1858 bytes | |||
-rw-r--r-- | widgets/e-table/image2.png | bin | 0 -> 1987 bytes | |||
-rw-r--r-- | widgets/e-table/image3.png | bin | 0 -> 2051 bytes | |||
-rw-r--r-- | widgets/e-table/table-test.c | 228 |
9 files changed, 103 insertions, 385 deletions
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog index 02cb902aea..d1a58f7022 100644 --- a/widgets/e-table/ChangeLog +++ b/widgets/e-table/ChangeLog @@ -1,3 +1,16 @@ +1999-11-30 Miguel de Icaza <miguel@gnu.org> + + * e-cell-checkbox.c (e_cell_checkbox_new): This one derives from + e-cell-toggle. + + * check-emtpy.xpm, check-filled.xpm: new files. + + * e-cell-toggle.c (etog_draw): Paint in white. + If we have transparency enabled, do the nice alpha computation. + + * test-table.c, test-cols.c: new files; They implement the split + tests. + 1999-11-29 Miguel de Icaza <miguel@gnu.org> * e-table-col.c (e_table_col_new): Set etc->resizeable. diff --git a/widgets/e-table/Makefile.am b/widgets/e-table/Makefile.am index ae5cfae4be..1b237dce70 100644 --- a/widgets/e-table/Makefile.am +++ b/widgets/e-table/Makefile.am @@ -9,6 +9,8 @@ noinst_LIBRARIES = \ libevolutionwidgets_a_SOURCES = \ e-cell.c \ e-cell.h \ + e-cell-checkbox.c \ + e-cell-checkbox.h \ e-cell-text.c \ e-cell-text.h \ e-cell-toggle.c \ @@ -36,11 +38,18 @@ noinst_PROGRAMS = \ table-test table_test_SOURCES = \ + test-table.c \ + test-check.c \ + test-cols.c \ table-test.c table_test_LDADD = \ $(EXTRA_GNOME_LIBS) \ - libevolutionwidgets.a + libevolutionwidgets.a + +table_test_LDFLAGS = `gnome-config --libs gdk_pixbuf` -EXTRA_DIST = \ - sample.table +EXTRA_DIST = \ + sample.table \ + check-empty.xpm \ + check-filled.xpm diff --git a/widgets/e-table/e-cell-checkbox.c b/widgets/e-table/e-cell-checkbox.c index db74464d5c..73620b9ce4 100644 --- a/widgets/e-table/e-cell-checkbox.c +++ b/widgets/e-table/e-cell-checkbox.c @@ -17,169 +17,28 @@ #include "e-util.h" #include "e-table-item.h" -#define PARENT_TYPE e_cell_get_type() +#include "check-empty.xpm" +#include "check-filled.xpm" -typedef struct { - ECellView cell_view; - GdkGC *gc; - GnomeCanvas *canvas; - ETableItem *eti; -} ECellCheckboxView; +#define PARENT_TYPE e_cell_toggle_get_type() -static ECellClass *parent_class; - -static void -eccb_queue_redraw (ECellCheckboxView *text_view, int col, int row) -{ - e_table_item_redraw_range (text_view->eti, col, row, col, row); -} - -/* - * ECell::realize method - */ -static ECellView * -eecb_realize (ECell *ecell, void *view) -{ - ECellCheckbox *eccb = E_CELL_CHECKBOX (ecell); - ECellCheckboxView *check_view = g_new0 (ECellCheckboxView, 1); - ETableItem *eti = E_TABLE_ITEM (view); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; - - check_view->cell_view.ecell = ecell; - check_view->gc = gdk_gc_new (GTK_WIDGET (canvas)->window); - check_view->eti = eti; - check_view->canvas = canvas; - - return (ECellView *) check_view; -} - -/* - * ECell::unrealize method - */ -static void -eecb_unrealize (ECellView *ecv) -{ - ECellCheckboxView *check_view = (ECellCheckboxView *) ecv; - - gdk_gc_unref (check_view->gc); - text_view->gc = NULL; - - g_free (check_view); -} - -/* - * ECell::draw method - */ -static void -eecb_draw (ECellView *ecell_view, GdkDrawable *drawable, - int col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ -} - -/* - * ECell::event method - */ -static gint -eecb_event (ECellView *ecell_view, GdkEvent *event, int col, int row) -{ - ECellCheckboxView *text_view = (ECellCheckboxView *) ecell_view; - - switch (event->type){ - case GDK_BUTTON_PRESS: - /* - * Adjust for the border we use - */ - event->button.x++; - - printf ("Button pressed at %g %g\n", event->button.x, event->button.y); - if (text_view->edit){ - printf ("FIXME: Should handle click here\n"); - } else - e_table_item_enter_edit (text_view->eti, col, row); - break; - - case GDK_BUTTON_RELEASE: - /* - * Adjust for the border we use - */ - event->button.x++; - printf ("Button released at %g %g\n", event->button.x, event->button.y); - return TRUE; - - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Escape){ - eecb_cancel_edit (text_view); - return TRUE; - } - - if (!text_view->edit){ - e_table_item_enter_edit (text_view->eti, col, row); - eecb_edit_seleecb_all (text_view); - } - - gtk_widget_event (GTK_WIDGET (text_view->edit->entry), event); - eecb_queue_redraw (text_view, col, row); - break; - - case GDK_KEY_RELEASE: - break; - - default: - return FALSE; - } - return TRUE; -} - -/* - * ECell::height method - */ -static int -eecb_height (ECellView *ecell_view, int col, int row) -{ - return 10; -} - -/* - * ECellView::enter_edit method - */ -static void * -eecb_enter_edit (ECellView *ecell_view, int col, int row) -{ -} - -/* - * ECellView::leave_edit method - */ -static void -eecb_leave_edit (ECellView *ecell_view, int col, int row, void *edit_context) -{ -} +static GdkPixbuf *checks [2]; static void e_cell_checkbox_class_init (GtkObjectClass *object_class) { - ECellClass *ecc = (ECellClass *) object_class; - - ecc->realize = eecb_realize; - ecc->unrealize = eecb_unrealize; - ecc->draw = eecb_draw; - ecc->event = eecb_event; - ecc->height = eecb_height; - ecc->enter_edit = eecb_enter_edit; - ecc->leave_edit = eecb_leave_edit; - - parent_class = gtk_type_class (PARENT_TYPE); + checks [0] = gdk_pixbuf_new_from_xpm_data (check_empty_xpm); + checks [1] = gdk_pixbuf_new_from_xpm_data (check_filled_xpm); } -E_MAKE_TYPE(e_cell_text, "ECellCheckbox", ECellCheckbox, e_cell_checkbox_class_init, NULL, PARENT_TYPE); +E_MAKE_TYPE(e_cell_checkbox, "ECellCheckbox", ECellCheckbox, e_cell_checkbox_class_init, NULL, PARENT_TYPE); ECell * e_cell_checkbox_new (ETableModel *etm) { ECellCheckbox *eccb = gtk_type_new (e_cell_checkbox_get_type ()); - E_CELL (eccb)->table_model = etm; + e_cell_toggle_construct (E_CELL_TOGGLE (eccb), etm, 2, 2, checks); return (ECell *) eccb; } diff --git a/widgets/e-table/e-cell-checkbox.h b/widgets/e-table/e-cell-checkbox.h index 6c85fbff21..6afca6bde2 100644 --- a/widgets/e-table/e-cell-checkbox.h +++ b/widgets/e-table/e-cell-checkbox.h @@ -1,8 +1,7 @@ #ifndef _E_CELL_CHECKBOX_H_ #define _E_CELL_CHECKBOX_H_ -#include <libgnomeui/gnome-canvas.h> -#include "e-cell.h" +#include "e-cell-toggle.h" #define E_CELL_CHECKBOX_TYPE (e_cell_checkbox_get_type ()) #define E_CELL_CHECKBOX(o) (GTK_CHECK_CAST ((o), E_CELL_CHECKBOX_TYPE, ECellCheckbox)) @@ -11,11 +10,11 @@ #define E_IS_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_CHECKBOX_TYPE)) typedef struct { - ECell parent; + ECellToggle parent; } ECellCheckbox; typedef struct { - ECellClass parent_class; + ECellToggleClass parent_class; } ECellCheckboxClass; GtkType e_cell_checkbox_get_type (void); diff --git a/widgets/e-table/e-cell-toggle.c b/widgets/e-table/e-cell-toggle.c index b12db945b3..8e06d8d87d 100644 --- a/widgets/e-table/e-cell-toggle.c +++ b/widgets/e-table/e-cell-toggle.c @@ -48,6 +48,7 @@ etog_realize (ECell *ecell, void *view) toggle_view->cell_view.ecell = ecell; toggle_view->eti = eti; toggle_view->canvas = canvas; + toggle_view->gc = gdk_gc_new (GTK_WIDGET (canvas)->window); return (ECellView *) toggle_view; } @@ -60,6 +61,9 @@ etog_unrealize (ECellView *ecv) { ECellToggleView *toggle_view = (ECellToggleView *) ecv; + gdk_gc_unref (toggle_view->gc); + toggle_view->gc = NULL; + g_free (toggle_view); } @@ -76,6 +80,7 @@ etog_draw (ECellView *ecell_view, GdkDrawable *drawable, GdkPixbuf *image; ArtPixBuf *art; int x, y, width, height; + gboolean free_image; const int value = GPOINTER_TO_INT ( e_table_model_value_at (ecell_view->ecell->table_model, col, row)); @@ -85,6 +90,11 @@ etog_draw (ECellView *ecell_view, GdkDrawable *drawable, return; } + /* + * Paint the background + */ + gdk_draw_rectangle (drawable, GTK_WIDGET (toggle_view->canvas)->style->white_gc, TRUE, x1, y1, x2 - x1, y2 - y1); + image = toggle->images [value]; art = image->art_pixbuf; @@ -104,13 +114,55 @@ etog_draw (ECellView *ecell_view, GdkDrawable *drawable, height = art->height; } - width = y2 - y1; - gdk_pixbuf_render_to_drawable_alpha ( - image, drawable, 0, 0, x, y, - width, height, - GDK_PIXBUF_ALPHA_FULL, 0, - GDK_RGB_DITHER_NORMAL, - 0, 0); + width = y2 - y1; + + if (image->art_pixbuf->has_alpha){ + GdkColor background; + guchar *buffer; + int alpha, ix, iy; + + buffer = g_malloc (art->rowstride * art->height * 3); + + background.red = 255; + background.green = 255; + background.blue = 255; + + for (iy = 0; iy < art->height; iy++){ + unsigned char *dest; + unsigned char *src; + + dest = buffer + (iy * art->rowstride); + src = art->pixels + (iy * art->rowstride); + + for (ix = 0; ix < art->width; ix++){ + alpha = src [3]; + if (alpha == 0){ + *dest++ = background.red; + *dest++ = background.green; + *dest++ = background.blue; + src += 3; + } else if (alpha == 255){ + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + } else { + *dest++ = (background.red + ((*src++ - background.red) * alpha + 0x80)) >> 8; + *dest++ = (background.green + ((*src++ - background.green) * alpha + 0x80)) >> 8; + *dest++ = (background.blue + ((*src++ - background.blue) * alpha + 0x80)) >> 8; + } + src++; + } + } + + gdk_draw_rgb_image_dithalign ( + drawable, toggle_view->gc, x, y, width, height, + GDK_RGB_DITHER_NORMAL, buffer, art->rowstride, 0, 0); + + g_free (buffer); + } else + gdk_draw_rgb_image_dithalign ( + drawable, toggle_view->gc, x, y, width, height, + GDK_RGB_DITHER_NORMAL, art->pixels, art->rowstride, 0, 0); } static void @@ -196,7 +248,7 @@ e_cell_toggle_class_init (GtkObjectClass *object_class) parent_class = gtk_type_class (PARENT_TYPE); } -E_MAKE_TYPE(e_cell_text, "ECellToggle", ECellToggle, e_cell_toggle_class_init, NULL, PARENT_TYPE); +E_MAKE_TYPE(e_cell_toggle, "ECellToggle", ECellToggle, e_cell_toggle_class_init, NULL, PARENT_TYPE); void e_cell_toggle_construct (ECellToggle *etog, ETableModel *etm, int border, int n_states, GdkPixbuf **images) diff --git a/widgets/e-table/image1.png b/widgets/e-table/image1.png Binary files differnew file mode 100644 index 0000000000..8326ac241f --- /dev/null +++ b/widgets/e-table/image1.png diff --git a/widgets/e-table/image2.png b/widgets/e-table/image2.png Binary files differnew file mode 100644 index 0000000000..e6a4c75dbe --- /dev/null +++ b/widgets/e-table/image2.png diff --git a/widgets/e-table/image3.png b/widgets/e-table/image3.png Binary files differnew file mode 100644 index 0000000000..50e16e8620 --- /dev/null +++ b/widgets/e-table/image3.png diff --git a/widgets/e-table/table-test.c b/widgets/e-table/table-test.c index 4ff03016b4..706dec437c 100644 --- a/widgets/e-table/table-test.c +++ b/widgets/e-table/table-test.c @@ -8,237 +8,23 @@ #include <stdio.h> #include <string.h> #include <gnome.h> -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cursors.h" -#include "e-cell-text.h" -char buffer [1024]; -char **column_labels; -char ***table_data; -int cols = 0; -int lines = 0; -int lines_alloc = 0; - -static void -parse_headers () +int +main (int argc, char *argv []) { - char *p, *s; - int in_value = 0, i; - - fgets (buffer, sizeof (buffer)-1, stdin); - for (p = buffer; *p; p++){ - if (*p == ' ' || *p == '\t'){ - if (in_value){ - cols++; - in_value = 0; - } - } else - in_value = 1; - } - if (in_value) - cols++; - - if (!cols){ - fprintf (stderr, "No columns in first row\n"); + if (isatty (0)){ + printf ("you have to provide data on standard input\n"); exit (1); } - - column_labels = g_new0 (char *, cols); - - p = buffer; - for (i = 0; (s = strtok (p, " \t")) != NULL; i++){ - column_labels [i] = g_strdup (s); - p = NULL; - } - - printf ("%d headers:\n", cols); - for (i = 0; i < cols; i++){ - printf ("header %d: %s\n", i, column_labels [i]); - } -} - -static char ** -load_line (char *buffer, int cols) -{ - char **line = g_new0 (char *, cols); - char *p; - int i; - - for (i = 0; i < cols; i++){ - p = strtok (buffer, " \t\n"); - if (p == NULL){ - for (; i < cols; i++) - line [i] = g_strdup (""); - return line; - } else - line [i] = g_strdup (p); - buffer = NULL; - } - return line; -} - -static void -append_line (char **line) -{ - if (lines <= lines_alloc){ - lines_alloc = lines + 50; - table_data = g_renew (char **, table_data, lines_alloc); - } - table_data [lines] = line; - lines++; -} - -static void -load_data () -{ - int i; - - parse_headers (); - - while (fgets (buffer, sizeof (buffer)-1, stdin) != NULL){ - char **line; - - if (buffer [0] == '\n') - continue; - line = load_line (buffer, cols); - append_line (line); - } - - for (i = 0; i < lines; i++){ - int j; - - printf ("Line %d: ", i); - for (j = 0; j < cols; j++) - printf ("[%s] ", table_data [i][j]); - printf ("\n"); - } -} - -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return cols; -} - -static const char * -col_name (ETableModel *etc, int col, void *data) -{ - g_assert (col < cols); - - return column_labels [col]; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return lines; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - return (void *) table_data [row][col]; -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -int -main (int argc, char *argv []) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ECell *cell_left_just; - int i; gnome_init ("TableTest", "TableTest", argc, argv); e_cursors_init (); - - load_data (); - - /* - * Data model - */ - e_table_model = e_table_simple_new ( - col_count, col_name, row_count, value_at, - 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, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - column_labels [i], 80, 20, cell_left_just, - g_str_equal, TRUE); - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Setup GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = gnome_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); + table_browser_test (); + multi_cols_test (); + check_test (); - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - "x", 0, - "y", 0, - NULL); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "x", 10, - "y", 30, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); gtk_main (); e_cursors_shutdown (); |