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
|
/*
* e-table-model.c: a Table Model
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*
* (C) 1999 Helix Code, Inc.
*/
#include <config.h>
#include <gtk/gtksignal.h>
#include "e-table-model.h"
#define ETM_CLASS(e) ((ETableModelClass *)((GtkObject *)e)->klass)
static GtkObjectClass *e_table_model_parent_class;
enum {
MODEL_CHANGED,
ROW_SELECTION,
LAST_SIGNAL
};
static guint etm_signals [LAST_SIGNAL] = { 0, };
int
e_table_model_column_count (ETableModel *etable)
{
return ETM_CLASS (etable)->column_count (etable);
}
const char *
e_table_model_column_name (ETableModel *etable, int col)
{
return ETM_CLASS (etable)->column_name (etable, col);
}
int
e_table_model_row_count (ETableModel *etable)
{
return ETM_CLASS (etable)->row_count (etable);
}
void *
e_table_model_value_at (ETableModel *etable, int col, int row)
{
return ETM_CLASS (etable)->value_at (etable, col, row);
}
void
e_table_model_set_value_at (ETableModel *etable, int col, int row, void *data)
{
return ETM_CLASS (etable)->set_value_at (etable, col, row, data);
}
gboolean
e_table_model_is_cell_editable (ETableModel *etable, int col, int row)
{
return ETM_CLASS (etable)->is_cell_editable (etable, col, row);
}
int
e_table_model_row_height (ETableModel *etable, int row)
{
return ETM_CLASS (etable)->row_height (etable, row);
}
static void
e_table_model_destroy (GtkObject *object)
{
GSList *l;
ETableModel *etable = (ETableModel *) object;
if (e_table_model_parent_class->destroy)
(*e_table_model_parent_class->destroy)(object);
}
static void
e_table_model_class_init (GtkObjectClass *object_class)
{
e_table_model_parent_class = gtk_type_class (gtk_object_get_type ());
object_class->destroy = e_table_model_destroy;
etm_signals [MODEL_CHANGED] =
gtk_signal_new ("model_changed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableModelClass, model_changed),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
etm_signals [ROW_SELECTION] =
gtk_signal_new ("row_selection",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableModelClass, row_selection),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT);
gtk_object_class_add_signals (object_class, etm_signals, LAST_SIGNAL);
}
GtkType
e_table_model_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"ETableModel",
sizeof (ETableModel),
sizeof (ETableModelClass),
(GtkClassInitFunc) e_table_model_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gtk_object_get_type (), &info);
}
return type;
}
int
e_table_model_height (ETableModel *etable)
{
int rows, size, i;
g_return_val_if_fail (etable != NULL, 0);
rows = e_table_model_row_count (etable);
size = 0;
for (i = 0; i < rows; i++)
size += e_table_model_row_height (etable, i) + 1;
return size;
}
void
e_table_model_changed (ETableModel *e_table_model)
{
gtk_signal_emit (GTK_OBJECT (e_table_model),
etm_signals [MODEL_CHANGED]);
}
#if 0
int
e_table_model_max_col_width (ETableModel *etm, int col)
{
const int nvals = e_table_model_row_count (etm);
int max = 0;
int row;
for (row = 0; row < nvals; row++){
int w;
w = e_table_model_cell_width (etm, col, i);
if (w > max)
max = w;
}
return max;
}
#endif
void
e_table_model_select_row (ETableModel *etm, int row)
{
gtk_signal_emit (GTK_OBJECT (etm), etm_signals [ROW_SELECTION], row, 1);
etm->row_selected = row;
}
void
e_table_model_unselect_row (ETableModel *etm, int row)
{
if (etm->row_selected != -1){
gtk_signal_emit (
GTK_OBJECT (etm), etm_signals [ROW_SELECTION],
etm->row_selected, 0);
}
etm->row_selected = -1;
}
gint
e_table_model_get_selected_row (ETableModel *etm)
{
return etm->row_selected;
}
|