From 36bf5ddf1af62edc0bf85016d5d70387b12f11f3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 7 Nov 2023 12:27:19 +0300 Subject: =?UTF-8?q?fixes=20#3876=20(=D0=9F=D1=80=D0=B8=20=D1=81=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=20=D1=8F=D0=B7=D1=8B=D0=BA=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=80=D1=8F=D1=87=D0=B8=D1=85=20=D0=BA=D0=BB=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=88=20=D1=83=D0=B5=D0=B7=D0=B6=D0=B0=D1=8E=D1=82=20=D0=B2=20?= =?UTF-8?q?=D0=B4=D1=80=D1=83=D0=B3=D1=83=D1=8E=20=D1=81=D0=B5=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D1=8E)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir_app/src/hotkey_opts.cpp | 86 ++++++++++++++--------------------------- src/mir_app/src/keyboard.cpp | 2 +- 2 files changed, 31 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/hotkey_opts.cpp b/src/mir_app/src/hotkey_opts.cpp index 04d78d2bf8..094e96115f 100644 --- a/src/mir_app/src/hotkey_opts.cpp +++ b/src/mir_app/src/hotkey_opts.cpp @@ -261,51 +261,7 @@ static void sttOptionsDeleteHotkey(HWND hwndList, int idx, THotkeyItem *item) item->rootHotkey->OptChanged = true; } -static int CALLBACK sttOptionsSortList(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) -{ - wchar_t title1[256] = {}, title2[256] = {}; - THotkeyItem *item1 = nullptr, *item2 = nullptr; - LVITEM lvi = {}; - int res; - - lvi.mask = LVIF_TEXT | LVIF_PARAM; - lvi.iItem = lParam1; - lvi.pszText = title1; - lvi.cchTextMax = _countof(title1); - if (ListView_GetItem((HWND)lParamSort, &lvi)) - item1 = (THotkeyItem *)lvi.lParam; - - lvi.mask = LVIF_TEXT | LVIF_PARAM; - lvi.iItem = lParam2; - lvi.pszText = title2; - lvi.cchTextMax = _countof(title2); - if (ListView_GetItem((HWND)lParamSort, &lvi)) - item2 = (THotkeyItem *)lvi.lParam; - - if (!item1 && !item2) - return mir_wstrcmp(title1, title2); - - if (!item1 && item2) { - if (res = mir_wstrcmp(title1, item2->getSection())) - return res; - return -1; - } - - if (!item2 && item1) { - if (res = mir_wstrcmp(item1->getSection(), title2)) - return res; - return 1; - } - /* item1 != nullptr && item2 != nullptr */ - - if (res = mir_wstrcmp(item1->getSection(), item2->getSection())) return res; - if (res = mir_wstrcmp(item1->getDescr(), item2->getDescr())) return res; - if (!item1->rootHotkey && item2->rootHotkey) return -1; - if (item1->rootHotkey && !item2->rootHotkey) return 1; - return 0; -} - -static void sttOptionsAddHotkey(HWND hwndList, THotkeyItem *item) +static void sttOptionsAddHotkey(HWND hwndList, int iItem, THotkeyItem *item) { char buf[256]; mir_snprintf(buf, "mir_hotkey_%d_%d", g_pid, g_hkid++); @@ -322,15 +278,12 @@ static void sttOptionsAddHotkey(HWND hwndList, THotkeyItem *item) newItem->Enabled = newItem->OptEnabled = newItem->OptNew = true; hotkeys.insert(newItem); - SendMessage(hwndList, WM_SETREDRAW, FALSE, 0); - LVITEM lvi = {}; - lvi.mask |= LVIF_PARAM; + lvi.mask = LVIF_PARAM; + lvi.iItem = iItem; lvi.lParam = (LPARAM)newItem; sttOptionsSetupItem(hwndList, ListView_InsertItem(hwndList, &lvi), newItem); - ListView_SortItemsEx(hwndList, sttOptionsSortList, (LPARAM)hwndList); - SendMessage(hwndList, WM_SETREDRAW, TRUE, 0); RedrawWindow(hwndList, nullptr, nullptr, RDW_INVALIDATE); item->OptChanged = true; @@ -378,13 +331,33 @@ static void sttOptionsSaveItem(THotkeyItem *item) db_set_dw(0, DBMODULENAME, buf, item->nSubHotkeys); } +///////////////////////////////////////////////////////////////////////////////////////// + +static int SortHotkeysTranslated(const THotkeyItem *p1, const THotkeyItem *p2) +{ + if (int res = mir_wstrcmp(p1->getSection(), p2->getSection())) + return res; + if (int res = mir_wstrcmp(p1->getDescr(), p2->getDescr())) + return res; + if (!p1->rootHotkey && p2->rootHotkey) + return -1; + if (p1->rootHotkey && !p2->rootHotkey) + return 1; + return 0; +} + static void sttBuildHotkeyList(HWND hwndList) { + LIST tmpList(hotkeys.getCount(), SortHotkeysTranslated); + for (auto &item : hotkeys) + tmpList.insert(item); + + SendMessage(hwndList, WM_SETREDRAW, FALSE, 0); ListView_DeleteAllItems(hwndList); int nItems = 0; THotkeyItem *prevItem = nullptr; - for (auto &item : hotkeys) { + for (auto &item : tmpList) { LVITEM lvi = {}; if (!item->OptDeleted) { @@ -415,10 +388,11 @@ static void sttBuildHotkeyList(HWND hwndList) prevItem = item; } - - ListView_SortItemsEx(hwndList, sttOptionsSortList, (LPARAM)hwndList); + SendMessage(hwndList, WM_SETREDRAW, TRUE, 0); } +///////////////////////////////////////////////////////////////////////////////////////// + static void sttOptionsStartEdit(HWND hwndDlg, HWND hwndHotkey) { LVITEM lvi; @@ -725,7 +699,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, break; case MI_ADD: initialized = false; - sttOptionsAddHotkey(hwndList, item); + sttOptionsAddHotkey(hwndList, lvi.iItem, item); initialized = true; break; case MI_REMOVE: @@ -812,7 +786,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, sttOptionsDeleteHotkey(lpnmia->hdr.hwndFrom, lpnmia->iItem, item); else { initialized = false; - sttOptionsAddHotkey(lpnmia->hdr.hwndFrom, item); + sttOptionsAddHotkey(lpnmia->hdr.hwndFrom, lpnmia->iItem, item); initialized = true; } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); @@ -912,7 +886,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, ListView_InsertItem(lpnmhdr->hwndFrom, &lvi2); sttOptionsSetupItem(lpnmhdr->hwndFrom, nItems - 1, it); } - ListView_SortItemsEx(lpnmhdr->hwndFrom, sttOptionsSortList, (LPARAM)lpnmhdr->hwndFrom); + sttBuildHotkeyList(hwndHotkey); initialized = TRUE; } } diff --git a/src/mir_app/src/keyboard.cpp b/src/mir_app/src/keyboard.cpp index 87929e756c..cb5d4e102c 100644 --- a/src/mir_app/src/keyboard.cpp +++ b/src/mir_app/src/keyboard.cpp @@ -51,7 +51,7 @@ static INT_PTR hkOpts(WPARAM, LPARAM) int InitClistHotKeys(void) { HOTKEYDESC shk = {}; - shk.szSection.a = "Main"; + shk.szSection.a = LPGEN("Main"); shk.szDescription.a = LPGEN("Show/Hide contact list"); shk.pszName = "ShowHide"; -- cgit v1.2.3