From d7c173cc05f139d012618e48e2dbfc4454732126 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 17 Aug 2014 15:30:10 -0400 Subject: [PATCH] Began implementing checkboxes in the Windows Table. --- redo/imagelist_windows.go | 3 +-- redo/table_windows.c | 7 +++++++ redo/table_windows.go | 20 +++++++++++++++++--- redo/uitask_windows.c | 1 + redo/winapi_windows.h | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/redo/imagelist_windows.go b/redo/imagelist_windows.go index 479e9a5..37924bd 100644 --- a/redo/imagelist_windows.go +++ b/redo/imagelist_windows.go @@ -41,6 +41,5 @@ func (i *imagelist) apply(hwnd C.HWND, uMsg C.UINT, wParam C.WPARAM) { for index := range i.list { C.addImage(il, hwnd, i.list[index], C.int(i.width[index]), C.int(i.height[index]), width, height) } -// C.applyImageList(hwnd, uMsg, wParam, il) - C.applyImageList(hwnd, uMsg, wParam, C.checkboxImageList) + C.applyImageList(hwnd, uMsg, wParam, il) } diff --git a/redo/table_windows.c b/redo/table_windows.c index d5ca418..775d4e6 100644 --- a/redo/table_windows.c +++ b/redo/table_windows.c @@ -75,3 +75,10 @@ void tableAutosizeColumns(HWND hwnd, int nColumns) if (SendMessageW(hwnd, LVM_SETCOLUMNWIDTH, (WPARAM) i, (LPARAM) LVSCW_AUTOSIZE_USEHEADER) == FALSE) xpanic("error resizing columns of results list view", GetLastError()); } + +void tableSetCheckboxImageList(HWND hwnd) +{ + if (SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM) checkboxImageList) == (LRESULT) NULL) +;//TODO xpanic("error setting image list", GetLastError()); + // TODO free old one here if any/different +} diff --git a/redo/table_windows.go b/redo/table_windows.go index b65202a..c90a6fa 100644 --- a/redo/table_windows.go +++ b/redo/table_windows.go @@ -29,6 +29,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table { // LVS_EX_FULLROWSELECT gives us selection across the whole row, not just the leftmost column; this makes the list view work like on other platforms // LVS_EX_SUBITEMIMAGES gives us images in subitems, which will be important when both images and checkboxes are added C.tableAddExtendedStyles(t._hwnd, C.LVS_EX_FULLROWSELECT | C.LVS_EX_SUBITEMIMAGES) + C.tableSetCheckboxImageList(t._hwnd) for i := 0; i < ty.NumField(); i++ { C.tableAppendColumn(t._hwnd, C.int(i), toUTF16(ty.Field(i).Name)) } @@ -61,9 +62,22 @@ func tableGetCell(data unsafe.Pointer, item *C.LVITEMW) { d := reflect.Indirect(reflect.ValueOf(t.data)) datum := d.Index(int(item.iItem)).Field(int(item.iSubItem)) // TODO figure out why changing item.mask causes crashes or why "it just works" - switch d := datum.Interface().(type) { - case ImageIndex: - item.iImage = C.int(d) + switch { + case datum.Type() == reflect.TypeOf(ImageIndex(0)): + item.iImage = C.int(datum.Interface().(ImageIndex)) + case datum.Kind() == reflect.Bool: + item.stateMask = C.LVIS_STATEIMAGEMASK + // state image index is 1-based + curstate := ((item.state & C.LVIS_STATEIMAGEMASK) >> 12) + if curstate > 0 { + curstate-- + } + if datum.Bool() == true { + curstate |= C.checkboxStateChecked + } else { + curstate &^= C.checkboxStateChecked + } + item.state = (curstate + 1) << 12 default: s := fmt.Sprintf("%v", datum) item.pszText = toUTF16(s) diff --git a/redo/uitask_windows.c b/redo/uitask_windows.c index 7a20bbe..85203da 100644 --- a/redo/uitask_windows.c +++ b/redo/uitask_windows.c @@ -82,6 +82,7 @@ static LRESULT CALLBACK msgwinproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l // initial makeCheckboxImageList(hwnd); return 0; + // TODO respond to WM_THEMECHANGED case msgRequest: doissue((void *) lParam); return 0; diff --git a/redo/winapi_windows.h b/redo/winapi_windows.h index c937f64..cf0f2b3 100644 --- a/redo/winapi_windows.h +++ b/redo/winapi_windows.h @@ -104,6 +104,7 @@ extern void tableAppendColumn(HWND, int, LPWSTR); extern void tableUpdate(HWND, int); extern void tableAddExtendedStyles(HWND, LPARAM); extern void tableAutosizeColumns(HWND, int); +extern void tableSetCheckboxImageList(HWND); // container_windows.c extern DWORD makeContainerWindowClass(char **);