diff options
author | George Hazan <george.hazan@gmail.com> | 2023-12-15 16:59:14 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-12-15 16:59:17 +0300 |
commit | b7876a1fbad586a5293f5ad2b18893b9e48d70c3 (patch) | |
tree | c1e112ff8d3bf686ad5c0ce28c196cfa9a841b07 | |
parent | 969f5c01a5039ac62573e22557158badccf44b20 (diff) |
fixes #4056 (NewStory: жестокие тормоза)
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 37 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.h | 1 | ||||
-rw-r--r-- | 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; |