summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src/history_control.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-08-02 18:46:15 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-08-02 18:46:15 +0300
commitf847488c4175051f1608905ef00b28867326ff19 (patch)
tree1857ecc4565fdb0287f8c2a5433558ec33c412f0 /plugins/NewStory/src/history_control.cpp
parent975b603994a6e1f135424a31457db54e56b1dcb3 (diff)
code cleaning
Diffstat (limited to 'plugins/NewStory/src/history_control.cpp')
-rw-r--r--plugins/NewStory/src/history_control.cpp79
1 files changed, 37 insertions, 42 deletions
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) {