From ae93aa98b214f98a0e28df1bdaa8df18b3f6da02 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 2 Mar 2017 14:12:59 +0300 Subject: further SRMM window unification - CSrmmBaseDialog received m_hContact as its common member; - less usage of CTabBaseDlg::m_bType in tabSRMM --- plugins/TabSRMM/src/chat/log.cpp | 2 +- plugins/TabSRMM/src/chat/window.cpp | 21 ++++++++ plugins/TabSRMM/src/infopanel.cpp | 4 +- plugins/TabSRMM/src/msgdialog.cpp | 33 ++++++++++-- plugins/TabSRMM/src/msgdlgutils.cpp | 51 ++---------------- plugins/TabSRMM/src/msgs.cpp | 4 +- plugins/TabSRMM/src/msgs.h | 12 ++++- plugins/TabSRMM/src/tabctrl.cpp | 2 +- plugins/TabSRMM/src/taskbar.cpp | 103 ++++++++++++++++++------------------ plugins/TabSRMM/src/taskbar.h | 8 +-- 10 files changed, 127 insertions(+), 113 deletions(-) (limited to 'plugins/TabSRMM/src') diff --git a/plugins/TabSRMM/src/chat/log.cpp b/plugins/TabSRMM/src/chat/log.cpp index 16ee04bc07..5981eb3557 100644 --- a/plugins/TabSRMM/src/chat/log.cpp +++ b/plugins/TabSRMM/src/chat/log.cpp @@ -857,7 +857,7 @@ static DWORD CALLBACK Log_StreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG return 0; } -void CChatRoomDlg::StreamInEvents(LOGINFO* lin, SESSION_INFO *si, bool bRedraw) +void CChatRoomDlg::StreamInEvents(LOGINFO *lin, SESSION_INFO *si, bool bRedraw) { CHARRANGE oldsel, sel, newsel; POINT point = { 0 }; diff --git a/plugins/TabSRMM/src/chat/window.cpp b/plugins/TabSRMM/src/chat/window.cpp index 17c40a43a6..89b5c71d12 100644 --- a/plugins/TabSRMM/src/chat/window.cpp +++ b/plugins/TabSRMM/src/chat/window.cpp @@ -1542,6 +1542,27 @@ CChatRoomDlg::CChatRoomDlg(TNewWindowData *pData) m_Panel = new CInfoPanel(this); } +CThumbBase* CChatRoomDlg::CreateThumb(CProxyWindow *pProxy) const +{ + return new CThumbMUC(pProxy, si); +} + +void CChatRoomDlg::ClearLog() +{ + SESSION_INFO *s = pci->SM_FindSession(si->ptszID, si->pszModule); + if (s) { + m_log.SetText(L""); + pci->LM_RemoveAll(&s->pLog, &s->pLogEnd); + s->iEventCount = 0; + s->LastTime = 0; + si->iEventCount = 0; + si->LastTime = 0; + si->pLog = s->pLog; + si->pLogEnd = s->pLogEnd; + PostMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); + } +} + void CChatRoomDlg::OnInitDialog() { SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); diff --git a/plugins/TabSRMM/src/infopanel.cpp b/plugins/TabSRMM/src/infopanel.cpp index bba1ddffdd..a24101d889 100644 --- a/plugins/TabSRMM/src/infopanel.cpp +++ b/plugins/TabSRMM/src/infopanel.cpp @@ -598,8 +598,8 @@ void CInfoPanel::RenderIPStatus(const HDC hdc, RECT& rcItem) void CInfoPanel::Chat_RenderIPNickname(const HDC hdc, RECT& rcItem) { - SESSION_INFO *si = reinterpret_cast(m_dat->si); - if (si == 0) + SESSION_INFO *si = m_dat->si; + if (si == nullptr) return; ::SetBkMode(hdc, TRANSPARENT); diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index d899201b24..acaa4fe9a8 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -80,7 +80,7 @@ static void _clrMsgFilter(LPARAM lParam) // @param hwndFrom src window handle // @param pt mouse pointer position -static void ShowPopupMenu(CSrmmWindow *dat, int idFrom, HWND hwndFrom, POINT pt) +static void ShowPopupMenu(CTabBaseDlg *dat, int idFrom, HWND hwndFrom, POINT pt) { CHARRANGE sel, all = { 0, -1 }; HWND hwndDlg = dat->GetHwnd(); @@ -915,9 +915,8 @@ LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM dat->m_dynaSplitter = dat->m_savedDynaSplit; dat->DM_RecalcPictureSize(); if (dat->m_bType == SESSIONTYPE_CHAT) { - SESSION_INFO *si = dat->si; - si->iSplitterY = dat->m_savedSplitY; - dat->m_splitterY = si->iSplitterY + DPISCALEY_S(22); + dat->si->iSplitterY = dat->m_savedSplitY; + dat->m_splitterY = dat->si->iSplitterY + DPISCALEY_S(22); } dat->UpdateToolbarBG(); SendMessage(hwndParent, WM_SIZE, 0, 0); @@ -944,6 +943,32 @@ CSrmmWindow::CSrmmWindow(TNewWindowData *pNewData) m_Panel = new CInfoPanel(this); } +void CSrmmWindow::ClearLog() +{ + if (m_hwndIEView || m_hwndHPP) { + IEVIEWEVENT event; + event.cbSize = sizeof(IEVIEWEVENT); + event.iType = IEE_CLEAR_LOG; + event.dwFlags = (m_dwFlags & MWF_LOG_RTL) ? IEEF_RTL : 0; + event.hContact = m_hContact; + if (m_hwndIEView) { + event.hwnd = m_hwndIEView; + CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&event); + } + else { + event.hwnd = m_hwndHPP; + CallService(MS_HPP_EG_EVENT, 0, (LPARAM)&event); + } + } + m_log.SetText(L""); + m_hDbEventFirst = 0; +} + +CThumbBase* CSrmmWindow::CreateThumb(CProxyWindow *pProxy) const +{ + return new CThumbIM(pProxy); +} + void CSrmmWindow::OnInitDialog() { m_pContainer = newData->pContainer; diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index df8a2536e2..40224c9339 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -325,12 +325,10 @@ int CTabBaseDlg::MsgWindowMenuHandler(int selection, int menuId) db_unset(m_hContact, SRMSGMOD_T, "tabindex"); break; case ID_TABMENU_LEAVECHATROOM: - if (m_bType == SESSIONTYPE_CHAT) { - if (si != NULL && m_hContact != NULL) { - char *szProto = GetContactProto(m_hContact); - if (szProto) - CallProtoService(szProto, PS_LEAVECHAT, m_hContact, 0); - } + if (m_bType == SESSIONTYPE_CHAT && m_hContact != NULL) { + char *szProto = GetContactProto(m_hContact); + if (szProto) + CallProtoService(szProto, PS_LEAVECHAT, m_hContact, 0); } return 1; @@ -1704,47 +1702,6 @@ void CTabBaseDlg::KbdState(bool &isShift, bool &isControl, bool &isAlt) isAlt = (kstate[VK_MENU] & 0x80) != 0; } -///////////////////////////////////////////////////////////////////////////////////////// -// clear the message log -// code needs to distuingish between IM and MUC sessions. - -void CTabBaseDlg::ClearLog() -{ - if (m_bType == SESSIONTYPE_IM) { - if (m_hwndIEView || m_hwndHPP) { - IEVIEWEVENT event; - event.cbSize = sizeof(IEVIEWEVENT); - event.iType = IEE_CLEAR_LOG; - event.dwFlags = (m_dwFlags & MWF_LOG_RTL) ? IEEF_RTL : 0; - event.hContact = m_hContact; - if (m_hwndIEView) { - event.hwnd = m_hwndIEView; - CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&event); - } - else { - event.hwnd = m_hwndHPP; - CallService(MS_HPP_EG_EVENT, 0, (LPARAM)&event); - } - } - m_log.SetText(L""); - m_hDbEventFirst = 0; - } - else if (m_bType == SESSIONTYPE_CHAT && si) { - SESSION_INFO *s = pci->SM_FindSession(si->ptszID, si->pszModule); - if (s) { - m_log.SetText(L""); - pci->LM_RemoveAll(&s->pLog, &s->pLogEnd); - s->iEventCount = 0; - s->LastTime = 0; - si->iEventCount = 0; - si->LastTime = 0; - si->pLog = s->pLog; - si->pLogEnd = s->pLogEnd; - PostMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); - } - } -} - ///////////////////////////////////////////////////////////////////////////////////////// // calculate the minimum required client height for the given message // window layout diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp index 29597c7215..12d28e1498 100644 --- a/plugins/TabSRMM/src/msgs.cpp +++ b/plugins/TabSRMM/src/msgs.cpp @@ -123,11 +123,11 @@ CTabBaseDlg::CTabBaseDlg(TNewWindowData *pData, int iResource) m_message(this, IDC_MESSAGE), newData(pData), - m_pContainer(pData->pContainer), - m_hContact(pData->hContact) + m_pContainer(pData->pContainer) { m_pLog = &m_log; m_pEntry = &m_message; + m_hContact = pData->hContact; m_autoClose = 0; m_forceResizable = true; diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index 26648a98ad..ef7d394969 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -135,6 +135,7 @@ class CMenuBar; class CInfoPanel; class CSideBar; class CProxyWindow; +class CThumbBase; struct CContactCache; @@ -274,7 +275,6 @@ public: BYTE m_bType; DWORD m_dwFlags; DWORD m_dwFlagsEx; - MCONTACT m_hContact; char *m_szProto; wchar_t m_wszMyNickname[130]; wchar_t m_wszStatusBar[100]; @@ -375,6 +375,9 @@ public: public: CTabBaseDlg(TNewWindowData*, int); + virtual CThumbBase* CreateThumb(CProxyWindow*) const = 0; + virtual void ClearLog() = 0; + HWND DM_CreateClist(); void DM_EventAdded(WPARAM wParam, LPARAM lParam); void DM_InitRichEdit(); @@ -408,7 +411,6 @@ public: void AdjustBottomAvatarDisplay(); void CalcDynamicAvatarSize(BITMAP *bminfo); void CheckStatusIconClick(POINT pt, const RECT &rc, int gap, int code); - void ClearLog(); BOOL DoRtfToTags(CMStringW &pszText, int iNumColors, COLORREF *pColors) const; void DrawStatusIcons(HDC hDC, const RECT &rc, int gap); void EnableSendButton(bool bMode) const; @@ -445,6 +447,9 @@ public: class CSrmmWindow : public CTabBaseDlg, public MZeroedObject { + virtual CThumbBase* CreateThumb(CProxyWindow *pProxy) const override; + virtual void ClearLog() override; + void DM_OptionsApplied(WPARAM wParam, LPARAM lParam); void MsgWindowUpdateState(UINT msg); @@ -468,6 +473,9 @@ class CChatRoomDlg : public CTabBaseDlg, public MZeroedObject { bool m_bWasDeleted; + virtual CThumbBase* CreateThumb(CProxyWindow *pProxy) const override; + virtual void ClearLog() override; + public: CChatRoomDlg(TNewWindowData*); diff --git a/plugins/TabSRMM/src/tabctrl.cpp b/plugins/TabSRMM/src/tabctrl.cpp index b82a1016dd..ec39dfb404 100644 --- a/plugins/TabSRMM/src/tabctrl.cpp +++ b/plugins/TabSRMM/src/tabctrl.cpp @@ -182,7 +182,7 @@ static void DrawItem(TabControlData *tabdat, HDC dc, RECT *rcItem, int nHint, in else if (dat->m_bCanFlashTab) hIcon = dat->m_iFlashIcon; else { - if (dat->si && dat->m_iFlashIcon) { + if (dat->m_bType == SESSIONTYPE_CHAT && dat->m_iFlashIcon) { hIcon = dat->m_iFlashIcon; int sizeY; diff --git a/plugins/TabSRMM/src/taskbar.cpp b/plugins/TabSRMM/src/taskbar.cpp index aa0be96110..16a3c67145 100644 --- a/plugins/TabSRMM/src/taskbar.cpp +++ b/plugins/TabSRMM/src/taskbar.cpp @@ -293,10 +293,7 @@ void CProxyWindow::sendThumb(LONG width, LONG height) if (0 == m_thumb) { m_width = width; m_height = height; - if (m_dat->m_bType == SESSIONTYPE_IM) - m_thumb = new CThumbIM(this); - else - m_thumb = new CThumbMUC(this); + m_thumb = m_dat->CreateThumb(this); } else if (width != m_width || height != m_height || !m_thumb->isValid()) { m_width = width; @@ -834,7 +831,9 @@ void CThumbIM::renderContent() * @param _p our owner (CProxyWindow object) * @return */ -CThumbMUC::CThumbMUC(const CProxyWindow* _p) : CThumbBase(_p) +CThumbMUC::CThumbMUC(const CProxyWindow* _p, SESSION_INFO *_si) + : CThumbBase(_p), + si(_si) { renderContent(); setValid(true); @@ -855,61 +854,63 @@ void CThumbMUC::update() */ void CThumbMUC::renderContent() { - if (m_dat->si) { - const MODULEINFO* mi = pci->MM_FindModule(m_dat->si->pszModule); - wchar_t szTemp[250]; - const wchar_t* szStatusMsg = 0; + if (si == nullptr) + return; - if (mi) { - if (m_dat->m_dwUnread) { - mir_snwprintf(szTemp, TranslateT("%d unread"), m_dat->m_dwUnread); - CSkin::RenderText(m_hdc, m_dat->m_hTheme, szTemp, &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); - m_rcIcon.top += m_sz.cy; + const MODULEINFO *mi = pci->MM_FindModule(si->pszModule); + if (mi) { + wchar_t szTemp[250]; + if (m_dat->m_dwUnread) { + mir_snwprintf(szTemp, TranslateT("%d unread"), m_dat->m_dwUnread); + CSkin::RenderText(m_hdc, m_dat->m_hTheme, szTemp, &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); + m_rcIcon.top += m_sz.cy; + } + if (si->iType != GCW_SERVER) { + wchar_t* _p = NULL; + if (si->ptszStatusbarText) + _p = wcschr(si->ptszStatusbarText, ']'); + if (_p) { + _p++; + wchar_t _t = *_p; + *_p = 0; + mir_snwprintf(szTemp, TranslateT("Chat room %s"), si->ptszStatusbarText); + *_p = _t; } - if (m_dat->si->iType != GCW_SERVER) { - wchar_t* _p = NULL; - if (m_dat->si->ptszStatusbarText) - _p = wcschr(m_dat->si->ptszStatusbarText, ']'); - if (_p) { - _p++; - wchar_t _t = *_p; - *_p = 0; - mir_snwprintf(szTemp, TranslateT("Chat room %s"), m_dat->si->ptszStatusbarText); - *_p = _t; - } - else - mir_snwprintf(szTemp, TranslateT("Chat room %s"), L""); - CSkin::RenderText(m_hdc, m_dat->m_hTheme, szTemp, &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); + else + mir_snwprintf(szTemp, TranslateT("Chat room %s"), L""); + CSkin::RenderText(m_hdc, m_dat->m_hTheme, szTemp, &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); + m_rcIcon.top += m_sz.cy; + mir_snwprintf(szTemp, TranslateT("%d user(s)"), si->nUsersInNicklist); + CSkin::RenderText(m_hdc, m_dat->m_hTheme, szTemp, &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); + } + else { + mir_snwprintf(szTemp, TranslateT("Server window")); + CSkin::RenderText(m_hdc, m_dat->m_hTheme, szTemp, &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); + if (mi->tszIdleMsg[0] && mir_wstrlen(mi->tszIdleMsg) > 2) { m_rcIcon.top += m_sz.cy; - mir_snwprintf(szTemp, TranslateT("%d user(s)"), m_dat->si->nUsersInNicklist); - CSkin::RenderText(m_hdc, m_dat->m_hTheme, szTemp, &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); - } - else { - mir_snwprintf(szTemp, TranslateT("Server window")); - CSkin::RenderText(m_hdc, m_dat->m_hTheme, szTemp, &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); - if (mi->tszIdleMsg[0] && mir_wstrlen(mi->tszIdleMsg) > 2) { - m_rcIcon.top += m_sz.cy; - CSkin::RenderText(m_hdc, m_dat->m_hTheme, &mi->tszIdleMsg[2], &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); - } + CSkin::RenderText(m_hdc, m_dat->m_hTheme, &mi->tszIdleMsg[2], &m_rcIcon, m_dtFlags | DT_SINGLELINE | DT_RIGHT, 10, 0, true); } } + } - if ((m_rcBottom.bottom - m_rcBottom.top) < 2 * m_sz.cy) - m_dtFlags |= DT_SINGLELINE; - - m_rcBottom.bottom -= ((m_rcBottom.bottom - m_rcBottom.top) % m_sz.cy); // adjust to a multiple of line height + if ((m_rcBottom.bottom - m_rcBottom.top) < 2 * m_sz.cy) + m_dtFlags |= DT_SINGLELINE; - if (m_dat->si->iType != GCW_SERVER) { - if (0 == (szStatusMsg = m_dat->si->ptszTopic)) - szStatusMsg = TranslateT("no topic set."); - } - else if (mi) { - mir_snwprintf(szTemp, TranslateT("%s on %s%s"), m_dat->m_wszMyNickname, mi->ptszModDispName, L""); - szStatusMsg = szTemp; - } + m_rcBottom.bottom -= ((m_rcBottom.bottom - m_rcBottom.top) % m_sz.cy); // adjust to a multiple of line height - CSkin::RenderText(m_hdc, m_dat->m_hTheme, szStatusMsg, &m_rcBottom, DT_WORD_ELLIPSIS | DT_END_ELLIPSIS | m_dtFlags, 10, 0, true); + const wchar_t *szStatusMsg = 0; + if (si->iType != GCW_SERVER) { + if (0 == (szStatusMsg = si->ptszTopic)) + szStatusMsg = TranslateT("no topic set."); + } + else if (mi) { + wchar_t szTemp[250]; + mir_snwprintf(szTemp, TranslateT("%s on %s%s"), m_dat->m_wszMyNickname, mi->ptszModDispName, L""); + szStatusMsg = szTemp; } + + CSkin::RenderText(m_hdc, m_dat->m_hTheme, szStatusMsg, &m_rcBottom, DT_WORD_ELLIPSIS | DT_END_ELLIPSIS | m_dtFlags, 10, 0, true); + /* * finalize it * do NOT delete the bitmap, the dwm will need the handle diff --git a/plugins/TabSRMM/src/taskbar.h b/plugins/TabSRMM/src/taskbar.h index d8ca7ec962..8c7c3e4719 100644 --- a/plugins/TabSRMM/src/taskbar.h +++ b/plugins/TabSRMM/src/taskbar.h @@ -80,18 +80,20 @@ public: void update(); private: - void renderContent(); + virtual void renderContent() override; }; class CThumbMUC : public CThumbBase { + SESSION_INFO *si; + public: - CThumbMUC(const CProxyWindow* pWnd); + CThumbMUC(const CProxyWindow* pWnd, SESSION_INFO*); virtual ~CThumbMUC() {}; void update(); private: - void renderContent(); + virtual void renderContent() override; }; class CProxyWindow -- cgit v1.2.3