Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / Extras / wtableview.c
Commit [+]AuthorDateLineData
dc67e814 kojima2000-11-12 03:29:53 +00001
a20aebde dan2001-01-18 19:21:56 +00002#include <WINGs/WINGsP.h>
dc67e814 kojima2000-11-12 03:29:53 +00003#include <X11/cursorfont.h>
06f59b99 Carlos R. Mafra2008-11-06 01:37:44 +01004#include <stdint.h>
dc67e814 kojima2000-11-12 03:29:53 +00005
6#include "wtableview.h"
7
e99511b0 kojima2001-01-02 14:17:26 +00008const char *WMTableViewSelectionDidChangeNotification = "WMTableViewSelectionDidChangeNotification";
f912d9f3 kojima2000-12-21 04:46:20 +00009
dc67e814 kojima2000-11-12 03:29:53 +000010struct W_TableColumn {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020011 WMTableView *table;
12 WMWidget *titleW;
13 char *title;
14 int width;
15 int minWidth;
16 int maxWidth;
6830b057 dan2004-10-12 21:28:27 +000017
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020018 void *id;
dc67e814 kojima2000-11-12 03:29:53 +000019
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020020 WMTableColumnDelegate *delegate;
dc67e814 kojima2000-11-12 03:29:53 +000021
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020022 unsigned resizable:1;
23 unsigned editable:1;
dc67e814 kojima2000-11-12 03:29:53 +000024};
25
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020026static void handleResize(W_ViewDelegate * self, WMView * view);
dc67e814 kojima2000-11-12 03:29:53 +000027
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028static void rearrangeHeader(WMTableView * table);
e99511b0 kojima2001-01-02 14:17:26 +000029
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030static WMRange rowsInRect(WMTableView * table, WMRect rect);
dc67e814 kojima2000-11-12 03:29:53 +000031
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020032WMTableColumn *WMCreateTableColumn(char *title)
dc67e814 kojima2000-11-12 03:29:53 +000033{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034 WMTableColumn *col = wmalloc(sizeof(WMTableColumn));
6830b057 dan2004-10-12 21:28:27 +000035
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020036 col->table = NULL;
37 col->titleW = NULL;
38 col->width = 50;
39 col->minWidth = 5;
40 col->maxWidth = 0;
6830b057 dan2004-10-12 21:28:27 +000041
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020042 col->id = NULL;
6830b057 dan2004-10-12 21:28:27 +000043
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020044 col->title = wstrdup(title);
6830b057 dan2004-10-12 21:28:27 +000045
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020046 col->delegate = NULL;
6830b057 dan2004-10-12 21:28:27 +000047
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020048 col->resizable = 1;
49 col->editable = 0;
6830b057 dan2004-10-12 21:28:27 +000050
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020051 return col;
dc67e814 kojima2000-11-12 03:29:53 +000052}
53
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020054void WMSetTableColumnId(WMTableColumn * column, void *id)
dc67e814 kojima2000-11-12 03:29:53 +000055{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020056 column->id = id;
dc67e814 kojima2000-11-12 03:29:53 +000057}
58
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020059void *WMGetTableColumnId(WMTableColumn * column)
dc67e814 kojima2000-11-12 03:29:53 +000060{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020061 return column->id;
dc67e814 kojima2000-11-12 03:29:53 +000062}
63
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020064void WMSetTableColumnWidth(WMTableColumn * column, unsigned width)
dc67e814 kojima2000-11-12 03:29:53 +000065{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020066 if (column->maxWidth == 0)
67 column->width = WMAX(column->minWidth, width);
68 else
69 column->width = WMAX(column->minWidth, WMIN(column->maxWidth, width));
70
71 if (column->table) {
72 rearrangeHeader(column->table);
73 }
dc67e814 kojima2000-11-12 03:29:53 +000074}
75
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020076void WMSetTableColumnDelegate(WMTableColumn * column, WMTableColumnDelegate * delegate)
dc67e814 kojima2000-11-12 03:29:53 +000077{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020078 column->delegate = delegate;
dc67e814 kojima2000-11-12 03:29:53 +000079}
80
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020081void WMSetTableColumnConstraints(WMTableColumn * column, unsigned minWidth, unsigned maxWidth)
dc67e814 kojima2000-11-12 03:29:53 +000082{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020083 wassertr(maxWidth == 0 || minWidth <= maxWidth);
6830b057 dan2004-10-12 21:28:27 +000084
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020085 column->minWidth = minWidth;
86 column->maxWidth = maxWidth;
6830b057 dan2004-10-12 21:28:27 +000087
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020088 if (column->width < column->minWidth)
89 WMSetTableColumnWidth(column, column->minWidth);
90 else if (column->width > column->maxWidth && column->maxWidth != 0)
91 WMSetTableColumnWidth(column, column->maxWidth);
dc67e814 kojima2000-11-12 03:29:53 +000092}
93
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020094void WMSetTableColumnEditable(WMTableColumn * column, Bool flag)
dc67e814 kojima2000-11-12 03:29:53 +000095{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020096 column->editable = ((flag == 0) ? 0 : 1);
dc67e814 kojima2000-11-12 03:29:53 +000097}
98
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020099WMTableView *WMGetTableColumnTableView(WMTableColumn * column)
dc67e814 kojima2000-11-12 03:29:53 +0000100{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200101 return column->table;
dc67e814 kojima2000-11-12 03:29:53 +0000102}
103
dc67e814 kojima2000-11-12 03:29:53 +0000104struct W_TableView {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200105 W_Class widgetClass;
106 WMView *view;
dc67e814 kojima2000-11-12 03:29:53 +0000107
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200108 WMFrame *header;
6830b057 dan2004-10-12 21:28:27 +0000109
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200110 WMLabel *corner;
22ae4f5a kojima2001-05-17 22:30:38 +0000111
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200112 WMScroller *hscroll;
113 WMScroller *vscroll;
114 WMView *tableView;
6830b057 dan2004-10-12 21:28:27 +0000115
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200116 WMPixmap *viewBuffer;
dc67e814 kojima2000-11-12 03:29:53 +0000117
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200118 WMArray *columns;
119 WMArray *splitters;
f912d9f3 kojima2000-12-21 04:46:20 +0000120
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200121 WMArray *selectedRows;
f912d9f3 kojima2000-12-21 04:46:20 +0000122
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200123 int tableWidth;
6830b057 dan2004-10-12 21:28:27 +0000124
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200125 int rows;
22ae4f5a kojima2001-05-17 22:30:38 +0000126
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200127 WMColor *backColor;
6830b057 dan2004-10-12 21:28:27 +0000128
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200129 GC gridGC;
130 WMColor *gridColor;
6830b057 dan2004-10-12 21:28:27 +0000131
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200132 Cursor splitterCursor;
6830b057 dan2004-10-12 21:28:27 +0000133
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200134 void *dataSource;
dc67e814 kojima2000-11-12 03:29:53 +0000135
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200136 WMTableViewDelegate *delegate;
4c60cd5b kojima2000-12-21 21:06:00 +0000137
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200138 WMAction *action;
139 void *clientData;
6830b057 dan2004-10-12 21:28:27 +0000140
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200141 void *clickedColumn;
142 int clickedRow;
6830b057 dan2004-10-12 21:28:27 +0000143
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200144 int editingRow;
6830b057 dan2004-10-12 21:28:27 +0000145
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200146 unsigned headerHeight;
6830b057 dan2004-10-12 21:28:27 +0000147
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200148 unsigned rowHeight;
e99511b0 kojima2001-01-02 14:17:26 +0000149
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200150 unsigned dragging:1;
151 unsigned drawsGrid:1;
152 unsigned canSelectRow:1;
153 unsigned canSelectMultiRows:1;
154 unsigned canDeselectRow:1;
18ed0463 kojima2003-03-13 21:36:34 +0000155
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200156 unsigned int hasVScroller:1;
157 unsigned int hasHScroller:1;
dc67e814 kojima2000-11-12 03:29:53 +0000158};
159
160static W_Class tableClass = 0;
161
dc67e814 kojima2000-11-12 03:29:53 +0000162static W_ViewDelegate viewDelegate = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200163 NULL,
164 NULL,
165 handleResize,
166 NULL,
167 NULL
dc67e814 kojima2000-11-12 03:29:53 +0000168};
169
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200170static void reorganizeInterior(WMTableView * table);
dc67e814 kojima2000-11-12 03:29:53 +0000171
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200172static void handleEvents(XEvent * event, void *data);
173static void handleTableEvents(XEvent * event, void *data);
174static void repaintTable(WMTableView * table);
dc67e814 kojima2000-11-12 03:29:53 +0000175
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200176static WMSize getTotalSize(WMTableView * table)
dc67e814 kojima2000-11-12 03:29:53 +0000177{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200178 WMSize size;
179 int i;
6830b057 dan2004-10-12 21:28:27 +0000180
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200181 /* get width from columns */
182 size.width = 0;
183 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
184 WMTableColumn *column;
6830b057 dan2004-10-12 21:28:27 +0000185
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200186 column = WMGetFromArray(table->columns, i);
6830b057 dan2004-10-12 21:28:27 +0000187
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200188 size.width += column->width;
189 }
22ae4f5a kojima2001-05-17 22:30:38 +0000190
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200191 /* get height from rows */
192 size.height = table->rows * table->rowHeight;
6830b057 dan2004-10-12 21:28:27 +0000193
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200194 return size;
22ae4f5a kojima2001-05-17 22:30:38 +0000195}
196
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200197static WMRect getVisibleRect(WMTableView * table)
22ae4f5a kojima2001-05-17 22:30:38 +0000198{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200199 WMSize size = getTotalSize(table);
200 WMRect rect;
201
202 if (table->vscroll) {
203 rect.size.height = size.height * WMGetScrollerKnobProportion(table->vscroll);
204 rect.pos.y = (size.height - rect.size.height) * WMGetScrollerValue(table->vscroll);
205 } else {
206 rect.size.height = size.height;
207 rect.pos.y = 0;
208 }
209
210 if (table->hscroll) {
211 rect.size.width = size.width * WMGetScrollerKnobProportion(table->hscroll);
212 rect.pos.x = (size.width - rect.size.width) * WMGetScrollerValue(table->hscroll);
213 } else {
214 rect.size.width = size.width;
215 rect.pos.x = 0;
216 }
217
218 return rect;
22ae4f5a kojima2001-05-17 22:30:38 +0000219}
220
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200221static void scrollToPoint(WMTableView * table, int x, int y)
22ae4f5a kojima2001-05-17 22:30:38 +0000222{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200223 WMSize size = getTotalSize(table);
224 int i;
225 float value, prop;
226
227 if (table->hscroll) {
228 if (size.width > W_VIEW_WIDTH(table->tableView)) {
229 prop = (float)W_VIEW_WIDTH(table->tableView) / (float)size.width;
230 value = (float)x / (float)(size.width - W_VIEW_WIDTH(table->tableView));
231 } else {
232 prop = 1.0;
233 value = 0.0;
234 }
235 WMSetScrollerParameters(table->hscroll, value, prop);
236 }
237
238 if (table->vscroll) {
239 if (size.height > W_VIEW_HEIGHT(table->tableView)) {
240 prop = (float)W_VIEW_HEIGHT(table->tableView) / (float)size.height;
241 value = (float)y / (float)(size.height - W_VIEW_HEIGHT(table->tableView));
242 } else {
243 prop = 1.0;
244 value = 0.0;
245 }
246
247 WMSetScrollerParameters(table->vscroll, value, prop);
248 }
249
250 if (table->editingRow >= 0) {
251 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
252 WMTableColumn *column;
253
254 column = WMGetFromArray(table->columns, i);
255
256 if (column->delegate && column->delegate->beginCellEdit)
257 (*column->delegate->beginCellEdit) (column->delegate, column, table->editingRow);
258 }
259 }
260
261 repaintTable(table);
22ae4f5a kojima2001-05-17 22:30:38 +0000262}
263
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200264static void adjustScrollers(WMTableView * table)
22ae4f5a kojima2001-05-17 22:30:38 +0000265{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200266 WMSize size = getTotalSize(table);
267 WMSize vsize = WMGetViewSize(table->tableView);
268 float prop, value;
269 float oprop, ovalue;
270
271 if (table->hscroll) {
272 if (size.width <= vsize.width) {
273 value = 0.0;
274 prop = 1.0;
275 } else {
276 oprop = WMGetScrollerKnobProportion(table->hscroll);
277 if (oprop == 0.0)
278 oprop = 1.0;
279 ovalue = WMGetScrollerValue(table->hscroll);
280
281 prop = (float)vsize.width / (float)size.width;
282 value = prop * ovalue / oprop;
283 }
284 WMSetScrollerParameters(table->hscroll, value, prop);
285 }
286
287 if (table->vscroll) {
288 if (size.height <= vsize.height) {
289 value = 0.0;
290 prop = 1.0;
291 } else {
292 oprop = WMGetScrollerKnobProportion(table->vscroll);
293 if (oprop == 0.0)
294 oprop = 1.0;
295 ovalue = WMGetScrollerValue(table->vscroll);
296
297 prop = (float)vsize.height / (float)size.height;
298 value = prop * ovalue / oprop;
299 }
300 WMSetScrollerParameters(table->vscroll, value, prop);
301 }
22ae4f5a kojima2001-05-17 22:30:38 +0000302}
303
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200304static void doScroll(WMWidget * self, void *data)
22ae4f5a kojima2001-05-17 22:30:38 +0000305{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200306 WMTableView *table = (WMTableView *) data;
307 float value;
308 float vpsize;
309 float size;
310 WMSize ts = getTotalSize(table);
311
312 value = WMGetScrollerValue(self);
313
314 if (table->hscroll == (WMScroller *) self) {
315 vpsize = W_VIEW_WIDTH(table->tableView);
316 size = ts.width;
317 } else {
318 vpsize = W_VIEW_HEIGHT(table->tableView);
319 size = ts.height;
320 }
321
322 switch (WMGetScrollerHitPart(self)) {
323 case WSDecrementWheel:
324 case WSDecrementLine:
325 value -= (float)table->rowHeight / size;
326 if (value < 0)
327 value = 0.0;
328 WMSetScrollerParameters(self, value, WMGetScrollerKnobProportion(self));
329 repaintTable(table);
330 break;
331
332 case WSIncrementWheel:
333 case WSIncrementLine:
334 value += (float)table->rowHeight / size;
335 if (value > 1.0)
336 value = 1.0;
337 WMSetScrollerParameters(self, value, WMGetScrollerKnobProportion(self));
338 repaintTable(table);
339 break;
340
341 case WSKnob:
342 repaintTable(table);
343 break;
344
345 case WSDecrementPage:
346 value -= vpsize / size;
347 if (value < 0.0)
348 value = 0.0;
349 WMSetScrollerParameters(self, value, WMGetScrollerKnobProportion(self));
350 repaintTable(table);
351 break;
352
353 case WSIncrementPage:
354 value += vpsize / size;
355 if (value > 1.0)
356 value = 1.0;
357 WMSetScrollerParameters(self, value, WMGetScrollerKnobProportion(self));
358 repaintTable(table);
359 break;
360
361 case WSNoPart:
362 case WSKnobSlot:
363 break;
364 }
365
366 if (table->editingRow >= 0) {
367 int i;
368 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
369 WMTableColumn *column;
370
371 column = WMGetFromArray(table->columns, i);
372
373 if (column->delegate && column->delegate->beginCellEdit)
374 (*column->delegate->beginCellEdit) (column->delegate, column, table->editingRow);
375 }
376 }
377
378 if (table->hscroll == self) {
379 int x = 0;
380 int i;
381 WMRect rect = getVisibleRect(table);
382
383 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
384 WMTableColumn *column;
385 WMView *splitter;
386
387 column = WMGetFromArray(table->columns, i);
388
389 WMMoveWidget(column->titleW, x - rect.pos.x, 0);
390
391 x += W_VIEW_WIDTH(WMWidgetView(column->titleW)) + 1;
392
393 splitter = WMGetFromArray(table->splitters, i);
394 W_MoveView(splitter, x - rect.pos.x - 1, 0);
395 }
396 }
dc67e814 kojima2000-11-12 03:29:53 +0000397}
398
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200399static void splitterHandler(XEvent * event, void *data)
dc67e814 kojima2000-11-12 03:29:53 +0000400{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200401 WMTableColumn *column = (WMTableColumn *) data;
402 WMTableView *table = column->table;
403 int done = 0;
404 int cx, ox, offsX;
405 WMPoint pos;
406 WMScreen *scr = WMWidgetScreen(table);
407 GC gc = scr->ixorGC;
408 Display *dpy = WMScreenDisplay(scr);
409 int h = WMWidgetHeight(table) - 22;
410 Window w = WMViewXID(table->view);
411
412 pos = WMGetViewPosition(WMWidgetView(column->titleW));
413
414 offsX = pos.x + column->width;
415
416 ox = cx = offsX;
417
418 XDrawLine(dpy, w, gc, cx + 20, 0, cx + 20, h);
419
420 while (!done) {
421 XEvent ev;
422
423 WMMaskEvent(dpy, ButtonMotionMask | ButtonReleaseMask, &ev);
424
425 switch (ev.type) {
426 case MotionNotify:
427 ox = cx;
428
429 if (column->width + ev.xmotion.x < column->minWidth)
430 cx = pos.x + column->minWidth;
431 else if (column->maxWidth > 0 && column->width + ev.xmotion.x > column->maxWidth)
432 cx = pos.x + column->maxWidth;
433 else
434 cx = offsX + ev.xmotion.x;
435
436 XDrawLine(dpy, w, gc, ox + 20, 0, ox + 20, h);
437 XDrawLine(dpy, w, gc, cx + 20, 0, cx + 20, h);
438 break;
439
440 case ButtonRelease:
441 column->width = cx - pos.x;
442 done = 1;
443 break;
444 }
445 }
446
447 XDrawLine(dpy, w, gc, cx + 20, 0, cx + 20, h);
448 rearrangeHeader(table);
449 repaintTable(table);
dc67e814 kojima2000-11-12 03:29:53 +0000450}
451
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200452static void realizeTable(void *data, WMNotification * notif)
22ae4f5a kojima2001-05-17 22:30:38 +0000453{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200454 repaintTable(data);
22ae4f5a kojima2001-05-17 22:30:38 +0000455}
456
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200457WMTableView *WMCreateTableView(WMWidget * parent)
dc67e814 kojima2000-11-12 03:29:53 +0000458{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200459 WMTableView *table = wmalloc(sizeof(WMTableView));
460 WMScreen *scr = WMWidgetScreen(parent);
6830b057 dan2004-10-12 21:28:27 +0000461
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200462 memset(table, 0, sizeof(WMTableView));
dc67e814 kojima2000-11-12 03:29:53 +0000463
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200464 if (!tableClass) {
465 tableClass = W_RegisterUserWidget();
466 }
467 table->widgetClass = tableClass;
6830b057 dan2004-10-12 21:28:27 +0000468
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200469 table->view = W_CreateView(W_VIEW(parent));
470 if (!table->view)
471 goto error;
472 table->view->self = table;
6830b057 dan2004-10-12 21:28:27 +0000473
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200474 table->view->delegate = &viewDelegate;
6830b057 dan2004-10-12 21:28:27 +0000475
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200476 table->headerHeight = 20;
6830b057 dan2004-10-12 21:28:27 +0000477
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200478 table->hscroll = WMCreateScroller(table);
479 WMSetScrollerAction(table->hscroll, doScroll, table);
480 WMMoveWidget(table->hscroll, 1, 2 + table->headerHeight);
481 WMMapWidget(table->hscroll);
dc67e814 kojima2000-11-12 03:29:53 +0000482
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200483 table->hasHScroller = 1;
18ed0463 kojima2003-03-13 21:36:34 +0000484
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200485 table->vscroll = WMCreateScroller(table);
486 WMSetScrollerArrowsPosition(table->vscroll, WSAMaxEnd);
487 WMSetScrollerAction(table->vscroll, doScroll, table);
488 WMMoveWidget(table->vscroll, 1, 2 + table->headerHeight);
489 WMMapWidget(table->vscroll);
18ed0463 kojima2003-03-13 21:36:34 +0000490
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200491 table->hasVScroller = 1;
18ed0463 kojima2003-03-13 21:36:34 +0000492
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200493 table->header = WMCreateFrame(table);
494 WMMoveWidget(table->header, 22, 2);
495 WMMapWidget(table->header);
496 WMSetFrameRelief(table->header, WRFlat);
6830b057 dan2004-10-12 21:28:27 +0000497
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200498 table->corner = WMCreateLabel(table);
499 WMResizeWidget(table->corner, 20, table->headerHeight);
500 WMMoveWidget(table->corner, 2, 2);
501 WMMapWidget(table->corner);
502 WMSetLabelRelief(table->corner, WRRaised);
503 WMSetWidgetBackgroundColor(table->corner, scr->darkGray);
6830b057 dan2004-10-12 21:28:27 +0000504
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200505 table->tableView = W_CreateView(table->view);
506 if (!table->tableView)
507 goto error;
508 table->tableView->self = table;
509 W_MapView(table->tableView);
dc67e814 kojima2000-11-12 03:29:53 +0000510
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200511 WMAddNotificationObserver(realizeTable, table, WMViewRealizedNotification, table->tableView);
6830b057 dan2004-10-12 21:28:27 +0000512
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200513 table->tableView->flags.dontCompressExpose = 1;
6830b057 dan2004-10-12 21:28:27 +0000514
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200515 table->gridColor = WMCreateNamedColor(scr, "#cccccc", False);
516 /* table->gridColor = WMGrayColor(scr); */
6830b057 dan2004-10-12 21:28:27 +0000517
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200518 {
519 XGCValues gcv;
6830b057 dan2004-10-12 21:28:27 +0000520
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200521 table->backColor = WMWhiteColor(scr);
6830b057 dan2004-10-12 21:28:27 +0000522
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200523 gcv.foreground = WMColorPixel(table->gridColor);
524 gcv.dashes = 1;
525 gcv.line_style = LineOnOffDash;
526 table->gridGC = XCreateGC(WMScreenDisplay(scr), W_DRAWABLE(scr), GCForeground, &gcv);
527 }
6830b057 dan2004-10-12 21:28:27 +0000528
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200529 table->editingRow = -1;
530 table->clickedRow = -1;
6830b057 dan2004-10-12 21:28:27 +0000531
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200532 table->drawsGrid = 1;
533 table->rowHeight = 16;
6830b057 dan2004-10-12 21:28:27 +0000534
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200535 table->tableWidth = 1;
6830b057 dan2004-10-12 21:28:27 +0000536
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200537 table->columns = WMCreateArray(4);
538 table->splitters = WMCreateArray(4);
6830b057 dan2004-10-12 21:28:27 +0000539
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200540 table->selectedRows = WMCreateArray(16);
f912d9f3 kojima2000-12-21 04:46:20 +0000541
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200542 table->splitterCursor = XCreateFontCursor(WMScreenDisplay(scr), XC_sb_h_double_arrow);
6830b057 dan2004-10-12 21:28:27 +0000543
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200544 table->canSelectRow = 1;
6830b057 dan2004-10-12 21:28:27 +0000545
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200546 WMCreateEventHandler(table->view, ExposureMask | StructureNotifyMask, handleEvents, table);
6830b057 dan2004-10-12 21:28:27 +0000547
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200548 WMCreateEventHandler(table->tableView, ExposureMask | ButtonPressMask |
549 ButtonReleaseMask | ButtonMotionMask, handleTableEvents, table);
dc67e814 kojima2000-11-12 03:29:53 +0000550
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200551 WMResizeWidget(table, 50, 50);
07c9bb7d kojima2001-02-13 23:00:14 +0000552
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200553 return table;
6830b057 dan2004-10-12 21:28:27 +0000554
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200555 error:
556 if (table->tableView)
557 W_DestroyView(table->tableView);
558 if (table->view)
559 W_DestroyView(table->view);
560 wfree(table);
561 return NULL;
dc67e814 kojima2000-11-12 03:29:53 +0000562}
563
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200564void WMAddTableViewColumn(WMTableView * table, WMTableColumn * column)
dc67e814 kojima2000-11-12 03:29:53 +0000565{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200566 WMScreen *scr = WMWidgetScreen(table);
6830b057 dan2004-10-12 21:28:27 +0000567
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200568 column->table = table;
dc67e814 kojima2000-11-12 03:29:53 +0000569
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200570 WMAddToArray(table->columns, column);
6830b057 dan2004-10-12 21:28:27 +0000571
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200572 if (!column->titleW) {
573 column->titleW = WMCreateLabel(table);
574 WMSetLabelRelief(column->titleW, WRRaised);
575 WMSetLabelFont(column->titleW, scr->boldFont);
576 WMSetLabelTextColor(column->titleW, scr->white);
577 WMSetWidgetBackgroundColor(column->titleW, scr->darkGray);
578 WMSetLabelText(column->titleW, column->title);
579 W_ReparentView(WMWidgetView(column->titleW), WMWidgetView(table->header), 0, 0);
580 if (W_VIEW_REALIZED(table->view))
581 WMRealizeWidget(column->titleW);
582 WMMapWidget(column->titleW);
583 }
6830b057 dan2004-10-12 21:28:27 +0000584
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200585 {
586 WMView *splitter = W_CreateView(WMWidgetView(table->header));
6830b057 dan2004-10-12 21:28:27 +0000587
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200588 W_SetViewBackgroundColor(splitter, WMWhiteColor(scr));
dc67e814 kojima2000-11-12 03:29:53 +0000589
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200590 if (W_VIEW_REALIZED(table->view))
591 W_RealizeView(splitter);
dc67e814 kojima2000-11-12 03:29:53 +0000592
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200593 W_ResizeView(splitter, 2, table->headerHeight);
594 W_MapView(splitter);
07c9bb7d kojima2001-02-13 23:00:14 +0000595
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200596 W_SetViewCursor(splitter, table->splitterCursor);
597 WMCreateEventHandler(splitter, ButtonPressMask | ButtonReleaseMask, splitterHandler, column);
dc67e814 kojima2000-11-12 03:29:53 +0000598
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200599 WMAddToArray(table->splitters, splitter);
600 }
dc67e814 kojima2000-11-12 03:29:53 +0000601
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200602 rearrangeHeader(table);
dc67e814 kojima2000-11-12 03:29:53 +0000603}
604
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200605void WMSetTableViewHeaderHeight(WMTableView * table, unsigned height)
dc67e814 kojima2000-11-12 03:29:53 +0000606{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200607 table->headerHeight = height;
6830b057 dan2004-10-12 21:28:27 +0000608
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200609 handleResize(NULL, table->view);
dc67e814 kojima2000-11-12 03:29:53 +0000610}
611
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200612void WMSetTableViewDelegate(WMTableView * table, WMTableViewDelegate * delegate)
dc67e814 kojima2000-11-12 03:29:53 +0000613{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200614 table->delegate = delegate;
dc67e814 kojima2000-11-12 03:29:53 +0000615}
616
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200617void WMSetTableViewAction(WMTableView * table, WMAction * action, void *clientData)
e99511b0 kojima2001-01-02 14:17:26 +0000618{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200619 table->action = action;
6830b057 dan2004-10-12 21:28:27 +0000620
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200621 table->clientData = clientData;
e99511b0 kojima2001-01-02 14:17:26 +0000622}
623
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200624void *WMGetTableViewClickedColumn(WMTableView * table)
e99511b0 kojima2001-01-02 14:17:26 +0000625{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200626 return table->clickedColumn;
e99511b0 kojima2001-01-02 14:17:26 +0000627}
628
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200629int WMGetTableViewClickedRow(WMTableView * table)
e99511b0 kojima2001-01-02 14:17:26 +0000630{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200631 return table->clickedRow;
e99511b0 kojima2001-01-02 14:17:26 +0000632}
633
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200634WMArray *WMGetTableViewSelectedRows(WMTableView * table)
bb886be8 kojima2001-01-18 02:00:56 +0000635{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200636 return table->selectedRows;
bb886be8 kojima2001-01-18 02:00:56 +0000637}
638
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200639WMView *WMGetTableViewDocumentView(WMTableView * table)
dc67e814 kojima2000-11-12 03:29:53 +0000640{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200641 return table->tableView;
dc67e814 kojima2000-11-12 03:29:53 +0000642}
643
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200644void *WMTableViewDataForCell(WMTableView * table, WMTableColumn * column, int row)
dc67e814 kojima2000-11-12 03:29:53 +0000645{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200646 return (*table->delegate->valueForCell) (table->delegate, column, row);
dc67e814 kojima2000-11-12 03:29:53 +0000647}
648
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200649void WMSetTableViewDataForCell(WMTableView * table, WMTableColumn * column, int row, void *data)
4c60cd5b kojima2000-12-21 21:06:00 +0000650{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200651 (*table->delegate->setValueForCell) (table->delegate, column, row, data);
4c60cd5b kojima2000-12-21 21:06:00 +0000652}
653
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200654WMRect WMTableViewRectForCell(WMTableView * table, WMTableColumn * column, int row)
dc67e814 kojima2000-11-12 03:29:53 +0000655{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200656 WMRect rect;
657 int i;
6830b057 dan2004-10-12 21:28:27 +0000658
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200659 rect.pos.x = 0;
660 rect.pos.y = row * table->rowHeight;
661 rect.size.height = table->rowHeight;
6830b057 dan2004-10-12 21:28:27 +0000662
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200663 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
664 WMTableColumn *col;
665 col = WMGetFromArray(table->columns, i);
6830b057 dan2004-10-12 21:28:27 +0000666
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200667 if (col == column) {
668 rect.size.width = col->width;
669 break;
670 }
6830b057 dan2004-10-12 21:28:27 +0000671
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200672 rect.pos.x += col->width;
673 }
6830b057 dan2004-10-12 21:28:27 +0000674
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200675 {
676 WMRect r = getVisibleRect(table);
6830b057 dan2004-10-12 21:28:27 +0000677
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200678 rect.pos.y -= r.pos.y;
679 rect.pos.x -= r.pos.x;
680 }
6830b057 dan2004-10-12 21:28:27 +0000681
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200682 return rect;
dc67e814 kojima2000-11-12 03:29:53 +0000683}
684
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200685void WMSetTableViewDataSource(WMTableView * table, void *source)
dc67e814 kojima2000-11-12 03:29:53 +0000686{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200687 table->dataSource = source;
dc67e814 kojima2000-11-12 03:29:53 +0000688}
689
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200690void *WMGetTableViewDataSource(WMTableView * table)
dc67e814 kojima2000-11-12 03:29:53 +0000691{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200692 return table->dataSource;
dc67e814 kojima2000-11-12 03:29:53 +0000693}
694
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200695void WMSetTableViewHasHorizontalScroller(WMTableView * tPtr, Bool flag)
18ed0463 kojima2003-03-13 21:36:34 +0000696{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200697 if (flag) {
698 if (tPtr->hasHScroller)
699 return;
700 tPtr->hasHScroller = 1;
701
702 tPtr->hscroll = WMCreateScroller(tPtr);
703 WMSetScrollerAction(tPtr->hscroll, doScroll, tPtr);
704 WMSetScrollerArrowsPosition(tPtr->hscroll, WSAMaxEnd);
705 /* make it a horiz. scroller */
706 WMResizeWidget(tPtr->hscroll, 1, 2);
707
708 if (W_VIEW_REALIZED(tPtr->view)) {
709 WMRealizeWidget(tPtr->hscroll);
710 }
711
712 reorganizeInterior(tPtr);
713
714 WMMapWidget(tPtr->hscroll);
715 } else {
716 if (!tPtr->hasHScroller)
717 return;
718 tPtr->hasHScroller = 0;
719
720 WMUnmapWidget(tPtr->hscroll);
721 WMDestroyWidget(tPtr->hscroll);
722 tPtr->hscroll = NULL;
723
724 reorganizeInterior(tPtr);
725 }
18ed0463 kojima2003-03-13 21:36:34 +0000726}
727
728#if 0
729/* not supported by now */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200730void WMSetTableViewHasVerticalScroller(WMTableView * tPtr, Bool flag)
18ed0463 kojima2003-03-13 21:36:34 +0000731{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200732 if (flag) {
733 if (tPtr->hasVScroller)
734 return;
735 tPtr->hasVScroller = 1;
736
737 tPtr->vscroll = WMCreateScroller(tPtr);
738 WMSetScrollerAction(tPtr->vscroll, doScroll, tPtr);
739 WMSetScrollerArrowsPosition(tPtr->vscroll, WSAMaxEnd);
740 /* make it a vert. scroller */
741 WMResizeWidget(tPtr->vscroll, 1, 2);
742
743 if (W_VIEW_REALIZED(tPtr->view)) {
744 WMRealizeWidget(tPtr->vscroll);
745 }
746
747 reorganizeInterior(tPtr);
748
749 WMMapWidget(tPtr->vscroll);
750 } else {
751 if (!tPtr->hasVScroller)
752 return;
753 tPtr->hasVScroller = 0;
754
755 WMUnmapWidget(tPtr->vscroll);
756 WMDestroyWidget(tPtr->vscroll);
757 tPtr->vscroll = NULL;
758
759 reorganizeInterior(tPtr);
760 }
18ed0463 kojima2003-03-13 21:36:34 +0000761}
762#endif
763
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200764void WMSetTableViewBackgroundColor(WMTableView * table, WMColor * color)
dc67e814 kojima2000-11-12 03:29:53 +0000765{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200766 W_SetViewBackgroundColor(table->tableView, color);
6830b057 dan2004-10-12 21:28:27 +0000767
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200768 if (table->backColor)
769 WMReleaseColor(table->backColor);
22ae4f5a kojima2001-05-17 22:30:38 +0000770
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200771 table->backColor = WMRetainColor(color);
6830b057 dan2004-10-12 21:28:27 +0000772
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200773 repaintTable(table);
dc67e814 kojima2000-11-12 03:29:53 +0000774}
775
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200776void WMSetTableViewGridColor(WMTableView * table, WMColor * color)
dc67e814 kojima2000-11-12 03:29:53 +0000777{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200778 WMReleaseColor(table->gridColor);
779 table->gridColor = WMRetainColor(color);
780 XSetForeground(WMScreenDisplay(WMWidgetScreen(table)), table->gridGC, WMColorPixel(color));
781 repaintTable(table);
dc67e814 kojima2000-11-12 03:29:53 +0000782}
783
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200784void WMSetTableViewRowHeight(WMTableView * table, int height)
e99511b0 kojima2001-01-02 14:17:26 +0000785{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200786 table->rowHeight = height;
6830b057 dan2004-10-12 21:28:27 +0000787
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200788 repaintTable(table);
e99511b0 kojima2001-01-02 14:17:26 +0000789}
790
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200791void WMScrollTableViewRowToVisible(WMTableView * table, int row)
e99511b0 kojima2001-01-02 14:17:26 +0000792{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200793 WMScroller *scroller;
794 WMRange range;
795 WMRect rect;
796 int newY, tmp;
797
798 rect = getVisibleRect(table);
799 range = rowsInRect(table, rect);
800
801 scroller = table->vscroll;
802
803 if (row < range.position) {
804 newY = row * table->rowHeight - rect.size.height / 2;
805 } else if (row >= range.position + range.count) {
806 newY = row * table->rowHeight - rect.size.height / 2;
807 } else {
808 return;
809 }
810 tmp = table->rows * table->rowHeight - rect.size.height;
811 newY = WMAX(0, WMIN(newY, tmp));
812
813 scrollToPoint(table, rect.pos.x, newY);
e99511b0 kojima2001-01-02 14:17:26 +0000814}
22ae4f5a kojima2001-05-17 22:30:38 +0000815
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200816static void drawGrid(WMTableView * table, WMRect rect)
dc67e814 kojima2000-11-12 03:29:53 +0000817{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200818 WMScreen *scr = WMWidgetScreen(table);
819 Display *dpy = WMScreenDisplay(scr);
820 int i;
821 int y1, y2;
822 int x1, x2;
823 int xx;
824 Drawable d = WMGetPixmapXID(table->viewBuffer);
825 GC gc = table->gridGC;
6830b057 dan2004-10-12 21:28:27 +0000826
dc67e814 kojima2000-11-12 03:29:53 +0000827#if 0
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200828 char dashl[1] = { 1 };
6830b057 dan2004-10-12 21:28:27 +0000829
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200830 XSetDashes(dpy, gc, 0, dashl, 1);
6830b057 dan2004-10-12 21:28:27 +0000831
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200832 y1 = (rect.pos.y / table->rowHeight - 1) * table->rowHeight;
833 y2 = y1 + (rect.size.height / table->rowHeight + 2) * table->rowHeight;
dc67e814 kojima2000-11-12 03:29:53 +0000834#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200835 y1 = 0;
836 y2 = W_VIEW_HEIGHT(table->tableView);
dc67e814 kojima2000-11-12 03:29:53 +0000837
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200838 xx = -rect.pos.x;
839 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
840 WMTableColumn *column;
22ae4f5a kojima2001-05-17 22:30:38 +0000841
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200842 XDrawLine(dpy, d, gc, xx, y1, xx, y2);
22ae4f5a kojima2001-05-17 22:30:38 +0000843
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200844 column = WMGetFromArray(table->columns, i);
845 xx += column->width;
846 }
847 XDrawLine(dpy, d, gc, xx, y1, xx, y2);
6830b057 dan2004-10-12 21:28:27 +0000848
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200849 x1 = 0;
850 x2 = rect.size.width;
6830b057 dan2004-10-12 21:28:27 +0000851
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200852 if (x2 <= x1)
853 return;
dc67e814 kojima2000-11-12 03:29:53 +0000854#if 0
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200855 XSetDashes(dpy, gc, (rect.pos.x & 1), dashl, 1);
dc67e814 kojima2000-11-12 03:29:53 +0000856#endif
6830b057 dan2004-10-12 21:28:27 +0000857
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200858 y1 = -rect.pos.y % table->rowHeight;
859 y2 = y1 + rect.size.height + table->rowHeight;
6830b057 dan2004-10-12 21:28:27 +0000860
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200861 for (i = y1; i <= y2; i += table->rowHeight) {
862 XDrawLine(dpy, d, gc, x1, i, x2, i);
863 }
dc67e814 kojima2000-11-12 03:29:53 +0000864}
865
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200866static WMRange columnsInRect(WMTableView * table, WMRect rect)
dc67e814 kojima2000-11-12 03:29:53 +0000867{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200868 WMTableColumn *column;
869 int pos;
870 int i, found;
871 int totalColumns = WMGetArrayItemCount(table->columns);
872 WMRange range;
873
874 pos = 0;
875 found = 0;
876 for (i = 0; i < totalColumns; i++) {
877 column = WMGetFromArray(table->columns, i);
878 if (!found) {
879 if (rect.pos.x >= pos && rect.pos.x < pos + column->width) {
880 range.position = i;
881 range.count = 1;
882 found = 1;
883 }
884 } else {
885 if (pos > rect.pos.x + rect.size.width) {
886 break;
887 }
888 range.count++;
889 }
890 pos += column->width;
891 }
892 range.count = WMAX(1, WMIN(range.count, totalColumns - range.position));
893 return range;
dc67e814 kojima2000-11-12 03:29:53 +0000894}
895
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200896static WMRange rowsInRect(WMTableView * table, WMRect rect)
dc67e814 kojima2000-11-12 03:29:53 +0000897{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200898 WMRange range;
899 int rh = table->rowHeight;
900 int dif;
6830b057 dan2004-10-12 21:28:27 +0000901
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200902 dif = rect.pos.y % rh;
6830b057 dan2004-10-12 21:28:27 +0000903
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200904 range.position = WMAX(0, (rect.pos.y - dif) / rh);
905 range.count = WMAX(1, WMIN((rect.size.height + dif) / rh, table->rows));
dc67e814 kojima2000-11-12 03:29:53 +0000906
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200907 return range;
dc67e814 kojima2000-11-12 03:29:53 +0000908}
909
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200910static void drawRow(WMTableView * table, int row, WMRect clipRect)
dc67e814 kojima2000-11-12 03:29:53 +0000911{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200912 int i;
913 WMRange cols = columnsInRect(table, clipRect);
914 WMTableColumn *column;
915 Drawable d = WMGetPixmapXID(table->viewBuffer);
916
917 for (i = cols.position; i < cols.position + cols.count; i++) {
918 column = WMGetFromArray(table->columns, i);
919
920 if (!column->delegate || !column->delegate->drawCell)
921 continue;
922
923 if (WMFindInArray(table->selectedRows, NULL, (void *)(uintptr_t) row) != WANotFound)
924 (*column->delegate->drawSelectedCell) (column->delegate, column, row, d);
925 else
926 (*column->delegate->drawCell) (column->delegate, column, row, d);
927 }
f912d9f3 kojima2000-12-21 04:46:20 +0000928}
929
33cc542e dan2001-10-04 03:07:34 +0000930#if 0
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200931static void drawFullRow(WMTableView * table, int row)
f912d9f3 kojima2000-12-21 04:46:20 +0000932{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200933 int i;
934 WMTableColumn *column;
935 Drawable d = WMGetPixmapXID(table->viewBuffer);
22ae4f5a kojima2001-05-17 22:30:38 +0000936
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200937 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
938 column = WMGetFromArray(table->columns, i);
f912d9f3 kojima2000-12-21 04:46:20 +0000939
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200940 if (!column->delegate || !column->delegate->drawCell)
941 continue;
22ae4f5a kojima2001-05-17 22:30:38 +0000942
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200943 if (WMFindInArray(table->selectedRows, NULL, (void *)row) != WANotFound)
944 (*column->delegate->drawSelectedCell) (column->delegate, column, row, d);
945 else
946 (*column->delegate->drawCell) (column->delegate, column, row, d);
947 }
f912d9f3 kojima2000-12-21 04:46:20 +0000948}
33cc542e dan2001-10-04 03:07:34 +0000949#endif
f912d9f3 kojima2000-12-21 04:46:20 +0000950
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200951static void setRowSelected(WMTableView * table, unsigned row, Bool flag)
f912d9f3 kojima2000-12-21 04:46:20 +0000952{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200953 int repaint = 0;
954
955 if (WMFindInArray(table->selectedRows, NULL, (void *)(uintptr_t) row) != WANotFound) {
956 if (!flag) {
957 WMRemoveFromArray(table->selectedRows, (void *)(uintptr_t) row);
958 repaint = 1;
959 }
960 } else {
961 if (flag) {
962 WMAddToArray(table->selectedRows, (void *)(uintptr_t) row);
963 repaint = 1;
964 }
965 }
966 if (repaint && row < table->rows) {
967 /*drawFullRow(table, row); */
968 repaintTable(table);
969 }
dc67e814 kojima2000-11-12 03:29:53 +0000970}
971
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200972static void repaintTable(WMTableView * table)
dc67e814 kojima2000-11-12 03:29:53 +0000973{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200974 WMRect rect;
975 WMRange rows;
976 WMScreen *scr = WMWidgetScreen(table);
977 int i;
dc67e814 kojima2000-11-12 03:29:53 +0000978
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200979 if (!table->delegate || !W_VIEW_REALIZED(table->view))
980 return;
dc67e814 kojima2000-11-12 03:29:53 +0000981
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200982 wassertr(table->delegate->numberOfRows);
983
984 if (!table->viewBuffer) {
985 table->viewBuffer = WMCreatePixmap(scr,
986 W_VIEW_WIDTH(table->tableView),
987 W_VIEW_HEIGHT(table->tableView), WMScreenDepth(scr), 0);
988 }
989
990 XFillRectangle(scr->display,
991 WMGetPixmapXID(table->viewBuffer),
992 WMColorGC(table->backColor), 0, 0,
993 W_VIEW_WIDTH(table->tableView), W_VIEW_HEIGHT(table->tableView));
994
995 rect = getVisibleRect(table);
996
997 if (table->drawsGrid) {
998 drawGrid(table, rect);
999 }
4c60cd5b kojima2000-12-21 21:06:00 +00001000
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001001 rows = rowsInRect(table, rect);
1002 for (i = rows.position; i < WMIN(rows.position + rows.count + 1, table->rows); i++) {
1003 drawRow(table, i, rect);
1004 }
f912d9f3 kojima2000-12-21 04:46:20 +00001005
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001006 XSetWindowBackgroundPixmap(scr->display, table->tableView->window, WMGetPixmapXID(table->viewBuffer));
1007 XClearWindow(scr->display, table->tableView->window);
4c60cd5b kojima2000-12-21 21:06:00 +00001008}
1009
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001010static void stopRowEdit(WMTableView * table, int row)
1011{
1012 int i;
1013 WMTableColumn *column;
1014
1015 table->editingRow = -1;
1016 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
1017 column = WMGetFromArray(table->columns, i);
4c60cd5b kojima2000-12-21 21:06:00 +00001018
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001019 if (column->delegate && column->delegate->endCellEdit)
1020 (*column->delegate->endCellEdit) (column->delegate, column, row);
1021 }
1022}
4c60cd5b kojima2000-12-21 21:06:00 +00001023
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001024void WMEditTableViewRow(WMTableView * table, int row)
4c60cd5b kojima2000-12-21 21:06:00 +00001025{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001026 int i;
1027 WMTableColumn *column;
4c60cd5b kojima2000-12-21 21:06:00 +00001028
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001029 if (table->editingRow >= 0) {
1030 stopRowEdit(table, table->editingRow);
1031 }
2cf8c125 kojima2001-01-26 19:30:53 +00001032
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001033 table->editingRow = row;
6830b057 dan2004-10-12 21:28:27 +00001034
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001035 if (row < 0)
1036 return;
6830b057 dan2004-10-12 21:28:27 +00001037
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001038 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
1039 column = WMGetFromArray(table->columns, i);
4c60cd5b kojima2000-12-21 21:06:00 +00001040
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001041 if (column->delegate && column->delegate->beginCellEdit)
1042 (*column->delegate->beginCellEdit) (column->delegate, column, row);
1043 }
f912d9f3 kojima2000-12-21 04:46:20 +00001044}
1045
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001046void WMSelectTableViewRow(WMTableView * table, int row)
e99511b0 kojima2001-01-02 14:17:26 +00001047{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001048 if (table->clickedRow >= 0)
1049 setRowSelected(table, table->clickedRow, False);
6830b057 dan2004-10-12 21:28:27 +00001050
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001051 if (row >= table->rows) {
1052 return;
1053 }
6830b057 dan2004-10-12 21:28:27 +00001054
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001055 setRowSelected(table, row, True);
1056 table->clickedRow = row;
b6f543df kojima2001-01-10 21:10:39 +00001057
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001058 if (table->action)
1059 (*table->action) (table, table->clientData);
1060 WMPostNotificationName(WMTableViewSelectionDidChangeNotification, table, NULL);
e99511b0 kojima2001-01-02 14:17:26 +00001061}
1062
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001063void WMReloadTableView(WMTableView * table)
e99511b0 kojima2001-01-02 14:17:26 +00001064{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001065 if (table->editingRow >= 0)
1066 stopRowEdit(table, table->editingRow);
e99511b0 kojima2001-01-02 14:17:26 +00001067
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001068 /* when this is called, nothing in the table can be assumed to be
1069 * like the last time we accessed it (ie, rows might have disappeared) */
e99511b0 kojima2001-01-02 14:17:26 +00001070
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001071 WMEmptyArray(table->selectedRows);
e99511b0 kojima2001-01-02 14:17:26 +00001072
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001073 if (table->clickedRow >= 0) {
1074 if (table->action)
1075 (*table->action) (table, table->clientData);
1076 WMPostNotificationName(WMTableViewSelectionDidChangeNotification, table, NULL);
1077 table->clickedRow = -1;
1078 }
e99511b0 kojima2001-01-02 14:17:26 +00001079
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001080 if (table->delegate && table->delegate->numberOfRows) {
1081 int rows;
dc67e814 kojima2000-11-12 03:29:53 +00001082
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001083 rows = (*table->delegate->numberOfRows) (table->delegate, table);
dc67e814 kojima2000-11-12 03:29:53 +00001084
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001085 if (rows != table->rows) {
1086 table->rows = rows;
1087 handleResize(table->view->delegate, table->view);
1088 } else {
1089 repaintTable(table);
1090 }
1091 }
dc67e814 kojima2000-11-12 03:29:53 +00001092}
1093
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001094void WMNoteTableViewNumberOfRowsChanged(WMTableView * table)
1095{
1096 WMReloadTableView(table);
1097}
dc67e814 kojima2000-11-12 03:29:53 +00001098
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001099static void handleTableEvents(XEvent * event, void *data)
dc67e814 kojima2000-11-12 03:29:53 +00001100{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001101 WMTableView *table = (WMTableView *) data;
1102 int row;
1103
1104 switch (event->type) {
1105 case ButtonPress:
1106 if (event->xbutton.button == Button1) {
1107 WMRect rect = getVisibleRect(table);
1108
1109 row = (event->xbutton.y + rect.pos.y) / table->rowHeight;
1110 if (row != table->clickedRow) {
1111 setRowSelected(table, table->clickedRow, False);
1112 setRowSelected(table, row, True);
1113 table->clickedRow = row;
1114 table->dragging = 1;
1115 } else {
1116 table->dragging = 1;
1117 }
1118 }
1119 break;
1120
1121 case MotionNotify:
1122 if (table->dragging && event->xmotion.y >= 0) {
1123 WMRect rect = getVisibleRect(table);
1124
1125 row = (event->xmotion.y + rect.pos.y) / table->rowHeight;
1126 if (table->clickedRow != row && row >= 0 && row < table->rows) {
1127 setRowSelected(table, table->clickedRow, False);
1128 setRowSelected(table, row, True);
1129 table->clickedRow = row;
1130 }
1131 }
1132 break;
1133
1134 case ButtonRelease:
1135 if (event->xbutton.button == Button1) {
1136 if (table->action)
1137 (*table->action) (table, table->clientData);
1138 WMPostNotificationName(WMTableViewSelectionDidChangeNotification, table, NULL);
1139 table->dragging = 0;
1140 }
1141 break;
1142 }
18ed0463 kojima2003-03-13 21:36:34 +00001143}
1144
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001145static void handleEvents(XEvent * event, void *data)
1146{
1147 WMTableView *table = (WMTableView *) data;
1148 WMScreen *scr = WMWidgetScreen(table);
1149
1150 switch (event->type) {
1151 case Expose:
1152 W_DrawRelief(scr, W_VIEW_DRAWABLE(table->view), 0, 0,
1153 W_VIEW_WIDTH(table->view), W_VIEW_HEIGHT(table->view), WRSunken);
1154 break;
1155 }
1156}
18ed0463 kojima2003-03-13 21:36:34 +00001157
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001158static void handleResize(W_ViewDelegate * self, WMView * view)
18ed0463 kojima2003-03-13 21:36:34 +00001159{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001160 reorganizeInterior(view->self);
1161}
18ed0463 kojima2003-03-13 21:36:34 +00001162
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001163static void reorganizeInterior(WMTableView * table)
1164{
1165 int width;
1166 int height;
1167 WMSize size = getTotalSize(table);
1168 WMView *view = table->view;
1169 int vw, vh;
1170 int hsThickness, vsThickness;
dc67e814 kojima2000-11-12 03:29:53 +00001171
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001172 if (table->vscroll)
1173 vsThickness = WMWidgetWidth(table->vscroll);
1174 if (table->hscroll)
1175 hsThickness = WMWidgetHeight(table->hscroll);
dc67e814 kojima2000-11-12 03:29:53 +00001176
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001177 width = W_VIEW_WIDTH(view) - 2;
1178 height = W_VIEW_HEIGHT(view) - 3;
6830b057 dan2004-10-12 21:28:27 +00001179
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001180 height -= table->headerHeight; /* table header */
22ae4f5a kojima2001-05-17 22:30:38 +00001181
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001182 if (table->corner)
1183 WMResizeWidget(table->corner, 20, table->headerHeight);
18ed0463 kojima2003-03-13 21:36:34 +00001184
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001185 WMMoveWidget(table->vscroll, 1, table->headerHeight + 1);
1186 WMResizeWidget(table->vscroll, 20, height + 1);
18ed0463 kojima2003-03-13 21:36:34 +00001187
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001188 if (table->hscroll) {
1189 WMMoveWidget(table->hscroll, vsThickness, W_VIEW_HEIGHT(view) - hsThickness - 1);
1190 WMResizeWidget(table->hscroll, width - (vsThickness + 1), hsThickness);
1191 }
6830b057 dan2004-10-12 21:28:27 +00001192
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001193 if (table->header)
1194 WMResizeWidget(table->header, width - (vsThickness + 1), table->headerHeight);
22ae4f5a kojima2001-05-17 22:30:38 +00001195
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001196 if (table->viewBuffer) {
1197 WMReleasePixmap(table->viewBuffer);
1198 table->viewBuffer = NULL;
1199 }
18ed0463 kojima2003-03-13 21:36:34 +00001200
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001201 width -= vsThickness;
1202 height -= hsThickness;
22ae4f5a kojima2001-05-17 22:30:38 +00001203
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001204 vw = WMIN(size.width, width);
1205 vh = WMIN(size.height, height);
22ae4f5a kojima2001-05-17 22:30:38 +00001206
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001207 W_MoveView(table->tableView, vsThickness + 1, 1 + table->headerHeight + 1);
1208 W_ResizeView(table->tableView, WMAX(vw, 1), WMAX(vh, 1) + 1);
6830b057 dan2004-10-12 21:28:27 +00001209
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001210 adjustScrollers(table);
6830b057 dan2004-10-12 21:28:27 +00001211
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001212 repaintTable(table);
dc67e814 kojima2000-11-12 03:29:53 +00001213}
1214
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001215static void rearrangeHeader(WMTableView * table)
e99511b0 kojima2001-01-02 14:17:26 +00001216{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001217 int width;
1218 int count;
1219 int i;
1220 /*WMRect rect = WMGetScrollViewVisibleRect(table->scrollView); */
6830b057 dan2004-10-12 21:28:27 +00001221
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001222 width = 0;
6830b057 dan2004-10-12 21:28:27 +00001223
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001224 count = WMGetArrayItemCount(table->columns);
1225 for (i = 0; i < count; i++) {
1226 WMTableColumn *column = WMGetFromArray(table->columns, i);
1227 WMView *splitter = WMGetFromArray(table->splitters, i);
e99511b0 kojima2001-01-02 14:17:26 +00001228
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001229 WMMoveWidget(column->titleW, width, 0);
1230 WMResizeWidget(column->titleW, column->width - 1, table->headerHeight);
e99511b0 kojima2001-01-02 14:17:26 +00001231
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001232 width += column->width;
1233 W_MoveView(splitter, width - 1, 0);
1234 }
6830b057 dan2004-10-12 21:28:27 +00001235
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001236 wassertr(table->delegate && table->delegate->numberOfRows);
6830b057 dan2004-10-12 21:28:27 +00001237
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001238 table->rows = table->delegate->numberOfRows(table->delegate, table);
e99511b0 kojima2001-01-02 14:17:26 +00001239
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001240 table->tableWidth = width + 1;
6830b057 dan2004-10-12 21:28:27 +00001241
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001242 handleResize(table->view->delegate, table->view);
e99511b0 kojima2001-01-02 14:17:26 +00001243}