aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/e-cell.c
blob: 79f0a0e9bdf7656d8bb453f205a37e23f70fb366 (plain) (blame)
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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * e-cell.c: base class for cell renderers in e-table
 *
 * Author:
 *   Miguel de Icaza (miguel@kernel.org)
 *
 * (C) 1999 Ximian, Inc
 */
#include <config.h>
#include "e-cell.h"
#include "gal/util/e-util.h"

#define PARENT_TYPE gtk_object_get_type ()

static ECellView *
ec_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view)
{
    return NULL;
}

static void
ec_realize (ECellView *e_cell)
{
}

static void
ec_kill_view (ECellView *ecell_view)
{
}

static void
ec_unrealize (ECellView *e_cell)
{
}

static void
ec_draw (ECellView *ecell_view, GdkDrawable *drawable,
     int model_col, int view_col, int row, ECellFlags flags,
     int x1, int y1, int x2, int y2)
{
    g_error ("e-cell-draw invoked\n");
}

static gint
ec_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions)
{
    g_error ("e-cell-event invoked\n");
    return 0;
}

static gint
ec_height (ECellView *ecell_view, int model_col, int view_col, int row)
{
    g_error ("e-cell-height invoked\n");
    return 0;
}

static void
ec_focus (ECellView *ecell_view, int model_col, int view_col, int row, int x1, int y1, int x2, int y2)
{
    ecell_view->focus_col = view_col; 
    ecell_view->focus_row = row;
    ecell_view->focus_x1 = x1;
    ecell_view->focus_y1 = y1;
    ecell_view->focus_x2 = x2;
    ecell_view->focus_y2 = y2;
}

static void
ec_unfocus (ECellView *ecell_view)
{
    ecell_view->focus_col = -1;
    ecell_view->focus_row = -1;
    ecell_view->focus_x1 = -1;
    ecell_view->focus_y1 = -1;
    ecell_view->focus_x2 = -1;
    ecell_view->focus_y2 = -1;
}

static void *
ec_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row)
{
    return NULL;
}

static void
ec_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *context)
{
}

static void
ec_show_tooltip (ECellView *ecell_view, int model_col, int view_col, int row, int col_width, ETableTooltip *tooltip)
{
    /* Do nothing */
}

static void
e_cell_class_init (GtkObjectClass *object_class)
{
    ECellClass *ecc = (ECellClass *) object_class;

    ecc->realize = ec_realize;
    ecc->unrealize = ec_unrealize;
    ecc->new_view = ec_new_view;
    ecc->kill_view = ec_kill_view;
    ecc->draw = ec_draw;
    ecc->event = ec_event;
    ecc->focus = ec_focus;
    ecc->unfocus = ec_unfocus;
    ecc->height = ec_height;
    ecc->enter_edit = ec_enter_edit;
    ecc->leave_edit = ec_leave_edit;
    ecc->print = NULL;
    ecc->print_height = NULL;
    ecc->max_width = NULL;
    ecc->show_tooltip = ec_show_tooltip;
}

static void
e_cell_init (GtkObject *object)
{
}

E_MAKE_TYPE(e_cell, "ECell", ECell, e_cell_class_init, e_cell_init, PARENT_TYPE);

/**
 * e_cell_event:
 * @ecell_view: The ECellView where the event will be dispatched
 * @event: The GdkEvent.
 * @model_col: the column in the model
 * @view_col: the column in the view
 * @row: the row
 * @flags: flags about the current state
 * @actions: A second return value in case the cell wants to take some action (specifically grabbing & ungrabbing)
 *
 * Dispatches the event @event to the @ecell_view for.
 *
 * Returns: processing state from the GdkEvent handling.
 */
gint
e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions)
{
    return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->event (
        ecell_view, event, model_col, view_col, row, flags, actions);
}

/** 
 * e_cell_new_view:
 * @ecell: the Ecell that will create the new view
 * @table_model: the table model the ecell is bound to
 * @e_table_item_view: An ETableItem object (the CanvasItem that reprensents the view of the table)
 *
 * ECell renderers new to be bound to a table_model and to the actual view
 * during their life time to actually render the data.  This method is invoked
 * by the ETableItem canvas item to instatiate a new view of the ECell.
 *
 * This is invoked when the ETableModel is attached to the ETableItem (a CanvasItem
 * that can render ETableModels in the screen).
 *
 * Returns: a new ECellView for this @ecell on the @table_model displayed on the @e_table_item_view.
 */
ECellView *
e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view)
{
    return E_CELL_CLASS (GTK_OBJECT (ecell)->klass)->new_view (
        ecell, table_model, e_table_item_view);
}

/**
 * e_cell_realize:
 * @ecell_view: The ECellView to be realized.
 *
 * This function is invoked to give a chance to the ECellView to allocate
 * any resources it needs from Gdk, equivalent to the GtkWidget::realize
 * signal.
 */
void
e_cell_realize (ECellView *ecell_view)
{
    E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->realize (ecell_view);
}

/**
 * e_cell_kill_view:
 * @ecell_view: view to be destroyed.
 *
 * This method it used to destroy a view of an ECell renderer
 */
void
e_cell_kill_view (ECellView *ecell_view)
{
    E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->kill_view (ecell_view);
}

/**
 * e_cell_unrealize:
 * @ecell_view: The ECellView to be unrealized.
 *
 * This function is invoked to give a chance to the ECellView to
 * release any resources it allocated during the realize method,
 * equivalent to the GtkWidget::unrealize signal.
 */
void
e_cell_unrealize (ECellView *ecell_view)
{
    E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->unrealize (ecell_view);
}

/**
 * e_cell_draw:
 * @ecell_view: the ECellView to redraw
 * @drawable: draw desination
 * @model_col: the column in the model being drawn.
 * @view_col: the column in the view being drawn (what the model maps to).
 * @row: the row being drawn
 * @flags: rendering flags.
 * @x1: boudary for the rendering
 * @y1: boudary for the rendering
 * @x2: boudary for the rendering
 * @y2: boudary for the rendering
 *
 * This instructs the ECellView to render itself into the drawable.  The
 * region to be drawn in given by (x1,y1)-(x2,y2).
 *
 * The most important flags are %E_CELL_SELECTED and %E_CELL_FOCUSED, other
 * flags include alignments and justifications.
 */
void
e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable,
         int model_col, int view_col, int row, ECellFlags flags,
         int x1, int y1, int x2, int y2)
{
    g_return_if_fail (ecell_view != NULL);
    g_return_if_fail (row >= 0);
    g_return_if_fail (row < e_table_model_row_count(ecell_view->e_table_model));

    E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->draw (
        ecell_view, drawable, model_col, view_col, row, flags, x1, y1, x2, y2);
}

/**
 * e_cell_print:
 * @ecell_view: the ECellView to redraw
 * @context: The GnomePrintContext where we output our printed data.
 * @model_col: the column in the model being drawn.
 * @view_col: the column in the view being drawn (what the model maps to).
 * @row: the row being drawn
 * @width: width 
 * @height: height
 *
 * FIXME:
 */
void
e_cell_print (ECellView *ecell_view, GnomePrintContext *context, 
          int model_col, int view_col, int row,
          double width, double height)
{
    E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print
        (ecell_view, context, model_col, view_col, row, width, height);
}

/**
 * e_cell_print:
 *
 * FIXME:
 */
gdouble
e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context, 
             int model_col, int view_col, int row,
             double width)
{
    if (E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height)
        return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height
            (ecell_view, context, model_col, view_col, row, width);
    else
        return 0.0;
}

/**
 * e_cell_height:
 * @ecell_view: the ECellView.
 * @model_col: the column in the model
 * @view_col: the column in the view.
 * @row: the row to me measured
 *
 * Returns: the height of the cell at @model_col, @row rendered at
 * @view_col, @row.
 */
int
e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row)
{
    return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height (
        ecell_view, model_col, view_col, row);
}

/**
 * e_cell_enter_edit:
 * @ecell_view: the ECellView that will enter editing
 * @model_col: the column in the model
 * @view_col: the column in the view
 * @row: the row
 *
 * Notifies the ECellView that it is about to enter editing mode for
 * @model_col, @row rendered at @view_col, @row.
 */
void *
e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row)
{
    return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->enter_edit (
        ecell_view, model_col, view_col, row);
}

/**
 * e_cell_leave_edit:
 * @ecell_view: the ECellView that will leave editing
 * @model_col: the column in the model
 * @view_col: the column in the view
 * @row: the row
 * @edit_context: the editing context
 *
 * Notifies the ECellView that editing is finished at @model_col, @row
 * rendered at @view_col, @row.
 */
void
e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context)
{
    E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->leave_edit (
        ecell_view, model_col, view_col, row, edit_context);
}

/**
 * e_cell_max_width:
 * @ecell_view: the ECellView that will leave editing
 * @model_col: the column in the model
 * @view_col: the column in the view.
 *
 * Returns: the maximum width for the ECellview at @model_col which
 * is being rendered as @view_col
 */
int
e_cell_max_width (ECellView *ecell_view, int model_col, int view_col)
{
    return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->max_width 
        (ecell_view, model_col, view_col);
}
          
void
e_cell_show_tooltip (ECellView *ecell_view, int model_col, int view_col, 
             int row, int col_width, ETableTooltip *tooltip)
{
    E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->show_tooltip
        (ecell_view, model_col, view_col, row, col_width, tooltip);
}