Implemented reasonable table column autosizing on Windows.
This commit is contained in:
parent
3dcdd05562
commit
b3b91c68d0
|
@ -20,6 +20,21 @@ static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
|
|||
return 0;
|
||||
}
|
||||
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
||||
/* the autosize behavior is simple: always autosize until the user manually sizes, then never autosize again (this is my best guess as to how GTK+ behaves) */
|
||||
case WM_NOTIFY: /* from the contained header control */
|
||||
if (nmhdr->code == HDN_BEGINTRACK)
|
||||
tableStopColumnAutosize((void *) data);
|
||||
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
||||
case WM_SIZE:
|
||||
if (tableAutosizeColumns((void *) data)) {
|
||||
int i, nColumns;
|
||||
|
||||
nColumns = tableColumnCount((void *) data);
|
||||
for (i = 0; i < nColumns; i++)
|
||||
if (SendMessageW(hwnd, LVM_SETCOLUMNWIDTH, (WPARAM) i, (LPARAM) LVSCW_AUTOSIZE_USEHEADER) == FALSE)
|
||||
xpanic("error resizing columns of results list view", GetLastError());
|
||||
}
|
||||
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
||||
case WM_NCDESTROY:
|
||||
if ((*fv_RemoveWindowSubclass)(hwnd, tableSubProc, id) == FALSE)
|
||||
xpanic("error removing Table subclass (which was for its own event handler)", GetLastError());
|
||||
|
|
|
@ -14,6 +14,8 @@ import "C"
|
|||
type table struct {
|
||||
*tablebase
|
||||
_hwnd C.HWND
|
||||
noautosize bool
|
||||
colcount C.int
|
||||
}
|
||||
|
||||
func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
||||
|
@ -30,6 +32,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
|||
for i := 0; i < ty.NumField(); i++ {
|
||||
C.tableAppendColumn(t._hwnd, C.int(i), toUTF16(ty.Field(i).Name))
|
||||
}
|
||||
t.colcount = C.int(ty.NumField())
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -53,6 +56,27 @@ func tableGetCellText(data unsafe.Pointer, row C.int, col C.int, str *C.LPWSTR)
|
|||
*str = toUTF16(s)
|
||||
}
|
||||
|
||||
//export tableStopColumnAutosize
|
||||
func tableStopColumnAutosize(data unsafe.Pointer) {
|
||||
t := (*table)(data)
|
||||
t.noautosize = true
|
||||
}
|
||||
|
||||
//export tableAutosizeColumns
|
||||
func tableAutosizeColumns(data unsafe.Pointer) C.BOOL {
|
||||
t := (*table)(data)
|
||||
if t.noautosize {
|
||||
return C.FALSE
|
||||
}
|
||||
return C.TRUE
|
||||
}
|
||||
|
||||
//export tableColumnCount
|
||||
func tableColumnCount(data unsafe.Pointer) C.int {
|
||||
t := (*table)(data)
|
||||
return t.colcount
|
||||
}
|
||||
|
||||
func (t *table) hwnd() C.HWND {
|
||||
return t._hwnd
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue