- put back wmksize(), wmkrange() and wmkpoint() as functions instead of macros
[wmaker-crm.git] / WINGs / Extras / wtableview.c
blob9792ad48e91dfd321da45ce34fc56eece28a6698
3 #include <WINGs/WINGsP.h>
4 #include <X11/cursorfont.h>
6 #include "wtableview.h"
9 const char *WMTableViewSelectionDidChangeNotification = "WMTableViewSelectionDidChangeNotification";
12 struct W_TableColumn {
13 WMTableView *table;
14 WMWidget *titleW;
15 char *title;
16 int width;
17 int minWidth;
18 int maxWidth;
20 void *id;
22 WMTableColumnDelegate *delegate;
24 unsigned resizable:1;
25 unsigned editable:1;
30 static void handleResize(W_ViewDelegate *self, WMView *view);
32 static void rearrangeHeader(WMTableView *table);
34 static WMRange rowsInRect(WMTableView *table, WMRect rect);
37 WMTableColumn *WMCreateTableColumn(char *title)
39 WMTableColumn *col = wmalloc(sizeof(WMTableColumn));
41 col->table = NULL;
42 col->titleW = NULL;
43 col->width = 50;
44 col->minWidth = 5;
45 col->maxWidth = 0;
47 col->id = NULL;
49 col->title = wstrdup(title);
51 col->delegate = NULL;
53 col->resizable = 1;
54 col->editable = 0;
56 return col;
60 void WMSetTableColumnId(WMTableColumn *column, void *id)
62 column->id = id;
66 void *WMGetTableColumnId(WMTableColumn *column)
68 return column->id;
72 void WMSetTableColumnWidth(WMTableColumn *column, unsigned width)
74 if (column->maxWidth == 0)
75 column->width = WMAX(column->minWidth, width);
76 else
77 column->width = WMAX(column->minWidth, WMIN(column->maxWidth, width));
79 if (column->table) {
80 rearrangeHeader(column->table);
85 void WMSetTableColumnDelegate(WMTableColumn *column,
86 WMTableColumnDelegate *delegate)
88 column->delegate = delegate;
92 void WMSetTableColumnConstraints(WMTableColumn *column,
93 unsigned minWidth, unsigned maxWidth)
95 wassertr(maxWidth == 0 || minWidth <= maxWidth);
97 column->minWidth = minWidth;
98 column->maxWidth = maxWidth;
100 if (column->width < column->minWidth)
101 WMSetTableColumnWidth(column, column->minWidth);
102 else if (column->width > column->maxWidth && column->maxWidth != 0)
103 WMSetTableColumnWidth(column, column->maxWidth);
107 void WMSetTableColumnEditable(WMTableColumn *column, Bool flag)
109 column->editable = flag;
113 WMTableView *WMGetTableColumnTableView(WMTableColumn *column)
115 return column->table;
120 struct W_TableView {
121 W_Class widgetClass;
122 WMView *view;
124 WMFrame *header;
126 WMLabel *corner;
128 WMScrollView *scrollView;
129 WMView *tableView;
131 WMArray *columns;
132 WMArray *splitters;
134 WMArray *selectedRows;
136 int tableWidth;
138 int rows;
140 GC gridGC;
141 WMColor *gridColor;
143 Cursor splitterCursor;
145 void *dataSource;
147 WMTableViewDelegate *delegate;
149 WMAction *action;
150 void *clientData;
152 void *clickedColumn;
153 int clickedRow;
155 int editingRow;
157 unsigned headerHeight;
159 unsigned rowHeight;
161 unsigned dragging:1;
162 unsigned drawsGrid:1;
163 unsigned canSelectRow:1;
164 unsigned canSelectMultiRows:1;
165 unsigned canDeselectRow:1;
168 static W_Class tableClass = 0;
171 static W_ViewDelegate viewDelegate = {
172 NULL,
173 NULL,
174 handleResize,
175 NULL,
176 NULL
183 static void handleEvents(XEvent *event, void *data);
184 static void handleTableEvents(XEvent *event, void *data);
187 static void scrollObserver(void *self, WMNotification *notif)
189 WMTableView *table = (WMTableView*)self;
190 WMRect rect;
191 int i, x;
193 rect = WMGetScrollViewVisibleRect(table->scrollView);
195 x = 0;
196 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
197 WMTableColumn *column;
198 WMView *splitter;
200 column = WMGetFromArray(table->columns, i);
202 WMMoveWidget(column->titleW, x - rect.pos.x, 0);
204 x += W_VIEW_WIDTH(WMWidgetView(column->titleW)) + 1;
206 splitter = WMGetFromArray(table->splitters, i);
207 W_MoveView(splitter, x - rect.pos.x - 1, 0);
212 static void splitterHandler(XEvent *event, void *data)
214 WMTableColumn *column = (WMTableColumn*)data;
215 WMTableView *table = column->table;
216 int done = 0;
217 int cx, ox, offsX;
218 WMPoint pos;
219 WMScreen *scr = WMWidgetScreen(table);
220 GC gc = scr->ixorGC;
221 Display *dpy = WMScreenDisplay(scr);
222 int h = WMWidgetHeight(table) - 22;
223 Window w = WMViewXID(table->view);
225 pos = WMGetViewPosition(WMWidgetView(column->titleW));
227 offsX = pos.x + column->width;
229 ox = cx = offsX;
231 XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h);
233 while (!done) {
234 XEvent ev;
236 WMMaskEvent(dpy, ButtonMotionMask|ButtonReleaseMask, &ev);
238 switch (ev.type) {
239 case MotionNotify:
240 ox = cx;
242 if (column->width + ev.xmotion.x < column->minWidth)
243 cx = pos.x + column->minWidth;
244 else if (column->maxWidth > 0
245 && column->width + ev.xmotion.x > column->maxWidth)
246 cx = pos.x + column->maxWidth;
247 else
248 cx = offsX + ev.xmotion.x;
250 XDrawLine(dpy, w, gc, ox+20, 0, ox+20, h);
251 XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h);
252 break;
254 case ButtonRelease:
255 column->width = cx - pos.x;
256 done = 1;
257 break;
261 XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h);
262 rearrangeHeader(table);
267 WMTableView *WMCreateTableView(WMWidget *parent)
269 WMTableView *table = wmalloc(sizeof(WMTableView));
270 WMScreen *scr = WMWidgetScreen(parent);
272 memset(table, 0, sizeof(WMTableView));
274 if (!tableClass) {
275 tableClass = W_RegisterUserWidget();
277 table->widgetClass = tableClass;
279 table->view = W_CreateView(W_VIEW(parent));
280 if (!table->view)
281 goto error;
282 table->view->self = table;
284 table->view->delegate = &viewDelegate;
286 table->headerHeight = 20;
288 table->scrollView = WMCreateScrollView(table);
289 if (!table->scrollView)
290 goto error;
291 WMResizeWidget(table->scrollView, 10, 10);
292 WMSetScrollViewHasVerticalScroller(table->scrollView, True);
293 WMSetScrollViewHasHorizontalScroller(table->scrollView, True);
295 WMScroller *scroller;
296 scroller = WMGetScrollViewHorizontalScroller(table->scrollView);
297 WMAddNotificationObserver(scrollObserver, table,
298 WMScrollerDidScrollNotification,
299 scroller);
301 WMMoveWidget(table->scrollView, 1, 2+table->headerHeight);
302 WMMapWidget(table->scrollView);
304 table->header = WMCreateFrame(table);
305 WMMoveWidget(table->header, 22, 2);
306 WMMapWidget(table->header);
307 WMSetFrameRelief(table->header, WRFlat);
309 table->corner = WMCreateLabel(table);
310 WMResizeWidget(table->corner, 20, table->headerHeight);
311 WMMoveWidget(table->corner, 2, 2);
312 WMMapWidget(table->corner);
313 WMSetLabelRelief(table->corner, WRRaised);
314 WMSetWidgetBackgroundColor(table->corner, scr->darkGray);
317 table->tableView = W_CreateView(W_VIEW(parent));
318 if (!table->tableView)
319 goto error;
320 table->tableView->self = table;
321 W_ResizeView(table->tableView, 100, 1000);
322 W_MapView(table->tableView);
324 table->tableView->flags.dontCompressExpose = 1;
326 table->gridColor = WMCreateNamedColor(scr, "#cccccc", False);
327 /* table->gridColor = WMGrayColor(scr);*/
330 XGCValues gcv;
332 gcv.foreground = WMColorPixel(table->gridColor);
333 gcv.dashes = 1;
334 gcv.line_style = LineOnOffDash;
335 table->gridGC = XCreateGC(WMScreenDisplay(scr), W_DRAWABLE(scr),
336 GCForeground, &gcv);
339 table->editingRow = -1;
340 table->clickedRow = -1;
342 table->drawsGrid = 1;
343 table->rowHeight = 16;
345 WMSetScrollViewLineScroll(table->scrollView, table->rowHeight);
347 table->tableWidth = 1;
349 table->columns = WMCreateArray(4);
350 table->splitters = WMCreateArray(4);
352 table->selectedRows = WMCreateArray(16);
354 table->splitterCursor = XCreateFontCursor(WMScreenDisplay(scr),
355 XC_sb_h_double_arrow);
357 table->canSelectRow = 1;
359 WMCreateEventHandler(table->view, ExposureMask|StructureNotifyMask,
360 handleEvents, table);
362 WMCreateEventHandler(table->tableView, ExposureMask|ButtonPressMask|
363 ButtonReleaseMask|ButtonMotionMask,
364 handleTableEvents, table);
366 WMSetScrollViewContentView(table->scrollView, table->tableView);
368 return table;
370 error:
371 if (table->scrollView)
372 WMDestroyWidget(table->scrollView);
373 if (table->tableView)
374 W_DestroyView(table->tableView);
375 if (table->view)
376 W_DestroyView(table->view);
377 wfree(table);
378 return NULL;
382 void WMAddTableViewColumn(WMTableView *table, WMTableColumn *column)
384 WMScreen *scr = WMWidgetScreen(table);
386 column->table = table;
388 WMAddToArray(table->columns, column);
390 if (!column->titleW) {
391 column->titleW = WMCreateLabel(table);
392 WMSetLabelRelief(column->titleW, WRRaised);
393 WMSetLabelFont(column->titleW, scr->boldFont);
394 WMSetLabelTextColor(column->titleW, scr->white);
395 WMSetWidgetBackgroundColor(column->titleW, scr->darkGray);
396 WMSetLabelText(column->titleW, column->title);
397 W_ReparentView(WMWidgetView(column->titleW),
398 WMWidgetView(table->header), 0, 0);
399 if (W_VIEW_REALIZED(table->view))
400 WMRealizeWidget(column->titleW);
401 WMMapWidget(column->titleW);
405 WMView *splitter = W_CreateView(WMWidgetView(table->header));
407 W_SetViewBackgroundColor(splitter, WMWhiteColor(scr));
409 if (W_VIEW_REALIZED(table->view))
410 W_RealizeView(splitter);
412 W_ResizeView(splitter, 2, table->headerHeight-1);
413 W_MapView(splitter);
415 W_SetViewCursor(splitter, table->splitterCursor);
416 WMCreateEventHandler(splitter, ButtonPressMask|ButtonReleaseMask,
417 splitterHandler, column);
419 WMAddToArray(table->splitters, splitter);
422 rearrangeHeader(table);
426 void WMSetTableViewHeaderHeight(WMTableView *table, unsigned height)
428 table->headerHeight = height;
430 handleResize(NULL, table->view);
434 void WMSetTableViewDelegate(WMTableView *table, WMTableViewDelegate *delegate)
436 table->delegate = delegate;
440 void WMSetTableViewAction(WMTableView *table, WMAction *action, void *clientData)
442 table->action = action;
444 table->clientData = clientData;
448 void *WMGetTableViewClickedColumn(WMTableView *table)
450 return table->clickedColumn;
454 int WMGetTableViewClickedRow(WMTableView *table)
456 return table->clickedRow;
460 WMArray *WMGetTableViewSelectedRows(WMTableView *table)
462 return table->selectedRows;
466 WMView *WMGetTableViewDocumentView(WMTableView *table)
468 return table->tableView;
472 void *WMTableViewDataForCell(WMTableView *table, WMTableColumn *column,
473 int row)
475 return (*table->delegate->valueForCell)(table->delegate, column, row);
479 void WMSetTableViewDataForCell(WMTableView *table, WMTableColumn *column,
480 int row, void *data)
482 (*table->delegate->setValueForCell)(table->delegate, column, row, data);
486 WMRect WMTableViewRectForCell(WMTableView *table, WMTableColumn *column,
487 int row)
489 WMRect rect;
490 int i;
492 rect.pos.x = 0;
493 rect.pos.y = row * table->rowHeight;
494 rect.size.height = table->rowHeight;
496 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
497 WMTableColumn *col;
498 col = WMGetFromArray(table->columns, i);
500 if (col == column) {
501 rect.size.width = col->width;
502 break;
505 rect.pos.x += col->width;
507 return rect;
511 void WMSetTableViewDataSource(WMTableView *table, void *source)
513 table->dataSource = source;
517 void *WMGetTableViewDataSource(WMTableView *table)
519 return table->dataSource;
523 void WMSetTableViewBackgroundColor(WMTableView *table, WMColor *color)
525 W_SetViewBackgroundColor(table->tableView, color);
529 void WMSetTableViewGridColor(WMTableView *table, WMColor *color)
531 WMReleaseColor(table->gridColor);
532 table->gridColor = WMRetainColor(color);
533 XSetForeground(WMScreenDisplay(WMWidgetScreen(table)), table->gridGC,
534 WMColorPixel(color));
539 void WMSetTableViewRowHeight(WMTableView *table, int height)
541 table->rowHeight = height;
543 WMRedisplayWidget(table);
547 void WMScrollTableViewRowToVisible(WMTableView *table, int row)
549 WMScroller *scroller;
550 WMRange range;
551 WMRect rect;
552 int newY, tmp;
554 rect = WMGetScrollViewVisibleRect(table->scrollView);
555 range = rowsInRect(table, rect);
557 scroller = WMGetScrollViewVerticalScroller(table->scrollView);
559 if (row < range.position) {
560 newY = row * table->rowHeight - rect.size.height / 2;
561 } else if (row >= range.position + range.count) {
562 newY = row * table->rowHeight - rect.size.height / 2;
563 } else {
564 return;
566 tmp = table->rows*table->rowHeight - rect.size.height;
567 newY = WMAX(0, WMIN(newY, tmp));
568 WMScrollViewScrollPoint(table->scrollView, rect.pos.x, newY);
573 static void drawGrid(WMTableView *table, WMRect rect)
575 WMScreen *scr = WMWidgetScreen(table);
576 Display *dpy = WMScreenDisplay(scr);
577 int i;
578 int y1, y2;
579 int x1, x2;
580 int xx;
581 Drawable d = W_VIEW_DRAWABLE(table->tableView);
582 GC gc = table->gridGC;
584 #if 0
585 char dashl[1] = {1};
587 XSetDashes(dpy, gc, 0, dashl, 1);
589 y1 = (rect.pos.y/table->rowHeight - 1)*table->rowHeight;
590 y2 = y1 + (rect.size.height/table->rowHeight+2)*table->rowHeight;
591 #endif
592 y1 = 0;
593 y2 = W_VIEW_HEIGHT(table->tableView);
595 xx = 0;
596 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
597 WMTableColumn *column;
599 if (xx >= rect.pos.x && xx <= rect.pos.x+rect.size.width) {
600 XDrawLine(dpy, d, gc, xx, y1, xx, y2);
602 column = WMGetFromArray(table->columns, i);
603 xx += column->width;
605 XDrawLine(dpy, d, gc, xx, y1, xx, y2);
608 x1 = rect.pos.x;
609 x2 = WMIN(x1 + rect.size.width, xx);
611 if (x2 <= x1)
612 return;
613 #if 0
614 XSetDashes(dpy, gc, (rect.pos.x&1), dashl, 1);
615 #endif
617 y1 = rect.pos.y - rect.pos.y%table->rowHeight;
618 y2 = y1 + rect.size.height + table->rowHeight;
620 for (i = y1; i <= y2; i += table->rowHeight) {
621 XDrawLine(dpy, d, gc, x1, i, x2, i);
626 static WMRange columnsInRect(WMTableView *table, WMRect rect)
628 WMTableColumn *column;
629 int width;
630 int i , j;
631 int totalColumns = WMGetArrayItemCount(table->columns);
632 WMRange range;
634 j = 0;
635 width = 0;
636 for (i = 0; i < totalColumns; i++) {
637 column = WMGetFromArray(table->columns, i);
638 if (j == 0) {
639 if (width <= rect.pos.x && width + column->width > rect.pos.x) {
640 range.position = i;
641 j = 1;
643 } else {
644 range.count++;
645 if (width > rect.pos.x + rect.size.width) {
646 break;
649 width += column->width;
651 range.count = WMAX(1, WMIN(range.count, totalColumns - range.position));
652 return range;
656 static WMRange rowsInRect(WMTableView *table, WMRect rect)
658 WMRange range;
659 int rh = table->rowHeight;
660 int dif;
662 dif = rect.pos.y % rh;
664 range.position = WMAX(0, (rect.pos.y - dif) / rh);
665 range.count = WMAX(1, WMIN((rect.size.height + dif) / rh, table->rows));
667 return range;
671 static void drawRow(WMTableView *table, int row, WMRect clipRect)
673 int i;
674 WMRange cols = columnsInRect(table, clipRect);
675 WMTableColumn *column;
677 for (i = cols.position; i < cols.position+cols.count; i++) {
678 column = WMGetFromArray(table->columns, i);
680 wassertr(column->delegate && column->delegate->drawCell);
682 if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound)
683 (*column->delegate->drawSelectedCell)(column->delegate, column, row);
684 else
685 (*column->delegate->drawCell)(column->delegate, column, row);
690 static void drawFullRow(WMTableView *table, int row)
692 int i;
693 WMTableColumn *column;
695 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
696 column = WMGetFromArray(table->columns, i);
698 wassertr(column->delegate && column->delegate->drawCell);
700 if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound)
701 (*column->delegate->drawSelectedCell)(column->delegate, column, row);
702 else
703 (*column->delegate->drawCell)(column->delegate, column, row);
708 static void setRowSelected(WMTableView *table, unsigned row, Bool flag)
710 int repaint = 0;
712 if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound) {
713 if (!flag) {
714 WMRemoveFromArray(table->selectedRows, (void*)row);
715 repaint = 1;
717 } else {
718 if (flag) {
719 WMAddToArray(table->selectedRows, (void*)row);
720 repaint = 1;
723 if (repaint && row < table->rows) {
724 drawFullRow(table, row);
729 static void repaintTable(WMTableView *table, int x, int y,
730 int width, int height)
732 WMRect rect;
733 WMRange rows;
734 int i;
736 wassertr(table->delegate && table->delegate->numberOfRows);
737 i = (*table->delegate->numberOfRows)(table->delegate, table);
739 if (i != table->rows) {
740 table->rows = i;
741 W_ResizeView(table->tableView, table->tableWidth,
742 table->rows * table->rowHeight + 1);
746 if (x >= table->tableWidth-1)
747 return;
749 rect.pos = wmkpoint(x,y);
750 rect.size = wmksize(width, height);
752 if (table->drawsGrid) {
753 drawGrid(table, rect);
756 rows = rowsInRect(table, rect);
757 for (i = rows.position;
758 i < WMIN(rows.position+rows.count + 1, table->rows);
759 i++) {
760 drawRow(table, i, rect);
765 static void stopRowEdit(WMTableView *table, int row)
767 int i;
768 WMTableColumn *column;
770 table->editingRow = -1;
771 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
772 column = WMGetFromArray(table->columns, i);
774 if (column->delegate && column->delegate->endCellEdit)
775 (*column->delegate->endCellEdit)(column->delegate, column, row);
781 void WMEditTableViewRow(WMTableView *table, int row)
783 int i;
784 WMTableColumn *column;
786 if (table->editingRow >= 0) {
787 stopRowEdit(table, table->editingRow);
790 table->editingRow = row;
792 if (row < 0)
793 return;
795 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
796 column = WMGetFromArray(table->columns, i);
798 if (column->delegate && column->delegate->beginCellEdit)
799 (*column->delegate->beginCellEdit)(column->delegate, column, row);
804 void WMSelectTableViewRow(WMTableView *table, int row)
806 if (table->clickedRow >= 0)
807 setRowSelected(table, table->clickedRow, False);
809 if (row >= table->rows) {
810 return;
813 setRowSelected(table, row, True);
814 table->clickedRow = row;
816 if (table->action)
817 (*table->action)(table, table->clientData);
818 WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
819 table, NULL);
823 void WMReloadTableView(WMTableView *table)
825 WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);
827 if (table->editingRow >= 0)
828 stopRowEdit(table, table->editingRow);
830 /* when this is called, nothing in the table can be assumed to be
831 * like the last time we accessed it (ie, rows might have disappeared) */
833 WMEmptyArray(table->selectedRows);
835 if (table->clickedRow >= 0) {
836 table->clickedRow = -1;
838 if (table->action)
839 (*table->action)(table, table->clientData);
840 WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
841 table, NULL);
844 repaintTable(table, 0, 0,
845 W_VIEW_WIDTH(table->tableView), rect.size.height);
849 void WMNoteTableViewNumberOfRowsChanged(WMTableView *table)
851 WMReloadTableView(table);
855 static void handleTableEvents(XEvent *event, void *data)
857 WMTableView *table = (WMTableView*)data;
858 int row;
860 switch (event->type) {
861 case ButtonPress:
862 if (event->xbutton.button == Button1) {
863 row = event->xbutton.y/table->rowHeight;
864 if (row != table->clickedRow) {
865 setRowSelected(table, table->clickedRow, False);
866 setRowSelected(table, row, True);
867 table->clickedRow = row;
868 table->dragging = 1;
871 break;
873 case MotionNotify:
874 if (table->dragging && event->xmotion.y >= 0) {
875 row = event->xmotion.y/table->rowHeight;
876 if (table->clickedRow != row && row >= 0 && row < table->rows) {
877 setRowSelected(table, table->clickedRow, False);
878 setRowSelected(table, row, True);
879 table->clickedRow = row;
882 break;
884 case ButtonRelease:
885 if (event->xbutton.button == Button1) {
886 if (table->action)
887 (*table->action)(table, table->clientData);
888 WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
889 table, NULL);
890 table->dragging = 0;
892 break;
894 case Expose:
895 repaintTable(table, event->xexpose.x, event->xexpose.y,
896 event->xexpose.width, event->xexpose.height);
897 break;
902 static void handleEvents(XEvent *event, void *data)
904 WMTableView *table = (WMTableView*)data;
905 WMScreen *scr = WMWidgetScreen(table);
907 switch (event->type) {
908 case Expose:
909 W_DrawRelief(scr, W_VIEW_DRAWABLE(table->view), 0, 0,
910 W_VIEW_WIDTH(table->view), W_VIEW_HEIGHT(table->view),
911 WRSunken);
913 if (event->xexpose.serial == 0) {
914 WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);
916 repaintTable(table, rect.pos.x, rect.pos.y,
917 rect.size.width, rect.size.height);
919 break;
924 static void handleResize(W_ViewDelegate *self, WMView *view)
926 int width;
927 int height;
928 WMTableView *table = view->self;
930 width = W_VIEW_WIDTH(view) - 2;
931 height = W_VIEW_HEIGHT(view) - 3;
933 height -= table->headerHeight; /* table header */
935 if (table->corner)
936 WMResizeWidget(table->corner, 20, table->headerHeight);
938 if (table->scrollView) {
939 WMMoveWidget(table->scrollView, 1, table->headerHeight + 2);
940 WMResizeWidget(table->scrollView, width, height);
942 if (table->header)
943 WMResizeWidget(table->header, width - 21, table->headerHeight);
947 static void rearrangeHeader(WMTableView *table)
949 int width;
950 int count;
951 int i;
952 /*WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);*/
954 width = 0;
956 count = WMGetArrayItemCount(table->columns);
957 for (i = 0; i < count; i++) {
958 WMTableColumn *column = WMGetFromArray(table->columns, i);
959 WMView *splitter = WMGetFromArray(table->splitters, i);
961 WMMoveWidget(column->titleW, width, 0);
962 WMResizeWidget(column->titleW, column->width-1, table->headerHeight);
964 width += column->width;
965 W_MoveView(splitter, width-1, 0);
968 wassertr(table->delegate && table->delegate->numberOfRows);
970 table->rows = table->delegate->numberOfRows(table->delegate, table);
972 W_ResizeView(table->tableView, width+1,
973 table->rows * table->rowHeight + 1);
975 table->tableWidth = width + 1;