summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-25 22:31:53 -0400
committerPietro Gagliardi <[email protected]>2018-08-25 22:31:53 -0400
commita5a00c644c08a6e0f52740c3f2a280977929a285 (patch)
treece3809111d67627503fe726af495f9e6dd000967
parent76aa5f420a61489d2d6baba720a6c9e4a1a14d11 (diff)
And finished TableModel. There's cgo issues I need to fix; I might as well split out all the cgo code...
-rw-r--r--tablemodel.go45
1 files changed, 44 insertions, 1 deletions
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))
+}