From e252945cb386312d9fb79b2fbe3179e4b1e40a62 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 21 Feb 2015 15:53:13 -0500 Subject: [PATCH] Implemented Table column names on all platforms. Updates #40. --- table_darwin.go | 6 +++++- table_unix.go | 6 +++++- table_windows.go | 11 ++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/table_darwin.go b/table_darwin.go index 26418b6b..1bfbe747 100644 --- a/table_darwin.go +++ b/table_darwin.go @@ -31,7 +31,11 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table { // also sets the delegate C.tableMakeDataSource(t.id, unsafe.Pointer(t)) for i := 0; i < ty.NumField(); i++ { - cname := C.CString(ty.Field(i).Name) + colname := ty.Field(i).Tag.Get("uicolumn") + if colname == "" { + colname = ty.Field(i).Name + } + cname := C.CString(colname) coltype := C.colTypeText editable := false switch { diff --git a/table_unix.go b/table_unix.go index 08570148..97873b0b 100644 --- a/table_unix.go +++ b/table_unix.go @@ -61,7 +61,11 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table { C.gpointer(unsafe.Pointer(t))) C.gtk_tree_view_set_model(t.treeview, t.modelgtk) for i := 0; i < ty.NumField(); i++ { - cname := togstr(ty.Field(i).Name) + colname := ty.Field(i).Tag.Get("uicolumn") + if colname == "" { + colname = ty.Field(i).Name + } + cname := togstr(colname) switch { case ty.Field(i).Type == reflect.TypeOf((*image.RGBA)(nil)): // can't use GDK_TYPE_PIXBUF here because it's a macro that expands to a function and cgo hates that diff --git a/table_windows.go b/table_windows.go index a26c2f00..159f1c29 100644 --- a/table_windows.go +++ b/table_windows.go @@ -6,6 +6,7 @@ package ui // - why are we not getting keyboard input (focus?) on a mouse click? // - are we getting keyboard input (focus?) on tab? // - random freezes on Windows 7 when resizing headers or clicking new rows; likely another package ui infrastructure issue though... +// - investigate japanese display in the table headers on wine (it has worked in the past in ANSI mode via Shift-JIS with what I assume is the same font, so huh?) import ( "fmt" @@ -53,9 +54,13 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table { case ty.Field(i).Type.Kind() == reflect.Bool: coltype = C.tableColumnCheckbox } - colname := toUTF16(ty.Field(i).Name) - C.SendMessageW(t.hwnd, C.tableAddColumn, coltype, C.LPARAM(uintptr(unsafe.Pointer(colname)))) - // TODO free colname + colname := ty.Field(i).Tag.Get("uicolumn") + if colname == "" { + colname = ty.Field(i).Name + } + ccolname := toUTF16(colname) + C.SendMessageW(t.hwnd, C.tableAddColumn, coltype, C.LPARAM(uintptr(unsafe.Pointer(ccolname)))) + // TODO free ccolname } t.colcount = C.int(ty.NumField()) return t