mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 21:08:08 +01:00
tableview field editor delegates
This commit is contained in:
@@ -4,24 +4,27 @@ AUTOMAKE_OPTIONS = no-dependencies
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
include_HEADERS = wtableview.h tabledelegates.h fieldeditor.h
|
include_HEADERS = wtableview.h tabledelegates.h
|
||||||
|
|
||||||
|
|
||||||
lib_LIBRARIES = libExtraWINGs.a
|
lib_LIBRARIES = libExtraWINGs.a
|
||||||
|
|
||||||
|
noinst_PROGRAMS = test
|
||||||
|
|
||||||
EXTRA_DIST =
|
EXTRA_DIST =
|
||||||
|
|
||||||
libExtraWINGs_a_SOURCES = \
|
libExtraWINGs_a_SOURCES = \
|
||||||
wtableview.c \
|
wtableview.c \
|
||||||
tabledelegates.c \
|
tabledelegates.c \
|
||||||
fieldeditor.c \
|
|
||||||
wtableview.h \
|
wtableview.h \
|
||||||
tabledelegates.h \
|
tabledelegates.h
|
||||||
fieldeditor.h
|
|
||||||
|
|
||||||
|
|
||||||
INCLUDES = -I$(top_srcdir)/wrlib -I$(top_srcdir)/WINGs \
|
INCLUDES = -I$(top_srcdir)/wrlib -I$(top_srcdir)/WINGs \
|
||||||
-DRESOURCE_PATH=\"$(datadir)/WINGs\" @HEADER_SEARCH_PATH@ -DDEBUG
|
-DRESOURCE_PATH=\"$(datadir)/WINGs\" @HEADER_SEARCH_PATH@ -DDEBUG
|
||||||
|
|
||||||
|
LDADD= $(top_builddir)/WINGs/libWINGs.a $(top_builddir)/wrlib/libwraster.la \
|
||||||
|
@LIBPL@
|
||||||
|
|
||||||
|
test_LDADD = wtableview.o tabledelegates.o $(LDADD)
|
||||||
|
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <WINGs.h>
|
|
||||||
|
|
||||||
#include "wtableview.h"
|
|
||||||
|
|
||||||
#include "fieldeditor.h"
|
|
||||||
|
|
||||||
|
|
||||||
WFStringEditor *WFCreateStringEditor(WMScreen *scr)
|
|
||||||
{
|
|
||||||
WFStringEditor *editor = wmalloc(sizeof(WFStringEditor));
|
|
||||||
|
|
||||||
editor->scr = scr;
|
|
||||||
editor->field = NULL;
|
|
||||||
editor->font = WMSystemFontOfSize(scr, 12);
|
|
||||||
editor->gc = WMColorGC(WMBlackColor(scr));
|
|
||||||
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void WFStringEditorTableDraw(WFStringEditor *self, Drawable d,
|
|
||||||
void *data, WMRect rect)
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
XRectangle rects[1];
|
|
||||||
|
|
||||||
x = rect.pos.x + 5;
|
|
||||||
y = rect.pos.y + (rect.size.height - WMFontHeight(self->font))/2;
|
|
||||||
|
|
||||||
rects[0].x = rect.pos.x+1;
|
|
||||||
rects[0].y = rect.pos.y+1;
|
|
||||||
rects[0].width = rect.size.width-2;
|
|
||||||
rects[0].height = rect.size.height-2;
|
|
||||||
XSetClipRectangles(WMScreenDisplay(self->scr), self->gc, 0, 0,
|
|
||||||
rects, 1, YXSorted);
|
|
||||||
WMDrawString(self->scr, d, self->gc, self->font, x, y, data, strlen(data));
|
|
||||||
XSetClipMask(WMScreenDisplay(self->scr), self->gc, None);
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
WMTextField *field;
|
|
||||||
WMScreen *scr;
|
|
||||||
GC gc;
|
|
||||||
WMFont *font;
|
|
||||||
} WFStringEditor;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
|
|
||||||
} WFStringSelector;
|
|
||||||
|
|
||||||
|
|
||||||
WFStringEditor *WFCreateStringEditor();
|
|
||||||
|
|
||||||
void WFStringEditorTableDraw(WFStringEditor *self, Drawable d, void *data, WMRect rect);
|
|
||||||
|
|
||||||
@@ -2,35 +2,122 @@
|
|||||||
|
|
||||||
#include <WINGs.h>
|
#include <WINGs.h>
|
||||||
|
|
||||||
#include "fieldeditor.h"
|
|
||||||
#include "wtableview.h"
|
#include "wtableview.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
WMTextField *widget;
|
||||||
|
WMTableView *table;
|
||||||
|
WMFont *font;
|
||||||
|
GC gc;
|
||||||
|
GC selGc;
|
||||||
|
GC selTextGc;
|
||||||
|
} StringEditorData;
|
||||||
|
|
||||||
|
|
||||||
|
static void stringDraw(WMScreen *scr, Drawable d, GC gc,
|
||||||
|
GC sgc, GC stgc, WMFont *font, void *data,
|
||||||
|
WMRect rect, Bool selected)
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
XRectangle rects[1];
|
||||||
|
Display *dpy = WMScreenDisplay(scr);
|
||||||
|
|
||||||
|
x = rect.pos.x + 5;
|
||||||
|
y = rect.pos.y + (rect.size.height - WMFontHeight(font))/2;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
WMDrawString(scr, d, gc, font, x, y,
|
||||||
|
data, strlen(data));
|
||||||
|
} else {
|
||||||
|
XFillRectangles(dpy, d, sgc, rects, 1);
|
||||||
|
|
||||||
|
WMDrawString(scr, d, stgc, font, x, y,
|
||||||
|
data, strlen(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
XSetClipMask(dpy, gc, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void cellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
|
static void cellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
|
||||||
int row)
|
int row)
|
||||||
{
|
{
|
||||||
// WTStringDelegate *strdel = (WTStringDelegate*)self->data;
|
StringEditorData *strdata = (StringEditorData*)self->data;
|
||||||
WMTableView *table = WMGetTableColumnTableView(column);
|
WMTableView *table = WMGetTableColumnTableView(column);
|
||||||
|
|
||||||
WFStringEditorTableDraw(self->data,
|
stringDraw(WMWidgetScreen(table),
|
||||||
WMViewXID(WMGetTableViewDocumentView(table)),
|
WMViewXID(WMGetTableViewDocumentView(table)),
|
||||||
WMTableViewDataForCell(table, column, row),
|
strdata->gc, strdata->selGc, strdata->selTextGc, strdata->font,
|
||||||
WMTableViewRectForCell(table, column, row));
|
WMTableViewDataForCell(table, column, row),
|
||||||
|
WMTableViewRectForCell(table, column, row),
|
||||||
|
False);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void selectedCellPainter(WMTableColumnDelegate *self,
|
||||||
|
WMTableColumn *column, int row)
|
||||||
|
{
|
||||||
|
StringEditorData *strdata = (StringEditorData*)self->data;
|
||||||
|
WMTableView *table = WMGetTableColumnTableView(column);
|
||||||
|
|
||||||
|
stringDraw(WMWidgetScreen(table),
|
||||||
|
WMViewXID(WMGetTableViewDocumentView(table)),
|
||||||
|
strdata->gc, strdata->selGc, strdata->selTextGc, strdata->font,
|
||||||
|
WMTableViewDataForCell(table, column, row),
|
||||||
|
WMTableViewRectForCell(table, column, row),
|
||||||
|
True);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void beginCellEdit(WMTableColumnDelegate *self,
|
||||||
|
WMTableColumn *column, int row)
|
||||||
|
{
|
||||||
|
StringEditorData *strdata = (StringEditorData*)self->data;
|
||||||
|
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
|
||||||
|
void *data = WMTableViewDataForCell(strdata->table, column, row);
|
||||||
|
|
||||||
|
WMSetTextFieldText(strdata->widget, (char*)data);
|
||||||
|
WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
|
||||||
|
WMResizeWidget(strdata->widget, rect.size.width+1, rect.size.height+1);
|
||||||
|
|
||||||
|
WMMapWidget(strdata->widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WMTableColumnDelegate *WTCreateStringDelegate(WMTableView *parent)
|
WMTableColumnDelegate *WTCreateStringDelegate(WMTableView *parent)
|
||||||
{
|
{
|
||||||
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
|
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
|
||||||
|
WMScreen *scr = WMWidgetScreen(parent);
|
||||||
|
StringEditorData *data = wmalloc(sizeof(StringEditorData));
|
||||||
|
|
||||||
delegate->data = wmalloc(sizeof(StringEditorData));
|
data->widget = WMCreateTextField(parent);
|
||||||
delegate->data->widget = WFCreateStringEditor(WMWidgetScreen(parent));
|
W_ReparentView(WMWidgetView(data->widget),
|
||||||
delegate->data->table = parent;
|
WMGetTableViewDocumentView(parent),
|
||||||
|
0, 0);
|
||||||
|
data->table = parent;
|
||||||
|
data->font = WMSystemFontOfSize(scr, 12);
|
||||||
|
data->selGc = WMColorGC(WMDarkGrayColor(scr));
|
||||||
|
data->selTextGc = WMColorGC(WMWhiteColor(scr));
|
||||||
|
data->gc = WMColorGC(WMBlackColor(scr));
|
||||||
|
|
||||||
|
delegate->data = data;
|
||||||
delegate->drawCell = cellPainter;
|
delegate->drawCell = cellPainter;
|
||||||
delegate->beginCellEdit = NULL;
|
delegate->drawSelectedCell = selectedCellPainter;
|
||||||
|
delegate->beginCellEdit = beginCellEdit;
|
||||||
delegate->endCellEdit = NULL;
|
delegate->endCellEdit = NULL;
|
||||||
|
|
||||||
return delegate;
|
return delegate;
|
||||||
|
|||||||
85
WINGs/Extras/test.c
Normal file
85
WINGs/Extras/test.c
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include <WINGs.h>
|
||||||
|
#include "wtableview.h"
|
||||||
|
#include "tabledelegates.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int numberOfRows(WMTableViewDelegate *self, WMTableView *table)
|
||||||
|
{
|
||||||
|
return 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row)
|
||||||
|
{
|
||||||
|
WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column);
|
||||||
|
|
||||||
|
return "TESTE";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static WMTableViewDelegate delegate = {
|
||||||
|
NULL,
|
||||||
|
numberOfRows,
|
||||||
|
valueForCell,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
Display *dpy = XOpenDisplay("");
|
||||||
|
WMScreen *scr;
|
||||||
|
WMWindow *win;
|
||||||
|
WMTableView *table;
|
||||||
|
WMTableColumn *col;
|
||||||
|
WMTableColumnDelegate *colDeleg;
|
||||||
|
|
||||||
|
WMInitializeApplication("test", &argc, argv);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dpy = XOpenDisplay("");
|
||||||
|
if (!dpy) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
|
||||||
|
|
||||||
|
|
||||||
|
win = WMCreateWindow(scr, "eweq");
|
||||||
|
WMResizeWidget(win, 400, 200);
|
||||||
|
WMMapWidget(win);
|
||||||
|
|
||||||
|
table = WMCreateTableView(win);
|
||||||
|
WMResizeWidget(table, 400, 200);
|
||||||
|
WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
|
||||||
|
WMSetTableViewGridColor(table, WMGrayColor(scr));
|
||||||
|
WMSetTableViewHeaderHeight(table, 20);
|
||||||
|
WMSetTableViewDelegate(table, &delegate);
|
||||||
|
|
||||||
|
colDeleg = WTCreateStringDelegate(table);
|
||||||
|
|
||||||
|
col = WMCreateTableColumn("Group");
|
||||||
|
WMSetTableColumnWidth(col, 180);
|
||||||
|
WMAddTableViewColumn(table, col);
|
||||||
|
WMSetTableColumnDelegate(col, colDeleg);
|
||||||
|
WMSetTableColumnId(col, (void*)1);
|
||||||
|
|
||||||
|
colDeleg = WTCreateStringDelegate(table);
|
||||||
|
|
||||||
|
col = WMCreateTableColumn("Package");
|
||||||
|
WMSetTableColumnWidth(col, 240);
|
||||||
|
WMAddTableViewColumn(table, col);
|
||||||
|
WMSetTableColumnDelegate(col, colDeleg);
|
||||||
|
WMSetTableColumnId(col, (void*)2);
|
||||||
|
|
||||||
|
|
||||||
|
WMMapWidget(table);
|
||||||
|
WMRealizeWidget(win);
|
||||||
|
WMScreenMainLoop(scr);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,11 @@
|
|||||||
|
|
||||||
#include "wtableview.h"
|
#include "wtableview.h"
|
||||||
|
|
||||||
|
|
||||||
|
const char *WMTableViewRowWasSelectedNotification = "WMTableViewRowWasSelectedNotification";
|
||||||
|
const char *WMTableViewRowWasUnselectedNotification = "WMTableViewRowWasUnselectedNotification";
|
||||||
|
|
||||||
|
|
||||||
struct W_TableColumn {
|
struct W_TableColumn {
|
||||||
WMTableView *table;
|
WMTableView *table;
|
||||||
WMWidget *titleW;
|
WMWidget *titleW;
|
||||||
@@ -122,7 +127,9 @@ struct W_TableView {
|
|||||||
|
|
||||||
WMArray *columns;
|
WMArray *columns;
|
||||||
WMArray *splitters;
|
WMArray *splitters;
|
||||||
|
|
||||||
|
WMArray *selectedRows;
|
||||||
|
|
||||||
int tableWidth;
|
int tableWidth;
|
||||||
|
|
||||||
int rows;
|
int rows;
|
||||||
@@ -141,6 +148,9 @@ struct W_TableView {
|
|||||||
unsigned rowHeight;
|
unsigned rowHeight;
|
||||||
|
|
||||||
unsigned drawsGrid:1;
|
unsigned drawsGrid:1;
|
||||||
|
unsigned canSelectRow:1;
|
||||||
|
unsigned canSelectMultiRows:1;
|
||||||
|
unsigned canDeselectRow:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static W_Class tableClass = 0;
|
static W_Class tableClass = 0;
|
||||||
@@ -193,8 +203,24 @@ static void scrollObserver(void *self, WMNotification *notif)
|
|||||||
static void splitterHandler(XEvent *event, void *data)
|
static void splitterHandler(XEvent *event, void *data)
|
||||||
{
|
{
|
||||||
WMTableView *table = (WMTableView*)data;
|
WMTableView *table = (WMTableView*)data;
|
||||||
|
int done = 0;
|
||||||
|
|
||||||
|
while (!done) {
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
|
WMMaskEvent(event->xany.display, ButtonMotionMask|ButtonReleaseMask,
|
||||||
|
&ev);
|
||||||
|
|
||||||
|
switch (event->type) {
|
||||||
|
case MotionNotify:
|
||||||
|
printf("%i\n", event->xmotion.x);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ButtonRelease:
|
||||||
|
done = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,10 +275,11 @@ WMTableView *WMCreateTableView(WMWidget *parent)
|
|||||||
|
|
||||||
|
|
||||||
table->tableView = W_CreateView(W_VIEW(parent));
|
table->tableView = W_CreateView(W_VIEW(parent));
|
||||||
if (!table->tableView)
|
if (!table->tableView)
|
||||||
goto error;
|
goto error;
|
||||||
|
table->tableView->self = table;
|
||||||
W_ResizeView(table->tableView, 100, 1000);
|
W_ResizeView(table->tableView, 100, 1000);
|
||||||
W_MapView(table->tableView);
|
W_MapView(table->tableView);
|
||||||
|
|
||||||
WMSetScrollViewContentView(table->scrollView, table->tableView);
|
WMSetScrollViewContentView(table->scrollView, table->tableView);
|
||||||
|
|
||||||
@@ -277,14 +304,18 @@ WMTableView *WMCreateTableView(WMWidget *parent)
|
|||||||
|
|
||||||
table->columns = WMCreateArray(4);
|
table->columns = WMCreateArray(4);
|
||||||
table->splitters = WMCreateArray(4);
|
table->splitters = WMCreateArray(4);
|
||||||
|
|
||||||
|
table->selectedRows = WMCreateArray(16);
|
||||||
|
|
||||||
table->splitterCursor = XCreateFontCursor(WMScreenDisplay(scr),
|
table->splitterCursor = XCreateFontCursor(WMScreenDisplay(scr),
|
||||||
XC_sb_h_double_arrow);
|
XC_sb_h_double_arrow);
|
||||||
|
|
||||||
|
table->canSelectRow = 1;
|
||||||
|
|
||||||
WMCreateEventHandler(table->view, ExposureMask|StructureNotifyMask,
|
WMCreateEventHandler(table->view, ExposureMask|StructureNotifyMask,
|
||||||
handleEvents, table);
|
handleEvents, table);
|
||||||
|
|
||||||
WMCreateEventHandler(table->tableView, ExposureMask,
|
WMCreateEventHandler(table->tableView, ExposureMask|ButtonPressMask,
|
||||||
handleTableEvents, table);
|
handleTableEvents, table);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
@@ -338,8 +369,8 @@ void WMAddTableViewColumn(WMTableView *table, WMTableColumn *column)
|
|||||||
W_MapView(splitter);
|
W_MapView(splitter);
|
||||||
|
|
||||||
W_SetViewCursor(splitter, table->splitterCursor);
|
W_SetViewCursor(splitter, table->splitterCursor);
|
||||||
WMCreateEventHandler(splitter, ButtonPressMask|ButtonReleaseMask
|
WMCreateEventHandler(splitter, ButtonPressMask,
|
||||||
|PointerMotionMask, splitterHandler, table);
|
splitterHandler, table);
|
||||||
|
|
||||||
WMAddToArray(table->splitters, splitter);
|
WMAddToArray(table->splitters, splitter);
|
||||||
}
|
}
|
||||||
@@ -448,6 +479,7 @@ void WMSetTableViewGridColor(WMTableView *table, WMColor *color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void drawGrid(WMTableView *table, WMRect rect)
|
static void drawGrid(WMTableView *table, WMRect rect)
|
||||||
{
|
{
|
||||||
WMScreen *scr = WMWidgetScreen(table);
|
WMScreen *scr = WMWidgetScreen(table);
|
||||||
@@ -550,13 +582,73 @@ static void drawRow(WMTableView *table, int row, WMRect clipRect)
|
|||||||
int i;
|
int i;
|
||||||
WMRange cols = columnsInRect(table, clipRect);
|
WMRange cols = columnsInRect(table, clipRect);
|
||||||
WMTableColumn *column;
|
WMTableColumn *column;
|
||||||
|
|
||||||
for (i = cols.position; i < cols.position+cols.count; i++) {
|
for (i = cols.position; i < cols.position+cols.count; i++) {
|
||||||
column = WMGetFromArray(table->columns, i);
|
column = WMGetFromArray(table->columns, i);
|
||||||
|
|
||||||
wassertr(column->delegate && column->delegate->drawCell);
|
wassertr(column->delegate && column->delegate->drawCell);
|
||||||
|
|
||||||
(*column->delegate->drawCell)(column->delegate, column, row);
|
if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound)
|
||||||
|
(*column->delegate->drawSelectedCell)(column->delegate, column, row);
|
||||||
|
else
|
||||||
|
(*column->delegate->drawCell)(column->delegate, column, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void drawFullRow(WMTableView *table, int row)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
WMTableColumn *column;
|
||||||
|
|
||||||
|
for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
|
||||||
|
column = WMGetFromArray(table->columns, i);
|
||||||
|
|
||||||
|
wassertr(column->delegate && column->delegate->drawCell);
|
||||||
|
|
||||||
|
if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound)
|
||||||
|
(*column->delegate->drawSelectedCell)(column->delegate, column, row);
|
||||||
|
else
|
||||||
|
(*column->delegate->drawCell)(column->delegate, column, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repaint) {
|
||||||
|
drawFullRow(table, row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,11 +686,31 @@ static void repaintTable(WMTableView *table, int x, int y,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void startRowEdit(WMTableView *table, int row)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
WMTableColumn *column;
|
||||||
|
|
||||||
|
for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
|
||||||
|
column = WMGetFromArray(table->columns, i);
|
||||||
|
|
||||||
|
wassertr(column->delegate && column->delegate->drawCell);
|
||||||
|
|
||||||
|
(*column->delegate->beginCellEdit)(column->delegate, column, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void handleTableEvents(XEvent *event, void *data)
|
static void handleTableEvents(XEvent *event, void *data)
|
||||||
{
|
{
|
||||||
WMTableView *table = (WMTableView*)data;
|
WMTableView *table = (WMTableView*)data;
|
||||||
|
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
|
case ButtonPress:
|
||||||
|
setRowSelected(table, event->xbutton.y/table->rowHeight, True);
|
||||||
|
startRowEdit(table, event->xbutton.y/table->rowHeight);
|
||||||
|
break;
|
||||||
|
|
||||||
case Expose:
|
case Expose:
|
||||||
repaintTable(table, event->xexpose.x, event->xexpose.y,
|
repaintTable(table, event->xexpose.x, event->xexpose.y,
|
||||||
event->xexpose.width, event->xexpose.height);
|
event->xexpose.width, event->xexpose.height);
|
||||||
|
|||||||
@@ -12,12 +12,20 @@ typedef struct W_TableColumn WMTableColumn;
|
|||||||
typedef struct W_TableView WMTableView;
|
typedef struct W_TableView WMTableView;
|
||||||
|
|
||||||
|
|
||||||
|
extern const char *WMTableViewRowWasSelectedNotification;
|
||||||
|
extern const char *WMTableViewRowWasUnselectedNotification;
|
||||||
|
|
||||||
|
|
||||||
typedef struct WMTableColumnDelegate {
|
typedef struct WMTableColumnDelegate {
|
||||||
void *data;
|
void *data;
|
||||||
void (*drawCell)(struct WMTableColumnDelegate *self, WMTableColumn *column,
|
void (*drawCell)(struct WMTableColumnDelegate *self, WMTableColumn *column,
|
||||||
int row);
|
int row);
|
||||||
void (*editCell)(struct WMTableColumnDelegate *self, WMTableColumn *column,
|
void (*drawSelectedCell)(struct WMTableColumnDelegate *self,
|
||||||
int row, XEvent *event);
|
WMTableColumn *column, int row);
|
||||||
|
void (*beginCellEdit)(struct WMTableColumnDelegate *self, WMTableColumn *column,
|
||||||
|
int row);
|
||||||
|
void (*endCellEdit)(struct WMTableColumnDelegate *self, WMTableColumn *column,
|
||||||
|
int row);
|
||||||
} WMTableColumnDelegate;
|
} WMTableColumnDelegate;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user