mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-29 01:42:32 +01:00
- Added WMSetTableViewHasHorizontalScroller()
This commit is contained in:
@@ -52,6 +52,7 @@ Changes since wmaker 0.80.1:
|
|||||||
- Added wstrndup()
|
- Added wstrndup()
|
||||||
- Added WMGetFontName()
|
- Added WMGetFontName()
|
||||||
- Added fontpanel callback
|
- Added fontpanel callback
|
||||||
|
- Added WMSetTableViewHasHorizontalScroller()
|
||||||
|
|
||||||
|
|
||||||
Changes since wmaker 0.80.0:
|
Changes since wmaker 0.80.0:
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ main(int argc, char **argv)
|
|||||||
WMMapWidget(win);
|
WMMapWidget(win);
|
||||||
|
|
||||||
table = WMCreateTableView(win);
|
table = WMCreateTableView(win);
|
||||||
|
WMSetTableViewHasHorizontalScroller(table, 0);
|
||||||
WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
|
WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
|
||||||
WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
|
WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
|
||||||
/*WMSetTableViewGridColor(table, WMGrayColor(scr));*/
|
/*WMSetTableViewGridColor(table, WMGrayColor(scr));*/
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ struct W_TableColumn {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void handleResize(W_ViewDelegate *self, WMView *view);
|
static void handleResize(W_ViewDelegate *self, WMView *view);
|
||||||
|
|
||||||
static void rearrangeHeader(WMTableView *table);
|
static void rearrangeHeader(WMTableView *table);
|
||||||
@@ -168,6 +167,9 @@ struct W_TableView {
|
|||||||
unsigned canSelectRow:1;
|
unsigned canSelectRow:1;
|
||||||
unsigned canSelectMultiRows:1;
|
unsigned canSelectMultiRows:1;
|
||||||
unsigned canDeselectRow:1;
|
unsigned canDeselectRow:1;
|
||||||
|
|
||||||
|
unsigned int hasVScroller:1;
|
||||||
|
unsigned int hasHScroller:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static W_Class tableClass = 0;
|
static W_Class tableClass = 0;
|
||||||
@@ -183,6 +185,7 @@ static W_ViewDelegate viewDelegate = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void reorganizeInterior(WMTableView *table);
|
||||||
|
|
||||||
|
|
||||||
static void handleEvents(XEvent *event, void *data);
|
static void handleEvents(XEvent *event, void *data);
|
||||||
@@ -216,11 +219,21 @@ static WMRect getVisibleRect(WMTableView *table)
|
|||||||
WMSize size = getTotalSize(table);
|
WMSize size = getTotalSize(table);
|
||||||
WMRect rect;
|
WMRect rect;
|
||||||
|
|
||||||
rect.size.height = size.height * WMGetScrollerKnobProportion(table->vscroll);
|
if (table->vscroll) {
|
||||||
rect.size.width = size.width * WMGetScrollerKnobProportion(table->hscroll);
|
rect.size.height = size.height * WMGetScrollerKnobProportion(table->vscroll);
|
||||||
|
rect.pos.y = (size.height - rect.size.height) * WMGetScrollerValue(table->vscroll);
|
||||||
rect.pos.x = (size.width - rect.size.width) * WMGetScrollerValue(table->hscroll);
|
} else {
|
||||||
rect.pos.y = (size.height - rect.size.height) * WMGetScrollerValue(table->vscroll);
|
rect.size.height = size.height;
|
||||||
|
rect.pos.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table->hscroll) {
|
||||||
|
rect.size.width = size.width * WMGetScrollerKnobProportion(table->hscroll);
|
||||||
|
rect.pos.x = (size.width - rect.size.width) * WMGetScrollerValue(table->hscroll);
|
||||||
|
} else {
|
||||||
|
rect.size.width = size.width;
|
||||||
|
rect.pos.x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
@@ -232,28 +245,30 @@ static void scrollToPoint(WMTableView *table, int x, int y)
|
|||||||
int i;
|
int i;
|
||||||
float value, prop;
|
float value, prop;
|
||||||
|
|
||||||
if (size.width > W_VIEW_WIDTH(table->tableView)) {
|
if (table->hscroll) {
|
||||||
prop = (float)W_VIEW_WIDTH(table->tableView) / (float)size.width;
|
if (size.width > W_VIEW_WIDTH(table->tableView)) {
|
||||||
value = (float)x / (float)(size.width - W_VIEW_WIDTH(table->tableView));
|
prop = (float)W_VIEW_WIDTH(table->tableView) / (float)size.width;
|
||||||
} else {
|
value = (float)x / (float)(size.width - W_VIEW_WIDTH(table->tableView));
|
||||||
prop = 1.0;
|
} else {
|
||||||
value = 0.0;
|
prop = 1.0;
|
||||||
}
|
value = 0.0;
|
||||||
WMSetScrollerParameters(table->hscroll, value, prop);
|
}
|
||||||
|
WMSetScrollerParameters(table->hscroll, value, prop);
|
||||||
|
|
||||||
if (size.height > W_VIEW_HEIGHT(table->tableView)) {
|
|
||||||
prop = (float)W_VIEW_HEIGHT(table->tableView) / (float)size.height;
|
|
||||||
value = (float)y / (float)(size.height - W_VIEW_HEIGHT(table->tableView));
|
|
||||||
} else {
|
|
||||||
prop = 1.0;
|
|
||||||
value = 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WMSetScrollerParameters(table->vscroll, value, prop);
|
if (table->vscroll) {
|
||||||
|
if (size.height > W_VIEW_HEIGHT(table->tableView)) {
|
||||||
|
prop = (float)W_VIEW_HEIGHT(table->tableView) / (float)size.height;
|
||||||
|
value = (float)y / (float)(size.height - W_VIEW_HEIGHT(table->tableView));
|
||||||
|
} else {
|
||||||
|
prop = 1.0;
|
||||||
|
value = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
WMSetScrollerParameters(table->vscroll, value, prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (table->editingRow >= 0) {
|
if (table->editingRow >= 0) {
|
||||||
for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
|
for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
|
||||||
WMTableColumn *column;
|
WMTableColumn *column;
|
||||||
@@ -277,34 +292,37 @@ static void adjustScrollers(WMTableView *table)
|
|||||||
float prop, value;
|
float prop, value;
|
||||||
float oprop, ovalue;
|
float oprop, ovalue;
|
||||||
|
|
||||||
if (size.width <= vsize.width) {
|
if (table->hscroll) {
|
||||||
value = 0.0;
|
if (size.width <= vsize.width) {
|
||||||
prop = 1.0;
|
value = 0.0;
|
||||||
} else {
|
prop = 1.0;
|
||||||
oprop = WMGetScrollerKnobProportion(table->hscroll);
|
} else {
|
||||||
if (oprop == 0.0)
|
oprop = WMGetScrollerKnobProportion(table->hscroll);
|
||||||
oprop = 1.0;
|
if (oprop == 0.0)
|
||||||
ovalue = WMGetScrollerValue(table->hscroll);
|
oprop = 1.0;
|
||||||
|
ovalue = WMGetScrollerValue(table->hscroll);
|
||||||
prop = (float)vsize.width/(float)size.width;
|
|
||||||
value = prop*ovalue / oprop;
|
prop = (float)vsize.width/(float)size.width;
|
||||||
|
value = prop*ovalue / oprop;
|
||||||
|
}
|
||||||
|
WMSetScrollerParameters(table->hscroll, value, prop);
|
||||||
}
|
}
|
||||||
WMSetScrollerParameters(table->hscroll, value, prop);
|
|
||||||
|
|
||||||
if (size.height <= vsize.height) {
|
if (table->vscroll) {
|
||||||
value = 0.0;
|
if (size.height <= vsize.height) {
|
||||||
prop = 1.0;
|
value = 0.0;
|
||||||
} else {
|
prop = 1.0;
|
||||||
oprop = WMGetScrollerKnobProportion(table->vscroll);
|
} else {
|
||||||
oprop = WMGetScrollerKnobProportion(table->hscroll);
|
oprop = WMGetScrollerKnobProportion(table->vscroll);
|
||||||
if (oprop == 0.0)
|
if (oprop == 0.0)
|
||||||
oprop = 1.0;
|
oprop = 1.0;
|
||||||
ovalue = WMGetScrollerValue(table->vscroll);
|
ovalue = WMGetScrollerValue(table->vscroll);
|
||||||
|
|
||||||
prop = (float)vsize.height/(float)size.height;
|
prop = (float)vsize.height/(float)size.height;
|
||||||
value = prop*ovalue / oprop;
|
value = prop*ovalue / oprop;
|
||||||
|
}
|
||||||
|
WMSetScrollerParameters(table->vscroll, value, prop);
|
||||||
}
|
}
|
||||||
WMSetScrollerParameters(table->vscroll, value, prop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -499,13 +517,16 @@ WMTableView *WMCreateTableView(WMWidget *parent)
|
|||||||
WMMoveWidget(table->hscroll, 1, 2+table->headerHeight);
|
WMMoveWidget(table->hscroll, 1, 2+table->headerHeight);
|
||||||
WMMapWidget(table->hscroll);
|
WMMapWidget(table->hscroll);
|
||||||
|
|
||||||
|
table->hasHScroller = 1;
|
||||||
|
|
||||||
table->vscroll = WMCreateScroller(table);
|
table->vscroll = WMCreateScroller(table);
|
||||||
WMSetScrollerArrowsPosition(table->vscroll, WSAMaxEnd);
|
WMSetScrollerArrowsPosition(table->vscroll, WSAMaxEnd);
|
||||||
WMSetScrollerAction(table->vscroll, doScroll, table);
|
WMSetScrollerAction(table->vscroll, doScroll, table);
|
||||||
WMMoveWidget(table->vscroll, 1, 2+table->headerHeight);
|
WMMoveWidget(table->vscroll, 1, 2+table->headerHeight);
|
||||||
WMMapWidget(table->vscroll);
|
WMMapWidget(table->vscroll);
|
||||||
|
|
||||||
|
table->hasVScroller = 1;
|
||||||
|
|
||||||
table->header = WMCreateFrame(table);
|
table->header = WMCreateFrame(table);
|
||||||
WMMoveWidget(table->header, 22, 2);
|
WMMoveWidget(table->header, 22, 2);
|
||||||
WMMapWidget(table->header);
|
WMMapWidget(table->header);
|
||||||
@@ -733,6 +754,76 @@ void *WMGetTableViewDataSource(WMTableView *table)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void WMSetTableViewHasHorizontalScroller(WMTableView *tPtr, Bool flag)
|
||||||
|
{
|
||||||
|
if (flag) {
|
||||||
|
if (tPtr->hasHScroller)
|
||||||
|
return;
|
||||||
|
tPtr->hasHScroller = 1;
|
||||||
|
|
||||||
|
tPtr->hscroll = WMCreateScroller(tPtr);
|
||||||
|
WMSetScrollerAction(tPtr->hscroll, doScroll, tPtr);
|
||||||
|
WMSetScrollerArrowsPosition(tPtr->hscroll, WSAMaxEnd);
|
||||||
|
/* make it a horiz. scroller */
|
||||||
|
WMResizeWidget(tPtr->hscroll, 1, 2);
|
||||||
|
|
||||||
|
if (W_VIEW_REALIZED(tPtr->view)) {
|
||||||
|
WMRealizeWidget(tPtr->hscroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
reorganizeInterior(tPtr);
|
||||||
|
|
||||||
|
WMMapWidget(tPtr->hscroll);
|
||||||
|
} else {
|
||||||
|
if (!tPtr->hasHScroller)
|
||||||
|
return;
|
||||||
|
tPtr->hasHScroller = 0;
|
||||||
|
|
||||||
|
WMUnmapWidget(tPtr->hscroll);
|
||||||
|
WMDestroyWidget(tPtr->hscroll);
|
||||||
|
tPtr->hscroll = NULL;
|
||||||
|
|
||||||
|
reorganizeInterior(tPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* not supported by now */
|
||||||
|
void WMSetTableViewHasVerticalScroller(WMTableView *tPtr, Bool flag)
|
||||||
|
{
|
||||||
|
if (flag) {
|
||||||
|
if (tPtr->hasVScroller)
|
||||||
|
return;
|
||||||
|
tPtr->hasVScroller = 1;
|
||||||
|
|
||||||
|
tPtr->vscroll = WMCreateScroller(tPtr);
|
||||||
|
WMSetScrollerAction(tPtr->vscroll, doScroll, tPtr);
|
||||||
|
WMSetScrollerArrowsPosition(tPtr->vscroll, WSAMaxEnd);
|
||||||
|
/* make it a vert. scroller */
|
||||||
|
WMResizeWidget(tPtr->vscroll, 1, 2);
|
||||||
|
|
||||||
|
if (W_VIEW_REALIZED(tPtr->view)) {
|
||||||
|
WMRealizeWidget(tPtr->vscroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
reorganizeInterior(tPtr);
|
||||||
|
|
||||||
|
WMMapWidget(tPtr->vscroll);
|
||||||
|
} else {
|
||||||
|
if (!tPtr->hasVScroller)
|
||||||
|
return;
|
||||||
|
tPtr->hasVScroller = 0;
|
||||||
|
|
||||||
|
WMUnmapWidget(tPtr->vscroll);
|
||||||
|
WMDestroyWidget(tPtr->vscroll);
|
||||||
|
tPtr->vscroll = NULL;
|
||||||
|
|
||||||
|
reorganizeInterior(tPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void WMSetTableViewBackgroundColor(WMTableView *table, WMColor *color)
|
void WMSetTableViewBackgroundColor(WMTableView *table, WMColor *color)
|
||||||
{
|
{
|
||||||
W_SetViewBackgroundColor(table->tableView, color);
|
W_SetViewBackgroundColor(table->tableView, color);
|
||||||
@@ -1160,12 +1251,24 @@ static void handleEvents(XEvent *event, void *data)
|
|||||||
|
|
||||||
|
|
||||||
static void handleResize(W_ViewDelegate *self, WMView *view)
|
static void handleResize(W_ViewDelegate *self, WMView *view)
|
||||||
|
{
|
||||||
|
reorganizeInterior(view->self);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void reorganizeInterior(WMTableView *table)
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
WMTableView *table = view->self;
|
|
||||||
WMSize size = getTotalSize(table);
|
WMSize size = getTotalSize(table);
|
||||||
|
WMView *view = table->view;
|
||||||
int vw, vh;
|
int vw, vh;
|
||||||
|
int hsThickness, vsThickness;
|
||||||
|
|
||||||
|
if (table->vscroll)
|
||||||
|
vsThickness = WMWidgetWidth(table->vscroll);
|
||||||
|
if (table->hscroll)
|
||||||
|
hsThickness = WMWidgetHeight(table->hscroll);
|
||||||
|
|
||||||
width = W_VIEW_WIDTH(view) - 2;
|
width = W_VIEW_WIDTH(view) - 2;
|
||||||
height = W_VIEW_HEIGHT(view) - 3;
|
height = W_VIEW_HEIGHT(view) - 3;
|
||||||
@@ -1177,25 +1280,28 @@ static void handleResize(W_ViewDelegate *self, WMView *view)
|
|||||||
|
|
||||||
WMMoveWidget(table->vscroll, 1, table->headerHeight + 1);
|
WMMoveWidget(table->vscroll, 1, table->headerHeight + 1);
|
||||||
WMResizeWidget(table->vscroll, 20, height + 1);
|
WMResizeWidget(table->vscroll, 20, height + 1);
|
||||||
|
|
||||||
WMMoveWidget(table->hscroll, 20, W_VIEW_HEIGHT(view) - 20 - 1);
|
if (table->hscroll) {
|
||||||
WMResizeWidget(table->hscroll, width-20+1, 20);
|
WMMoveWidget(table->hscroll, vsThickness, W_VIEW_HEIGHT(view) - hsThickness - 1);
|
||||||
|
WMResizeWidget(table->hscroll, width-(vsThickness+1), hsThickness);
|
||||||
|
}
|
||||||
|
|
||||||
if (table->header)
|
if (table->header)
|
||||||
WMResizeWidget(table->header, width - 21, table->headerHeight);
|
WMResizeWidget(table->header, width-(vsThickness+1), table->headerHeight);
|
||||||
|
|
||||||
if (table->viewBuffer) {
|
if (table->viewBuffer) {
|
||||||
WMReleasePixmap(table->viewBuffer);
|
WMReleasePixmap(table->viewBuffer);
|
||||||
table->viewBuffer = NULL;
|
table->viewBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
width -= 20;
|
width -= vsThickness;
|
||||||
height -= 20;
|
height -= hsThickness;
|
||||||
|
|
||||||
|
|
||||||
vw = WMIN(size.width, width);
|
vw = WMIN(size.width, width);
|
||||||
vh = WMIN(size.height, height);
|
vh = WMIN(size.height, height);
|
||||||
|
|
||||||
W_MoveView(table->tableView, 21, 1+table->headerHeight+1);
|
W_MoveView(table->tableView, vsThickness+1, 1+table->headerHeight+1);
|
||||||
W_ResizeView(table->tableView, WMAX(vw, 1), WMAX(vh, 1)+1);
|
W_ResizeView(table->tableView, WMAX(vw, 1), WMAX(vh, 1)+1);
|
||||||
|
|
||||||
adjustScrollers(table);
|
adjustScrollers(table);
|
||||||
|
|||||||
@@ -108,7 +108,11 @@ void WMReloadTableView(WMTableView *table);
|
|||||||
|
|
||||||
void WMNoteTableViewNumberOfRowsChanged(WMTableView *table);
|
void WMNoteTableViewNumberOfRowsChanged(WMTableView *table);
|
||||||
|
|
||||||
void WMScrollTableViewRowToVisible(WMTableView *table, int row);
|
void WMScrollTableViewRowToVisible(WMTableView *table, int row);
|
||||||
|
|
||||||
|
void WMSetTableViewHasHorizontalScroller(WMTableView *tPtr, Bool flag);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user