diff options
author | George Hazan <ghazan@miranda.im> | 2022-01-26 12:30:03 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-01-26 12:30:03 +0300 |
commit | 1a8b125e5f9859b9e99c59cf0cf946bc583ccef1 (patch) | |
tree | 96566771fd36991c85dc121fbc533572fa530115 /src/mir_app | |
parent | e9e27e8335285078d78b4f8c4405ddc78efbd00c (diff) |
fixes #3012 (Падение при добавлении горячей клавиши действию, у которого в имени есть слеш)
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/src/hotkey_opts.cpp | 151 | ||||
-rw-r--r-- | src/mir_app/src/skin.h | 4 |
2 files changed, 76 insertions, 79 deletions
diff --git a/src/mir_app/src/hotkey_opts.cpp b/src/mir_app/src/hotkey_opts.cpp index bea8f03b99..7221e4df60 100644 --- a/src/mir_app/src/hotkey_opts.cpp +++ b/src/mir_app/src/hotkey_opts.cpp @@ -26,9 +26,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_hotkeys.h> #include "skin.h" -static wchar_t* sttHokeyVkToName(uint16_t vkKey) +static wchar_t *sttHokeyVkToName(uint16_t vkKey) { - static wchar_t buf[256] = { 0 }; + static wchar_t buf[256] = {}; uint32_t code = MapVirtualKey(vkKey, 0) << 16; switch (vkKey) { @@ -115,8 +115,10 @@ void HotkeyToName(wchar_t *buf, int size, uint8_t shift, uint8_t key) static LRESULT CALLBACK sttHotkeyEditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { THotkeyBoxData *data = (THotkeyBoxData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - BOOL bKeyDown = FALSE; - if (!data) return 0; + if (!data) + return 0; + + bool bKeyDown = false; switch (msg) { case HKM_GETHOTKEY: @@ -124,7 +126,7 @@ static LRESULT CALLBACK sttHotkeyEditProc(HWND hwnd, UINT msg, WPARAM wParam, LP case HKM_SETHOTKEY: { - wchar_t buf[256] = { 0 }; + wchar_t buf[256] = {}; data->key = (uint8_t)LOWORD(wParam); data->shift = (uint8_t)HIWORD(wParam); HotkeyToName(buf, _countof(buf), data->shift, data->key); @@ -146,12 +148,12 @@ static LRESULT CALLBACK sttHotkeyEditProc(HWND hwnd, UINT msg, WPARAM wParam, LP case WM_KEYDOWN: case WM_SYSKEYDOWN: - bKeyDown = TRUE; + bKeyDown = true; case WM_KEYUP: case WM_SYSKEYUP: { - wchar_t buf[256] = { 0 }; + wchar_t buf[256] = {}; uint8_t shift = 0; uint8_t key = wParam; @@ -207,7 +209,7 @@ enum { COL_NAME, COL_TYPE, COL_KEY, COL_RESET, COL_ADDREMOVE }; static void sttOptionsSetupItem(HWND hwndList, int idx, THotkeyItem *item) { wchar_t buf[256]; - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.iItem = idx; if (!item->rootHotkey) { @@ -253,17 +255,17 @@ static void sttOptionsSetupItem(HWND hwndList, int idx, THotkeyItem *item) static void sttOptionsDeleteHotkey(HWND hwndList, int idx, THotkeyItem *item) { - item->OptDeleted = TRUE; + item->OptDeleted = true; ListView_DeleteItem(hwndList, idx); if (item->rootHotkey) - item->rootHotkey->OptChanged = TRUE; + item->rootHotkey->OptChanged = true; } static int CALLBACK sttOptionsSortList(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { - wchar_t title1[256] = { 0 }, title2[256] = { 0 }; + wchar_t title1[256] = {}, title2[256] = {}; THotkeyItem *item1 = nullptr, *item2 = nullptr; - LVITEM lvi = { 0 }; + LVITEM lvi = {}; int res; lvi.mask = LVIF_TEXT | LVIF_PARAM; @@ -308,24 +310,21 @@ static void sttOptionsAddHotkey(HWND hwndList, THotkeyItem *item) char buf[256]; mir_snprintf(buf, "mir_hotkey_%d_%d", g_pid, g_hkid++); - THotkeyItem *newItem = (THotkeyItem *)mir_alloc(sizeof(THotkeyItem)); - newItem->pszName = nullptr; - newItem->pszService = item->pszService ? mir_strdup(item->pszService) : nullptr; + THotkeyItem *newItem = (THotkeyItem *)mir_calloc(sizeof(THotkeyItem)); + newItem->pPlugin = item->pPlugin; + newItem->pszService = mir_strdup(item->pszService); newItem->pwszSection = mir_wstrdup(item->pwszSection); newItem->pwszDescription = mir_wstrdup(item->pwszDescription); newItem->lParam = item->lParam; newItem->idHotkey = GlobalAddAtomA(buf); newItem->rootHotkey = item; - newItem->Hotkey = newItem->DefHotkey = newItem->OptHotkey = 0; newItem->type = newItem->OptType = item->OptType; - newItem->Enabled = newItem->OptEnabled = TRUE; - newItem->OptChanged = newItem->OptDeleted = FALSE; - newItem->OptNew = TRUE; + newItem->Enabled = newItem->OptEnabled = newItem->OptNew = true; hotkeys.insert(newItem); SendMessage(hwndList, WM_SETREDRAW, FALSE, 0); - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.mask |= LVIF_PARAM; lvi.lParam = (LPARAM)newItem; sttOptionsSetupItem(hwndList, ListView_InsertItem(hwndList, &lvi), newItem); @@ -334,14 +333,14 @@ static void sttOptionsAddHotkey(HWND hwndList, THotkeyItem *item) SendMessage(hwndList, WM_SETREDRAW, TRUE, 0); RedrawWindow(hwndList, nullptr, nullptr, RDW_INVALIDATE); - item->OptChanged = TRUE; + item->OptChanged = true; } static void sttOptionsSetChanged(THotkeyItem *item) { - item->OptChanged = TRUE; + item->OptChanged = true; if (item->rootHotkey) - item->rootHotkey->OptChanged = TRUE; + item->rootHotkey->OptChanged = true; } static void sttOptionsSaveItem(THotkeyItem *item) @@ -386,7 +385,7 @@ static void sttBuildHotkeyList(HWND hwndList) int nItems = 0; THotkeyItem *prevItem = nullptr; for (auto &item : hotkeys) { - LVITEM lvi = { 0 }; + LVITEM lvi = {}; if (!item->OptDeleted) { if (!prevItem || mir_wstrcmp(item->pwszSection, prevItem->pwszSection)) { @@ -425,7 +424,8 @@ static void sttOptionsStartEdit(HWND hwndDlg, HWND hwndHotkey) LVITEM lvi; THotkeyItem *item; int iItem = ListView_GetNextItem(hwndHotkey, -1, LVNI_SELECTED); - if (iItem < 0) return; + if (iItem < 0) + return; lvi.mask = LVIF_PARAM; lvi.iItem = iItem; @@ -457,7 +457,7 @@ static void sttOptionsDrawTextChunk(HDC hdc, wchar_t *text, RECT *rc) static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static BOOL initialized = FALSE; + static bool initialized = false; static int colWidth = 0; static uint16_t currentLanguage = 0; @@ -465,7 +465,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, switch (msg) { case WM_INITDIALOG: - initialized = FALSE; + initialized = false; TranslateDialogDefault(hwndDlg); @@ -502,8 +502,8 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, ListView_InsertColumn(hwndHotkey, COL_ADDREMOVE, &lvc); for (auto &it : hotkeys) { - it->OptChanged = FALSE; - it->OptDeleted = it->OptNew = FALSE; + it->OptChanged = false; + it->OptDeleted = it->OptNew = false; it->OptEnabled = it->Enabled; it->OptHotkey = it->Hotkey; it->OptType = it->type; @@ -518,27 +518,21 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, /* load group states */ int count = ListView_GetItemCount(hwndHotkey); wchar_t buf[128]; - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.pszText = buf; lvi.cchTextMax = _countof(buf); for (lvi.iItem = 0; lvi.iItem < count; ++lvi.iItem) { - char *szSetting; - lvi.mask = LVIF_PARAM; lvi.iSubItem = 0; ListView_GetItem(hwndHotkey, &lvi); - if (lvi.lParam) continue; + if (lvi.lParam) + continue; lvi.mask = LVIF_TEXT; lvi.iSubItem = 1; ListView_GetItem(hwndHotkey, &lvi); - szSetting = mir_u2a(lvi.pszText); - - ListView_SetCheckState(hwndHotkey, lvi.iItem, - db_get_b(0, DBMODULENAME "UI", szSetting, TRUE)); - - mir_free(szSetting); + ListView_SetCheckState(hwndHotkey, lvi.iItem, db_get_b(0, DBMODULENAME "UI", _T2A(lvi.pszText), TRUE)); } } @@ -553,7 +547,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, int count = ListView_GetItemCount(hwndHotkey); - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.mask = LVIF_PARAM; for (lvi.iItem = 0; lvi.iItem < count; ++lvi.iItem) { ListView_GetItem(hwndHotkey, &lvi); @@ -568,7 +562,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, { int count = ListView_GetItemCount(hwndHotkey); - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.mask = LVIF_PARAM; for (lvi.iItem = 0; lvi.iItem < count; ++lvi.iItem) { ListView_GetItem(hwndHotkey, &lvi); @@ -664,17 +658,19 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, if (GetWindowLongPtr((HWND)wParam, GWL_ID) == IDC_LV_HOTKEYS) { HWND hwndList = (HWND)wParam; POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - LVITEM lvi = { 0 }; + LVITEM lvi = {}; THotkeyItem *item = nullptr; lvi.iItem = ListView_GetNextItem(hwndHotkey, -1, LVNI_SELECTED); - if (lvi.iItem < 0) return FALSE; + if (lvi.iItem < 0) + return FALSE; lvi.mask = LVIF_PARAM; ListView_GetItem(hwndList, &lvi); - if (!(item = (THotkeyItem *)lvi.lParam)) return FALSE; + if (!(item = (THotkeyItem *)lvi.lParam)) + return FALSE; - if ((pt.x == -1) && (pt.y == -1)) { + if (pt.x == -1 && pt.y == -1) { RECT rc; ListView_GetItemRect(hwndList, lvi.iItem, &rc, LVIR_LABEL); pt.x = rc.left; @@ -684,14 +680,14 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, enum { MI_CANCEL, MI_CHANGE, MI_SYSTEM, MI_LOCAL, MI_ADD, MI_REMOVE, MI_REVERT }; - MENUITEMINFO mii = { 0 }; + MENUITEMINFO mii = {}; mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; mii.fState = MFS_DEFAULT; HMENU hMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_STRING, (UINT_PTR)MI_CHANGE, TranslateT("Modify")); - SetMenuItemInfo(hMenu, (UINT_PTR)MI_CHANGE, FALSE, &mii); + AppendMenu(hMenu, MF_STRING, MI_CHANGE, TranslateT("Modify")); + SetMenuItemInfo(hMenu, MI_CHANGE, FALSE, &mii); if (item->type != HKT_MANUAL) { AppendMenu(hMenu, MF_SEPARATOR, 0, nullptr); AppendMenu(hMenu, MF_STRING | @@ -703,12 +699,12 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, } AppendMenu(hMenu, MF_SEPARATOR, 0, nullptr); if (!item->rootHotkey) - AppendMenu(hMenu, MF_STRING, (UINT_PTR)MI_ADD, TranslateT("Add binding")); + AppendMenu(hMenu, MF_STRING, MI_ADD, TranslateT("Add binding")); else - AppendMenu(hMenu, MF_STRING, (UINT_PTR)MI_REMOVE, TranslateT("Remove")); + AppendMenu(hMenu, MF_STRING, MI_REMOVE, TranslateT("Remove")); if (item->Hotkey != item->OptHotkey) { AppendMenu(hMenu, MF_SEPARATOR, 0, nullptr); - AppendMenu(hMenu, MF_STRING, (UINT_PTR)MI_REVERT, TranslateT("Undo")); + AppendMenu(hMenu, MF_STRING, MI_REVERT, TranslateT("Undo")); } switch (TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, nullptr)) { @@ -728,9 +724,9 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case MI_ADD: - initialized = FALSE; + initialized = false; sttOptionsAddHotkey(hwndList, item); - initialized = FALSE; + initialized = true; break; case MI_REMOVE: sttOptionsDeleteHotkey(hwndList, lvi.iItem, item); @@ -760,7 +756,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, FreeHotkey(hotkeys.removeItem(&p)); if (lpnmhdr->code == PSN_APPLY) { - LVITEM lvi = { 0 }; + LVITEM lvi = {}; int count = ListView_GetItemCount(hwndHotkey); for (auto &it : hotkeys) @@ -782,41 +778,42 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, switch (lpnmhdr->code) { case NM_CLICK: { - THotkeyItem *item = nullptr; LPNMITEMACTIVATE lpnmia = (LPNMITEMACTIVATE)lParam; - LVHITTESTINFO lvhti = { 0 }; - LVITEM lvi = { 0 }; - + + LVITEM lvi = {}; lvi.mask = LVIF_PARAM | LVIF_IMAGE; lvi.iItem = lpnmia->iItem; ListView_GetItem(lpnmia->hdr.hwndFrom, &lvi); - item = (THotkeyItem *)lvi.lParam; + auto *item = (THotkeyItem *)lvi.lParam; + if (item == nullptr) + break; + + LVHITTESTINFO lvhti = {}; lvhti.pt = lpnmia->ptAction; lvhti.iItem = lpnmia->iItem; lvhti.iSubItem = lpnmia->iSubItem; ListView_HitTest(lpnmia->hdr.hwndFrom, &lvhti); - if (item && - (!item->rootHotkey && (lpnmia->iSubItem == COL_NAME) && ((lvhti.flags & LVHT_ONITEM) == LVHT_ONITEMICON) || - item->rootHotkey && (lpnmia->iSubItem == COL_TYPE)) && + if ((!item->rootHotkey && (lpnmia->iSubItem == COL_NAME) && ((lvhti.flags & LVHT_ONITEM) == LVHT_ONITEMICON) || + item->rootHotkey && (lpnmia->iSubItem == COL_TYPE)) && ((item->OptType == HKT_GLOBAL) || (item->OptType == HKT_LOCAL))) { item->OptType = (item->OptType == HKT_GLOBAL) ? HKT_LOCAL : HKT_GLOBAL; sttOptionsSetupItem(lpnmia->hdr.hwndFrom, lpnmia->iItem, item); sttOptionsSetChanged(item); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } - else if (item && (lpnmia->iSubItem == COL_RESET)) { + else if (lpnmia->iSubItem == COL_RESET) { item->OptHotkey = item->Hotkey; sttOptionsSetupItem(lpnmia->hdr.hwndFrom, lpnmia->iItem, item); } - else if (item && (lpnmia->iSubItem == COL_ADDREMOVE)) { + else if (lpnmia->iSubItem == COL_ADDREMOVE) { if (item->rootHotkey) sttOptionsDeleteHotkey(lpnmia->hdr.hwndFrom, lpnmia->iItem, item); else { - initialized = FALSE; + initialized = false; sttOptionsAddHotkey(lpnmia->hdr.hwndFrom, item); - initialized = TRUE; + initialized = true; } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } @@ -827,7 +824,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, { LPNMLVKEYDOWN param = (LPNMLVKEYDOWN)lParam; if (param->wVKey == VK_SUBTRACT || param->wVKey == VK_LEFT || param->wVKey == VK_ADD || param->wVKey == VK_RIGHT) { - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.mask = LVIF_PARAM; lvi.iItem = ListView_GetNextItem(lpnmhdr->hwndFrom, -1, LVNI_SELECTED); if (lvi.iItem < 0) @@ -851,7 +848,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, case LVN_ITEMACTIVATE: { - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.mask = LVIF_PARAM; lvi.iItem = ListView_GetNextItem(lpnmhdr->hwndFrom, -1, LVNI_SELECTED); if (lvi.iItem < 0) break; @@ -878,7 +875,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, } else if (!item) { wchar_t buf[256]; - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.mask = LVIF_TEXT; lvi.iItem = param->iItem; lvi.pszText = buf; @@ -887,11 +884,11 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, if (param->uNewState >> 12 == 1) { int count = ListView_GetItemCount(lpnmhdr->hwndFrom); - LVITEM lvi2 = { 0 }; + LVITEM lvi2 = {}; lvi2.mask = LVIF_PARAM; for (lvi2.iItem = 0; lvi2.iItem < count; ++lvi2.iItem) { ListView_GetItem(lpnmhdr->hwndFrom, &lvi2); - item = (THotkeyItem*)lvi2.lParam; + item = (THotkeyItem *)lvi2.lParam; if (!item) continue; if (!mir_wstrcmp(item->getSection(), buf)) { ListView_DeleteItem(lpnmhdr->hwndFrom, lvi2.iItem); @@ -902,9 +899,9 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, } else if (param->uNewState >> 12 == 2) { int nItems = ListView_GetItemCount(lpnmhdr->hwndFrom); - initialized = FALSE; + initialized = false; for (auto &it : hotkeys) { - LVITEM lvi2 = { 0 }; + LVITEM lvi2 = {}; if (it->OptDeleted || mir_wstrcmp(buf, it->getSection())) continue; @@ -935,7 +932,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, { THotkeyItem *item; wchar_t buf[256]; - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.mask = LVIF_TEXT | LVIF_PARAM; lvi.iItem = param->nmcd.dwItemSpec; lvi.pszText = buf; @@ -948,8 +945,8 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, HFONT hfnt; ListView_GetSubItemRect(lpnmhdr->hwndFrom, param->nmcd.dwItemSpec, param->iSubItem, LVIR_BOUNDS, &rc); - FillRect(param->nmcd.hdc, &rc, GetSysColorBrush(param->nmcd.uItemState&CDIS_SELECTED ? COLOR_HIGHLIGHT : COLOR_WINDOW)); - SetTextColor(param->nmcd.hdc, GetSysColor(param->nmcd.uItemState&CDIS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)); + FillRect(param->nmcd.hdc, &rc, GetSysColorBrush(param->nmcd.uItemState & CDIS_SELECTED ? COLOR_HIGHLIGHT : COLOR_WINDOW)); + SetTextColor(param->nmcd.hdc, GetSysColor(param->nmcd.uItemState & CDIS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)); if (param->iSubItem == 0) { rc.left += 3; @@ -994,7 +991,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, KillTimer(hwndDlg, 1024); wchar_t buf[128]; - LVITEM lvi = { 0 }; + LVITEM lvi = {}; lvi.pszText = buf; lvi.cchTextMax = _countof(buf); for (lvi.iItem = 0; lvi.iItem < count; ++lvi.iItem) { diff --git a/src/mir_app/src/skin.h b/src/mir_app/src/skin.h index c1c2916d1e..d0a76adfc0 100644 --- a/src/mir_app/src/skin.h +++ b/src/mir_app/src/skin.h @@ -42,7 +42,7 @@ struct THotkeyItem char *pszService, *pszName; // pszName is valid _only_ for "root" hotkeys
wchar_t *pwszSection, *pwszDescription;
LPARAM lParam;
- uint16_t DefHotkey, Hotkey;
+ uint16_t DefHotkey, Hotkey;
bool Enabled;
HPLUGIN pPlugin;
ATOM idHotkey;
@@ -52,7 +52,7 @@ struct THotkeyItem bool allowSubHotkeys;
bool OptChanged, OptDeleted, OptNew;
- uint16_t OptHotkey;
+ uint16_t OptHotkey;
THotkeyType OptType;
bool OptEnabled;
|