fixed scroller bug when displaying scroller before
[wmaker-crm.git] / WINGs / Extras / wtableview.c
blob398ac8f68afc17c7929e2f966cf1f49380938125
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 int width;
385 int i;
386 WMScreen *scr = WMWidgetScreen(table);
387 int count;
389 column->table = table;
391 WMAddToArray(table->columns, column);
393 if (!column->titleW) {
394 column->titleW = WMCreateLabel(table);
395 WMSetLabelRelief(column->titleW, WRRaised);
396 WMSetLabelFont(column->titleW, scr->boldFont);
397 WMSetLabelTextColor(column->titleW, scr->white);
398 WMSetWidgetBackgroundColor(column->titleW, scr->darkGray);
399 WMSetLabelText(column->titleW, column->title);
400 W_ReparentView(WMWidgetView(column->titleW),
401 WMWidgetView(table->header), 0, 0);
402 if (W_VIEW_REALIZED(table->view))
403 WMRealizeWidget(column->titleW);
404 WMMapWidget(column->titleW);
408 WMView *splitter = W_CreateView(WMWidgetView(table->header));
410 W_SetViewBackgroundColor(splitter, WMWhiteColor(scr));
412 if (W_VIEW_REALIZED(table->view))
413 W_RealizeView(splitter);
415 W_ResizeView(splitter, 2, table->headerHeight-1);
416 W_MapView(splitter);
418 W_SetViewCursor(splitter, table->splitterCursor);
419 WMCreateEventHandler(splitter, ButtonPressMask|ButtonReleaseMask,
420 splitterHandler, column);
422 WMAddToArray(table->splitters, splitter);
425 rearrangeHeader(table);
429 void WMSetTableViewHeaderHeight(WMTableView *table, unsigned height)
431 table->headerHeight = height;
433 handleResize(NULL, table->view);
437 void WMSetTableViewDelegate(WMTableView *table, WMTableViewDelegate *delegate)
439 table->delegate = delegate;
443 void WMSetTableViewAction(WMTableView *table, WMAction *action, void *clientData)
445 table->action = action;
447 table->clientData = clientData;
451 void *WMGetTableViewClickedColumn(WMTableView *table)
453 return table->clickedColumn;
457 int WMGetTableViewClickedRow(WMTableView *table)
459 return table->clickedRow;
463 WMArray *WMGetTableViewSelectedRows(WMTableView *table)
465 return table->selectedRows;
469 WMView *WMGetTableViewDocumentView(WMTableView *table)
471 return table->tableView;
475 void *WMTableViewDataForCell(WMTableView *table, WMTableColumn *column,
476 int row)
478 return (*table->delegate->valueForCell)(table->delegate, column, row);
482 void WMSetTableViewDataForCell(WMTableView *table, WMTableColumn *column,
483 int row, void *data)
485 (*table->delegate->setValueForCell)(table->delegate, column, row, data);
489 WMRect WMTableViewRectForCell(WMTableView *table, WMTableColumn *column,
490 int row)
492 WMRect rect;
493 int i;
495 rect.pos.x = 0;
496 rect.pos.y = row * table->rowHeight;
497 rect.size.height = table->rowHeight;
499 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
500 WMTableColumn *col;
501 col = WMGetFromArray(table->columns, i);
503 if (col == column) {
504 rect.size.width = col->width;
505 break;
508 rect.pos.x += col->width;
510 return rect;
514 void WMSetTableViewDataSource(WMTableView *table, void *source)
516 table->dataSource = source;
520 void *WMGetTableViewDataSource(WMTableView *table)
522 return table->dataSource;
526 void WMSetTableViewBackgroundColor(WMTableView *table, WMColor *color)
528 W_SetViewBackgroundColor(table->tableView, color);
532 void WMSetTableViewGridColor(WMTableView *table, WMColor *color)
534 WMReleaseColor(table->gridColor);
535 table->gridColor = WMRetainColor(color);
536 XSetForeground(WMScreenDisplay(WMWidgetScreen(table)), table->gridGC,
537 WMColorPixel(color));
542 void WMSetTableViewRowHeight(WMTableView *table, int height)
544 table->rowHeight = height;
546 WMRedisplayWidget(table);
550 void WMScrollTableViewRowToVisible(WMTableView *table, int row)
552 WMScroller *scroller;
553 WMRange range;
554 WMRect rect;
555 int newY, tmp;
557 rect = WMGetScrollViewVisibleRect(table->scrollView);
558 range = rowsInRect(table, rect);
560 scroller = WMGetScrollViewVerticalScroller(table->scrollView);
562 if (row < range.position) {
563 newY = row * table->rowHeight - rect.size.height / 2;
564 } else if (row >= range.position + range.count) {
565 newY = row * table->rowHeight - rect.size.height / 2;
566 } else {
567 return;
569 tmp = table->rows*table->rowHeight - rect.size.height;
570 newY = WMAX(0, WMIN(newY, tmp));
571 WMScrollViewScrollPoint(table->scrollView, rect.pos.x, newY);
576 static void drawGrid(WMTableView *table, WMRect rect)
578 WMScreen *scr = WMWidgetScreen(table);
579 Display *dpy = WMScreenDisplay(scr);
580 int i;
581 int y1, y2;
582 int x1, x2;
583 int xx;
584 Drawable d = W_VIEW_DRAWABLE(table->tableView);
585 GC gc = table->gridGC;
587 #if 0
588 char dashl[1] = {1};
590 XSetDashes(dpy, gc, 0, dashl, 1);
592 y1 = (rect.pos.y/table->rowHeight - 1)*table->rowHeight;
593 y2 = y1 + (rect.size.height/table->rowHeight+2)*table->rowHeight;
594 #endif
595 y1 = 0;
596 y2 = W_VIEW_HEIGHT(table->tableView);
598 xx = 0;
599 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
600 WMTableColumn *column;
602 if (xx >= rect.pos.x && xx <= rect.pos.x+rect.size.width) {
603 XDrawLine(dpy, d, gc, xx, y1, xx, y2);
605 column = WMGetFromArray(table->columns, i);
606 xx += column->width;
608 XDrawLine(dpy, d, gc, xx, y1, xx, y2);
611 x1 = rect.pos.x;
612 x2 = WMIN(x1 + rect.size.width, xx);
614 if (x2 <= x1)
615 return;
616 #if 0
617 XSetDashes(dpy, gc, (rect.pos.x&1), dashl, 1);
618 #endif
620 y1 = rect.pos.y - rect.pos.y%table->rowHeight;
621 y2 = y1 + rect.size.height + table->rowHeight;
623 for (i = y1; i <= y2; i += table->rowHeight) {
624 XDrawLine(dpy, d, gc, x1, i, x2, i);
629 static WMRange columnsInRect(WMTableView *table, WMRect rect)
631 WMTableColumn *column;
632 int width;
633 int i , j;
634 int totalColumns = WMGetArrayItemCount(table->columns);
635 WMRange range;
637 j = 0;
638 width = 0;
639 for (i = 0; i < totalColumns; i++) {
640 column = WMGetFromArray(table->columns, i);
641 if (j == 0) {
642 if (width <= rect.pos.x && width + column->width > rect.pos.x) {
643 range.position = i;
644 j = 1;
646 } else {
647 range.count++;
648 if (width > rect.pos.x + rect.size.width) {
649 break;
652 width += column->width;
654 range.count = WMAX(1, WMIN(range.count, totalColumns - range.position));
655 return range;
659 static WMRange rowsInRect(WMTableView *table, WMRect rect)
661 WMRange range;
662 int rh = table->rowHeight;
663 int dif;
665 dif = rect.pos.y % rh;
667 range.position = WMAX(0, (rect.pos.y - dif) / rh);
668 range.count = WMAX(1, WMIN((rect.size.height + dif) / rh, table->rows));
670 return range;
674 static void drawRow(WMTableView *table, int row, WMRect clipRect)
676 int i;
677 WMRange cols = columnsInRect(table, clipRect);
678 WMTableColumn *column;
680 for (i = cols.position; i < cols.position+cols.count; i++) {
681 column = WMGetFromArray(table->columns, i);
683 wassertr(column->delegate && column->delegate->drawCell);
685 if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound)
686 (*column->delegate->drawSelectedCell)(column->delegate, column, row);
687 else
688 (*column->delegate->drawCell)(column->delegate, column, row);
693 static void drawFullRow(WMTableView *table, int row)
695 int i;
696 WMTableColumn *column;
698 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
699 column = WMGetFromArray(table->columns, i);
701 wassertr(column->delegate && column->delegate->drawCell);
703 if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound)
704 (*column->delegate->drawSelectedCell)(column->delegate, column, row);
705 else
706 (*column->delegate->drawCell)(column->delegate, column, row);
711 static void setRowSelected(WMTableView *table, unsigned row, Bool flag)
713 int repaint = 0;
715 if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound) {
716 if (!flag) {
717 WMRemoveFromArray(table->selectedRows, (void*)row);
718 repaint = 1;
720 } else {
721 if (flag) {
722 WMAddToArray(table->selectedRows, (void*)row);
723 repaint = 1;
726 if (repaint && row < table->rows) {
727 drawFullRow(table, row);
732 static void repaintTable(WMTableView *table, int x, int y,
733 int width, int height)
735 WMRect rect;
736 WMRange rows;
737 int i;
739 wassertr(table->delegate && table->delegate->numberOfRows);
740 i = (*table->delegate->numberOfRows)(table->delegate, table);
742 if (i != table->rows) {
743 table->rows = i;
744 W_ResizeView(table->tableView, table->tableWidth,
745 table->rows * table->rowHeight + 1);
749 if (x >= table->tableWidth-1)
750 return;
752 rect.pos = wmkpoint(x,y);
753 rect.size = wmksize(width, height);
755 if (table->drawsGrid) {
756 drawGrid(table, rect);
759 rows = rowsInRect(table, rect);
760 for (i = rows.position;
761 i < WMIN(rows.position+rows.count + 1, table->rows);
762 i++) {
763 drawRow(table, i, rect);
768 static void stopRowEdit(WMTableView *table, int row)
770 int i;
771 WMTableColumn *column;
773 table->editingRow = -1;
774 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
775 column = WMGetFromArray(table->columns, i);
777 if (column->delegate && column->delegate->endCellEdit)
778 (*column->delegate->endCellEdit)(column->delegate, column, row);
784 void WMEditTableViewRow(WMTableView *table, int row)
786 int i;
787 WMTableColumn *column;
789 if (table->editingRow >= 0) {
790 stopRowEdit(table, table->editingRow);
793 table->editingRow = row;
795 if (row < 0)
796 return;
798 for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
799 column = WMGetFromArray(table->columns, i);
801 if (column->delegate && column->delegate->beginCellEdit)
802 (*column->delegate->beginCellEdit)(column->delegate, column, row);
807 void WMSelectTableViewRow(WMTableView *table, int row)
809 if (table->clickedRow >= 0)
810 setRowSelected(table, table->clickedRow, False);
812 if (row >= table->rows) {
813 return;
816 setRowSelected(table, row, True);
817 table->clickedRow = row;
819 if (table->action)
820 (*table->action)(table, table->clientData);
821 WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
822 table, NULL);
826 void WMReloadTableView(WMTableView *table)
828 WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);
830 if (table->editingRow >= 0)
831 stopRowEdit(table, table->editingRow);
833 /* when this is called, nothing in the table can be assumed to be
834 * like the last time we accessed it (ie, rows might have disappeared) */
836 WMEmptyArray(table->selectedRows);
838 if (table->clickedRow >= 0) {
839 table->clickedRow = -1;
841 if (table->action)
842 (*table->action)(table, table->clientData);
843 WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
844 table, NULL);
847 repaintTable(table, 0, 0,
848 W_VIEW_WIDTH(table->tableView), rect.size.height);
852 void WMNoteTableViewNumberOfRowsChanged(WMTableView *table)
854 WMReloadTableView(table);
858 static void handleTableEvents(XEvent *event, void *data)
860 WMTableView *table = (WMTableView*)data;
861 int row;
863 switch (event->type) {
864 case ButtonPress:
865 if (event->xbutton.button == Button1) {
866 row = event->xbutton.y/table->rowHeight;
867 if (row != table->clickedRow) {
868 setRowSelected(table, table->clickedRow, False);
869 setRowSelected(table, row, True);
870 table->clickedRow = row;
871 table->dragging = 1;
874 break;
876 case MotionNotify:
877 if (table->dragging && event->xmotion.y >= 0) {
878 row = event->xmotion.y/table->rowHeight;
879 if (table->clickedRow != row && row >= 0 && row < table->rows) {
880 setRowSelected(table, table->clickedRow, False);
881 setRowSelected(table, row, True);
882 table->clickedRow = row;
885 break;
887 case ButtonRelease:
888 if (event->xbutton.button == Button1) {
889 if (table->action)
890 (*table->action)(table, table->clientData);
891 WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
892 table, NULL);
893 table->dragging = 0;
895 break;
897 case Expose:
898 repaintTable(table, event->xexpose.x, event->xexpose.y,
899 event->xexpose.width, event->xexpose.height);
900 break;
905 static void handleEvents(XEvent *event, void *data)
907 WMTableView *table = (WMTableView*)data;
908 WMScreen *scr = WMWidgetScreen(table);
910 switch (event->type) {
911 case Expose:
912 W_DrawRelief(scr, W_VIEW_DRAWABLE(table->view), 0, 0,
913 W_VIEW_WIDTH(table->view), W_VIEW_HEIGHT(table->view),
914 WRSunken);
916 if (event->xexpose.serial == 0) {
917 WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);
919 repaintTable(table, rect.pos.x, rect.pos.y,
920 rect.size.width, rect.size.height);
922 break;
927 static void handleResize(W_ViewDelegate *self, WMView *view)
929 int width;
930 int height;
931 WMTableView *table = view->self;
933 width = W_VIEW_WIDTH(view) - 2;
934 height = W_VIEW_HEIGHT(view) - 3;
936 height -= table->headerHeight; /* table header */
938 if (table->corner)
939 WMResizeWidget(table->corner, 20, table->headerHeight);
941 if (table->scrollView) {
942 WMMoveWidget(table->scrollView, 1, table->headerHeight + 2);
943 WMResizeWidget(table->scrollView, width, height);
945 if (table->header)
946 WMResizeWidget(table->header, width - 21, table->headerHeight);
950 static void rearrangeHeader(WMTableView *table)
952 int width;
953 int count;
954 int i;
955 WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);
957 width = 0;
959 count = WMGetArrayItemCount(table->columns);
960 for (i = 0; i < count; i++) {
961 WMTableColumn *column = WMGetFromArray(table->columns, i);
962 WMView *splitter = WMGetFromArray(table->splitters, i);
964 WMMoveWidget(column->titleW, width, 0);
965 WMResizeWidget(column->titleW, column->width-1, table->headerHeight);
967 width += column->width;
968 W_MoveView(splitter, width-1, 0);
971 wassertr(table->delegate && table->delegate->numberOfRows);
973 table->rows = table->delegate->numberOfRows(table->delegate, table);
975 W_ResizeView(table->tableView, width+1,
976 table->rows * table->rowHeight + 1);
978 table->tableWidth = width + 1;