diff --git a/redo/table_windows.c b/redo/table_windows.c index a9039f0..151fe06 100644 --- a/redo/table_windows.c +++ b/redo/table_windows.c @@ -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) { + NMHDR *nmhdr = (NMHDR *) lParam; + NMLVDISPINFOW *fill = (NMLVDISPINFO *) lParam; + switch (uMsg) { - case msgCOMMAND: - /* TODO */ - return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); 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); case WM_NCDESTROY: 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()); } -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()); } diff --git a/redo/table_windows.go b/redo/table_windows.go index 8dd9049..6839be0 100644 --- a/redo/table_windows.go +++ b/redo/table_windows.go @@ -3,6 +3,7 @@ package ui import ( + "fmt" "unsafe" "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) tablebase: b, } - C.setTableSubclass(t.hwnd, unsafe.Pointer(&t)) + C.setTableSubclass(t.hwnd, unsafe.Pointer(t)) for i := 0; i < ty.NumField(); i++ { C.tableAppendColumn(t.hwnd, C.int(i), toUTF16(ty.Field(i).Name)) } @@ -37,3 +38,15 @@ func (t *table) Unlock() { defer t.RUnlock() 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))) +}