Files
evolution/widgets/table/test-check.c
Christopher James Lahey c3e3a85f28 Changed the license announcement at the top of these files.
2001-10-26  Christopher James Lahey  <clahey@ximian.com>

	* e-cell-checkbox.c, e-cell-checkbox.h, e-cell-combo.c,
	e-cell-combo.h, e-cell-date.c, e-cell-date.h, e-cell-number.c,
	e-cell-number.h, e-cell-pixbuf.c, e-cell-pixbuf.h, e-cell-popup.c,
	e-cell-popup.h, e-cell-size.c, e-cell-size.h,
	e-cell-spin-button.c, e-cell-spin-button.h, e-cell-string.c,
	e-cell-text.c, e-cell-text.h, e-cell-toggle.c, e-cell-toggle.h,
	e-cell-tree.c, e-cell-tree.h, e-cell.c, e-cell.h,
	e-table-click-to-add.c, e-table-click-to-add.h, e-table-col-dnd.h,
	e-table-col.c, e-table-col.h, e-table-column-specification.c,
	e-table-column-specification.h, e-table-column.c,
	e-table-config-field.c, e-table-config-field.h, e-table-config.c,
	e-table-config.h, e-table-defines.h, e-table-example-1.c,
	e-table-example-2.c, e-table-extras.c, e-table-extras.h,
	e-table-field-chooser-dialog.c, e-table-field-chooser-dialog.h,
	e-table-field-chooser-item.c, e-table-field-chooser-item.h,
	e-table-field-chooser.c, e-table-field-chooser.h,
	e-table-group-container.c, e-table-group-container.h,
	e-table-group-leaf.c, e-table-group-leaf.h, e-table-group.c,
	e-table-group.h, e-table-header-item.c, e-table-header-item.h,
	e-table-header-utils.c, e-table-header-utils.h, e-table-header.c,
	e-table-header.h, e-table-item.c, e-table-item.h,
	e-table-memory-callbacks.c, e-table-memory-callbacks.h,
	e-table-memory.c, e-table-memory.h, e-table-model.c,
	e-table-model.h, e-table-one.c, e-table-one.h, e-table-scrolled.c,
	e-table-scrolled.h, e-table-selection-model.c,
	e-table-selection-model.h, e-table-simple.c, e-table-simple.h,
	e-table-size-test.c, e-table-sort-info.c, e-table-sort-info.h,
	e-table-sorted-variable.c, e-table-sorted-variable.h,
	e-table-sorted.c, e-table-sorted.h, e-table-sorter.c,
	e-table-sorter.h, e-table-sorting-utils.c,
	e-table-sorting-utils.h, e-table-specification.c,
	e-table-specification.h, e-table-state.c, e-table-state.h,
	e-table-subset-variable.c, e-table-subset-variable.h,
	e-table-subset.c, e-table-subset.h, e-table-tooltip.h,
	e-table-tree.h, e-table-utils.c, e-table-utils.h,
	e-table-without.c, e-table-without.h, e-table.c, e-table.h,
	e-tree-memory-callbacks.c, e-tree-memory-callbacks.h,
	e-tree-memory.c, e-tree-memory.h, e-tree-model.c, e-tree-model.h,
	e-tree-scrolled.c, e-tree-scrolled.h, e-tree-selection-model.c,
	e-tree-selection-model.h, e-tree-simple.c, e-tree-simple.h,
	e-tree-sorted-variable.c, e-tree-sorted-variable.h,
	e-tree-sorted.c, e-tree-sorted.h, e-tree-table-adapter.c,
	e-tree-table-adapter.h, e-tree.c, e-tree.h, table-test.c,
	table-test.h, test-check.c, test-cols.c, test-table.c: Changed the
	license announcement at the top of these files.

	* e-cell-string.c: Removed unused file.

svn path=/trunk/; revision=14154
2001-10-26 18:25:47 +00:00

223 lines
5.1 KiB
C

/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* test-check.c
* Copyright 2000, 2001, Ximian, Inc.
*
* Authors:
* Miguel de Icaza (miguel@gnu.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License, version 2, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#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 "gal/widgets/e-cursors.h"
#include "gal/widgets/e-canvas-utils.h"
#include "gal/widgets/e-canvas.h"
#include "gal/util/e-util.h"
#include "e-cell-text.h"
#include "e-cell-checkbox.h"
#include "table-test.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 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 *
duplicate_value (ETableModel *etc, int col, const void *value, void *data)
{
if (col == 0) {
return (void *) value;
} else {
return g_strdup (value);
}
}
static void
free_value (ETableModel *etc, int col, void *value, void *data)
{
if (col != 0) {
g_free (value);
}
}
static void *
initialize_value (ETableModel *etc, int col, void *data)
{
if (col == 0)
return NULL;
else
return g_strdup ("");
}
static gboolean
value_is_empty (ETableModel *etc, int col, const void *value, void *data)
{
if (col == 0)
return value == NULL;
else
return !(value && *(char *)value);
}
static char *
value_to_string (ETableModel *etc, int col, const void *value, void *data)
{
if (col == 0)
return g_strdup_printf("%d", (int) value);
else
return g_strdup(value);
}
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;
GdkPixbuf *pixbuf;
GnomeCanvasItem *item;
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, row_count, value_at,
set_value_at, is_cell_editable,
duplicate_value, free_value,
initialize_value, value_is_empty,
value_to_string,
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 ();
pixbuf = gdk_pixbuf_new_from_file ("clip.png");
col_0 = e_table_col_new_with_pixbuf (0, pixbuf, 0.0, 18, cell_image_check, g_int_compare, TRUE);
gdk_pixbuf_unref (pixbuf);
e_table_header_add_column (e_table_header, col_0, 0);
col_1 = e_table_col_new (1, "Item Name", 1.0, 20, cell_left_just, g_str_compare, TRUE);
e_table_header_add_column (e_table_header, col_1, 1);
e_table_col_set_arrow (col_1, E_TABLE_COL_ARROW_DOWN);
/*
* GUI
*/
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
canvas = e_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,
NULL);
item = gnome_canvas_item_new (
gnome_canvas_root (GNOME_CANVAS (canvas)),
e_table_item_get_type (),
"ETableHeader", e_table_header,
"ETableModel", e_table_model,
"drawgrid", TRUE,
"drawfocus", TRUE,
#if 0
"spreadsheet", TRUE,
#endif
"cursor_mode", E_TABLE_CURSOR_SIMPLE,
NULL);
e_canvas_item_move_absolute (item, 0, 30);
}