This commit is contained in:
Angelo Haller 2021-01-02 10:21:43 -05:00 committed by GitHub
commit a544b1fd32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 43 deletions

25
ui.h
View File

@ -1324,11 +1324,13 @@ _UI_EXTERN uiTableModel *uiNewTableModel(uiTableModelHandler *mh);
// free table models currently associated with a uiTable. // free table models currently associated with a uiTable.
_UI_EXTERN void uiFreeTableModel(uiTableModel *m); _UI_EXTERN void uiFreeTableModel(uiTableModel *m);
// uiTableModelRowInserted() tells any uiTable associated with m // uiTableModelRowInserted() tell all uiTables associated with
// that a new row has been added to m at index index. You call // the uiTableModel m that a new row has been added to m at
// this function when the number of rows in your model has // index newIndex.
// changed; after calling it, NumRows() should returm the new row // You must insert the row data in your model before calling this
// count. // function.
// NumRows() must represent the new row count before you call
// this function.
_UI_EXTERN void uiTableModelRowInserted(uiTableModel *m, int newIndex); _UI_EXTERN void uiTableModelRowInserted(uiTableModel *m, int newIndex);
// uiTableModelRowChanged() tells any uiTable associated with m // uiTableModelRowChanged() tells any uiTable associated with m
@ -1337,12 +1339,13 @@ _UI_EXTERN void uiTableModelRowInserted(uiTableModel *m, int newIndex);
// this if your data changes at some other point. // this if your data changes at some other point.
_UI_EXTERN void uiTableModelRowChanged(uiTableModel *m, int index); _UI_EXTERN void uiTableModelRowChanged(uiTableModel *m, int index);
// uiTableModelRowDeleted() tells any uiTable associated with m // uiTableModelRowDeleted() tells all uiTables associated with
// that the row at index index has been deleted. You call this // the uiTableModel m that the row at index oldIndex has been
// function when the number of rows in your model has changed; // deleted.
// after calling it, NumRows() should returm the new row // You must delete the row from your model before you call this
// count. // function.
// TODO for this and Inserted: make sure the "after" part is right; clarify if it's after returning or after calling // NumRows() must represent the new row count before you call
// this function.
_UI_EXTERN void uiTableModelRowDeleted(uiTableModel *m, int oldIndex); _UI_EXTERN void uiTableModelRowDeleted(uiTableModel *m, int oldIndex);
// TODO reordering/moving // TODO reordering/moving

View File

@ -24,28 +24,19 @@ void uiFreeTableModel(uiTableModel *m)
uiprivFree(m); uiprivFree(m);
} }
// TODO document that when this is called, the model must return the new row count when asked
void uiTableModelRowInserted(uiTableModel *m, int newIndex) void uiTableModelRowInserted(uiTableModel *m, int newIndex)
{ {
LVITEMW item; LVITEMW item = {};
int newCount;
newCount = uiprivTableModelNumRows(m);
ZeroMemory(&item, sizeof (LVITEMW));
item.mask = 0; item.mask = 0;
item.iItem = newIndex; item.iItem = newIndex;
item.iSubItem = 0; item.iSubItem = 0;
for (auto t : *(m->tables)) {
// actually insert the rows
if (SendMessageW(t->hwnd, LVM_SETITEMCOUNT, (WPARAM) newCount, LVSICF_NOINVALIDATEALL) == 0)
logLastError(L"error calling LVM_SETITEMCOUNT in uiTableModelRowInserted()");
// and redraw every row from the new row down to simulate adding it
if (SendMessageW(t->hwnd, LVM_REDRAWITEMS, (WPARAM) newIndex, (LPARAM) (newCount - 1)) == FALSE)
logLastError(L"error calling LVM_REDRAWITEMS in uiTableModelRowInserted()");
// update selection state for (auto t : *(m->tables)) {
if (SendMessageW(t->hwnd, LVM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1)) if (ListView_InsertItem(t->hwnd, &item) == -1)
logLastError(L"error calling LVM_INSERTITEM in uiTableModelRowInserted() to update selection state"); logLastError(L"error calling ListView_InsertItem in uiTableModelRowInserted()");
// redraw every row from the new row down to simulate adding it
if (ListView_RedrawItems(t->hwnd, newIndex, ListView_GetItemCount(t->hwnd)-1) == -1)
logLastError(L"error calling ListView_RedrawItems in uiTableModelRowInserted()");
} }
} }
@ -57,25 +48,14 @@ void uiTableModelRowChanged(uiTableModel *m, int index)
logLastError(L"error calling LVM_UPDATE in uiTableModelRowChanged()"); logLastError(L"error calling LVM_UPDATE in uiTableModelRowChanged()");
} }
// TODO document that when this is called, the model must return the OLD row count when asked
// TODO for this and the above, see what GTK+ requires and adjust accordingly
void uiTableModelRowDeleted(uiTableModel *m, int oldIndex) void uiTableModelRowDeleted(uiTableModel *m, int oldIndex)
{ {
int newCount;
newCount = uiprivTableModelNumRows(m);
newCount--;
for (auto t : *(m->tables)) { for (auto t : *(m->tables)) {
// update selection state if (ListView_DeleteItem(t->hwnd, oldIndex) == -1)
if (SendMessageW(t->hwnd, LVM_DELETEITEM, (WPARAM) oldIndex, 0) == (LRESULT) (-1)) logLastError(L"error calling ListView_DeleteItem() in uiTableModelRowDeleted()");
logLastError(L"error calling LVM_DELETEITEM in uiTableModelRowDeleted() to update selection state"); // redraw every row from the new nth row down to simulate removing the old nth row
if (ListView_RedrawItems(t->hwnd, oldIndex, ListView_GetItemCount(t->hwnd)-1) == -1)
// actually delete the rows logLastError(L"error calling ListView_RedrawItems() in uiTableModelRowDeleted()");
if (SendMessageW(t->hwnd, LVM_SETITEMCOUNT, (WPARAM) newCount, LVSICF_NOINVALIDATEALL) == 0)
logLastError(L"error calling LVM_SETITEMCOUNT in uiTableModelRowDeleted()");
// and redraw every row from the new nth row down to simulate removing the old nth row
if (SendMessageW(t->hwnd, LVM_REDRAWITEMS, (WPARAM) oldIndex, (LPARAM) (newCount - 1)) == FALSE)
logLastError(L"error calling LVM_REDRAWITEMS in uiTableModelRowDeleted()");
} }
} }