3 #include <WINGs/WINGsP.h>
5 #include "wtableview.h"
7 #include "wtabledelegates.h"
36 WMPopUpButton
*widget
;
56 static char *SelectionColor
= "#bbbbcc";
60 static void stringDraw(WMScreen
*scr
, Drawable d
, GC gc
, GC sgc
,
61 WMColor
*textColor
, WMFont
*font
, void *data
,
62 WMRect rect
, Bool selected
)
66 Display
*dpy
= WMScreenDisplay(scr
);
69 y
= rect
.pos
.y
+ (rect
.size
.height
- WMFontHeight(font
))/2;
71 rects
[0].x
= rect
.pos
.x
+1;
72 rects
[0].y
= rect
.pos
.y
+1;
73 rects
[0].width
= rect
.size
.width
-1;
74 rects
[0].height
= rect
.size
.height
-1;
75 XSetClipRectangles(dpy
, gc
, 0, 0, rects
, 1, YXSorted
);
78 XFillRectangles(dpy
, d
, gc
, rects
, 1);
80 WMDrawString(scr
, d
, textColor
, font
, x
, y
,
83 XFillRectangles(dpy
, d
, sgc
, rects
, 1);
85 WMDrawString(scr
, d
, textColor
, font
, x
, y
,
89 XSetClipMask(dpy
, gc
, None
);
94 static void pixmapDraw(WMScreen
*scr
, Drawable d
, GC gc
, GC sgc
,
95 WMPixmap
*pixmap
, WMRect rect
, Bool selected
)
99 Display
*dpy
= WMScreenDisplay(scr
);
102 rects
[0].x
= rect
.pos
.x
+1;
103 rects
[0].y
= rect
.pos
.y
+1;
104 rects
[0].width
= rect
.size
.width
-1;
105 rects
[0].height
= rect
.size
.height
-1;
106 XSetClipRectangles(dpy
, gc
, 0, 0, rects
, 1, YXSorted
);
109 XFillRectangles(dpy
, d
, gc
, rects
, 1);
112 size
= WMGetPixmapSize(pixmap
);
113 x
= rect
.pos
.x
+ (rect
.size
.width
- size
.width
) / 2;
114 y
= rect
.pos
.y
+ (rect
.size
.height
- size
.height
) / 2;
116 WMDrawPixmap(pixmap
, d
, x
, y
);
119 XFillRectangles(dpy
, d
, sgc
, rects
, 1);
122 size
= WMGetPixmapSize(pixmap
);
123 x
= rect
.pos
.x
+ (rect
.size
.width
- size
.width
) / 2;
124 y
= rect
.pos
.y
+ (rect
.size
.height
- size
.height
) / 2;
126 WMDrawPixmap(pixmap
, d
, x
, y
);
130 XSetClipMask(dpy
, gc
, None
);
134 /* ---------------------------------------------------------------------- */
138 static void SECellPainter(WMTableColumnDelegate
*self
,
139 WMTableColumn
*column
, int row
, Drawable d
)
141 StringEditorData
*strdata
= (StringEditorData
*)self
->data
;
142 WMTableView
*table
= WMGetTableColumnTableView(column
);
144 stringDraw(WMWidgetScreen(table
), d
,
145 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
146 WMTableViewDataForCell(table
, column
, row
),
147 WMTableViewRectForCell(table
, column
, row
),
152 static void selectedSECellPainter(WMTableColumnDelegate
*self
,
153 WMTableColumn
*column
, int row
, Drawable d
)
155 StringEditorData
*strdata
= (StringEditorData
*)self
->data
;
156 WMTableView
*table
= WMGetTableColumnTableView(column
);
158 stringDraw(WMWidgetScreen(table
), d
,
159 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
160 WMTableViewDataForCell(table
, column
, row
),
161 WMTableViewRectForCell(table
, column
, row
),
166 static void beginSECellEdit(WMTableColumnDelegate
*self
,
167 WMTableColumn
*column
, int row
)
169 StringEditorData
*strdata
= (StringEditorData
*)self
->data
;
170 WMRect rect
= WMTableViewRectForCell(strdata
->table
, column
, row
);
171 void *data
= WMTableViewDataForCell(strdata
->table
, column
, row
);
173 WMSetTextFieldText(strdata
->widget
, (char*)data
);
174 WMMoveWidget(strdata
->widget
, rect
.pos
.x
, rect
.pos
.y
);
175 WMResizeWidget(strdata
->widget
, rect
.size
.width
+1, rect
.size
.height
+1);
177 WMMapWidget(strdata
->widget
);
181 static void endSECellEdit(WMTableColumnDelegate
*self
,
182 WMTableColumn
*column
, int row
)
184 StringEditorData
*strdata
= (StringEditorData
*)self
->data
;
187 WMUnmapWidget(strdata
->widget
);
189 text
= WMGetTextFieldText(strdata
->widget
);
190 WMSetTableViewDataForCell(strdata
->table
, column
, row
, (void*)text
);
194 WMTableColumnDelegate
*WTCreateStringEditorDelegate(WMTableView
*parent
)
196 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
197 WMScreen
*scr
= WMWidgetScreen(parent
);
198 StringEditorData
*data
= wmalloc(sizeof(StringEditorData
));
200 data
->widget
= WMCreateTextField(parent
);
201 W_ReparentView(WMWidgetView(data
->widget
),
202 WMGetTableViewDocumentView(parent
),
204 data
->table
= parent
;
205 data
->font
= WMSystemFontOfSize(scr
, 12);
206 data
->gc
= WMColorGC(WMWhiteColor(scr
));
207 data
->selGC
= WMColorGC(WMCreateNamedColor(scr
, SelectionColor
, False
));
208 data
->textColor
= WMBlackColor(scr
);
210 delegate
->data
= data
;
211 delegate
->drawCell
= SECellPainter
;
212 delegate
->drawSelectedCell
= selectedSECellPainter
;
213 delegate
->beginCellEdit
= beginSECellEdit
;
214 delegate
->endCellEdit
= endSECellEdit
;
221 /* ---------------------------------------------------------------------- */
224 static void ESCellPainter(WMTableColumnDelegate
*self
,
225 WMTableColumn
*column
, int row
, Drawable d
)
227 EnumSelectorData
*strdata
= (EnumSelectorData
*)self
->data
;
228 WMTableView
*table
= WMGetTableColumnTableView(column
);
229 int i
= (int)WMTableViewDataForCell(table
, column
, row
);
231 stringDraw(WMWidgetScreen(table
), d
,
232 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
234 WMTableViewRectForCell(table
, column
, row
),
239 static void selectedESCellPainter(WMTableColumnDelegate
*self
,
240 WMTableColumn
*column
, int row
, Drawable d
)
242 EnumSelectorData
*strdata
= (EnumSelectorData
*)self
->data
;
243 WMTableView
*table
= WMGetTableColumnTableView(column
);
244 int i
= (int)WMTableViewDataForCell(table
, column
, row
);
246 stringDraw(WMWidgetScreen(table
), d
,
247 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
249 WMTableViewRectForCell(table
, column
, row
),
254 static void beginESCellEdit(WMTableColumnDelegate
*self
,
255 WMTableColumn
*column
, int row
)
257 EnumSelectorData
*strdata
= (EnumSelectorData
*)self
->data
;
258 WMRect rect
= WMTableViewRectForCell(strdata
->table
, column
, row
);
259 int data
= (int)WMTableViewDataForCell(strdata
->table
, column
, row
);
261 wassertr(data
< strdata
->count
);
263 WMSetPopUpButtonSelectedItem(strdata
->widget
, data
);
265 WMMoveWidget(strdata
->widget
, rect
.pos
.x
, rect
.pos
.y
);
266 WMResizeWidget(strdata
->widget
, rect
.size
.width
, rect
.size
.height
+1);
268 WMMapWidget(strdata
->widget
);
272 static void endESCellEdit(WMTableColumnDelegate
*self
,
273 WMTableColumn
*column
, int row
)
275 EnumSelectorData
*strdata
= (EnumSelectorData
*)self
->data
;
278 WMUnmapWidget(strdata
->widget
);
280 option
= WMGetPopUpButtonSelectedItem(strdata
->widget
);
281 WMSetTableViewDataForCell(strdata
->table
, column
, row
, (void*)option
);
285 WMTableColumnDelegate
*WTCreateEnumSelectorDelegate(WMTableView
*parent
)
287 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
288 WMScreen
*scr
= WMWidgetScreen(parent
);
289 EnumSelectorData
*data
= wmalloc(sizeof(EnumSelectorData
));
291 data
->widget
= WMCreatePopUpButton(parent
);
292 W_ReparentView(WMWidgetView(data
->widget
),
293 WMGetTableViewDocumentView(parent
),
295 data
->table
= parent
;
296 data
->font
= WMSystemFontOfSize(scr
, 12);
297 data
->gc
= WMColorGC(WMWhiteColor(scr
));
298 data
->selGC
= WMColorGC(WMCreateNamedColor(scr
, SelectionColor
, False
));
299 data
->textColor
= WMBlackColor(scr
);
301 data
->options
= NULL
;
303 delegate
->data
= data
;
304 delegate
->drawCell
= ESCellPainter
;
305 delegate
->drawSelectedCell
= selectedESCellPainter
;
306 delegate
->beginCellEdit
= beginESCellEdit
;
307 delegate
->endCellEdit
= endESCellEdit
;
313 void WTSetEnumSelectorOptions(WMTableColumnDelegate
*delegate
,
314 char **options
, int count
)
316 EnumSelectorData
*data
= (EnumSelectorData
*)delegate
->data
;
320 i
< WMGetPopUpButtonNumberOfItems(data
->widget
);
322 WMRemovePopUpButtonItem(data
->widget
, 0);
325 data
->options
= options
;
328 for (i
= 0; i
< count
; i
++) {
329 WMAddPopUpButtonItem(data
->widget
, options
[i
]);
335 /* ---------------------------------------------------------------------- */
337 static void BSCellPainter(WMTableColumnDelegate
*self
,
338 WMTableColumn
*column
, int row
, Drawable d
)
340 BooleanSwitchData
*strdata
= (BooleanSwitchData
*)self
->data
;
341 WMTableView
*table
= WMGetTableColumnTableView(column
);
342 int i
= (int)WMTableViewDataForCell(table
, column
, row
);
343 WMScreen
*scr
= WMWidgetScreen(table
);
347 strdata
->gc
, strdata
->selGC
, WMGetSystemPixmap(scr
, WSICheckMark
),
348 WMTableViewRectForCell(table
, column
, row
), False
);
351 strdata
->gc
, strdata
->selGC
, NULL
,
352 WMTableViewRectForCell(table
, column
, row
), False
);
357 static void selectedBSCellPainter(WMTableColumnDelegate
*self
,
358 WMTableColumn
*column
, int row
, Drawable d
)
360 BooleanSwitchData
*strdata
= (BooleanSwitchData
*)self
->data
;
361 WMTableView
*table
= WMGetTableColumnTableView(column
);
362 int i
= (int)WMTableViewDataForCell(table
, column
, row
);
363 WMScreen
*scr
= WMWidgetScreen(table
);
367 strdata
->gc
, strdata
->selGC
, WMGetSystemPixmap(scr
, WSICheckMark
),
368 WMTableViewRectForCell(table
, column
, row
), True
);
371 strdata
->gc
, strdata
->selGC
, NULL
,
372 WMTableViewRectForCell(table
, column
, row
), True
);
378 static void beginBSCellEdit(WMTableColumnDelegate
*self
,
379 WMTableColumn
*column
, int row
)
381 BooleanSwitchData
*strdata
= (BooleanSwitchData
*)self
->data
;
382 WMRect rect
= WMTableViewRectForCell(strdata
->table
, column
, row
);
383 int data
= (int)WMTableViewDataForCell(strdata
->table
, column
, row
);
385 WMSetButtonSelected(strdata
->widget
, data
);
386 WMMoveWidget(strdata
->widget
, rect
.pos
.x
+1, rect
.pos
.y
+1);
387 WMResizeWidget(strdata
->widget
, rect
.size
.width
-1, rect
.size
.height
-1);
389 WMMapWidget(strdata
->widget
);
393 static void endBSCellEdit(WMTableColumnDelegate
*self
,
394 WMTableColumn
*column
, int row
)
396 BooleanSwitchData
*strdata
= (BooleanSwitchData
*)self
->data
;
399 value
= WMGetButtonSelected(strdata
->widget
);
400 WMSetTableViewDataForCell(strdata
->table
, column
, row
, (void*)value
);
401 WMUnmapWidget(strdata
->widget
);
405 WMTableColumnDelegate
*WTCreateBooleanSwitchDelegate(WMTableView
*parent
)
407 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
408 WMScreen
*scr
= WMWidgetScreen(parent
);
409 BooleanSwitchData
*data
= wmalloc(sizeof(BooleanSwitchData
));
412 data
->widget
= WMCreateSwitchButton(parent
);
413 W_ReparentView(WMWidgetView(data
->widget
),
414 WMGetTableViewDocumentView(parent
),
416 WMSetButtonText(data
->widget
, NULL
);
417 WMSetButtonImagePosition(data
->widget
, WIPImageOnly
);
418 WMSetButtonImage(data
->widget
, NULL
);
419 WMSetButtonAltImage(data
->widget
, WMGetSystemPixmap(scr
, WSICheckMark
));
421 data
->table
= parent
;
422 color
= WMCreateNamedColor(scr
, SelectionColor
, False
);
423 WMSetWidgetBackgroundColor(data
->widget
, color
);
424 data
->gc
= WMColorGC(WMWhiteColor(scr
));
425 data
->selGC
= WMColorGC(color
);
427 delegate
->data
= data
;
428 delegate
->drawCell
= BSCellPainter
;
429 delegate
->drawSelectedCell
= selectedBSCellPainter
;
430 delegate
->beginCellEdit
= beginBSCellEdit
;
431 delegate
->endCellEdit
= endBSCellEdit
;
437 /* ---------------------------------------------------------------------- */
440 static void SCellPainter(WMTableColumnDelegate
*self
,
441 WMTableColumn
*column
, int row
, Drawable d
)
443 StringData
*strdata
= (StringData
*)self
->data
;
444 WMTableView
*table
= WMGetTableColumnTableView(column
);
446 stringDraw(WMWidgetScreen(table
), d
,
447 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
448 WMTableViewDataForCell(table
, column
, row
),
449 WMTableViewRectForCell(table
, column
, row
),
454 static void selectedSCellPainter(WMTableColumnDelegate
*self
,
455 WMTableColumn
*column
, int row
, Drawable d
)
457 StringData
*strdata
= (StringData
*)self
->data
;
458 WMTableView
*table
= WMGetTableColumnTableView(column
);
460 stringDraw(WMWidgetScreen(table
), d
,
461 strdata
->gc
, strdata
->selGC
, strdata
->textColor
, strdata
->font
,
462 WMTableViewDataForCell(table
, column
, row
),
463 WMTableViewRectForCell(table
, column
, row
),
468 WMTableColumnDelegate
*WTCreateStringDelegate(WMTableView
*parent
)
470 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
471 WMScreen
*scr
= WMWidgetScreen(parent
);
472 StringData
*data
= wmalloc(sizeof(StringData
));
474 data
->table
= parent
;
475 data
->font
= WMSystemFontOfSize(scr
, 12);
476 data
->gc
= WMColorGC(WMWhiteColor(scr
));
477 data
->selGC
= WMColorGC(WMCreateNamedColor(scr
, SelectionColor
, False
));
478 data
->textColor
= WMBlackColor(scr
);
480 delegate
->data
= data
;
481 delegate
->drawCell
= SCellPainter
;
482 delegate
->drawSelectedCell
= selectedSCellPainter
;
483 delegate
->beginCellEdit
= NULL
;
484 delegate
->endCellEdit
= NULL
;
490 /* ---------------------------------------------------------------------- */
493 static void PCellPainter(WMTableColumnDelegate
*self
,
494 WMTableColumn
*column
, int row
, Drawable d
)
496 StringData
*strdata
= (StringData
*)self
->data
;
497 WMTableView
*table
= WMGetTableColumnTableView(column
);
499 pixmapDraw(WMWidgetScreen(table
), d
,
500 strdata
->gc
, strdata
->selGC
,
501 (WMPixmap
*)WMTableViewDataForCell(table
, column
, row
),
502 WMTableViewRectForCell(table
, column
, row
),
507 static void selectedPCellPainter(WMTableColumnDelegate
*self
,
508 WMTableColumn
*column
, int row
, Drawable d
)
510 StringData
*strdata
= (StringData
*)self
->data
;
511 WMTableView
*table
= WMGetTableColumnTableView(column
);
513 pixmapDraw(WMWidgetScreen(table
), d
,
514 strdata
->gc
, strdata
->selGC
,
515 (WMPixmap
*)WMTableViewDataForCell(table
, column
, row
),
516 WMTableViewRectForCell(table
, column
, row
),
521 WMTableColumnDelegate
*WTCreatePixmapDelegate(WMTableView
*table
)
523 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
524 WMScreen
*scr
= WMWidgetScreen(table
);
525 StringData
*data
= wmalloc(sizeof(StringData
));
528 data
->gc
= WMColorGC(WMWhiteColor(scr
));
529 data
->selGC
= WMColorGC(WMCreateNamedColor(scr
, SelectionColor
, False
));
531 delegate
->data
= data
;
532 delegate
->drawCell
= PCellPainter
;
533 delegate
->drawSelectedCell
= selectedPCellPainter
;
534 delegate
->beginCellEdit
= NULL
;
535 delegate
->endCellEdit
= NULL
;
541 /* ---------------------------------------------------------------------- */
544 static void drawPSCell(WMTableColumnDelegate
*self
, Drawable d
,
545 WMTableColumn
*column
, int row
, Bool selected
)
547 StringData
*strdata
= (StringData
*)self
->data
;
548 WMTableView
*table
= WMGetTableColumnTableView(column
);
555 data
= WMTableViewDataForCell(table
, column
, row
);
557 str
= (char*)data
[0];
558 pix
= (WMPixmap
*)data
[1];
560 rect
= WMTableViewRectForCell(table
, column
, row
);
563 int owidth
= rect
.size
.width
;
565 size
= WMGetPixmapSize(pix
);
566 rect
.size
.width
= size
.width
;
568 pixmapDraw(WMWidgetScreen(table
),
569 WMViewXID(WMGetTableViewDocumentView(table
)),
570 strdata
->gc
, strdata
->selGC
, pix
, rect
,
573 rect
.pos
.x
+= size
.width
-1;
574 rect
.size
.width
= owidth
-size
.width
+1;
577 stringDraw(WMWidgetScreen(table
), d
, strdata
->gc
, strdata
->selGC
,
578 strdata
->textColor
, strdata
->font
, str
, rect
, selected
);
582 static void PSCellPainter(WMTableColumnDelegate
*self
,
583 WMTableColumn
*column
, int row
, Drawable d
)
585 drawPSCell(self
, d
, column
, row
, False
);
589 static void selectedPSCellPainter(WMTableColumnDelegate
*self
,
590 WMTableColumn
*column
, int row
, Drawable d
)
592 drawPSCell(self
, d
, column
, row
, True
);
596 WMTableColumnDelegate
*WTCreatePixmapStringDelegate(WMTableView
*parent
)
598 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
599 WMScreen
*scr
= WMWidgetScreen(parent
);
600 StringData
*data
= wmalloc(sizeof(StringData
));
602 data
->table
= parent
;
603 data
->font
= WMSystemFontOfSize(scr
, 12);
604 data
->gc
= WMColorGC(WMWhiteColor(scr
));
605 data
->selGC
= WMColorGC(WMCreateNamedColor(scr
, SelectionColor
, False
));
606 data
->textColor
= WMBlackColor(scr
);
608 delegate
->data
= data
;
609 delegate
->drawCell
= PSCellPainter
;
610 delegate
->drawSelectedCell
= selectedPSCellPainter
;
611 delegate
->beginCellEdit
= NULL
;
612 delegate
->endCellEdit
= NULL
;