3 #include <WINGs/WINGsP.h>
5 #include "wtableview.h"
7 #include "wtabledelegates.h"
32 WMPopUpButton
*widget
;
50 static char *SelectionColor
= "#bbbbcc";
53 stringDraw(WMScreen
* scr
, Drawable d
, GC gc
, GC sgc
, WMColor
* textColor
,
54 WMFont
* font
, void *data
, WMRect rect
, Bool selected
)
58 Display
*dpy
= WMScreenDisplay(scr
);
61 y
= rect
.pos
.y
+ (rect
.size
.height
- WMFontHeight(font
)) / 2;
63 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
);
70 XFillRectangles(dpy
, d
, gc
, rects
, 1);
72 WMDrawString(scr
, d
, textColor
, font
, x
, y
, data
, strlen(data
));
74 XFillRectangles(dpy
, d
, sgc
, rects
, 1);
76 WMDrawString(scr
, d
, textColor
, font
, x
, y
, data
, strlen(data
));
79 XSetClipMask(dpy
, gc
, None
);
82 static void pixmapDraw(WMScreen
* scr
, Drawable d
, GC gc
, GC sgc
, WMPixmap
* pixmap
, WMRect rect
, Bool selected
)
86 Display
*dpy
= WMScreenDisplay(scr
);
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
);
96 XFillRectangles(dpy
, d
, gc
, rects
, 1);
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;
103 WMDrawPixmap(pixmap
, d
, x
, y
);
106 XFillRectangles(dpy
, d
, sgc
, rects
, 1);
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;
113 WMDrawPixmap(pixmap
, d
, x
, y
);
117 XSetClipMask(dpy
, gc
, None
);
120 /* ---------------------------------------------------------------------- */
122 static void SECellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
124 StringEditorData
*strdata
= (StringEditorData
*) self
->data
;
125 WMTableView
*table
= WMGetTableColumnTableView(column
);
127 stringDraw(WMWidgetScreen(table
), d
,
128 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
129 WMTableViewDataForCell(table
, column
, row
), WMTableViewRectForCell(table
, column
, row
), False
);
132 static void selectedSECellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
134 StringEditorData
*strdata
= (StringEditorData
*) self
->data
;
135 WMTableView
*table
= WMGetTableColumnTableView(column
);
137 stringDraw(WMWidgetScreen(table
), d
,
138 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
139 WMTableViewDataForCell(table
, column
, row
), WMTableViewRectForCell(table
, column
, row
), True
);
142 static void beginSECellEdit(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
)
144 StringEditorData
*strdata
= (StringEditorData
*) self
->data
;
145 WMRect rect
= WMTableViewRectForCell(strdata
->table
, column
, row
);
146 void *data
= WMTableViewDataForCell(strdata
->table
, column
, row
);
148 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);
152 WMMapWidget(strdata
->widget
);
155 static void endSECellEdit(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
)
157 StringEditorData
*strdata
= (StringEditorData
*) self
->data
;
160 WMUnmapWidget(strdata
->widget
);
162 text
= WMGetTextFieldText(strdata
->widget
);
163 WMSetTableViewDataForCell(strdata
->table
, column
, row
, (void *)text
);
166 WMTableColumnDelegate
*WTCreateStringEditorDelegate(WMTableView
* parent
)
168 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
169 WMScreen
*scr
= WMWidgetScreen(parent
);
170 StringEditorData
*data
= wmalloc(sizeof(StringEditorData
));
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
);
180 delegate
->data
= data
;
181 delegate
->drawCell
= SECellPainter
;
182 delegate
->drawSelectedCell
= selectedSECellPainter
;
183 delegate
->beginCellEdit
= beginSECellEdit
;
184 delegate
->endCellEdit
= endSECellEdit
;
189 /* ---------------------------------------------------------------------- */
191 static void ESCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
193 EnumSelectorData
*strdata
= (EnumSelectorData
*) self
->data
;
194 WMTableView
*table
= WMGetTableColumnTableView(column
);
195 uintptr_t i
= (uintptr_t)WMTableViewDataForCell(table
, column
, row
);
197 stringDraw(WMWidgetScreen(table
), d
,
198 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
199 strdata
->options
[i
], WMTableViewRectForCell(table
, column
, row
), False
);
202 static void selectedESCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
204 EnumSelectorData
*strdata
= (EnumSelectorData
*) self
->data
;
205 WMTableView
*table
= WMGetTableColumnTableView(column
);
206 uintptr_t i
= (uintptr_t)WMTableViewDataForCell(table
, column
, row
);
208 stringDraw(WMWidgetScreen(table
), d
,
209 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
210 strdata
->options
[i
], WMTableViewRectForCell(table
, column
, row
), True
);
213 static void beginESCellEdit(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
)
215 EnumSelectorData
*strdata
= (EnumSelectorData
*) self
->data
;
216 WMRect rect
= WMTableViewRectForCell(strdata
->table
, column
, row
);
217 uintptr_t data
= (uintptr_t)WMTableViewDataForCell(strdata
->table
, column
, row
);
219 wassertr(data
< strdata
->count
);
221 WMSetPopUpButtonSelectedItem(strdata
->widget
, data
);
223 WMMoveWidget(strdata
->widget
, rect
.pos
.x
, rect
.pos
.y
);
224 WMResizeWidget(strdata
->widget
, rect
.size
.width
, rect
.size
.height
+ 1);
226 WMMapWidget(strdata
->widget
);
229 static void endESCellEdit(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
)
231 EnumSelectorData
*strdata
= (EnumSelectorData
*) self
->data
;
234 WMUnmapWidget(strdata
->widget
);
236 option
= WMGetPopUpButtonSelectedItem(strdata
->widget
);
237 WMSetTableViewDataForCell(strdata
->table
, column
, row
, (void *)(uintptr_t) option
);
240 WMTableColumnDelegate
*WTCreateEnumSelectorDelegate(WMTableView
* parent
)
242 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
243 WMScreen
*scr
= WMWidgetScreen(parent
);
244 EnumSelectorData
*data
= wmalloc(sizeof(EnumSelectorData
));
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
);
254 data
->options
= NULL
;
256 delegate
->data
= data
;
257 delegate
->drawCell
= ESCellPainter
;
258 delegate
->drawSelectedCell
= selectedESCellPainter
;
259 delegate
->beginCellEdit
= beginESCellEdit
;
260 delegate
->endCellEdit
= endESCellEdit
;
265 void WTSetEnumSelectorOptions(WMTableColumnDelegate
* delegate
, char **options
, int count
)
267 EnumSelectorData
*data
= (EnumSelectorData
*) delegate
->data
;
270 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(data
->widget
); i
++) {
271 WMRemovePopUpButtonItem(data
->widget
, 0);
274 data
->options
= options
;
277 for (i
= 0; i
< count
; i
++) {
278 WMAddPopUpButtonItem(data
->widget
, options
[i
]);
282 /* ---------------------------------------------------------------------- */
284 static void BSCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
286 BooleanSwitchData
*strdata
= (BooleanSwitchData
*) self
->data
;
287 WMTableView
*table
= WMGetTableColumnTableView(column
);
288 uintptr_t i
= (uintptr_t)WMTableViewDataForCell(table
, column
, row
);
289 WMScreen
*scr
= WMWidgetScreen(table
);
293 strdata
->gc
, strdata
->selGC
, WMGetSystemPixmap(scr
, WSICheckMark
),
294 WMTableViewRectForCell(table
, column
, row
), False
);
297 strdata
->gc
, strdata
->selGC
, NULL
, WMTableViewRectForCell(table
, column
, row
), False
);
301 static void selectedBSCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
303 BooleanSwitchData
*strdata
= (BooleanSwitchData
*) self
->data
;
304 WMTableView
*table
= WMGetTableColumnTableView(column
);
305 uintptr_t i
= (uintptr_t)WMTableViewDataForCell(table
, column
, row
);
306 WMScreen
*scr
= WMWidgetScreen(table
);
310 strdata
->gc
, strdata
->selGC
, WMGetSystemPixmap(scr
, WSICheckMark
),
311 WMTableViewRectForCell(table
, column
, row
), True
);
314 strdata
->gc
, strdata
->selGC
, NULL
, WMTableViewRectForCell(table
, column
, row
), True
);
318 static void beginBSCellEdit(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
)
320 BooleanSwitchData
*strdata
= (BooleanSwitchData
*) self
->data
;
321 WMRect rect
= WMTableViewRectForCell(strdata
->table
, column
, row
);
322 uintptr_t data
= (uintptr_t)WMTableViewDataForCell(strdata
->table
, column
, row
);
324 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);
328 WMMapWidget(strdata
->widget
);
331 static void endBSCellEdit(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
)
333 BooleanSwitchData
*strdata
= (BooleanSwitchData
*) self
->data
;
336 value
= WMGetButtonSelected(strdata
->widget
);
337 WMSetTableViewDataForCell(strdata
->table
, column
, row
, (void *)(uintptr_t) value
);
338 WMUnmapWidget(strdata
->widget
);
341 WMTableColumnDelegate
*WTCreateBooleanSwitchDelegate(WMTableView
* parent
)
343 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
344 WMScreen
*scr
= WMWidgetScreen(parent
);
345 BooleanSwitchData
*data
= wmalloc(sizeof(BooleanSwitchData
));
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
));
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
);
361 delegate
->data
= data
;
362 delegate
->drawCell
= BSCellPainter
;
363 delegate
->drawSelectedCell
= selectedBSCellPainter
;
364 delegate
->beginCellEdit
= beginBSCellEdit
;
365 delegate
->endCellEdit
= endBSCellEdit
;
370 /* ---------------------------------------------------------------------- */
372 static void SCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
374 StringData
*strdata
= (StringData
*) self
->data
;
375 WMTableView
*table
= WMGetTableColumnTableView(column
);
377 stringDraw(WMWidgetScreen(table
), d
,
378 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
379 WMTableViewDataForCell(table
, column
, row
), WMTableViewRectForCell(table
, column
, row
), False
);
382 static void selectedSCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
384 StringData
*strdata
= (StringData
*) self
->data
;
385 WMTableView
*table
= WMGetTableColumnTableView(column
);
387 stringDraw(WMWidgetScreen(table
), d
,
388 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
389 WMTableViewDataForCell(table
, column
, row
), WMTableViewRectForCell(table
, column
, row
), True
);
392 WMTableColumnDelegate
*WTCreateStringDelegate(WMTableView
* parent
)
394 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
395 WMScreen
*scr
= WMWidgetScreen(parent
);
396 StringData
*data
= wmalloc(sizeof(StringData
));
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
);
404 delegate
->data
= data
;
405 delegate
->drawCell
= SCellPainter
;
406 delegate
->drawSelectedCell
= selectedSCellPainter
;
407 delegate
->beginCellEdit
= NULL
;
408 delegate
->endCellEdit
= NULL
;
413 /* ---------------------------------------------------------------------- */
415 static void PCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
417 StringData
*strdata
= (StringData
*) self
->data
;
418 WMTableView
*table
= WMGetTableColumnTableView(column
);
420 pixmapDraw(WMWidgetScreen(table
), d
,
421 strdata
->gc
, strdata
->selGC
,
422 (WMPixmap
*) WMTableViewDataForCell(table
, column
, row
),
423 WMTableViewRectForCell(table
, column
, row
), False
);
426 static void selectedPCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
428 StringData
*strdata
= (StringData
*) self
->data
;
429 WMTableView
*table
= WMGetTableColumnTableView(column
);
431 pixmapDraw(WMWidgetScreen(table
), d
,
432 strdata
->gc
, strdata
->selGC
,
433 (WMPixmap
*) WMTableViewDataForCell(table
, column
, row
),
434 WMTableViewRectForCell(table
, column
, row
), True
);
437 WMTableColumnDelegate
*WTCreatePixmapDelegate(WMTableView
* table
)
439 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
440 WMScreen
*scr
= WMWidgetScreen(table
);
441 StringData
*data
= wmalloc(sizeof(StringData
));
444 data
->gc
= WMColorGC(WMWhiteColor(scr
));
445 data
->selGC
= WMColorGC(WMCreateNamedColor(scr
, SelectionColor
, False
));
447 delegate
->data
= data
;
448 delegate
->drawCell
= PCellPainter
;
449 delegate
->drawSelectedCell
= selectedPCellPainter
;
450 delegate
->beginCellEdit
= NULL
;
451 delegate
->endCellEdit
= NULL
;
456 /* ---------------------------------------------------------------------- */
458 static void drawPSCell(WMTableColumnDelegate
* self
, Drawable d
, WMTableColumn
* column
, int row
, Bool selected
)
460 StringData
*strdata
= (StringData
*) self
->data
;
461 WMTableView
*table
= WMGetTableColumnTableView(column
);
468 data
= WMTableViewDataForCell(table
, column
, row
);
470 str
= (char *)data
[0];
471 pix
= (WMPixmap
*) data
[1];
473 rect
= WMTableViewRectForCell(table
, column
, row
);
476 int owidth
= rect
.size
.width
;
478 size
= WMGetPixmapSize(pix
);
479 rect
.size
.width
= size
.width
;
481 pixmapDraw(WMWidgetScreen(table
),
482 WMViewXID(WMGetTableViewDocumentView(table
)),
483 strdata
->gc
, strdata
->selGC
, pix
, rect
, selected
);
485 rect
.pos
.x
+= size
.width
- 1;
486 rect
.size
.width
= owidth
- size
.width
+ 1;
489 stringDraw(WMWidgetScreen(table
), d
, strdata
->gc
, strdata
->selGC
,
490 strdata
->textColor
, strdata
->font
, str
, rect
, selected
);
493 static void PSCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
495 drawPSCell(self
, d
, column
, row
, False
);
498 static void selectedPSCellPainter(WMTableColumnDelegate
* self
, WMTableColumn
* column
, int row
, Drawable d
)
500 drawPSCell(self
, d
, column
, row
, True
);
503 WMTableColumnDelegate
*WTCreatePixmapStringDelegate(WMTableView
* parent
)
505 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
506 WMScreen
*scr
= WMWidgetScreen(parent
);
507 StringData
*data
= wmalloc(sizeof(StringData
));
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
);
515 delegate
->data
= data
;
516 delegate
->drawCell
= PSCellPainter
;
517 delegate
->drawSelectedCell
= selectedPSCellPainter
;
518 delegate
->beginCellEdit
= NULL
;
519 delegate
->endCellEdit
= NULL
;