summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-09-02 20:32:54 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-09-02 20:32:54 +0300
commitba09e75933056cd4638fe849419ead008e2ba5f0 (patch)
treed7cd28b3d66de68b8556b3b64736f37396955ca1 /src
parent69600a1c659d6708e13c90b7b00644ebe55a8f1f (diff)
StdMsg: tab processing code unification
Diffstat (limited to 'src')
-rw-r--r--src/core/stdmsg/src/chat_manager.cpp4
-rw-r--r--src/core/stdmsg/src/chat_window.cpp24
-rw-r--r--src/core/stdmsg/src/msgdialog.cpp50
-rw-r--r--src/core/stdmsg/src/msgs.h2
-rw-r--r--src/core/stdmsg/src/stdafx.h7
-rw-r--r--src/core/stdmsg/src/tabs.cpp79
6 files changed, 81 insertions, 85 deletions
diff --git a/src/core/stdmsg/src/chat_manager.cpp b/src/core/stdmsg/src/chat_manager.cpp
index 56f2e5aa28..634532b411 100644
--- a/src/core/stdmsg/src/chat_manager.cpp
+++ b/src/core/stdmsg/src/chat_manager.cpp
@@ -46,9 +46,11 @@ SESSION_INFO* SM_GetNextWindow(SESSION_INFO *si)
if (i == -1)
return nullptr;
- for (auto &p : g_chatApi.arSessions)
+ for (i++; i < g_chatApi.arSessions.getCount(); i++) {
+ SESSION_INFO *p = g_chatApi.arSessions[i];
if (p->pDlg)
return p;
+ }
return nullptr;
}
diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp
index f7aac47d3c..75eac732e4 100644
--- a/src/core/stdmsg/src/chat_window.cpp
+++ b/src/core/stdmsg/src/chat_window.cpp
@@ -656,30 +656,6 @@ LRESULT CChatRoomDlg::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam)
return TRUE;
}
- if (wParam == VK_TAB && isCtrl && !isShift) { // CTRL-TAB (switch tab/window)
- if (g_Settings.bTabsEnable)
- SendMessage(GetParent(GetParent(m_hwnd)), GC_SWITCHNEXTTAB, 0, 0);
- else
- g_chatApi.ShowRoom(SM_GetNextWindow(m_si));
- return TRUE;
- }
-
- if (wParam == VK_TAB && isCtrl && isShift) { // CTRL_SHIFT-TAB (switch tab/window)
- if (g_Settings.bTabsEnable)
- SendMessage(GetParent(GetParent(m_hwnd)), GC_SWITCHPREVTAB, 0, 0);
- else
- g_chatApi.ShowRoom(SM_GetPrevWindow(m_si));
- return TRUE;
- }
-
- if (wParam <= '9' && wParam >= '1' && isCtrl && !isAlt) // CTRL + 1 -> 9 (switch tab)
- if (g_Settings.bTabsEnable)
- SendMessage(m_hwnd, GC_SWITCHTAB, 0, (int)wParam - (int)'1');
-
- if (wParam <= VK_NUMPAD9 && wParam >= VK_NUMPAD1 && isCtrl && !isAlt) // CTRL + 1 -> 9 (switch tab)
- if (g_Settings.bTabsEnable)
- SendMessage(m_hwnd, GC_SWITCHTAB, 0, (int)wParam - (int)VK_NUMPAD1);
-
if (wParam == VK_TAB && !isCtrl && !isShift) { // tab-autocomplete
LRESULT lResult = (LRESULT)m_message.SendMsg(EM_GETSEL, 0, 0);
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp
index c318090f74..1f5b7d25a6 100644
--- a/src/core/stdmsg/src/msgdialog.cpp
+++ b/src/core/stdmsg/src/msgdialog.cpp
@@ -129,6 +129,41 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
return CSuper::DlgProc(uMsg, wParam, lParam);
}
+LRESULT CMsgDialog::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ if (msg == WM_KEYDOWN) {
+ bool isShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
+ bool isCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
+ bool isAlt = (GetKeyState(VK_MENU) & 0x8000) != 0;
+
+ if (wParam <= '9' && wParam >= '1' && isCtrl && !isAlt) // CTRL + 1 -> 9 (switch tab)
+ if (g_Settings.bTabsEnable) {
+ m_pOwner->SwitchTab(wParam - '1');
+ return TRUE;
+ }
+
+ if (wParam <= VK_NUMPAD9 && wParam >= VK_NUMPAD1 && isCtrl && !isAlt) // CTRL + 1 -> 9 (switch tab)
+ if (g_Settings.bTabsEnable) {
+ m_pOwner->SwitchTab(wParam - VK_NUMPAD1);
+ return TRUE;
+ }
+
+ if (wParam == VK_TAB && isCtrl && !isShift) // CTRL-TAB (switch tab/window)
+ if (g_Settings.bTabsEnable) {
+ m_pOwner->SwitchNextTab();
+ return TRUE;
+ }
+
+ if (wParam == VK_TAB && isCtrl && isShift) // CTRL_SHIFT-TAB (switch tab/window)
+ if (g_Settings.bTabsEnable) {
+ m_pOwner->SwitchPrevTab();
+ return TRUE;
+ }
+ }
+
+ return CSuper::WndProc_Message(msg, wParam, lParam);
+}
+
int CMsgDialog::GetImageId() const
{
if (m_nFlash & 1)
@@ -899,21 +934,6 @@ LRESULT CSrmmWindow::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam)
if (ProcessHotkeys(wParam, isShift, isCtrl, isAlt))
return FALSE;
-
- if (wParam == VK_TAB && isCtrl && !isShift) { // CTRL-TAB (switch tab/window)
- if (g_Settings.bTabsEnable) {
- SendMessage(GetParent(GetParent(m_hwnd)), GC_SWITCHNEXTTAB, 0, 0);
- return TRUE;
- }
- }
-
- if (wParam == VK_TAB && isCtrl && isShift) { // CTRL_SHIFT-TAB (switch tab/window)
- if (g_Settings.bTabsEnable) {
- SendMessage(GetParent(GetParent(m_hwnd)), GC_SWITCHPREVTAB, 0, 0);
- return TRUE;
- }
- }
-
break;
case WM_LBUTTONDOWN:
diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h
index 6f64924304..cc7b57a17f 100644
--- a/src/core/stdmsg/src/msgs.h
+++ b/src/core/stdmsg/src/msgs.h
@@ -61,6 +61,8 @@ protected:
void OnDestroy() override;
INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override;
+ LRESULT WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) override;
+
public:
virtual void RemakeLog() {}
diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h
index 1eb52cf754..918f63a017 100644
--- a/src/core/stdmsg/src/stdafx.h
+++ b/src/core/stdmsg/src/stdafx.h
@@ -107,6 +107,9 @@ public:
void RemoveTab(CMsgDialog*);
void SetMessageHighlight(CMsgDialog*);
void SetTabHighlight(CMsgDialog*);
+ void SwitchNextTab(void);
+ void SwitchPrevTab(void);
+ void SwitchTab(int iNewTab);
void TabClicked(void);
bool OnInitDialog() override;
@@ -134,10 +137,6 @@ struct LOGSTREAMDATA : public GCLogStreamDataBase {};
#define EM_ACTIVATE (WM_USER+0x102)
-#define GC_SWITCHNEXTTAB (WM_USER+0x103)
-#define GC_SWITCHPREVTAB (WM_USER+0x104)
-#define GC_SWITCHTAB (WM_USER+0x106)
-
/////////////////////////////////////////////////////////////////////////////////////////
struct GlobalLogSettings : public GlobalLogSettingsBase
diff --git a/src/core/stdmsg/src/tabs.cpp b/src/core/stdmsg/src/tabs.cpp
index 3ed1b72fb2..0494c08cc4 100644
--- a/src/core/stdmsg/src/tabs.cpp
+++ b/src/core/stdmsg/src/tabs.cpp
@@ -403,6 +403,44 @@ void CTabbedWindow::SetWindowPosition()
Srmm_Broadcast(DM_CASCADENEWWINDOW, (WPARAM)m_hwnd, (LPARAM)&m_windowWasCascaded);
}
+void CTabbedWindow::SwitchNextTab()
+{
+ int total = m_tab.GetCount();
+ int i = TabCtrl_GetCurSel(m_tab.GetHwnd());
+ if (i != -1 && total > 1) {
+ if (i < total - 1)
+ i++;
+ else
+ i = 0;
+ m_tab.ActivatePage(i);
+ TabClicked();
+ }
+}
+
+void CTabbedWindow::SwitchPrevTab()
+{
+ int total = m_tab.GetCount();
+ int i = TabCtrl_GetCurSel(m_tab.GetHwnd());
+ if (i != -1 && total >= 1) {
+ if (i > 0)
+ i--;
+ else
+ i = total - 1;
+ m_tab.ActivatePage(i);
+ TabClicked();
+ }
+}
+
+void CTabbedWindow::SwitchTab(int iNewTab)
+{
+ int total = m_tab.GetCount();
+ int i = TabCtrl_GetCurSel(m_tab.GetHwnd());
+ if (i != -1 && total != -1 && total != 1 && i != iNewTab && total > iNewTab) {
+ m_tab.ActivatePage(iNewTab);
+ TabClicked();
+ }
+}
+
void CTabbedWindow::TabClicked()
{
CChatRoomDlg *pDlg = (CChatRoomDlg*)m_tab.GetActivePage();
@@ -442,47 +480,6 @@ INT_PTR CTabbedWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
int idx;
switch (msg) {
- case GC_SWITCHNEXTTAB:
- {
- int total = m_tab.GetCount();
- int i = TabCtrl_GetCurSel(m_tab.GetHwnd());
- if (i != -1 && total > 1) {
- if (i < total - 1)
- i++;
- else
- i = 0;
- m_tab.ActivatePage(i);
- TabClicked();
- }
- }
- break;
-
- case GC_SWITCHPREVTAB:
- {
- int total = m_tab.GetCount();
- int i = TabCtrl_GetCurSel(m_tab.GetHwnd());
- if (i != -1 && total >= 1) {
- if (i > 0)
- i--;
- else
- i = total - 1;
- m_tab.ActivatePage(i);
- TabClicked();
- }
- }
- break;
-
- case GC_SWITCHTAB:
- {
- int total = m_tab.GetCount();
- int i = TabCtrl_GetCurSel(m_tab.GetHwnd());
- if (i != -1 && total != -1 && total != 1 && i != lParam && total > lParam) {
- m_tab.ActivatePage(i);
- TabClicked();
- }
- }
- break;
-
case WM_MOVE:
SaveWindowPosition(false);
break;