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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
/*
* e-table-column.c: TableColumn implementation
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*
* (C) 1999 Ximian, Inc
*/
#include <config.h>
#include "e-table-column.h"
enum {
STRUCTURE_CHANGE,
DIMENSION_CHANGE,
LAST_SIGNAL
};
static guint etc_signals [LAST_SIGNAL] = { 0, };
static GtkObjectClass *e_table_column_parent_class;
static void
e_table_column_destroy (GtkObject *object)
{
ETableColumn *etc = E_TABLE_COLUMN (object);
const int cols = etc->col_count;
/*
* Destroy listeners
*/
for (l = etc->listeners; l; l = l->next)
g_free (l->data);
g_slist_free (etc->listeners);
etc->listeners = NULL;
/*
* Destroy columns
*/
for (i = 0; i < cols; i++)
e_table_column_remove (etc, i);
if (e_table_column_parent_class->destroy)
e_table_column_parent_class->destroy (object);
}
static void
e_table_column_class_init (GtkObjectClass *object_class)
{
object_class->destroy = e_table_column_destroy;
e_table_column_parent_class = (gtk_type_class (gtk_object_get_type ()));
etc_signals [STRUCTURE_CHANGE] =
gtk_signal_new ("structure_change",
GTK_RUN_LAST,
E_OBJECT_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (ETableColumn, structure_change),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
etc_signals [DIMENSION_CHANGE] =
gtk_signal_new ("dimension_change",
GTK_RUN_LAST,
E_OBJECT_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (ETableColumn, dimension_change),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
E_OBJECT_CLASS_ADD_SIGNALS (object_class, etc_signals, LAST_SIGNAL);
}
GtkType
e_table_column_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"ETableColumn",
sizeof (ETableColumn),
sizeof (ETableColumnClass),
(GtkClassInitFunc) e_table_column_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gtk_object_get_type (), &info);
}
return type;
}
static void
etc_do_insert (ETableColumn *etc, int pos, ETableCol *val)
{
memcpy (&etc->columns [pos+1], &etc->columns [pos],
sizeof (ETableCol *) * (etc->col_count - pos));
etc->columns [pos] = val;
}
void
e_table_column_add_column (ETableColumn *etc, ETableCol *tc, int pos)
{
ETableCol **new_ptr;
g_return_if_fail (etc != NULL);
g_return_if_fail (E_IS_TABLE_COLUMN (etc));
g_return_if_fail (tc != NULL);
g_return_if_fail (pos >= 0 && pos < etc->col_count);
if (pos == -1)
pos = etc->col_count;
etc->columns = g_realloc (etc->columns, sizeof (ETableCol *) * (etc->col_count + 1));
etc_do_insert (etc, pos, tc);
etc->col_count++;
gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]);
}
ETableCol *
e_table_column_get_column (ETableColumn *etc, int column)
{
g_return_val_if_fail (etc != NULL, NULL);
g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), NULL);
if (column < 0)
return NULL;
if (column >= etc->col_count)
return NULL;
return etc->columns [column];
}
int
e_table_column_count (ETableColumn *etc)
{
g_return_val_if_fail (etc != NULL, 0);
g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0);
return etc->col_count;
}
int
e_table_column_index (ETableColumn *etc, const char *identifier)
{
int i;
g_return_val_if_fail (etc != NULL, 0);
g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0);
g_return_val_if_fail (identifier != NULL, 0);
for (i = 0; i < etc->col_count; i++){
ETableCol *tc = etc->columns [i];
if (strcmp (i->id, identifier) == 0)
return i;
}
return -1;
}
int
e_table_column_get_index_at (ETableColumn *etc, int x_offset)
{
int i, total;
g_return_val_if_fail (etc != NULL, 0);
g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0);
g_return_val_if_fail (identifier != NULL, 0);
total = 0;
for (i = 0; i < etc->col_count; i++){
total += etc->columns [i]->width;
if (x_offset < total)
return i;
}
return -1;
}
ETableCol **
e_table_column_get_columns (ETableColumn *etc)
{
ETableCol **ret;
int i;
g_return_val_if_fail (etc != NULL, 0);
g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0);
ret = g_new (ETableCol *, etc->col_count + 1);
memcpy (ret, etc->columns, sizeof (ETableCol *) * etc->col_count);
ret [etc->col_count] = NULL;
return ret;
}
gboolean
e_table_column_selection_ok (ETableColumn *etc)
{
g_return_val_if_fail (etc != NULL, FALSE);
g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), FALSE);
return etc->selectable;
}
int
ve_table_column_get_selected (ETableColumn *etc)
{
int i;
int selected = 0;
g_return_val_if_fail (etc != NULL, 0);
g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0);
for (i = 0; i < etc->col_count; i++){
if (etc->columns [i]->selected)
selected++;
}
return selected;
}
int
e_table_column_total_width (ETableColumn *etc)
{
int total;
g_return_val_if_fail (etc != NULL, 0);
g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0);
total = 0;
for (i = 0; i < etc->col_count; i++)
total += etc->columns [i].width;
return total;
}
static void
etc_do_remove (ETableColumn *etc, int idx)
{
memcpy (&etc->columns [idx], &etc->columns [idx+1],
sizeof (ETableCol *) * etc->col_count - idx);
etc->col_count--;
}
void
e_table_column_move (ETableColumn *etc, int source_index, int target_index)
{
g_return_if_fail (etc != NULL);
g_return_if_fail (E_IS_TABLE_COLUMN (etc));
g_return_if_fail (source_index >= 0);
g_return_if_fail (target_index >= 0);
g_return_if_fail (source_index < etc->col_count);
g_return_if_fail (target_index < etc->col_count);
old = etc->columns [source_index];
etc_do_remove (etc, source_index);
etc_do_insert (etc, target_index, old);
gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]);
}
void
e_table_column_remove (ETableColumn *etc, int idx)
{
g_return_if_fail (etc != NULL);
g_return_if_fail (E_IS_TABLE_COLUMN (etc));
g_return_if_fail (idx >= 0);
g_return_if_fail (idx < etc->col_count);
etc_do_remove (etc, idx);
gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]);
}
void
e_table_column_set_selection (ETableColumn *etc, gboolean allow_selection);
{
}
void
e_table_column_set_size (ETableColumn *etc, int idx, int size)
{
g_return_if_fail (etc != NULL);
g_return_if_fail (E_IS_TABLE_COLUMN (etc));
g_return_if_fail (idx >= 0);
g_return_if_fail (idx < etc->col_count);
g_return_if_fail (size > 0);
etc->columns [idx]->width = size;
gtk_signal_emit (GTK_OBJECT (etc), etc_signals [SIZE_CHANGE], idx);
}
|