From b2946761fc087e8a838f2e52123b74e7be984c43 Mon Sep 17 00:00:00 2001 From: Vadzim Dambrouski Date: Wed, 5 Feb 2020 22:26:23 +0300 Subject: [PATCH] Fix #416, uiTableModelRowInserted on windows adds 2 rows instead of 1. When LVM_INSERTITEM is called after we updated LVM_SETITEMCOUNT, the actual count will be increased by one causing one extra item to appear in the table and loading data from the model. This extra item is invisible at first because it doesn't get painted but you can click on it to confirm that it is actually there. To fix this problem we need to call INSERTITEM first and then update the ITEMCOUNT. Fixes #416 Fixes andlabs/ui#369 cc @bcampbell r? @andlabs --- windows/table.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/windows/table.cpp b/windows/table.cpp index 85a51c1a..957e4119 100644 --- a/windows/table.cpp +++ b/windows/table.cpp @@ -36,16 +36,16 @@ void uiTableModelRowInserted(uiTableModel *m, int newIndex) item.iItem = newIndex; item.iSubItem = 0; for (auto t : *(m->tables)) { + // update selection state + if (SendMessageW(t->hwnd, LVM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1)) + logLastError(L"error calling LVM_INSERTITEM in uiTableModelRowInserted() to update selection state"); + // 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 - if (SendMessageW(t->hwnd, LVM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1)) - logLastError(L"error calling LVM_INSERTITEM in uiTableModelRowInserted() to update selection state"); } }