From b7876a1fbad586a5293f5ad2b18893b9e48d70c3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 15 Dec 2023 16:59:14 +0300 Subject: =?UTF-8?q?fixes=20#4056=20(NewStory:=20=D0=B6=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8=D0=B5=20=D1=82=D0=BE=D1=80=D0=BC=D0=BE=D0=B7?= =?UTF-8?q?=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/NewStory/src/history_control.cpp | 37 +++++++++++++++++++++++--------- plugins/NewStory/src/history_control.h | 1 + plugins/NewStory/src/history_dlg.cpp | 5 ++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index bc2ce23a28..f0fd1d29b0 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -81,7 +81,7 @@ void NewstoryListData::OnResize(int newWidth, int newHeight) if (newWidth != cachedWindowWidth) { cachedWindowWidth = newWidth; for (int i = 0; i < totalCount; i++) - LoadItem(i)->savedHeight = -1; + GetItem(i)->savedHeight = -1; bDraw = true; } @@ -489,17 +489,20 @@ int NewstoryListData::GetItemFromPixel(int yPos) int NewstoryListData::GetItemHeight(int index) { - auto *item = LoadItem(index); - if (!item) - return 0; + if (auto *pItem = LoadItem(index)) + return GetItemHeight(pItem); + return 0; +} - if (item->savedHeight == -1) { +int NewstoryListData::GetItemHeight(ItemData *pItem) +{ + if (pItem->savedHeight == -1) { HDC hdc = GetDC(m_hwnd); - item->savedHeight = PaintItem(hdc, item, 0, cachedWindowWidth, false); + pItem->savedHeight = PaintItem(hdc, pItem, 0, cachedWindowWidth, false); ReleaseDC(m_hwnd, hdc); } - - return item->savedHeight; + + return pItem->savedHeight; } bool NewstoryListData::HasSelection() const @@ -669,13 +672,27 @@ void NewstoryListData::RecalcScrollBar() if (totalCount == 0) return; - int yTotal = 0, yTop = 0; + int yTotal = 0, yTop = 0, numRec = 0; for (int i = 0; i < totalCount; i++) { if (i == scrollTopItem) yTop = yTotal - scrollTopPixel; - yTotal += GetItemHeight(i); + + auto *pItem = GetItem(i); + if (pItem->m_bLoaded) { + yTotal += GetItemHeight(pItem); + numRec++; + } } + if (numRec != totalCount) { + yTotal = (yTotal * totalCount) / numRec; + for (int i = 0; i < totalCount; i++) + if (i == scrollTopItem) { + yTop = yTotal - scrollTopPixel; + break; + } + } + SCROLLINFO si = {}; si.cbSize = sizeof(si); si.fMask = SIF_ALL; diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index e9d3631bcc..2f9cd9ac56 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -61,6 +61,7 @@ struct NewstoryListData : public MZeroedObject ItemData* GetItem(int idx) const; int GetItemFromPixel(int yPos); int GetItemHeight(int index); + int GetItemHeight(ItemData *pItem); bool HasSelection() const; void HitTotal(int y); void LineUp(); diff --git a/plugins/NewStory/src/history_dlg.cpp b/plugins/NewStory/src/history_dlg.cpp index 85ef3cce18..2f9c80fba4 100644 --- a/plugins/NewStory/src/history_dlg.cpp +++ b/plugins/NewStory/src/history_dlg.cpp @@ -360,7 +360,10 @@ class CHistoryDlg : public CDlgBase int CurYear = 0, CurMonth = 0, CurDay = 0, PrevYear = -1, PrevMonth = -1, PrevDay = -1; HTREEITEM hCurYear = 0, hCurMonth = 0, hCurDay = 0; for (int i = 0; i < numItems; i++) { - auto *pItem = pArray.get(i, true); + auto *pItem = pArray.get(i, false); + if (!pItem->fetch()) + continue; + if (pItem->dbe.timestamp == 0) continue; -- cgit v1.2.3