From 975b603994a6e1f135424a31457db54e56b1dcb3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 2 Aug 2023 18:35:26 +0300 Subject: fixes #2415 (NewStory: add message direction option) --- plugins/NewStory/res/resource.rc | 5 +- plugins/NewStory/src/history_array.h | 1 - plugins/NewStory/src/history_control.cpp | 235 +++++++++++++++++-------------- plugins/NewStory/src/history_control.h | 71 ++++------ plugins/NewStory/src/history_menus.cpp | 2 +- plugins/NewStory/src/history_svc.cpp | 2 +- plugins/NewStory/src/main.cpp | 3 +- plugins/NewStory/src/options.cpp | 32 ++++- plugins/NewStory/src/resource.h | 3 +- plugins/NewStory/src/stdafx.h | 2 +- 10 files changed, 199 insertions(+), 157 deletions(-) (limited to 'plugins') diff --git a/plugins/NewStory/res/resource.rc b/plugins/NewStory/res/resource.rc index 069771bfb7..8197f03223 100644 --- a/plugins/NewStory/res/resource.rc +++ b/plugins/NewStory/res/resource.rc @@ -7,7 +7,7 @@ // // Generated from the TEXTINCLUDE 2 resource. // -#include +#include "winres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -139,9 +139,10 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN CONTROL "Group messages",IDC_GROUPING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,9,289,14 - GROUPBOX "Log window",IDC_STATIC,0,0,307,52 + GROUPBOX "Log window",IDC_STATIC,0,0,307,65 CONTROL "Enable vertical scroll bar",IDC_VSCROLL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,22,289,14 CONTROL "Draw window edge",IDC_DRAWEDGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,35,289,14 + CONTROL "Ascending events sort order",IDC_SORT_ASCENDING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,48,289,14 END IDD_OPT_TEMPLATES DIALOGEX 0, 0, 307, 223 diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index 4e353aadf6..fea6f21e66 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -143,7 +143,6 @@ public: // bool preloadEvents(int count = 10); ItemData* get(int id, bool bLoad = false); - ItemData* operator[] (int id) { return get(id, true); } void remove(int idx); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 52bdb600c8..62b7cd36bf 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -10,9 +10,18 @@ static LRESULT CALLBACK HistoryEditWndProc(HWND, UINT, WPARAM, LPARAM); ///////////////////////////////////////////////////////////////////////// // Control utilities, types and constants +NewstoryListData::NewstoryListData(HWND _1) : + hwnd(_1), + redrawTimer(Miranda_GetSystemWindow(), (LPARAM)this) +{ + bSortAscending = g_plugin.bSortAscending; + + redrawTimer.OnEvent = Callback(this, &NewstoryListData::OnTimer); +} + void NewstoryListData::OnContextMenu(int index, POINT pt) { - ItemData *item = items[index]; + ItemData *item = LoadItem(index); if (item == nullptr) return; @@ -32,20 +41,33 @@ void NewstoryListData::OnResize(int newWidth) if (newWidth == cachedWindowWidth) return; - int count = items.getCount(); - for (int i = 0; i < count; i++) - items[i]->savedHeight = -1; + for (int i = 0; i < totalCount; i++) + LoadItem(i)->savedHeight = -1; } void NewstoryListData::OnTimer(CTimer *pTimer) { pTimer->Stop(); - scrollTopItem = items.getCount(); + scrollTopItem = totalCount; FixScrollPosition(); InvalidateRect(hwnd, 0, FALSE); } +void NewstoryListData::AddSelection(int first, int last) +{ + int start = min(totalCount - 1, first); + int end = min(totalCount - 1, max(0, last)); + if (start > end) + std::swap(start, end); + + for (int i = start; i <= end; ++i) + if (auto *p = GetItem(i)) + p->m_bSelected = true; + + InvalidateRect(hwnd, 0, FALSE); +} + void NewstoryListData::BeginEditItem(int index, bool bReadOnly) { if (hwndEditBox) @@ -54,7 +76,7 @@ void NewstoryListData::BeginEditItem(int index, bool bReadOnly) if (scrollTopItem > index) return; - ItemData *item = items[index]; + ItemData *item = LoadItem(index); if (item->dbe.eventType != EVENTTYPE_MESSAGE) return; @@ -98,9 +120,8 @@ void NewstoryListData::DeleteItems(void) db_set_safety_mode(false); int firstSel = -1; - int eventCount = items.getCount(); - for (int i = eventCount - 1; i >= 0; i--) { - auto *p = items.get(i, false); + for (int i = totalCount - 1; i >= 0; i--) { + auto *p = GetItem(i); if (p->hEvent && p->m_bSelected) { db_event_delete(p->hEvent); items.remove(i); @@ -110,8 +131,8 @@ void NewstoryListData::DeleteItems(void) db_set_safety_mode(true); if (firstSel != -1) { - SendMessage(hwnd, NSM_SETCARET, firstSel, 0); - SendMessage(hwnd, NSM_SELECTITEMS, firstSel, firstSel); + SetCaret(firstSel, false); + SetSelection(firstSel, firstSel); } } @@ -192,7 +213,7 @@ void NewstoryListData::FixScrollPosition() if (windowHeight != cachedWindowHeight || cachedMaxTopItem != scrollTopItem) { int maxTopItem = 0; int tmp = 0; - for (maxTopItem = items.getCount(); (maxTopItem > 0) && (tmp < windowHeight); maxTopItem--) + for (maxTopItem = totalCount; (maxTopItem > 0) && (tmp < windowHeight); maxTopItem--) tmp += GetItemHeight(maxTopItem - 1); cachedMaxTopItem = maxTopItem; cachedWindowHeight = windowHeight; @@ -212,10 +233,17 @@ void NewstoryListData::FixScrollPosition() RecalcScrollBar(); } +ItemData* NewstoryListData::GetItem(int idx) +{ + if (totalCount == 0) + return nullptr; + + return (bSortAscending) ? items.get(idx, false) : items.get(totalCount - 1 - idx, false); +} + int NewstoryListData::GetItemFromPixel(int yPos) { - int count = items.getCount(); - if (!count) + if (!totalCount) return -1; RECT rc; @@ -228,7 +256,7 @@ int NewstoryListData::GetItemFromPixel(int yPos) while (top <= height) { if (yPos >= top && yPos <= bottom) return current; - if (++current >= count) + if (++current >= totalCount) break; top = bottom; bottom = top + GetItemHeight(current); @@ -239,7 +267,7 @@ int NewstoryListData::GetItemFromPixel(int yPos) int NewstoryListData::GetItemHeight(int index) { - ItemData *item = items[index]; + auto *item = LoadItem(index); if (!item) return 0; @@ -265,9 +293,17 @@ int NewstoryListData::GetItemHeight(int index) return item->savedHeight = sz.cy + 5; } +ItemData *NewstoryListData::LoadItem(int idx) +{ + if (totalCount == 0) + return nullptr; + + return (bSortAscending) ? items.get(idx, true) : items.get(totalCount - 1 - idx, true); +} + int NewstoryListData::PaintItem(HDC hdc, int index, int top, int width) { - auto *item = items[index]; + auto *item = LoadItem(index); item->savedTop = top; // LOGFONT lfText; @@ -329,7 +365,7 @@ void NewstoryListData::RecalcScrollBar() si.cbSize = sizeof(si); si.fMask = SIF_ALL; si.nMin = 0; - si.nMax = items.getCount(); + si.nMax = totalCount-1; si.nPage = si.nMax / 10; si.nPos = caret; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); @@ -341,11 +377,39 @@ void NewstoryListData::ScheduleDraw() redrawTimer.Start(100); } +void NewstoryListData::SetCaret(int idx, bool bEnsureVisible) +{ + if (idx < totalCount) { + caret = idx; + if (bEnsureVisible) + EnsureVisible(idx); + } +} + void NewstoryListData::SetPos(int pos) { caret = pos; - SendMessage(hwnd, NSM_SELECTITEMS2, (selStart == -1) ? pos : selStart, pos); - SendMessage(hwnd, NSM_SETCARET, pos, TRUE); + SetSelection((selStart == -1) ? pos : selStart, pos); + SetCaret(pos, true); +} + +void NewstoryListData::SetSelection(int first, int last) +{ + int start = min(totalCount - 1, first); + int end = min(totalCount - 1, max(0, last)); + if (start > end) + std::swap(start, end); + + int count = totalCount; + for (int i = 0; i < count; ++i) { + auto *p = GetItem(i); + if ((i >= start) && (i <= end)) + p->m_bSelected = true; + else + p->m_bSelected = false; + } + + InvalidateRect(hwnd, 0, FALSE); } ///////////////////////////////////////////////////////////////////////// @@ -406,18 +470,22 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM // History list control messages case NSM_ADDEVENTS: - if (auto *p = (ADDEVENTS *)wParam) + if (auto *p = (ADDEVENTS *)wParam) { data->items.addEvent(p->hContact, p->hFirstEVent, p->eventCount); + data->totalCount = data->items.getCount(); + } data->ScheduleDraw(); break; case NSM_ADDCHATEVENT: data->items.addChatEvent((SESSION_INFO *)wParam, (LOGINFO *)lParam); + data->totalCount++; data->ScheduleDraw(); break; case NSM_CLEAR: data->items.clear(); + data->totalCount = 0; data->ScheduleDraw(); break; @@ -425,33 +493,21 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return (LRESULT)&data->items; case NSM_GETCOUNT: - return data->items.getCount(); + return data->totalCount; case NSM_SELECTITEMS: - { - int start = min(data->items.getCount() - 1, (int)wParam); - int end = min(data->items.getCount() - 1, max(0, lParam)); - if (start > end) - std::swap(start, end); - - for (int i = start; i <= end; ++i) { - if (auto *p = data->items.get(i, false)) - p->m_bSelected = true; - } - - InvalidateRect(hwnd, 0, FALSE); - return 0; - } + data->AddSelection(wParam, lParam); + return 0; case NSM_TOGGLEITEMS: { - int start = min(data->items.getCount() - 1, (int)wParam); - int end = min(data->items.getCount() - 1, max(0, lParam)); + int start = min(data->totalCount - 1, (int)wParam); + int end = min(data->totalCount - 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); + auto *p = data->GetItem(i); p->m_bSelected = !p->m_bSelected; } @@ -459,35 +515,15 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return 0; } - case NSM_SELECTITEMS2: - { - int start = min(data->items.getCount() - 1, (int)wParam); - int end = min(data->items.getCount() - 1, max(0, lParam)); - if (start > end) - std::swap(start, end); - - int count = data->items.getCount(); - for (int i = 0; i < count; ++i) { - auto *p = data->items.get(i, false); - if ((i >= start) && (i <= end)) - p->m_bSelected = true; - else - p->m_bSelected = false; - } - - InvalidateRect(hwnd, 0, FALSE); - return 0; - } - case NSM_DESELECTITEMS: { - int start = min(data->items.getCount() - 1, (int)wParam); - int end = min(data->items.getCount() - 1, max(0, lParam)); + int start = min(data->totalCount - 1, (int)wParam); + int end = min(data->totalCount - 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); + auto *p = data->GetItem(i); p->m_bSelected = false; } @@ -495,60 +531,49 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return 0; } - case NSM_ENSUREVISIBLE: - data->EnsureVisible(wParam); - return 0; - case NSM_GETITEMFROMPIXEL: return data->GetItemFromPixel(lParam); - case NSM_SETCARET: - if ((int)wParam < data->items.getCount()) { - data->caret = wParam; - if (lParam) - SendMessage(hwnd, NSM_ENSUREVISIBLE, data->caret, 0); - } - case NSM_GETCARET: return data->caret; case NSM_FINDNEXT: idx = data->items.FindNext(data->caret, Filter(Filter::EVENTONLY, (wchar_t *)wParam)); if (idx >= 0) { - SendMessage(hwnd, NSM_SELECTITEMS2, idx, idx); - SendMessage(hwnd, NSM_SETCARET, idx, TRUE); + data->SetSelection(idx, idx); + data->SetCaret(idx, true); } return idx; case NSM_FINDPREV: idx = data->items.FindPrev(data->caret, Filter(Filter::EVENTONLY, (wchar_t *)wParam)); if (idx >= 0) { - SendMessage(hwnd, NSM_SELECTITEMS2, idx, idx); - SendMessage(hwnd, NSM_SETCARET, idx, TRUE); + data->SetSelection(idx, idx); + data->SetCaret(idx, true); } return idx; case NSM_SEEKTIME: { - int eventCount = data->items.getCount(); + int eventCount = data->totalCount; for (int i = 0; i < eventCount; i++) { - auto *p = data->items.get(i, false); + auto *p = data->GetItem(i); if (p->dbe.timestamp >= wParam) { - SendMessage(hwnd, NSM_SELECTITEMS2, i, i); - SendMessage(hwnd, NSM_SETCARET, i, TRUE); + data->SetSelection(i, i); + data->SetCaret(i, true); break; } if (i == eventCount - 1) { - SendMessage(hwnd, NSM_SELECTITEMS2, i, i); - SendMessage(hwnd, NSM_SETCARET, i, TRUE); + data->SetSelection(i, i); + data->SetCaret(i, true); } } } return TRUE; case NSM_SEEKEND: - SendMessage(hwnd, NSM_SETCARET, data->items.getCount() - 1, 1); + data->SetCaret(data->totalCount - 1, true); break; case NSM_SET_SRMM: @@ -564,9 +589,9 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM { CMStringW res; - int eventCount = data->items.getCount(); + int eventCount = data->totalCount; for (int i = 0; i < eventCount; i++) { - ItemData *p = data->items.get(i, false); + ItemData *p = data->GetItem(i); if (!p->m_bSelected) continue; @@ -588,14 +613,19 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM break; case NSM_DOWNLOAD: - if (auto *p = data->items[data->caret]) + if (auto *p = data->LoadItem(data->caret)) Srmm_DownloadOfflineFile(p->hContact, p->hEvent, lParam); break; + case NSM_SET_OPTIONS: + data->bSortAscending = g_plugin.bSortAscending; + data->ScheduleDraw(); + break; + case UM_EDITEVENT: idx = data->items.find(lParam); if (idx != -1) { - auto *p = data->items[idx]; + auto *p = data->LoadItem(idx); p->load(true); p->setText(); data->ScheduleDraw(); @@ -642,7 +672,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM int width = rc.right - rc.left; int top = data->scrollTopPixel; idx = data->scrollTopItem; - while ((top < height) && (idx < data->items.getCount())) + while ((top < height) && (idx < data->totalCount)) top += data->PaintItem(hdc, idx++, top, width); if (top <= height) { @@ -677,9 +707,8 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM if (idx != -1) { if (data->caret != idx) data->EndEditItem(false); - SendMessage(hwnd, NSM_SELECTITEMS2, idx, idx); - SendMessage(hwnd, NSM_SETCARET, idx, TRUE); - + data->SetSelection(idx, idx); + data->SetCaret(idx, true); data->OnContextMenu(idx, pt); } break; @@ -762,7 +791,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case 'A': if (isCtrl) - SendMessage(hwnd, NSM_SELECTITEMS, 0, data->items.getCount()); + data->AddSelection(0, data->totalCount); break; } } @@ -775,15 +804,15 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM if (data->caret != idx) data->EndEditItem(false); - auto *pItem = data->items[idx]; + auto *pItem = data->LoadItem(idx); if (wParam & MK_CONTROL) { SendMessage(hwnd, NSM_TOGGLEITEMS, idx, idx); - SendMessage(hwnd, NSM_SETCARET, idx, TRUE); + data->SetCaret(idx, true); } else if (wParam & MK_SHIFT) { - SendMessage(hwnd, NSM_SELECTITEMS, data->caret, idx); - SendMessage(hwnd, NSM_SETCARET, idx, TRUE); + data->AddSelection(data->caret, idx); + data->SetCaret(idx, true); } else { pt.y -= pItem->savedTop; @@ -794,8 +823,8 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return 0; } - SendMessage(hwnd, NSM_SELECTITEMS2, idx, idx); - SendMessage(hwnd, NSM_SETCARET, idx, TRUE); + data->SetSelection(idx, idx); + data->SetCaret(idx, true); } } SetFocus(hwnd); @@ -808,7 +837,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM if (data->caret != idx) data->EndEditItem(false); - auto *pItem = data->items[idx]; + auto *pItem = data->LoadItem(idx); pt.y -= pItem->savedTop; if (pItem->m_bOfflineFile) { @@ -829,7 +858,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; idx = data->GetItemFromPixel(pt.y); if (idx >= 0) { - auto *pItem = data->items[idx]; + auto *pItem = data->LoadItem(idx); MTextSendMessage(hwnd, pItem->data, msg, wParam, lParam); } break; @@ -871,8 +900,8 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM si.cbSize = sizeof(si); si.fMask = SIF_TRACKPOS | SIF_RANGE; GetScrollInfo(hwnd, SB_VERT, &si); - data->SetPos(data->items.getCount() * si.nTrackPos / si.nMax); - //data->FixScrollPosition(); + data->SetPos(data->totalCount * si.nTrackPos / si.nMax); + data->FixScrollPosition(); } break; diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index 3b84558539..38d2d65ad5 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -24,20 +24,11 @@ enum // result = number of total selected items NSM_TOGGLEITEMS, - // wParam = fist item - // lParam = last item - // result = number of total selected items - // select items wParam - lParam and deselect all other - NSM_SELECTITEMS2, - // wParam = fist item // lParam = last item // result = number of total selected items NSM_DESELECTITEMS, - // wParam = item id - NSM_ENSUREVISIBLE, - // wParam = x in control // lParam = y in control // result = id @@ -50,9 +41,6 @@ enum // clear log NSM_CLEAR, - // wParam = id - NSM_SETCARET, - // result = id NSM_GETCARET, @@ -79,19 +67,15 @@ enum // NSM_SET_SRMM, // act inside SRMM dialog - NSM_SET_CONTACT, + NSM_SET_CONTACT, // set hContact + NSM_SET_OPTIONS, // options were changed NSM_LAST }; struct NewstoryListData : public MZeroedObject { - NewstoryListData(HWND _1) : - hwnd(_1), - redrawTimer(Miranda_GetSystemWindow(), (LPARAM)this) - { - redrawTimer.OnEvent = Callback(this, &NewstoryListData::OnTimer); - } + NewstoryListData(HWND); HistoryArray items; @@ -103,10 +87,11 @@ struct NewstoryListData : public MZeroedObject int cachedMaxTopItem; // the largest ID of top item to avoid empty space int cachedMaxTopPixel; int cachedWindowWidth = -1; + int totalCount; RECT rcLastPaint; - bool bWasShift; + bool bWasShift, bSortAscending; HWND hwnd; HWND hwndEditBox; @@ -114,20 +99,26 @@ struct NewstoryListData : public MZeroedObject CTimer redrawTimer; CSrmmBaseDialog *pMsgDlg = nullptr; - void OnContextMenu(int index, POINT pt); - void OnResize(int newWidth); - void OnTimer(CTimer *pTimer); - void BeginEditItem(int index, bool bReadOnly); - void DeleteItems(void); - void EndEditItem(bool bAccept); - void EnsureVisible(int item); - void FixScrollPosition(); - int GetItemFromPixel(int yPos); - int GetItemHeight(int index); - int PaintItem(HDC hdc, int index, int top, int width); - void RecalcScrollBar(); - void ScheduleDraw(); - void SetPos(int pos); + void OnContextMenu(int index, POINT pt); + void OnResize(int newWidth); + void OnTimer(CTimer *pTimer); + + void AddSelection(int first, int last); + void BeginEditItem(int index, bool bReadOnly); + void DeleteItems(void); + void EndEditItem(bool bAccept); + void EnsureVisible(int item); + void FixScrollPosition(); + ItemData* GetItem(int idx); + int GetItemFromPixel(int yPos); + int GetItemHeight(int index); + ItemData* LoadItem(int idx); + int PaintItem(HDC hdc, int index, int top, int width); + void RecalcScrollBar(); + void ScheduleDraw(); + void SetCaret(int idx, bool bEnsureVisible); + void SetPos(int pos); + void SetSelection(int first, int last); void LineUp() { @@ -137,7 +128,7 @@ struct NewstoryListData : public MZeroedObject void LineDown() { - if (caret < items.getCount() - 1) + if (caret < totalCount - 1) SetPos(caret + 1); } @@ -151,11 +142,11 @@ struct NewstoryListData : public MZeroedObject void PageDown() { - if (int count = items.getCount()) { - if (caret + 10 < count - 1) + if (totalCount) { + if (caret + 10 < totalCount - 1) SetPos(caret + 10); else - SetPos(count - 1); + SetPos(totalCount - 1); } } @@ -166,8 +157,8 @@ struct NewstoryListData : public MZeroedObject void ScrollBottom() { - if (int count = items.getCount()) - SetPos(count - 1); + if (totalCount) + SetPos(totalCount - 1); } }; diff --git a/plugins/NewStory/src/history_menus.cpp b/plugins/NewStory/src/history_menus.cpp index 3acbde588b..48b800715b 100644 --- a/plugins/NewStory/src/history_menus.cpp +++ b/plugins/NewStory/src/history_menus.cpp @@ -46,7 +46,7 @@ static INT_PTR NSMenuHelper(WPARAM wParam, LPARAM lParam) break; case 4: - SendMessage(pData->hwnd, NSM_SELECTITEMS, 0, pData->items.getCount() - 1); + SendMessage(pData->hwnd, NSM_SELECTITEMS, 0, pData->totalCount - 1); break; case 5: diff --git a/plugins/NewStory/src/history_svc.cpp b/plugins/NewStory/src/history_svc.cpp index 336f0ada37..ad59635956 100644 --- a/plugins/NewStory/src/history_svc.cpp +++ b/plugins/NewStory/src/history_svc.cpp @@ -22,7 +22,7 @@ static INT_PTR SvcGetSelection(WPARAM wParam, LPARAM lParam) auto *pData = (NewstoryListData *)wParam; auto *pRet = (std::vector*)lParam; if (pData && pRet) { - for (int i = pData->items.getCount(); i >= 0; i--) { + for (int i = pData->totalCount; i >= 0; i--) { auto *p = pData->items.get(i); if (p->m_bSelected) pRet->push_back(p->hEvent); diff --git a/plugins/NewStory/src/main.cpp b/plugins/NewStory/src/main.cpp index 918d0dbd57..16747f78d4 100644 --- a/plugins/NewStory/src/main.cpp +++ b/plugins/NewStory/src/main.cpp @@ -34,7 +34,8 @@ PLUGININFOEX pluginInfoEx = CMPlugin::CMPlugin() : PLUGIN(MODULENAME, pluginInfoEx), - bOptVScroll(MODULENAME, "VScroll", true) + bOptVScroll(MODULENAME, "VScroll", true), + bSortAscending(MODULENAME, "SortAscending", true) { } diff --git a/plugins/NewStory/src/options.cpp b/plugins/NewStory/src/options.cpp index 3e8beaadfc..4e7e6372be 100644 --- a/plugins/NewStory/src/options.cpp +++ b/plugins/NewStory/src/options.cpp @@ -1,22 +1,42 @@ #include "stdafx.h" +///////////////////////////////////////////////////////////////////////////////////////// +// Basic options page class + +class CBaseOptsDlg : public CDlgBase +{ +protected: + CBaseOptsDlg(int iDlgId) : + CDlgBase(g_plugin, iDlgId) + { + m_OnFinishWizard = Callback(this, &CBaseOptsDlg::OnFinish); + } + + void OnFinish(void *) + { + WindowList_BroadcastAsync(g_hNewstoryLogs, NSM_SET_OPTIONS, 0, 0); + } +}; + ///////////////////////////////////////////////////////////////////////////////////////// // General options dialog -class CGeneralOptsDlg : public CDlgBase +class CGeneralOptsDlg : public CBaseOptsDlg { - CCtrlCheck chkGrouping, chkVScroll, chkDrawEdge; + CCtrlCheck chkGrouping, chkVScroll, chkDrawEdge, chkSortOrder; public: CGeneralOptsDlg() : - CDlgBase(g_plugin, IDD_OPT_ADVANCED), + CBaseOptsDlg(IDD_OPT_ADVANCED), chkVScroll(this, IDC_VSCROLL), chkDrawEdge(this, IDC_DRAWEDGE), - chkGrouping(this, IDC_GROUPING) + chkGrouping(this, IDC_GROUPING), + chkSortOrder(this, IDC_SORT_ASCENDING) { CreateLink(chkVScroll, g_plugin.bOptVScroll); CreateLink(chkGrouping, g_bOptGrouping); CreateLink(chkDrawEdge, g_bOptDrawEdge); + CreateLink(chkSortOrder, g_plugin.bSortAscending); } bool OnApply() override @@ -30,7 +50,7 @@ public: ///////////////////////////////////////////////////////////////////////////////////////// // Template options dialog -class CTemplateOptsDlg : public CDlgBase +class CTemplateOptsDlg : public CBaseOptsDlg { MCONTACT m_hContact; MEVENT m_hDbEVent; @@ -57,7 +77,7 @@ class CTemplateOptsDlg : public CDlgBase public: CTemplateOptsDlg() : - CDlgBase(g_plugin, IDD_OPT_TEMPLATES), + CBaseOptsDlg(IDD_OPT_TEMPLATES), m_edit(this, IDC_EDITTEMPLATE), m_tree(this, IDC_TEMPLATES), preview(this, IDC_PREVIEW), diff --git a/plugins/NewStory/src/resource.h b/plugins/NewStory/src/resource.h index fc1bb6966a..47234f6a50 100644 --- a/plugins/NewStory/src/resource.h +++ b/plugins/NewStory/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by w:\miranda-ng\plugins\NewStory\res\resource.rc +// Used by W:\miranda-ng\plugins\NewStory\res\resource.rc // #define IDD_HISTORY 101 #define IDD_OPT_TEMPLATES 102 @@ -86,6 +86,7 @@ #define IDC_VARHELP 1055 #define IDC_VSCROLL 1056 #define IDC_DRAWEDGE 1057 +#define IDC_SORT_ASCENDING 1058 #define ID_FILTER_SHOWALLEVENTS 40001 #define ID_FILTER_SHOWINCOMINGEVENTSONLY 40002 #define ID_FILTER_SHOWOUTGOINGEVENTSONLY 40003 diff --git a/plugins/NewStory/src/stdafx.h b/plugins/NewStory/src/stdafx.h index 39f00c47af..f0429246a7 100644 --- a/plugins/NewStory/src/stdafx.h +++ b/plugins/NewStory/src/stdafx.h @@ -84,7 +84,7 @@ struct CMPlugin : public PLUGIN { HANDLE m_log; - CMOption bOptVScroll; + CMOption bOptVScroll, bSortAscending; bool bMsgGrouping, bDrawEdge; // thesw options are a copy of static CMOption to keep performance high CMPlugin(); -- cgit v1.2.3