diff options
-rw-r--r-- | src/core/stdmsg/src/msgdialog.cpp | 54 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgs.cpp | 6 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgs.h | 19 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgtimedout.cpp | 5 | ||||
-rw-r--r-- | src/core/stdmsg/src/stdafx.h | 99 | ||||
-rw-r--r-- | src/core/stdmsg/src/tabs.cpp | 110 |
6 files changed, 148 insertions, 145 deletions
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 396c0aa422..c318090f74 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -33,6 +33,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define ENTERCLICKTIME 1000 //max time in ms during which a double-tap on enter will cause a send
+static int CompareDialogs(const CMsgDialog *p1, const CMsgDialog *p2)
+{
+ if (p1->GetHwnd() == p2->GetHwnd())
+ return 0;
+
+ return (p1->GetHwnd() < p2->GetHwnd()) ? -1 : 1;
+}
+
+LIST<CMsgDialog> g_arDialogs(10, CompareDialogs);
+
/////////////////////////////////////////////////////////////////////////////////////////
static void AddToFileList(wchar_t ***pppFiles, int *totalCount, const wchar_t *szFilename)
@@ -72,12 +82,21 @@ CMsgDialog::CMsgDialog(CTabbedWindow *pOwner, int iDialogId, SESSION_INFO *si) : {
m_autoClose = 0;
m_forceResizable = true;
+
+ g_arDialogs.insert(this);
+}
+
+void CMsgDialog::OnDestroy()
+{
+ g_arDialogs.remove(this);
+
+ CSuper::OnDestroy();
}
void CMsgDialog::CloseTab()
{
if (g_Settings.bTabsEnable) {
- SendMessage(GetParent(m_hwndParent), GC_REMOVETAB, 0, (LPARAM)this);
+ m_pOwner->RemoveTab(this);
Close();
}
else SendMessage(m_hwndParent, WM_CLOSE, 0, 0);
@@ -99,7 +118,7 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_TIMER:
if (wParam == TIMERID_FLASHWND) {
- m_pOwner->FixTabIcons(this);
+ FixTabIcons();
if (!g_dat.nFlashMax || m_nFlash < 2 * g_dat.nFlashMax)
FlashWindow(m_pOwner->GetHwnd(), TRUE);
m_nFlash++;
@@ -153,7 +172,7 @@ void CMsgDialog::StopFlash() ::FlashWindow(m_pOwner->GetHwnd(), FALSE);
m_nFlash = 0;
- m_pOwner->FixTabIcons(this);
+ FixTabIcons();
}
}
@@ -389,7 +408,7 @@ void CSrmmWindow::OnActivate() UpdateTitle();
UpdateLastMessage();
StopFlash();
- SendMessage(m_hwnd, DM_UPDATEWINICON, 0, 0);
+ FixTabIcons();
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -504,8 +523,8 @@ void CSrmmWindow::OnOptionsApplied(bool bUpdateAvatar) m_log.SendMsg(EM_SETPARAFORMAT, 0, (LPARAM)&pf2);
m_log.SendMsg(EM_SETLANGOPTIONS, 0, m_log.SendMsg(EM_GETLANGOPTIONS, 0, 0) & ~IMF_AUTOKEYBOARD);
- SendMessage(m_hwnd, DM_REMAKELOG, 0, 0);
- SendMessage(m_hwnd, DM_UPDATEWINICON, 0, 0);
+ RemakeLog();
+ FixTabIcons();
}
void CSrmmWindow::OnSplitterMoved(CSplitter *pSplitter)
@@ -566,6 +585,11 @@ void CSrmmWindow::NotifyTyping(int mode) CallService(MS_PROTO_SELFISTYPING, m_hContact, m_nTypeMode);
}
+void CSrmmWindow::RemakeLog()
+{
+ StreamInEvents(m_hDbEventFirst, -1, 0);
+}
+
void CSrmmWindow::ProcessFileDrop(HDROP hDrop)
{
if (m_szProto == nullptr) return;
@@ -675,7 +699,7 @@ void CSrmmWindow::UpdateIcon(WPARAM wParam) }
if (g_dat.bUseStatusWinIcon)
- SendMessage(m_hwnd, DM_UPDATEWINICON, 0, 0);
+ FixTabIcons();
}
}
@@ -1113,10 +1137,6 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) m_nTypeSecs = (INT_PTR)lParam > 0 ? (int)lParam : 0;
break;
- case DM_UPDATEWINICON:
- m_pOwner->FixTabIcons(this);
- break;
-
case DM_USERNAMETOCLIP:
if (m_hContact) {
ptrW id(Contact_GetInfo(CNF_UNIQUEID, m_hContact, m_szProto));
@@ -1190,10 +1210,6 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) }
return TRUE;
- case DM_REMAKELOG:
- StreamInEvents(m_hDbEventFirst, -1, 0);
- break;
-
case HM_DBEVENTADDED:
if (wParam == m_hContact) {
MEVENT hDbEvent = lParam;
@@ -1220,7 +1236,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) if (hDbEvent != m_hDbEventFirst && db_event_next(m_hContact, hDbEvent) == 0)
StreamInEvents(hDbEvent, 1, 1);
else
- SendMessage(m_hwnd, DM_REMAKELOG, 0, 0);
+ RemakeLog();
// Flash window *only* for messages, not for custom events
if (isMessage && !isSent) {
@@ -1242,7 +1258,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_TIMECHANGE:
PostMessage(m_hwnd, DM_NEWTIMEZONE, 0, 0);
- PostMessage(m_hwnd, DM_REMAKELOG, 0, 0);
+ RemakeLog();
break;
case WM_TIMER:
@@ -1255,12 +1271,12 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) if (m_nTypeSecs) {
m_nTypeSecs--;
if (GetForegroundWindow() == m_pOwner->GetHwnd())
- SendMessage(m_hwnd, DM_UPDATEWINICON, 0, 0);
+ FixTabIcons();
}
else {
UpdateLastMessage();
if (g_dat.bShowTypingWin)
- SendMessage(m_hwnd, DM_UPDATEWINICON, 0, 0);
+ FixTabIcons();
m_bShowTyping = false;
}
}
diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index e58a812e6b..c6995229d5 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -471,8 +471,10 @@ static int IconsChanged(WPARAM, LPARAM) LoadMsgLogIcons();
// change all the icons
- Srmm_Broadcast(DM_REMAKELOG, 0, 0);
- Srmm_Broadcast(DM_UPDATEWINICON, 0, 0);
+ for (auto &it : g_arDialogs) {
+ it->RemakeLog();
+ it->FixTabIcons();
+ }
return 0;
}
diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index ef724a153c..6f64924304 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SRMM_MSGS_H
#define SRMM_MSGS_H
-#define DM_REMAKELOG (WM_USER+11)
#define HM_DBEVENTADDED (WM_USER+12)
#define DM_CASCADENEWWINDOW (WM_USER+13)
#define DM_OPTIONSAPPLIED (WM_USER+14)
@@ -51,7 +50,7 @@ protected: CCtrlButton m_btnOk;
CTabbedWindow *m_pOwner;
DWORD m_nFlash = 0;
- char *m_szProto;
+ char *m_szProto = nullptr;
CMsgDialog(CTabbedWindow *pOwner, int idDialog, SESSION_INFO *si = nullptr);
@@ -59,11 +58,18 @@ protected: virtual void OnActivate() PURE;
+ void OnDestroy() override;
INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override;
public:
+ virtual void RemakeLog() {}
+
int GetImageId() const;
+ void __forceinline FixTabIcons()
+ { m_pOwner->FixTabIcons(this);
+ }
+
void CloseTab() override;
bool IsActive() const override;
void ScrollToBottom() override;
@@ -134,6 +140,7 @@ public: virtual int GetStatus() const { return m_wStatus; }
void LoadSettings() override {}
+ void RemakeLog() override;
void SetStatusText(const wchar_t*, HICON) override;
void UpdateTitle() override;
@@ -150,12 +157,9 @@ public: }
};
-/////////////////////////////////////////////////////////////////////////////////////////
+extern LIST<CMsgDialog> g_arDialogs;
-#define GC_ADDTAB (WM_USER+200)
-#define GC_REMOVETAB (WM_USER+201)
-#define GC_DROPPEDTAB (WM_USER+202)
-#define GC_RENAMETAB (WM_USER+203)
+/////////////////////////////////////////////////////////////////////////////////////////
class CChatRoomDlg : public CMsgDialog
{
@@ -205,7 +209,6 @@ public: void onSplitterY(CSplitter*);
};
-INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
int DbEventIsForMsgWindow(DBEVENTINFO *dbei);
int DbEventIsShown(DBEVENTINFO *dbei);
int SendMessageDirect(const wchar_t *szMsg, MCONTACT hContact);
diff --git a/src/core/stdmsg/src/msgtimedout.cpp b/src/core/stdmsg/src/msgtimedout.cpp index e121317bb5..054e15ee68 100644 --- a/src/core/stdmsg/src/msgtimedout.cpp +++ b/src/core/stdmsg/src/msgtimedout.cpp @@ -79,7 +79,10 @@ void MessageFailureProcess(TMsgQueue *item, const wchar_t *err) SendMessageCmd(item->hContact, nullptr);
hwnd = Srmm_FindWindow(hContact);
}
- else SendMessage(hwnd, DM_REMAKELOG, 0, 0);
+ else {
+ auto *pDlg = (CMsgDialog *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ pDlg->RemakeLog();
+ }
Skin_PlaySound("SendError");
diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index fcd2edc8d0..1eb52cf754 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -71,6 +71,57 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_srmm_int.h>
/////////////////////////////////////////////////////////////////////////////////////////
+// tabs.cpp
+
+class CMsgDialog;
+
+class CTabbedWindow : public CDlgBase
+{
+ void SaveWindowPosition(bool bUpdateSession);
+ void SetWindowPosition();
+
+ int oldSizeX = 0, oldSizeY = 0;
+ int iX = 0, iY = 0;
+ int iWidth = 0, iHeight = 0;
+ int m_windowWasCascaded = 0;
+ int m_statusHeight = 0;
+
+public:
+ CCtrlPages m_tab;
+ HWND m_hwndStatus = nullptr;
+ CMsgDialog *m_pEmbed = nullptr;
+
+ CTabbedWindow();
+
+ bool IsActive() const
+ {
+ return GetActiveWindow() == m_hwnd && GetForegroundWindow() == m_hwnd;
+ }
+
+ CTabbedWindow *AddPage(MCONTACT hContact, wchar_t *pwszText = nullptr, int iActivate = -1);
+ CMsgDialog *CurrPage() const;
+
+ void AddPage(SESSION_INFO*, int insertAt = -1);
+ void DropTab(int begin, int end);
+ void FixTabIcons(CMsgDialog*);
+ void RemoveTab(CMsgDialog*);
+ void SetMessageHighlight(CMsgDialog*);
+ void SetTabHighlight(CMsgDialog*);
+ void TabClicked(void);
+
+ bool OnInitDialog() override;
+ void OnDestroy() override;
+
+ INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override;
+ int Resizer(UTILRESIZECONTROL *urc) override;
+};
+
+extern CTabbedWindow *g_pTabDialog;
+
+void UninitTabs(void);
+CTabbedWindow *GetContainer();
+
+/////////////////////////////////////////////////////////////////////////////////////////
struct MODULEINFO : public GCModuleInfoBase {};
struct SESSION_INFO : public GCSessionInfoBase {};
@@ -85,7 +136,6 @@ struct LOGSTREAMDATA : public GCLogStreamDataBase {}; #define GC_SWITCHNEXTTAB (WM_USER+0x103)
#define GC_SWITCHPREVTAB (WM_USER+0x104)
-#define GC_TABCHANGE (WM_USER+0x105)
#define GC_SWITCHTAB (WM_USER+0x106)
/////////////////////////////////////////////////////////////////////////////////////////
@@ -133,51 +183,4 @@ void AddIcons(void); // tools.cpp
void SetButtonsPos(HWND hwndDlg, bool bIsChat);
-/////////////////////////////////////////////////////////////////////////////////////////
-// tabs.cpp
-
-class CTabbedWindow : public CDlgBase
-{
- void SaveWindowPosition(bool bUpdateSession);
- void SetWindowPosition();
-
- int oldSizeX = 0, oldSizeY = 0;
- int iX = 0, iY = 0;
- int iWidth = 0, iHeight = 0;
- int m_windowWasCascaded = 0;
- int m_statusHeight = 0;
-
-public:
- CCtrlPages m_tab;
- HWND m_hwndStatus = nullptr;
- CMsgDialog *m_pEmbed = nullptr;
-
- CTabbedWindow();
-
- bool IsActive() const
- {
- return GetActiveWindow() == m_hwnd && GetForegroundWindow() == m_hwnd;
- }
-
- CTabbedWindow* AddPage(MCONTACT hContact, wchar_t *pwszText = nullptr, int iActivate = -1);
- CMsgDialog* CurrPage() const;
-
- void AddPage(SESSION_INFO*, int insertAt = -1);
- void FixTabIcons(CMsgDialog*);
- void SetMessageHighlight(CMsgDialog*);
- void SetTabHighlight(CMsgDialog*);
- void TabClicked();
-
- bool OnInitDialog() override;
- void OnDestroy() override;
-
- INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override;
- int Resizer(UTILRESIZECONTROL *urc) override;
-};
-
-extern CTabbedWindow *g_pTabDialog;
-
-void UninitTabs(void);
-CTabbedWindow* GetContainer();
-
#pragma comment(lib,"comctl32.lib")
diff --git a/src/core/stdmsg/src/tabs.cpp b/src/core/stdmsg/src/tabs.cpp index d743ce5243..3ed1b72fb2 100644 --- a/src/core/stdmsg/src/tabs.cpp +++ b/src/core/stdmsg/src/tabs.cpp @@ -98,7 +98,7 @@ static LRESULT CALLBACK TabSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR ScreenToClient(hwnd, &tci.pt); int idx = TabCtrl_HitTest(hwnd, &tci); if (idx != -1 && idx != iBeginIndex) - SendMessage(GetParent(hwnd), GC_DROPPEDTAB, idx, iBeginIndex); + pOwner->DropTab(idx, iBeginIndex); } break; @@ -254,6 +254,32 @@ CMsgDialog* CTabbedWindow::CurrPage() const return (m_pEmbed != nullptr) ? m_pEmbed : (CMsgDialog*)m_tab.GetActivePage(); } +void CTabbedWindow::DropTab(int begin, int end) +{ + if (begin == end) + return; + + m_tab.SwapPages(begin, end); + + CChatRoomDlg *pDlg = (CChatRoomDlg *)m_tab.GetNthPage(end); + if (pDlg) { + FixTabIcons(pDlg); + m_tab.ActivatePage(end); + } + + // fix the "fixed" positions + int tabCount = m_tab.GetCount(); + for (int i = 0; i < tabCount; i++) { + pDlg = (CChatRoomDlg *)m_tab.GetNthPage(i); + if (pDlg == nullptr) + continue; + + SESSION_INFO *si = pDlg->m_si; + if (si && si->hContact && db_get_w(si->hContact, si->pszModule, "TabPosition", 0) != 0) + db_set_w(si->hContact, si->pszModule, "TabPosition", i + 1); + } +} + void CTabbedWindow::FixTabIcons(CMsgDialog *pDlg) { if (pDlg == nullptr) @@ -288,6 +314,22 @@ void CTabbedWindow::FixTabIcons(CMsgDialog *pDlg) } } +void CTabbedWindow::RemoveTab(CMsgDialog *pDlg) +{ + int idx = m_tab.GetDlgIndex(pDlg); + if (idx == -1) + return; + + m_tab.RemovePage(idx); + if (m_tab.GetCount() == 0) + PostMessage(m_hwnd, WM_CLOSE, 0, 0); + else { + if (m_tab.GetNthPage(idx) == nullptr) + idx--; + m_tab.ActivatePage(idx); + } +} + void CTabbedWindow::SaveWindowPosition(bool bUpdateSession) { WINDOWPLACEMENT wp = {}; @@ -400,10 +442,6 @@ INT_PTR CTabbedWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) int idx; switch (msg) { - case GC_ADDTAB: - AddPage((SESSION_INFO*)lParam); - break; - case GC_SWITCHNEXTTAB: { int total = m_tab.GetCount(); @@ -445,68 +483,6 @@ INT_PTR CTabbedWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) } break; - case GC_REMOVETAB: - idx = (lParam) ? m_tab.GetDlgIndex((CDlgBase*)lParam) : TabCtrl_GetCurSel(m_tab.GetHwnd()); - if (idx == -1) - break; - - m_tab.RemovePage(idx); - if (m_tab.GetCount() == 0) - PostMessage(m_hwnd, WM_CLOSE, 0, 0); - else { - if (m_tab.GetNthPage(idx) == nullptr) - idx--; - m_tab.ActivatePage(idx); - } - break; - - case GC_TABCHANGE: - SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)lParam); - // ScrollToBottom(); - break; - - case GC_DROPPEDTAB: - { - int begin = (int)lParam; - int end = (int)wParam; - if (begin == end) - break; - - m_tab.SwapPages(begin, end); - - CChatRoomDlg *pDlg = (CChatRoomDlg*)m_tab.GetNthPage(end); - if (pDlg) { - FixTabIcons(pDlg); - m_tab.ActivatePage(end); - } - - // fix the "fixed" positions - int tabCount = m_tab.GetCount(); - for (int i = 0; i < tabCount; i++) { - pDlg = (CChatRoomDlg*)m_tab.GetNthPage(i); - if (pDlg == nullptr) - continue; - - SESSION_INFO *si = pDlg->m_si; - if (si && si->hContact && db_get_w(si->hContact, si->pszModule, "TabPosition", 0) != 0) - db_set_w(si->hContact, si->pszModule, "TabPosition", i + 1); - } - } - break; - - case GC_RENAMETAB: - if (CChatRoomDlg *pDlg = (CChatRoomDlg*)lParam) { - idx = m_tab.GetDlgIndex(pDlg); - if (idx == -1) - break; - - TCITEM tci; - tci.mask = TCIF_TEXT; - tci.pszText = pDlg->m_si->ptszName; - TabCtrl_SetItem(m_tab.GetHwnd(), idx, &tci); - } - break; - case WM_MOVE: SaveWindowPosition(false); break; |