5 #include "wtableview.h"
18 static void stringDraw(WMScreen
*scr
, Drawable d
, GC gc
,
19 GC sgc
, GC stgc
, WMFont
*font
, void *data
,
20 WMRect rect
, Bool selected
)
24 Display
*dpy
= WMScreenDisplay(scr
);
27 y
= rect
.pos
.y
+ (rect
.size
.height
- WMFontHeight(font
))/2;
29 rects
[0].x
= rect
.pos
.x
+1;
30 rects
[0].y
= rect
.pos
.y
+1;
31 rects
[0].width
= rect
.size
.width
-1;
32 rects
[0].height
= rect
.size
.height
-1;
33 XSetClipRectangles(dpy
, gc
, 0, 0, rects
, 1, YXSorted
);
36 XClearArea(dpy
, d
, rects
[0].x
, rects
[0].y
,
37 rects
[0].width
, rects
[0].height
,
40 WMDrawString(scr
, d
, gc
, font
, x
, y
,
43 XFillRectangles(dpy
, d
, sgc
, rects
, 1);
45 WMDrawString(scr
, d
, stgc
, font
, x
, y
,
49 XSetClipMask(dpy
, gc
, None
);
55 static void cellPainter(WMTableColumnDelegate
*self
, WMTableColumn
*column
,
58 StringEditorData
*strdata
= (StringEditorData
*)self
->data
;
59 WMTableView
*table
= WMGetTableColumnTableView(column
);
61 stringDraw(WMWidgetScreen(table
),
62 WMViewXID(WMGetTableViewDocumentView(table
)),
63 strdata
->gc
, strdata
->selGc
, strdata
->selTextGc
, strdata
->font
,
64 WMTableViewDataForCell(table
, column
, row
),
65 WMTableViewRectForCell(table
, column
, row
),
70 static void selectedCellPainter(WMTableColumnDelegate
*self
,
71 WMTableColumn
*column
, int row
)
73 StringEditorData
*strdata
= (StringEditorData
*)self
->data
;
74 WMTableView
*table
= WMGetTableColumnTableView(column
);
76 stringDraw(WMWidgetScreen(table
),
77 WMViewXID(WMGetTableViewDocumentView(table
)),
78 strdata
->gc
, strdata
->selGc
, strdata
->selTextGc
, strdata
->font
,
79 WMTableViewDataForCell(table
, column
, row
),
80 WMTableViewRectForCell(table
, column
, row
),
85 static void beginCellEdit(WMTableColumnDelegate
*self
,
86 WMTableColumn
*column
, int row
)
88 StringEditorData
*strdata
= (StringEditorData
*)self
->data
;
89 WMRect rect
= WMTableViewRectForCell(strdata
->table
, column
, row
);
90 void *data
= WMTableViewDataForCell(strdata
->table
, column
, row
);
92 WMSetTextFieldText(strdata
->widget
, (char*)data
);
93 WMMoveWidget(strdata
->widget
, rect
.pos
.x
, rect
.pos
.y
);
94 WMResizeWidget(strdata
->widget
, rect
.size
.width
+1, rect
.size
.height
+1);
96 WMMapWidget(strdata
->widget
);
101 WMTableColumnDelegate
*WTCreateStringDelegate(WMTableView
*parent
)
103 WMTableColumnDelegate
*delegate
= wmalloc(sizeof(WMTableColumnDelegate
));
104 WMScreen
*scr
= WMWidgetScreen(parent
);
105 StringEditorData
*data
= wmalloc(sizeof(StringEditorData
));
107 data
->widget
= WMCreateTextField(parent
);
108 W_ReparentView(WMWidgetView(data
->widget
),
109 WMGetTableViewDocumentView(parent
),
111 data
->table
= parent
;
112 data
->font
= WMSystemFontOfSize(scr
, 12);
113 data
->selGc
= WMColorGC(WMDarkGrayColor(scr
));
114 data
->selTextGc
= WMColorGC(WMWhiteColor(scr
));
115 data
->gc
= WMColorGC(WMBlackColor(scr
));
117 delegate
->data
= data
;
118 delegate
->drawCell
= cellPainter
;
119 delegate
->drawSelectedCell
= selectedCellPainter
;
120 delegate
->beginCellEdit
= beginCellEdit
;
121 delegate
->endCellEdit
= NULL
;