aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/test-cols.c
blob: c47a1d47d77c29142a503b0879ecf9f309143013 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* -*- 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-canvas-utils.h"
#include "e-util/e-canvas.h"
#include "e-util/e-cursors.h"
#include "e-util/e-util.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-cell-toggle.h"

#include "table-test.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 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
multi_cols_test (void)
{
    GtkWidget *canvas, *window;
    ETableModel *e_table_model;
    ETableHeader *e_table_header, *e_table_header_multiple;
    ETableCol *col_0, *col_1;
    ECell *cell_left_just, *cell_image_toggle;
    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);

    {
        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 (0, 3, images);

        for (i = 0; i < 3; i++)
            gdk_pixbuf_unref (images [i]);
        
        g_free (images);
    } 
                           
    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, 0);

    col_0 = e_table_col_new (0, "A", 0.0, 48, cell_image_toggle, g_int_compare, TRUE);
    e_table_header_add_column (e_table_header, col_0, 1);

    /*
     * Second test
     */
    e_table_header_multiple = e_table_header_new ();
    e_table_header_add_column (e_table_header_multiple, col_0, 0);
    e_table_header_add_column (e_table_header_multiple, col_1, 1);
    e_table_header_add_column (e_table_header_multiple, col_1, 2);
    
    /*
     * 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,
        "cursor_mode", E_TABLE_CURSOR_SIMPLE,
#if 0
        "spreadsheet", TRUE,
#endif
        NULL);

    e_canvas_item_move_absolute (item, 0, 30);
    
    gnome_canvas_item_new (
        gnome_canvas_root (GNOME_CANVAS (canvas)),
        e_table_header_item_get_type (),
        "ETableHeader", e_table_header_multiple,
        NULL);
    item = gnome_canvas_item_new (
        gnome_canvas_root (GNOME_CANVAS (canvas)),
        e_table_item_get_type (),
        "ETableHeader", e_table_header_multiple,
        "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, 300, 30);
}





39e226de447ed11f8b7d0b'>Use the new libviet port in building.obrien2001-02-123-16/+15 * Use the new libviet port in building.obrien2001-02-113-14/+17 * Update vnterm so it is based on the X11R6.5.1 Xterm rather than the X11R5 one.obrien2001-02-1123-191/+1411 * Fix prefix bogon.obrien2001-02-111-0/+1 * These X fonts allow you to display Vietnamese characters in an Xterm andobrien2001-02-118-0/+134 * VIQR<->VISCII conversion and VISCII ctype-like routinesobrien2001-02-106-0/+49 * teTeX Vietnamese language + font supportobrien2001-02-078-0/+475 * Style fixes in ports/vietnamese.olgeni2001-02-061-1/+1 * Converts Vietnamese text files between popular formats.obrien2001-01-066-0/+40 * Add $FreeBSD$, which help me in problem reports.obrien2000-11-221-0/+1 * Fix curses clear() usage.obrien2000-11-033-0/+54 * Change PKGDIR from pkg/ to . Also fix places where ${PKGDIR} isasami2000-10-081-1/+1 * Add dependency to mkfontdir:XFree86-4-clients when XFREE86_VERSION=4.asami2000-09-121-1/+8 * Back out the previous commit. That one has a problem which occurs onknu2000-08-281-5/+1 * PKGNAMEPREFIX cleanup. This should allow chained PKGNAMEPREFIX'es.knu2000-08-271-1/+5 * Add one manpage, one doc file and delete two directories.asami2000-07-052-0/+4 * List two files in share/doc/vnlpr and delete the directory upon deinstall.asami2000-07-051-2/+3 * Update the manpage to note this now adhears to Vietnamese Standard Code forobrien2000-05-214-7/+58 * Correct whitespace introduced during PORTNAME conversion and portlintmharo2000-04-216-6/+6 * Remove "vi-" prefix from PORTNAMEs, they are set by PKGNAMEPREFIX inasami2000-04-157-12/+12 * Set PKGNAMEPREFIX with ?= so it can be overridden.asami2000-04-111-1/+1 * Add PKGNAMEPREFIX definitions for language-specific dirs.asami2000-04-111-0/+4 * Update with the new PORTNAME/PORTVERSION variablescpiazza2000-04-107-21/+20 * Restore useless version required comments.obrien2000-03-227-0/+7 * Remove the "version required" line.obrien2000-03-207-7/+0 * Style nits in the ports I maintain.obrien2000-02-13