summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-04-12 17:31:28 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-04-12 17:31:28 +0300
commit6e1ac661d4824b2693ab8bae613ef8d43ef16d7f (patch)
treeb62af7cbd7e518274d2b5f335e10f64c4abbd258 /plugins
parent25e3bdc5ef034fcedcaa46d448c0e3e4531fd790 (diff)
fixes #4336 (NewStory: Скроллинг при помощи таскания движка скроллера глючит)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/NewStory/src/history_array.cpp28
-rw-r--r--plugins/NewStory/src/history_array.h2
-rw-r--r--plugins/NewStory/src/history_control.cpp67
-rw-r--r--plugins/NewStory/src/templates.cpp2
4 files changed, 55 insertions, 44 deletions
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"</body></html>");
- Netlib_LogfW(0, str);
+ // Netlib_LogfW(0, str);
return str;
}