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
|
/*
* e-cell-checkbox.c: Checkbox cell renderer
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*
* (C) 1999 Helix Code, Inc
*/
#include <config.h>
#include <gtk/gtkenums.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtksignal.h>
#include <gdk/gdkkeysyms.h>
#include <libgnomeui/gnome-canvas.h>
#include "e-cell-checkbox.h"
#include "e-util.h"
#include "e-table-item.h"
#define PARENT_TYPE e_cell_get_type()
typedef struct {
ECellView cell_view;
GdkGC *gc;
GnomeCanvas *canvas;
ETableItem *eti;
} ECellCheckboxView;
static ECellClass *parent_class;
static void
eccb_queue_redraw (ECellCheckboxView *text_view, int col, int row)
{
e_table_item_redraw_range (text_view->eti, col, row, col, row);
}
/*
* ECell::realize method
*/
static ECellView *
eecb_realize (ECell *ecell, void *view)
{
ECellCheckbox *eccb = E_CELL_CHECKBOX (ecell);
ECellCheckboxView *check_view = g_new0 (ECellCheckboxView, 1);
ETableItem *eti = E_TABLE_ITEM (view);
GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas;
check_view->cell_view.ecell = ecell;
check_view->gc = gdk_gc_new (GTK_WIDGET (canvas)->window);
check_view->eti = eti;
check_view->canvas = canvas;
return (ECellView *) check_view;
}
/*
* ECell::unrealize method
*/
static void
eecb_unrealize (ECellView *ecv)
{
ECellCheckboxView *check_view = (ECellCheckboxView *) ecv;
gdk_gc_unref (check_view->gc);
text_view->gc = NULL;
g_free (check_view);
}
/*
* ECell::draw method
*/
static void
eecb_draw (ECellView *ecell_view, GdkDrawable *drawable,
int col, int row, gboolean selected,
int x1, int y1, int x2, int y2)
{
}
/*
* ECell::event method
*/
static gint
eecb_event (ECellView *ecell_view, GdkEvent *event, int col, int row)
{
ECellCheckboxView *text_view = (ECellCheckboxView *) ecell_view;
switch (event->type){
case GDK_BUTTON_PRESS:
/*
* Adjust for the border we use
*/
event->button.x++;
printf ("Button pressed at %g %g\n", event->button.x, event->button.y);
if (text_view->edit){
printf ("FIXME: Should handle click here\n");
} else
e_table_item_enter_edit (text_view->eti, col, row);
break;
case GDK_BUTTON_RELEASE:
/*
* Adjust for the border we use
*/
event->button.x++;
printf ("Button released at %g %g\n", event->button.x, event->button.y);
return TRUE;
case GDK_KEY_PRESS:
if (event->key.keyval == GDK_Escape){
eecb_cancel_edit (text_view);
return TRUE;
}
if (!text_view->edit){
e_table_item_enter_edit (text_view->eti, col, row);
eecb_edit_seleecb_all (text_view);
}
gtk_widget_event (GTK_WIDGET (text_view->edit->entry), event);
eecb_queue_redraw (text_view, col, row);
break;
case GDK_KEY_RELEASE:
break;
default:
return FALSE;
}
return TRUE;
}
/*
* ECell::height method
*/
static int
eecb_height (ECellView *ecell_view, int col, int row)
{
return 10;
}
/*
* ECellView::enter_edit method
*/
static void *
eecb_enter_edit (ECellView *ecell_view, int col, int row)
{
}
/*
* ECellView::leave_edit method
*/
static void
eecb_leave_edit (ECellView *ecell_view, int col, int row, void *edit_context)
{
}
static void
e_cell_checkbox_class_init (GtkObjectClass *object_class)
{
ECellClass *ecc = (ECellClass *) object_class;
ecc->realize = eecb_realize;
ecc->unrealize = eecb_unrealize;
ecc->draw = eecb_draw;
ecc->event = eecb_event;
ecc->height = eecb_height;
ecc->enter_edit = eecb_enter_edit;
ecc->leave_edit = eecb_leave_edit;
parent_class = gtk_type_class (PARENT_TYPE);
}
E_MAKE_TYPE(e_cell_text, "ECellCheckbox", ECellCheckbox, e_cell_checkbox_class_init, NULL, PARENT_TYPE);
ECell *
e_cell_checkbox_new (ETableModel *etm)
{
ECellCheckbox *eccb = gtk_type_new (e_cell_checkbox_get_type ());
E_CELL (eccb)->table_model = etm;
return (ECell *) eccb;
}
|