Implemented Table item text grabbing on Windows.

This commit is contained in:
Pietro Gagliardi 2014-07-28 23:29:06 -04:00
parent 3c34f22373
commit 8fcadffeaf
2 changed files with 26 additions and 7 deletions

View File

@ -7,12 +7,17 @@ LPCWSTR xWC_LISTVIEW = WC_LISTVIEW;
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;
NMLVDISPINFOW *fill = (NMLVDISPINFO *) lParam;
switch (uMsg) { switch (uMsg) {
case msgCOMMAND:
/* TODO */
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
case msgNOTIFY: case msgNOTIFY:
/* TODO */ switch (nmhdr->code) {
case LVN_GETDISPINFO:
/* TODO we could probably copy into the buffer provided by the list view control instead... see LVITEM's docs */
tableGetCellText((void *) data, fill->item.iItem, fill->item.iSubItem, &(fill->item.pszText));
return 0;
}
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
case WM_NCDESTROY: case WM_NCDESTROY:
if ((*fv_RemoveWindowSubclass)(hwnd, tableSubProc, id) == FALSE) if ((*fv_RemoveWindowSubclass)(hwnd, tableSubProc, id) == FALSE)
@ -45,7 +50,8 @@ void tableAppendColumn(HWND hwnd, int index, LPCWSTR name)
xpanic("error adding column to Table", GetLastError()); xpanic("error adding column to Table", GetLastError());
} }
void tableUpdate(HWND table, int nItems) void tableUpdate(HWND hwnd, int nItems)
{ {
/* TODO */ if (SendMessageW(hwnd, LVM_SETITEMCOUNT, (WPARAM) nItems, 0) == 0)
xpanic("error setting number of items in Table", GetLastError());
} }

View File

@ -3,6 +3,7 @@
package ui package ui
import ( import (
"fmt"
"unsafe" "unsafe"
"reflect" "reflect"
) )
@ -22,7 +23,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
C.WS_EX_CLIENTEDGE), // WS_EX_CLIENTEDGE without WS_BORDER will show the canonical visual styles border (thanks to MindChild in irc.efnet.net/#winprog) C.WS_EX_CLIENTEDGE), // WS_EX_CLIENTEDGE without WS_BORDER will show the canonical visual styles border (thanks to MindChild in irc.efnet.net/#winprog)
tablebase: b, tablebase: b,
} }
C.setTableSubclass(t.hwnd, unsafe.Pointer(&t)) C.setTableSubclass(t.hwnd, unsafe.Pointer(t))
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))
} }
@ -37,3 +38,15 @@ func (t *table) Unlock() {
defer t.RUnlock() defer t.RUnlock()
C.tableUpdate(t.hwnd, C.int(reflect.Indirect(reflect.ValueOf(t.data)).Len())) C.tableUpdate(t.hwnd, C.int(reflect.Indirect(reflect.ValueOf(t.data)).Len()))
} }
//export tableGetCellText
func tableGetCellText(data unsafe.Pointer, row C.int, col C.int, str *C.LPWSTR) {
t := (*table)(data)
t.RLock()
defer t.RUnlock()
d := reflect.Indirect(reflect.ValueOf(t.data))
datum := d.Index(int(row)).Field(int(col))
s := fmt.Sprintf("%v", datum)
// TODO get rid of conversions
*str = C.LPWSTR(unsafe.Pointer(toUTF16(s)))
}