From 3c4b7e208af45ff4a5647d372a8cbcba00315de2 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 26 Aug 2018 17:36:39 -0400 Subject: [PATCH] And migrated tablemodel.go back. And now we can finally build it properly! --- pkgui.c | 14 ++++++++ pkgui.h | 5 ++- BBB_GOFILES/tablemodel.go => tablemodel.go | 40 ++++++---------------- 3 files changed, 29 insertions(+), 30 deletions(-) rename BBB_GOFILES/tablemodel.go => tablemodel.go (79%) diff --git a/pkgui.c b/pkgui.c index 1527fad..05fe8cd 100644 --- a/pkgui.c +++ b/pkgui.c @@ -224,3 +224,17 @@ void pkguiFreeAreaHandler(uiAreaHandler *ah) { free(ah); } + +// cgo can't generate const, so we need this trampoline +static void realDoTableModelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int column, const uiTableValue *value) +{ + pkguiDoTableModelSetCellValue(mh, m, row, column, (uiTableValue *) value); +} + +const uiTableModelHandler pkguiTableModelHandler = { + .NumColumns = pkguiDoTableModelNumColumns, + .ColumnType = pkguiDoTableModelColumnType, + .NumRows = pkguiDoTableModelNumRows, + .CellValue = pkguiDoTableModelCellValue, + .SetCellValue = realDoTableModelSetCellValue, +}; diff --git a/pkgui.h b/pkgui.h index 5081a32..f2c28a4 100644 --- a/pkgui.h +++ b/pkgui.h @@ -85,8 +85,11 @@ extern void pkguiFreeFontDescriptor(uiFontDescriptor *fd); extern uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void); extern void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *p); -// area.go +// areahandler.go extern uiAreaHandler *pkguiAllocAreaHandler(void); extern void pkguiFreeAreaHandler(uiAreaHandler *ah); +// tablemodel.go +extern const uiTableModelHandler pkguiTableModelHandler; + #endif diff --git a/BBB_GOFILES/tablemodel.go b/tablemodel.go similarity index 79% rename from BBB_GOFILES/tablemodel.go rename to tablemodel.go index b4ca7a4..d5d3f56 100644 --- a/BBB_GOFILES/tablemodel.go +++ b/tablemodel.go @@ -2,25 +2,7 @@ package ui -// #include "ui.h" -// extern int doTableModelNumColumns(uiTableModelHandler *, uiTableModel *); -// extern uiTableValueType doTableModelColumnType(uiTableModelHandler *, uiTableModel *, int); -// extern int doTableModelNumRows(uiTableModelHandler *, uiTableModel *); -// extern uiTableValue *doTableModelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int column); -// extern void doTableModelSetCellValue(uiTableModelHandler *, uiTableModel *, int, int, uiTableValue *); -// // deal with cgo being dumb -// static inline void realDoTableModelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int column, const uiTableValue *value) -// { -// doTableModelSetCellValue(mh, m, row, column, (uiTableValue *) value); -// } -// // TODO why can't this be static? -// const uiTableModelHandler pkguiTableModelHandler = { -// .NumColumns = doTableModelNumColumns, -// .ColumnType = doTableModelColumnType, -// .NumRows = doTableModelNumRows, -// .CellValue = doTableModelCellValue, -// .SetCellValue = realDoTableModelSetCellValue, -// }; +// #include "pkgui.h" import "C" // TableValue is a type that represents a piece of data that can come @@ -154,14 +136,14 @@ type TableModelHandler interface { SetCellValue(m *TableModel, row, column int, value TableValue) } -//export doTableModelNumColumns -func doTableModelNumColumns(umh *C.uiTableModelHandler, um *C.uiTableModel) C.int { +//export pkguiDoTableModelNumColumns +func pkguiDoTableModelNumColumns(umh *C.uiTableModelHandler, um *C.uiTableModel) C.int { mh := modelhandlers[um] return C.int(len(mh.ColumnTypes(models[um]))) } -//export doTableModelColumnType -func doTableModelColumnType(umh *C.uiTableModelHandler, um *C.uiTableModel, n C.int) C.uiTableValueType { +//export pkguiDoTableModelColumnType +func pkguiDoTableModelColumnType(umh *C.uiTableModelHandler, um *C.uiTableModel, n C.int) C.uiTableValueType { mh := modelhandlers[um] c := mh.ColumnTypes(models[um]) switch c[n].(type) { @@ -177,14 +159,14 @@ func doTableModelColumnType(umh *C.uiTableModelHandler, um *C.uiTableModel, n C. panic("unreachable") } -//export doTableModelNumRows -func doTableModelNumRows(umh *C.uiTableModelHandler, um *C.uiTableModel) C.int { +//export pkguiDoTableModelNumRows +func pkguiDoTableModelNumRows(umh *C.uiTableModelHandler, um *C.uiTableModel) C.int { mh := modelhandlers[um] return C.int(mh.NumRows(models[um])) } -//export doTableModelCellValue -func doTableModelCellValue(umh *C.uiTableModelHandler, um *C.uiTableModel, row, column C.int) *C.uiTableValue { +//export pkguiDoTableModelCellValue +func pkguiDoTableModelCellValue(umh *C.uiTableModelHandler, um *C.uiTableModel, row, column C.int) *C.uiTableValue { mh := modelhandlers[um] v := mh.CellValue(models[um], int(row), int(column)) if v == nil { @@ -193,8 +175,8 @@ func doTableModelCellValue(umh *C.uiTableModelHandler, um *C.uiTableModel, row, return v.toLibui() } -//export doTableModelSetCellValue -func doTableModelSetCellValue(umh *C.uiTableModelHandler, um *C.uiTableModel, row, column C.int, value *C.uiTableValue) { +//export pkguiDoTableModelSetCellValue +func pkguiDoTableModelSetCellValue(umh *C.uiTableModelHandler, um *C.uiTableModel, row, column C.int, value *C.uiTableValue) { mh := modelhandlers[um] v := tableValueFromLibui(value) mh.SetCellValue(models[um], int(row), int(column), v)