diff options
author | George Hazan <ghazan@miranda.im> | 2021-05-08 18:18:34 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-05-10 19:45:55 +0300 |
commit | 0943ae89e869ded753e5fbc5b64dca458a8f31b8 (patch) | |
tree | 7a661c8402302df8a4eb2d20b97218e346d896c9 /src | |
parent | acd0d6c62891a2e3fa0bf94b66b93e65e5922e24 (diff) |
CCtrlListView::MoveItem, CCtrlListView::SetCurSel, CCtrlCombo::SelectData - new useful methods
(cherry picked from commit 9661e86b4d2e1280b6e5e562ffafb46d1b6c0817)
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_core/src/CCtrlCombo.cpp | 17 | ||||
-rw-r--r-- | src/mir_core/src/CCtrlListView.cpp | 31 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 3 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 3 |
4 files changed, 54 insertions, 0 deletions
diff --git a/src/mir_core/src/CCtrlCombo.cpp b/src/mir_core/src/CCtrlCombo.cpp index 39e82949f6..a7abf1d707 100644 --- a/src/mir_core/src/CCtrlCombo.cpp +++ b/src/mir_core/src/CCtrlCombo.cpp @@ -76,6 +76,23 @@ void CCtrlCombo::OnReset() SetInt(LoadInt()); } +// selects line with userdata passed +int CCtrlCombo::SelectData(LPARAM data) +{ + int ret = -1, nCount = GetCount(); + + for (int i = 0; i < nCount; i++) + if (GetItemData(i) == data) { + ret = i; + break; + } + + return SetCurSel(ret); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Windows API + int CCtrlCombo::AddString(const wchar_t *text, LPARAM data) { int iItem = SendMessage(m_hwnd, CB_ADDSTRING, 0, (LPARAM)text); diff --git a/src/mir_core/src/CCtrlListView.cpp b/src/mir_core/src/CCtrlListView.cpp index ec0995e4d2..9ef8687bc6 100644 --- a/src/mir_core/src/CCtrlListView.cpp +++ b/src/mir_core/src/CCtrlListView.cpp @@ -75,6 +75,37 @@ BOOL CCtrlListView::OnNotify(int, NMHDR *pnmh) return FALSE; } +///////////////////////////////////////////////////////////////////////////////////////// + +static int CALLBACK LVMoveSortProc(LPARAM l1, LPARAM l2, LPARAM param) +{ + int result = l1 - l2; + int newItem = HIWORD(param); + int oldItem = LOWORD(param); + if (newItem > oldItem) + return (l1 == oldItem && l2 <= newItem) ? 1 : result; + + return (l2 == oldItem && l1 >= newItem) ? 1 : result; +} + +int CCtrlListView::MoveItem(int idx, int direction) +{ + if ((direction > 0 && idx >= GetItemCount() - 1) || (direction < 0 && idx <= 0)) + return idx; + + if (idx < 0) + idx = GetNextItem(-1, LVNI_FOCUSED); + SortItemsEx(&LVMoveSortProc, MAKELONG(idx, idx + direction)); + return idx + direction; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +void CCtrlListView::SetCurSel(int idx) +{ + SetItemState(idx, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); +} + // additional api HIMAGELIST CCtrlListView::CreateImageList(int iImageList) { diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 3441b0543f..a895c2f6c6 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1501,3 +1501,6 @@ TimeZone_GetSystemTime @1692 ?GetCaretPos@CCtrlListBox@@MBEXAAUCContextMenuPos@@@Z @1724 NONAME
?GetCaretPos@CCtrlListView@@MBEXAAUCContextMenuPos@@@Z @1725 NONAME
?GetCaretPos@CCtrlTreeView@@MBEXAAUCContextMenuPos@@@Z @1726 NONAME
+?MoveItem@CCtrlListView@@QAEHHH@Z @1727 NONAME
+?SelectData@CCtrlCombo@@QAEHJ@Z @1728 NONAME
+?SetCurSel@CCtrlListView@@QAEXH@Z @1729 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 392cfa2cda..9e6cf832e4 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1501,3 +1501,6 @@ TimeZone_GetSystemTime @1692 ?GetCaretPos@CCtrlListBox@@MEBAXAEAUCContextMenuPos@@@Z @1724 NONAME
?GetCaretPos@CCtrlListView@@MEBAXAEAUCContextMenuPos@@@Z @1725 NONAME
?GetCaretPos@CCtrlTreeView@@MEBAXAEAUCContextMenuPos@@@Z @1726 NONAME
+?MoveItem@CCtrlListView@@QEAAHHH@Z @1727 NONAME
+?SelectData@CCtrlCombo@@QEAAH_J@Z @1728 NONAME
+?SetCurSel@CCtrlListView@@QEAAXH@Z @1729 NONAME
|