From a5a00c644c08a6e0f52740c3f2a280977929a285 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 25 Aug 2018 22:31:53 -0400 Subject: [PATCH] And finished TableModel. There's cgo issues I need to fix; I might as well split out all the cgo code... --- tablemodel.go | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tablemodel.go b/tablemodel.go index 93bde19..b4ca7a4 100644 --- a/tablemodel.go +++ b/tablemodel.go @@ -13,7 +13,8 @@ package ui // { // doTableModelSetCellValue(mh, m, row, column, (uiTableValue *) value); // } -// static const uiTableModelHandler pkguiTableModelHandler = { +// // TODO why can't this be static? +// const uiTableModelHandler pkguiTableModelHandler = { // .NumColumns = doTableModelNumColumns, // .ColumnType = doTableModelColumnType, // .NumRows = doTableModelNumRows, @@ -198,3 +199,45 @@ func doTableModelSetCellValue(umh *C.uiTableModelHandler, um *C.uiTableModel, ro v := tableValueFromLibui(value) mh.SetCellValue(models[um], int(row), int(column), v) } + +// NewTableModel creates a new TableModel. +func NewTableModel(handler TableModelHandler) *TableModel { + m := &TableModel{ + m: C.uiNewTableModel(&C.pkguiTableModelHandler), + } + modelhandlers[m.m] = handler + models[m.m] = m + return m +} + +// Free frees m. It is an error to Free any models associated with a +// Table. +func (m *TableModel) Free() { + delete(models, m.m) + delete(modelhandlers, m.m) + C.uiFreeTableModel(m.m) +} + +// RowInserted tells any Tables associated with m that a new row +// has been added to m at index index. You call this method when +// the number of rows in your model has changed; after calling it, +// NumRows should returm the new row count. +func (m *TableModel) RowInserted(index int) { + C.uiTableModelRowInserted(m.m, C.int(index)) +} + +// RowChanged tells any Tables associated with m that the data in +// the row at index has changed. You do not need to call this in +// your SetCellValue handlers, but you do need to call this if your +// data changes at some other point. +func (m *TableModel) RowChanged(index int) { + C.uiTableModelRowChanged(m.m, C.int(index)) +} + +// RowDeleted tells any Tables associated with m that the row at +// index index has been deleted. You call this function when the +// number of rows in your model has changed; after calling it, +// NumRows should returm the new row count. +func (m *TableModel) RowDeleted(index int) { + C.uiTableModelRowDeleted(m.m, C.int(index)) +}