aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/test-check.c
blob: b24a7aff644c863596b743bae4d3d8707b96295a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * 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"

#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
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;

    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, 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 ();
    col_0 = e_table_col_new (0, "", 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 (1, "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",  (double) 0,
        "y",  (double) 30,
        "drawgrid", TRUE,
        "drawfocus", TRUE,
        "spreadsheet", TRUE,
        NULL);
    
}