summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-03-09 17:28:47 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-03-09 17:28:47 +0300
commit2d737d50469b965c2787823a94757f4c9f0a7107 (patch)
tree34d46e0968485a7e9f16cbcbf9f4a18451ba06b1 /src/core
parent017f8e72ac56a88ecaea40dd1c52b1da0ae46986 (diff)
chat API:
- SESSION_INFO now addresses an instance of CChatRoomDlg instead of HWND; - linked list of sessions replaced with the usual LIST<>; - saveCI removed everywhere
Diffstat (limited to 'src/core')
-rw-r--r--src/core/stdmsg/src/chat_manager.cpp92
-rw-r--r--src/core/stdmsg/src/chat_util.cpp11
-rw-r--r--src/core/stdmsg/src/chat_window.cpp14
-rw-r--r--src/core/stdmsg/src/globals.cpp7
-rw-r--r--src/core/stdmsg/src/stdafx.h2
-rw-r--r--src/core/stdmsg/src/tabs.cpp30
6 files changed, 69 insertions, 87 deletions
diff --git a/src/core/stdmsg/src/chat_manager.cpp b/src/core/stdmsg/src/chat_manager.cpp
index 0041d3ea6f..c0e881954d 100644
--- a/src/core/stdmsg/src/chat_manager.cpp
+++ b/src/core/stdmsg/src/chat_manager.cpp
@@ -22,56 +22,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
+pfnDoTrayIcon oldDoTrayIcon;
+pfnDoPopup oldDoPopup;
+
SESSION_INFO* SM_GetPrevWindow(SESSION_INFO *si)
{
- if (!si)
- return NULL;
-
- BOOL bFound = FALSE;
- SESSION_INFO *pTemp = pci->wndList;
- while (pTemp != NULL) {
- if (si == pTemp) {
- if (bFound)
- return NULL;
- else
- bFound = TRUE;
- }
- else if (bFound == TRUE && pTemp->hWnd)
- return pTemp;
- pTemp = pTemp->next;
- if (pTemp == NULL && bFound)
- pTemp = pci->wndList;
+ int i = pci->arSessions.indexOf(si);
+ if (i == -1)
+ return nullptr;
+
+ for (i--; i >= 0; i--) {
+ SESSION_INFO *p = pci->arSessions[i];
+ if (p->pDlg)
+ return p;
}
- return NULL;
+
+ return nullptr;
}
SESSION_INFO* SM_GetNextWindow(SESSION_INFO *si)
{
- if (!si)
- return NULL;
-
- SESSION_INFO *pTemp = pci->wndList, *pLast = NULL;
- while (pTemp != NULL) {
- if (si == pTemp) {
- if (pLast) {
- if (pLast != pTemp)
- return pLast;
- else
- return NULL;
- }
- }
- if (pTemp->hWnd)
- pLast = pTemp;
- pTemp = pTemp->next;
- if (pTemp == NULL)
- pTemp = pci->wndList;
+ int i = pci->arSessions.indexOf(si);
+ if (i == -1)
+ return nullptr;
+
+ for (i++; i < pci->arSessions.getCount(); i++) {
+ SESSION_INFO *p = pci->arSessions[i];
+ if (p->pDlg)
+ return p;
}
- return NULL;
+
+ return nullptr;
}
/////////////////////////////////////////////////////////////////////////////////////////
-CHAT_MANAGER *pci, saveCI;
+CHAT_MANAGER *pci;
HMENU g_hMenu = NULL;
@@ -95,14 +81,14 @@ static void OnCreateModule(MODULEINFO *mi)
static void OnReplaceSession(SESSION_INFO *si)
{
- if (si->hWnd)
- RedrawWindow(GetDlgItem(si->hWnd, IDC_LIST), NULL, NULL, RDW_INVALIDATE);
+ if (si->pDlg)
+ RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_LIST), NULL, NULL, RDW_INVALIDATE);
}
static void OnNewUser(SESSION_INFO *si, USERINFO*)
{
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
}
static void OnFlashHighlight(SESSION_INFO *si, int bInactive)
@@ -110,10 +96,10 @@ static void OnFlashHighlight(SESSION_INFO *si, int bInactive)
if (!bInactive)
return;
- if (!g_Settings.bTabsEnable && si->hWnd && g_Settings.bFlashWindowHighlight)
- SetTimer(si->hWnd, TIMERID_FLASHWND, 900, NULL);
+ if (!g_Settings.bTabsEnable && si->pDlg && g_Settings.bFlashWindowHighlight)
+ SetTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND, 900, NULL);
if (g_Settings.bTabsEnable && si->pDlg)
- SendMessage(si->hWnd, GC_SETMESSAGEHIGHLIGHT, 0, (LPARAM)si->pDlg);
+ SendMessage(si->pDlg->GetHwnd(), GC_SETMESSAGEHIGHLIGHT, 0, (LPARAM)si->pDlg);
}
static void OnFlashWindow(SESSION_INFO *si, int bInactive)
@@ -121,23 +107,23 @@ static void OnFlashWindow(SESSION_INFO *si, int bInactive)
if (!bInactive)
return;
- if (!g_Settings.bTabsEnable && si->hWnd && g_Settings.bFlashWindow)
- SetTimer(si->hWnd, TIMERID_FLASHWND, 900, NULL);
+ if (!g_Settings.bTabsEnable && si->pDlg && g_Settings.bFlashWindow)
+ SetTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND, 900, NULL);
if (g_Settings.bTabsEnable && si->pDlg)
- SendMessage(si->hWnd, GC_SETTABHIGHLIGHT, 0, (LPARAM)si->pDlg);
+ SendMessage(si->pDlg->GetHwnd(), GC_SETTABHIGHLIGHT, 0, (LPARAM)si->pDlg);
}
static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce)
{
if (gce->pDest->iType & g_Settings.dwTrayIconFlags)
- return saveCI.DoTrayIcon(si, gce);
+ return oldDoTrayIcon(si, gce);
return TRUE;
}
static BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce)
{
if (gce->pDest->iType & g_Settings.dwPopupFlags)
- return saveCI.DoPopup(si, gce);
+ return oldDoPopup(si, gce);
return TRUE;
}
@@ -212,10 +198,8 @@ void Load_ChatModule()
CHAT_MANAGER_INITDATA data = { &g_Settings, sizeof(MODULEINFO), sizeof(SESSION_INFO), LPGENW("Chat module"), FONTMODE_SKIP };
pci = Chat_GetInterface(&data);
- saveCI = *pci;
pci->OnNewUser = OnNewUser;
-
pci->OnCreateModule = OnCreateModule;
pci->OnReplaceSession = OnReplaceSession;
@@ -224,8 +208,8 @@ void Load_ChatModule()
pci->OnFlashHighlight = OnFlashHighlight;
pci->ShowRoom = ShowRoom;
- pci->DoPopup = DoPopup;
- pci->DoTrayIcon = DoTrayIcon;
+ oldDoPopup = pci->DoPopup; pci->DoPopup = DoPopup;
+ oldDoTrayIcon = pci->DoTrayIcon; pci->DoTrayIcon = DoTrayIcon;
pci->ReloadSettings();
g_hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU));
diff --git a/src/core/stdmsg/src/chat_util.cpp b/src/core/stdmsg/src/chat_util.cpp
index 26d8f37f12..b9a44e45f6 100644
--- a/src/core/stdmsg/src/chat_util.cpp
+++ b/src/core/stdmsg/src/chat_util.cpp
@@ -171,13 +171,12 @@ bool LoadMessageFont(LOGFONT *lf, COLORREF *colour)
lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
mir_snprintf(str, "SRMFont%d", i);
- DBVARIANT dbv;
- if (db_get_ws(NULL, "SRMM", str, &dbv))
+ ptrW wszFontFace(db_get_wsa(NULL, "SRMM", str));
+ if (wszFontFace == nullptr)
mir_wstrcpy(lf->lfFaceName, L"Arial");
- else {
- mir_wstrncpy(lf->lfFaceName, dbv.ptszVal, _countof(lf->lfFaceName));
- db_free(&dbv);
- }
+ else
+ mir_wstrncpy(lf->lfFaceName, wszFontFace, _countof(lf->lfFaceName));
+
mir_snprintf(str, "SRMFont%dSet", i);
lf->lfCharSet = db_get_b(NULL, "SRMM", str, DEFAULT_CHARSET);
}
diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp
index b66912c87d..cf7cf376ac 100644
--- a/src/core/stdmsg/src/chat_window.cpp
+++ b/src/core/stdmsg/src/chat_window.cpp
@@ -819,8 +819,8 @@ static void __cdecl phase2(void * lParam)
{
SESSION_INFO *si = (SESSION_INFO*)lParam;
Sleep(30);
- if (si && si->hWnd)
- PostMessage(si->hWnd, GC_REDRAWLOG2, 0, 0);
+ if (si && si->pDlg)
+ PostMessage(si->pDlg->GetHwnd(), GC_REDRAWLOG2, 0, 0);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -881,7 +881,6 @@ CChatRoomDlg::CChatRoomDlg(SESSION_INFO *si) :
void CChatRoomDlg::OnInitDialog()
{
- m_si->hWnd = m_hwnd;
m_si->pDlg = this;
if (g_Settings.bTabsEnable)
@@ -937,8 +936,7 @@ void CChatRoomDlg::OnDestroy()
WindowList_Remove(pci->hWindowList, m_hwnd);
- m_si->pDlg = NULL;
- m_si->hWnd = NULL;
+ m_si->pDlg = nullptr;
m_si->wState &= ~STATE_TALK;
DestroyWindow(m_hwndStatus); m_hwndStatus = NULL;
@@ -1168,14 +1166,14 @@ void CChatRoomDlg::SetWindowPosition()
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->hWnd && db_get_b(NULL, CHAT_MODULE, "CascadeWindows", 1)) {
+ if (pActive && pActive->pDlg && db_get_b(NULL, 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->hWnd, &rcNew);
+ 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);
@@ -1491,7 +1489,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
switch (wParam) {
case SESSION_OFFLINE:
SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0);
- SendMessage(m_si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ SendMessage(m_si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
return TRUE;
case SESSION_ONLINE:
diff --git a/src/core/stdmsg/src/globals.cpp b/src/core/stdmsg/src/globals.cpp
index 4a42858cbb..5b2ec570f5 100644
--- a/src/core/stdmsg/src/globals.cpp
+++ b/src/core/stdmsg/src/globals.cpp
@@ -44,8 +44,11 @@ static int IconsChanged(WPARAM, LPARAM)
static int OnShutdown(WPARAM, LPARAM)
{
- for (SESSION_INFO *si = pci->wndList; si; si = si->next)
- SendMessage(si->hWnd, WM_CLOSE, 0, 0);
+ for (int i = 0; i < pci->arSessions.getCount(); i++) {
+ SESSION_INFO *si = pci->arSessions[i];
+ if (si->pDlg)
+ si->pDlg->Close();
+ }
UninitTabs();
ImageList_Destroy(hIconsList);
diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h
index 076d743dad..f15624007b 100644
--- a/src/core/stdmsg/src/stdafx.h
+++ b/src/core/stdmsg/src/stdafx.h
@@ -92,7 +92,6 @@ struct MODULEINFO : public GCModuleInfoBase
struct SESSION_INFO : public GCSessionInfoBase
{
int iX, iY;
- class CChatRoomDlg *pDlg;
};
struct LOGSTREAMDATA : public GCLogStreamDataBase {};
@@ -110,7 +109,6 @@ struct GlobalLogSettings : public GlobalLogSettingsBase
/////////////////////////////////////////////////////////////////////////////////////////
extern GlobalLogSettings g_Settings;
-extern CHAT_MANAGER saveCI;
extern HMENU g_hMenu;
extern HIMAGELIST hIconsList;
diff --git a/src/core/stdmsg/src/tabs.cpp b/src/core/stdmsg/src/tabs.cpp
index 11bc1d1e39..5a4a904096 100644
--- a/src/core/stdmsg/src/tabs.cpp
+++ b/src/core/stdmsg/src/tabs.cpp
@@ -243,7 +243,7 @@ void CTabbedWindow::TabClicked()
}
SendMessage(m_hwnd, GC_FIXTABICONS, 0, (LPARAM)pDlg);
- if (!s->hWnd) {
+ if (!s->pDlg) {
pci->ShowRoom(s);
SendMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0);
}
@@ -527,9 +527,9 @@ void ShowRoom(SESSION_INFO *si)
return;
// Do we need to create a window?
- if (si->hWnd == NULL) {
+ if (si->pDlg == nullptr) {
if (g_Settings.bTabsEnable) {
- if (pDialog == NULL) {
+ if (pDialog == nullptr) {
pDialog = new CTabbedWindow();
pDialog->Show();
}
@@ -541,22 +541,22 @@ void ShowRoom(SESSION_INFO *si)
pRoom->Show();
}
- PostMessage(si->hWnd, WM_SIZE, 0, 0);
+ PostMessage(si->pDlg->GetHwnd(), WM_SIZE, 0, 0);
if (si->iType != GCW_SERVER)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
else
- SendMessage(si->hWnd, GC_UPDATETITLE, 0, 0);
- SendMessage(si->hWnd, GC_REDRAWLOG, 0, 0);
- SendMessage(si->hWnd, GC_UPDATESTATUSBAR, 0, 0);
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATETITLE, 0, 0);
+ SendMessage(si->pDlg->GetHwnd(), GC_REDRAWLOG, 0, 0);
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATESTATUSBAR, 0, 0);
}
- SetWindowLongPtr(si->hWnd, GWL_EXSTYLE, GetWindowLongPtr(si->hWnd, GWL_EXSTYLE) | WS_EX_APPWINDOW);
+ SetWindowLongPtr(si->pDlg->GetHwnd(), GWL_EXSTYLE, GetWindowLongPtr(si->pDlg->GetHwnd(), GWL_EXSTYLE) | WS_EX_APPWINDOW);
- if (IsIconic(si->hWnd))
- ShowWindow(si->hWnd, SW_NORMAL);
- ShowWindow(si->hWnd, SW_SHOW);
- SetForegroundWindow(si->hWnd);
+ if (IsIconic(si->pDlg->GetHwnd()))
+ ShowWindow(si->pDlg->GetHwnd(), SW_NORMAL);
+ ShowWindow(si->pDlg->GetHwnd(), SW_SHOW);
+ SetForegroundWindow(si->pDlg->GetHwnd());
- SendMessage(si->hWnd, WM_MOUSEACTIVATE, 0, 0);
- SetFocus(GetDlgItem(si->hWnd, IDC_MESSAGE));
+ SendMessage(si->pDlg->GetHwnd(), WM_MOUSEACTIVATE, 0, 0);
+ SetFocus(GetDlgItem(si->pDlg->GetHwnd(), IDC_MESSAGE));
}