Switched the image list stuff to a static function/message pair.

This commit is contained in:
Pietro Gagliardi 2014-08-25 11:51:38 -04:00
parent fe01ebbbcd
commit 774e451967
3 changed files with 19 additions and 15 deletions

View File

@ -31,6 +31,19 @@ struct tableData {
HIMAGELIST checkboxImageList; HIMAGELIST checkboxImageList;
}; };
static void tableSetCheckboxImageList(HWND hwnd, struct tableData *t)
{
HIMAGELIST checkboxImageList;
checkboxImageList = makeCheckboxImageList(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
// thanks to Jonathan Potter (http://stackoverflow.com/questions/25354448/why-do-my-owner-data-list-view-state-images-come-up-as-blank-on-windows-xp)
if (SendMessageW(hwnd, LVM_SETCALLBACKMASK, LVIS_STATEIMAGEMASK, 0) == FALSE)
xpanic("error marking state image list as application-managed", GetLastError());
}
static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data) static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
{ {
NMHDR *nmhdr = (NMHDR *) lParam; NMHDR *nmhdr = (NMHDR *) lParam;
@ -72,6 +85,9 @@ static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
tablePushed(t->gotable, -1, -1); // in case button held as drag out tablePushed(t->gotable, -1, -1); // in case button held as drag out
// and let the list view do its thing // and let the list view do its thing
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
case msgTableMakeInitialImageList:
tableSetCheckboxImageList(hwnd, t);
return 0;
// see table.autoresize() in table_windows.go for the column autosize policy // see table.autoresize() in table_windows.go for the column autosize policy
case WM_NOTIFY: // from the contained header control case WM_NOTIFY: // from the contained header control
if (nmhdr->code == HDN_BEGINTRACK) if (nmhdr->code == HDN_BEGINTRACK)
@ -137,19 +153,6 @@ void tableAutosizeColumns(HWND hwnd, int nColumns)
xpanic("error resizing columns of results list view", GetLastError()); xpanic("error resizing columns of results list view", GetLastError());
} }
void tableSetCheckboxImageList(HWND hwnd)
{
HIMAGELIST checkboxImageList;
checkboxImageList = makeCheckboxImageList(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
// thanks to Jonathan Potter (http://stackoverflow.com/questions/25354448/why-do-my-owner-data-list-view-state-images-come-up-as-blank-on-windows-xp)
if (SendMessageW(hwnd, LVM_SETCALLBACKMASK, LVIS_STATEIMAGEMASK, 0) == FALSE)
xpanic("error marking state image list as application-managed", GetLastError());
}
// because Go won't let me do C.WPARAM(-1) // because Go won't let me do C.WPARAM(-1)
intptr_t tableSelectedItem(HWND hwnd) intptr_t tableSelectedItem(HWND hwnd)
{ {

View File

@ -39,7 +39,8 @@ 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_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 // 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.tableAddExtendedStyles(t._hwnd, C.LVS_EX_FULLROWSELECT | C.LVS_EX_SUBITEMIMAGES)
C.tableSetCheckboxImageList(t._hwnd) // this must come after the subclass because it uses one of our private messages
C.SendMessageW(t._hwnd, C.msgTableMakeInitialImageList, 0, 0)
for i := 0; i < ty.NumField(); i++ { for i := 0; i < ty.NumField(); i++ {
C.tableAppendColumn(t._hwnd, C.int(i), toUTF16(ty.Field(i).Name)) C.tableAppendColumn(t._hwnd, C.int(i), toUTF16(ty.Field(i).Name))
} }

View File

@ -38,6 +38,7 @@ enum {
msgEndModal, msgEndModal,
msgAreaKeyDown, msgAreaKeyDown,
msgAreaKeyUp, msgAreaKeyUp,
msgTableMakeInitialImageList,
}; };
// uitask_windows.c // uitask_windows.c
@ -115,7 +116,6 @@ extern void tableAppendColumn(HWND, int, LPWSTR);
extern void tableUpdate(HWND, int); extern void tableUpdate(HWND, int);
extern void tableAddExtendedStyles(HWND, LPARAM); extern void tableAddExtendedStyles(HWND, LPARAM);
extern void tableAutosizeColumns(HWND, int); extern void tableAutosizeColumns(HWND, int);
extern void tableSetCheckboxImageList(HWND);
extern intptr_t tableSelectedItem(HWND); extern intptr_t tableSelectedItem(HWND);
extern void tableSelectItem(HWND, intptr_t); extern void tableSelectItem(HWND, intptr_t);