diff options
author | George Hazan <george.hazan@gmail.com> | 2023-08-14 14:30:56 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-08-14 14:30:56 +0300 |
commit | ec7b698640006863ee289c73f7bd3bf2590be32f (patch) | |
tree | 239200f27a69237209db2e2760a7fb2742eeefa5 /plugins/NewStory/src | |
parent | e17ab7d1d4fbe0a32e3153235b8316a1f38ddef3 (diff) |
NewStory: direct control methods' usage instead of the slow message sending
Diffstat (limited to 'plugins/NewStory/src')
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 6 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.h | 4 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 64 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.h | 19 | ||||
-rw-r--r-- | plugins/NewStory/src/history_dlg.cpp | 37 | ||||
-rw-r--r-- | plugins/NewStory/src/history_log.cpp | 9 |
6 files changed, 66 insertions, 73 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 43e9d1e516..0db96c8b51 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -333,7 +333,7 @@ void HistoryArray::clear() iLastPageCounter = 0; } -void HistoryArray::addChatEvent(SESSION_INFO *si, LOGINFO *lin) +void HistoryArray::addChatEvent(SESSION_INFO *si, const LOGINFO *lin) { if (si == nullptr) return; @@ -406,12 +406,12 @@ bool HistoryArray::addEvent(MCONTACT hContact, MEVENT hEvent, int count) return true; } -void HistoryArray::addResults(OBJLIST<SearchResult> *pArray) +void HistoryArray::addResults(const OBJLIST<SearchResult> &pArray) { int numItems = getCount(); auto *pPrev = (numItems == 0) ? nullptr : get(numItems - 1); - for (auto &it : *pArray) { + for (auto &it : pArray) { auto &p = allocateItem(); p.hContact = it->hContact; p.hEvent = it->hEvent; diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index 5ca180ff82..263cd8dfdf 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -127,8 +127,8 @@ public: ~HistoryArray(); bool addEvent(MCONTACT hContact, MEVENT hEvent, int count); - void addChatEvent(SESSION_INFO *si, LOGINFO *pEvent); - void addResults(OBJLIST<SearchResult> *pArray); + void addChatEvent(SESSION_INFO *si, const LOGINFO *pEvent); + void addResults(const OBJLIST<SearchResult> &pArray); void clear(); int find(MEVENT hEvent); int find(int id, int dir, const Filter &filter); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 7856c005bf..e86c882451 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -77,6 +77,30 @@ void NewstoryListData::OnTimer(CTimer *pTimer) InvalidateRect(hwnd, 0, FALSE); } +void NewstoryListData::AddChatEvent(SESSION_INFO *si, const LOGINFO *lin) +{ + items.addChatEvent(si, lin); + totalCount++; + hasData = true; + ScheduleDraw(); +} + +void NewstoryListData::AddEvent(MCONTACT hContact, MEVENT hFirstEvent, int iCount) +{ + items.addEvent(hContact, hFirstEvent, iCount); + totalCount = items.getCount(); + hasData = true; + ScheduleDraw(); +} + +void NewstoryListData::AddResults(const OBJLIST<SearchResult> &results) +{ + items.addResults(results); + totalCount = items.getCount(); + hasData = true; + ScheduleDraw(); +} + void NewstoryListData::AddSelection(int iFirst, int iLast) { int start = min(totalCount - 1, iFirst); @@ -135,6 +159,13 @@ void NewstoryListData::BeginEditItem(int index, bool bReadOnly) SetFocus(hwndEditBox); } +void NewstoryListData::Clear() +{ + items.clear(); + totalCount = 0; + InvalidateRect(hwnd, 0, FALSE); +} + void NewstoryListData::ClearSelection(int iFirst, int iLast) { int start = min(totalCount - 1, iFirst); @@ -618,38 +649,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VSCROLL); break; - // History list control messages - case NSM_ADDEVENTS: - if (auto *p = (ADDEVENTS *)wParam) { - data->items.addEvent(p->hContact, p->hFirstEVent, p->eventCount); - data->totalCount = data->items.getCount(); - } - data->hasData = true; - data->ScheduleDraw(); - break; - - case NSM_ADDCHATEVENT: - data->items.addChatEvent((SESSION_INFO *)wParam, (LOGINFO *)lParam); - data->totalCount++; - data->hasData = true; - data->ScheduleDraw(); - break; - - case NSM_ADDRESULTS: - if (auto *pResults = (OBJLIST<SearchResult>*)wParam) { - data->items.addResults(pResults); - data->totalCount = data->items.getCount(); - data->hasData = true; - data->ScheduleDraw(); - } - break; - - case NSM_CLEAR: - data->items.clear(); - data->totalCount = 0; - InvalidateRect(hwnd, 0, FALSE); - break; - + // History list control messages case NSM_GETARRAY: return (LRESULT)&data->items; diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index cb653364a5..2f63056a97 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -3,13 +3,6 @@ #define NEWSTORYLIST_CLASS "NewstoryList" -struct ADDEVENTS -{ - MCONTACT hContact; - MEVENT hFirstEVent; - int eventCount; -}; - enum { NSM_FIRST = WM_USER + 100, @@ -19,14 +12,6 @@ enum // result = number of total selected items NSM_SELECTITEMS = NSM_FIRST, - // add one or more events - NSM_ADDEVENTS, - NSM_ADDCHATEVENT, - NSM_ADDRESULTS, - - // clear log - NSM_CLEAR, - // result = id NSM_GETCARET, @@ -92,8 +77,12 @@ struct NewstoryListData : public MZeroedObject void OnResize(int newWidth); void OnTimer(CTimer *pTimer); + void AddChatEvent(SESSION_INFO *si, const LOGINFO *lin); + void AddEvent(MCONTACT hContact, MEVENT hFirstEvent, int iCount); + void AddResults(const OBJLIST<SearchResult> &results); void AddSelection(int iFirst, int iLast); void BeginEditItem(int index, bool bReadOnly); + void Clear(); void ClearSelection(int iFirst, int iLast); void DeleteItems(void); void EndEditItem(bool bAccept); diff --git a/plugins/NewStory/src/history_dlg.cpp b/plugins/NewStory/src/history_dlg.cpp index 250c2b3bab..66655f5f7e 100644 --- a/plugins/NewStory/src/history_dlg.cpp +++ b/plugins/NewStory/src/history_dlg.cpp @@ -104,6 +104,9 @@ class CHistoryDlg : public CDlgBase // main controls HWND m_hwndTimeTree; + CCtrlBase m_histWindow; + NewstoryListData *m_histCtrl; + // searchbar HWND m_hwndBtnCloseSearch; // statusbar @@ -127,7 +130,7 @@ class CHistoryDlg : public CDlgBase return; // clear messages array first - m_histControl.SendMsg(NSM_CLEAR, 0, 0); + m_histCtrl->Clear(); CharLowerW(wszPattern); DoSearchContact(0, wszPattern); @@ -135,7 +138,7 @@ class CHistoryDlg : public CDlgBase DoSearchContact(hContact, wszPattern); qsort(m_arResults.getArray(), m_arResults.getCount(), sizeof(void *), stubSortResults); - m_histControl.SendMsg(NSM_ADDRESULTS, WPARAM(&m_arResults), 0); + m_histCtrl->AddResults(m_arResults); m_arResults.destroy(); TimeTreeBuild(); @@ -226,7 +229,7 @@ class CHistoryDlg : public CDlgBase return; m_timeTree.DeleteAllItems(); - auto *pArray = (HistoryArray *)m_histControl.SendMsg(NSM_GETARRAY, 0, 0); + auto *pArray = (HistoryArray *)m_histWindow.SendMsg(NSM_GETARRAY, 0, 0); int numItems = pArray->getCount(); int CurYear = 0, CurMonth = 0, CurDay = 0, PrevYear = -1, PrevMonth = -1, PrevDay = -1; @@ -277,7 +280,6 @@ class CHistoryDlg : public CDlgBase m_timeTree.SelectItem(root); } - CCtrlBase m_histControl; CCtrlEdit edtSearchText; CCtrlMButton btnUserInfo, btnSendMsg, btnUserMenu, btnCopy, btnOptions, btnFilter; CCtrlMButton btnCalendar, btnSearch, btnExport, btnFindNext, btnFindPrev, btnDelete, btnTimeTree; @@ -289,7 +291,7 @@ public: m_arResults(10000), m_hContact(_hContact), m_timeTree(this, IDC_TIMETREEVIEW), - m_histControl(this, IDC_HISTORYCONTROL), + m_histWindow(this, IDC_HISTORYCONTROL), edtSearchText(this, IDC_SEARCHTEXT), btnCopy(this, IDC_COPY, g_plugin.getIcon(IDI_COPY), LPGEN("Copy")), btnExport(this, IDC_EXPORT, g_plugin.getIcon(IDI_EXPORT), LPGEN("Export...")), @@ -432,14 +434,15 @@ public: ShowHideControls(); UpdateTitle(); + m_histCtrl = (NewstoryListData *)GetWindowLongPtr(m_histWindow.GetHwnd(), GWLP_USERDATA); + if (m_hContact != INVALID_CONTACT_ID) { Utils_RestoreWindowPosition(m_hwnd, m_hContact, MODULENAME, "wnd_"); - ADDEVENTS tmp = { m_hContact, 0, -1 }; - m_histControl.SendMsg(NSM_ADDEVENTS, WPARAM(&tmp), 0); + m_histCtrl->AddEvent(m_hContact, 0, -1); TimeTreeBuild(); - SetFocus(m_histControl.GetHwnd()); + SetFocus(m_histWindow.GetHwnd()); } else { btnSendMsg.Disable(); @@ -450,8 +453,8 @@ public: m_dwOptions |= WND_OPT_SEARCHBAR; } - m_histControl.SendMsg(NSM_SET_CONTACT, m_hContact, 0); - m_histControl.SendMsg(NSM_SEEKEND, 0, 0); + m_histWindow.SendMsg(NSM_SET_CONTACT, m_hContact, 0); + m_histWindow.SendMsg(NSM_SEEKEND, 0, 0); Window_SetIcon_IcoLib(m_hwnd, g_plugin.getIconHandle(IDI_NEWSTORY)); @@ -483,7 +486,7 @@ public: DoGlobalSearch(); } - m_histControl.SendMsg(NSM_FINDNEXT, ptrW(edtSearchText.GetText()), 0); + m_histWindow.SendMsg(NSM_FINDNEXT, ptrW(edtSearchText.GetText()), 0); return false; } @@ -614,7 +617,7 @@ public: SWP_NOZORDER | SWP_NOACTIVATE); } - hDwp = DeferWindowPos(hDwp, m_histControl.GetHwnd(), 0, + hDwp = DeferWindowPos(hDwp, m_histWindow.GetHwnd(), 0, WND_SPACING + hTimeTree, WND_SPACING + hToolBar + hFilterBar, w - WND_SPACING * 2 - hTimeTree, h - WND_SPACING * 2 - hFilterBar - hToolBar - hSearch - hStatus, SWP_NOZORDER | SWP_NOACTIVATE); @@ -651,13 +654,13 @@ public: void onClick_Copy(CCtrlButton *) { - m_histControl.SendMsg(NSM_COPY, 0, 0); + m_histWindow.SendMsg(NSM_COPY, 0, 0); } void onClick_Delete(CCtrlButton *) { CallService(MS_HISTORY_EMPTY, m_hContact, 0); - m_histControl.SendMsg(NSM_CLEAR, 0, 0); + m_histCtrl->Clear(); UpdateTitle(); TimeTreeBuild(); @@ -814,7 +817,7 @@ public: void onClick_FindPrev(CCtrlButton *) { - m_histControl.SendMsg(NSM_FINDPREV, ptrW(edtSearchText.GetText()), 0); + m_histWindow.SendMsg(NSM_FINDPREV, ptrW(edtSearchText.GetText()), 0); } void onClick_Message(CCtrlButton *) @@ -877,7 +880,7 @@ public: INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override { if ((msg >= NSM_FIRST) && (msg < NSM_LAST)) { - LPARAM result = m_histControl.SendMsg(msg, wParam, lParam); + LPARAM result = m_histWindow.SendMsg(msg, wParam, lParam); SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, result); return result; } @@ -981,7 +984,7 @@ public: case WM_USER + 0x600: if (wParam) - m_histControl.SendMsg(NSM_SEEKTIME, wParam, 0); + m_histWindow.SendMsg(NSM_SEEKTIME, wParam, 0); } return CDlgBase::DlgProc(msg, wParam, lParam); diff --git a/plugins/NewStory/src/history_log.cpp b/plugins/NewStory/src/history_log.cpp index 7b85321202..8f16ca1e92 100644 --- a/plugins/NewStory/src/history_log.cpp +++ b/plugins/NewStory/src/history_log.cpp @@ -3,6 +3,7 @@ class CNewStoryLogWindow : public CSimpleLogWindow { HWND m_hwnd = nullptr; + NewstoryListData *m_histCtrl; public: CNewStoryLogWindow(CMsgDialog &pDlg) : @@ -19,6 +20,7 @@ public: 0, 0, rc.left - rc.right, rc.bottom - rc.top, m_pDlg.GetHwnd(), 0, m_pDlg.GetInst(), 0); SendMessage(m_hwnd, NSM_SET_SRMM, 0, (LPARAM)&m_pDlg); + m_histCtrl = (NewstoryListData *)GetWindowLongPtr(m_hwnd, GWLP_USERDATA); } void Detach() override @@ -37,7 +39,7 @@ public: void Clear() override { - SendMessage(m_hwnd, NSM_CLEAR, 0, 0); + m_histCtrl->Clear(); } HWND GetHwnd() override @@ -60,13 +62,12 @@ public: if (!bAppend) Clear(); - ADDEVENTS tmp = { m_pDlg.m_hContact, hDbEventFirst, count }; - SendMessage(m_hwnd, NSM_ADDEVENTS, (LPARAM)&tmp, 0); + m_histCtrl->AddEvent(m_pDlg.m_hContact, hDbEventFirst, count); } void LogChatEvent(const LOGINFO &lin) override { - SendMessage(m_hwnd, NSM_ADDCHATEVENT, (WPARAM)m_pDlg.getChat(), (LPARAM)&lin); + m_histCtrl->AddChatEvent(m_pDlg.getChat(), &lin); } void Resize() override |