summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src/history_control.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewStory/src/history_control.cpp')
-rw-r--r--plugins/NewStory/src/history_control.cpp158
1 files changed, 88 insertions, 70 deletions
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index f7797fc912..a25760ae87 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -1,6 +1,6 @@
/*
Copyright (c) 2005 Victor Pavlychko (nullbyte@sotline.net.ua)
-Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-25 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -186,10 +186,7 @@ bool NewstoryListData::AtTop(void) const
if (scrollTopItem < 0)
return true;
- if (scrollTopItem == 0 && scrollTopPixel == 0)
- return true;
-
- return false;
+ return (scrollTopItem == 0 && scrollTopPixel == 0);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -270,7 +267,7 @@ void NewstoryListData::BeginEditItem()
mir_subclassWindow(hwndEditBox, HistoryEditWndProc);
SendMessage(hwndEditBox, WM_SETFONT, (WPARAM)g_fontTable[fontid].hfnt, 0);
SendMessage(hwndEditBox, EM_SETMARGINS, EC_RIGHTMARGIN, 100);
- if (item->dbe.eventType != EVENTTYPE_MESSAGE || !(item->dbe.flags & DBEF_SENT))
+ if (item->dbe.eventType != EVENTTYPE_MESSAGE || !item->dbe.bSent)
SendMessage(hwndEditBox, EM_SETREADONLY, TRUE, 0);
ShowWindow(hwndEditBox, SW_SHOW);
@@ -411,7 +408,7 @@ void NewstoryListData::DeleteItems(void)
for (int i = totalCount - 1; i >= 0; i--) {
auto *pItem = GetItem(i);
if (pItem->m_bSelected) {
- if ((pItem->dbe.flags & DBEF_SENT) == 0)
+ if (!pItem->dbe.bSent)
bIncoming = true;
nSelected++;
}
@@ -419,6 +416,7 @@ void NewstoryListData::DeleteItems(void)
CDeleteEventsDlg dlg(m_hContact, nSelected, bIncoming);
if (IDOK == dlg.DoModal()) {
+ int iSaveCount = totalCount;
g_plugin.bDisableDelete = true;
int firstSel = -1, flags = 0;
@@ -440,6 +438,8 @@ void NewstoryListData::DeleteItems(void)
}
g_plugin.bDisableDelete = false;
+ if (iSaveCount != totalCount)
+ PostMessage(GetParent(m_hwnd), UM_UPDATE_WINDOW, 0, 0);
if (firstSel != -1) {
SetCaret(firstSel, false);
@@ -459,7 +459,7 @@ void NewstoryListData::DeliverEvent(MCONTACT hContact, MEVENT hEvent)
for (int i = totalCount - 1; i >= 0; i--) {
auto *pItem = GetItem(i);
- if (pItem->dbe.hContact != hContact || !(pItem->dbe.flags & DBEF_SENT))
+ if (pItem->dbe.hContact != hContact || !pItem->dbe.bSent)
continue;
if (pItem->dbe.getEvent() == hEvent)
@@ -499,11 +499,12 @@ void NewstoryListData::EndEditItem(bool bAccept)
pItem->wtext[iTextLen] = 0;
if (pItem->dbe.hContact && pItem->dbe.getEvent()) {
- DBEVENTINFO dbei = pItem->dbe;
+ DB::EventInfo dbei(pItem->dbe.getEvent());
ptrA szUtf(mir_utf8encodeW(pItem->wtext));
dbei.cbBlob = (int)mir_strlen(szUtf) + 1;
- dbei.pBlob = szUtf.get();
+ dbei.pBlob = szUtf.detach();
+ dbei.bEdited = true;
db_event_edit(pItem->dbe.getEvent(), &dbei);
}
@@ -729,6 +730,18 @@ void NewstoryListData::OpenFolder()
/////////////////////////////////////////////////////////////////////////////////////////
// Painting
+static void recursive_set_color(element::ptr el, const web_color &fore, const background &back)
+{
+ el->css_w().set_bg(back);
+ el->css_w().set_color(fore);
+
+ for (auto &it : el->children()) {
+ if (it->tag() == _a_ || (it->tag() == _font_ && mir_strcmp(it->get_attr("class"), "body")))
+ continue;
+ recursive_set_color(it, fore, back);
+ }
+}
+
void NewstoryListData::Paint(simpledib::dib &dib)
{
int top = 0;
@@ -780,7 +793,8 @@ void NewstoryListData::Paint(simpledib::dib &dib)
SetBkMode(dib, TRANSPARENT);
// left offset of icons & text
- int xPos = 2, yPos = top + 2, xRight = 0, yOffset = 0;
+ bool bDrawProgress = false;
+ int xPos = 2, yPos = top + 2, xRight = 0;
if (!bReadOnly) {
HICON hIcon;
@@ -804,7 +818,7 @@ void NewstoryListData::Paint(simpledib::dib &dib)
if (g_plugin.bShowType) {
switch (pItem->dbe.eventType) {
case EVENTTYPE_MESSAGE:
- hIcon = g_plugin.getIcon(IDI_SENDMSG);
+ hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE);
break;
case EVENTTYPE_FILE:
hIcon = Skin_LoadIcon(SKINICON_EVENT_FILE);
@@ -818,20 +832,22 @@ void NewstoryListData::Paint(simpledib::dib &dib)
}
DrawIconEx(dib, xPos, yPos, hIcon, 16, 16, 0, 0, DI_NORMAL);
xPos += 18;
+ IcoLib_ReleaseIcon(hIcon);
}
// Direction icon
if (g_plugin.bShowDirection) {
- if (pItem->dbe.flags & DBEF_SENT)
+ if (pItem->dbe.bSent)
hIcon = g_plugin.getIcon(IDI_MSGOUT);
else
hIcon = g_plugin.getIcon(IDI_MSGIN);
DrawIconEx(dib, xPos, yPos, hIcon, 16, 16, 0, 0, DI_NORMAL);
xPos += 18;
+ IcoLib_ReleaseIcon(hIcon);
}
// Bookmark icon
- if (pItem->dbe.flags & DBEF_BOOKMARK) {
+ if (pItem->dbe.isBookmark) {
DrawIconEx(dib, xPos, yPos, g_plugin.getIcon(IDI_BOOKMARK), 16, 16, 0, 0, DI_NORMAL);
xPos += 18;
}
@@ -839,37 +855,48 @@ void NewstoryListData::Paint(simpledib::dib &dib)
// Finished icon
if (pItem->m_bOfflineDownloaded != 0) {
if (pItem->completed())
- DrawIconEx(dib, cachedWindowWidth - (xRight = 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);
- LineTo(dib, rc.left + (rc.right - rc.left) * int(pItem->m_bOfflineDownloaded) / 100, rc.bottom - 4);
- DeleteObject(SelectObject(dib, hpn));
- yOffset = 4;
- }
+ DrawIconEx(dib, cachedWindowWidth - (xRight = 18), yPos, g_plugin.getIcon(IDI_OK), 16, 16, 0, 0, DI_NORMAL);
+ else
+ bDrawProgress = true;
}
// Delivered & remote read icons
if (pItem->m_bRemoteRead)
- DrawIconEx(dib, cachedWindowWidth - (xRight = 20), yPos, g_plugin.getIcon(IDI_REMOTEREAD), 16, 16, 0, 0, DI_NORMAL);
+ DrawIconEx(dib, cachedWindowWidth - (xRight = 18), yPos, g_plugin.getIcon(IDI_REMOTEREAD), 16, 16, 0, 0, DI_NORMAL);
else if (pItem->m_bDelivered)
- DrawIconEx(dib, cachedWindowWidth - (xRight = 20), yPos, g_plugin.getIcon(IDI_DELIVERED), 16, 16, 0, 0, DI_NORMAL);
+ DrawIconEx(dib, cachedWindowWidth - (xRight = 18), yPos, g_plugin.getIcon(IDI_DELIVERED), 16, 16, 0, 0, DI_NORMAL);
+
+ // Edited icon
+ if (pItem->dbe.bEdited) {
+ xRight += 18;
+ DrawIconEx(dib, cachedWindowWidth - xRight, yPos, g_plugin.getIcon(IDI_SENDMSG), 16, 16, 0, 0, DI_NORMAL);
+ }
}
// draw html itself
- litehtml::position clip(xPos, yPos, cachedWindowWidth - xPos - xRight, iItemHeigth - yOffset);
+ litehtml::position clip(xPos, yPos, cachedWindowWidth - xPos - xRight, iItemHeigth);
if (auto &pDoc = pItem->m_doc) {
if (auto pBody = pDoc->root()->select_one("body")) {
- litehtml::background back = pBody->css().get_bg();
- back.m_color = litehtml::web_color(GetRValue(clBack), GetGValue(clBack), GetBValue(clBack));
- pBody->css_w().set_bg(back);
+ if (auto pBbody = pBody->select_one("[id=bbody]")) {
+ litehtml::background back = pBbody->css().get_bg();
+ back.m_color = litehtml::web_color(GetRValue(clBack), GetGValue(clBack), GetBValue(clBack));
- pBody->css_w().set_color(litehtml::web_color(GetRValue(clText), GetGValue(clText), GetBValue(clText)));
+ litehtml::web_color fore(GetRValue(clText), GetGValue(clText), GetBValue(clText));
+ recursive_set_color(pBbody, fore, back);
+ }
}
pDoc->draw((UINT_PTR)dib.hdc(), xPos, yPos + iOffsetY, &clip);
}
+ // draw progress
+ if (bDrawProgress) {
+ HPEN hpn = (HPEN)SelectObject(dib, CreatePen(PS_SOLID, 4, g_colorTable[COLOR_PROGRESS].cl));
+ MoveToEx(dib, rc.left, rc.bottom - 4, 0);
+ LineTo(dib, rc.left + (rc.right - rc.left) * int(pItem->m_bOfflineDownloaded) / 100, rc.bottom - 4);
+ DeleteObject(SelectObject(dib, hpn));
+ }
+
// draw border
HPEN hpn = (HPEN)SelectObject(dib, CreatePen(PS_SOLID, 1, clLine));
MoveToEx(dib, rc.left, rc.bottom - 1, 0);
@@ -964,7 +991,7 @@ void NewstoryListData::RemoteRead(MCONTACT hContact, MEVENT hEvent)
if (!pItem->m_bLoaded)
pItem->fetch();
- if (pItem->dbe.hContact != hContact || !(pItem->dbe.flags & DBEF_SENT))
+ if (pItem->dbe.hContact != hContact || !pItem->dbe.bSent)
continue;
if (pItem->dbe.getEvent() == hEvent)
@@ -1010,19 +1037,6 @@ void NewstoryListData::SetCaret(int idx, bool bEnsureVisible)
}
}
-void NewstoryListData::SetContact(MCONTACT hContact)
-{
- m_hContact = hContact;
-
- WindowList_Add(g_hNewstoryLogs, m_hwnd, hContact);
-}
-
-void NewstoryListData::SetDialog(CSrmmBaseDialog *pDlg)
-{
- if (pMsgDlg = pDlg)
- SetContact(pDlg->m_hContact);
-}
-
void NewstoryListData::SetPos(int pos)
{
SetSelection((selStart == -1) ? pos : selStart, pos);
@@ -1128,7 +1142,7 @@ void NewstoryListData::TryUp(int iCount)
for (int j = 0; j < i + 1; j++)
if (auto *pItem = GetItem(j)) {
pItem->fetch();
- if (pItem->dbe.flags & DBEF_SENT)
+ if (pItem->dbe.bSent)
pItem->m_bRemoteRead = hasRead;
pPrev = pItem->checkNext(pPrev);
}
@@ -1323,7 +1337,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int eventCount = data->totalCount;
for (int i = 0; i < eventCount; i++) {
auto *p = data->GetItem(i);
- if (p->dbe.timestamp >= wParam) {
+ if (p->dbe.getUnixtime() >= wParam) {
data->SetSelection(i, i);
data->SetCaret(i);
break;
@@ -1470,57 +1484,62 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
if (msg == WM_KEYUP)
break;
+ int oldCaret = data->caret;
switch (wParam) {
case VK_UP:
- if (g_plugin.bHppCompat)
+ if (g_plugin.bHppCompat) {
data->EventUp();
- else
- data->LineUp();
- if (isShift)
- data->SetSelection(data->scrollTopItem, data->caret);
+ if (isShift)
+ data->AddSelection(data->caret, oldCaret);
+ }
+ else data->LineUp();
break;
case VK_DOWN:
- if (g_plugin.bHppCompat)
+ if (g_plugin.bHppCompat) {
data->EventDown();
- else
- data->LineDown();
- if (isShift)
- data->SetSelection(data->scrollTopItem, data->caret);
+ if (isShift)
+ data->AddSelection(oldCaret, data->caret);
+ }
+ else data->LineDown();
break;
case VK_PRIOR:
if (isCtrl)
data->ScrollTop();
- else if (g_plugin.bHppCompat)
- data->EventPageUp();
- else
- data->PageUp();
- if (isShift)
- data->SetSelection(data->scrollTopItem, data->caret);
+ else {
+ if (g_plugin.bHppCompat) {
+ data->EventPageUp();
+ if (isShift)
+ data->AddSelection(data->caret, oldCaret);
+ }
+ else data->PageUp();
+ }
break;
case VK_NEXT:
if (isCtrl)
data->ScrollBottom();
- else if (g_plugin.bHppCompat)
- data->EventPageDown();
- else
- data->PageDown();
- if (isShift)
- data->SetSelection(data->scrollTopItem, data->caret);
+ else {
+ if (g_plugin.bHppCompat) {
+ data->EventPageDown();
+ if (isShift)
+ data->AddSelection(oldCaret, data->caret);
+ }
+ else data->PageDown();
+ }
break;
case VK_HOME:
data->ScrollTop();
if (isShift)
- data->SetSelection(0, data->caret);
+ data->AddSelection(0, data->caret);
break;
case VK_END:
data->ScrollBottom();
if (isShift)
- data->SetSelection(data->caret, data->totalCount);
+ data->AddSelection(data->caret, data->totalCount);
break;
case VK_F2:
@@ -1715,7 +1734,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
break;
case WM_DESTROY:
- WindowList_Remove(g_hNewstoryLogs, hwnd);
delete data;
SetWindowLongPtr(hwnd, 0, 0);
break;