From 18fe3efd2ff9ce9250c353aacc969f4a12d0062e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 11 Apr 2017 16:45:32 +0300 Subject: StdMsg: if tabs are used, SRMM window to share container with chats. also fixes #680 completely --- src/core/stdmsg/res/resource.rc | 9 +-- src/core/stdmsg/src/chat_manager.cpp | 13 +--- src/core/stdmsg/src/chat_window.cpp | 8 +- src/core/stdmsg/src/msgdialog.cpp | 141 ++++++++++++++++++++--------------- src/core/stdmsg/src/msgoptions.cpp | 56 +++++++------- src/core/stdmsg/src/msgs.cpp | 20 ++--- src/core/stdmsg/src/msgs.h | 5 +- src/core/stdmsg/src/stdafx.h | 4 +- src/core/stdmsg/src/tabs.cpp | 55 ++++++++++++-- 9 files changed, 181 insertions(+), 130 deletions(-) (limited to 'src') diff --git a/src/core/stdmsg/res/resource.rc b/src/core/stdmsg/res/resource.rc index 2f84259b04..58288b226f 100644 --- a/src/core/stdmsg/res/resource.rc +++ b/src/core/stdmsg/res/resource.rc @@ -80,17 +80,16 @@ BEGIN END IDD_MSG DIALOGEX 0, 0, 185, 79 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME -EXSTYLE WS_EX_NOPARENTNOTIFY | WS_EX_ACCEPTFILES | WS_EX_CONTROLPARENT -CAPTION "Message session" +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - CONTROL "",IDC_SRMM_MESSAGE,"RichEdit50W",WS_VSCROLL | WS_TABSTOP | 0x1144,1,49,141,13,WS_EX_ACCEPTFILES | WS_EX_STATICEDGE + CONTROL "",IDC_SRMM_MESSAGE,"RichEdit50W",WS_VSCROLL | WS_TABSTOP | 0x1144,1,49,141,29,WS_EX_ACCEPTFILES | WS_EX_STATICEDGE DEFPUSHBUTTON "&Send",IDOK,143,48,39,15 PUSHBUTTON "Close",IDCANCEL,129,0,54,15,NOT WS_VISIBLE CONTROL "",IDC_SRMM_LOG,"RichEdit50W",WS_VSCROLL | WS_TABSTOP | 0x844,1,18,183,26,WS_EX_STATICEDGE CONTROL "",IDC_SPLITTERY,"Static",SS_ENHMETAFILE,0,45,183,2 - CONTROL "",IDC_AVATAR,"Button",BS_OWNERDRAW | NOT WS_VISIBLE,1,50,1,13 + CONTROL "",IDC_AVATAR,"Button",BS_OWNERDRAW | NOT WS_VISIBLE,1,66,1,13 END IDD_OPT_MSGLOG DIALOGEX 0, 0, 311, 164 diff --git a/src/core/stdmsg/src/chat_manager.cpp b/src/core/stdmsg/src/chat_manager.cpp index 6d6eedf8bf..4ae765f651 100644 --- a/src/core/stdmsg/src/chat_manager.cpp +++ b/src/core/stdmsg/src/chat_manager.cpp @@ -195,19 +195,14 @@ static void ShowRoom(SESSION_INFO *si) // Do we need to create a window? if (si->pDlg == nullptr) { + CTabbedWindow *pContainer = GetContainer(); if (g_Settings.bTabsEnable) { - if (pDialog == nullptr) { - pDialog = new CTabbedWindow(); - pDialog->Show(); - } - pDialog->AddPage(si); - PostMessage(pDialog->GetHwnd(), WM_SIZE, 0, 0); + pContainer->AddPage(si); + PostMessage(pContainer->GetHwnd(), WM_SIZE, 0, 0); } else { - CTabbedWindow *pContainer = new CTabbedWindow(); - pContainer->Create(); - CDlgBase *pDlg = pContainer->m_pEmbed = new CChatRoomDlg(pContainer, si); + pContainer->Create(); pDlg->SetParent(pContainer->GetHwnd()); pDlg->Create(); pContainer->Show(); diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index d405be1514..a137c51998 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -29,7 +29,7 @@ static wchar_t szTrimString[] = L":;,.!?\'\"><()[]- \r\n"; ///////////////////////////////////////////////////////////////////////////////////////// CChatRoomDlg::CChatRoomDlg(CTabbedWindow *pContainer, SESSION_INFO *si) : - CSrmmBaseDialog(g_hInst, IDD_CHANNEL, si), + CSuper(g_hInst, IDD_CHANNEL, si), m_pOwner(pContainer), m_btnOk(this, IDOK), @@ -53,7 +53,7 @@ CChatRoomDlg::CChatRoomDlg(CTabbedWindow *pContainer, SESSION_INFO *si) : void CChatRoomDlg::OnInitDialog() { - CSrmmBaseDialog::OnInitDialog(); + CSuper::OnInitDialog(); m_si->pDlg = this; if (g_Settings.bTabsEnable) @@ -1022,7 +1022,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) m_btnChannelMgr.Enable(pci->MM_FindModule(m_si->pszModule)->bChanMgr); } - CSrmmBaseDialog::DlgProc(uMsg, wParam, lParam); // call built-in resizer + CSuper::DlgProc(uMsg, wParam, lParam); // call built-in resizer SetButtonsPos(m_hwnd, true); InvalidateRect(m_pOwner->m_hwndStatus, nullptr, true); @@ -1217,5 +1217,5 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) break; } - return CSrmmBaseDialog::DlgProc(uMsg, wParam, lParam); + return CSuper::DlgProc(uMsg, wParam, lParam); } diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 7cd9f37272..f64f4e826b 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -99,16 +99,18 @@ static void SetEditorText(HWND hwnd, const wchar_t* txt) ///////////////////////////////////////////////////////////////////////////////////////// -CSrmmWindow::CSrmmWindow(MCONTACT hContact) : - CSrmmBaseDialog(g_hInst, IDD_MSG), +CSrmmWindow::CSrmmWindow(CTabbedWindow *pOwner, MCONTACT hContact) : + CSuper(g_hInst, IDD_MSG), m_splitter(this, IDC_SPLITTERY), m_avatar(this, IDC_AVATAR), m_btnOk(this, IDOK), m_cmdList(20), - m_bNoActivate(g_dat.bDoNotStealFocus) + m_bNoActivate(g_dat.bDoNotStealFocus), + m_pOwner(pOwner) { m_hContact = hContact; - m_autoClose = CLOSE_ON_CANCEL; + m_autoClose = 0; + m_forceResizable = true; m_btnOk.OnClick = Callback(this, &CSrmmWindow::onClick_Ok); m_splitter.OnChange = Callback(this, &CSrmmWindow::OnSplitterMoved); @@ -116,7 +118,7 @@ CSrmmWindow::CSrmmWindow(MCONTACT hContact) : void CSrmmWindow::OnInitDialog() { - CSrmmBaseDialog::OnInitDialog(); + CSuper::OnInitDialog(); m_bIsMeta = db_mc_isMeta(m_hContact) != 0; m_hTimeZone = TimeZone_CreateByContact(m_hContact, 0, TZF_KNOWNONLY); @@ -158,7 +160,6 @@ void CSrmmWindow::OnInitDialog() GetWindowRect(m_message.GetHwnd(), &m_minEditInit); SendMessage(m_hwnd, DM_UPDATESIZEBAR, 0, 0); - m_hwndStatus = nullptr; m_avatar.Enable(false); @@ -263,9 +264,6 @@ void CSrmmWindow::OnInitDialog() else SetWindowPos(m_hwnd, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW); } - if (!g_dat.bSavePerContact && g_dat.bCascade) - Srmm_Broadcast(DM_CASCADENEWWINDOW, (WPARAM)m_hwnd, (LPARAM)&m_windowWasCascaded); - if (m_bNoActivate) { SetWindowPos(m_hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW); SetTimer(m_hwnd, TIMERID_FLASHWND, TIMEOUT_FLASHWND, nullptr); @@ -298,8 +296,6 @@ void CSrmmWindow::OnDestroy() if (m_hBkgBrush) DeleteObject(m_hBkgBrush); - if (m_hwndStatus) - DestroyWindow(m_hwndStatus); for (int i = 0; i < m_cmdList.getCount(); i++) mir_free(m_cmdList[i]); @@ -384,12 +380,6 @@ void CSrmmWindow::OnOptionsApplied(bool bUpdateAvatar) ShowWindow(hwndButton, (bShow) ? SW_SHOW : SW_HIDE); } - if (!m_hwndStatus) { - int grip = (GetWindowLongPtr(m_hwnd, GWL_STYLE) & WS_THICKFRAME) ? SBARS_SIZEGRIP : 0; - m_hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, nullptr, WS_CHILD | WS_VISIBLE | grip, 0, 0, 0, 0, m_hwnd, nullptr, g_hInst, nullptr); - SendMessage(m_hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0); - } - ShowWindow(GetDlgItem(m_hwnd, IDCANCEL), SW_HIDE); m_splitter.Show(); m_btnOk.Show(g_dat.bSendButton); @@ -463,6 +453,17 @@ void CSrmmWindow::OnSplitterMoved(CSplitter *pSplitter) m_splitterPos = oldSplitterY - m_minEditBoxSize.cy + (rcLog.bottom - rcLog.top); } +///////////////////////////////////////////////////////////////////////////////////////// + +void CSrmmWindow::CloseTab() +{ + if (g_Settings.bTabsEnable) { + SendMessage(GetParent(m_hwndParent), GC_REMOVETAB, 0, (LPARAM)this); + Close(); + } + else SendMessage(m_hwndParent, WM_CLOSE, 0, 0); +} + void CSrmmWindow::NotifyTyping(int mode) { if (!m_hContact) @@ -535,7 +536,7 @@ void CSrmmWindow::ShowAvatar() void CSrmmWindow::ShowTime() { - if (m_hwndStatus && m_hTimeZone) { + if (m_hTimeZone) { SYSTEMTIME st; GetSystemTime(&st); if (m_wMinute != st.wMinute) { @@ -543,7 +544,7 @@ void CSrmmWindow::ShowTime() unsigned i = g_dat.bShowReadChar ? 2 : 1; TimeZone_PrintDateTime(m_hTimeZone, L"t", buf, _countof(buf), 0); - SendMessage(m_hwndStatus, SB_SETTEXT, i, (LPARAM)buf); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, i, (LPARAM)buf); m_wMinute = st.wMinute; } } @@ -555,7 +556,7 @@ void CSrmmWindow::SetupStatusBar() int icons_width = GetStatusIconsCount(m_hContact) * (GetSystemMetrics(SM_CXSMICON) + 2) + SB_GRIP_WIDTH; RECT rc; - GetWindowRect(m_hwndStatus, &rc); + GetWindowRect(m_pOwner->m_hwndStatus, &rc); int cx = rc.right - rc.left; if (m_hTimeZone) { @@ -568,7 +569,7 @@ void CSrmmWindow::SetupStatusBar() statwidths[i++] = cx - icons_width; statwidths[i++] = -1; - SendMessage(m_hwndStatus, SB_SETPARTS, i, (LPARAM)statwidths); + SendMessage(m_pOwner->m_hwndStatus, SB_SETPARTS, i, (LPARAM)statwidths); UpdateReadChars(); ShowTime(); @@ -577,18 +578,18 @@ void CSrmmWindow::SetupStatusBar() void CSrmmWindow::SetStatusData(StatusTextData *st) { - SendMessage(m_hwndStatus, SB_SETICON, 0, (LPARAM)(st == nullptr ? 0 : st->hIcon)); - SendMessage(m_hwndStatus, SB_SETTEXT, 0, (LPARAM)(st == nullptr ? L"" : st->tszText)); + SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, (LPARAM)(st == nullptr ? 0 : st->hIcon)); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)(st == nullptr ? L"" : st->tszText)); } void CSrmmWindow::UpdateReadChars() { - if (m_hwndStatus && g_dat.bShowReadChar) { + if (g_dat.bShowReadChar) { wchar_t buf[32]; int len = GetWindowTextLength(m_message.GetHwnd()); mir_snwprintf(buf, L"%d", len); - SendMessage(m_hwndStatus, SB_SETTEXT, 1, (LPARAM)buf); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 1, (LPARAM)buf); } } @@ -636,6 +637,8 @@ int CSrmmWindow::Resizer(UTILRESIZECONTROL *urc) LRESULT CSrmmWindow::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) { + bool isShift, isCtrl, isAlt; + switch (msg) { case WM_DROPFILES: SendMessage(m_hwnd, WM_DROPFILES, wParam, lParam); @@ -651,14 +654,18 @@ LRESULT CSrmmWindow::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) } if (wParam == 23 && GetKeyState(VK_CONTROL) & 0x8000) { // ctrl-w - Close(); + CloseTab(); return 0; } break; case WM_KEYDOWN: + isShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0; + isCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0; + isAlt = (GetKeyState(VK_MENU) & 0x8000) != 0; + if (wParam == VK_RETURN) { - if (!(GetKeyState(VK_SHIFT) & 0x8000) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0) != g_dat.bSendOnEnter) { + if (!isShift && isCtrl != g_dat.bSendOnEnter) { PostMessage(m_hwnd, WM_COMMAND, IDOK, 0); return 0; } @@ -675,13 +682,12 @@ LRESULT CSrmmWindow::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) } else m_iLastEnterTime = 0; - if (((wParam == VK_INSERT && (GetKeyState(VK_SHIFT) & 0x8000)) || (wParam == 'V' && (GetKeyState(VK_CONTROL) & 0x8000))) && - !(GetKeyState(VK_MENU) & 0x8000)) { // ctrl-v (paste clean text) + if (wParam == VK_INSERT && isShift || wParam == 'V' && isCtrl) { // ctrl-v (paste clean text) m_message.SendMsg(WM_PASTE, 0, 0); return 0; } - if (wParam == VK_UP && (GetKeyState(VK_CONTROL) & 0x8000) && g_dat.bCtrlSupport && !g_dat.bAutoClose) { + if (wParam == VK_UP && isCtrl && g_dat.bCtrlSupport && !g_dat.bAutoClose) { if (m_cmdList.getCount()) { if (m_cmdListInd < 0) { m_cmdListInd = m_cmdList.getCount() - 1; @@ -696,7 +702,7 @@ LRESULT CSrmmWindow::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) return 0; } - if (wParam == VK_DOWN && (GetKeyState(VK_CONTROL) & 0x8000) && g_dat.bCtrlSupport && !g_dat.bAutoClose) { + if (wParam == VK_DOWN && isCtrl && g_dat.bCtrlSupport && !g_dat.bAutoClose) { if (m_cmdList.getCount() && m_cmdListInd >= 0) { if (m_cmdListInd < m_cmdList.getCount() - 1) SetEditorText(m_message.GetHwnd(), m_cmdList[++m_cmdListInd]); @@ -709,6 +715,24 @@ LRESULT CSrmmWindow::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) m_btnOk.Enable(GetWindowTextLength(m_message.GetHwnd()) != 0); UpdateReadChars(); } + + 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: @@ -851,14 +875,14 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) switch (uMsg) { case WM_CONTEXTMENU: - if (m_hwndStatus && m_hwndStatus == (HWND)wParam) { + if (m_pOwner->m_hwndStatus == (HWND)wParam) { POINT pt, pt2; GetCursorPos(&pt); pt2.x = pt.x; pt2.y = pt.y; - ScreenToClient(m_hwndStatus, &pt); + ScreenToClient(m_pOwner->m_hwndStatus, &pt); // no popup menu for status icons - this is handled via NM_RCLICK notification and the plugins that added the icons - SendMessage(m_hwndStatus, SB_GETRECT, SendMessage(m_hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc); + SendMessage(m_pOwner->m_hwndStatus, SB_GETRECT, SendMessage(m_pOwner->m_hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc); if (pt.x >= rc.left) break; @@ -947,15 +971,15 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case DM_UPDATEWINICON: if (g_dat.bUseStatusWinIcon) { - Window_FreeIcon_IcoLib(m_hwnd); + Window_FreeIcon_IcoLib(m_pOwner->GetHwnd()); if (m_szProto) { WORD wStatus = db_get_w(m_hContact, m_szProto, "Status", ID_STATUS_OFFLINE); - Window_SetProtoIcon_IcoLib(m_hwnd, m_szProto, wStatus); + Window_SetProtoIcon_IcoLib(m_pOwner->GetHwnd(), m_szProto, wStatus); break; } } - Window_SetSkinIcon_IcoLib(m_hwnd, SKINICON_EVENT_MESSAGE); + Window_SetSkinIcon_IcoLib(m_pOwner->GetHwnd(), SKINICON_EVENT_MESSAGE); break; case DM_USERNAMETOCLIP: @@ -973,7 +997,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) break; case DM_UPDATELASTMESSAGE: - if (!m_hwndStatus || m_nTypeSecs) + if (m_nTypeSecs) break; if (m_lastMessage) { @@ -981,11 +1005,11 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) TimeZone_PrintTimeStamp(nullptr, m_lastMessage, L"d", date, _countof(date), 0); TimeZone_PrintTimeStamp(nullptr, m_lastMessage, L"t", time, _countof(time), 0); mir_snwprintf(fmt, TranslateT("Last message received on %s at %s."), date, time); - SendMessage(m_hwndStatus, SB_SETTEXT, 0, (LPARAM)fmt); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)fmt); } - else SendMessage(m_hwndStatus, SB_SETTEXT, 0, (LPARAM)L""); + else SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)L""); - SendMessage(m_hwndStatus, SB_SETICON, 0, 0); + SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, 0); break; case DM_OPTIONSAPPLIED: @@ -1025,7 +1049,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) wchar_t oldtitle[256]; GetWindowText(m_hwnd, oldtitle, _countof(oldtitle)); if (mir_wstrcmp(newtitle, oldtitle)) { //swt() flickers even if the title hasn't actually changed - SetWindowText(m_hwnd, newtitle); + SetWindowText(m_pOwner->GetHwnd(), newtitle); SendMessage(m_hwnd, WM_SIZE, 0, 0); } break; @@ -1039,7 +1063,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case DM_CASCADENEWWINDOW: if ((HWND)wParam != m_hwnd) { RECT rcThis, rcNew; - GetWindowRect(m_hwnd, &rcThis); + 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); @@ -1083,10 +1107,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) if (!IsIconic(m_hwnd)) { BOOL bottomScroll = TRUE; - if (m_hwndStatus) { - SendMessage(m_hwndStatus, WM_SIZE, 0, 0); - SetupStatusBar(); - } + SetupStatusBar(); if (GetWindowLongPtr(m_log.GetHwnd(), GWL_STYLE) & WS_VSCROLL) { SCROLLINFO si = {}; @@ -1099,13 +1120,9 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) CDlgBase::DlgProc(uMsg, 0, 0); SetButtonsPos(m_hwnd, false); - // The statusbar sometimes draws over these 2 controls so - // redraw them - if (m_hwndStatus) { - RedrawWindow(m_btnOk.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); - RedrawWindow(m_message.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); - } - + // The statusbar sometimes draws over these 2 controls so redraw them + RedrawWindow(m_btnOk.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); + RedrawWindow(m_message.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); if (g_dat.bShowAvatar && m_avatarPic) RedrawWindow(m_avatar.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); @@ -1208,8 +1225,8 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) mir_snwprintf(szBuf, TranslateT("%s is typing a message..."), szContactName); m_nTypeSecs--; - SendMessage(m_hwndStatus, SB_SETTEXT, 0, (LPARAM)szBuf); - SendMessage(m_hwndStatus, SB_SETICON, 0, (LPARAM)hTyping); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)szBuf); + SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, (LPARAM)hTyping); if (g_dat.bShowTypingWin && GetForegroundWindow() != m_hwnd) { HICON hIcon = (HICON)SendMessage(m_hwnd, WM_GETICON, ICON_SMALL, 0); SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hTyping); @@ -1235,7 +1252,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) if (dis->CtlType == ODT_MENU) return Menu_DrawItem(lParam); - if (dis->hwndItem == m_hwndStatus) { + if (dis->hwndItem == m_pOwner->m_hwndStatus) { DrawStatusIcons(m_hContact, dis->hDC, dis->rcItem, 2); return TRUE; } @@ -1313,12 +1330,12 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) break; case WM_NOTIFY: - if (((LPNMHDR)lParam)->hwndFrom == m_hwndStatus) { + if (((LPNMHDR)lParam)->hwndFrom == m_pOwner->m_hwndStatus) { if (((LPNMHDR)lParam)->code == NM_CLICK || ((LPNMHDR)lParam)->code == NM_RCLICK) { NMMOUSE *nm = (NMMOUSE *)lParam; - SendMessage(m_hwndStatus, SB_GETRECT, SendMessage(m_hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc); + SendMessage(m_pOwner->m_hwndStatus, SB_GETRECT, SendMessage(m_pOwner->m_hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc); if (nm->pt.x >= rc.left) - CheckStatusIconClick(m_hContact, m_hwndStatus, nm->pt, rc, 2, ((LPNMHDR)lParam)->code == NM_RCLICK ? MBCF_RIGHTBUTTON : 0); + CheckStatusIconClick(m_hContact, m_pOwner->m_hwndStatus, nm->pt, rc, 2, ((LPNMHDR)lParam)->code == NM_RCLICK ? MBCF_RIGHTBUTTON : 0); return TRUE; } } @@ -1396,9 +1413,9 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) break; case DM_STATUSICONCHANGE: - SendMessage(m_hwndStatus, SB_SETTEXT, (SBT_OWNERDRAW | (SendMessage(m_hwndStatus, SB_GETPARTS, 0, 0) - 1)), 0); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, (SBT_OWNERDRAW | (SendMessage(m_pOwner->m_hwndStatus, SB_GETPARTS, 0, 0) - 1)), 0); break; } - return CSrmmBaseDialog::DlgProc(uMsg, wParam, lParam); + return CSuper::DlgProc(uMsg, wParam, lParam); } diff --git a/src/core/stdmsg/src/msgoptions.cpp b/src/core/stdmsg/src/msgoptions.cpp index de0f3dbe79..9e90e85fe1 100644 --- a/src/core/stdmsg/src/msgoptions.cpp +++ b/src/core/stdmsg/src/msgoptions.cpp @@ -169,8 +169,8 @@ static void FillCheckBoxTree(HWND hwndTree, const struct CheckBoxValues_t *value static DWORD MakeCheckBoxTreeFlags(HWND hwndTree) { DWORD flags = 0; - TVITEM tvi; + TVITEM tvi; tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE; tvi.hItem = TreeView_GetRoot(hwndTree); while (tvi.hItem) { @@ -182,6 +182,8 @@ static DWORD MakeCheckBoxTreeFlags(HWND hwndTree) return flags; } +///////////////////////////////////////////////////////////////////////////////////////// + static INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { @@ -191,21 +193,21 @@ static INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LP SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_POPLIST), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_POPLIST), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); FillCheckBoxTree(GetDlgItem(hwndDlg, IDC_POPLIST), statusValues, _countof(statusValues), db_get_dw(0, SRMMMOD, SRMSGSET_POPFLAGS, SRMSGDEFSET_POPFLAGS)); - CheckDlgButton(hwndDlg, IDC_DELTEMP, g_dat.bDeleteTempCont ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_AUTOMIN, g_dat.bAutoMin ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CASCADE, g_dat.bCascade ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_AUTOCLOSE, g_dat.bAutoClose ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHARCOUNT, g_dat.bShowReadChar ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_STATUSWIN, g_dat.bUseStatusWinIcon ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CTRLSUPPORT, g_dat.bCtrlSupport ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SHOWSENDBTN, g_dat.bSendButton ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SENDONENTER, g_dat.bSendOnEnter ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_LIMITAVATARH, db_get_b(0, SRMMMOD, SRMSGSET_LIMITAVHEIGHT, SRMSGDEFSET_LIMITAVHEIGHT) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SENDONDBLENTER, g_dat.bSendOnDblEnter ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_AVATARSUPPORT, g_dat.bShowAvatar ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SHOWBUTTONLINE, g_dat.bShowButtons ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SAVEPERCONTACT, g_dat.bSavePerContact ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_DONOTSTEALFOCUS, g_dat.bDoNotStealFocus ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DELTEMP, g_dat.bDeleteTempCont); + CheckDlgButton(hwndDlg, IDC_AUTOMIN, g_dat.bAutoMin); + CheckDlgButton(hwndDlg, IDC_CASCADE, g_dat.bCascade); + CheckDlgButton(hwndDlg, IDC_AUTOCLOSE, g_dat.bAutoClose); + CheckDlgButton(hwndDlg, IDC_CHARCOUNT, g_dat.bShowReadChar); + CheckDlgButton(hwndDlg, IDC_STATUSWIN, g_dat.bUseStatusWinIcon); + CheckDlgButton(hwndDlg, IDC_CTRLSUPPORT, g_dat.bCtrlSupport); + CheckDlgButton(hwndDlg, IDC_SHOWSENDBTN, g_dat.bSendButton); + CheckDlgButton(hwndDlg, IDC_SENDONENTER, g_dat.bSendOnEnter); + CheckDlgButton(hwndDlg, IDC_LIMITAVATARH, db_get_b(0, SRMMMOD, SRMSGSET_LIMITAVHEIGHT, SRMSGDEFSET_LIMITAVHEIGHT)); + CheckDlgButton(hwndDlg, IDC_SENDONDBLENTER, g_dat.bSendOnDblEnter); + CheckDlgButton(hwndDlg, IDC_AVATARSUPPORT, g_dat.bShowAvatar); + CheckDlgButton(hwndDlg, IDC_SHOWBUTTONLINE, g_dat.bShowButtons); + CheckDlgButton(hwndDlg, IDC_SAVEPERCONTACT, g_dat.bSavePerContact); + CheckDlgButton(hwndDlg, IDC_DONOTSTEALFOCUS, g_dat.bDoNotStealFocus); { DWORD avatarHeight = db_get_dw(0, SRMMMOD, SRMSGSET_AVHEIGHT, SRMSGDEFSET_AVHEIGHT); SetDlgItemInt(hwndDlg, IDC_NFLASHES, db_get_b(0, SRMMMOD, SRMSGSET_FLASHCOUNT, SRMSGDEFSET_FLASHCOUNT), FALSE); @@ -352,14 +354,14 @@ static INT_PTR CALLBACK DlgProcLogOptions(HWND hwndDlg, UINT msg, WPARAM wParam, SendDlgItemMessage(hwndDlg, IDC_LOADTIMESPIN, UDM_SETRANGE, 0, MAKELONG(12 * 60, 0)); SendDlgItemMessage(hwndDlg, IDC_LOADTIMESPIN, UDM_SETPOS, 0, db_get_w(0, SRMMMOD, SRMSGSET_LOADTIME, SRMSGDEFSET_LOADTIME)); - CheckDlgButton(hwndDlg, IDC_SHOWLOGICONS, db_get_b(0, SRMMMOD, SRMSGSET_SHOWLOGICONS, SRMSGDEFSET_SHOWLOGICONS) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SHOWNAMES, !db_get_b(0, SRMMMOD, SRMSGSET_HIDENAMES, SRMSGDEFSET_HIDENAMES) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SHOWTIMES, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTIME, SRMSGDEFSET_SHOWTIME) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_SHOWLOGICONS, db_get_b(0, SRMMMOD, SRMSGSET_SHOWLOGICONS, SRMSGDEFSET_SHOWLOGICONS)); + CheckDlgButton(hwndDlg, IDC_SHOWNAMES, !db_get_b(0, SRMMMOD, SRMSGSET_HIDENAMES, SRMSGDEFSET_HIDENAMES)); + CheckDlgButton(hwndDlg, IDC_SHOWTIMES, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTIME, SRMSGDEFSET_SHOWTIME)); EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWSECS), IsDlgButtonChecked(hwndDlg, IDC_SHOWTIMES)); - CheckDlgButton(hwndDlg, IDC_SHOWSECS, db_get_b(0, SRMMMOD, SRMSGSET_SHOWSECS, SRMSGDEFSET_SHOWSECS) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_SHOWSECS, db_get_b(0, SRMMMOD, SRMSGSET_SHOWSECS, SRMSGDEFSET_SHOWSECS)); EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWDATES), IsDlgButtonChecked(hwndDlg, IDC_SHOWTIMES)); - CheckDlgButton(hwndDlg, IDC_SHOWDATES, db_get_b(0, SRMMMOD, SRMSGSET_SHOWDATE, SRMSGDEFSET_SHOWDATE) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SHOWFORMATTING, db_get_b(0, SRMMMOD, SRMSGSET_SHOWFORMAT, SRMSGDEFSET_SHOWFORMAT) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_SHOWDATES, db_get_b(0, SRMMMOD, SRMSGSET_SHOWDATE, SRMSGDEFSET_SHOWDATE)); + CheckDlgButton(hwndDlg, IDC_SHOWFORMATTING, db_get_b(0, SRMMMOD, SRMSGSET_SHOWFORMAT, SRMSGDEFSET_SHOWFORMAT)); return TRUE; case WM_COMMAND: @@ -477,11 +479,11 @@ static INT_PTR CALLBACK DlgProcTypeOptions(HWND hwndDlg, UINT msg, WPARAM wParam } SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE) | (CLS_SHOWHIDDEN) | (CLS_NOHIDEOFFLINE)); ResetCList(hwndDlg); - CheckDlgButton(hwndDlg, IDC_SHOWNOTIFY, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPING, SRMSGDEFSET_SHOWTYPING) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_TYPEWIN, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPINGWIN, SRMSGDEFSET_SHOWTYPINGWIN) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_TYPETRAY, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPINGNOWIN, SRMSGDEFSET_SHOWTYPINGNOWIN) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_NOTIFYTRAY, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPINGCLIST, SRMSGDEFSET_SHOWTYPINGCLIST) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_NOTIFYBALLOON, !db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPINGCLIST, SRMSGDEFSET_SHOWTYPINGCLIST) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_SHOWNOTIFY, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPING, SRMSGDEFSET_SHOWTYPING)); + CheckDlgButton(hwndDlg, IDC_TYPEWIN, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPINGWIN, SRMSGDEFSET_SHOWTYPINGWIN)); + CheckDlgButton(hwndDlg, IDC_TYPETRAY, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPINGNOWIN, SRMSGDEFSET_SHOWTYPINGNOWIN)); + CheckDlgButton(hwndDlg, IDC_NOTIFYTRAY, db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPINGCLIST, SRMSGDEFSET_SHOWTYPINGCLIST)); + CheckDlgButton(hwndDlg, IDC_NOTIFYBALLOON, !db_get_b(0, SRMMMOD, SRMSGSET_SHOWTYPINGCLIST, SRMSGDEFSET_SHOWTYPINGCLIST)); EnableWindow(GetDlgItem(hwndDlg, IDC_TYPEWIN), IsDlgButtonChecked(hwndDlg, IDC_SHOWNOTIFY)); EnableWindow(GetDlgItem(hwndDlg, IDC_TYPETRAY), IsDlgButtonChecked(hwndDlg, IDC_SHOWNOTIFY)); EnableWindow(GetDlgItem(hwndDlg, IDC_NOTIFYTRAY), IsDlgButtonChecked(hwndDlg, IDC_TYPETRAY)); diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index 36675d350b..2e8d5752e0 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -81,8 +81,7 @@ static int MessageEventAdded(WPARAM hContact, LPARAM lParam) char *szProto = GetContactProto(hContact); if (szProto && (g_dat.openFlags & SRMMStatusToPf2(CallProtoService(szProto, PS_GETSTATUS, 0, 0)))) { - CSrmmWindow *pDlg = new CSrmmWindow(hContact); - pDlg->Show(); + GetContainer()->AddPage(hContact); return 0; } @@ -120,12 +119,8 @@ INT_PTR SendMessageCmd(MCONTACT hContact, wchar_t *pwszInitialText) SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); SetForegroundWindow(hwnd); } - else { - CSrmmWindow *pDlg = new CSrmmWindow(hContact); - pDlg->m_wszInitialText = pwszInitialText; - pDlg->m_bNoActivate = false; - pDlg->Show(); - } + else GetContainer()->AddPage(hContact, pwszInitialText, false); + return 0; } @@ -247,11 +242,10 @@ static void RestoreUnreadMessageAlerts(void) if (szProto && (g_dat.openFlags & SRMMStatusToPf2(CallProtoService(szProto, PS_GETSTATUS, 0, 0)))) autoPopup = true; - if (autoPopup && !windowAlreadyExists) { - CSrmmWindow *pDlg = new CSrmmWindow(hContact); - pDlg->Show(); - } - else arEvents.insert(new MSavedEvent(hContact, hDbEvent)); + if (autoPopup && !windowAlreadyExists) + GetContainer()->AddPage(hContact); + else + arEvents.insert(new MSavedEvent(hContact, hDbEvent)); } } } diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index 9e3e11b129..48a028245a 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -66,7 +66,6 @@ class CSrmmWindow : public CSrmmBaseDialog void StreamInEvents(MEVENT hDbEventFirst, int count, bool bAppend); char *m_szProto; - HWND m_hwndStatus; HFONT m_hFont; HBRUSH m_hBkgBrush; @@ -97,9 +96,10 @@ public: HBITMAP m_avatarPic; wchar_t *m_wszInitialText; + CTabbedWindow *m_pOwner; public: - CSrmmWindow(MCONTACT hContact); + CSrmmWindow(CTabbedWindow*, MCONTACT hContact); virtual void OnInitDialog() override; virtual void OnDestroy() override; @@ -107,6 +107,7 @@ public: virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override; virtual int Resizer(UTILRESIZECONTROL *urc) override; + virtual void CloseTab() override; virtual void LoadSettings() override {} virtual void ScrollToBottom() override; virtual void UpdateTitle() override {} diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index b8248a870d..820fc8d910 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -154,8 +154,9 @@ public: CTabbedWindow(); + CTabbedWindow* AddPage(MCONTACT hContact, wchar_t *pwszText = nullptr, int iActivate = -1); void AddPage(SESSION_INFO*, int insertAt = -1); - void FixTabIcons(CChatRoomDlg*); + void FixTabIcons(CSrmmBaseDialog*); void SetMessageHighlight(CChatRoomDlg*); void SetTabHighlight(CChatRoomDlg*); void TabClicked(); @@ -170,6 +171,7 @@ public: extern CTabbedWindow *pDialog; void UninitTabs(void); +CTabbedWindow* GetContainer(); void TB_SaveSession(SESSION_INFO *si); diff --git a/src/core/stdmsg/src/tabs.cpp b/src/core/stdmsg/src/tabs.cpp index 2336e068ad..a3f9ed91d8 100644 --- a/src/core/stdmsg/src/tabs.cpp +++ b/src/core/stdmsg/src/tabs.cpp @@ -44,6 +44,21 @@ CTabbedWindow *pDialog = nullptr; ///////////////////////////////////////////////////////////////////////////////////////// +CTabbedWindow* GetContainer() +{ + if (g_Settings.bTabsEnable) { + if (pDialog == nullptr) { + pDialog = new CTabbedWindow(); + pDialog->Show(); + } + return pDialog; + } + + return new CTabbedWindow(); +} + +///////////////////////////////////////////////////////////////////////////////////////// + CTabbedWindow::CTabbedWindow() : CDlgBase(g_hInst, IDD_CONTAINER), m_tab(this, IDC_TAB), @@ -117,6 +132,31 @@ int CTabbedWindow::Resizer(UTILRESIZECONTROL *urc) ///////////////////////////////////////////////////////////////////////////////////////// +CTabbedWindow* CTabbedWindow::AddPage(MCONTACT hContact, wchar_t *pwszText, int iNoActivate) +{ + CSrmmWindow *pDlg = new CSrmmWindow(this, hContact); + pDlg->m_wszInitialText = pwszText; + if (iNoActivate != -1) + pDlg->m_bNoActivate = iNoActivate != 0; + + if (g_Settings.bTabsEnable) { + m_tab.AddPage(pcli->pfnGetContactDisplayName(hContact, 0), nullptr, pDlg); + FixTabIcons(pDlg); + + m_tab.ActivatePage(m_tab.GetCount() - 1); + } + else { + m_pEmbed = pDlg; + Create(); + pDlg->SetParent(m_hwnd); + pDlg->Create(); + Show(); + } + + PostMessage(m_hwnd, WM_SIZE, 0, 0); + return this; +} + void CTabbedWindow::AddPage(SESSION_INFO *si, int insertAt) { // does the tab already exist? @@ -141,20 +181,21 @@ void CTabbedWindow::AddPage(SESSION_INFO *si, int insertAt) m_tab.ActivatePage(indexfound); } -void CTabbedWindow::FixTabIcons(CChatRoomDlg *pDlg) +void CTabbedWindow::FixTabIcons(CSrmmBaseDialog *pDlg) { if (pDlg != nullptr) { int idx = m_tab.GetDlgIndex(pDlg); if (idx == -1) return; - SESSION_INFO *si = pDlg->m_si; int image = 0; - if (!(si->wState & GC_EVENT_HIGHLIGHT)) { - MODULEINFO *mi = pci->MM_FindModule(si->pszModule); - image = (si->wStatus == ID_STATUS_ONLINE) ? mi->OnlineIconIndex : mi->OfflineIconIndex; - if (si->wState & STATE_TALK) - image++; + if (SESSION_INFO *si = ((CChatRoomDlg*)pDlg)->m_si) { + if (!(si->wState & GC_EVENT_HIGHLIGHT)) { + MODULEINFO *mi = pci->MM_FindModule(si->pszModule); + image = (si->wStatus == ID_STATUS_ONLINE) ? mi->OnlineIconIndex : mi->OfflineIconIndex; + if (si->wState & STATE_TALK) + image++; + } } TCITEM tci = {}; -- cgit v1.2.3