This commit is contained in:
Angelo Haller 2021-01-02 10:21:37 -05:00 committed by GitHub
commit 9ada04140f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 0 deletions

View File

@ -14,8 +14,10 @@
@interface uiprivTableView : NSTableView {
uiTable *uiprivT;
uiTableModel *uiprivM;
NSTableHeaderView *headerViewRef;
}
- (id)initWithFrame:(NSRect)r uiprivT:(uiTable *)t uiprivM:(uiTableModel *)m;
- (void)restoreHeaderView;
@end
@implementation uiprivTableView
@ -26,10 +28,16 @@
if (self) {
self->uiprivT = t;
self->uiprivM = m;
self->headerViewRef = [self headerView];
}
return self;
}
- (void)restoreHeaderView
{
[self setHeaderView:self->headerViewRef];
}
// TODO is this correct for overflow scrolling?
static void setBackgroundColor(uiprivTableView *t, NSTableRowView *rv, NSInteger row)
{
@ -170,6 +178,19 @@ static void uiTableDestroy(uiControl *c)
uiFreeControl(uiControl(t));
}
int uiTableHeaderVisible(uiTable *t)
{
return [t->tv headerView] != nil;
}
void uiTableHeaderSetVisible(uiTable *t, int visible)
{
if (visible)
[(uiprivTableView*)t->tv restoreHeaderView];
else
[t->tv setHeaderView:nil];
}
uiTable *uiNewTable(uiTableParams *p)
{
uiTable *t;

View File

@ -98,11 +98,20 @@ static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row,
checkStates[row] = uiTableValueInt(val);
}
void headerVisibleToggled(uiCheckbox *c, void *data)
{
uiTable *t = data;
uiTableHeaderSetVisible(t, uiCheckboxChecked(c));
uiCheckboxSetChecked(c, uiTableHeaderVisible(t));
}
static uiTableModel *m;
uiBox *makePage16(void)
{
uiBox *page16;
uiBox *controls;
uiCheckbox *headerVisible;
uiTable *t;
uiTableParams p;
uiTableTextColumnOptionalParams tp;
@ -119,6 +128,8 @@ uiBox *makePage16(void)
memset(checkStates, 0, 15 * sizeof (int));
page16 = newVerticalBox();
controls = newHorizontalBox();
uiBoxAppend(page16, uiControl(controls), 0);
mh.NumColumns = modelNumColumns;
mh.ColumnType = modelColumnType;
@ -152,6 +163,11 @@ uiBox *makePage16(void)
uiTableAppendProgressBarColumn(t, "Progress Bar",
8);
headerVisible = uiNewCheckbox("Header Visible");
uiCheckboxSetChecked(headerVisible, uiTableHeaderVisible(t));
uiCheckboxOnToggled(headerVisible, headerVisibleToggled, t);
uiBoxAppend(controls, uiControl(headerVisible), 0);
return page16;
}

7
ui.h
View File

@ -1455,6 +1455,13 @@ _UI_EXTERN void uiTableAppendButtonColumn(uiTable *t,
int buttonModelColumn,
int buttonClickableModelColumn);
// uiTableHeaderVisible() returns whether the table header is visible
// or not.
_UI_EXTERN int uiTableHeaderVisible(uiTable *t);
// uiTableHeaderSetVisible() sets the visibility of the table header.
_UI_EXTERN void uiTableHeaderSetVisible(uiTable *t, int visible);
// uiNewTable() creates a new uiTable with the specified parameters.
_UI_EXTERN uiTable *uiNewTable(uiTableParams *params);

View File

@ -477,6 +477,16 @@ void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonModelColu
g_ptr_array_add(t->columnParams, p);
}
int uiTableHeaderVisible(uiTable *t)
{
return gtk_tree_view_get_headers_visible(t->tv);
}
void uiTableHeaderSetVisible(uiTable *t, int visible)
{
gtk_tree_view_set_headers_visible(t->tv, visible);
}
uiUnixControlAllDefaultsExceptDestroy(uiTable)
static void uiTableDestroy(uiControl *c)

View File

@ -479,6 +479,26 @@ void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonModelColu
p->buttonClickableModelColumn = buttonClickableModelColumn;
}
int uiTableHeaderVisible(uiTable *t)
{
HWND header = ListView_GetHeader(t->hwnd);
if (header) {
LONG style = GetWindowLong(header, GWL_STYLE);
return !(style & HDS_HIDDEN);
}
// TODO abort here?
return 0;
}
void uiTableHeaderSetVisible(uiTable *t, int visible)
{
LONG style = GetWindowLong(t->hwnd, GWL_STYLE);
if (visible)
SetWindowLong(t->hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
else
SetWindowLong(t->hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
}
uiTable *uiNewTable(uiTableParams *p)
{
uiTable *t;