Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / Extras / wtabledelegates.c
Commit [+]AuthorDateLineData
dc67e814 kojima2000-11-12 03:29:53 +00001
06f59b99 Carlos R. Mafra2008-11-06 01:37:44 +01002#include <stdint.h>
33cc542e dan2001-10-04 03:07:34 +00003#include <WINGs/WINGsP.h>
dc67e814 kojima2000-11-12 03:29:53 +00004
dc67e814 kojima2000-11-12 03:29:53 +00005#include "wtableview.h"
6
c6c09547 kojima2001-01-06 17:20:46 +00007#include "wtabledelegates.h"
dc67e814 kojima2000-11-12 03:29:53 +00008
f912d9f3 kojima2000-12-21 04:46:20 +00009typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020010 WMTableView *table;
11 WMFont *font;
12 GC gc;
13 GC selGC;
14 WMColor *textColor;
4c60cd5b kojima2000-12-21 21:06:00 +000015} StringData;
16
4c60cd5b kojima2000-12-21 21:06:00 +000017typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020018 WMTableView *table;
19 GC selGc;
e99511b0 kojima2001-01-02 14:17:26 +000020} PixmapData;
21
e99511b0 kojima2001-01-02 14:17:26 +000022typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020023 WMTextField *widget;
24 WMTableView *table;
25 WMFont *font;
26 GC gc;
27 GC selGC;
28 WMColor *textColor;
f912d9f3 kojima2000-12-21 04:46:20 +000029} StringEditorData;
30
4c60cd5b kojima2000-12-21 21:06:00 +000031typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020032 WMPopUpButton *widget;
33 WMTableView *table;
34 WMFont *font;
35 char **options;
36 int count;
37 GC gc;
38 GC selGC;
39 WMColor *textColor;
4c60cd5b kojima2000-12-21 21:06:00 +000040} EnumSelectorData;
41
e99511b0 kojima2001-01-02 14:17:26 +000042typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020043 WMButton *widget;
44 WMTableView *table;
45 Bool state;
46 GC gc;
47 GC selGC;
e99511b0 kojima2001-01-02 14:17:26 +000048} BooleanSwitchData;
49
e99511b0 kojima2001-01-02 14:17:26 +000050static char *SelectionColor = "#bbbbcc";
51
6830b057 dan2004-10-12 21:28:27 +000052static void
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020053stringDraw(WMScreen * scr, Drawable d, GC gc, GC sgc, WMColor * textColor,
54 WMFont * font, void *data, WMRect rect, Bool selected)
f912d9f3 kojima2000-12-21 04:46:20 +000055{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020056 int x, y;
57 XRectangle rects[1];
58 Display *dpy = WMScreenDisplay(scr);
f912d9f3 kojima2000-12-21 04:46:20 +000059
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020060 x = rect.pos.x + 5;
61 y = rect.pos.y + (rect.size.height - WMFontHeight(font)) / 2;
f912d9f3 kojima2000-12-21 04:46:20 +000062
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020063 rects[0].x = rect.pos.x + 1;
64 rects[0].y = rect.pos.y + 1;
65 rects[0].width = rect.size.width - 1;
66 rects[0].height = rect.size.height - 1;
67 XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
6830b057 dan2004-10-12 21:28:27 +000068
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020069 if (!selected) {
70 XFillRectangles(dpy, d, gc, rects, 1);
a2b404b5 dan2002-10-08 08:26:06 +000071
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020072 WMDrawString(scr, d, textColor, font, x, y, data, strlen(data));
73 } else {
74 XFillRectangles(dpy, d, sgc, rects, 1);
a2b404b5 dan2002-10-08 08:26:06 +000075
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020076 WMDrawString(scr, d, textColor, font, x, y, data, strlen(data));
77 }
6830b057 dan2004-10-12 21:28:27 +000078
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020079 XSetClipMask(dpy, gc, None);
f912d9f3 kojima2000-12-21 04:46:20 +000080}
81
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020082static void pixmapDraw(WMScreen * scr, Drawable d, GC gc, GC sgc, WMPixmap * pixmap, WMRect rect, Bool selected)
e99511b0 kojima2001-01-02 14:17:26 +000083{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020084 int x, y;
85 XRectangle rects[1];
86 Display *dpy = WMScreenDisplay(scr);
87 WMSize size;
88
89 rects[0].x = rect.pos.x + 1;
90 rects[0].y = rect.pos.y + 1;
91 rects[0].width = rect.size.width - 1;
92 rects[0].height = rect.size.height - 1;
93 XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
94
95 if (!selected) {
96 XFillRectangles(dpy, d, gc, rects, 1);
97
98 if (pixmap) {
99 size = WMGetPixmapSize(pixmap);
100 x = rect.pos.x + (rect.size.width - size.width) / 2;
101 y = rect.pos.y + (rect.size.height - size.height) / 2;
102
103 WMDrawPixmap(pixmap, d, x, y);
104 }
105 } else {
106 XFillRectangles(dpy, d, sgc, rects, 1);
107
108 if (pixmap) {
109 size = WMGetPixmapSize(pixmap);
110 x = rect.pos.x + (rect.size.width - size.width) / 2;
111 y = rect.pos.y + (rect.size.height - size.height) / 2;
112
113 WMDrawPixmap(pixmap, d, x, y);
114 }
115 }
116
117 XSetClipMask(dpy, gc, None);
e99511b0 kojima2001-01-02 14:17:26 +0000118}
119
e99511b0 kojima2001-01-02 14:17:26 +0000120/* ---------------------------------------------------------------------- */
dc67e814 kojima2000-11-12 03:29:53 +0000121
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200122static void SECellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
dc67e814 kojima2000-11-12 03:29:53 +0000123{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200124 StringEditorData *strdata = (StringEditorData *) self->data;
125 WMTableView *table = WMGetTableColumnTableView(column);
f912d9f3 kojima2000-12-21 04:46:20 +0000126
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200127 stringDraw(WMWidgetScreen(table), d,
128 strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
129 WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), False);
130}
f912d9f3 kojima2000-12-21 04:46:20 +0000131
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200132static void selectedSECellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
f912d9f3 kojima2000-12-21 04:46:20 +0000133{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200134 StringEditorData *strdata = (StringEditorData *) self->data;
135 WMTableView *table = WMGetTableColumnTableView(column);
f912d9f3 kojima2000-12-21 04:46:20 +0000136
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200137 stringDraw(WMWidgetScreen(table), d,
138 strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
139 WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), True);
140}
f912d9f3 kojima2000-12-21 04:46:20 +0000141
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200142static void beginSECellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
f912d9f3 kojima2000-12-21 04:46:20 +0000143{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200144 StringEditorData *strdata = (StringEditorData *) self->data;
145 WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
146 void *data = WMTableViewDataForCell(strdata->table, column, row);
f912d9f3 kojima2000-12-21 04:46:20 +0000147
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200148 WMSetTextFieldText(strdata->widget, (char *)data);
149 WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
150 WMResizeWidget(strdata->widget, rect.size.width + 1, rect.size.height + 1);
f912d9f3 kojima2000-12-21 04:46:20 +0000151
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200152 WMMapWidget(strdata->widget);
dc67e814 kojima2000-11-12 03:29:53 +0000153}
154
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200155static void endSECellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
4c60cd5b kojima2000-12-21 21:06:00 +0000156{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200157 StringEditorData *strdata = (StringEditorData *) self->data;
158 char *text;
e99511b0 kojima2001-01-02 14:17:26 +0000159
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200160 WMUnmapWidget(strdata->widget);
6830b057 dan2004-10-12 21:28:27 +0000161
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200162 text = WMGetTextFieldText(strdata->widget);
163 WMSetTableViewDataForCell(strdata->table, column, row, (void *)text);
4c60cd5b kojima2000-12-21 21:06:00 +0000164}
dc67e814 kojima2000-11-12 03:29:53 +0000165
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200166WMTableColumnDelegate *WTCreateStringEditorDelegate(WMTableView * parent)
dc67e814 kojima2000-11-12 03:29:53 +0000167{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200168 WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
169 WMScreen *scr = WMWidgetScreen(parent);
170 StringEditorData *data = wmalloc(sizeof(StringEditorData));
171
172 data->widget = WMCreateTextField(parent);
173 W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
174 data->table = parent;
175 data->font = WMSystemFontOfSize(scr, 12);
176 data->gc = WMColorGC(WMWhiteColor(scr));
177 data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
178 data->textColor = WMBlackColor(scr);
179
180 delegate->data = data;
181 delegate->drawCell = SECellPainter;
182 delegate->drawSelectedCell = selectedSECellPainter;
183 delegate->beginCellEdit = beginSECellEdit;
184 delegate->endCellEdit = endSECellEdit;
185
186 return delegate;
4c60cd5b kojima2000-12-21 21:06:00 +0000187}
188
4c60cd5b kojima2000-12-21 21:06:00 +0000189/* ---------------------------------------------------------------------- */
190
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200191static void ESCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
4c60cd5b kojima2000-12-21 21:06:00 +0000192{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200193 EnumSelectorData *strdata = (EnumSelectorData *) self->data;
194 WMTableView *table = WMGetTableColumnTableView(column);
195 int i = (int)(uintptr_t) WMTableViewDataForCell(table, column, row);
4c60cd5b kojima2000-12-21 21:06:00 +0000196
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200197 stringDraw(WMWidgetScreen(table), d,
198 strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
199 strdata->options[i], WMTableViewRectForCell(table, column, row), False);
200}
4c60cd5b kojima2000-12-21 21:06:00 +0000201
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200202static void selectedESCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
4c60cd5b kojima2000-12-21 21:06:00 +0000203{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200204 EnumSelectorData *strdata = (EnumSelectorData *) self->data;
205 WMTableView *table = WMGetTableColumnTableView(column);
206 int i = (int)(uintptr_t) WMTableViewDataForCell(table, column, row);
4c60cd5b kojima2000-12-21 21:06:00 +0000207
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200208 stringDraw(WMWidgetScreen(table), d,
209 strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
210 strdata->options[i], WMTableViewRectForCell(table, column, row), True);
211}
4c60cd5b kojima2000-12-21 21:06:00 +0000212
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200213static void beginESCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
4c60cd5b kojima2000-12-21 21:06:00 +0000214{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200215 EnumSelectorData *strdata = (EnumSelectorData *) self->data;
216 WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
217 int data = (int)(uintptr_t) WMTableViewDataForCell(strdata->table, column, row);
4c60cd5b kojima2000-12-21 21:06:00 +0000218
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200219 wassertr(data < strdata->count);
6830b057 dan2004-10-12 21:28:27 +0000220
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200221 WMSetPopUpButtonSelectedItem(strdata->widget, data);
6830b057 dan2004-10-12 21:28:27 +0000222
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200223 WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
224 WMResizeWidget(strdata->widget, rect.size.width, rect.size.height + 1);
4c60cd5b kojima2000-12-21 21:06:00 +0000225
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200226 WMMapWidget(strdata->widget);
4c60cd5b kojima2000-12-21 21:06:00 +0000227}
228
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200229static void endESCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
4c60cd5b kojima2000-12-21 21:06:00 +0000230{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200231 EnumSelectorData *strdata = (EnumSelectorData *) self->data;
232 int option;
e99511b0 kojima2001-01-02 14:17:26 +0000233
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200234 WMUnmapWidget(strdata->widget);
6830b057 dan2004-10-12 21:28:27 +0000235
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200236 option = WMGetPopUpButtonSelectedItem(strdata->widget);
237 WMSetTableViewDataForCell(strdata->table, column, row, (void *)(uintptr_t) option);
4c60cd5b kojima2000-12-21 21:06:00 +0000238}
239
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200240WMTableColumnDelegate *WTCreateEnumSelectorDelegate(WMTableView * parent)
4c60cd5b kojima2000-12-21 21:06:00 +0000241{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200242 WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
243 WMScreen *scr = WMWidgetScreen(parent);
244 EnumSelectorData *data = wmalloc(sizeof(EnumSelectorData));
245
246 data->widget = WMCreatePopUpButton(parent);
247 W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
248 data->table = parent;
249 data->font = WMSystemFontOfSize(scr, 12);
250 data->gc = WMColorGC(WMWhiteColor(scr));
251 data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
252 data->textColor = WMBlackColor(scr);
253 data->count = 0;
254 data->options = NULL;
255
256 delegate->data = data;
257 delegate->drawCell = ESCellPainter;
258 delegate->drawSelectedCell = selectedESCellPainter;
259 delegate->beginCellEdit = beginESCellEdit;
260 delegate->endCellEdit = endESCellEdit;
261
262 return delegate;
dc67e814 kojima2000-11-12 03:29:53 +0000263}
5e1e94ef kojima2000-12-21 03:38:12 +0000264
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200265void WTSetEnumSelectorOptions(WMTableColumnDelegate * delegate, char **options, int count)
4c60cd5b kojima2000-12-21 21:06:00 +0000266{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200267 EnumSelectorData *data = (EnumSelectorData *) delegate->data;
268 int i;
6830b057 dan2004-10-12 21:28:27 +0000269
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200270 for (i = 0; i < WMGetPopUpButtonNumberOfItems(data->widget); i++) {
271 WMRemovePopUpButtonItem(data->widget, 0);
272 }
6830b057 dan2004-10-12 21:28:27 +0000273
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200274 data->options = options;
275 data->count = count;
6830b057 dan2004-10-12 21:28:27 +0000276
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200277 for (i = 0; i < count; i++) {
278 WMAddPopUpButtonItem(data->widget, options[i]);
279 }
4c60cd5b kojima2000-12-21 21:06:00 +0000280}
281
e99511b0 kojima2001-01-02 14:17:26 +0000282/* ---------------------------------------------------------------------- */
283
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200284static void BSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
e99511b0 kojima2001-01-02 14:17:26 +0000285{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200286 BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
287 WMTableView *table = WMGetTableColumnTableView(column);
288 int i = (int)(uintptr_t) WMTableViewDataForCell(table, column, row);
289 WMScreen *scr = WMWidgetScreen(table);
290
291 if (i) {
292 pixmapDraw(scr, d,
293 strdata->gc, strdata->selGC, WMGetSystemPixmap(scr, WSICheckMark),
294 WMTableViewRectForCell(table, column, row), False);
295 } else {
296 pixmapDraw(scr, d,
297 strdata->gc, strdata->selGC, NULL, WMTableViewRectForCell(table, column, row), False);
298 }
e99511b0 kojima2001-01-02 14:17:26 +0000299}
300
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200301static void selectedBSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
e99511b0 kojima2001-01-02 14:17:26 +0000302{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200303 BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
304 WMTableView *table = WMGetTableColumnTableView(column);
305 int i = (int)(uintptr_t) WMTableViewDataForCell(table, column, row);
306 WMScreen *scr = WMWidgetScreen(table);
307
308 if (i) {
309 pixmapDraw(scr, d,
310 strdata->gc, strdata->selGC, WMGetSystemPixmap(scr, WSICheckMark),
311 WMTableViewRectForCell(table, column, row), True);
312 } else {
313 pixmapDraw(scr, d,
314 strdata->gc, strdata->selGC, NULL, WMTableViewRectForCell(table, column, row), True);
315 }
e99511b0 kojima2001-01-02 14:17:26 +0000316}
317
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200318static void beginBSCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
e99511b0 kojima2001-01-02 14:17:26 +0000319{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200320 BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
321 WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
322 int data = (int)(uintptr_t) WMTableViewDataForCell(strdata->table, column, row);
e99511b0 kojima2001-01-02 14:17:26 +0000323
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200324 WMSetButtonSelected(strdata->widget, data);
325 WMMoveWidget(strdata->widget, rect.pos.x + 1, rect.pos.y + 1);
326 WMResizeWidget(strdata->widget, rect.size.width - 1, rect.size.height - 1);
e99511b0 kojima2001-01-02 14:17:26 +0000327
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200328 WMMapWidget(strdata->widget);
e99511b0 kojima2001-01-02 14:17:26 +0000329}
330
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200331static void endBSCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
e99511b0 kojima2001-01-02 14:17:26 +0000332{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200333 BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
334 int value;
6830b057 dan2004-10-12 21:28:27 +0000335
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200336 value = WMGetButtonSelected(strdata->widget);
337 WMSetTableViewDataForCell(strdata->table, column, row, (void *)(uintptr_t) value);
338 WMUnmapWidget(strdata->widget);
e99511b0 kojima2001-01-02 14:17:26 +0000339}
340
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200341WMTableColumnDelegate *WTCreateBooleanSwitchDelegate(WMTableView * parent)
e99511b0 kojima2001-01-02 14:17:26 +0000342{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200343 WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
344 WMScreen *scr = WMWidgetScreen(parent);
345 BooleanSwitchData *data = wmalloc(sizeof(BooleanSwitchData));
346 WMColor *color;
347
348 data->widget = WMCreateSwitchButton(parent);
349 W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
350 WMSetButtonText(data->widget, NULL);
351 WMSetButtonImagePosition(data->widget, WIPImageOnly);
352 WMSetButtonImage(data->widget, NULL);
353 WMSetButtonAltImage(data->widget, WMGetSystemPixmap(scr, WSICheckMark));
354
355 data->table = parent;
356 color = WMCreateNamedColor(scr, SelectionColor, False);
357 WMSetWidgetBackgroundColor(data->widget, color);
358 data->gc = WMColorGC(WMWhiteColor(scr));
359 data->selGC = WMColorGC(color);
360
361 delegate->data = data;
362 delegate->drawCell = BSCellPainter;
363 delegate->drawSelectedCell = selectedBSCellPainter;
364 delegate->beginCellEdit = beginBSCellEdit;
365 delegate->endCellEdit = endBSCellEdit;
366
367 return delegate;
e99511b0 kojima2001-01-02 14:17:26 +0000368}
369
4c60cd5b kojima2000-12-21 21:06:00 +0000370/* ---------------------------------------------------------------------- */
5e1e94ef kojima2000-12-21 03:38:12 +0000371
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200372static void SCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
4c60cd5b kojima2000-12-21 21:06:00 +0000373{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200374 StringData *strdata = (StringData *) self->data;
375 WMTableView *table = WMGetTableColumnTableView(column);
4c60cd5b kojima2000-12-21 21:06:00 +0000376
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200377 stringDraw(WMWidgetScreen(table), d,
378 strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
379 WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), False);
380}
4c60cd5b kojima2000-12-21 21:06:00 +0000381
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200382static void selectedSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
4c60cd5b kojima2000-12-21 21:06:00 +0000383{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200384 StringData *strdata = (StringData *) self->data;
385 WMTableView *table = WMGetTableColumnTableView(column);
4c60cd5b kojima2000-12-21 21:06:00 +0000386
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200387 stringDraw(WMWidgetScreen(table), d,
388 strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
389 WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), True);
390}
4c60cd5b kojima2000-12-21 21:06:00 +0000391
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200392WMTableColumnDelegate *WTCreateStringDelegate(WMTableView * parent)
4c60cd5b kojima2000-12-21 21:06:00 +0000393{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200394 WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
395 WMScreen *scr = WMWidgetScreen(parent);
396 StringData *data = wmalloc(sizeof(StringData));
397
398 data->table = parent;
399 data->font = WMSystemFontOfSize(scr, 12);
400 data->gc = WMColorGC(WMWhiteColor(scr));
401 data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
402 data->textColor = WMBlackColor(scr);
403
404 delegate->data = data;
405 delegate->drawCell = SCellPainter;
406 delegate->drawSelectedCell = selectedSCellPainter;
407 delegate->beginCellEdit = NULL;
408 delegate->endCellEdit = NULL;
409
410 return delegate;
4c60cd5b kojima2000-12-21 21:06:00 +0000411}
e99511b0 kojima2001-01-02 14:17:26 +0000412
e99511b0 kojima2001-01-02 14:17:26 +0000413/* ---------------------------------------------------------------------- */
414
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200415static void PCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
e99511b0 kojima2001-01-02 14:17:26 +0000416{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200417 StringData *strdata = (StringData *) self->data;
418 WMTableView *table = WMGetTableColumnTableView(column);
e99511b0 kojima2001-01-02 14:17:26 +0000419
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200420 pixmapDraw(WMWidgetScreen(table), d,
421 strdata->gc, strdata->selGC,
422 (WMPixmap *) WMTableViewDataForCell(table, column, row),
423 WMTableViewRectForCell(table, column, row), False);
424}
e99511b0 kojima2001-01-02 14:17:26 +0000425
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200426static void selectedPCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
e99511b0 kojima2001-01-02 14:17:26 +0000427{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200428 StringData *strdata = (StringData *) self->data;
429 WMTableView *table = WMGetTableColumnTableView(column);
e99511b0 kojima2001-01-02 14:17:26 +0000430
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200431 pixmapDraw(WMWidgetScreen(table), d,
432 strdata->gc, strdata->selGC,
433 (WMPixmap *) WMTableViewDataForCell(table, column, row),
434 WMTableViewRectForCell(table, column, row), True);
435}
e99511b0 kojima2001-01-02 14:17:26 +0000436
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200437WMTableColumnDelegate *WTCreatePixmapDelegate(WMTableView * table)
e99511b0 kojima2001-01-02 14:17:26 +0000438{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200439 WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
440 WMScreen *scr = WMWidgetScreen(table);
441 StringData *data = wmalloc(sizeof(StringData));
6830b057 dan2004-10-12 21:28:27 +0000442
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200443 data->table = table;
444 data->gc = WMColorGC(WMWhiteColor(scr));
445 data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
6830b057 dan2004-10-12 21:28:27 +0000446
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200447 delegate->data = data;
448 delegate->drawCell = PCellPainter;
449 delegate->drawSelectedCell = selectedPCellPainter;
450 delegate->beginCellEdit = NULL;
451 delegate->endCellEdit = NULL;
e99511b0 kojima2001-01-02 14:17:26 +0000452
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200453 return delegate;
e99511b0 kojima2001-01-02 14:17:26 +0000454}
455
e99511b0 kojima2001-01-02 14:17:26 +0000456/* ---------------------------------------------------------------------- */
457
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200458static void drawPSCell(WMTableColumnDelegate * self, Drawable d, WMTableColumn * column, int row, Bool selected)
e99511b0 kojima2001-01-02 14:17:26 +0000459{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200460 StringData *strdata = (StringData *) self->data;
461 WMTableView *table = WMGetTableColumnTableView(column);
462 void **data;
463 WMPixmap *pix;
464 char *str;
465 WMRect rect;
466 WMSize size;
e99511b0 kojima2001-01-02 14:17:26 +0000467
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200468 data = WMTableViewDataForCell(table, column, row);
e99511b0 kojima2001-01-02 14:17:26 +0000469
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200470 str = (char *)data[0];
471 pix = (WMPixmap *) data[1];
e99511b0 kojima2001-01-02 14:17:26 +0000472
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200473 rect = WMTableViewRectForCell(table, column, row);
6830b057 dan2004-10-12 21:28:27 +0000474
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200475 if (pix) {
476 int owidth = rect.size.width;
a2b404b5 dan2002-10-08 08:26:06 +0000477
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200478 size = WMGetPixmapSize(pix);
479 rect.size.width = size.width;
a2b404b5 dan2002-10-08 08:26:06 +0000480
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200481 pixmapDraw(WMWidgetScreen(table),
482 WMViewXID(WMGetTableViewDocumentView(table)),
483 strdata->gc, strdata->selGC, pix, rect, selected);
a2b404b5 dan2002-10-08 08:26:06 +0000484
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200485 rect.pos.x += size.width - 1;
486 rect.size.width = owidth - size.width + 1;
487 }
6830b057 dan2004-10-12 21:28:27 +0000488
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200489 stringDraw(WMWidgetScreen(table), d, strdata->gc, strdata->selGC,
490 strdata->textColor, strdata->font, str, rect, selected);
e99511b0 kojima2001-01-02 14:17:26 +0000491}
492
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200493static void PSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
e99511b0 kojima2001-01-02 14:17:26 +0000494{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200495 drawPSCell(self, d, column, row, False);
e99511b0 kojima2001-01-02 14:17:26 +0000496}
497
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200498static void selectedPSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
e99511b0 kojima2001-01-02 14:17:26 +0000499{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200500 drawPSCell(self, d, column, row, True);
e99511b0 kojima2001-01-02 14:17:26 +0000501}
502
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200503WMTableColumnDelegate *WTCreatePixmapStringDelegate(WMTableView * parent)
e99511b0 kojima2001-01-02 14:17:26 +0000504{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200505 WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
506 WMScreen *scr = WMWidgetScreen(parent);
507 StringData *data = wmalloc(sizeof(StringData));
508
509 data->table = parent;
510 data->font = WMSystemFontOfSize(scr, 12);
511 data->gc = WMColorGC(WMWhiteColor(scr));
512 data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
513 data->textColor = WMBlackColor(scr);
514
515 delegate->data = data;
516 delegate->drawCell = PSCellPainter;
517 delegate->drawSelectedCell = selectedPSCellPainter;
518 delegate->beginCellEdit = NULL;
519 delegate->endCellEdit = NULL;
520
521 return delegate;
e99511b0 kojima2001-01-02 14:17:26 +0000522}