Switch from GPLv2 to GPLv2+
[fw/altos] / ao-tools / ao-view / aoview_table.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include "aoview.h"
20
21 #define NCOL    3
22
23 static GtkTreeView      *dataview[NCOL];
24 static GtkListStore     *datalist[NCOL];
25
26 void
27 aoview_table_start(void)
28 {
29         int col;
30         for (col = 0; col < NCOL; col++)
31                 datalist[col] = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
32 }
33
34 void
35 aoview_table_add_row(int col, char *label, char *format, ...)
36 {
37         char            buf[1024];
38         va_list         ap;
39         GtkTreeIter     iter;
40
41         va_start(ap, format);
42         vsnprintf(buf, sizeof (buf), format, ap);
43         va_end(ap);
44         gtk_list_store_append(datalist[col], &iter);
45         gtk_list_store_set(datalist[col], &iter,
46                            0, label,
47                            1, buf,
48                            -1);
49 }
50
51 void
52 aoview_table_finish(void)
53 {
54         int     col;
55         for (col = 0; col < NCOL; col++) {
56                 gtk_tree_view_set_model(dataview[col], GTK_TREE_MODEL(datalist[col]));
57                 g_object_unref(G_OBJECT(datalist[col]));
58                 gtk_tree_view_columns_autosize(dataview[col]);
59         }
60 }
61
62 void
63 aoview_table_clear(void)
64 {
65         int     col;
66         for (col = 0; col < NCOL; col++)
67                 gtk_tree_view_set_model(dataview[col], NULL);
68 }
69
70 void
71 aoview_table_init(GladeXML *xml)
72 {
73         int     col;
74
75         for (col = 0; col < NCOL; col++) {
76                 char    name[32];
77                 sprintf(name, "dataview_%d", col);
78                 dataview[col] = GTK_TREE_VIEW(glade_xml_get_widget(xml, name));
79                 assert(dataview[col]);
80
81                 aoview_add_plain_text_column(dataview[col], "Field", 0, 20);
82                 aoview_add_plain_text_column(dataview[col], "Value", 1, 32);
83         }
84 }