From a716ef2bcd976387000014ad2bdd7c94df396624 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 5 Nov 2024 19:23:27 +0300 Subject: fixes #3091 (StdMsg/Scriver: Get rid of all hardcoded hotkeys) --- src/mir_app/src/chat.h | 12 ++++- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/srmm_base.cpp | 52 ++----------------- src/mir_app/src/srmm_log_rtf.cpp | 2 +- src/mir_app/src/srmm_main.cpp | 16 ++++++ src/mir_app/src/srmm_toolbar.cpp | 105 ++++++++++++++++++++++++++++++--------- 7 files changed, 115 insertions(+), 74 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 60c4af86e0..7334aae921 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -32,13 +32,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define STREAMSTAGE_TAIL 2 #define STREAMSTAGE_STOP 3 +#define SRMM_HK_BOLD 40001 +#define SRMM_HK_ITALIC 40002 +#define SRMM_HK_UNDERLINE 40003 +#define SRMM_HK_BKCOLOR 40004 +#define SRMM_HK_COLOR 40005 +#define SRMM_HK_CLEAR 40006 +#define SRMM_HK_HISTORY 40007 +#define SRMM_HK_CHANNELMGR 40008 +#define SRMM_HK_FILTERTOGGLE 40009 +#define SRMM_HK_LISTTOGGLE 40010 + #define N_CUSTOM_BBCODES 3 extern wchar_t *wszBbcodes[N_CUSTOM_BBCODES]; #define DM_OPTIONSAPPLIED (WM_USER+14) void Srmm_CreateToolbarIcons(CSrmmBaseDialog *pDlg, int flags); -void Srmm_ProcessToolbarHotkey(MCONTACT hContact, INT_PTR iButtonFrom, HWND hwndDlg); void CheckChatCompatibility(); diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 7d909a5ab8..8fe34eac7d 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -993,3 +993,4 @@ _Proto_CanDeleteHistory@8 @1124 NONAME ?markRead@SESSION_INFO@@QAEX_N@Z @1130 NONAME ?Srmm_NotifyRemoteRead@@YGXII@Z @1131 NONAME ?RemakeLog@CSrmmBaseDialog@@UAEXXZ @1132 NONAME +?ProcessToolbarHotkey@CSrmmBaseDialog@@AAEXH@Z @1133 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 7e5827cbcf..0d48f71055 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -993,3 +993,4 @@ Proto_CanDeleteHistory @1118 NONAME ?markRead@SESSION_INFO@@QEAAX_N@Z @1124 NONAME ?Srmm_NotifyRemoteRead@@YAXII@Z @1125 NONAME ?RemakeLog@CSrmmBaseDialog@@UEAAXXZ @1126 NONAME +?ProcessToolbarHotkey@CSrmmBaseDialog@@AEAAX_J@Z @1129 NONAME diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index b53ca52b13..700026399d 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -249,7 +249,7 @@ LRESULT CSrmmBaseDialog::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) MSG message = { m_hwnd, msg, wParam, lParam }; LRESULT iButtonFrom = Hotkey_Check(&message, BB_HK_SECTION); if (iButtonFrom) { - Srmm_ProcessToolbarHotkey(m_hContact, iButtonFrom, m_hwnd); + ProcessToolbarHotkey(iButtonFrom); return TRUE; } } @@ -1102,50 +1102,9 @@ bool CSrmmBaseDialog::ProcessHotkeys(int key, bool isShift, bool isCtrl, bool is return true; } - if (isCtrl && !isAlt) { - switch (key) { - case VK_SPACE: // ctrl-space (paste clean text) - m_btnBold.Push(false); m_btnBold.Click(); - m_btnItalic.Push(false); m_btnItalic.Click(); - m_btnUnderline.Push(false); m_btnUnderline.Click(); - - m_btnColor.Push(false); m_btnColor.Click(); - m_btnBkColor.Push(false); m_btnBkColor.Click(); - return true; - - case 0x42: // ctrl-b (bold) - m_btnBold.Push(!m_btnBold.IsPushed()); - m_btnBold.Click(); - return true; - - case 0x48: // ctrl-h (history) - m_btnHistory.Click(); - return true; - - case 0x49: // ctrl-i (italics) - m_btnItalic.Push(!m_btnItalic.IsPushed()); - m_btnItalic.Click(); - return true; - - case 0x4b: // ctrl-k (text color) - m_btnColor.Push(!m_btnColor.IsPushed()); - m_btnColor.Click(); - return true; - - case 0x4c: // ctrl-l (back color) - m_btnBkColor.Push(!m_btnBkColor.IsPushed()); - m_btnBkColor.Click(); - return true; - - case 0x55: // ctrl-u (underlining) - m_btnUnderline.Push(!m_btnUnderline.IsPushed()); - m_btnUnderline.Click(); - return true; - - case VK_F4: // ctrl-F4 - CloseTab(); - return true; - } + if (isCtrl && !isAlt && key == VK_F4) { // ctrl-F4 + CloseTab(); + return true; } return false; @@ -1153,9 +1112,6 @@ bool CSrmmBaseDialog::ProcessHotkeys(int key, bool isShift, bool isCtrl, bool is void CSrmmBaseDialog::RefreshButtonStatus() { - if (m_si == nullptr) - return; - CHARFORMAT2 cf; cf.cbSize = sizeof(CHARFORMAT2); cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_BACKCOLOR | CFM_COLOR; diff --git a/src/mir_app/src/srmm_log_rtf.cpp b/src/mir_app/src/srmm_log_rtf.cpp index 4e4615667f..75583cf1de 100644 --- a/src/mir_app/src/srmm_log_rtf.cpp +++ b/src/mir_app/src/srmm_log_rtf.cpp @@ -467,7 +467,7 @@ INT_PTR CRtfLogWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) MSG message = { m_pDlg.m_hwnd, msg, wParam, lParam }; LRESULT iButtonFrom = Hotkey_Check(&message, BB_HK_SECTION); if (iButtonFrom) { - Srmm_ProcessToolbarHotkey(m_pDlg.m_hContact, iButtonFrom, m_pDlg.m_hwnd); + m_pDlg.ProcessToolbarHotkey(iButtonFrom); return TRUE; } } diff --git a/src/mir_app/src/srmm_main.cpp b/src/mir_app/src/srmm_main.cpp index b8c0a4cc3c..be3b847489 100644 --- a/src/mir_app/src/srmm_main.cpp +++ b/src/mir_app/src/srmm_main.cpp @@ -176,8 +176,24 @@ void SrmmModulesLoaded() ///////////////////////////////////////////////////////////////////////////////////////// +static HOTKEYDESC srmmHotkeys[] = { + { "srmm_bold", LPGEN("Toggle bold formatting"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'B'), 0, SRMM_HK_BOLD }, + { "srmm_italic", LPGEN("Toggle italic formatting"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'I'), 0, SRMM_HK_ITALIC }, + { "srmm_under", LPGEN("Toggle underline formatting"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'U'), 0, SRMM_HK_UNDERLINE }, + { "srmm_color", LPGEN("Toggle text color"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'K'), 0, SRMM_HK_COLOR }, + { "srmm_bkcolor", LPGEN("Toggle back color"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'L'), 0, SRMM_HK_BKCOLOR }, + { "srmm_clear", LPGEN("Clear formatting"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, VK_SPACE), 0, SRMM_HK_CLEAR }, + { "srmm_history", LPGEN("Open history window"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'H'), 0, SRMM_HK_HISTORY}, + { "srmm_cmgr", LPGEN("Channel manager"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_SHIFT | HOTKEYF_CONTROL, 'C'), 0, SRMM_HK_CHANNELMGR }, + { "srmm_filter", LPGEN("Toggle filter"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_SHIFT | HOTKEYF_CONTROL, 'F'), 0, SRMM_HK_FILTERTOGGLE }, + { "srmm_nicklist", LPGEN("Toggle nick list"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_SHIFT | HOTKEYF_CONTROL, 'N'), 0, SRMM_HK_LISTTOGGLE }, +}; + int LoadSrmmModule() { + for (auto &it : srmmHotkeys) + g_plugin.addHotkey(&it); + g_hCurHyperlinkHand = LoadCursor(nullptr, IDC_HAND); LoadSrmmToolbarModule(); diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp index 76b9fa0882..bddeef51d4 100644 --- a/src/mir_app/src/srmm_toolbar.cpp +++ b/src/mir_app/src/srmm_toolbar.cpp @@ -219,39 +219,96 @@ MIR_APP_DLL(void) Srmm_ClickToolbarIcon(MCONTACT hContact, int idFrom, HWND hwnd NotifyEventHooks(hHookButtonPressedEvt, hContact, (LPARAM)&cbcd); } -void Srmm_ProcessToolbarHotkey(MCONTACT hContact, INT_PTR iButtonFrom, HWND hwndDlg) -{ - HWND hwndFrom = nullptr; +///////////////////////////////////////////////////////////////////////////////////////// - CustomButtonClickData cbcd = {}; +void CSrmmBaseDialog::ProcessToolbarHotkey(INT_PTR iButtonFrom) +{ + switch (iButtonFrom) { + case SRMM_HK_CLEAR: + m_btnBold.Push(false); m_btnBold.Click(); + m_btnItalic.Push(false); m_btnItalic.Click(); + m_btnUnderline.Push(false); m_btnUnderline.Click(); + + m_btnColor.Push(false); m_btnColor.Click(); + m_btnBkColor.Push(false); m_btnBkColor.Click(); + break; + + case SRMM_HK_BOLD: + m_btnBold.Push(!m_btnBold.IsPushed()); + m_btnBold.Click(); + break; + + case SRMM_HK_ITALIC: + m_btnItalic.Push(!m_btnItalic.IsPushed()); + m_btnItalic.Click(); + break; + + case SRMM_HK_UNDERLINE: + m_btnUnderline.Push(!m_btnUnderline.IsPushed()); + m_btnUnderline.Click(); + break; + + case SRMM_HK_COLOR: + m_btnColor.Push(!m_btnColor.IsPushed()); + m_btnColor.Click(); + break; + + case SRMM_HK_BKCOLOR: + m_btnBkColor.Push(!m_btnBkColor.IsPushed()); + m_btnBkColor.Click(); + break; + + case SRMM_HK_HISTORY: + m_btnHistory.Click(); + break; + + case SRMM_HK_CHANNELMGR: + m_btnChannelMgr.Click(); + break; + + case SRMM_HK_FILTERTOGGLE: + m_btnFilter.Click(); + InvalidateRect(m_btnFilter.GetHwnd(), nullptr, TRUE); + break; + + case SRMM_HK_LISTTOGGLE: + m_btnNickList.Click(); + break; + + default: + HWND hwndFrom = nullptr; + + CustomButtonClickData cbcd = {}; - for (auto &cbd : arButtonsList) { - if (cbd->m_hotkey == nullptr || cbd->m_bDisabled) - continue; + for (auto &cbd : arButtonsList) { + if (cbd->m_hotkey == nullptr || cbd->m_bDisabled) + continue; - if (cbd->m_hotkey->lParam == iButtonFrom) { - cbcd.pszModule = cbd->m_pszModuleName; - cbcd.dwButtonId = cbd->m_dwButtonID; - hwndFrom = GetDlgItem(hwndDlg, cbd->m_dwButtonCID); - break; + if (cbd->m_hotkey->lParam == iButtonFrom) { + cbcd.pszModule = cbd->m_pszModuleName; + cbcd.dwButtonId = cbd->m_dwButtonID; + hwndFrom = GetDlgItem(m_hwnd, cbd->m_dwButtonCID); + break; + } } - } - if (hwndFrom == nullptr) - return; - - RECT rc; - GetWindowRect(hwndFrom, &rc); - cbcd.pt.x = rc.left; - cbcd.pt.y = rc.bottom; + if (hwndFrom) { + RECT rc; + GetWindowRect(hwndFrom, &rc); + cbcd.pt.x = rc.left; + cbcd.pt.y = rc.bottom; - cbcd.hwndFrom = GetParent(hwndFrom); - cbcd.hContact = hContact; - cbcd.flags = (GetKeyState(VK_SHIFT) & 0x8000 ? BBCF_SHIFTPRESSED : 0) | (GetKeyState(VK_CONTROL) & 0x8000 ? BBCF_CONTROLPRESSED : 0); + cbcd.hwndFrom = GetParent(hwndFrom); + cbcd.hContact = m_hContact; + cbcd.flags = (GetKeyState(VK_SHIFT) & 0x8000 ? BBCF_SHIFTPRESSED : 0) | (GetKeyState(VK_CONTROL) & 0x8000 ? BBCF_CONTROLPRESSED : 0); - NotifyEventHooks(hHookButtonPressedEvt, hContact, (LPARAM)&cbcd); + NotifyEventHooks(hHookButtonPressedEvt, m_hContact, (LPARAM)&cbcd); + } + } } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(void) Srmm_ResetToolbar() { for (auto &cbd : arButtonsList) { -- cgit v1.2.3