mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-02 22:25:48 +01:00
various table widget updates
and fixed in misc other ones
This commit is contained in:
@@ -14,6 +14,13 @@ typedef struct {
|
||||
} StringData;
|
||||
|
||||
|
||||
typedef struct {
|
||||
WMTableView *table;
|
||||
GC selGc;
|
||||
} PixmapData;
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
WMTextField *widget;
|
||||
WMTableView *table;
|
||||
@@ -36,6 +43,17 @@ typedef struct {
|
||||
} EnumSelectorData;
|
||||
|
||||
|
||||
typedef struct {
|
||||
WMButton *widget;
|
||||
WMTableView *table;
|
||||
Bool state;
|
||||
GC gc;
|
||||
} BooleanSwitchData;
|
||||
|
||||
|
||||
static char *SelectionColor = "#bbbbcc";
|
||||
|
||||
|
||||
|
||||
static void stringDraw(WMScreen *scr, Drawable d, GC gc,
|
||||
GC sgc, GC stgc, WMFont *font, void *data,
|
||||
@@ -73,6 +91,49 @@ static void stringDraw(WMScreen *scr, Drawable d, GC gc,
|
||||
|
||||
|
||||
|
||||
static void pixmapDraw(WMScreen *scr, Drawable d, GC gc,
|
||||
WMPixmap *pixmap, WMRect rect, Bool selected)
|
||||
{
|
||||
int x, y;
|
||||
XRectangle rects[1];
|
||||
Display *dpy = WMScreenDisplay(scr);
|
||||
WMSize size;
|
||||
|
||||
rects[0].x = rect.pos.x+1;
|
||||
rects[0].y = rect.pos.y+1;
|
||||
rects[0].width = rect.size.width-1;
|
||||
rects[0].height = rect.size.height-1;
|
||||
XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
|
||||
|
||||
if (!selected) {
|
||||
XClearArea(dpy, d, rects[0].x, rects[0].y,
|
||||
rects[0].width, rects[0].height,
|
||||
False);
|
||||
|
||||
if (pixmap) {
|
||||
size = WMGetPixmapSize(pixmap);
|
||||
x = rect.pos.x + (rect.size.width - size.width) / 2;
|
||||
y = rect.pos.y + (rect.size.height - size.height) / 2;
|
||||
|
||||
WMDrawPixmap(pixmap, d, x, y);
|
||||
}
|
||||
} else {
|
||||
XFillRectangles(dpy, d, gc, rects, 1);
|
||||
|
||||
if (pixmap) {
|
||||
size = WMGetPixmapSize(pixmap);
|
||||
x = rect.pos.x + (rect.size.width - size.width) / 2;
|
||||
y = rect.pos.y + (rect.size.height - size.height) / 2;
|
||||
|
||||
WMDrawPixmap(pixmap, d, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
XSetClipMask(dpy, gc, None);
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
@@ -124,9 +185,10 @@ static void beginSECellEdit(WMTableColumnDelegate *self,
|
||||
static void endSECellEdit(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
StringEditorData *strdata = (StringEditorData*)self->data;
|
||||
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
|
||||
StringEditorData *strdata = (StringEditorData*)self->data;
|
||||
char *text;
|
||||
|
||||
WMUnmapWidget(strdata->widget);
|
||||
|
||||
text = WMGetTextFieldText(strdata->widget);
|
||||
WMSetTableViewDataForCell(strdata->table, column, row, (void*)text);
|
||||
@@ -145,8 +207,8 @@ WMTableColumnDelegate *WTCreateStringEditorDelegate(WMTableView *parent)
|
||||
0, 0);
|
||||
data->table = parent;
|
||||
data->font = WMSystemFontOfSize(scr, 12);
|
||||
data->selGc = WMColorGC(WMDarkGrayColor(scr));
|
||||
data->selTextGc = WMColorGC(WMWhiteColor(scr));
|
||||
data->selGc = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
|
||||
data->selTextGc = WMColorGC(WMBlackColor(scr));
|
||||
data->gc = WMColorGC(WMBlackColor(scr));
|
||||
|
||||
delegate->data = data;
|
||||
@@ -168,7 +230,7 @@ static void ESCellPainter(WMTableColumnDelegate *self,
|
||||
{
|
||||
EnumSelectorData *strdata = (EnumSelectorData*)self->data;
|
||||
WMTableView *table = WMGetTableColumnTableView(column);
|
||||
int i = WMTableViewDataForCell(table, column, row);
|
||||
int i = (int)WMTableViewDataForCell(table, column, row);
|
||||
|
||||
stringDraw(WMWidgetScreen(table),
|
||||
WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
@@ -184,7 +246,7 @@ static void selectedESCellPainter(WMTableColumnDelegate *self,
|
||||
{
|
||||
EnumSelectorData *strdata = (EnumSelectorData*)self->data;
|
||||
WMTableView *table = WMGetTableColumnTableView(column);
|
||||
int i = WMTableViewDataForCell(table, column, row);
|
||||
int i = (int)WMTableViewDataForCell(table, column, row);
|
||||
|
||||
stringDraw(WMWidgetScreen(table),
|
||||
WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
@@ -206,8 +268,8 @@ static void beginESCellEdit(WMTableColumnDelegate *self,
|
||||
|
||||
WMSetPopUpButtonSelectedItem(strdata->widget, data);
|
||||
|
||||
WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y-1);
|
||||
WMResizeWidget(strdata->widget, rect.size.width, rect.size.height+2);
|
||||
WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
|
||||
WMResizeWidget(strdata->widget, rect.size.width, rect.size.height+1);
|
||||
|
||||
WMMapWidget(strdata->widget);
|
||||
}
|
||||
@@ -216,9 +278,10 @@ static void beginESCellEdit(WMTableColumnDelegate *self,
|
||||
static void endESCellEdit(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
EnumSelectorData *strdata = (EnumSelectorData*)self->data;
|
||||
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
|
||||
EnumSelectorData *strdata = (EnumSelectorData*)self->data;
|
||||
int option;
|
||||
|
||||
WMUnmapWidget(strdata->widget);
|
||||
|
||||
option = WMGetPopUpButtonSelectedItem(strdata->widget);
|
||||
WMSetTableViewDataForCell(strdata->table, column, row, (void*)option);
|
||||
@@ -237,8 +300,8 @@ WMTableColumnDelegate *WTCreateEnumSelectorDelegate(WMTableView *parent)
|
||||
0, 0);
|
||||
data->table = parent;
|
||||
data->font = WMSystemFontOfSize(scr, 12);
|
||||
data->selGc = WMColorGC(WMDarkGrayColor(scr));
|
||||
data->selTextGc = WMColorGC(WMWhiteColor(scr));
|
||||
data->selGc = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
|
||||
data->selTextGc = WMColorGC(WMBlackColor(scr));
|
||||
data->gc = WMColorGC(WMBlackColor(scr));
|
||||
data->count = 0;
|
||||
data->options = NULL;
|
||||
@@ -274,6 +337,108 @@ void WTSetEnumSelectorOptions(WMTableColumnDelegate *delegate,
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
static void BSCellPainter(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
|
||||
WMTableView *table = WMGetTableColumnTableView(column);
|
||||
int i = (int)WMTableViewDataForCell(table, column, row);
|
||||
WMScreen *scr = WMWidgetScreen(table);
|
||||
|
||||
if (i) {
|
||||
pixmapDraw(scr, WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
strdata->gc, WMGetSystemPixmap(scr, WSICheckMark),
|
||||
WMTableViewRectForCell(table, column, row), False);
|
||||
} else {
|
||||
pixmapDraw(scr, WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
strdata->gc, NULL,
|
||||
WMTableViewRectForCell(table, column, row), False);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void selectedBSCellPainter(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
|
||||
WMTableView *table = WMGetTableColumnTableView(column);
|
||||
int i = (int)WMTableViewDataForCell(table, column, row);
|
||||
WMScreen *scr = WMWidgetScreen(table);
|
||||
|
||||
if (i) {
|
||||
pixmapDraw(scr, WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
strdata->gc, WMGetSystemPixmap(scr, WSICheckMark),
|
||||
WMTableViewRectForCell(table, column, row), True);
|
||||
} else {
|
||||
pixmapDraw(scr, WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
strdata->gc, NULL,
|
||||
WMTableViewRectForCell(table, column, row), True);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void beginBSCellEdit(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
|
||||
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
|
||||
int data = (int)WMTableViewDataForCell(strdata->table, column, row);
|
||||
|
||||
WMSetButtonSelected(strdata->widget, data);
|
||||
WMMoveWidget(strdata->widget, rect.pos.x+1, rect.pos.y+1);
|
||||
WMResizeWidget(strdata->widget, rect.size.width-1, rect.size.height-1);
|
||||
|
||||
WMMapWidget(strdata->widget);
|
||||
}
|
||||
|
||||
|
||||
static void endBSCellEdit(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
|
||||
int value;
|
||||
|
||||
value = WMGetButtonSelected(strdata->widget);
|
||||
WMSetTableViewDataForCell(strdata->table, column, row, (void*)value);
|
||||
WMUnmapWidget(strdata->widget);
|
||||
}
|
||||
|
||||
|
||||
WMTableColumnDelegate *WTCreateBooleanSwitchDelegate(WMTableView *parent)
|
||||
{
|
||||
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
|
||||
WMScreen *scr = WMWidgetScreen(parent);
|
||||
BooleanSwitchData *data = wmalloc(sizeof(BooleanSwitchData));
|
||||
WMColor *color;
|
||||
|
||||
data->widget = WMCreateSwitchButton(parent);
|
||||
W_ReparentView(WMWidgetView(data->widget),
|
||||
WMGetTableViewDocumentView(parent),
|
||||
0, 0);
|
||||
WMSetButtonText(data->widget, NULL);
|
||||
WMSetButtonImagePosition(data->widget, WIPImageOnly);
|
||||
WMSetButtonImage(data->widget, NULL);
|
||||
WMSetButtonAltImage(data->widget, WMGetSystemPixmap(scr, WSICheckMark));
|
||||
|
||||
data->table = parent;
|
||||
color = WMCreateNamedColor(scr, SelectionColor, False);
|
||||
WMSetWidgetBackgroundColor(data->widget, color);
|
||||
data->gc = WMColorGC(color);
|
||||
|
||||
delegate->data = data;
|
||||
delegate->drawCell = BSCellPainter;
|
||||
delegate->drawSelectedCell = selectedBSCellPainter;
|
||||
delegate->beginCellEdit = beginBSCellEdit;
|
||||
delegate->endCellEdit = endBSCellEdit;
|
||||
|
||||
return delegate;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -315,8 +480,8 @@ WMTableColumnDelegate *WTCreateStringDelegate(WMTableView *parent)
|
||||
|
||||
data->table = parent;
|
||||
data->font = WMSystemFontOfSize(scr, 12);
|
||||
data->selGc = WMColorGC(WMDarkGrayColor(scr));
|
||||
data->selTextGc = WMColorGC(WMWhiteColor(scr));
|
||||
data->selGc = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
|
||||
data->selTextGc = WMColorGC(WMBlackColor(scr));
|
||||
data->gc = WMColorGC(WMBlackColor(scr));
|
||||
|
||||
delegate->data = data;
|
||||
@@ -327,3 +492,134 @@ WMTableColumnDelegate *WTCreateStringDelegate(WMTableView *parent)
|
||||
|
||||
return delegate;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static void PCellPainter(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
StringData *strdata = (StringData*)self->data;
|
||||
WMTableView *table = WMGetTableColumnTableView(column);
|
||||
|
||||
pixmapDraw(WMWidgetScreen(table),
|
||||
WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
strdata->selGc,
|
||||
(WMPixmap*)WMTableViewDataForCell(table, column, row),
|
||||
WMTableViewRectForCell(table, column, row),
|
||||
False);
|
||||
}
|
||||
|
||||
|
||||
static void selectedPCellPainter(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
StringData *strdata = (StringData*)self->data;
|
||||
WMTableView *table = WMGetTableColumnTableView(column);
|
||||
|
||||
pixmapDraw(WMWidgetScreen(table),
|
||||
WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
strdata->selGc,
|
||||
(WMPixmap*)WMTableViewDataForCell(table, column, row),
|
||||
WMTableViewRectForCell(table, column, row),
|
||||
True);
|
||||
}
|
||||
|
||||
|
||||
WMTableColumnDelegate *WTCreatePixmapDelegate(WMTableView *table)
|
||||
{
|
||||
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
|
||||
WMScreen *scr = WMWidgetScreen(table);
|
||||
StringData *data = wmalloc(sizeof(StringData));
|
||||
|
||||
data->table = table;
|
||||
data->selGc = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
|
||||
|
||||
delegate->data = data;
|
||||
delegate->drawCell = PCellPainter;
|
||||
delegate->drawSelectedCell = selectedPCellPainter;
|
||||
delegate->beginCellEdit = NULL;
|
||||
delegate->endCellEdit = NULL;
|
||||
|
||||
return delegate;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static void drawPSCell(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row, Bool selected)
|
||||
{
|
||||
StringData *strdata = (StringData*)self->data;
|
||||
WMTableView *table = WMGetTableColumnTableView(column);
|
||||
void **data;
|
||||
WMPixmap *pix;
|
||||
char *str;
|
||||
WMRect rect;
|
||||
WMSize size;
|
||||
|
||||
data = WMTableViewDataForCell(table, column, row);
|
||||
|
||||
str = (char*)data[0];
|
||||
pix = (WMPixmap*)data[1];
|
||||
|
||||
rect = WMTableViewRectForCell(table, column, row);
|
||||
|
||||
if (pix) {
|
||||
int owidth = rect.size.width;
|
||||
|
||||
size = WMGetPixmapSize(pix);
|
||||
rect.size.width = size.width;
|
||||
|
||||
pixmapDraw(WMWidgetScreen(table),
|
||||
WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
strdata->selGc, pix, rect,
|
||||
selected);
|
||||
|
||||
rect.pos.x += size.width-1;
|
||||
rect.size.width = owidth-size.width+1;
|
||||
}
|
||||
|
||||
stringDraw(WMWidgetScreen(table),
|
||||
WMViewXID(WMGetTableViewDocumentView(table)),
|
||||
strdata->gc, strdata->selGc, strdata->selTextGc, strdata->font,
|
||||
str, rect, selected);
|
||||
}
|
||||
|
||||
|
||||
static void PSCellPainter(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
drawPSCell(self, column, row, False);
|
||||
}
|
||||
|
||||
|
||||
static void selectedPSCellPainter(WMTableColumnDelegate *self,
|
||||
WMTableColumn *column, int row)
|
||||
{
|
||||
drawPSCell(self, column, row, True);
|
||||
}
|
||||
|
||||
|
||||
WMTableColumnDelegate *WTCreatePixmapStringDelegate(WMTableView *parent)
|
||||
{
|
||||
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
|
||||
WMScreen *scr = WMWidgetScreen(parent);
|
||||
StringData *data = wmalloc(sizeof(StringData));
|
||||
|
||||
data->table = parent;
|
||||
data->font = WMSystemFontOfSize(scr, 12);
|
||||
data->selGc = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
|
||||
data->selTextGc = WMColorGC(WMBlackColor(scr));
|
||||
data->gc = WMColorGC(WMBlackColor(scr));
|
||||
|
||||
delegate->data = data;
|
||||
delegate->drawCell = PSCellPainter;
|
||||
delegate->drawSelectedCell = selectedPSCellPainter;
|
||||
delegate->beginCellEdit = NULL;
|
||||
delegate->endCellEdit = NULL;
|
||||
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,18 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WMTableColumnDelegate *WTCreatePixmapDelegate(WMTableView *table);
|
||||
WMTableColumnDelegate *WTCreateStringDelegate(WMTableView *table);
|
||||
WMTableColumnDelegate *WTCreateStringEditorDelegate(WMTableView *table);
|
||||
WMTableColumnDelegate *WTCreateEnumSelectorDelegate(WMTableView *table);
|
||||
WMTableColumnDelegate *WTCreatePixmapStringDelegate(WMTableView *parent);
|
||||
|
||||
WMTableColumnDelegate *WTCreateStringEditorDelegate(WMTableView *table);
|
||||
|
||||
WMTableColumnDelegate *WTCreateEnumSelectorDelegate(WMTableView *table);
|
||||
void WTSetEnumSelectorOptions(WMTableColumnDelegate *delegate,
|
||||
char **options, int count);
|
||||
|
||||
WMTableColumnDelegate *WTCreateBooleanSwitchDelegate(WMTableView *parent);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -60,10 +60,10 @@ static WMTableViewDelegate delegate = {
|
||||
|
||||
|
||||
|
||||
void selectedRowObserver(void *self, WMNotification *notif)
|
||||
void clickedTable(WMWidget *w, void *self)
|
||||
{
|
||||
int row = (int)WMGetNotificationClientData(notif);
|
||||
|
||||
int row = WMGetTableViewClickedRow((WMTableView*)self);
|
||||
|
||||
WMEditTableViewRow(self, row);
|
||||
}
|
||||
|
||||
@@ -98,12 +98,10 @@ main(int argc, char **argv)
|
||||
table = WMCreateTableView(win);
|
||||
WMResizeWidget(table, 400, 200);
|
||||
WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
|
||||
WMSetTableViewGridColor(table, WMGrayColor(scr));
|
||||
// WMSetTableViewGridColor(table, WMGrayColor(scr));
|
||||
WMSetTableViewHeaderHeight(table, 20);
|
||||
WMSetTableViewDelegate(table, &delegate);
|
||||
WMAddNotificationObserver(selectedRowObserver, table,
|
||||
WMTableViewRowWasSelectedNotification,
|
||||
table);
|
||||
WMSetTableViewAction(table, clickedTable, table);
|
||||
|
||||
colDeleg = WTCreateStringEditorDelegate(table);
|
||||
|
||||
@@ -122,6 +120,15 @@ main(int argc, char **argv)
|
||||
WMSetTableColumnDelegate(col, colDeleg);
|
||||
WMSetTableColumnId(col, (void*)2);
|
||||
|
||||
|
||||
colDeleg = WTCreateBooleanSwitchDelegate(table);
|
||||
|
||||
col = WMCreateTableColumn("Bool");
|
||||
WMSetTableColumnWidth(col, 50);
|
||||
WMAddTableViewColumn(table, col);
|
||||
WMSetTableColumnDelegate(col, colDeleg);
|
||||
WMSetTableColumnId(col, (void*)2);
|
||||
|
||||
|
||||
WMMapWidget(table);
|
||||
WMRealizeWidget(win);
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
#include "wtableview.h"
|
||||
|
||||
|
||||
const char *WMTableViewRowWasSelectedNotification = "WMTableViewRowWasSelectedNotification";
|
||||
const char *WMTableViewRowWasUnselectedNotification = "WMTableViewRowWasUnselectedNotification";
|
||||
const char *WMTableViewSelectionDidChangeNotification = "WMTableViewSelectionDidChangeNotification";
|
||||
|
||||
|
||||
struct W_TableColumn {
|
||||
@@ -30,6 +29,10 @@ struct W_TableColumn {
|
||||
|
||||
static void handleResize(W_ViewDelegate *self, WMView *view);
|
||||
|
||||
static void rearrangeHeader(WMTableView *table);
|
||||
|
||||
static WMRange rowsInRect(WMTableView *table, WMRect rect);
|
||||
|
||||
|
||||
WMTableColumn *WMCreateTableColumn(char *title)
|
||||
{
|
||||
@@ -72,9 +75,9 @@ void WMSetTableColumnWidth(WMTableColumn *column, unsigned width)
|
||||
column->width = WMAX(column->minWidth, width);
|
||||
else
|
||||
column->width = WMAX(column->minWidth, WMIN(column->maxWidth, width));
|
||||
|
||||
|
||||
if (column->table) {
|
||||
handleResize(NULL, W_VIEW(column->table));
|
||||
rearrangeHeader(column->table);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,12 +146,19 @@ struct W_TableView {
|
||||
|
||||
WMTableViewDelegate *delegate;
|
||||
|
||||
WMAction *action;
|
||||
void *clientData;
|
||||
|
||||
void *clickedColumn;
|
||||
int clickedRow;
|
||||
|
||||
int editingRow;
|
||||
|
||||
unsigned headerHeight;
|
||||
|
||||
unsigned rowHeight;
|
||||
|
||||
|
||||
unsigned dragging:1;
|
||||
unsigned drawsGrid:1;
|
||||
unsigned canSelectRow:1;
|
||||
unsigned canSelectMultiRows:1;
|
||||
@@ -188,13 +198,13 @@ static void scrollObserver(void *self, WMNotification *notif)
|
||||
|
||||
column = WMGetFromArray(table->columns, i);
|
||||
|
||||
WMMoveWidget(column->titleW, x + rect.pos.x, 0);
|
||||
WMMoveWidget(column->titleW, x - rect.pos.x, 0);
|
||||
|
||||
if (i > 0) {
|
||||
WMView *splitter;
|
||||
|
||||
splitter = WMGetFromArray(table->splitters, i-1);
|
||||
W_MoveView(splitter, x + rect.pos.x - 1, 0);
|
||||
W_MoveView(splitter, x - rect.pos.x - 1, 0);
|
||||
}
|
||||
|
||||
x += W_VIEW_WIDTH(WMWidgetView(column->titleW)) + 1;
|
||||
@@ -268,6 +278,7 @@ WMTableView *WMCreateTableView(WMWidget *parent)
|
||||
WMMoveWidget(table->header, 22, 2);
|
||||
WMMapWidget(table->header);
|
||||
WMSetFrameRelief(table->header, WRFlat);
|
||||
|
||||
table->corner = WMCreateLabel(table);
|
||||
WMResizeWidget(table->corner, 20, table->headerHeight);
|
||||
WMMoveWidget(table->corner, 2, 2);
|
||||
@@ -287,7 +298,8 @@ WMTableView *WMCreateTableView(WMWidget *parent)
|
||||
|
||||
table->tableView->flags.dontCompressExpose = 1;
|
||||
|
||||
table->gridColor = WMDarkGrayColor(scr);
|
||||
table->gridColor = WMCreateNamedColor(scr, "#cccccc", False);
|
||||
/* table->gridColor = WMGrayColor(scr);*/
|
||||
|
||||
{
|
||||
XGCValues gcv;
|
||||
@@ -300,10 +312,13 @@ WMTableView *WMCreateTableView(WMWidget *parent)
|
||||
}
|
||||
|
||||
table->editingRow = -1;
|
||||
table->clickedRow = -1;
|
||||
|
||||
table->drawsGrid = 1;
|
||||
table->rowHeight = 16;
|
||||
|
||||
WMSetScrollViewLineScroll(table->scrollView, table->rowHeight);
|
||||
|
||||
table->tableWidth = 1;
|
||||
|
||||
table->columns = WMCreateArray(4);
|
||||
@@ -319,7 +334,8 @@ WMTableView *WMCreateTableView(WMWidget *parent)
|
||||
WMCreateEventHandler(table->view, ExposureMask|StructureNotifyMask,
|
||||
handleEvents, table);
|
||||
|
||||
WMCreateEventHandler(table->tableView, ExposureMask|ButtonPressMask,
|
||||
WMCreateEventHandler(table->tableView, ExposureMask|ButtonPressMask|
|
||||
ButtonReleaseMask|ButtonMotionMask,
|
||||
handleTableEvents, table);
|
||||
|
||||
return table;
|
||||
@@ -379,29 +395,7 @@ void WMAddTableViewColumn(WMTableView *table, WMTableColumn *column)
|
||||
WMAddToArray(table->splitters, splitter);
|
||||
}
|
||||
|
||||
count = WMGetArrayItemCount(table->columns);
|
||||
for (i = 0, width = 0; i < count; i++) {
|
||||
WMTableColumn *column = WMGetFromArray(table->columns, i);
|
||||
|
||||
WMMoveWidget(column->titleW, width, 0);
|
||||
WMResizeWidget(column->titleW, column->width-1, table->headerHeight);
|
||||
|
||||
if (i > 0) {
|
||||
WMView *splitter = WMGetFromArray(table->splitters, i-1);
|
||||
|
||||
W_MoveView(splitter, width-1, 0);
|
||||
}
|
||||
width += column->width;
|
||||
}
|
||||
|
||||
wassertr(table->delegate && table->delegate->numberOfRows);
|
||||
|
||||
table->rows = table->delegate->numberOfRows(table->delegate, table);
|
||||
|
||||
W_ResizeView(table->tableView, width+1,
|
||||
table->rows * table->rowHeight + 1);
|
||||
|
||||
table->tableWidth = width + 1;
|
||||
rearrangeHeader(table);
|
||||
}
|
||||
|
||||
|
||||
@@ -419,6 +413,26 @@ void WMSetTableViewDelegate(WMTableView *table, WMTableViewDelegate *delegate)
|
||||
}
|
||||
|
||||
|
||||
void WMSetTableViewAction(WMTableView *table, WMAction *action, void *clientData)
|
||||
{
|
||||
table->action = action;
|
||||
|
||||
table->clientData = clientData;
|
||||
}
|
||||
|
||||
|
||||
void *WMGetTableViewClickedColumn(WMTableView *table)
|
||||
{
|
||||
return table->clickedColumn;
|
||||
}
|
||||
|
||||
|
||||
int WMGetTableViewClickedRow(WMTableView *table)
|
||||
{
|
||||
return table->clickedRow;
|
||||
}
|
||||
|
||||
|
||||
WMView *WMGetTableViewDocumentView(WMTableView *table)
|
||||
{
|
||||
return table->tableView;
|
||||
@@ -486,11 +500,46 @@ void WMSetTableViewGridColor(WMTableView *table, WMColor *color)
|
||||
{
|
||||
WMReleaseColor(table->gridColor);
|
||||
table->gridColor = WMRetainColor(color);
|
||||
XSetForeground(WMScreenDisplay(WMWidgetScreen(table)), table->gridGC, WMColorPixel(color));
|
||||
XSetForeground(WMScreenDisplay(WMWidgetScreen(table)), table->gridGC,
|
||||
WMColorPixel(color));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WMSetTableViewRowHeight(WMTableView *table, int height)
|
||||
{
|
||||
table->rowHeight = height;
|
||||
|
||||
WMRedisplayWidget(table);
|
||||
}
|
||||
|
||||
|
||||
void WMScrollTableViewRowToVisible(WMTableView *table, int row)
|
||||
{
|
||||
WMScroller *scroller;
|
||||
WMRange range;
|
||||
WMRect rect;
|
||||
int newY, tmp;
|
||||
|
||||
rect = WMGetScrollViewVisibleRect(table->scrollView);
|
||||
range = rowsInRect(table, rect);
|
||||
|
||||
scroller = WMGetScrollViewVerticalScroller(table->scrollView);
|
||||
|
||||
if (row < range.position) {
|
||||
newY = row * table->rowHeight - rect.size.height / 2;
|
||||
} else if (row >= range.position + range.count) {
|
||||
newY = row * table->rowHeight - rect.size.height / 2;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
tmp = table->rows*table->rowHeight - rect.size.height;
|
||||
newY = WMAX(0, WMIN(newY, tmp));
|
||||
WMScrollViewScrollPoint(table->scrollView, rect.pos.x, newY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void drawGrid(WMTableView *table, WMRect rect)
|
||||
{
|
||||
WMScreen *scr = WMWidgetScreen(table);
|
||||
@@ -580,9 +629,12 @@ static WMRange rowsInRect(WMTableView *table, WMRect rect)
|
||||
{
|
||||
WMRange range;
|
||||
int rh = table->rowHeight;
|
||||
int dif;
|
||||
|
||||
range.position = WMAX(0, rect.pos.y / rh - 1);
|
||||
range.count = WMAX(1, WMIN(rect.size.height / rh + 3, table->rows));
|
||||
dif = rect.pos.y % rh;
|
||||
|
||||
range.position = WMAX(0, (rect.pos.y - dif) / rh);
|
||||
range.count = WMAX(1, WMIN((rect.size.height + dif) / rh, table->rows));
|
||||
|
||||
return range;
|
||||
}
|
||||
@@ -630,30 +682,14 @@ static void setRowSelected(WMTableView *table, unsigned row, Bool flag)
|
||||
int repaint = 0;
|
||||
|
||||
|
||||
if (WMGetArrayItemCount(table->selectedRows) > 0
|
||||
&& !table->canSelectMultiRows) {
|
||||
int r = (int)WMGetFromArray(table->selectedRows, 0);
|
||||
|
||||
WMDeleteFromArray(table->selectedRows, 0);
|
||||
|
||||
drawFullRow(table, r);
|
||||
|
||||
WMPostNotificationName(WMTableViewRowWasUnselectedNotification,
|
||||
table, (void*)r);
|
||||
}
|
||||
|
||||
if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound) {
|
||||
if (!flag) {
|
||||
WMRemoveFromArray(table->selectedRows, (void*)row);
|
||||
WMPostNotificationName(WMTableViewRowWasUnselectedNotification,
|
||||
table, (void*)row);
|
||||
repaint = 1;
|
||||
}
|
||||
} else {
|
||||
if (flag) {
|
||||
WMAddToArray(table->selectedRows, (void*)row);
|
||||
WMPostNotificationName(WMTableViewRowWasSelectedNotification,
|
||||
table, (void*)row);
|
||||
repaint = 1;
|
||||
}
|
||||
}
|
||||
@@ -690,7 +726,7 @@ static void repaintTable(WMTableView *table, int x, int y,
|
||||
|
||||
rows = rowsInRect(table, rect);
|
||||
for (i = rows.position;
|
||||
i < WMIN(rows.position+rows.count, table->rows);
|
||||
i < WMIN(rows.position+rows.count + 1, table->rows);
|
||||
i++) {
|
||||
drawRow(table, i, rect);
|
||||
}
|
||||
@@ -706,9 +742,8 @@ static void stopRowEdit(WMTableView *table, int row)
|
||||
for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
|
||||
column = WMGetFromArray(table->columns, i);
|
||||
|
||||
wassertr(column->delegate && column->delegate->endCellEdit);
|
||||
|
||||
(*column->delegate->endCellEdit)(column->delegate, column, row);
|
||||
if (column->delegate && column->delegate->endCellEdit)
|
||||
(*column->delegate->endCellEdit)(column->delegate, column, row);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,27 +762,85 @@ void WMEditTableViewRow(WMTableView *table, int row)
|
||||
for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
|
||||
column = WMGetFromArray(table->columns, i);
|
||||
|
||||
wassertr(column->delegate && column->delegate->beginCellEdit);
|
||||
|
||||
(*column->delegate->beginCellEdit)(column->delegate, column, row);
|
||||
if (column->delegate && column->delegate->beginCellEdit)
|
||||
(*column->delegate->beginCellEdit)(column->delegate, column, row);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WMSelectTableViewRow(WMTableView *table, int row)
|
||||
{
|
||||
if (table->clickedRow >= 0)
|
||||
setRowSelected(table, table->clickedRow, False);
|
||||
setRowSelected(table, row, True);
|
||||
table->clickedRow = row;
|
||||
|
||||
if (table->action)
|
||||
(*table->action)(table, table->clientData);
|
||||
WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
|
||||
table, NULL);
|
||||
}
|
||||
|
||||
|
||||
void WMReloadTableView(WMTableView *table)
|
||||
{
|
||||
WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);
|
||||
|
||||
repaintTable(table, 0, 0,
|
||||
W_VIEW_WIDTH(table->tableView), rect.size.height);
|
||||
}
|
||||
|
||||
|
||||
void WMNoteTableViewNumberOfRowsChanged(WMTableView *table)
|
||||
{
|
||||
WMReloadTableView(table);
|
||||
}
|
||||
|
||||
|
||||
static void handleTableEvents(XEvent *event, void *data)
|
||||
{
|
||||
WMTableView *table = (WMTableView*)data;
|
||||
int row;
|
||||
|
||||
switch (event->type) {
|
||||
case ButtonPress:
|
||||
setRowSelected(table, event->xbutton.y/table->rowHeight, True);
|
||||
if (event->xbutton.button == Button1) {
|
||||
row = event->xbutton.y/table->rowHeight;
|
||||
if (row != table->clickedRow) {
|
||||
setRowSelected(table, table->clickedRow, False);
|
||||
setRowSelected(table, row, True);
|
||||
table->clickedRow = row;
|
||||
table->dragging = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionNotify:
|
||||
if (table->dragging && event->xmotion.y >= 0) {
|
||||
row = event->xmotion.y/table->rowHeight;
|
||||
if (table->clickedRow != row && row >= 0) {
|
||||
setRowSelected(table, table->clickedRow, False);
|
||||
setRowSelected(table, row, True);
|
||||
table->clickedRow = row;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonRelease:
|
||||
if (event->xbutton.button == Button1) {
|
||||
if (table->action)
|
||||
(*table->action)(table, table->clientData);
|
||||
WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
|
||||
table, NULL);
|
||||
table->dragging = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case Expose:
|
||||
repaintTable(table, event->xexpose.x, event->xexpose.y,
|
||||
event->xexpose.width, event->xexpose.height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -761,6 +854,13 @@ static void handleEvents(XEvent *event, void *data)
|
||||
W_DrawRelief(scr, W_VIEW_DRAWABLE(table->view), 0, 0,
|
||||
W_VIEW_WIDTH(table->view), W_VIEW_HEIGHT(table->view),
|
||||
WRSunken);
|
||||
|
||||
if (event->xexpose.serial == 0) {
|
||||
WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);
|
||||
|
||||
repaintTable(table, rect.pos.x, rect.pos.y,
|
||||
rect.size.width, rect.size.height);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -789,3 +889,34 @@ static void handleResize(W_ViewDelegate *self, WMView *view)
|
||||
}
|
||||
|
||||
|
||||
static void rearrangeHeader(WMTableView *table)
|
||||
{
|
||||
int width;
|
||||
int count;
|
||||
int i;
|
||||
width = 0;
|
||||
|
||||
count = WMGetArrayItemCount(table->columns);
|
||||
for (i = 0; i < count; i++) {
|
||||
WMTableColumn *column = WMGetFromArray(table->columns, i);
|
||||
|
||||
WMMoveWidget(column->titleW, width, 0);
|
||||
WMResizeWidget(column->titleW, column->width-1, table->headerHeight);
|
||||
|
||||
if (i > 0) {
|
||||
WMView *splitter = WMGetFromArray(table->splitters, i-1);
|
||||
|
||||
W_MoveView(splitter, width-1, 0);
|
||||
}
|
||||
width += column->width;
|
||||
}
|
||||
|
||||
wassertr(table->delegate && table->delegate->numberOfRows);
|
||||
|
||||
table->rows = table->delegate->numberOfRows(table->delegate, table);
|
||||
|
||||
W_ResizeView(table->tableView, width+1,
|
||||
table->rows * table->rowHeight + 1);
|
||||
|
||||
table->tableWidth = width + 1;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ typedef struct W_TableColumn WMTableColumn;
|
||||
typedef struct W_TableView WMTableView;
|
||||
|
||||
|
||||
extern const char *WMTableViewRowWasSelectedNotification;
|
||||
extern const char *WMTableViewRowWasUnselectedNotification;
|
||||
extern const char *WMTableViewSelectionDidChangeNotification;
|
||||
|
||||
|
||||
typedef struct WMTableColumnDelegate {
|
||||
@@ -25,7 +24,7 @@ typedef struct WMTableColumnDelegate {
|
||||
void (*beginCellEdit)(struct WMTableColumnDelegate *self, WMTableColumn *column,
|
||||
int row);
|
||||
void (*endCellEdit)(struct WMTableColumnDelegate *self, WMTableColumn *column,
|
||||
int row);
|
||||
int row);
|
||||
} WMTableColumnDelegate;
|
||||
|
||||
|
||||
@@ -50,6 +49,7 @@ void WMSetTableColumnWidth(WMTableColumn *column, unsigned width);
|
||||
void WMSetTableColumnDelegate(WMTableColumn *column,
|
||||
WMTableColumnDelegate *delegate);
|
||||
|
||||
|
||||
WMTableView *WMGetTableColumnTableView(WMTableColumn *column);
|
||||
|
||||
void WMSetTableColumnId(WMTableColumn *column, void *id);
|
||||
@@ -70,10 +70,19 @@ void WMAddTableViewColumn(WMTableView *table, WMTableColumn *column);
|
||||
|
||||
void WMSetTableViewDelegate(WMTableView *table, WMTableViewDelegate *delegate);
|
||||
|
||||
void WMSetTableViewAction(WMTableView *table, WMAction *action,
|
||||
void *clientData);
|
||||
|
||||
void *WMGetTableViewClickedColumn(WMTableView *table);
|
||||
|
||||
int WMGetTableViewClickedRow(WMTableView *table);
|
||||
|
||||
WMView *WMGetTableViewDocumentView(WMTableView *table);
|
||||
|
||||
void WMEditTableViewRow(WMTableView *table, int row);
|
||||
|
||||
|
||||
void WMSelectTableViewRow(WMTableView *table, int row);
|
||||
|
||||
void *WMTableViewDataForCell(WMTableView *table, WMTableColumn *column,
|
||||
int row);
|
||||
|
||||
@@ -87,6 +96,13 @@ void WMSetTableViewBackgroundColor(WMTableView *table, WMColor *color);
|
||||
|
||||
void WMSetTableViewGridColor(WMTableView *table, WMColor *color);
|
||||
|
||||
void WMSetTableViewRowHeight(WMTableView *table, int height);
|
||||
|
||||
void WMReloadTableView(WMTableView *table);
|
||||
|
||||
void WMNoteTableViewNumberOfRowsChanged(WMTableView *table);
|
||||
|
||||
void WMScrollTableViewRowToVisible(WMTableView *table, int row);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user