diff options
-rw-r--r-- | widgets/check-empty.xpm | 21 | ||||
-rw-r--r-- | widgets/check-filled.xpm | 22 | ||||
-rw-r--r-- | widgets/e-table/check-empty.xpm | 21 | ||||
-rw-r--r-- | widgets/e-table/check-filled.xpm | 22 | ||||
-rw-r--r-- | widgets/e-table/test-check.c | 163 | ||||
-rw-r--r-- | widgets/e-table/test-cols.c | 178 | ||||
-rw-r--r-- | widgets/e-table/test-table.c | 240 | ||||
-rw-r--r-- | widgets/table/check-empty.xpm | 21 | ||||
-rw-r--r-- | widgets/table/check-filled.xpm | 22 | ||||
-rw-r--r-- | widgets/table/test-check.c | 163 | ||||
-rw-r--r-- | widgets/table/test-cols.c | 178 | ||||
-rw-r--r-- | widgets/table/test-table.c | 240 | ||||
-rw-r--r-- | widgets/test-check.c | 163 | ||||
-rw-r--r-- | widgets/test-cols.c | 178 | ||||
-rw-r--r-- | widgets/test-table.c | 240 |
15 files changed, 1872 insertions, 0 deletions
diff --git a/widgets/check-empty.xpm b/widgets/check-empty.xpm new file mode 100644 index 0000000000..68c2c168ce --- /dev/null +++ b/widgets/check-empty.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static const char * check_empty_xpm[] = { +"16 16 2 1", +" c None", +". c #000000", +" ", +" .............. ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" .............. ", +" "}; diff --git a/widgets/check-filled.xpm b/widgets/check-filled.xpm new file mode 100644 index 0000000000..c2a2b4a097 --- /dev/null +++ b/widgets/check-filled.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static char * check_filled_xpm[] = { +"16 16 3 1", +" c None", +". c #000000", +"+ c #FF0000", +" ", +" .............. ", +" . . ", +" . + . ", +" . ++ . ", +" . ++ . ", +" . +++ . ", +" . +++ . ", +" . ++ +++ . ", +" . ++++++ . ", +" . +++++ . ", +" . +++ . ", +" . + . ", +" . . ", +" .............. ", +" "}; diff --git a/widgets/e-table/check-empty.xpm b/widgets/e-table/check-empty.xpm new file mode 100644 index 0000000000..68c2c168ce --- /dev/null +++ b/widgets/e-table/check-empty.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static const char * check_empty_xpm[] = { +"16 16 2 1", +" c None", +". c #000000", +" ", +" .............. ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" .............. ", +" "}; diff --git a/widgets/e-table/check-filled.xpm b/widgets/e-table/check-filled.xpm new file mode 100644 index 0000000000..c2a2b4a097 --- /dev/null +++ b/widgets/e-table/check-filled.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static char * check_filled_xpm[] = { +"16 16 3 1", +" c None", +". c #000000", +"+ c #FF0000", +" ", +" .............. ", +" . . ", +" . + . ", +" . ++ . ", +" . ++ . ", +" . +++ . ", +" . +++ . ", +" . ++ +++ . ", +" . ++++++ . ", +" . +++++ . ", +" . +++ . ", +" . + . ", +" . . ", +" .............. ", +" "}; diff --git a/widgets/e-table/test-check.c b/widgets/e-table/test-check.c new file mode 100644 index 0000000000..49c7f44f70 --- /dev/null +++ b/widgets/e-table/test-check.c @@ -0,0 +1,163 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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" +#include "e-cell-checkbox.h" + +#define LINES 4 + +static struct { + int value; + char *string; +} my_table [LINES] = { + { 0, "Buy food" }, + { 1, "Breathe " }, + { 0, "Cancel gdb session with shrink" }, + { 1, "Make screenshots" }, +}; +/* + * ETableSimple callbacks + */ +static int +col_count (ETableModel *etc, void *data) +{ + return 2; +} + +static const char * +col_name (ETableModel *etc, int col, void *data) +{ + g_assert (col < 2); + + if (col == 0) + return "flag"; + else + return "text"; +} + +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 < 2); + g_assert (row < LINES); + + if (col == 0) + return GINT_TO_POINTER (my_table [row].value); + else + return my_table [row].string; + +} + +static void +set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) +{ + g_assert (col < 2); + g_assert (row < LINES); + + if (col == 0){ + my_table [row].value = GPOINTER_TO_INT (val); + printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); + } else { + my_table [row].string = 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); +} + +void +check_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ETableCol *col_0, *col_1; + ECell *cell_left_just, *cell_image_check; + int i; + + gtk_widget_push_visual (gdk_rgb_get_visual ()); + gtk_widget_push_colormap (gdk_rgb_get_cmap ()); + + 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); + + cell_image_check = e_cell_checkbox_new (e_table_model); + col_0 = e_table_col_new ("", 18, 18, cell_image_check, g_int_equal, TRUE); + e_table_header_add_column (e_table_header, col_0, 0); + + col_1 = e_table_col_new ("Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); + e_table_header_add_column (e_table_header, col_1, 1); + + /* + * 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); + + 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", 0, + "y", 30, + "drawgrid", TRUE, + "drawfocus", TRUE, + "spreadsheet", TRUE, + NULL); + +} + + + + + diff --git a/widgets/e-table/test-cols.c b/widgets/e-table/test-cols.c new file mode 100644 index 0000000000..f8fb01081f --- /dev/null +++ b/widgets/e-table/test-cols.c @@ -0,0 +1,178 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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" +#include "e-cell-toggle.h" + +#define LINES 4 + +static struct { + int value; + char *string; +} my_table [LINES] = { + { 0, "You are not" }, + { 1, "A beautiful and unique " }, + { 0, "Snowflake" }, + { 2, "You are not your wallet" }, +}; +/* + * ETableSimple callbacks + */ +static int +col_count (ETableModel *etc, void *data) +{ + return 2; +} + +static const char * +col_name (ETableModel *etc, int col, void *data) +{ + g_assert (col < 2); + + if (col == 0) + return "flag"; + else + return "text"; +} + +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 < 2); + g_assert (row < LINES); + + if (col == 0) + return GINT_TO_POINTER (my_table [row].value); + else + return my_table [row].string; + +} + +static void +set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) +{ + g_assert (col < 2); + g_assert (row < LINES); + + if (col == 0){ + my_table [row].value = GPOINTER_TO_INT (val); + printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); + } else { + my_table [row].string = 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); +} + +void +multi_cols_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ETableCol *col_0, *col_1; + ECell *cell_left_just, *cell_image_toggle; + int i; + + gtk_widget_push_visual (gdk_rgb_get_visual ()); + gtk_widget_push_colormap (gdk_rgb_get_cmap ()); + + 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); + + { + GdkPixbuf **images = g_new (GdkPixbuf *, 3); + int i; + + images [0] = gdk_pixbuf_new_from_file ("image1.png"); + images [1] = gdk_pixbuf_new_from_file ("image2.png"); + images [2] = gdk_pixbuf_new_from_file ("image3.png"); + + cell_image_toggle = e_cell_toggle_new (e_table_model, 0, 3, images); + + for (i = 0; i < 3; i++) + gdk_pixbuf_unref (images [i]); + + g_free (images); + } + + col_0 = e_table_col_new ("A", 48, 48, cell_image_toggle, g_int_equal, TRUE); + e_table_header_add_column (e_table_header, col_0, 0); + + col_1 = e_table_col_new ("Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); + e_table_header_add_column (e_table_header, col_1, 1); + + /* + * 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); + + 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", 0, + "y", 30, + "drawgrid", TRUE, + "drawfocus", TRUE, + "spreadsheet", TRUE, + NULL); + +} + + + + + diff --git a/widgets/e-table/test-table.c b/widgets/e-table/test-table.c new file mode 100644 index 0000000000..56cdd0f208 --- /dev/null +++ b/widgets/e-table/test-table.c @@ -0,0 +1,240 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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 () +{ + 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"); + 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); +} + +void +table_browser_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ECell *cell_left_just; + int i; + + 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); + + 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); +} + diff --git a/widgets/table/check-empty.xpm b/widgets/table/check-empty.xpm new file mode 100644 index 0000000000..68c2c168ce --- /dev/null +++ b/widgets/table/check-empty.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static const char * check_empty_xpm[] = { +"16 16 2 1", +" c None", +". c #000000", +" ", +" .............. ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" .............. ", +" "}; diff --git a/widgets/table/check-filled.xpm b/widgets/table/check-filled.xpm new file mode 100644 index 0000000000..c2a2b4a097 --- /dev/null +++ b/widgets/table/check-filled.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static char * check_filled_xpm[] = { +"16 16 3 1", +" c None", +". c #000000", +"+ c #FF0000", +" ", +" .............. ", +" . . ", +" . + . ", +" . ++ . ", +" . ++ . ", +" . +++ . ", +" . +++ . ", +" . ++ +++ . ", +" . ++++++ . ", +" . +++++ . ", +" . +++ . ", +" . + . ", +" . . ", +" .............. ", +" "}; diff --git a/widgets/table/test-check.c b/widgets/table/test-check.c new file mode 100644 index 0000000000..49c7f44f70 --- /dev/null +++ b/widgets/table/test-check.c @@ -0,0 +1,163 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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" +#include "e-cell-checkbox.h" + +#define LINES 4 + +static struct { + int value; + char *string; +} my_table [LINES] = { + { 0, "Buy food" }, + { 1, "Breathe " }, + { 0, "Cancel gdb session with shrink" }, + { 1, "Make screenshots" }, +}; +/* + * ETableSimple callbacks + */ +static int +col_count (ETableModel *etc, void *data) +{ + return 2; +} + +static const char * +col_name (ETableModel *etc, int col, void *data) +{ + g_assert (col < 2); + + if (col == 0) + return "flag"; + else + return "text"; +} + +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 < 2); + g_assert (row < LINES); + + if (col == 0) + return GINT_TO_POINTER (my_table [row].value); + else + return my_table [row].string; + +} + +static void +set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) +{ + g_assert (col < 2); + g_assert (row < LINES); + + if (col == 0){ + my_table [row].value = GPOINTER_TO_INT (val); + printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); + } else { + my_table [row].string = 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); +} + +void +check_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ETableCol *col_0, *col_1; + ECell *cell_left_just, *cell_image_check; + int i; + + gtk_widget_push_visual (gdk_rgb_get_visual ()); + gtk_widget_push_colormap (gdk_rgb_get_cmap ()); + + 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); + + cell_image_check = e_cell_checkbox_new (e_table_model); + col_0 = e_table_col_new ("", 18, 18, cell_image_check, g_int_equal, TRUE); + e_table_header_add_column (e_table_header, col_0, 0); + + col_1 = e_table_col_new ("Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); + e_table_header_add_column (e_table_header, col_1, 1); + + /* + * 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); + + 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", 0, + "y", 30, + "drawgrid", TRUE, + "drawfocus", TRUE, + "spreadsheet", TRUE, + NULL); + +} + + + + + diff --git a/widgets/table/test-cols.c b/widgets/table/test-cols.c new file mode 100644 index 0000000000..f8fb01081f --- /dev/null +++ b/widgets/table/test-cols.c @@ -0,0 +1,178 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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" +#include "e-cell-toggle.h" + +#define LINES 4 + +static struct { + int value; + char *string; +} my_table [LINES] = { + { 0, "You are not" }, + { 1, "A beautiful and unique " }, + { 0, "Snowflake" }, + { 2, "You are not your wallet" }, +}; +/* + * ETableSimple callbacks + */ +static int +col_count (ETableModel *etc, void *data) +{ + return 2; +} + +static const char * +col_name (ETableModel *etc, int col, void *data) +{ + g_assert (col < 2); + + if (col == 0) + return "flag"; + else + return "text"; +} + +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 < 2); + g_assert (row < LINES); + + if (col == 0) + return GINT_TO_POINTER (my_table [row].value); + else + return my_table [row].string; + +} + +static void +set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) +{ + g_assert (col < 2); + g_assert (row < LINES); + + if (col == 0){ + my_table [row].value = GPOINTER_TO_INT (val); + printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); + } else { + my_table [row].string = 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); +} + +void +multi_cols_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ETableCol *col_0, *col_1; + ECell *cell_left_just, *cell_image_toggle; + int i; + + gtk_widget_push_visual (gdk_rgb_get_visual ()); + gtk_widget_push_colormap (gdk_rgb_get_cmap ()); + + 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); + + { + GdkPixbuf **images = g_new (GdkPixbuf *, 3); + int i; + + images [0] = gdk_pixbuf_new_from_file ("image1.png"); + images [1] = gdk_pixbuf_new_from_file ("image2.png"); + images [2] = gdk_pixbuf_new_from_file ("image3.png"); + + cell_image_toggle = e_cell_toggle_new (e_table_model, 0, 3, images); + + for (i = 0; i < 3; i++) + gdk_pixbuf_unref (images [i]); + + g_free (images); + } + + col_0 = e_table_col_new ("A", 48, 48, cell_image_toggle, g_int_equal, TRUE); + e_table_header_add_column (e_table_header, col_0, 0); + + col_1 = e_table_col_new ("Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); + e_table_header_add_column (e_table_header, col_1, 1); + + /* + * 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); + + 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", 0, + "y", 30, + "drawgrid", TRUE, + "drawfocus", TRUE, + "spreadsheet", TRUE, + NULL); + +} + + + + + diff --git a/widgets/table/test-table.c b/widgets/table/test-table.c new file mode 100644 index 0000000000..56cdd0f208 --- /dev/null +++ b/widgets/table/test-table.c @@ -0,0 +1,240 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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 () +{ + 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"); + 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); +} + +void +table_browser_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ECell *cell_left_just; + int i; + + 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); + + 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); +} + diff --git a/widgets/test-check.c b/widgets/test-check.c new file mode 100644 index 0000000000..49c7f44f70 --- /dev/null +++ b/widgets/test-check.c @@ -0,0 +1,163 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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" +#include "e-cell-checkbox.h" + +#define LINES 4 + +static struct { + int value; + char *string; +} my_table [LINES] = { + { 0, "Buy food" }, + { 1, "Breathe " }, + { 0, "Cancel gdb session with shrink" }, + { 1, "Make screenshots" }, +}; +/* + * ETableSimple callbacks + */ +static int +col_count (ETableModel *etc, void *data) +{ + return 2; +} + +static const char * +col_name (ETableModel *etc, int col, void *data) +{ + g_assert (col < 2); + + if (col == 0) + return "flag"; + else + return "text"; +} + +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 < 2); + g_assert (row < LINES); + + if (col == 0) + return GINT_TO_POINTER (my_table [row].value); + else + return my_table [row].string; + +} + +static void +set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) +{ + g_assert (col < 2); + g_assert (row < LINES); + + if (col == 0){ + my_table [row].value = GPOINTER_TO_INT (val); + printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); + } else { + my_table [row].string = 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); +} + +void +check_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ETableCol *col_0, *col_1; + ECell *cell_left_just, *cell_image_check; + int i; + + gtk_widget_push_visual (gdk_rgb_get_visual ()); + gtk_widget_push_colormap (gdk_rgb_get_cmap ()); + + 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); + + cell_image_check = e_cell_checkbox_new (e_table_model); + col_0 = e_table_col_new ("", 18, 18, cell_image_check, g_int_equal, TRUE); + e_table_header_add_column (e_table_header, col_0, 0); + + col_1 = e_table_col_new ("Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); + e_table_header_add_column (e_table_header, col_1, 1); + + /* + * 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); + + 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", 0, + "y", 30, + "drawgrid", TRUE, + "drawfocus", TRUE, + "spreadsheet", TRUE, + NULL); + +} + + + + + diff --git a/widgets/test-cols.c b/widgets/test-cols.c new file mode 100644 index 0000000000..f8fb01081f --- /dev/null +++ b/widgets/test-cols.c @@ -0,0 +1,178 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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" +#include "e-cell-toggle.h" + +#define LINES 4 + +static struct { + int value; + char *string; +} my_table [LINES] = { + { 0, "You are not" }, + { 1, "A beautiful and unique " }, + { 0, "Snowflake" }, + { 2, "You are not your wallet" }, +}; +/* + * ETableSimple callbacks + */ +static int +col_count (ETableModel *etc, void *data) +{ + return 2; +} + +static const char * +col_name (ETableModel *etc, int col, void *data) +{ + g_assert (col < 2); + + if (col == 0) + return "flag"; + else + return "text"; +} + +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 < 2); + g_assert (row < LINES); + + if (col == 0) + return GINT_TO_POINTER (my_table [row].value); + else + return my_table [row].string; + +} + +static void +set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) +{ + g_assert (col < 2); + g_assert (row < LINES); + + if (col == 0){ + my_table [row].value = GPOINTER_TO_INT (val); + printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); + } else { + my_table [row].string = 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); +} + +void +multi_cols_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ETableCol *col_0, *col_1; + ECell *cell_left_just, *cell_image_toggle; + int i; + + gtk_widget_push_visual (gdk_rgb_get_visual ()); + gtk_widget_push_colormap (gdk_rgb_get_cmap ()); + + 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); + + { + GdkPixbuf **images = g_new (GdkPixbuf *, 3); + int i; + + images [0] = gdk_pixbuf_new_from_file ("image1.png"); + images [1] = gdk_pixbuf_new_from_file ("image2.png"); + images [2] = gdk_pixbuf_new_from_file ("image3.png"); + + cell_image_toggle = e_cell_toggle_new (e_table_model, 0, 3, images); + + for (i = 0; i < 3; i++) + gdk_pixbuf_unref (images [i]); + + g_free (images); + } + + col_0 = e_table_col_new ("A", 48, 48, cell_image_toggle, g_int_equal, TRUE); + e_table_header_add_column (e_table_header, col_0, 0); + + col_1 = e_table_col_new ("Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); + e_table_header_add_column (e_table_header, col_1, 1); + + /* + * 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); + + 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", 0, + "y", 30, + "drawgrid", TRUE, + "drawfocus", TRUE, + "spreadsheet", TRUE, + NULL); + +} + + + + + diff --git a/widgets/test-table.c b/widgets/test-table.c new file mode 100644 index 0000000000..56cdd0f208 --- /dev/null +++ b/widgets/test-table.c @@ -0,0 +1,240 @@ +/* + * Test code for the ETable package + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include <config.h> +#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 () +{ + 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"); + 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); +} + +void +table_browser_test (void) +{ + GtkWidget *canvas, *window; + ETableModel *e_table_model; + ETableHeader *e_table_header; + ECell *cell_left_just; + int i; + + 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); + + 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); +} + |