From e02f1e05b363226a48fe9a4b151748a5cbb295d9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 11 Mar 2017 12:27:21 +0300 Subject: GC_UPDATETITLE replaced with CSrmmBaseDlg::UpdateTitle --- plugins/Scriver/src/chat/window.cpp | 82 +++++++++++++++++---------------- plugins/Scriver/src/msgdialog.cpp | 91 ++++++++++++++++++++++++------------- plugins/Scriver/src/msgs.h | 2 + plugins/Scriver/src/tabs.cpp | 61 +------------------------ plugins/Scriver/src/tabs.h | 2 - 5 files changed, 106 insertions(+), 132 deletions(-) (limited to 'plugins/Scriver/src') diff --git a/plugins/Scriver/src/chat/window.cpp b/plugins/Scriver/src/chat/window.cpp index 0db9074563..4b1e6006db 100644 --- a/plugins/Scriver/src/chat/window.cpp +++ b/plugins/Scriver/src/chat/window.cpp @@ -971,7 +971,7 @@ void CChatRoomDlg::OnInitDialog() SendMessage(m_hwnd, GC_SETWNDPROPS, 0, 0); SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); - SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + UpdateTitle(); SendMessage(m_hwndParent, CM_ADDCHILD, (WPARAM)this, 0); PostMessage(m_hwnd, GC_UPDATENICKLIST, 0, 0); @@ -1217,6 +1217,44 @@ void CChatRoomDlg::onChange_Message(CCtrlEdit *pEdit) m_btnOk.Enable(GetRichTextLength(pEdit->GetHwnd(), 1200, FALSE) != 0); } +void CChatRoomDlg::UpdateTitle() +{ + TitleBarData tbd = {}; + if (g_dat.flags & SMF_STATUSICON) { + MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); + tbd.hIcon = (m_si->wStatus == ID_STATUS_ONLINE) ? mi->hOnlineIcon : mi->hOfflineIcon; + tbd.hIconBig = (m_si->wStatus == ID_STATUS_ONLINE) ? mi->hOnlineIconBig : mi->hOfflineIconBig; + } + else { + tbd.hIcon = GetCachedIcon("chat_window"); + tbd.hIconBig = g_dat.hIconChatBig; + } + tbd.hIconNot = (m_si->wState & (GC_EVENT_HIGHLIGHT | STATE_TALK)) ? GetCachedIcon("chat_overlay") : nullptr; + + wchar_t szTemp[512]; + switch (m_si->iType) { + case GCW_CHATROOM: + mir_snwprintf(szTemp, + (m_si->nUsersInNicklist == 1) ? TranslateT("%s: chat room (%u user)") : TranslateT("%s: chat room (%u users)"), + m_si->ptszName, m_si->nUsersInNicklist); + break; + case GCW_PRIVMESS: + mir_snwprintf(szTemp, + (m_si->nUsersInNicklist == 1) ? TranslateT("%s: message session") : TranslateT("%s: message session (%u users)"), + m_si->ptszName, m_si->nUsersInNicklist); + break; + case GCW_SERVER: + mir_snwprintf(szTemp, L"%s: Server", m_si->ptszName); + break; + } + tbd.iFlags = TBDF_TEXT | TBDF_ICON; + tbd.pszText = szTemp; + SendMessage(m_hwndParent, CM_UPDATETITLEBAR, (WPARAM)&tbd, (LPARAM)m_hwnd); + SendMessage(m_hwnd, DM_UPDATETABCONTROL, 0, 0); +} + +///////////////////////////////////////////////////////////////////////////////////////// + INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { static HMENU hToolbarMenu; @@ -1224,7 +1262,6 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) POINT pt; HICON hIcon; TabControlData tcd; - TitleBarData tbd; wchar_t szTemp[512]; switch (uMsg) { @@ -1245,7 +1282,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) } SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); - SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + UpdateTitle(); SendMessage(m_hwnd, GC_FIXTABICONS, 0, 0); m_log.SendMsg(EM_SETBKGNDCOLOR, 0, g_Settings.crLogBackground); @@ -1281,39 +1318,6 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) SendMessage(m_hwnd, GC_REDRAWLOG2, 0, 0); break; - case DM_UPDATETITLEBAR: - if (g_dat.flags & SMF_STATUSICON) { - MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); - tbd.hIcon = (m_si->wStatus == ID_STATUS_ONLINE) ? mi->hOnlineIcon : mi->hOfflineIcon; - tbd.hIconBig = (m_si->wStatus == ID_STATUS_ONLINE) ? mi->hOnlineIconBig : mi->hOfflineIconBig; - } - else { - tbd.hIcon = GetCachedIcon("chat_window"); - tbd.hIconBig = g_dat.hIconChatBig; - } - tbd.hIconNot = (m_si->wState & (GC_EVENT_HIGHLIGHT | STATE_TALK)) ? GetCachedIcon("chat_overlay") : nullptr; - - switch (m_si->iType) { - case GCW_CHATROOM: - mir_snwprintf(szTemp, - (m_si->nUsersInNicklist == 1) ? TranslateT("%s: chat room (%u user)") : TranslateT("%s: chat room (%u users)"), - m_si->ptszName, m_si->nUsersInNicklist); - break; - case GCW_PRIVMESS: - mir_snwprintf(szTemp, - (m_si->nUsersInNicklist == 1) ? TranslateT("%s: message session") : TranslateT("%s: message session (%u users)"), - m_si->ptszName, m_si->nUsersInNicklist); - break; - case GCW_SERVER: - mir_snwprintf(szTemp, L"%s: Server", m_si->ptszName); - break; - } - tbd.iFlags = TBDF_TEXT | TBDF_ICON; - tbd.pszText = szTemp; - SendMessage(m_hwndParent, CM_UPDATETITLEBAR, (WPARAM)&tbd, (LPARAM)m_hwnd); - SendMessage(m_hwnd, DM_UPDATETABCONTROL, 0, 0); - break; - case GC_UPDATESTATUSBAR: { MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); @@ -1417,14 +1421,14 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case GC_SETMESSAGEHIGHLIGHT: m_si->wState |= GC_EVENT_HIGHLIGHT; SendMessage(m_hwnd, GC_FIXTABICONS, 0, 0); - SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + UpdateTitle(); if (g_Settings.bFlashWindowHighlight && GetActiveWindow() != m_hwnd && GetForegroundWindow() != m_hwndParent) SendMessage(m_hwndParent, CM_STARTFLASHING, 0, 0); break; case GC_SETTABHIGHLIGHT: SendMessage(m_hwnd, GC_FIXTABICONS, 0, 0); - SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + UpdateTitle(); if (g_Settings.bFlashWindow && GetActiveWindow() != m_hwndParent && GetForegroundWindow() != m_hwndParent) SendMessage(m_hwndParent, CM_STARTFLASHING, 0, 0); break; @@ -1538,7 +1542,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) m_nickList.SendMsg(WM_SETREDRAW, TRUE, 0); InvalidateRect(m_nickList.GetHwnd(), nullptr, FALSE); UpdateWindow(m_nickList.GetHwnd()); - SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + UpdateTitle(); break; case GC_CHANGEFILTERFLAG: diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index e131d282ca..2326d472d9 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -1061,6 +1061,49 @@ void CSrmmWindow::onChanged_Splitter(CSplitter *pSplitter) m_pParent->iSplitterY = rc.bottom - pSplitter->GetPos(); } +///////////////////////////////////////////////////////////////////////////////////////// + +static const wchar_t *titleTokenNames[] = { L"%name%", L"%status%", L"%statusmsg%", L"%account%" }; + +void CSrmmWindow::UpdateTitle() +{ + CMStringW wszTitle; + ptrW tmplt(db_get_wsa(0, SRMMMOD, SRMSGSET_WINDOWTITLE)); + if (tmplt != nullptr) + wszTitle = tmplt; + else if (g_dat.flags & SMF_STATUSICON) + wszTitle = L"%name% - "; + else + wszTitle = L"%name% (%status%) : "; + + if (m_hContact && m_szProto) { + wszTitle.Replace(L"%name%", pcli->pfnGetContactDisplayName(m_hContact, 0)); + wszTitle.Replace(L"%status%", pcli->pfnGetStatusModeDescription(db_get_w(m_hContact, m_szProto, "Status", ID_STATUS_OFFLINE), 0)); + + CMStringW tszStatus = ptrW(db_get_wsa(m_hContact, "CList", "StatusMsg")); + tszStatus.Replace(L"\r\n", L" "); + wszTitle.Replace(L"%statusmsg%", tszStatus); + + char *accModule = Proto_GetBaseAccountName(m_hContact); + if (accModule != nullptr) { + PROTOACCOUNT *proto = Proto_GetAccount(accModule); + if (proto != nullptr) + wszTitle.Replace(L"%account%", proto->tszAccountName); + } + } + + if (tmplt == nullptr) + wszTitle.Append(TranslateT("Message session")); + + TitleBarData tbd = {}; + tbd.iFlags = TBDF_TEXT | TBDF_ICON; + GetTitlebarIcon(&tbd); + tbd.pszText = wszTitle.GetBuffer(); + SendMessage(m_hwndParent, CM_UPDATETITLEBAR, (WPARAM)&tbd, (LPARAM)m_hwnd); +} + +///////////////////////////////////////////////////////////////////////////////////////// + INT_PTR CSrmmWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) { PARAFORMAT2 pf2; @@ -1142,44 +1185,30 @@ INT_PTR CSrmmWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) } break; - case DM_UPDATETABCONTROL: { + case DM_UPDATETABCONTROL: TabControlData tcd; tcd.iFlags = TCDF_TEXT | TCDF_ICON; tcd.hIcon = GetTabIcon(); tcd.pszText = pcli->pfnGetContactDisplayName(m_hContact, 0); SendMessage(m_hwndParent, CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)m_hwnd); break; - } - - case DM_UPDATETITLEBAR: - { - TitleBarData tbd = { 0 }; - tbd.iFlags = TBDF_TEXT | TBDF_ICON; - GetTitlebarIcon(&tbd); - tbd.pszText = GetWindowTitle(m_hContact, m_szProto); - SendMessage(m_hwndParent, CM_UPDATETITLEBAR, (WPARAM)&tbd, (LPARAM)m_hwnd); - mir_free(tbd.pszText); - } - break; case DM_CLISTSETTINGSCHANGED: - if (wParam == m_hContact) { - if (m_hContact && m_szProto) { - DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; - char idbuf[128], buf[128]; - GetContactUniqueId(idbuf, sizeof(idbuf)); - mir_snprintf(buf, Translate("User menu - %s"), idbuf); - SendDlgItemMessage(m_hwnd, IDC_USERMENU, BUTTONADDTOOLTIP, (WPARAM)buf, 0); - - if (cws && !mir_strcmp(cws->szModule, m_szProto) && !mir_strcmp(cws->szSetting, "Status")) - m_wStatus = cws->value.wVal; - - SetStatusIcon(); - SendMessage(m_hwnd, DM_UPDATEICON, 0, 0); - SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); - SendMessage(m_hwnd, DM_UPDATETABCONTROL, 0, 0); - ShowAvatar(); - } + if (wParam == m_hContact && m_hContact && m_szProto) { + DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; + char idbuf[128], buf[128]; + GetContactUniqueId(idbuf, sizeof(idbuf)); + mir_snprintf(buf, Translate("User menu - %s"), idbuf); + SendDlgItemMessage(m_hwnd, IDC_USERMENU, BUTTONADDTOOLTIP, (WPARAM)buf, 0); + + if (cws && !mir_strcmp(cws->szModule, m_szProto) && !mir_strcmp(cws->szSetting, "Status")) + m_wStatus = cws->value.wVal; + + SetStatusIcon(); + SendMessage(m_hwnd, DM_UPDATEICON, 0, 0); + UpdateTitle(); + SendMessage(m_hwnd, DM_UPDATETABCONTROL, 0, 0); + ShowAvatar(); } break; @@ -1244,7 +1273,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) m_log.SendMsg(EM_SETLANGOPTIONS, 0, (LPARAM)m_log.SendMsg(EM_GETLANGOPTIONS, 0, 0) & ~(IMF_AUTOKEYBOARD | IMF_AUTOFONTSIZEADJUST)); SendMessage(m_hwnd, DM_REMAKELOG, 0, 0); - SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + UpdateTitle(); SendMessage(m_hwnd, DM_UPDATETABCONTROL, 0, 0); SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); m_message.SendMsg(EM_REQUESTRESIZE, 0, 0); diff --git a/plugins/Scriver/src/msgs.h b/plugins/Scriver/src/msgs.h index 9bde19bcec..873fd5ab90 100644 --- a/plugins/Scriver/src/msgs.h +++ b/plugins/Scriver/src/msgs.h @@ -148,6 +148,7 @@ public: virtual void OnInitDialog() override; virtual void OnDestroy() override; + virtual void UpdateTitle() override; virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override; @@ -189,6 +190,7 @@ public: virtual void OnDestroy() override; virtual INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override; + virtual void UpdateTitle() override; void onChange_Message(CCtrlEdit*); diff --git a/plugins/Scriver/src/tabs.cpp b/plugins/Scriver/src/tabs.cpp index 63ece38006..dc77083ee8 100644 --- a/plugins/Scriver/src/tabs.cpp +++ b/plugins/Scriver/src/tabs.cpp @@ -33,65 +33,6 @@ static void DrawTab(ParentWindowData *dat, HWND hwnd, WPARAM wParam, LPARAM lPar ///////////////////////////////////////////////////////////////////////////////////////// -static const wchar_t *titleTokenNames[] = { L"%name%", L"%status%", L"%statusmsg%", L"%account%" }; - -wchar_t* GetWindowTitle(MCONTACT hContact, const char *szProto) -{ - ptrW tmplt; - const wchar_t* tokens[4] = { 0 }; - - CMStringW tszTemplate, tszStatus, tszTitle; - if (hContact && szProto) { - tokens[0] = pcli->pfnGetContactDisplayName(hContact, 0); - tokens[1] = pcli->pfnGetStatusModeDescription(db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE), 0); - - tszStatus = ptrW(db_get_wsa(hContact, "CList", "StatusMsg")); - tszStatus.Replace(L"\r\n", L" "); - tokens[2] = tszStatus; - - char *accModule = Proto_GetBaseAccountName(hContact); - if (accModule != nullptr) { - PROTOACCOUNT* proto = Proto_GetAccount(accModule); - if (proto != nullptr) - tokens[3] = mir_wstrdup(proto->tszAccountName); - } - - tmplt = db_get_wsa(0, SRMMMOD, SRMSGSET_WINDOWTITLE); - if (tmplt != nullptr) - tszTemplate = tmplt; - else { - if (g_dat.flags & SMF_STATUSICON) - tszTemplate = L"%name% - "; - else - tszTemplate = L"%name% (%status%) : "; - } - } - - for (const wchar_t *p = tszTemplate; *p; p++) { - if (*p == '%') { - int i; - for (i = 0; i < _countof(titleTokenNames); i++) { - size_t tnlen = mir_wstrlen(titleTokenNames[i]); - if (!wcsncmp(p, titleTokenNames[i], tnlen)) { - if (tokens[i] != nullptr) - tszTitle.Append(tokens[i]); - - p += tnlen - 1; - break; - } - } - if (i < _countof(titleTokenNames)) - continue; - } - tszTitle.AppendChar(*p); - } - - if (tmplt == nullptr) - tszTitle.Append(TranslateT("Message session")); - - return tszTitle.Detach(); -} - static int GetChildCount(ParentWindowData *dat) { return TabCtrl_GetItemCount(dat->hwndTabs); @@ -253,7 +194,7 @@ static void ActivateChild(ParentWindowData *dat, HWND child) dat->hwndActive = child; SetupStatusBar(dat); SendMessage(dat->hwndActive, GC_UPDATESTATUSBAR, 0, 0); - SendMessage(dat->hwndActive, DM_UPDATETITLEBAR, 0, 0); + pDlg->UpdateTitle(); SendMessage(dat->hwndActive, WM_SIZE, 0, 0); ShowWindow(dat->hwndActive, SW_SHOWNOACTIVATE); SendMessage(dat->hwndActive, DM_SCROLLLOGTOBOTTOM, 0, 0); diff --git a/plugins/Scriver/src/tabs.h b/plugins/Scriver/src/tabs.h index ca2e643e7c..bafb7c4518 100644 --- a/plugins/Scriver/src/tabs.h +++ b/plugins/Scriver/src/tabs.h @@ -44,7 +44,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define CM_GETTOOLBARSTATUS (WM_USER+0x1A2) /* child window services */ -#define DM_UPDATETITLEBAR (WM_USER+0x1B0) #define DM_UPDATETABCONTROL (WM_USER+0x1B2) #define DM_SETPARENT (WM_USER+0x1B3) #define DM_ACTIVATE (WM_USER+0x1B6) @@ -85,7 +84,6 @@ struct TabControlData HICON hIcon; }; -wchar_t* GetWindowTitle(MCONTACT hContact, const char *szProto); HWND GetParentWindow(MCONTACT hContact, BOOL bChat); void NotifyLocalWinEvent(MCONTACT hContact, HWND hwnd, unsigned int type); -- cgit v1.2.3