Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new API functions to get and set the visibility of table headers. #512

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions darwin/table.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ - (id)initWithModel:(uiTableModel *)model;
@interface uiprivTableView : NSTableView {
uiTable *uiprivT;
uiTableModel *uiprivM;
NSTableHeaderView *headerViewRef;
}
- (id)initWithFrame:(NSRect)r uiprivT:(uiTable *)t uiprivM:(uiTableModel *)m;
- (void)restoreHeaderView;
@end

@implementation uiprivTableView
Expand All @@ -26,10 +28,16 @@ - (id)initWithFrame:(NSRect)r uiprivT:(uiTable *)t uiprivM:(uiTableModel *)m
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)
{
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions test/page16.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions unix/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions windows/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down