Added Table.Selected()/Table.Select() and implemented them on Windows.
This commit is contained in:
parent
3cad9aac25
commit
58e95f2399
|
@ -39,7 +39,13 @@ type Table interface {
|
|||
|
||||
// LoadImageList loads the given ImageList into the Table.
|
||||
// This function copies; changes to the ImageList made later will not be reflected by the Table.
|
||||
LoadImageList(ImageList)
|
||||
LoadImageList(imagelist ImageList)
|
||||
|
||||
// Selected and Select get and set the currently selected item in the Table.
|
||||
// Selected returns -1 if no item is selected.
|
||||
// Pass -1 to Select to deselect all items.
|
||||
Selected() int
|
||||
Select(index int)
|
||||
}
|
||||
|
||||
type tablebase struct {
|
||||
|
|
|
@ -122,3 +122,33 @@ void tableSetCheckboxImageList(HWND hwnd)
|
|||
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)
|
||||
intptr_t tableSelectedItem(HWND hwnd)
|
||||
{
|
||||
return (intptr_t) SendMessageW(hwnd, LVM_GETNEXTITEM, (WPARAM) -1, LVNI_SELECTED);
|
||||
}
|
||||
|
||||
void tableSelectItem(HWND hwnd, intptr_t index)
|
||||
{
|
||||
LVITEMW item;
|
||||
LRESULT current;
|
||||
|
||||
// via http://support.microsoft.com/kb/131284
|
||||
// we don't need to clear the other bits; Tables don't support cutting or drag/drop
|
||||
current = SendMessageW(hwnd, LVM_GETNEXTITEM, (WPARAM) -1, LVNI_SELECTED);
|
||||
if (current != (LRESULT) -1) {
|
||||
ZeroMemory(&item, sizeof (LVITEMW));
|
||||
item.mask = LVIF_STATE;
|
||||
item.state = 0;
|
||||
item.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
|
||||
if (SendMessageW(hwnd, LVM_SETITEMSTATE, (WPARAM) current, (LPARAM) (&item)) == FALSE)
|
||||
xpanic("error deselecting current Table item", GetLastError());
|
||||
}
|
||||
ZeroMemory(&item, sizeof (LVITEMW));
|
||||
item.mask = LVIF_STATE;
|
||||
item.state = LVIS_FOCUSED | LVIS_SELECTED;
|
||||
item.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
|
||||
if (SendMessageW(hwnd, LVM_SETITEMSTATE, (WPARAM) index, (LPARAM) (&item)) == FALSE)
|
||||
xpanic("error selecting new Table item", GetLastError());
|
||||
}
|
||||
|
|
|
@ -62,6 +62,18 @@ func (t *table) LoadImageList(il ImageList) {
|
|||
il.apply(t._hwnd, C.LVM_SETIMAGELIST, C.LVSIL_SMALL)
|
||||
}
|
||||
|
||||
func (t *table) Selected() int {
|
||||
t.RLock()
|
||||
defer t.RUnlock()
|
||||
return int(C.tableSelectedItem(t._hwnd))
|
||||
}
|
||||
|
||||
func (t *table) Select(index int) {
|
||||
t.RLock()
|
||||
defer t.RUnlock()
|
||||
C.tableSelectItem(t._hwnd, C.intptr_t(index))
|
||||
}
|
||||
|
||||
//export tableGetCell
|
||||
func tableGetCell(data unsafe.Pointer, item *C.LVITEMW) {
|
||||
t := (*table)(data)
|
||||
|
|
|
@ -105,6 +105,8 @@ extern void tableUpdate(HWND, int);
|
|||
extern void tableAddExtendedStyles(HWND, LPARAM);
|
||||
extern void tableAutosizeColumns(HWND, int);
|
||||
extern void tableSetCheckboxImageList(HWND);
|
||||
extern intptr_t tableSelectedItem(HWND);
|
||||
extern void tableSelectItem(HWND, intptr_t);
|
||||
|
||||
// container_windows.c
|
||||
extern DWORD makeContainerWindowClass(char **);
|
||||
|
|
Loading…
Reference in New Issue