summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewStory/src')
-rw-r--r--plugins/NewStory/src/fonts.cpp2
-rw-r--r--plugins/NewStory/src/history.cpp29
-rw-r--r--plugins/NewStory/src/history.h2
-rw-r--r--plugins/NewStory/src/history_array.cpp196
-rw-r--r--plugins/NewStory/src/history_array.h2
-rw-r--r--plugins/NewStory/src/history_control.cpp46
-rw-r--r--plugins/NewStory/src/history_control.h10
-rw-r--r--plugins/NewStory/src/main.cpp5
8 files changed, 172 insertions, 120 deletions
diff --git a/plugins/NewStory/src/fonts.cpp b/plugins/NewStory/src/fonts.cpp
index ccb901e20c..b054cf542d 100644
--- a/plugins/NewStory/src/fonts.cpp
+++ b/plugins/NewStory/src/fonts.cpp
@@ -50,7 +50,7 @@ int evtFontsChanged(WPARAM, LPARAM)
it.hfnt = CreateFontIndirectA(&it.lf);
}
- WindowList_Broadcast(hNewstoryWindows, UM_REDRAWLISTH, 0, 0);
+ WindowList_Broadcast(g_hNewstoryWindows, UM_REDRAWLISTH, 0, 0);
return 0;
}
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp
index 8ad2386fc7..d722241819 100644
--- a/plugins/NewStory/src/history.cpp
+++ b/plugins/NewStory/src/history.cpp
@@ -6,32 +6,33 @@
#include "stdafx.h"
-MWindowList hNewstoryWindows = 0;
+MWindowList g_hNewstoryWindows = 0, g_hNewstoryLogs = 0;
-int evtEventAdded(WPARAM wParam, LPARAM lParam)
+int evtEventAdded(WPARAM hContact, LPARAM lParam)
{
- HWND hwnd = WindowList_Find(hNewstoryWindows, (UINT_PTR)wParam);
- SendMessage(hwnd, UM_ADDEVENT, wParam, lParam);
+ if (HWND hwnd = WindowList_Find(g_hNewstoryLogs, hContact))
+ SendMessage(hwnd, UM_ADDEVENT, hContact, lParam);
return 0;
}
-int evtEventDeleted(WPARAM wParam, LPARAM lParam)
+int evtEventDeleted(WPARAM hContact, LPARAM lParam)
{
- HWND hwnd = WindowList_Find(hNewstoryWindows, (UINT_PTR)wParam);
- SendMessage(hwnd, UM_REMOVEEVENT, wParam, lParam);
+ if (HWND hwnd = WindowList_Find(g_hNewstoryLogs, hContact))
+ SendMessage(hwnd, UM_REMOVEEVENT, hContact, lParam);
return 0;
}
-int evtEventEdited(WPARAM wParam, LPARAM lParam)
+int evtEventEdited(WPARAM hContact, LPARAM lParam)
{
- HWND hwnd = WindowList_Find(hNewstoryWindows, (UINT_PTR)wParam);
- SendMessage(hwnd, UM_EDITEVENT, wParam, lParam);
+ if (HWND hwnd = WindowList_Find(g_hNewstoryLogs, hContact))
+ SendMessage(hwnd, UM_EDITEVENT, hContact, lParam);
return 0;
}
void InitHistory()
{
- hNewstoryWindows = WindowList_Create();
+ g_hNewstoryLogs = WindowList_Create();
+ g_hNewstoryWindows = WindowList_Create();
HookEvent(ME_DB_EVENT_ADDED, evtEventAdded);
HookEvent(ME_DB_EVENT_DELETED, evtEventDeleted);
@@ -538,7 +539,7 @@ public:
Utils_RestoreWindowPosition(m_hwnd, m_hContact, MODULENAME, "wnd_");
PostMessage(m_hwnd, WM_SIZE, 0, 0);
- WindowList_Add(hNewstoryWindows, m_hwnd, m_hContact);
+ WindowList_Add(g_hNewstoryWindows, m_hwnd, m_hContact);
UpdateTitle();
@@ -580,7 +581,7 @@ public:
Utils_SaveWindowPosition(m_hwnd, m_hContact, MODULENAME, "wnd_");
Window_FreeIcon_IcoLib(m_hwnd);
- WindowList_Remove(hNewstoryWindows, m_hwnd);
+ WindowList_Remove(g_hNewstoryWindows, m_hwnd);
if (m_hwndStatus != nullptr) {
DestroyWindow(m_hwndStatus);
m_hwndStatus = nullptr;
@@ -1017,7 +1018,7 @@ public:
INT_PTR svcShowNewstory(WPARAM hContact, LPARAM)
{
- HWND hwnd = (HWND)WindowList_Find(hNewstoryWindows, hContact);
+ HWND hwnd = (HWND)WindowList_Find(g_hNewstoryWindows, hContact);
if (hwnd && IsWindow(hwnd)) {
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
SetFocus(hwnd);
diff --git a/plugins/NewStory/src/history.h b/plugins/NewStory/src/history.h
index 9a8caeca08..71acadff15 100644
--- a/plugins/NewStory/src/history.h
+++ b/plugins/NewStory/src/history.h
@@ -27,7 +27,7 @@ enum
UM_GETEVENTHANDLE
};
-extern MWindowList hNewstoryWindows;
+extern MWindowList g_hNewstoryWindows, g_hNewstoryLogs;
void InitHistory();
void InitMenus();
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index 5463421c37..41b091b37c 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -46,18 +46,34 @@ bool Filter::check(ItemData *item)
/////////////////////////////////////////////////////////////////////////////////////////
// Event
+ItemData::~ItemData()
+{
+ mir_free(wtext);
+ if (data)
+ MTextDestroy(data);
+}
+
void ItemData::checkCreate(HWND hwnd)
{
if (data == nullptr) {
- if (m_bRtf)
- data = MTextCreateEx(htuLog, this->wtext, MTEXT_FLG_WCHAR | MTEXT_FLG_RTF);
- else
- data = MTextCreateW(htuLog, Proto_GetBaseAccountName(hContact), ptrW(TplFormatString(getTemplate(), hContact, this)));
+ setText();
MTextSetParent(data, hwnd);
MTextActivate(data, true);
}
}
+bool ItemData::isGrouped() const
+{
+ if (pPrev && g_plugin.bMsgGrouping) {
+ if (!pPrev->m_bLoaded)
+ pPrev->load(true);
+
+ if (pPrev->hContact == hContact && (pPrev->dbe.flags & DBEF_SENT) == (dbe.flags & DBEF_SENT))
+ return true;
+ }
+ return false;
+}
+
bool ItemData::isLink(POINT pt, CMStringW &url) const
{
int cp = MTextSendMessage(0, data, EM_CHARFROMPOS, 0, LPARAM(&pt));
@@ -102,9 +118,77 @@ bool ItemData::isLinkChar(int idx) const
return ((res & CFM_LINK) && (cf.dwEffects & CFE_LINK)) || ((res & CFM_REVISED) && (cf.dwEffects & CFE_REVISED));
}
+int ItemData::getTemplate() const
+{
+ switch (dbe.eventType) {
+ case EVENTTYPE_MESSAGE: return isGrouped() ? TPL_MSG_GRP : TPL_MESSAGE;
+ case EVENTTYPE_FILE: return TPL_FILE;
+ case EVENTTYPE_STATUSCHANGE: return TPL_SIGN;
+ case EVENTTYPE_AUTHREQUEST: return TPL_AUTH;
+ case EVENTTYPE_ADDED: return TPL_ADDED;
+ case EVENTTYPE_JABBER_PRESENCE: return TPL_PRESENCE;
+ default:
+ return TPL_OTHER;
+ }
+}
+
+int ItemData::getCopyTemplate() const
+{
+ switch (dbe.eventType) {
+ case EVENTTYPE_MESSAGE: return TPL_COPY_MESSAGE;
+ case EVENTTYPE_FILE: return TPL_COPY_FILE;
+ case EVENTTYPE_STATUSCHANGE: return TPL_COPY_SIGN;
+ case EVENTTYPE_AUTHREQUEST: return TPL_COPY_AUTH;
+ case EVENTTYPE_ADDED: return TPL_COPY_ADDED;
+ case EVENTTYPE_JABBER_PRESENCE: return TPL_COPY_PRESENCE;
+ default:
+ return TPL_COPY_OTHER;
+ }
+}
+
+void ItemData::getFontColor(int &fontId, int &colorId) const
+{
+ switch (dbe.eventType) {
+ case EVENTTYPE_MESSAGE:
+ fontId = !(dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
+ colorId = !(dbe.flags & DBEF_SENT) ? COLOR_INMSG : COLOR_OUTMSG;
+ break;
+
+ case EVENTTYPE_FILE:
+ fontId = !(dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
+ colorId = !(dbe.flags & DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
+ break;
+
+ case EVENTTYPE_STATUSCHANGE:
+ fontId = FONT_STATUS;
+ colorId = COLOR_STATUS;
+ break;
+
+ case EVENTTYPE_AUTHREQUEST:
+ fontId = FONT_INOTHER;
+ colorId = COLOR_INOTHER;
+ break;
+
+ case EVENTTYPE_ADDED:
+ fontId = FONT_INOTHER;
+ colorId = COLOR_INOTHER;
+ break;
+
+ case EVENTTYPE_JABBER_PRESENCE:
+ fontId = !(dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ colorId = !(dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
+ break;
+
+ default:
+ fontId = !(dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ colorId = !(dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
+ break;
+ }
+}
+
void ItemData::load(bool bFullLoad)
{
- if (!bFullLoad || m_bLoaded)
+ if (!bFullLoad && m_bLoaded)
return;
dbe.cbBlob = -1;
@@ -180,91 +264,12 @@ void ItemData::load(bool bFullLoad)
dbe.pBlob = nullptr;
}
-bool ItemData::isGrouped() const
+void ItemData::setText()
{
- if (pPrev && g_plugin.bMsgGrouping) {
- if (!pPrev->m_bLoaded)
- pPrev->load(true);
-
- if (pPrev->hContact == hContact && (pPrev->dbe.flags & DBEF_SENT) == (dbe.flags & DBEF_SENT))
- return true;
- }
- return false;
-}
-
-ItemData::~ItemData()
-{
- mir_free(wtext);
- if (data)
- MTextDestroy(data);
-}
-
-int ItemData::getTemplate() const
-{
- switch (dbe.eventType) {
- case EVENTTYPE_MESSAGE: return isGrouped() ? TPL_MSG_GRP : TPL_MESSAGE;
- case EVENTTYPE_FILE: return TPL_FILE;
- case EVENTTYPE_STATUSCHANGE: return TPL_SIGN;
- case EVENTTYPE_AUTHREQUEST: return TPL_AUTH;
- case EVENTTYPE_ADDED: return TPL_ADDED;
- case EVENTTYPE_JABBER_PRESENCE: return TPL_PRESENCE;
- default:
- return TPL_OTHER;
- }
-}
-
-int ItemData::getCopyTemplate() const
-{
- switch (dbe.eventType) {
- case EVENTTYPE_MESSAGE: return TPL_COPY_MESSAGE;
- case EVENTTYPE_FILE: return TPL_COPY_FILE;
- case EVENTTYPE_STATUSCHANGE: return TPL_COPY_SIGN;
- case EVENTTYPE_AUTHREQUEST: return TPL_COPY_AUTH;
- case EVENTTYPE_ADDED: return TPL_COPY_ADDED;
- case EVENTTYPE_JABBER_PRESENCE: return TPL_COPY_PRESENCE;
- default:
- return TPL_COPY_OTHER;
- }
-}
-
-void ItemData::getFontColor(int &fontId, int &colorId) const
-{
- switch (dbe.eventType) {
- case EVENTTYPE_MESSAGE:
- fontId = !(dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
- colorId = !(dbe.flags & DBEF_SENT) ? COLOR_INMSG : COLOR_OUTMSG;
- break;
-
- case EVENTTYPE_FILE:
- fontId = !(dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
- colorId = !(dbe.flags & DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
- break;
-
- case EVENTTYPE_STATUSCHANGE:
- fontId = FONT_STATUS;
- colorId = COLOR_STATUS;
- break;
-
- case EVENTTYPE_AUTHREQUEST:
- fontId = FONT_INOTHER;
- colorId = COLOR_INOTHER;
- break;
-
- case EVENTTYPE_ADDED:
- fontId = FONT_INOTHER;
- colorId = COLOR_INOTHER;
- break;
-
- case EVENTTYPE_JABBER_PRESENCE:
- fontId = !(dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- colorId = !(dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
- break;
-
- default:
- fontId = !(dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- colorId = !(dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
- break;
- }
+ if (m_bRtf)
+ data = MTextCreateEx(htuLog, this->wtext, MTEXT_FLG_WCHAR | MTEXT_FLG_RTF);
+ else
+ data = MTextCreateW(htuLog, Proto_GetBaseAccountName(hContact), ptrW(TplFormatString(getTemplate(), hContact, this)));
}
// Array
@@ -354,6 +359,19 @@ ItemData& HistoryArray::allocateItem()
return p.data[iLastPageCounter++];
}
+int HistoryArray::find(MEVENT hEvent)
+{
+ int i = 0;
+ for (auto &it : pages)
+ for (auto &p : it->data) {
+ if (p.hEvent == hEvent)
+ return i;
+ i++;
+ }
+
+ return -1;
+}
+
ItemData* HistoryArray::get(int id, bool bLoad)
{
int pageNo = id / HIST_BLOCK_SIZE;
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index e7657dc135..212a85adbb 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -23,6 +23,7 @@ struct ItemData : public MZeroedObject
~ItemData();
void checkCreate(HWND hwnd);
+ void setText();
void load(bool bFullLoad);
bool isGrouped() const;
@@ -130,6 +131,7 @@ public:
bool addEvent(MCONTACT hContact, MEVENT hEvent, int count);
void addChatEvent(SESSION_INFO *si, LOGINFO *pEvent);
void clear();
+ int find(MEVENT hEvent);
int getCount() const;
void reset()
{
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 1a38dce3e5..4e723dfa1c 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -328,6 +328,12 @@ void NewstoryListData::RecalcScrollBar()
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
}
+void NewstoryListData::ScheduleDraw()
+{
+ redrawTimer.Stop();
+ redrawTimer.Start(100);
+}
+
void NewstoryListData::ScrollListBy(int scrollItems, int scrollPixels)
{
if (scrollItems) {
@@ -428,16 +434,12 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
case NSM_ADDEVENTS:
if (auto *p = (ADDEVENTS *)wParam)
data->items.addEvent(p->hContact, p->hFirstEVent, p->eventCount);
-
- data->redrawTimer.Stop();
- data->redrawTimer.Start(100);
+ data->ScheduleDraw();
break;
case NSM_ADDCHATEVENT:
data->items.addChatEvent((SESSION_INFO *)wParam, (LOGINFO *)lParam);
-
- data->redrawTimer.Stop();
- data->redrawTimer.Start(100);
+ data->ScheduleDraw();
break;
case NSM_CLEAR:
@@ -512,7 +514,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int end = min(data->items.getCount() - 1, max(0, lParam));
if (start > end)
std::swap(start, end);
-
+
for (int i = start; i <= end; ++i) {
auto *p = data->items.get(i, false);
p->m_bSelected = false;
@@ -580,6 +582,11 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
case NSM_SET_SRMM:
data->pMsgDlg = (CSrmmBaseDialog *)lParam;
+ lParam = data->pMsgDlg->m_hContact;
+ __fallthrough;
+
+ case NSM_SET_CONTACT:
+ WindowList_Add(g_hNewstoryLogs, hwnd, lParam);
break;
case NSM_COPY:
@@ -595,8 +602,26 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
Utils_ClipboardCopy(res);
}
- __fallthrough;
- // End of history list control messages
+ InvalidateRect(hwnd, 0, FALSE);
+ break;
+
+ case UM_EDITEVENT:
+ idx = data->items.find(lParam);
+ if (idx != -1) {
+ auto *p = data->items[idx];
+ p->load(true);
+ p->setText();
+ data->ScheduleDraw();
+ }
+ break;
+
+ case UM_REMOVEEVENT:
+ idx = data->items.find(lParam);
+ if (idx != -1) {
+ data->items.remove(idx);
+ data->ScheduleDraw();
+ }
+ break;
case WM_SIZE:
InvalidateRect(hwnd, 0, FALSE);
@@ -900,10 +925,11 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
if (s_scrollTopItem != data->scrollTopItem || s_scrollTopPixel != data->scrollTopPixel)
InvalidateRect(hwnd, 0, FALSE);
- break;
}
+ break;
case WM_DESTROY:
+ WindowList_Add(g_hNewstoryLogs, hwnd);
delete data;
SetWindowLongPtr(hwnd, 0, 0);
break;
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index 3d9784b8c1..743992e90a 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -77,7 +77,8 @@ enum
NSM_SEEKTIME,
//
- NSM_SET_SRMM, // act inside SRMM dialog
+ NSM_SET_SRMM, // act inside SRMM dialog
+ NSM_SET_CONTACT,
NSM_LAST
};
@@ -118,10 +119,11 @@ struct NewstoryListData : public MZeroedObject
void EndEditItem(bool bAccept);
void EnsureVisible(int item);
void FixScrollPosition();
- int GetItemFromPixel(int yPos);
- int LayoutItem(int index);
- int PaintItem(HDC hdc, int index, int top, int width);
+ int GetItemFromPixel(int yPos);
+ int LayoutItem(int index);
+ int PaintItem(HDC hdc, int index, int top, int width);
void RecalcScrollBar();
+ void ScheduleDraw();
void ScrollListBy(int scrollItems, int scrollPixels);
void SetPos(int pos);
};
diff --git a/plugins/NewStory/src/main.cpp b/plugins/NewStory/src/main.cpp
index 5c69a9efb0..918d0dbd57 100644
--- a/plugins/NewStory/src/main.cpp
+++ b/plugins/NewStory/src/main.cpp
@@ -84,7 +84,7 @@ static int evtModulesLoaded(WPARAM, LPARAM)
static int evtPreShutdown(WPARAM, LPARAM)
{
- WindowList_Broadcast(hNewstoryWindows, WM_CLOSE, 0, 0);
+ WindowList_Broadcast(g_hNewstoryWindows, WM_CLOSE, 0, 0);
return 0;
}
@@ -108,6 +108,9 @@ int CMPlugin::Load()
int CMPlugin::Unload()
{
+ WindowList_Destroy(g_hNewstoryLogs);
+ WindowList_Destroy(g_hNewstoryWindows);
+
UnregisterSrmmLog(m_log);
UnregisterClass(_T(NEWSTORYLIST_CLASS), g_plugin.getInst());
DestroyFonts();