summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-07-30 21:41:36 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-07-30 21:41:36 +0300
commitb1684967aae9ac5b29b283bfdef17926edbbddc0 (patch)
tree787426547f5f5b10959b784b7eebd3cc27b8a45a
parent81af1660759b655e0e65bf2f955ef50e87975a13 (diff)
added ability to bind hotkeys to SRMM toolbar icons
-rw-r--r--include/m_message.h5
-rw-r--r--src/mir_app/src/chat.h1
-rw-r--r--src/mir_app/src/srmm_base.cpp30
-rw-r--r--src/mir_app/src/srmm_toolbar.cpp46
4 files changed, 80 insertions, 2 deletions
diff --git a/include/m_message.h b/include/m_message.h
index 1173e822ca..a5454c3138 100644
--- a/include/m_message.h
+++ b/include/m_message.h
@@ -203,6 +203,9 @@ struct StatusIconClickData
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// srmm toolbar icons' support
+// default section for all SRMM toolbar hotkeys
+#define BB_HK_SECTION "Message window toolbar"
+
// button state flags
#define BBSF_HIDDEN (1<<0)
#define BBSF_DISABLED (1<<1)
@@ -233,6 +236,7 @@ struct BBButton
// use value >100, because internal buttons using 10,20,30... 80, etc
DWORD bbbFlags; // combine of BBBF_ flags above
HANDLE hIcon; // Handle to icolib registered icon
+ const char *pszHotkey; // name of the registered hotkey or NULL
};
// adds a new toolbar button
@@ -332,6 +336,7 @@ struct CustomButtonData : public MZeroedObject
bool m_bRSided;
BYTE m_opFlags;
int m_hLangpack;
+ struct THotkeyItem *m_hotkey;
};
// gets the required button or NULL, if i is out of boundaries
diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h
index 444aa25fd8..752f489577 100644
--- a/src/mir_app/src/chat.h
+++ b/src/mir_app/src/chat.h
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_fontservice.h>
void Srmm_CreateToolbarIcons(HWND hwndDlg, int flags);
+void Srmm_ProcessToolbarHotkey(MCONTACT hContact, INT_PTR iButtonFrom, HWND hwndDlg);
struct MODULEINFO : public GCModuleInfoBase {};
struct SESSION_INFO : public GCSessionInfoBase {};
diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp
index f2f9db318c..f3f8b7d1db 100644
--- a/src/mir_app/src/srmm_base.cpp
+++ b/src/mir_app/src/srmm_base.cpp
@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "chat.h"
#include "resource.h"
+#include "skin.h"
#include <m_history.h>
CSrmmBaseDialog::CSrmmBaseDialog(HINSTANCE hInst, int idDialog, SESSION_INFO *si)
@@ -171,6 +172,18 @@ LRESULT CSrmmBaseDialog::WndProc_Log(UINT msg, WPARAM wParam, LPARAM lParam)
}
break;
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ if (!(GetKeyState(VK_RMENU) & 0x8000)) {
+ MSG message = { m_hwnd, msg, wParam, lParam };
+ LRESULT iButtonFrom = Hotkey_Check(&message, LPGEN(BB_HK_SECTION));
+ if (iButtonFrom) {
+ Srmm_ProcessToolbarHotkey(m_hContact, iButtonFrom, m_hwnd);
+ return TRUE;
+ }
+ }
+ break;
+
case WM_CHAR:
SetFocus(m_message.GetHwnd());
if (wParam != '\t')
@@ -319,8 +332,23 @@ EXTERN_C MIR_APP_DLL(LRESULT) CALLBACK stubMessageProc(HWND hwnd, UINT msg, WPAR
LRESULT CSrmmBaseDialog::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam)
{
LRESULT res = mir_callNextSubclass(m_message.GetHwnd(), stubMessageProc, msg, wParam, lParam);
- if (msg == WM_GETDLGCODE)
+ switch (msg) {
+ case WM_GETDLGCODE:
return res & ~DLGC_HASSETSEL;
+
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ if (!(GetKeyState(VK_RMENU) & 0x8000)) {
+ MSG message = { m_hwnd, msg, wParam, lParam };
+ LRESULT iButtonFrom = Hotkey_Check(&message, LPGEN(BB_HK_SECTION));
+ if (iButtonFrom) {
+ Srmm_ProcessToolbarHotkey(m_hContact, iButtonFrom, m_hwnd);
+ return TRUE;
+ }
+ }
+ break;
+ }
+
return res;
}
diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp
index 95f4b0205e..7381fafcfb 100644
--- a/src/mir_app/src/srmm_toolbar.cpp
+++ b/src/mir_app/src/srmm_toolbar.cpp
@@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
#include "chat.h"
+#include "skin.h"
#define MODULENAME "SRMM_Toolbar"
@@ -61,7 +62,7 @@ static int sstSortButtons(const void *p1, const void *p2)
static void CB_RegisterSeparators()
{
- BBButton bbd = { 0 };
+ BBButton bbd = {};
bbd.pszModuleName = "Tabsrmm_sep";
for (DWORD i = 0; dwSepCount > i; i++) {
bbd.bbbFlags = BBBF_ISSEPARATOR | BBBF_ISIMBUTTON;
@@ -139,6 +140,15 @@ MIR_APP_DLL(int) Srmm_AddButton(const BBButton *bbdi, int _hLang)
cbd->m_bPushButton = (bbdi->bbbFlags & BBBF_ISPUSHBUTTON) != 0;
cbd->m_hLangpack = _hLang;
+ if (bbdi->pszHotkey) {
+ for (int i = 0; i < hotkeys.getCount(); i++) {
+ if (!mir_strcmp(hotkeys[i]->getName(), bbdi->pszHotkey)) {
+ cbd->m_hotkey = hotkeys[i];
+ break;
+ }
+ }
+ }
+
// download database settings
CB_GetButtonSettings(0, cbd);
@@ -314,6 +324,40 @@ MIR_APP_DLL(void) Srmm_ClickToolbarIcon(MCONTACT hContact, DWORD idFrom, HWND hw
NotifyEventHooks(hHookButtonPressedEvt, hContact, (LPARAM)&cbcd);
}
+void Srmm_ProcessToolbarHotkey(MCONTACT hContact, INT_PTR iButtonFrom, HWND hwndDlg)
+{
+ HWND hwndFrom = nullptr;
+
+ CustomButtonClickData cbcd = {};
+
+ for (int i = 0; i < arButtonsList.getCount(); i++) {
+ CustomButtonData *cbd = arButtonsList[i];
+ if (cbd->m_hotkey == nullptr || cbd->m_bDisabled)
+ continue;
+
+ if (cbd->m_hotkey->lParam == iButtonFrom) {
+ cbcd.pszModule = cbd->m_pszModuleName;
+ cbcd.dwButtonId = cbd->m_dwButtonOrigID;
+ hwndFrom = GetDlgItem(hwndDlg, cbd->m_dwButtonCID);
+ break;
+ }
+ }
+
+ if (hwndFrom == nullptr)
+ return;
+
+ 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);
+
+ NotifyEventHooks(hHookButtonPressedEvt, hContact, (LPARAM)&cbcd);
+}
+
MIR_APP_DLL(void) Srmm_ResetToolbar()
{
{ mir_cslock lck(csToolBar);