diff options
author | George Hazan <george.hazan@gmail.com> | 2023-08-02 18:46:15 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-08-02 18:46:15 +0300 |
commit | f847488c4175051f1608905ef00b28867326ff19 (patch) | |
tree | 1857ecc4565fdb0287f8c2a5433558ec33c412f0 /plugins/NewStory/src | |
parent | 975b603994a6e1f135424a31457db54e56b1dcb3 (diff) |
code cleaning
Diffstat (limited to 'plugins/NewStory/src')
-rw-r--r-- | plugins/NewStory/src/history.cpp | 3 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 79 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.h | 23 |
3 files changed, 44 insertions, 61 deletions
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index d722241819..52449c633a 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -545,7 +545,8 @@ public: ADDEVENTS tmp = { m_hContact, 0, -1 }; m_histControl.SendMsg(NSM_ADDEVENTS, WPARAM(&tmp), 0); - m_histControl.SendMsg(WM_KEYDOWN, VK_END, 0); + m_histControl.SendMsg(NSM_SET_CONTACT, m_hContact, 0); + m_histControl.SendMsg(NSM_SEEKEND, 0, 0); Window_SetIcon_IcoLib(m_hwnd, g_plugin.getIconHandle(ICO_NEWSTORY)); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 62b7cd36bf..f40b4663dc 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -54,10 +54,10 @@ void NewstoryListData::OnTimer(CTimer *pTimer) InvalidateRect(hwnd, 0, FALSE); } -void NewstoryListData::AddSelection(int first, int last) +void NewstoryListData::AddSelection(int iFirst, int iLast) { - int start = min(totalCount - 1, first); - int end = min(totalCount - 1, max(0, last)); + int start = min(totalCount - 1, iFirst); + int end = min(totalCount - 1, max(0, iLast)); if (start > end) std::swap(start, end); @@ -112,6 +112,21 @@ void NewstoryListData::BeginEditItem(int index, bool bReadOnly) SetFocus(hwndEditBox); } +void NewstoryListData::ClearSelection(int iFirst, int iLast) +{ + int start = min(totalCount - 1, iFirst); + int end = min(totalCount - 1, max(0, iLast)); + if (start > end) + std::swap(start, end); + + for (int i = start; i <= end; ++i) { + auto *p = GetItem(i); + p->m_bSelected = false; + } + + InvalidateRect(hwnd, 0, FALSE); +} + void NewstoryListData::DeleteItems(void) { if (IDYES != MessageBoxW(hwnd, TranslateT("Are you sure to remove selected event(s)?"), _T(MODULETITLE), MB_YESNOCANCEL | MB_ICONQUESTION)) @@ -393,10 +408,10 @@ void NewstoryListData::SetPos(int pos) SetCaret(pos, true); } -void NewstoryListData::SetSelection(int first, int last) +void NewstoryListData::SetSelection(int iFirst, int iLast) { - int start = min(totalCount - 1, first); - int end = min(totalCount - 1, max(0, last)); + int start = min(totalCount - 1, iFirst); + int end = min(totalCount - 1, max(0, iLast)); if (start > end) std::swap(start, end); @@ -412,6 +427,21 @@ void NewstoryListData::SetSelection(int first, int last) InvalidateRect(hwnd, 0, FALSE); } +void NewstoryListData::ToggleSelection(int iFirst, int iLast) +{ + int start = min(totalCount - 1, iFirst); + int end = min(totalCount - 1, max(0, iLast)); + if (start > end) + std::swap(start, end); + + for (int i = start; i <= end; ++i) { + auto *p = GetItem(i); + p->m_bSelected = !p->m_bSelected; + } + + InvalidateRect(hwnd, 0, FALSE); +} + ///////////////////////////////////////////////////////////////////////// // Edit box window procedure @@ -499,41 +529,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM data->AddSelection(wParam, lParam); return 0; - case NSM_TOGGLEITEMS: - { - 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->GetItem(i); - p->m_bSelected = !p->m_bSelected; - } - - InvalidateRect(hwnd, 0, FALSE); - return 0; - } - - case NSM_DESELECTITEMS: - { - 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->GetItem(i); - p->m_bSelected = false; - } - - InvalidateRect(hwnd, 0, FALSE); - return 0; - } - - case NSM_GETITEMFROMPIXEL: - return data->GetItemFromPixel(lParam); - case NSM_GETCARET: return data->caret; @@ -807,7 +802,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM auto *pItem = data->LoadItem(idx); if (wParam & MK_CONTROL) { - SendMessage(hwnd, NSM_TOGGLEITEMS, idx, idx); + data->ToggleSelection(idx, idx); data->SetCaret(idx, true); } else if (wParam & MK_SHIFT) { diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index 38d2d65ad5..cbcdbc3b3d 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -15,25 +15,10 @@ enum NSM_FIRST = WM_USER + 100, // wParam = fist item - // lParam = last item + // lParam = iLast item // result = number of total selected items NSM_SELECTITEMS = NSM_FIRST, - // wParam = fist item - // lParam = last item - // result = number of total selected items - NSM_TOGGLEITEMS, - - // wParam = fist item - // lParam = last item - // result = number of total selected items - NSM_DESELECTITEMS, - - // wParam = x in control - // lParam = y in control - // result = id - NSM_GETITEMFROMPIXEL, - // add one or more events NSM_ADDEVENTS, NSM_ADDCHATEVENT, @@ -103,8 +88,9 @@ struct NewstoryListData : public MZeroedObject void OnResize(int newWidth); void OnTimer(CTimer *pTimer); - void AddSelection(int first, int last); + void AddSelection(int iFirst, int iLast); void BeginEditItem(int index, bool bReadOnly); + void ClearSelection(int iFirst, int iLast); void DeleteItems(void); void EndEditItem(bool bAccept); void EnsureVisible(int item); @@ -118,7 +104,8 @@ struct NewstoryListData : public MZeroedObject void ScheduleDraw(); void SetCaret(int idx, bool bEnsureVisible); void SetPos(int pos); - void SetSelection(int first, int last); + void SetSelection(int iFirst, int iLast); + void ToggleSelection(int iFirst, int iLast); void LineUp() { |