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 | |
parent | acd0d6c62891a2e3fa0bf94b66b93e65e5922e24 (diff) |
CCtrlListView::MoveItem, CCtrlListView::SetCurSel, CCtrlCombo::SelectData - new useful methods
(cherry picked from commit 9661e86b4d2e1280b6e5e562ffafb46d1b6c0817)
-rw-r--r-- | include/m_gui.h | 8 | ||||
-rw-r--r-- | libs/win32/mir_core.lib | bin | 476778 -> 477644 bytes | |||
-rw-r--r-- | libs/win64/mir_core.lib | bin | 481918 -> 482802 bytes | |||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 2 | ||||
-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 |
8 files changed, 63 insertions, 1 deletions
diff --git a/include/m_gui.h b/include/m_gui.h index 152abae62c..25bd775638 100644 --- a/include/m_gui.h +++ b/include/m_gui.h @@ -949,6 +949,9 @@ public: bool OnApply() override;
void OnReset() override;
+ // selects line with userdata passed. returns index of this line or -1
+ int SelectData(LPARAM data);
+
// Control interface
int AddString(const wchar_t *text, LPARAM data = 0);
int AddStringA(const char *text, LPARAM data = 0);
@@ -985,6 +988,11 @@ class MIR_CORE_EXPORT CCtrlListView : public CCtrlBase public:
CCtrlListView(CDlgBase *dlg, int ctrlId);
+ // direction = -1 or 1. returns new item index
+ int MoveItem(int idx, int direction);
+
+ void SetCurSel(int idx);
+
// Classic LV interface
DWORD ApproximateViewRect(int cx, int cy, int iCount);
void Arrange(UINT code);
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib Binary files differindex 672d3e0e09..4d5c4ef62e 100644 --- a/libs/win32/mir_core.lib +++ b/libs/win32/mir_core.lib diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib Binary files differindex 43cbc15592..311f996f66 100644 --- a/libs/win64/mir_core.lib +++ b/libs/win64/mir_core.lib diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 781c279d7e..1c3a463a6f 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -330,7 +330,7 @@ public: if (m_iItem == -1) {
m_iItem = m_list->AddItem(ipv4, -1, NULL, 1);
- m_list->SetItemState(m_iItem, LVIS_FOCUSED | LVIS_SELECTED, 0x000F);
+ m_list->SetCurSel(m_iItem);
m_list->EnsureVisible(m_iItem, TRUE);
}
else
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
|