From 6e1ac661d4824b2693ab8bae613ef8d43ef16d7f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 12 Apr 2024 17:31:28 +0300 Subject: =?UTF-8?q?fixes=20#4336=20(NewStory:=20=D0=A1=D0=BA=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B8=D0=BD=D0=B3=20=D0=BF=D1=80=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BC=D0=BE=D1=89=D0=B8=20=D1=82=D0=B0=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B2=D0=B8=D0=B6=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BA=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D0=B0=20=D0=B3?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B8=D1=82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/NewStory/src/history_array.cpp | 28 ++++++------- plugins/NewStory/src/history_array.h | 2 +- plugins/NewStory/src/history_control.cpp | 67 ++++++++++++++++++++------------ plugins/NewStory/src/templates.cpp | 2 +- 4 files changed, 55 insertions(+), 44 deletions(-) (limited to 'plugins') diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 09cb998927..4bedf1b828 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -190,42 +190,36 @@ ItemData* ItemData::checkPrevGC(ItemData *pPrev) ///////////////////////////////////////////////////////////////////////////////////////// -int ItemData::calcHeight(int top, int width, POINT *pPos) +int ItemData::calcHeight(int width) { if (m_doc == nullptr) setText(); - SIZE sz; - sz.cx = width - 2; - - POINT pos; - pos.x = 2; - pos.y = top + 2; + int cx = width - 2; + int xPos = 2; if (!pOwner->bReadOnly) { if (g_plugin.bShowType) // Message type icon - pos.x += 18; + xPos += 18; if (g_plugin.bShowDirection) // Message direction icon - pos.x += 18; + xPos += 18; if (dbe.flags & DBEF_BOOKMARK) // Bookmark icon - pos.x += 18; + xPos += 18; - sz.cx -= pos.x; + cx -= xPos; if (m_bOfflineDownloaded != 0) // Download completed icon - sz.cx -= 18; + cx -= 18; } - leftOffset = pos.x; + leftOffset = xPos; if (savedHeight == -1) { - m_doc->render(sz.cx); + m_doc->render(cx); savedHeight = m_doc->height() + 5; } - if (pPos) - *pPos = pos; - return savedHeight; + return xPos; } bool ItemData::fetch(void) diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index 2fa212c0d6..eb535c83b5 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -35,7 +35,7 @@ struct ItemData ItemData* checkPrev(ItemData *pPrev); ItemData* checkPrevGC(ItemData *pPrev); - int calcHeight(int top, int width, POINT *pPos = nullptr); + int calcHeight(int width); bool completed() const { return m_bOfflineDownloaded == 100; } bool fetch(void); void fill(int tmpl); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 43a0cf6e4a..d4da49277d 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -589,7 +589,7 @@ int NewstoryListData::GetItemHeight(int index) int NewstoryListData::GetItemHeight(ItemData *pItem) { if (pItem->savedHeight == -1) - pItem->savedHeight = pItem->calcHeight(0, cachedWindowWidth); + pItem->calcHeight(cachedWindowWidth); return pItem->savedHeight; } @@ -606,15 +606,22 @@ bool NewstoryListData::HasSelection() const void NewstoryListData::HitTotal(int yCurr, int yTotal) { - int i = 0, y = yCurr; - while (i < totalCount && y > 0) { - auto *pItem = GetItem(i++); + int i, y = yCurr; + for (i = 0; i < totalCount; i++) { + auto *pItem = GetItem(i); if (!pItem->m_bLoaded) { i = totalCount * (double(yCurr) / double(yTotal)); y = 0; break; } - else y -= GetItemHeight(pItem); + + int h = GetItemHeight(pItem); + if (h > y) { + y = -y; + break; + } + + y -= h; } scrollTopItem = i; @@ -657,15 +664,14 @@ void NewstoryListData::OpenFolder() void NewstoryListData::Paint(simpledib::dib &dib) { - int top = scrollTopPixel; + int top = 0; - int idx; - for (idx = scrollTopItem; top < cachedWindowHeight && idx < totalCount; idx++) { + for (int idx = scrollTopItem; top < cachedWindowHeight && idx < totalCount; idx++) { if (hwndEditBox && caret == idx) continue; auto *pItem = LoadItem(idx); - pItem->savedTop = top; + pItem->calcHeight(cachedWindowWidth); // ensure that the item's height is calculated COLORREF clLine; int fontid, colorid; @@ -687,17 +693,27 @@ void NewstoryListData::Paint(simpledib::dib &dib) clLine = g_colorTable[COLOR_FRAME].cl; } - POINT pos; - int height = pItem->calcHeight(top, cachedWindowWidth, &pos); + int iItemHeigth, iOffsetY; + if (top == 0) { + pItem->savedTop = iOffsetY = scrollTopPixel; + iItemHeigth = pItem->savedHeight + scrollTopPixel; + } + else { + pItem->savedTop = top; + iOffsetY = 0; + iItemHeigth = pItem->savedHeight; + } + // draw item background HBRUSH hbr = CreateSolidBrush(webPage.clBack); - RECT rc = { 0, top, cachedWindowWidth, top + height }; + RECT rc = { 0, top, cachedWindowWidth, top + iItemHeigth }; FillRect(dib, &rc, hbr); DeleteObject(hbr); SetBkMode(dib, TRANSPARENT); - pos.x = 2; + // left offset of icons & text + int xPos = 2, yPos = top + 2; if (!bReadOnly) { HICON hIcon; @@ -718,8 +734,8 @@ void NewstoryListData::Paint(simpledib::dib &dib) hIcon = g_plugin.getIcon(IDI_UNKNOWN); break; } - DrawIconEx(dib, pos.x, pos.y, hIcon, 16, 16, 0, 0, DI_NORMAL); - pos.x += 18; + DrawIconEx(dib, xPos, yPos, hIcon, 16, 16, 0, 0, DI_NORMAL); + xPos += 18; } // Direction icon @@ -728,20 +744,20 @@ void NewstoryListData::Paint(simpledib::dib &dib) hIcon = g_plugin.getIcon(IDI_MSGOUT); else hIcon = g_plugin.getIcon(IDI_MSGIN); - DrawIconEx(dib, pos.x, pos.y, hIcon, 16, 16, 0, 0, DI_NORMAL); - pos.x += 18; + DrawIconEx(dib, xPos, yPos, hIcon, 16, 16, 0, 0, DI_NORMAL); + xPos += 18; } // Bookmark icon if (pItem->dbe.flags & DBEF_BOOKMARK) { - DrawIconEx(dib, pos.x, pos.y, g_plugin.getIcon(IDI_BOOKMARK), 16, 16, 0, 0, DI_NORMAL); - pos.x += 18; + DrawIconEx(dib, xPos, yPos, g_plugin.getIcon(IDI_BOOKMARK), 16, 16, 0, 0, DI_NORMAL); + xPos += 18; } // Finished icon if (pItem->m_bOfflineDownloaded != 0) { if (pItem->completed()) - DrawIconEx(dib, cachedWindowWidth - 20, pos.y, g_plugin.getIcon(IDI_OK), 16, 16, 0, 0, DI_NORMAL); + DrawIconEx(dib, cachedWindowWidth - 20, yPos, g_plugin.getIcon(IDI_OK), 16, 16, 0, 0, DI_NORMAL); else { HPEN hpn = (HPEN)SelectObject(dib, CreatePen(PS_SOLID, 4, g_colorTable[COLOR_PROGRESS].cl)); MoveToEx(dib, rc.left, rc.bottom - 4, 0); @@ -751,19 +767,20 @@ void NewstoryListData::Paint(simpledib::dib &dib) } } - litehtml::position clip(pos.x, pos.y, cachedWindowWidth - pos.x, height); - pItem->m_doc->draw((UINT_PTR)dib.hdc(), pos.x, pos.y, &clip); + // draw html itself + litehtml::position clip(xPos, yPos, cachedWindowWidth - xPos, iItemHeigth); + pItem->m_doc->draw((UINT_PTR)dib.hdc(), xPos, yPos + iOffsetY, &clip); + // draw border HPEN hpn = (HPEN)SelectObject(dib, CreatePen(PS_SOLID, 1, clLine)); MoveToEx(dib, rc.left, rc.bottom - 1, 0); LineTo(dib, rc.right, rc.bottom - 1); DeleteObject(SelectObject(dib, hpn)); - top += height; + top += iItemHeigth; + cachedMaxDrawnItem = idx; } - cachedMaxDrawnItem = idx; - if (top <= cachedWindowHeight) { RECT rc2; SetRect(&rc2, 0, top, cachedWindowWidth, cachedWindowHeight); diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index fbcde80cb1..4172521496 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -250,7 +250,7 @@ CMStringW ItemData::formatHtml(const wchar_t *pwszStr) str.Append(L""); - Netlib_LogfW(0, str); + // Netlib_LogfW(0, str); return str; } -- cgit v1.2.3