No issues found
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) version 3.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with the program; if not, see <http://www.gnu.org/licenses/>
14 *
15 *
16 * Authors:
17 * Chris Toshok <toshok@ximian.com>
18 * Chris Lahey <clahey@ximian.com>
19 *
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <ctype.h>
29 #include <math.h>
30 #include <stdio.h>
31
32 #include <gtk/gtk.h>
33
34 #include "gal-a11y-e-cell-registry.h"
35 #include "gal-a11y-e-cell-vbox.h"
36 #include "e-util/e-util.h"
37
38 #include "e-cell-vbox.h"
39 #include "e-table-item.h"
40
41 G_DEFINE_TYPE (ECellVbox, e_cell_vbox, E_TYPE_CELL)
42
43 #define INDENT_AMOUNT 16
44
45 /*
46 * ECell::new_view method
47 */
48 static ECellView *
49 ecv_new_view (ECell *ecell,
50 ETableModel *table_model,
51 gpointer e_table_item_view)
52 {
53 ECellVbox *ecv = E_CELL_VBOX (ecell);
54 ECellVboxView *vbox_view = g_new0 (ECellVboxView, 1);
55 gint i;
56
57 vbox_view->cell_view.ecell = ecell;
58 vbox_view->cell_view.e_table_model = table_model;
59 vbox_view->cell_view.e_table_item_view = e_table_item_view;
60 vbox_view->cell_view.kill_view_cb = NULL;
61 vbox_view->cell_view.kill_view_cb_data = NULL;
62
63 /* create our subcell view */
64 vbox_view->subcell_view_count = ecv->subcell_count;
65 vbox_view->subcell_views = g_new (ECellView *, vbox_view->subcell_view_count);
66 vbox_view->model_cols = g_new (int, vbox_view->subcell_view_count);
67
68 for (i = 0; i < vbox_view->subcell_view_count; i++) {
69 vbox_view->subcell_views[i] = e_cell_new_view (ecv->subcells[i], table_model, e_table_item_view /* XXX */);
70 vbox_view->model_cols[i] = ecv->model_cols[i];
71 }
72
73 return (ECellView *) vbox_view;
74 }
75
76 /*
77 * ECell::kill_view method
78 */
79 static void
80 ecv_kill_view (ECellView *ecv)
81 {
82 ECellVboxView *vbox_view = (ECellVboxView *) ecv;
83 gint i;
84
85 if (vbox_view->cell_view.kill_view_cb)
86 (vbox_view->cell_view.kill_view_cb)(ecv, vbox_view->cell_view.kill_view_cb_data);
87
88 if (vbox_view->cell_view.kill_view_cb_data)
89 g_list_free (vbox_view->cell_view.kill_view_cb_data);
90
91 /* kill our subcell view */
92 for (i = 0; i < vbox_view->subcell_view_count; i++)
93 e_cell_kill_view (vbox_view->subcell_views[i]);
94
95 g_free (vbox_view->model_cols);
96 g_free (vbox_view->subcell_views);
97 g_free (vbox_view);
98 }
99
100 /*
101 * ECell::realize method
102 */
103 static void
104 ecv_realize (ECellView *ecell_view)
105 {
106 ECellVboxView *vbox_view = (ECellVboxView *) ecell_view;
107 gint i;
108
109 /* realize our subcell view */
110 for (i = 0; i < vbox_view->subcell_view_count; i++)
111 e_cell_realize (vbox_view->subcell_views[i]);
112
113 if (E_CELL_CLASS (e_cell_vbox_parent_class)->realize)
114 (* E_CELL_CLASS (e_cell_vbox_parent_class)->realize) (ecell_view);
115 }
116
117 /*
118 * ECell::unrealize method
119 */
120 static void
121 ecv_unrealize (ECellView *ecv)
122 {
123 ECellVboxView *vbox_view = (ECellVboxView *) ecv;
124 gint i;
125
126 /* unrealize our subcell view. */
127 for (i = 0; i < vbox_view->subcell_view_count; i++)
128 e_cell_unrealize (vbox_view->subcell_views[i]);
129
130 if (E_CELL_CLASS (e_cell_vbox_parent_class)->unrealize)
131 (* E_CELL_CLASS (e_cell_vbox_parent_class)->unrealize) (ecv);
132 }
133
134 /*
135 * ECell::draw method
136 */
137 static void
138 ecv_draw (ECellView *ecell_view,
139 cairo_t *cr,
140 gint model_col,
141 gint view_col,
142 gint row,
143 ECellFlags flags,
144 gint x1,
145 gint y1,
146 gint x2,
147 gint y2)
148 {
149 ECellVboxView *vbox_view = (ECellVboxView *) ecell_view;
150
151 gint subcell_offset = 0;
152 gint i;
153
154 for (i = 0; i < vbox_view->subcell_view_count; i++) {
155 /* Now cause our subcells to draw their contents,
156 * shifted by subcell_offset pixels */
157 gint height;
158
159 height = e_cell_height (
160 vbox_view->subcell_views[i],
161 vbox_view->model_cols[i], view_col, row);
162 e_cell_draw (
163 vbox_view->subcell_views[i], cr,
164 vbox_view->model_cols[i], view_col, row, flags,
165 x1, y1 + subcell_offset, x2,
166 y1 + subcell_offset + height);
167
168 subcell_offset += e_cell_height (
169 vbox_view->subcell_views[i],
170 vbox_view->model_cols[i], view_col, row);
171 }
172 }
173
174 /*
175 * ECell::event method
176 */
177 static gint
178 ecv_event (ECellView *ecell_view,
179 GdkEvent *event,
180 gint model_col,
181 gint view_col,
182 gint row,
183 ECellFlags flags,
184 ECellActions *actions)
185 {
186 ECellVboxView *vbox_view = (ECellVboxView *) ecell_view;
187 gint y = 0;
188 gint i;
189 gint subcell_offset = 0;
190
191 switch (event->type) {
192 case GDK_BUTTON_PRESS:
193 case GDK_BUTTON_RELEASE:
194 case GDK_2BUTTON_PRESS:
195 case GDK_3BUTTON_PRESS:
196 y = event->button.y;
197 break;
198 case GDK_MOTION_NOTIFY:
199 y = event->motion.y;
200 break;
201 default:
202 /* nada */
203 break;
204 }
205
206 for (i = 0; i < vbox_view->subcell_view_count; i++) {
207 gint height = e_cell_height (vbox_view->subcell_views[i], vbox_view->model_cols[i], view_col, row);
208 if (y < subcell_offset + height)
209 return e_cell_event (vbox_view->subcell_views[i], event, vbox_view->model_cols[i], view_col, row, flags, actions);
210 subcell_offset += height;
211 }
212 return 0;
213 }
214
215 /*
216 * ECell::height method
217 */
218 static gint
219 ecv_height (ECellView *ecell_view,
220 gint model_col,
221 gint view_col,
222 gint row)
223 {
224 ECellVboxView *vbox_view = (ECellVboxView *) ecell_view;
225 gint height = 0;
226 gint i;
227
228 for (i = 0; i < vbox_view->subcell_view_count; i++) {
229 height += e_cell_height (vbox_view->subcell_views[i], vbox_view->model_cols[i], view_col, row);
230 }
231 return height;
232 }
233
234 /*
235 * ECell::max_width method
236 */
237 static gint
238 ecv_max_width (ECellView *ecell_view,
239 gint model_col,
240 gint view_col)
241 {
242 ECellVboxView *vbox_view = (ECellVboxView *) ecell_view;
243 gint max_width = 0;
244 gint i;
245
246 for (i = 0; i < vbox_view->subcell_view_count; i++) {
247 gint width = e_cell_max_width (vbox_view->subcell_views[i], vbox_view->model_cols[i], view_col);
248 max_width = MAX (width, max_width);
249 }
250
251 return max_width;
252 }
253
254 /*
255 * GObject::dispose method
256 */
257 static void
258 ecv_dispose (GObject *object)
259 {
260 ECellVbox *ecv = E_CELL_VBOX (object);
261 gint i;
262
263 /* destroy our subcell */
264 for (i = 0; i < ecv->subcell_count; i++)
265 if (ecv->subcells[i])
266 g_object_unref (ecv->subcells[i]);
267 g_free (ecv->subcells);
268 ecv->subcells = NULL;
269 ecv->subcell_count = 0;
270
271 G_OBJECT_CLASS (e_cell_vbox_parent_class)->dispose (object);
272 }
273
274 static void
275 ecv_finalize (GObject *object)
276 {
277 ECellVbox *ecv = E_CELL_VBOX (object);
278
279 g_free (ecv->model_cols);
280
281 G_OBJECT_CLASS (e_cell_vbox_parent_class)->finalize (object);
282 }
283
284 static void
285 e_cell_vbox_class_init (ECellVboxClass *class)
286 {
287 GObjectClass *object_class = G_OBJECT_CLASS (class);
288 ECellClass *ecc = E_CELL_CLASS (class);
289
290 object_class->dispose = ecv_dispose;
291 object_class->finalize = ecv_finalize;
292
293 ecc->new_view = ecv_new_view;
294 ecc->kill_view = ecv_kill_view;
295 ecc->realize = ecv_realize;
296 ecc->unrealize = ecv_unrealize;
297 ecc->draw = ecv_draw;
298 ecc->event = ecv_event;
299 ecc->height = ecv_height;
300 ecc->max_width = ecv_max_width;
301
302 gal_a11y_e_cell_registry_add_cell_type (NULL, E_TYPE_CELL_VBOX, gal_a11y_e_cell_vbox_new);
303 }
304
305 static void
306 e_cell_vbox_init (ECellVbox *ecv)
307 {
308 ecv->subcells = NULL;
309 ecv->subcell_count = 0;
310 }
311
312 /**
313 * e_cell_vbox_new:
314 *
315 * Creates a new ECell renderer that can be used to render multiple
316 * child cells.
317 *
318 * Return value: an ECell object that can be used to render multiple
319 * child cells.
320 **/
321 ECell *
322 e_cell_vbox_new (void)
323 {
324 return g_object_new (E_TYPE_CELL_VBOX, NULL);
325 }
326
327 void
328 e_cell_vbox_append (ECellVbox *vbox,
329 ECell *subcell,
330 gint model_col)
331 {
332 vbox->subcell_count++;
333
334 vbox->subcells = g_renew (ECell *, vbox->subcells, vbox->subcell_count);
335 vbox->model_cols = g_renew (int, vbox->model_cols, vbox->subcell_count);
336
337 vbox->subcells[vbox->subcell_count - 1] = subcell;
338 vbox->model_cols[vbox->subcell_count - 1] = model_col;
339
340 if (subcell)
341 g_object_ref_sink (subcell);
342 }