2000-02-24 Christopher James Lahey <clahey@helixcode.com> * widgets/e-text.c, widgets/e-text.h, e-text-event-processor.c, e-text-event-processor.h, e-text-event-processor-emacs-like.c, e-text-event-processor-emacs-like.h, e-text-event-processor-types.h: This were moved to widgets/e-text/ a while ago but never removed. They have now been removed. * widgets/e-text/e-text.c, widgets/e-text/e-text.h: Removed some warnings from this file. Made tooltips disappear when you're finished with them. * widgets/e-minicard/test-reflow.c, widgets/e-minicard/test-minicard.c, widgets/e-minicard/test-minicard-label.c: Commented out unused about_callback functions. * widgets/e-minicard/e-reflow.c: Made e-reflow pass an EFocus to its e-minicard children. * widgets/e-minicard/e-minicard.c: Made e-minicard take and return an EFocus for its "has_focus" argument. This makes shift-tab work properly. * widgets/e-minicard/e-minicard-label.c: Made e-minicard-label take and return an EFocus for its "has_focus" argument. Made the font that e-minicard-label uses only be allocated once. * e-util/e-canvas-utils.h: Fixed the comment at the top and added #ifndef __E_CANVAS_UTILS__. * e-util/Makefile.am: Added e-xml-utils.c and e-xml-utils.h. * e-util/e-xml-utils.h, e-util/e-xml-utils.c: Added files for some xml utilities. * e-util/e-util.h: Added type EFocus which describes which direction the focus will be coming from. in mail: 2000-02-24 Christopher James Lahey <clahey@helixcode.com> * message-list.c: Changed this to not use the "x" and "y" arguments to e-table-item. in widgets/e-table: 2000-02-24 Christopher James Lahey <clahey@helixcode.com> * e-table-subset-variable.c, e-table-subset-variable.h: A new model which is a subset, but you can add and remove rows. * test-table.c: Added a thaw method for use with the e-table-subset (emits model_changed.) Adapted to the changes to e_table_item. Properly parse headers. Adapted to the changes to e_table, including creating example xml spec data. * test-cols.c, test-check.c: Added a thaw method for use with the e-table-subset (emits model_changed.) Adapted to the changes to e_table_item. * e-table.c, e-table.h: Reworked e-table to use the ETable grouping system. The only difference for the interface is that instead of passing in a column_spec and a grouping_spec, you pass in a single string that is an xml format that includes both pieces of information. * e-table-subset.h: Added rules for emacs to do correct indentation. * e-table-subset.c: Implemented freezing. No signals are emitted while frozen and "model_changed" is emitted when thawed. * e-table-sorted.h: ETableSortedClass has ETableSubset as its parent object instead of ETableSubsetClass. Fixed this. * e-table-simple.c, e-table-simple.h: Implemented the thaw method. Use of simple now requires an extra argument (the thaw method.) * e-table-model.h, e-table-model.c: Added e_table_model_freeze and e_table_model_thaw. * e-table-item.h, e-table-item.c: Reworked this a bit to make it provide some things the new group system needed and to make inter-item keyboard focus work. Changed the external interface only in the list of arguments it recognizes and signals it emits. Instead of "x" and "y", you have to use e_canvas_item_move_absolute and instead of emitting a "height_changed" signal, it emits a "resize" signal. There's new "has_focus", "width", and "height" arguments and a function to get the currently focused column. * e-table-header-item.c: Got rid of some warnings here. Changed the * e-table-group-leaf.h, e-table-group-leaf.c, e-table-group-container.h, e-table-group-container.c: New types to make e_table_group work properly. * e-table-group.h, e-table-group.c: Completely reworked e-table grouping. e-table-group now uses a hierarchical structure. * e-cell.h: Added e_cell_print. This doesn't work yet. * e-cell.c: Made e_cell_realize exist. (It was improperly named e_cell_view_realize in the .c.) * e-cell-text.c: Made the blinking cursor disappear properly. * check-filled.xpm, check-empty.xpm: Made these const char *[] instead of char *[] to avoid compiler warnings. * Makefile.am: Added e-table-group-container.c, e-table-group-container.h, e-table-group-leaf.c, e-table-group-leaf.h, e-table-subset-variable.c, e-table-subset-variable.h. svn path=/trunk/; revision=1915
315 lines
6.9 KiB
C
315 lines
6.9 KiB
C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
/*
|
|
* 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-util/e-cursors.h"
|
|
#include "e-table-simple.h"
|
|
#include "e-table-header.h"
|
|
#include "e-table-header-item.h"
|
|
#include "e-table-item.h"
|
|
#include "e-cell-text.h"
|
|
#include "e-table.h"
|
|
|
|
#include "table-test.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);
|
|
if ( strchr(column_labels [i], '\n') )
|
|
*strchr(column_labels [i], '\n') = 0;
|
|
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;
|
|
|
|
{
|
|
static int loaded;
|
|
|
|
if (loaded)
|
|
return;
|
|
|
|
loaded = TRUE;
|
|
}
|
|
|
|
|
|
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 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
|
|
thaw (ETableModel *etc, void *data)
|
|
{
|
|
e_table_model_changed(etc);
|
|
}
|
|
|
|
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;
|
|
GnomeCanvasItem *group;
|
|
int i;
|
|
|
|
load_data ();
|
|
|
|
/*
|
|
* Data model
|
|
*/
|
|
e_table_model = e_table_simple_new (
|
|
col_count, row_count, value_at,
|
|
set_value_at, is_cell_editable, thaw, NULL);
|
|
|
|
/*
|
|
* Header
|
|
*/
|
|
e_table_header = e_table_header_new ();
|
|
cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT, TRUE);
|
|
|
|
for (i = 0; i < cols; i++){
|
|
ETableCol *ecol = e_table_col_new (
|
|
i, 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);
|
|
|
|
group = gnome_canvas_item_new (
|
|
gnome_canvas_root (GNOME_CANVAS (canvas)),
|
|
gnome_canvas_group_get_type (),
|
|
"x", 30.0,
|
|
"y", 30.0,
|
|
NULL);
|
|
|
|
gnome_canvas_item_new (
|
|
GNOME_CANVAS_GROUP (group),
|
|
e_table_item_get_type (),
|
|
"ETableHeader", e_table_header,
|
|
"ETableModel", e_table_model,
|
|
"drawgrid", TRUE,
|
|
"drawfocus", TRUE,
|
|
"spreadsheet", TRUE,
|
|
NULL);
|
|
}
|
|
|
|
static void
|
|
do_e_table_demo (const char *spec)
|
|
{
|
|
GtkWidget *e_table, *window, *frame;
|
|
ETableModel *e_table_model;
|
|
ECell *cell_left_just;
|
|
ETableHeader *full_header;
|
|
int i;
|
|
|
|
/*
|
|
* Data model
|
|
*/
|
|
e_table_model = e_table_simple_new (
|
|
col_count, row_count, value_at,
|
|
set_value_at, is_cell_editable, thaw, NULL);
|
|
|
|
full_header = e_table_header_new ();
|
|
cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT, TRUE);
|
|
|
|
for (i = 0; i < cols; i++){
|
|
ETableCol *ecol = e_table_col_new (
|
|
i, column_labels [i],
|
|
80, 20, cell_left_just,
|
|
g_str_equal, TRUE);
|
|
|
|
e_table_header_add_column (full_header, ecol, i);
|
|
}
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
frame = gtk_frame_new (NULL);
|
|
e_table = e_table_new (full_header, e_table_model, spec);
|
|
gtk_container_add (GTK_CONTAINER (frame), e_table);
|
|
gtk_container_add (GTK_CONTAINER (window), frame);
|
|
|
|
gtk_widget_set_usize (window, 200, 200);
|
|
gtk_widget_show (e_table);
|
|
gtk_widget_show (frame);
|
|
gtk_widget_show (window);
|
|
}
|
|
|
|
void
|
|
e_table_test (void)
|
|
{
|
|
load_data ();
|
|
|
|
if (1){/*getenv ("DO")){*/
|
|
do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <leaf/> </grouping> </ETableSpecification>");
|
|
do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 0 </column> <column> 0 </column> <column> 0 </column> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"3\"> <group column=\"4\"> <leaf/> </group> </group> </grouping> </ETableSpecification>");
|
|
}
|
|
do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"4\"> <leaf/> </group> </grouping> </ETableSpecification>");
|
|
do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"3\"> <leaf/> </group> </grouping> </ETableSpecification>");
|
|
}
|