diff options
author | George Hazan <ghazan@miranda.im> | 2017-03-31 22:49:14 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-03-31 22:49:22 +0300 |
commit | 60cc9a19a798edfe59ae0c412e4d1052d44f3b24 (patch) | |
tree | aac63604e7bfb847978735437f3d31ddff21e73a /src | |
parent | bebacab622a24452c281d21188f2190ef6733c31 (diff) |
StdMsg:
- tab control converted into the universal container;
- status bar moved from chat window to a container, thus allowing resize in both tabbed & sinlgle modes;
- chat own window save/restore method replaced with standard Miranda code;
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdmsg/res/resource.rc | 14 | ||||
-rw-r--r-- | src/core/stdmsg/src/chat_options.cpp | 2 | ||||
-rw-r--r-- | src/core/stdmsg/src/chat_util.cpp | 17 | ||||
-rw-r--r-- | src/core/stdmsg/src/chat_window.cpp | 142 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgs.h | 2 | ||||
-rw-r--r-- | src/core/stdmsg/src/resource.h | 1 | ||||
-rw-r--r-- | src/core/stdmsg/src/stdafx.h | 47 | ||||
-rw-r--r-- | src/core/stdmsg/src/tabs.cpp | 350 |
8 files changed, 277 insertions, 298 deletions
diff --git a/src/core/stdmsg/res/resource.rc b/src/core/stdmsg/res/resource.rc index 6ac278411b..f40dbdc22e 100644 --- a/src/core/stdmsg/res/resource.rc +++ b/src/core/stdmsg/res/resource.rc @@ -193,7 +193,7 @@ BEGIN LTEXT "Load history events",IDC_TXT_TITLE2,0,52,369,8
END
-IDD_CHANNEL_TAB DIALOGEX 0, 0, 252, 140
+IDD_CHANNEL DIALOGEX 0, 0, 252, 140
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 0, 0, 0x1
@@ -206,18 +206,6 @@ BEGIN LISTBOX IDC_SRMM_NICKLIST,182,2,69,94,LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT | LBS_NODATA | NOT WS_BORDER | WS_VSCROLL | WS_TABSTOP,WS_EX_STATICEDGE
END
-IDD_CHANNEL DIALOGEX 0, 0, 252, 140
-STYLE DS_SETFONT | DS_FIXEDSYS | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
-FONT 8, "MS Shell Dlg", 0, 0, 0x1
-BEGIN
- CONTROL "",IDC_SRMM_MESSAGE,"RichEdit50W",WS_VSCROLL | WS_TABSTOP | 0x3144,0,128,127,12,WS_EX_STATICEDGE
- PUSHBUTTON "&Send",IDOK,136,126,115,14,WS_DISABLED
- CONTROL "",IDC_SRMM_LOG,"RichEdit50W",WS_VSCROLL | WS_TABSTOP | 0x2844,8,23,164,73,WS_EX_STATICEDGE
- CONTROL "",IDC_SPLITTERX,"Static",SS_ENHMETAFILE,172,23,10,73
- CONTROL "",IDC_SPLITTERY,"Static",SS_ENHMETAFILE,0,102,251,6
- LISTBOX IDC_SRMM_NICKLIST,182,23,69,73,LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT | LBS_NODATA | NOT WS_BORDER | WS_VSCROLL | WS_TABSTOP,WS_EX_STATICEDGE
-END
-
IDD_CONTAINER DIALOGEX 0, 0, 252, 140
STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
FONT 8, "MS Shell Dlg", 0, 0, 0x1
diff --git a/src/core/stdmsg/src/chat_options.cpp b/src/core/stdmsg/src/chat_options.cpp index 3db5b9b045..e2313ddc94 100644 --- a/src/core/stdmsg/src/chat_options.cpp +++ b/src/core/stdmsg/src/chat_options.cpp @@ -47,8 +47,6 @@ static branch_t branch1[] = { { LPGENW("Show buttons for controlling the chat room"), "ShowTopButtons", 0, true }, { LPGENW("Show buttons for formatting the text you are typing"), "ShowFormatButtons", 0, true }, { LPGENW("Show button menus when right clicking the buttons"), "RightClickFilter", 0, false }, - { LPGENW("Show new windows cascaded"), "CascadeWindows", 0, true }, - { LPGENW("Save the size and position of chat rooms"), "SavePosition", 0, false }, { LPGENW("Show the topic of the room on your contact list (if supported)"), "TopicOnClist", 0, false }, { LPGENW("Do not play sounds when the chat room is focused"), "SoundsFocus", 0, false }, { LPGENW("Do not pop up the window when joining a chat room"), "PopupOnJoin", 0, false }, diff --git a/src/core/stdmsg/src/chat_util.cpp b/src/core/stdmsg/src/chat_util.cpp index 1a7182b490..9e7654c57a 100644 --- a/src/core/stdmsg/src/chat_util.cpp +++ b/src/core/stdmsg/src/chat_util.cpp @@ -197,20 +197,3 @@ void ValidateFilename(wchar_t *filename) p1 += 1; } } - -int RestoreWindowPosition(HWND hwnd, MCONTACT hContact, bool bHide) -{ - int x = db_get_dw(hContact, CHAT_MODULE, "roomx", -1); - if (x == -1) - return 0; - - int y = (int)db_get_dw(hContact, CHAT_MODULE, "roomy", -1); - int width = db_get_dw(hContact, CHAT_MODULE, "roomwidth", -1); - int height = db_get_dw(hContact, CHAT_MODULE, "roomheight", -1); - - DWORD dwFlags = SWP_NOACTIVATE | SWP_NOZORDER; - if (bHide) - dwFlags |= SWP_HIDEWINDOW; - SetWindowPos(hwnd, nullptr, x, y, width, height, dwFlags); - return 1; -} diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index 98d7edab7f..aaf6ee3a50 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -28,8 +28,9 @@ static wchar_t szTrimString[] = L":;,.!?\'\"><()[]- \r\n"; ///////////////////////////////////////////////////////////////////////////////////////// -CChatRoomDlg::CChatRoomDlg(SESSION_INFO *si) : - CSrmmBaseDialog(g_hInst, g_Settings.bTabsEnable ? IDD_CHANNEL_TAB : IDD_CHANNEL, si), +CChatRoomDlg::CChatRoomDlg(CTabbedWindow *pContainer, SESSION_INFO *si) : + CSrmmBaseDialog(g_hInst, IDD_CHANNEL, si), + m_pOwner(pContainer), m_btnOk(this, IDOK), m_splitterX(this, IDC_SPLITTERX), @@ -72,22 +73,11 @@ void CChatRoomDlg::OnInitDialog() m_log.SendMsg(EM_SETEVENTMASK, 0, mask | ENM_LINK | ENM_MOUSEEVENTS); m_log.SendMsg(EM_LIMITTEXT, sizeof(wchar_t) * 0x7FFFFFFF, 0); m_log.SendMsg(EM_SETOLECALLBACK, 0, (LPARAM)&reOleCallback); - - DWORD dwFlags = WS_CHILD | WS_VISIBLE | SBT_TOOLTIPS; - if (!g_Settings.bTabsEnable) - dwFlags |= SBARS_SIZEGRIP; - - m_hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, nullptr, dwFlags, 0, 0, 0, 0, m_hwnd, nullptr, g_hInst, nullptr); - SendMessage(m_hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0); - m_log.SendMsg(EM_HIDESELECTION, TRUE, 0); UpdateOptions(); UpdateStatusBar(); UpdateTitle(); - SetWindowPosition(); - - SendMessage(m_hwnd, WM_SIZE, 0, 0); NotifyEvent(MSG_WINDOW_EVT_OPEN); } @@ -96,21 +86,10 @@ void CChatRoomDlg::OnDestroy() { NotifyEvent(MSG_WINDOW_EVT_CLOSING); - SaveWindowPosition(true); - if (!g_Settings.bTabsEnable) { - if (db_get_b(0, CHAT_MODULE, "SavePosition", 0)) { - db_set_dw(m_hContact, CHAT_MODULE, "roomx", m_si->iX); - db_set_dw(m_hContact, CHAT_MODULE, "roomy", m_si->iY); - db_set_dw(m_hContact, CHAT_MODULE, "roomwidth", m_si->iWidth); - db_set_dw(m_hContact, CHAT_MODULE, "roomheight", m_si->iHeight); - } - } - WindowList_Remove(pci->hWindowList, m_hwnd); m_si->pDlg = nullptr; m_si->wState &= ~STATE_TALK; - DestroyWindow(m_hwndStatus); m_hwndStatus = nullptr; NotifyEvent(MSG_WINDOW_EVT_CLOSE); @@ -204,78 +183,15 @@ void CChatRoomDlg::onSplitterY(CSplitter *pSplitter) g_Settings.iSplitterY = m_iSplitterY; } -void CChatRoomDlg::SetWindowPosition() -{ - if (g_Settings.bTabsEnable) - return; - - WINDOWPLACEMENT wp; - wp.length = sizeof(wp); - GetWindowPlacement(m_hwnd, &wp); - - RECT screen; - SystemParametersInfo(SPI_GETWORKAREA, 0, &screen, 0); - - if (m_si->iX) { - wp.rcNormalPosition.left = m_si->iX; - wp.rcNormalPosition.top = m_si->iY; - wp.rcNormalPosition.right = wp.rcNormalPosition.left + m_si->iWidth; - wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + m_si->iHeight; - wp.showCmd = SW_HIDE; - SetWindowPlacement(m_hwnd, &wp); - return; - } - - if (db_get_b(0, CHAT_MODULE, "SavePosition", 0)) { - if (RestoreWindowPosition(m_hwnd, m_hContact, true)) { - Show(SW_HIDE); - return; - } - SetWindowPos(m_hwnd, 0, (screen.right - screen.left) / 2 - (550) / 2, (screen.bottom - screen.top) / 2 - (400) / 2, (550), (400), SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE); - } - else SetWindowPos(m_hwnd, 0, (screen.right - screen.left) / 2 - (550) / 2, (screen.bottom - screen.top) / 2 - (400) / 2, (550), (400), SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE); - - SESSION_INFO *pActive = pci->GetActiveSession(); - if (pActive && pActive->pDlg && db_get_b(0, CHAT_MODULE, "CascadeWindows", 1)) { - RECT rcThis, rcNew; - int dwFlag = SWP_NOZORDER | SWP_NOACTIVATE; - if (!IsWindowVisible(m_hwnd)) - dwFlag |= SWP_HIDEWINDOW; - - GetWindowRect(m_hwnd, &rcThis); - GetWindowRect(pActive->pDlg->GetHwnd(), &rcNew); - - int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME); - SetWindowPos(m_hwnd, 0, rcNew.left + offset, rcNew.top + offset, rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, dwFlag); - } -} - -void CChatRoomDlg::SaveWindowPosition(bool bUpdateSession) -{ - WINDOWPLACEMENT wp = {}; - wp.length = sizeof(wp); - GetWindowPlacement(getCaptionWindow(), &wp); - - g_Settings.iX = wp.rcNormalPosition.left; - g_Settings.iY = wp.rcNormalPosition.top; - g_Settings.iWidth = wp.rcNormalPosition.right - wp.rcNormalPosition.left; - g_Settings.iHeight = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; - - if (bUpdateSession) { - m_si->iX = g_Settings.iX; - m_si->iY = g_Settings.iY; - m_si->iWidth = g_Settings.iWidth; - m_si->iHeight = g_Settings.iHeight; - } -} - ///////////////////////////////////////////////////////////////////////////////////////// void CChatRoomDlg::CloseTab() { - if (g_Settings.bTabsEnable) + if (g_Settings.bTabsEnable) { SendMessage(GetParent(m_hwndParent), GC_REMOVETAB, 0, (LPARAM)this); - Close(); + Close(); + } + else SendMessage(m_hwndParent, WM_CLOSE, 0, 0); } void CChatRoomDlg::LoadSettings() @@ -381,9 +297,9 @@ void CChatRoomDlg::UpdateOptions() if (g_Settings.bTabsEnable) pDialog->FixTabIcons(nullptr); - SendMessage(m_hwndStatus, SB_SETICON, 0, (LPARAM)hIcon); + SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, (LPARAM)hIcon); - Window_SetIcon_IcoLib(getCaptionWindow(), GetIconHandle("window")); + Window_SetIcon_IcoLib(m_pOwner->GetHwnd(), GetIconHandle("window")); m_log.SendMsg(EM_SETBKGNDCOLOR, 0, g_Settings.crLogBackground); @@ -420,10 +336,10 @@ void CChatRoomDlg::UpdateStatusBar() MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); wchar_t *ptszDispName = mi->ptszModDispName; int x = 12; - x += Chat_GetTextPixelSize(ptszDispName, (HFONT)SendMessage(m_hwndStatus, WM_GETFONT, 0, 0), TRUE); + x += Chat_GetTextPixelSize(ptszDispName, (HFONT)SendMessage(m_pOwner->m_hwndStatus, WM_GETFONT, 0, 0), TRUE); x += GetSystemMetrics(SM_CXSMICON); int iStatusbarParts[2] = { x, -1 }; - SendMessage(m_hwndStatus, SB_SETPARTS, 2, (LPARAM)&iStatusbarParts); + SendMessage(m_pOwner->m_hwndStatus, SB_SETPARTS, 2, (LPARAM)&iStatusbarParts); // stupid hack to make icons show. I dunno why this is needed currently HICON hIcon = m_si->wStatus == ID_STATUS_ONLINE ? mi->hOnlineIcon : mi->hOfflineIcon; @@ -432,14 +348,14 @@ void CChatRoomDlg::UpdateStatusBar() hIcon = m_si->wStatus == ID_STATUS_ONLINE ? mi->hOnlineIcon : mi->hOfflineIcon; } - SendMessage(m_hwndStatus, SB_SETICON, 0, (LPARAM)hIcon); + SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, (LPARAM)hIcon); if (g_Settings.bTabsEnable) pDialog->FixTabIcons(nullptr); - SendMessage(m_hwndStatus, SB_SETTEXT, 0, (LPARAM)ptszDispName); - SendMessage(m_hwndStatus, SB_SETTEXT, 1, (LPARAM)(m_si->ptszStatusbarText ? m_si->ptszStatusbarText : L"")); - SendMessage(m_hwndStatus, SB_SETTIPTEXT, 1, (LPARAM)(m_si->ptszStatusbarText ? m_si->ptszStatusbarText : L"")); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)ptszDispName); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 1, (LPARAM)(m_si->ptszStatusbarText ? m_si->ptszStatusbarText : L"")); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTIPTEXT, 1, (LPARAM)(m_si->ptszStatusbarText ? m_si->ptszStatusbarText : L"")); } void CChatRoomDlg::UpdateTitle() @@ -461,14 +377,13 @@ void CChatRoomDlg::UpdateTitle() break; } - SetWindowText(getCaptionWindow(), szTemp); + SetWindowText(m_pOwner->GetHwnd(), szTemp); } ///////////////////////////////////////////////////////////////////////////////////////// int CChatRoomDlg::Resizer(UTILRESIZECONTROL *urc) { - RECT rc; bool bControl = db_get_b(0, CHAT_MODULE, "ShowTopButtons", 1) != 0; bool bFormat = db_get_b(0, CHAT_MODULE, "ShowFormatButtons", 1) != 0; bool bToolbar = bFormat || bControl; @@ -477,10 +392,9 @@ int CChatRoomDlg::Resizer(UTILRESIZECONTROL *urc) switch (urc->wId) { case IDOK: - GetWindowRect(m_hwndStatus, &rc); urc->rcItem.left = bSend ? 315 : urc->dlgNewSize.cx; urc->rcItem.top = urc->dlgNewSize.cy - m_iSplitterY + 23; - urc->rcItem.bottom = urc->dlgNewSize.cy - (rc.bottom - rc.top) - 1; + urc->rcItem.bottom = urc->dlgNewSize.cy - 1; return RD_ANCHORX_RIGHT | RD_ANCHORY_CUSTOM; case IDC_SRMM_LOG: @@ -513,10 +427,9 @@ int CChatRoomDlg::Resizer(UTILRESIZECONTROL *urc) return RD_ANCHORX_WIDTH | RD_ANCHORY_CUSTOM; case IDC_SRMM_MESSAGE: - GetWindowRect(m_hwndStatus, &rc); urc->rcItem.right = bSend ? urc->dlgNewSize.cx - 64 : urc->dlgNewSize.cx; urc->rcItem.top = urc->dlgNewSize.cy - m_iSplitterY + 22; - urc->rcItem.bottom = urc->dlgNewSize.cy - (rc.bottom - rc.top) - 1; + urc->rcItem.bottom = urc->dlgNewSize.cy - 1; return RD_ANCHORX_LEFT | RD_ANCHORY_CUSTOM; } return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; @@ -978,8 +891,6 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) ScrollToBottom(); if (!IsIconic(m_hwnd)) { - SendMessage(m_hwndStatus, WM_SIZE, 0, 0); - bool bSend = db_get_b(0, CHAT_MODULE, "ShowSend", 0) != 0; bool bFormat = db_get_b(0, CHAT_MODULE, "ShowFormatButtons", 1) != 0; bool bControl = db_get_b(0, CHAT_MODULE, "ShowTopButtons", 1) != 0; @@ -1017,10 +928,9 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) CSrmmBaseDialog::DlgProc(uMsg, wParam, lParam); // call built-in resizer SetButtonsPos(m_hwnd, true); - InvalidateRect(m_hwndStatus, nullptr, true); + InvalidateRect(m_pOwner->m_hwndStatus, nullptr, true); RedrawWindow(m_message.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); RedrawWindow(m_btnOk.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); - SaveWindowPosition(false); } return TRUE; @@ -1127,6 +1037,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) SetFocus(m_message.GetHwnd()); pci->SetActiveSession(m_si); + UpdateStatusBar(); if (KillTimer(m_hwnd, TIMERID_FLASHWND)) FlashWindow(m_hwnd, FALSE); @@ -1179,8 +1090,17 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) SetFocus(m_message.GetHwnd()); break; - case WM_MOVE: - SaveWindowPosition(false); + case DM_CASCADENEWWINDOW: + if ((HWND)wParam != m_pOwner->GetHwnd()) { + RECT rcThis, rcNew; + GetWindowRect(m_pOwner->GetHwnd(), &rcThis); + GetWindowRect((HWND)wParam, &rcNew); + if (abs(rcThis.left - rcNew.left) < 3 && abs(rcThis.top - rcNew.top) < 3) { + int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME); + SetWindowPos((HWND)wParam, 0, rcNew.left + offset, rcNew.top + offset, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE); + *(int *)lParam = 1; + } + } break; case WM_GETMINMAXINFO: diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index d4e8ba328b..67f1dbd6ae 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -49,7 +49,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. class CSrmmWindow : public CSrmmBaseDialog
{
- friend struct CTabbedWindow;
+ friend class CTabbedWindow;
typedef CSrmmBaseDialog CSuper;
static LRESULT CALLBACK TabSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
diff --git a/src/core/stdmsg/src/resource.h b/src/core/stdmsg/src/resource.h index 9deadabd3e..46ef9d8e5d 100644 --- a/src/core/stdmsg/src/resource.h +++ b/src/core/stdmsg/src/resource.h @@ -9,7 +9,6 @@ #define IDD_FILTER 105
#define IDD_OPTIONSPOPUP 106
#define IDD_CONTAINER 107
-#define IDD_CHANNEL_TAB 108
#define IDI_BUNDERLINE 120
#define IDI_BBOLD 121
#define IDI_BITALICS 122
diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index a7ed5a0da7..7f182b90e5 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -92,12 +92,7 @@ struct MODULEINFO : public GCModuleInfoBase int OfflineIconIndex;
};
-struct SESSION_INFO : public GCSessionInfoBase
-{
- int iX, iY;
- int iWidth, iHeight;
-};
-
+struct SESSION_INFO : public GCSessionInfoBase {};
struct LOGSTREAMDATA : public GCLogStreamDataBase {};
struct GlobalLogSettings : public GlobalLogSettingsBase
@@ -145,7 +140,6 @@ int GetColorIndex(const char* pszModule, COLORREF cr); void CheckColorsInModule(const char* pszModule);
int GetRichTextLength(HWND hwnd);
void SetButtonsPos(HWND hwndDlg, bool bIsChat);
-int RestoreWindowPosition(HWND hwnd, MCONTACT hContact, bool bHide);
// message.cpp
char* Message_GetFromStream(HWND hwndDlg, SESSION_INFO *si);
@@ -153,14 +147,21 @@ char* Message_GetFromStream(HWND hwndDlg, SESSION_INFO *si); /////////////////////////////////////////////////////////////////////////////////////////
// tabs.cpp
-struct CTabbedWindow : public CDlgBase
+class CTabbedWindow : public CDlgBase
{
+ void SaveWindowPosition(bool bUpdateSession);
+ void SetWindowPosition();
+
+ int iX, iY;
+ int iWidth, iHeight;
+ int m_windowWasCascaded;
+
+public:
CCtrlPages m_tab;
+ HWND m_hwndStatus;
+ CSrmmBaseDialog *m_pEmbed;
- CTabbedWindow() :
- CDlgBase(g_hInst, IDD_CONTAINER),
- m_tab(this, IDC_TAB)
- {}
+ CTabbedWindow();
void AddPage(SESSION_INFO*, int insertAt = -1);
void FixTabIcons(CChatRoomDlg*);
@@ -171,15 +172,8 @@ struct CTabbedWindow : public CDlgBase virtual void OnInitDialog() override;
virtual void OnDestroy() override;
- virtual int Resizer(UTILRESIZECONTROL *urc)
- {
- if (urc->wId == IDC_TAB)
- return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
-
- return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
- }
-
virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override;
+ virtual int Resizer(UTILRESIZECONTROL *urc) override;
};
extern CTabbedWindow *pDialog;
@@ -201,7 +195,7 @@ void TB_SaveSession(SESSION_INFO *si); class CChatRoomDlg : public CSrmmBaseDialog
{
typedef CSrmmBaseDialog CSuper;
- friend struct CTabbedWindow;
+ friend class CTabbedWindow;
static INT_PTR CALLBACK FilterWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
@@ -209,23 +203,16 @@ class CChatRoomDlg : public CSrmmBaseDialog virtual LRESULT WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) override;
virtual LRESULT WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam) override;
- HWND m_hwndStatus;
wchar_t szTabSave[20];
CCtrlButton m_btnOk;
CSplitter m_splitterX, m_splitterY;
-
- HWND getCaptionWindow() const
- { return (g_Settings.bTabsEnable) ? GetParent(m_hwndParent) : m_hwnd;
- }
-
- void SaveWindowPosition(bool bUpdateSession);
- void SetWindowPosition();
+ CTabbedWindow *m_pOwner;
int m_iSplitterX, m_iSplitterY;
public:
- CChatRoomDlg(SESSION_INFO*);
+ CChatRoomDlg(CTabbedWindow*, SESSION_INFO*);
virtual void OnInitDialog() override;
virtual void OnDestroy() override;
diff --git a/src/core/stdmsg/src/tabs.cpp b/src/core/stdmsg/src/tabs.cpp index 79bde8096e..78fa859426 100644 --- a/src/core/stdmsg/src/tabs.cpp +++ b/src/core/stdmsg/src/tabs.cpp @@ -42,107 +42,12 @@ void TB_SaveSession(SESSION_INFO *si) ///////////////////////////////////////////////////////////////////////////////////////// -LRESULT CALLBACK CSrmmWindow::TabSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +CTabbedWindow::CTabbedWindow() : + CDlgBase(g_hInst, IDD_CONTAINER), + m_tab(this, IDC_TAB), + m_pEmbed(nullptr) { - CTabbedWindow *pOwner = (CTabbedWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - - static BOOL bDragging = FALSE; - static int iBeginIndex = 0; - switch (msg) { - case WM_LBUTTONDOWN: - { - TCHITTESTINFO tci = {}; - tci.pt.x = (short)LOWORD(GetMessagePos()); - tci.pt.y = (short)HIWORD(GetMessagePos()); - if (DragDetect(hwnd, tci.pt) && TabCtrl_GetItemCount(hwnd) > 1) { - tci.flags = TCHT_ONITEM; - ScreenToClient(hwnd, &tci.pt); - int i = TabCtrl_HitTest(hwnd, &tci); - if (i != -1) { - CSrmmWindow *pDlg = (CSrmmWindow*)pOwner->m_tab.GetNthPage(i); - if (pDlg) { - SESSION_INFO *si = pDlg->m_si; - if (si != nullptr) { - bool bOnline = db_get_w(si->hContact, si->pszModule, "Status", ID_STATUS_OFFLINE) == ID_STATUS_ONLINE; - MODULEINFO *mi = pci->MM_FindModule(si->pszModule); - bDragging = TRUE; - iBeginIndex = i; - ImageList_BeginDrag(hIconsList, bOnline ? mi->OnlineIconIndex : mi->OfflineIconIndex, 8, 8); - ImageList_DragEnter(hwnd, tci.pt.x, tci.pt.y); - SetCapture(hwnd); - } - } - return TRUE; - } - } - else pOwner->TabClicked(); - } - break; - - case WM_CAPTURECHANGED: - bDragging = FALSE; - ImageList_DragLeave(hwnd); - ImageList_EndDrag(); - break; - - case WM_MOUSEMOVE: - if (bDragging) { - TCHITTESTINFO tci = {}; - tci.pt.x = (short)LOWORD(GetMessagePos()); - tci.pt.y = (short)HIWORD(GetMessagePos()); - ScreenToClient(hwnd, &tci.pt); - ImageList_DragMove(tci.pt.x, tci.pt.y); - } - break; - - case WM_LBUTTONUP: - if (bDragging && ReleaseCapture()) { - TCHITTESTINFO tci = {}; - tci.pt.x = (short)LOWORD(GetMessagePos()); - tci.pt.y = (short)HIWORD(GetMessagePos()); - tci.flags = TCHT_ONITEM; - bDragging = FALSE; - ImageList_DragLeave(hwnd); - ImageList_EndDrag(); - - ScreenToClient(hwnd, &tci.pt); - int i = TabCtrl_HitTest(hwnd, &tci); - if (i != -1 && i != iBeginIndex) - SendMessage(GetParent(hwnd), GC_DROPPEDTAB, i, iBeginIndex); - } - break; - - case WM_LBUTTONDBLCLK: - { - TCHITTESTINFO tci = {}; - tci.pt.x = (short)LOWORD(GetMessagePos()); - tci.pt.y = (short)HIWORD(GetMessagePos()); - tci.flags = TCHT_ONITEM; - - ScreenToClient(hwnd, &tci.pt); - int i = TabCtrl_HitTest(hwnd, &tci); - if (i != -1 && g_Settings.bTabCloseOnDblClick) { - CSrmmBaseDialog *pDlg = (CSrmmBaseDialog*)pOwner->m_tab.GetNthPage(i); - if (pDlg) - pDlg->CloseTab(); - } - } - break; - - case WM_MBUTTONUP: - TCHITTESTINFO tci = {}; - tci.pt.x = (short)LOWORD(GetMessagePos()); - tci.pt.y = (short)HIWORD(GetMessagePos()); - tci.flags = TCHT_ONITEM; - - ScreenToClient(hwnd, &tci.pt); - int i = TabCtrl_HitTest(hwnd, &tci); - if (i != -1) - SendMessage(GetParent(hwnd), GC_REMOVETAB, 0, (LPARAM)pOwner->m_tab.GetNthPage(i)); - break; - } - - return mir_callNextSubclass(hwnd, TabSubclassProc, msg, wParam, lParam); + iX = iY = iWidth = iHeight = m_windowWasCascaded = 0; } void CTabbedWindow::OnInitDialog() @@ -150,8 +55,15 @@ void CTabbedWindow::OnInitDialog() SetWindowLongPtr(m_tab.GetHwnd(), GWLP_USERDATA, LPARAM(this)); mir_subclassWindow(m_tab.GetHwnd(), &CSrmmWindow::TabSubclassProc); - if (db_get_b(0, CHAT_MODULE, "SavePosition", 0)) - RestoreWindowPosition(m_hwnd, 0, false); + m_hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, nullptr, WS_CHILD | WS_VISIBLE | SBT_TOOLTIPS | SBARS_SIZEGRIP, 0, 0, 0, 0, m_hwnd, nullptr, g_hInst, nullptr); + SendMessage(m_hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0); + + SetWindowPosition(); + + if (!g_Settings.bTabsEnable) { + m_tab.Hide(); + return; + } LONG_PTR mask = GetWindowLongPtr(m_tab.GetHwnd(), GWL_STYLE); if (g_Settings.bTabsAtBottom) @@ -176,6 +88,33 @@ void CTabbedWindow::OnInitDialog() } } +void CTabbedWindow::OnDestroy() +{ + DestroyWindow(m_hwndStatus); m_hwndStatus = nullptr; + + SaveWindowPosition(true); + + Utils_SaveWindowPosition(m_hwnd, g_dat.bSavePerContact ? ((m_pEmbed == nullptr) ? 0 : m_pEmbed->m_hContact) : 0, CHAT_MODULE, "room"); + + if (m_pEmbed == nullptr) + pDialog = nullptr; +} + +int CTabbedWindow::Resizer(UTILRESIZECONTROL *urc) +{ + if (urc->wId == IDC_TAB) { + RECT rc; + GetWindowRect(m_hwndStatus, &rc); + urc->rcItem.top = 1; + urc->rcItem.bottom = urc->dlgNewSize.cy - (rc.bottom - rc.top) - 1; + return RD_ANCHORX_WIDTH | RD_ANCHORY_CUSTOM; + } + + return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; // status bar +} + +///////////////////////////////////////////////////////////////////////////////////////// + void CTabbedWindow::AddPage(SESSION_INFO *si, int insertAt) { // does the tab already exist? @@ -189,9 +128,10 @@ void CTabbedWindow::AddPage(SESSION_INFO *si, int insertAt) if (!IsWindowVisible(m_hwnd)) Show(SW_SHOW); - CChatRoomDlg *pTab = new CChatRoomDlg(si); - m_tab.AddPage(szTemp, nullptr, pTab); - FixTabIcons(pTab); + CChatRoomDlg *pDlg = new CChatRoomDlg(this, si); + pDlg->SetParent(m_hwnd); + m_tab.AddPage(szTemp, nullptr, pDlg); + FixTabIcons(pDlg); m_tab.ActivatePage(m_tab.GetCount() - 1); } @@ -226,6 +166,26 @@ void CTabbedWindow::FixTabIcons(CChatRoomDlg *pDlg) else RedrawWindow(m_tab.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); } + +void CTabbedWindow::SaveWindowPosition(bool bUpdateSession) +{ + WINDOWPLACEMENT wp = {}; + wp.length = sizeof(wp); + GetWindowPlacement(m_hwnd, &wp); + + g_Settings.iX = wp.rcNormalPosition.left; + g_Settings.iY = wp.rcNormalPosition.top; + g_Settings.iWidth = wp.rcNormalPosition.right - wp.rcNormalPosition.left; + g_Settings.iHeight = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; + + if (bUpdateSession) { + iX = g_Settings.iX; + iY = g_Settings.iY; + iWidth = g_Settings.iWidth; + iHeight = g_Settings.iHeight; + } +} + void CTabbedWindow::SetMessageHighlight(CChatRoomDlg *pDlg) { if (pDlg != nullptr) { @@ -253,6 +213,39 @@ void CTabbedWindow::SetTabHighlight(CChatRoomDlg *pDlg) else RedrawWindow(m_tab.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); } +void CTabbedWindow::SetWindowPosition() +{ + if (m_pEmbed == nullptr) { + Utils_RestoreWindowPosition(m_hwnd, 0, CHAT_MODULE, "room"); + return; + } + + if (iX) { + WINDOWPLACEMENT wp; + wp.length = sizeof(wp); + GetWindowPlacement(m_hwnd, &wp); + + wp.rcNormalPosition.left = iX; + wp.rcNormalPosition.top = iY; + wp.rcNormalPosition.right = wp.rcNormalPosition.left + iWidth; + wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + iHeight; + wp.showCmd = SW_HIDE; + SetWindowPlacement(m_hwnd, &wp); + return; + } + + if (Utils_RestoreWindowPosition(m_hwnd, g_dat.bSavePerContact ? m_pEmbed->m_hContact : 0, CHAT_MODULE, "room")) { + if (g_dat.bSavePerContact) { + if (Utils_RestoreWindowPosition(m_hwnd, 0, CHAT_MODULE, "room", RWPF_NOMOVE)) + SetWindowPos(m_hwnd, 0, 0, 0, 550, 400, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW); + } + else SetWindowPos(m_hwnd, 0, 0, 0, 550, 400, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW); + } + + if (!g_dat.bSavePerContact && g_dat.bCascade) + WindowList_Broadcast(pci->hWindowList, DM_CASCADENEWWINDOW, (WPARAM)m_hwnd, (LPARAM)&m_windowWasCascaded); +} + void CTabbedWindow::TabClicked() { CChatRoomDlg *pDlg = (CChatRoomDlg*)m_tab.GetActivePage(); @@ -281,6 +274,111 @@ void CTabbedWindow::TabClicked() } } +///////////////////////////////////////////////////////////////////////////////////////// + +LRESULT CALLBACK CSrmmWindow::TabSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + CTabbedWindow *pOwner = (CTabbedWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA); + + static BOOL bDragging = FALSE; + static int iBeginIndex = 0; + switch (msg) { + case WM_LBUTTONDOWN: + { + TCHITTESTINFO tci = {}; + tci.pt.x = (short)LOWORD(GetMessagePos()); + tci.pt.y = (short)HIWORD(GetMessagePos()); + if (DragDetect(hwnd, tci.pt) && TabCtrl_GetItemCount(hwnd) > 1) { + tci.flags = TCHT_ONITEM; + ScreenToClient(hwnd, &tci.pt); + int i = TabCtrl_HitTest(hwnd, &tci); + if (i != -1) { + CSrmmWindow *pDlg = (CSrmmWindow*)pOwner->m_tab.GetNthPage(i); + if (pDlg) { + SESSION_INFO *si = pDlg->m_si; + if (si != nullptr) { + bool bOnline = db_get_w(si->hContact, si->pszModule, "Status", ID_STATUS_OFFLINE) == ID_STATUS_ONLINE; + MODULEINFO *mi = pci->MM_FindModule(si->pszModule); + bDragging = TRUE; + iBeginIndex = i; + ImageList_BeginDrag(hIconsList, bOnline ? mi->OnlineIconIndex : mi->OfflineIconIndex, 8, 8); + ImageList_DragEnter(hwnd, tci.pt.x, tci.pt.y); + SetCapture(hwnd); + } + } + return TRUE; + } + } + else pOwner->TabClicked(); + } + break; + + case WM_CAPTURECHANGED: + bDragging = FALSE; + ImageList_DragLeave(hwnd); + ImageList_EndDrag(); + break; + + case WM_MOUSEMOVE: + if (bDragging) { + TCHITTESTINFO tci = {}; + tci.pt.x = (short)LOWORD(GetMessagePos()); + tci.pt.y = (short)HIWORD(GetMessagePos()); + ScreenToClient(hwnd, &tci.pt); + ImageList_DragMove(tci.pt.x, tci.pt.y); + } + break; + + case WM_LBUTTONUP: + if (bDragging && ReleaseCapture()) { + TCHITTESTINFO tci = {}; + tci.pt.x = (short)LOWORD(GetMessagePos()); + tci.pt.y = (short)HIWORD(GetMessagePos()); + tci.flags = TCHT_ONITEM; + bDragging = FALSE; + ImageList_DragLeave(hwnd); + ImageList_EndDrag(); + + ScreenToClient(hwnd, &tci.pt); + int i = TabCtrl_HitTest(hwnd, &tci); + if (i != -1 && i != iBeginIndex) + SendMessage(GetParent(hwnd), GC_DROPPEDTAB, i, iBeginIndex); + } + break; + + case WM_LBUTTONDBLCLK: + { + TCHITTESTINFO tci = {}; + tci.pt.x = (short)LOWORD(GetMessagePos()); + tci.pt.y = (short)HIWORD(GetMessagePos()); + tci.flags = TCHT_ONITEM; + + ScreenToClient(hwnd, &tci.pt); + int i = TabCtrl_HitTest(hwnd, &tci); + if (i != -1 && g_Settings.bTabCloseOnDblClick) { + CSrmmBaseDialog *pDlg = (CSrmmBaseDialog*)pOwner->m_tab.GetNthPage(i); + if (pDlg) + pDlg->CloseTab(); + } + } + break; + + case WM_MBUTTONUP: + TCHITTESTINFO tci = {}; + tci.pt.x = (short)LOWORD(GetMessagePos()); + tci.pt.y = (short)HIWORD(GetMessagePos()); + tci.flags = TCHT_ONITEM; + + ScreenToClient(hwnd, &tci.pt); + int i = TabCtrl_HitTest(hwnd, &tci); + if (i != -1) + SendMessage(GetParent(hwnd), GC_REMOVETAB, 0, (LPARAM)pOwner->m_tab.GetNthPage(i)); + break; + } + + return mir_callNextSubclass(hwnd, TabSubclassProc, msg, wParam, lParam); +} + INT_PTR CTabbedWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { @@ -398,6 +496,10 @@ INT_PTR CTabbedWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) FlashWindow(m_hwnd, TRUE); break; + case WM_MOVE: + SaveWindowPosition(false); + break; + case WM_NOTIFY: if (((LPNMHDR)lParam)->idFrom == IDC_TAB) { switch (((LPNMHDR)lParam)->code) { @@ -466,27 +568,24 @@ INT_PTR CTabbedWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) break; } - return CDlgBase::DlgProc(msg, wParam, lParam); + LRESULT res = CDlgBase::DlgProc(msg, wParam, lParam); + if (msg == WM_SIZE) { + SendMessage(m_hwndStatus, WM_SIZE, 0, 0); + if (m_pEmbed) { + RECT rc; + GetClientRect(m_tab.GetHwnd(), &rc); + MoveWindow(m_pEmbed->GetHwnd(), 0, 0, rc.right - rc.left, rc.bottom - rc.top, FALSE); + } + SaveWindowPosition(false); + } + + return res; } ///////////////////////////////////////////////////////////////////////////////////////// CTabbedWindow *pDialog = nullptr; -void CTabbedWindow::OnDestroy() -{ - if (db_get_b(0, CHAT_MODULE, "SavePosition", 0)) { - RECT rc; - GetWindowRect(m_hwnd, &rc); - db_set_dw(0, CHAT_MODULE, "roomx", rc.left); - db_set_dw(0, CHAT_MODULE, "roomy", rc.top); - db_set_dw(0, CHAT_MODULE, "roomwidth", rc.right - rc.left); - db_set_dw(0, CHAT_MODULE, "roomheight", rc.bottom - rc.top); - } - - pDialog = nullptr; -} - void InitTabs() { if (g_Settings.bTabsEnable && pDialog == nullptr) { @@ -525,11 +624,16 @@ void ShowRoom(SESSION_INFO *si) PostMessage(pDialog->GetHwnd(), WM_SIZE, 0, 0); } else { - CChatRoomDlg *pRoom = new CChatRoomDlg(si); - pRoom->Show(); + CTabbedWindow *pContainer = new CTabbedWindow(); + pContainer->Create(); + + CDlgBase *pDlg = pContainer->m_pEmbed = new CChatRoomDlg(pContainer, si); + pDlg->SetParent(pContainer->GetHwnd()); + pDlg->Create(); + pContainer->Show(); + PostMessage(pContainer->GetHwnd(), WM_SIZE, 0, 0); } - PostMessage(si->pDlg->GetHwnd(), WM_SIZE, 0, 0); if (si->iType != GCW_SERVER) si->pDlg->UpdateNickList(); else |