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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* E-table-scrolled.c: A graphical view of a Table.
*
* Author:
* Chris Lahey <clahey@helixcode.com>
* Miguel de Icaza (miguel@helixcode.com)
*
* Copyright 2000, 1999, Helix Code, Inc
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <libgnomeui/gnome-canvas.h>
#include <gtk/gtksignal.h>
#include <gnome-xml/parser.h>
#include <gnome-xml/xmlmemory.h>
#include "e-table.h"
#include "e-table-scrolled.h"
#define COLUMN_HEADER_HEIGHT 16
#define PARENT_TYPE e_scroll_frame_get_type ()
static GtkObjectClass *parent_class;
enum {
CURSOR_CHANGE,
DOUBLE_CLICK,
RIGHT_CLICK,
KEY_PRESS,
LAST_SIGNAL
};
enum {
ARG_0,
ARG_TABLE_DRAW_GRID,
ARG_TABLE_DRAW_FOCUS,
ARG_CURSOR_MODE,
ARG_LENGTH_THRESHOLD,
ARG_CLICK_TO_ADD_MESSAGE,
};
static gint ets_signals [LAST_SIGNAL] = { 0, };
static void
cursor_change_proxy (ETable *et, int row, ETableScrolled *ets)
{
gtk_signal_emit (GTK_OBJECT (ets),
ets_signals [CURSOR_CHANGE],
row);
}
static void
double_click_proxy (ETable *et, int row, ETableScrolled *ets)
{
gtk_signal_emit (GTK_OBJECT (ets),
ets_signals [DOUBLE_CLICK],
row);
}
static gint
right_click_proxy (ETable *et, int row, int col, GdkEvent *event, ETableScrolled *ets)
{
int return_val = 0;
gtk_signal_emit (GTK_OBJECT (ets),
ets_signals [RIGHT_CLICK],
row, col, event, &return_val);
return return_val;
}
static gint
key_press_proxy (ETable *et, int row, int col, GdkEvent *event, ETableScrolled *ets)
{
int return_val;
gtk_signal_emit (GTK_OBJECT (ets),
ets_signals [KEY_PRESS],
row, col, event, &return_val);
return return_val;
}
static void
e_table_scrolled_init (GtkObject *object)
{
ETableScrolled *ets;
EScrollFrame *scroll_frame;
ets = E_TABLE_SCROLLED (object);
scroll_frame = E_SCROLL_FRAME (object);
ets->table = gtk_type_new(e_table_get_type());
e_scroll_frame_set_policy (scroll_frame, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
e_scroll_frame_set_shadow_type (scroll_frame, GTK_SHADOW_IN);
}
static void
e_table_scrolled_real_construct (ETableScrolled *ets)
{
gtk_object_set(GTK_OBJECT(ets),
"shadow_type", GTK_SHADOW_IN,
"hscrollbar_policy", GTK_POLICY_NEVER,
"vscrollbar_policy", GTK_POLICY_AUTOMATIC,
NULL);
gtk_container_add(GTK_CONTAINER(ets), GTK_WIDGET(ets->table));
gtk_signal_connect(GTK_OBJECT(ets->table), "cursor_change",
GTK_SIGNAL_FUNC(cursor_change_proxy), ets);
gtk_signal_connect(GTK_OBJECT(ets->table), "double_click",
GTK_SIGNAL_FUNC(double_click_proxy), ets);
gtk_signal_connect(GTK_OBJECT(ets->table), "right_click",
GTK_SIGNAL_FUNC(right_click_proxy), ets);
gtk_signal_connect(GTK_OBJECT(ets->table), "key_press",
GTK_SIGNAL_FUNC(key_press_proxy), ets);
gtk_widget_show(GTK_WIDGET(ets->table));
}
ETableScrolled *
e_table_scrolled_construct (ETableScrolled *ets, ETableHeader *full_header,
ETableModel *etm, const char *spec)
{
g_return_val_if_fail(ets != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL);
g_return_val_if_fail(full_header != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_HEADER(full_header), NULL);
g_return_val_if_fail(etm != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL);
g_return_val_if_fail(spec != NULL, NULL);
e_table_construct(ets->table, full_header, etm, spec);
e_table_scrolled_real_construct(ets);
return ets;
}
ETableScrolled *
e_table_scrolled_construct_from_spec_file (ETableScrolled *ets, ETableHeader *full_header, ETableModel *etm,
const char *filename)
{
g_return_val_if_fail(ets != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL);
g_return_val_if_fail(full_header != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_HEADER(full_header), NULL);
g_return_val_if_fail(etm != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL);
g_return_val_if_fail(filename != NULL, NULL);
e_table_construct_from_spec_file(ets->table, full_header, etm, filename);
e_table_scrolled_real_construct(ets);
return ets;
}
GtkWidget *
e_table_scrolled_new (ETableHeader *full_header, ETableModel *etm, const char *spec)
{
ETableScrolled *ets;
g_return_val_if_fail(full_header != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_HEADER(full_header), NULL);
g_return_val_if_fail(etm != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL);
g_return_val_if_fail(spec != NULL, NULL);
ets = E_TABLE_SCROLLED (gtk_widget_new (e_table_scrolled_get_type (),
"hadjustment", NULL,
"vadjustment", NULL,
NULL));
ets = e_table_scrolled_construct (ets, full_header, etm, spec);
return GTK_WIDGET (ets);
}
GtkWidget *
e_table_scrolled_new_from_spec_file (ETableHeader *full_header, ETableModel *etm, const char *filename)
{
ETableScrolled *ets;
g_return_val_if_fail(full_header != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_HEADER(full_header), NULL);
g_return_val_if_fail(etm != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL);
g_return_val_if_fail(filename != NULL, NULL);
ets = gtk_type_new (e_table_scrolled_get_type ());
ets = e_table_scrolled_construct_from_spec_file (ets, full_header, etm, filename);
return GTK_WIDGET (ets);
}
gchar *
e_table_scrolled_get_specification (ETableScrolled *ets)
{
g_return_val_if_fail(ets != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL);
return e_table_get_specification(ets->table);
}
void
e_table_scrolled_save_specification (ETableScrolled *ets, gchar *filename)
{
g_return_if_fail(ets != NULL);
g_return_if_fail(E_IS_TABLE_SCROLLED(ets));
g_return_if_fail(filename != NULL);
e_table_save_specification(ets->table, filename);
}
void
e_table_scrolled_set_cursor_row (ETableScrolled *ets, int row)
{
g_return_if_fail(ets != NULL);
g_return_if_fail(E_IS_TABLE_SCROLLED(ets));
e_table_set_cursor_row(ets->table, row);
}
int
e_table_scrolled_get_cursor_row (ETableScrolled *ets)
{
g_return_val_if_fail(ets != NULL, -1);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), -1);
return e_table_get_cursor_row(ets->table);
}
void
e_table_scrolled_selected_row_foreach (ETableScrolled *ets,
ETableForeachFunc callback,
gpointer closure)
{
g_return_if_fail(ets != NULL);
g_return_if_fail(E_IS_TABLE_SCROLLED(ets));
e_table_selected_row_foreach(ets->table,
callback,
closure);
}
EPrintable *
e_table_scrolled_get_printable (ETableScrolled *ets)
{
g_return_val_if_fail(ets != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL);
return e_table_get_printable(ets->table);
}
static void
ets_get_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
ETableScrolled *ets = E_TABLE_SCROLLED (o);
gboolean bool_val;
gchar *string_val;
switch (arg_id){
case ARG_TABLE_DRAW_GRID:
gtk_object_get(GTK_OBJECT(ets->table),
"drawgrid", &bool_val,
NULL);
GTK_VALUE_BOOL (*arg) = bool_val;
break;
case ARG_TABLE_DRAW_FOCUS:
gtk_object_get(GTK_OBJECT(ets->table),
"drawfocus", &bool_val,
NULL);
GTK_VALUE_BOOL (*arg) = bool_val;
break;
case ARG_CLICK_TO_ADD_MESSAGE:
gtk_object_get(GTK_OBJECT(ets->table),
"click_to_add_message", &string_val,
NULL);
GTK_VALUE_STRING (*arg) = string_val;
break;
}
}
static void
ets_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
ETableScrolled *ets = E_TABLE_SCROLLED (o);
switch (arg_id){
case ARG_LENGTH_THRESHOLD:
gtk_object_set(GTK_OBJECT(ets->table),
"length_threshold", GTK_VALUE_INT (*arg),
NULL);
break;
case ARG_TABLE_DRAW_GRID:
gtk_object_set(GTK_OBJECT(ets->table),
"drawgrid", GTK_VALUE_BOOL (*arg),
NULL);
break;
case ARG_TABLE_DRAW_FOCUS:
gtk_object_set(GTK_OBJECT(ets->table),
"drawfocus", GTK_VALUE_BOOL (*arg),
NULL);
break;
case ARG_CURSOR_MODE:
gtk_object_set(GTK_OBJECT(ets->table),
"cursor_mode", GTK_VALUE_INT (*arg),
NULL);
break;
case ARG_CLICK_TO_ADD_MESSAGE:
gtk_object_set(GTK_OBJECT(ets->table),
"click_to_add_message", GTK_VALUE_STRING (*arg),
NULL);
break;
}
}
static void
e_table_scrolled_class_init (GtkObjectClass *object_class)
{
ETableScrolledClass *klass = E_TABLE_SCROLLED_CLASS(object_class);
parent_class = gtk_type_class (PARENT_TYPE);
object_class->set_arg = ets_set_arg;
object_class->get_arg = ets_get_arg;
klass->cursor_change = NULL;
klass->double_click = NULL;
klass->right_click = NULL;
klass->key_press = NULL;
ets_signals [CURSOR_CHANGE] =
gtk_signal_new ("cursor_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableScrolledClass, cursor_change),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
ets_signals [DOUBLE_CLICK] =
gtk_signal_new ("double_click",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableScrolledClass, double_click),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
ets_signals [RIGHT_CLICK] =
gtk_signal_new ("right_click",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableScrolledClass, right_click),
e_marshal_INT__INT_INT_POINTER,
GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER);
ets_signals [KEY_PRESS] =
gtk_signal_new ("key_press",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableScrolledClass, key_press),
e_marshal_INT__INT_INT_POINTER,
GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER);
gtk_object_class_add_signals (object_class, ets_signals, LAST_SIGNAL);
gtk_object_add_arg_type ("ETableScrolled::drawgrid", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_TABLE_DRAW_GRID);
gtk_object_add_arg_type ("ETableScrolled::drawfocus", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_TABLE_DRAW_FOCUS);
gtk_object_add_arg_type ("ETableScrolled::cursor_mode", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_CURSOR_MODE);
gtk_object_add_arg_type ("ETableScrolled::length_threshold", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD);
gtk_object_add_arg_type ("ETableScrolled::click_to_add_message", GTK_TYPE_STRING,
GTK_ARG_READWRITE, ARG_CLICK_TO_ADD_MESSAGE);
}
E_MAKE_TYPE(e_table_scrolled, "ETableScrolled", ETableScrolled, e_table_scrolled_class_init, e_table_scrolled_init, PARENT_TYPE);
|