From 5c002a15891fc4cdfaeda7247003e13db28fc5ca Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 26 Feb 2017 16:02:07 +0300 Subject: Scriver moved to UI classes --- plugins/Scriver/src/chat/window.cpp | 1638 +++++++++++++++++------------------ 1 file changed, 818 insertions(+), 820 deletions(-) (limited to 'plugins/Scriver/src/chat/window.cpp') diff --git a/plugins/Scriver/src/chat/window.cpp b/plugins/Scriver/src/chat/window.cpp index db29862b00..bb980fc252 100644 --- a/plugins/Scriver/src/chat/window.cpp +++ b/plugins/Scriver/src/chat/window.cpp @@ -78,69 +78,6 @@ static void InitButtons(HWND hwndDlg, SESSION_INFO *si) } } -static void MessageDialogResize(HWND hwndDlg, SESSION_INFO *si, int w, int h) -{ - bool bNick = si->iType != GCW_SERVER && si->bNicklistEnabled; - bool bToolbar = SendMessage(GetParent(hwndDlg), CM_GETTOOLBARSTATUS, 0, 0) != 0; - int hSplitterMinTop = TOOLBAR_HEIGHT + si->minLogBoxHeight, hSplitterMinBottom = si->minEditBoxHeight; - int toolbarHeight = bToolbar ? TOOLBAR_HEIGHT : 0; - - si->iSplitterY = si->desiredInputAreaHeight + SPLITTER_HEIGHT + 3; - - if (h - si->iSplitterY < hSplitterMinTop) - si->iSplitterY = h - hSplitterMinTop; - if (si->iSplitterY < hSplitterMinBottom) - si->iSplitterY = hSplitterMinBottom; - - ShowWindow(GetDlgItem(hwndDlg, IDC_SPLITTERX), bNick ? SW_SHOW : SW_HIDE); - if (si->iType != GCW_SERVER) - ShowWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIST), si->bNicklistEnabled ? SW_SHOW : SW_HIDE); - else - ShowWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIST), SW_HIDE); - - if (si->iType == GCW_SERVER) { - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_SHOWNICKLIST), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_FILTER), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_CHANMGR), FALSE); - } - else { - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_SHOWNICKLIST), TRUE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_FILTER), TRUE); - if (si->iType == GCW_CHATROOM) - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_CHANMGR), pci->MM_FindModule(si->pszModule)->bChanMgr); - } - - HDWP hdwp = BeginDeferWindowPos(5); - int toolbarTopY = bToolbar ? h - si->iSplitterY - toolbarHeight : h - si->iSplitterY; - int logBottom = (si->hwndLog != NULL) ? toolbarTopY / 2 : toolbarTopY; - - hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_LOG), 0, 1, 0, bNick ? w - si->iSplitterX - 1 : w - 2, logBottom, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_CHAT_LIST), 0, w - si->iSplitterX + 2, 0, si->iSplitterX - 3, toolbarTopY, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_SPLITTERX), 0, w - si->iSplitterX, 1, 2, toolbarTopY - 1, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_SPLITTERY), 0, 0, h - si->iSplitterY, w, SPLITTER_HEIGHT, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_MESSAGE), 0, 1, h - si->iSplitterY + SPLITTER_HEIGHT, w - 2, si->iSplitterY - SPLITTER_HEIGHT - 1, SWP_NOZORDER); - EndDeferWindowPos(hdwp); - - SetButtonsPos(hwndDlg, bToolbar); - - if (si->hwndLog != NULL) { - IEVIEWWINDOW ieWindow; - ieWindow.cbSize = sizeof(IEVIEWWINDOW); - ieWindow.iType = IEW_SETPOS; - ieWindow.parent = hwndDlg; - ieWindow.hwnd = si->hwndLog; - ieWindow.x = 0; - ieWindow.y = logBottom + 1; - ieWindow.cx = bNick ? w - si->iSplitterX : w; - ieWindow.cy = logBottom; - CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); - } - else RedrawWindow(GetDlgItem(hwndDlg, IDC_LOG), NULL, NULL, RDW_INVALIDATE); - - RedrawWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIST), NULL, NULL, RDW_INVALIDATE); - RedrawWindow(GetDlgItem(hwndDlg, IDC_MESSAGE), NULL, NULL, RDW_INVALIDATE); -} - static void TabAutoComplete(HWND hwnd, MESSAGESUBDATA *dat, SESSION_INFO *si) { LRESULT lResult = (LRESULT)SendMessage(hwnd, EM_GETSEL, 0, 0); @@ -906,897 +843,953 @@ static void __cdecl phase2(void *lParam) PostMessage(si->hWnd, GC_REDRAWLOG2, 0, 0); } -static INT_PTR CALLBACK RoomWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - static HMENU hToolbarMenu; - RECT rc; - POINT pt; - HICON hIcon; - TabControlData tcd; - TitleBarData tbd; - wchar_t szTemp[512]; - - SESSION_INFO *si = (SESSION_INFO *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (!si && uMsg != WM_INITDIALOG) - return FALSE; - - switch (uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - SESSION_INFO *psi = (SESSION_INFO*)lParam; - NotifyLocalWinEvent(psi->hContact, hwndDlg, MSG_WINDOW_EVT_OPENING); - - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)psi); - si = psi; - RichUtil_SubClass(GetDlgItem(hwndDlg, IDC_MESSAGE)); - RichUtil_SubClass(GetDlgItem(hwndDlg, IDC_LOG)); - RichUtil_SubClass(GetDlgItem(hwndDlg, IDC_CHAT_LIST)); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_SPLITTERX), SplitterSubclassProc); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIST), NicklistSubclassProc); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_LOG), LogSubclassProc); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_CHAT_FILTER), ButtonSubclassProc); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_CHAT_COLOR), ButtonSubclassProc); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_CHAT_BKGCOLOR), ButtonSubclassProc); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_MESSAGE), MessageSubclassProc); - - Srmm_CreateToolbarIcons(hwndDlg, BBBF_ISCHATBUTTON); - - RECT minEditInit; - GetWindowRect(GetDlgItem(hwndDlg, IDC_MESSAGE), &minEditInit); - si->minEditBoxHeight = minEditInit.bottom - minEditInit.top; - si->minLogBoxHeight = si->minEditBoxHeight; - - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SUBCLASSED, 0, 0); - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_AUTOURLDETECT, 1, 0); - int mask = (int)SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETEVENTMASK, 0, 0); - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETEVENTMASK, 0, mask | ENM_LINK | ENM_MOUSEEVENTS); - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS | ENM_KEYEVENTS | ENM_CHANGE | ENM_REQUESTRESIZE); - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_LIMITTEXT, sizeof(wchar_t) * 0x7FFFFFFF, 0); - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETOLECALLBACK, 0, (LPARAM)&reOleCallback); - - if (db_get_b(NULL, CHAT_MODULE, "UseIEView", 0)) { - IEVIEWWINDOW ieWindow = { sizeof(ieWindow) }; - ieWindow.iType = IEW_CREATE; - ieWindow.dwMode = IEWM_CHAT; - ieWindow.parent = hwndDlg; - ieWindow.cx = 200; - ieWindow.cy = 300; - CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); - - si->hwndLog = ieWindow.hwnd; - - IEVIEWEVENT iee = { sizeof(iee) }; - iee.iType = IEE_CLEAR_LOG; - iee.hwnd = si->hwndLog; - iee.hContact = si->hContact; - iee.pszProto = si->pszModule; - CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&iee); - } +///////////////////////////////////////////////////////////////////////////////////////// - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_HIDESELECTION, TRUE, 0); +class CChatRoomDlg : public CSrmmBaseDialog +{ + SESSION_INFO *m_si; - SendMessage(hwndDlg, GC_SETWNDPROPS, 0, 0); - SendMessage(hwndDlg, GC_UPDATESTATUSBAR, 0, 0); - SendMessage(hwndDlg, DM_UPDATETITLEBAR, 0, 0); + CCtrlEdit m_message, m_log; + CCtrlListBox m_nickList; - SendMessage(GetParent(hwndDlg), CM_ADDCHILD, (WPARAM)hwndDlg, psi->hContact); - PostMessage(hwndDlg, GC_UPDATENICKLIST, 0, 0); - NotifyLocalWinEvent(psi->hContact, hwndDlg, MSG_WINDOW_EVT_OPEN); - } - break; + void MessageDialogResize(int w, int h) + { + bool bNick = m_si->iType != GCW_SERVER && m_si->bNicklistEnabled; + bool bToolbar = SendMessage(GetParent(m_hwnd), CM_GETTOOLBARSTATUS, 0, 0) != 0; + int hSplitterMinTop = TOOLBAR_HEIGHT + m_si->minLogBoxHeight, hSplitterMinBottom = m_si->minEditBoxHeight; + int toolbarHeight = bToolbar ? TOOLBAR_HEIGHT : 0; - case GC_SETWNDPROPS: - // LoadGlobalSettings(); - InitButtons(hwndDlg, si); + m_si->iSplitterY = m_si->desiredInputAreaHeight + SPLITTER_HEIGHT + 3; - SendMessage(hwndDlg, GC_UPDATESTATUSBAR, 0, 0); - SendMessage(hwndDlg, DM_UPDATETITLEBAR, 0, 0); - SendMessage(hwndDlg, GC_FIXTABICONS, 0, 0); + if (h - m_si->iSplitterY < hSplitterMinTop) + m_si->iSplitterY = h - hSplitterMinTop; + if (m_si->iSplitterY < hSplitterMinBottom) + m_si->iSplitterY = hSplitterMinBottom; - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETBKGNDCOLOR, 0, g_Settings.crLogBackground); - { - // messagebox - COLORREF crFore; - LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, NULL, &crFore); - - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwMask = CFM_COLOR | CFM_BOLD | CFM_UNDERLINE | CFM_BACKCOLOR; - cf.dwEffects = 0; - cf.crTextColor = crFore; - cf.crBackColor = db_get_dw(NULL, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETBKGNDCOLOR, 0, db_get_dw(NULL, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR)); - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_SETFONT, (WPARAM)g_Settings.MessageBoxFont, MAKELPARAM(TRUE, 0)); - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); - - // nicklist - int ih = GetTextPixelSize(L"AQG_glo'", g_Settings.UserListFont, FALSE); - int ih2 = GetTextPixelSize(L"AQG_glo'", g_Settings.UserListHeadingsFont, FALSE); - int height = db_get_b(NULL, CHAT_MODULE, "NicklistRowDist", 12); - int font = ih > ih2 ? ih : ih2; - // make sure we have space for icon! - if (db_get_b(NULL, CHAT_MODULE, "ShowContactStatus", 0)) - font = font > 16 ? font : 16; - - SendDlgItemMessage(hwndDlg, IDC_CHAT_LIST, LB_SETITEMHEIGHT, 0, height > font ? height : font); - InvalidateRect(GetDlgItem(hwndDlg, IDC_CHAT_LIST), NULL, TRUE); - } - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_REQUESTRESIZE, 0, 0); - SendMessage(hwndDlg, WM_SIZE, 0, 0); - SendMessage(hwndDlg, GC_REDRAWLOG2, 0, 0); - break; + ShowWindow(GetDlgItem(m_hwnd, IDC_SPLITTERX), bNick ? SW_SHOW : SW_HIDE); + if (m_si->iType != GCW_SERVER) + ShowWindow(GetDlgItem(m_hwnd, IDC_CHAT_LIST), m_si->bNicklistEnabled ? SW_SHOW : SW_HIDE); + else + ShowWindow(GetDlgItem(m_hwnd, IDC_CHAT_LIST), SW_HIDE); - case DM_UPDATETITLEBAR: - if (g_dat.flags & SMF_STATUSICON) { - MODULEINFO *mi = pci->MM_FindModule(si->pszModule); - tbd.hIcon = (si->wStatus == ID_STATUS_ONLINE) ? mi->hOnlineIcon : mi->hOfflineIcon; - tbd.hIconBig = (si->wStatus == ID_STATUS_ONLINE) ? mi->hOnlineIconBig : mi->hOfflineIconBig; + if (m_si->iType == GCW_SERVER) { + EnableWindow(GetDlgItem(m_hwnd, IDC_CHAT_SHOWNICKLIST), FALSE); + EnableWindow(GetDlgItem(m_hwnd, IDC_CHAT_FILTER), FALSE); + EnableWindow(GetDlgItem(m_hwnd, IDC_CHAT_CHANMGR), FALSE); } else { - tbd.hIcon = GetCachedIcon("chat_window"); - tbd.hIconBig = g_dat.hIconChatBig; + EnableWindow(GetDlgItem(m_hwnd, IDC_CHAT_SHOWNICKLIST), TRUE); + EnableWindow(GetDlgItem(m_hwnd, IDC_CHAT_FILTER), TRUE); + if (m_si->iType == GCW_CHATROOM) + EnableWindow(GetDlgItem(m_hwnd, IDC_CHAT_CHANMGR), pci->MM_FindModule(m_si->pszModule)->bChanMgr); } - tbd.hIconNot = (si->wState & (GC_EVENT_HIGHLIGHT | STATE_TALK)) ? GetCachedIcon("chat_overlay") : NULL; - switch (si->iType) { - case GCW_CHATROOM: - mir_snwprintf(szTemp, - (si->nUsersInNicklist == 1) ? TranslateT("%s: chat room (%u user)") : TranslateT("%s: chat room (%u users)"), - si->ptszName, si->nUsersInNicklist); - break; - case GCW_PRIVMESS: - mir_snwprintf(szTemp, - (si->nUsersInNicklist == 1) ? TranslateT("%s: message session") : TranslateT("%s: message session (%u users)"), - si->ptszName, si->nUsersInNicklist); - break; - case GCW_SERVER: - mir_snwprintf(szTemp, L"%s: Server", si->ptszName); - break; - } - tbd.iFlags = TBDF_TEXT | TBDF_ICON; - tbd.pszText = szTemp; - SendMessage(GetParent(hwndDlg), CM_UPDATETITLEBAR, (WPARAM)&tbd, (LPARAM)hwndDlg); - SendMessage(hwndDlg, DM_UPDATETABCONTROL, 0, 0); - break; + HDWP hdwp = BeginDeferWindowPos(5); + int toolbarTopY = bToolbar ? h - m_si->iSplitterY - toolbarHeight : h - m_si->iSplitterY; + int logBottom = (m_si->hwndIeview != NULL) ? toolbarTopY / 2 : toolbarTopY; - case GC_UPDATESTATUSBAR: - { - MODULEINFO *mi = pci->MM_FindModule(si->pszModule); - hIcon = si->wStatus == ID_STATUS_ONLINE ? mi->hOnlineIcon : mi->hOfflineIcon; - mir_snwprintf(szTemp, L"%s : %s", mi->ptszModDispName, si->ptszStatusbarText ? si->ptszStatusbarText : L""); - - StatusBarData sbd; - sbd.iItem = 0; - sbd.iFlags = SBDF_TEXT | SBDF_ICON; - sbd.hIcon = hIcon; - sbd.pszText = szTemp; - SendMessage(GetParent(hwndDlg), CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)hwndDlg); - - sbd.iItem = 1; - sbd.hIcon = NULL; - sbd.pszText = L""; - SendMessage(GetParent(hwndDlg), CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)hwndDlg); - - StatusIconData sid = { sizeof(sid) }; - sid.szModule = SRMMMOD; - Srmm_ModifyIcon(si->hContact, &sid); + hdwp = DeferWindowPos(hdwp, GetDlgItem(m_hwnd, IDC_LOG), 0, 1, 0, bNick ? w - m_si->iSplitterX - 1 : w - 2, logBottom, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, GetDlgItem(m_hwnd, IDC_CHAT_LIST), 0, w - m_si->iSplitterX + 2, 0, m_si->iSplitterX - 3, toolbarTopY, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, GetDlgItem(m_hwnd, IDC_SPLITTERX), 0, w - m_si->iSplitterX, 1, 2, toolbarTopY - 1, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, GetDlgItem(m_hwnd, IDC_SPLITTERY), 0, 0, h - m_si->iSplitterY, w, SPLITTER_HEIGHT, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, GetDlgItem(m_hwnd, IDC_MESSAGE), 0, 1, h - m_si->iSplitterY + SPLITTER_HEIGHT, w - 2, m_si->iSplitterY - SPLITTER_HEIGHT - 1, SWP_NOZORDER); + EndDeferWindowPos(hdwp); + + SetButtonsPos(m_hwnd, bToolbar); + + if (m_si->hwndIeview != NULL) { + IEVIEWWINDOW ieWindow; + ieWindow.cbSize = sizeof(IEVIEWWINDOW); + ieWindow.iType = IEW_SETPOS; + ieWindow.parent = m_hwnd; + ieWindow.hwnd = m_si->hwndIeview; + ieWindow.x = 0; + ieWindow.y = logBottom + 1; + ieWindow.cx = bNick ? w - m_si->iSplitterX : w; + ieWindow.cy = logBottom; + CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); } - break; + else RedrawWindow(GetDlgItem(m_hwnd, IDC_LOG), NULL, NULL, RDW_INVALIDATE); - case DM_SWITCHINFOBAR: - case DM_SWITCHTOOLBAR: - SendMessage(hwndDlg, WM_SIZE, 0, 0); - break; + RedrawWindow(GetDlgItem(m_hwnd, IDC_CHAT_LIST), NULL, NULL, RDW_INVALIDATE); + RedrawWindow(GetDlgItem(m_hwnd, IDC_MESSAGE), NULL, NULL, RDW_INVALIDATE); + } - case WM_SIZE: - if (wParam == SIZE_MAXIMIZED) - PostMessage(hwndDlg, GC_SCROLLTOBOTTOM, 0, 0); +public: + CChatRoomDlg(SESSION_INFO *si) + : CSrmmBaseDialog(g_hInst, IDD_CHANNEL), + m_si(si), + m_log(this, IDC_LOG), + m_message(this, IDC_MESSAGE), + m_nickList(this, IDC_CHAT_LIST) + { + m_pLog = &m_log; + m_pEntry = &m_message; + m_autoClose = 0; + } - if (IsIconic(hwndDlg)) break; + virtual void OnInitDialog() override + { + NotifyLocalWinEvent(m_si->hContact, m_hwnd, MSG_WINDOW_EVT_OPENING); + + SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)m_si); + + RichUtil_SubClass(m_message.GetHwnd()); + RichUtil_SubClass(m_log.GetHwnd()); + RichUtil_SubClass(m_nickList.GetHwnd()); + mir_subclassWindow(GetDlgItem(m_hwnd, IDC_SPLITTERX), SplitterSubclassProc); + mir_subclassWindow(m_nickList.GetHwnd(), NicklistSubclassProc); + mir_subclassWindow(m_log.GetHwnd(), LogSubclassProc); + mir_subclassWindow(GetDlgItem(m_hwnd, IDC_CHAT_FILTER), ButtonSubclassProc); + mir_subclassWindow(GetDlgItem(m_hwnd, IDC_CHAT_COLOR), ButtonSubclassProc); + mir_subclassWindow(GetDlgItem(m_hwnd, IDC_CHAT_BKGCOLOR), ButtonSubclassProc); + mir_subclassWindow(m_message.GetHwnd(), MessageSubclassProc); + + Srmm_CreateToolbarIcons(m_hwnd, BBBF_ISCHATBUTTON); + + RECT minEditInit; + GetWindowRect(m_message.GetHwnd(), &minEditInit); + m_si->minEditBoxHeight = minEditInit.bottom - minEditInit.top; + m_si->minLogBoxHeight = m_si->minEditBoxHeight; + + m_message.SendMsg(EM_SUBCLASSED, 0, 0); + m_message.SendMsg(EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS | ENM_KEYEVENTS | ENM_CHANGE | ENM_REQUESTRESIZE); + + int mask = (int)m_log.SendMsg(EM_GETEVENTMASK, 0, 0); + m_log.SendMsg(EM_SETEVENTMASK, 0, mask | ENM_LINK | ENM_MOUSEEVENTS); + m_log.SendMsg(EM_LIMITTEXT, sizeof(wchar_t) * 0x7FFFFFFF, 0); + m_log.SendMsg(EM_SETOLECALLBACK, 0, (LPARAM)&reOleCallback); + m_log.SendMsg(EM_AUTOURLDETECT, 1, 0); + + if (db_get_b(NULL, CHAT_MODULE, "UseIEView", 0)) { + IEVIEWWINDOW ieWindow = { sizeof(ieWindow) }; + ieWindow.iType = IEW_CREATE; + ieWindow.dwMode = IEWM_CHAT; + ieWindow.parent = m_hwnd; + ieWindow.cx = 200; + ieWindow.cy = 300; + CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); - if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) { - int dlgWidth, dlgHeight; - dlgWidth = LOWORD(lParam); - dlgHeight = HIWORD(lParam); - GetClientRect(hwndDlg, &rc); + m_si->hwndIeview = ieWindow.hwnd; - dlgWidth = rc.right - rc.left; - dlgHeight = rc.bottom - rc.top; - MessageDialogResize(hwndDlg, si, dlgWidth, dlgHeight); + IEVIEWEVENT iee = { sizeof(iee) }; + iee.iType = IEE_CLEAR_LOG; + iee.hwnd = m_si->hwndIeview; + iee.hContact = m_si->hContact; + iee.pszProto = m_si->pszModule; + CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&iee); } - break; - case GC_REDRAWWINDOW: - InvalidateRect(hwndDlg, NULL, TRUE); - break; + m_log.SendMsg(EM_HIDESELECTION, TRUE, 0); - case GC_REDRAWLOG: - si->LastTime = 0; - if (si->pLog) { - LOGINFO *pLog = si->pLog; - if (si->iEventCount > 60) { - int index = 0; - while (index < 59) { - if (pLog->next == NULL) - break; + SendMessage(m_hwnd, GC_SETWNDPROPS, 0, 0); + SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); + SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); - pLog = pLog->next; - if ((si->iType != GCW_CHATROOM && si->iType != GCW_PRIVMESS) || !si->bFilterEnabled || (si->iLogFilterFlags&pLog->iType) != 0) - index++; - } - Log_StreamInEvent(hwndDlg, pLog, si, TRUE); - mir_forkthread(phase2, si); - } - else Log_StreamInEvent(hwndDlg, si->pLogEnd, si, TRUE); - } - else SendMessage(hwndDlg, GC_CONTROL_MSG, WINDOW_CLEARLOG, 0); - break; - - case GC_REDRAWLOG2: - si->LastTime = 0; - if (si->pLog) - Log_StreamInEvent(hwndDlg, si->pLogEnd, si, TRUE); - break; + SendMessage(GetParent(m_hwnd), CM_ADDCHILD, (WPARAM)m_hwnd, m_si->hContact); + PostMessage(m_hwnd, GC_UPDATENICKLIST, 0, 0); + NotifyLocalWinEvent(m_si->hContact, m_hwnd, MSG_WINDOW_EVT_OPEN); + } - case GC_ADDLOG: - if (si->pLogEnd) - Log_StreamInEvent(hwndDlg, si->pLog, si, FALSE); - else - SendMessage(hwndDlg, GC_CONTROL_MSG, WINDOW_CLEARLOG, 0); - break; + virtual void OnDestroy() override + { + NotifyLocalWinEvent(m_si->hContact, m_hwnd, MSG_WINDOW_EVT_CLOSING); - case DM_UPDATETABCONTROL: - tcd.iFlags = TCDF_TEXT; - tcd.pszText = si->ptszName; - SendMessage(GetParent(hwndDlg), CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)hwndDlg); - // fall through + m_si->hWnd = NULL; + SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0); - case GC_FIXTABICONS: - if (!(si->wState & GC_EVENT_HIGHLIGHT)) { - if (si->wState & STATE_TALK) - hIcon = (si->wStatus == ID_STATUS_ONLINE) ? pci->MM_FindModule(si->pszModule)->hOnlineTalkIcon : pci->MM_FindModule(si->pszModule)->hOfflineTalkIcon; - else - hIcon = (si->wStatus == ID_STATUS_ONLINE) ? pci->MM_FindModule(si->pszModule)->hOnlineIcon : pci->MM_FindModule(si->pszModule)->hOfflineIcon; + SendMessage(GetParent(m_hwnd), CM_REMOVECHILD, 0, (LPARAM)m_hwnd); + if (m_si->hwndIeview != NULL) { + IEVIEWWINDOW ieWindow; + ieWindow.cbSize = sizeof(IEVIEWWINDOW); + ieWindow.iType = IEW_DESTROY; + ieWindow.hwnd = m_si->hwndIeview; + CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); } - else hIcon = g_dat.hMsgIcon; - tcd.iFlags = TCDF_ICON; - tcd.hIcon = hIcon; - SendMessage(GetParent(hwndDlg), CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)hwndDlg); - break; + NotifyLocalWinEvent(m_si->hContact, m_hwnd, MSG_WINDOW_EVT_CLOSE); + } - case GC_SETMESSAGEHIGHLIGHT: - si->wState |= GC_EVENT_HIGHLIGHT; - SendMessage(si->hWnd, GC_FIXTABICONS, 0, 0); - SendMessage(hwndDlg, DM_UPDATETITLEBAR, 0, 0); - if (g_Settings.bFlashWindowHighlight && GetActiveWindow() != hwndDlg && GetForegroundWindow() != GetParent(hwndDlg)) - SendMessage(GetParent(si->hWnd), CM_STARTFLASHING, 0, 0); - break; + virtual INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override + { + static HMENU hToolbarMenu; + RECT rc; + POINT pt; + HICON hIcon; + TabControlData tcd; + TitleBarData tbd; + wchar_t szTemp[512]; - case GC_SETTABHIGHLIGHT: - SendMessage(si->hWnd, GC_FIXTABICONS, 0, 0); - SendMessage(hwndDlg, DM_UPDATETITLEBAR, 0, 0); - if (g_Settings.bFlashWindow && GetActiveWindow() != GetParent(hwndDlg) && GetForegroundWindow() != GetParent(hwndDlg)) - SendMessage(GetParent(si->hWnd), CM_STARTFLASHING, 0, 0); - break; + switch (uMsg) { + case GC_SETWNDPROPS: + // LoadGlobalSettings(); + InitButtons(m_hwnd, m_si); - case DM_ACTIVATE: - if (si->wState & STATE_TALK) { - si->wState &= ~STATE_TALK; - db_set_w(si->hContact, si->pszModule, "ApparentMode", 0); - } + SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); + SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + SendMessage(m_hwnd, GC_FIXTABICONS, 0, 0); - if (si->wState & GC_EVENT_HIGHLIGHT) { - si->wState &= ~GC_EVENT_HIGHLIGHT; + m_log.SendMsg(EM_SETBKGNDCOLOR, 0, g_Settings.crLogBackground); + { + // messagebox + COLORREF crFore; + LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, NULL, &crFore); - if (pcli->pfnGetEvent(si->hContact, 0)) - pcli->pfnRemoveEvent(si->hContact, GC_FAKE_EVENT); - } + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwMask = CFM_COLOR | CFM_BOLD | CFM_UNDERLINE | CFM_BACKCOLOR; + cf.dwEffects = 0; + cf.crTextColor = crFore; + cf.crBackColor = db_get_dw(NULL, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); + m_message.SendMsg(EM_SETBKGNDCOLOR, 0, db_get_dw(NULL, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR)); + m_message.SendMsg(WM_SETFONT, (WPARAM)g_Settings.MessageBoxFont, MAKELPARAM(TRUE, 0)); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); + + // nicklist + int ih = GetTextPixelSize(L"AQG_glo'", g_Settings.UserListFont, FALSE); + int ih2 = GetTextPixelSize(L"AQG_glo'", g_Settings.UserListHeadingsFont, FALSE); + int height = db_get_b(NULL, CHAT_MODULE, "NicklistRowDist", 12); + int font = ih > ih2 ? ih : ih2; + // make sure we have space for icon! + if (db_get_b(NULL, CHAT_MODULE, "ShowContactStatus", 0)) + font = font > 16 ? font : 16; + + m_nickList.SendMsg(LB_SETITEMHEIGHT, 0, height > font ? height : font); + InvalidateRect(m_nickList.GetHwnd(), NULL, TRUE); + } + m_message.SendMsg(EM_REQUESTRESIZE, 0, 0); + SendMessage(m_hwnd, WM_SIZE, 0, 0); + SendMessage(m_hwnd, GC_REDRAWLOG2, 0, 0); + break; - SendMessage(hwndDlg, GC_FIXTABICONS, 0, 0); - if (!si->hWnd) { - ShowRoom(si); - SendMessage(hwndDlg, WM_MOUSEACTIVATE, 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") : NULL; - case WM_CTLCOLORLISTBOX: - SetBkColor((HDC)wParam, g_Settings.crUserListBGColor); - return (INT_PTR)pci->hListBkgBrush; + 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(GetParent(m_hwnd), CM_UPDATETITLEBAR, (WPARAM)&tbd, (LPARAM)m_hwnd); + SendMessage(m_hwnd, DM_UPDATETABCONTROL, 0, 0); + break; - case WM_MEASUREITEM: - if (!MeasureMenuItem(wParam, lParam)) { - MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam; - if (mis->CtlType == ODT_MENU) - return Menu_MeasureItem(lParam); + case GC_UPDATESTATUSBAR: + { + MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); + hIcon = m_si->wStatus == ID_STATUS_ONLINE ? mi->hOnlineIcon : mi->hOfflineIcon; + mir_snwprintf(szTemp, L"%s : %s", mi->ptszModDispName, m_si->ptszStatusbarText ? m_si->ptszStatusbarText : L""); + + StatusBarData sbd; + sbd.iItem = 0; + sbd.iFlags = SBDF_TEXT | SBDF_ICON; + sbd.hIcon = hIcon; + sbd.pszText = szTemp; + SendMessage(GetParent(m_hwnd), CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)m_hwnd); + + sbd.iItem = 1; + sbd.hIcon = NULL; + sbd.pszText = L""; + SendMessage(GetParent(m_hwnd), CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)m_hwnd); + + StatusIconData sid = { sizeof(sid) }; + sid.szModule = SRMMMOD; + Srmm_ModifyIcon(m_si->hContact, &sid); + } + break; - int ih = GetTextPixelSize(L"AQGgl'", g_Settings.UserListFont, FALSE); - int ih2 = GetTextPixelSize(L"AQGg'", g_Settings.UserListHeadingsFont, FALSE); - int font = ih > ih2 ? ih : ih2; - int height = db_get_b(NULL, CHAT_MODULE, "NicklistRowDist", 12); - // make sure we have space for icon! - if (db_get_b(NULL, CHAT_MODULE, "ShowContactStatus", 0)) - font = font > 16 ? font : 16; - mis->itemHeight = height > font ? height : font; - } - return TRUE; + case DM_SWITCHINFOBAR: + case DM_SWITCHTOOLBAR: + SendMessage(m_hwnd, WM_SIZE, 0, 0); + break; - case WM_DRAWITEM: - if (!DrawMenuItem(wParam, lParam)) { - DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; - if (dis->CtlType == ODT_MENU) - return Menu_DrawItem(lParam); + case WM_SIZE: + if (wParam == SIZE_MAXIMIZED) + PostMessage(m_hwnd, GC_SCROLLTOBOTTOM, 0, 0); - if (dis->CtlID == IDC_CHAT_LIST) { - int index = dis->itemID; - USERINFO *ui = pci->SM_GetUserFromIndex(si->ptszID, si->pszModule, index); - if (ui) { - int x_offset = 2; - - int height = dis->rcItem.bottom - dis->rcItem.top; - if (height & 1) - height++; - - int offset = (height == 10) ? 0 : height / 2 - 5; - HFONT hFont = (ui->iStatusEx == 0) ? g_Settings.UserListFont : g_Settings.UserListHeadingsFont; - HFONT hOldFont = (HFONT)SelectObject(dis->hDC, hFont); - SetBkMode(dis->hDC, TRANSPARENT); - - if (dis->itemAction == ODA_FOCUS && dis->itemState & ODS_SELECTED) - FillRect(dis->hDC, &dis->rcItem, pci->hListSelectedBkgBrush); - else //if (dis->itemState & ODS_INACTIVE) - FillRect(dis->hDC, &dis->rcItem, pci->hListBkgBrush); - - if (g_Settings.bShowContactStatus && g_Settings.bContactStatusFirst && ui->ContactStatus) { - hIcon = Skin_LoadProtoIcon(si->pszModule, ui->ContactStatus); - DrawIconEx(dis->hDC, x_offset, dis->rcItem.top + offset - 3, hIcon, 16, 16, 0, NULL, DI_NORMAL); - IcoLib_ReleaseIcon(hIcon); - x_offset += 18; - } - DrawIconEx(dis->hDC, x_offset, dis->rcItem.top + offset, pci->SM_GetStatusIcon(si, ui), 10, 10, 0, NULL, DI_NORMAL); - x_offset += 12; - if (g_Settings.bShowContactStatus && !g_Settings.bContactStatusFirst && ui->ContactStatus) { - hIcon = Skin_LoadProtoIcon(si->pszModule, ui->ContactStatus); - DrawIconEx(dis->hDC, x_offset, dis->rcItem.top + offset - 3, hIcon, 16, 16, 0, NULL, DI_NORMAL); - IcoLib_ReleaseIcon(hIcon); - x_offset += 18; - } + if (IsIconic(m_hwnd)) break; - SetTextColor(dis->hDC, ui->iStatusEx == 0 ? g_Settings.crUserListColor : g_Settings.crUserListHeadingsColor); - TextOut(dis->hDC, dis->rcItem.left + x_offset, dis->rcItem.top, ui->pszNick, (int)mir_wstrlen(ui->pszNick)); - SelectObject(dis->hDC, hOldFont); - } - return TRUE; + if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) { + GetClientRect(m_hwnd, &rc); + MessageDialogResize(rc.right - rc.left, rc.bottom - rc.top); } - } - break; + break; - case GC_UPDATENICKLIST: - SendDlgItemMessage(hwndDlg, IDC_CHAT_LIST, WM_SETREDRAW, FALSE, 0); - SendDlgItemMessage(hwndDlg, IDC_CHAT_LIST, LB_RESETCONTENT, 0, 0); - for (int index = 0; index < si->nUsersInNicklist; index++) { - USERINFO *ui = pci->SM_GetUserFromIndex(si->ptszID, si->pszModule, index); - if (ui) { - char szIndicator = SM_GetStatusIndicator(si, ui); - if (szIndicator > '\0') { - static wchar_t ptszBuf[128]; - mir_snwprintf(ptszBuf, L"%c%s", szIndicator, ui->pszNick); - SendDlgItemMessage(hwndDlg, IDC_CHAT_LIST, LB_ADDSTRING, 0, (LPARAM)ptszBuf); + case GC_REDRAWWINDOW: + InvalidateRect(m_hwnd, NULL, TRUE); + break; + + case GC_REDRAWLOG: + m_si->LastTime = 0; + if (m_si->pLog) { + LOGINFO *pLog = m_si->pLog; + if (m_si->iEventCount > 60) { + int index = 0; + while (index < 59) { + if (pLog->next == NULL) + break; + + pLog = pLog->next; + if ((m_si->iType != GCW_CHATROOM && m_si->iType != GCW_PRIVMESS) || !m_si->bFilterEnabled || (m_si->iLogFilterFlags&pLog->iType) != 0) + index++; + } + Log_StreamInEvent(m_hwnd, pLog, m_si, TRUE); + mir_forkthread(phase2, m_si); } - else SendDlgItemMessage(hwndDlg, IDC_CHAT_LIST, LB_ADDSTRING, 0, (LPARAM)ui->pszNick); + else Log_StreamInEvent(m_hwnd, m_si->pLogEnd, m_si, TRUE); } - } - SendDlgItemMessage(hwndDlg, IDC_CHAT_LIST, WM_SETREDRAW, TRUE, 0); - InvalidateRect(GetDlgItem(hwndDlg, IDC_CHAT_LIST), NULL, FALSE); - UpdateWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIST)); - SendMessage(hwndDlg, DM_UPDATETITLEBAR, 0, 0); - break; + else SendMessage(m_hwnd, GC_CONTROL_MSG, WINDOW_CLEARLOG, 0); + break; - case GC_CONTROL_MSG: - switch (wParam) { - case SESSION_OFFLINE: - SendMessage(hwndDlg, GC_UPDATESTATUSBAR, 0, 0); - SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0); - return TRUE; + case GC_REDRAWLOG2: + m_si->LastTime = 0; + if (m_si->pLog) + Log_StreamInEvent(m_hwnd, m_si->pLogEnd, m_si, TRUE); + break; - case SESSION_ONLINE: - SendMessage(hwndDlg, GC_UPDATESTATUSBAR, 0, 0); - return TRUE; + case GC_ADDLOG: + if (m_si->pLogEnd) + Log_StreamInEvent(m_hwnd, m_si->pLog, m_si, FALSE); + else + SendMessage(m_hwnd, GC_CONTROL_MSG, WINDOW_CLEARLOG, 0); + break; - case WINDOW_HIDDEN: - SendMessage(hwndDlg, GC_CLOSEWINDOW, 0, 0); - return TRUE; + case DM_UPDATETABCONTROL: + tcd.iFlags = TCDF_TEXT; + tcd.pszText = m_si->ptszName; + SendMessage(GetParent(m_hwnd), CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)m_hwnd); + // fall through - case WINDOW_CLEARLOG: - SetDlgItemText(hwndDlg, IDC_LOG, L""); - return TRUE; + case GC_FIXTABICONS: + if (!(m_si->wState & GC_EVENT_HIGHLIGHT)) { + if (m_si->wState & STATE_TALK) + hIcon = (m_si->wStatus == ID_STATUS_ONLINE) ? pci->MM_FindModule(m_si->pszModule)->hOnlineTalkIcon : pci->MM_FindModule(m_si->pszModule)->hOfflineTalkIcon; + else + hIcon = (m_si->wStatus == ID_STATUS_ONLINE) ? pci->MM_FindModule(m_si->pszModule)->hOnlineIcon : pci->MM_FindModule(m_si->pszModule)->hOfflineIcon; + } + else hIcon = g_dat.hMsgIcon; - case SESSION_TERMINATE: - if (pcli->pfnGetEvent(si->hContact, 0)) - pcli->pfnRemoveEvent(si->hContact, GC_FAKE_EVENT); - si->wState &= ~STATE_TALK; - db_set_w(si->hContact, si->pszModule, "ApparentMode", 0); - SendMessage(hwndDlg, GC_CLOSEWINDOW, 0, 0); - return TRUE; + tcd.iFlags = TCDF_ICON; + tcd.hIcon = hIcon; + SendMessage(GetParent(m_hwnd), CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)m_hwnd); + break; - case WINDOW_MINIMIZE: - ShowWindow(hwndDlg, SW_MINIMIZE); - goto LABEL_SHOWWINDOW; + case GC_SETMESSAGEHIGHLIGHT: + m_si->wState |= GC_EVENT_HIGHLIGHT; + SendMessage(m_si->hWnd, GC_FIXTABICONS, 0, 0); + SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + if (g_Settings.bFlashWindowHighlight && GetActiveWindow() != m_hwnd && GetForegroundWindow() != GetParent(m_hwnd)) + SendMessage(GetParent(m_si->hWnd), CM_STARTFLASHING, 0, 0); + break; - case WINDOW_MAXIMIZE: - ShowWindow(hwndDlg, SW_MAXIMIZE); - goto LABEL_SHOWWINDOW; + case GC_SETTABHIGHLIGHT: + SendMessage(m_si->hWnd, GC_FIXTABICONS, 0, 0); + SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); + if (g_Settings.bFlashWindow && GetActiveWindow() != GetParent(m_hwnd) && GetForegroundWindow() != GetParent(m_hwnd)) + SendMessage(GetParent(m_si->hWnd), CM_STARTFLASHING, 0, 0); + break; - case SESSION_INITDONE: - if (db_get_b(NULL, CHAT_MODULE, "PopupOnJoin", 0) != 0) - return TRUE; - // fall through - case WINDOW_VISIBLE: - if (IsIconic(hwndDlg)) - ShowWindow(hwndDlg, SW_NORMAL); -LABEL_SHOWWINDOW: - SendMessage(hwndDlg, WM_SIZE, 0, 0); - SendMessage(hwndDlg, GC_REDRAWLOG, 0, 0); - SendMessage(hwndDlg, GC_UPDATENICKLIST, 0, 0); - SendMessage(hwndDlg, GC_UPDATESTATUSBAR, 0, 0); - ShowWindow(hwndDlg, SW_SHOW); - SendMessage(hwndDlg, WM_SIZE, 0, 0); - SetForegroundWindow(hwndDlg); - return TRUE; - } - break; + case DM_ACTIVATE: + if (m_si->wState & STATE_TALK) { + m_si->wState &= ~STATE_TALK; + db_set_w(m_si->hContact, m_si->pszModule, "ApparentMode", 0); + } - case GC_SPLITTERMOVED: - if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SPLITTERX)) { - GetClientRect(hwndDlg, &rc); - pt.x = wParam; pt.y = 0; - ScreenToClient(hwndDlg, &pt); - - si->iSplitterX = rc.right - pt.x + 1; - if (si->iSplitterX < 35) - si->iSplitterX = 35; - if (si->iSplitterX > rc.right - rc.left - 35) - si->iSplitterX = rc.right - rc.left - 35; - g_Settings.iSplitterX = si->iSplitterX; - } - else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SPLITTERY)) { - GetClientRect(hwndDlg, &rc); - pt.x = 0; pt.y = wParam; - ScreenToClient(hwndDlg, &pt); - si->iSplitterY = rc.bottom - pt.y; - g_Settings.iSplitterY = si->iSplitterY; - } - PostMessage(hwndDlg, WM_SIZE, 0, 0); - break; + if (m_si->wState & GC_EVENT_HIGHLIGHT) { + m_si->wState &= ~GC_EVENT_HIGHLIGHT; - case GC_FIREHOOK: - if (lParam) { - NotifyEventHooks(pci->hSendEvent, 0, lParam); - GCHOOK *gch = (GCHOOK*)lParam; - if (gch->pDest) { - mir_free((void*)gch->pDest->ptszID); - mir_free((void*)gch->pDest->pszModule); - mir_free(gch->pDest); + if (pcli->pfnGetEvent(m_si->hContact, 0)) + pcli->pfnRemoveEvent(m_si->hContact, GC_FAKE_EVENT); } - mir_free(gch->ptszText); - mir_free(gch->ptszUID); - mir_free(gch->ptszNick); - mir_free(gch); - } - break; - case GC_CHANGEFILTERFLAG: - si->iLogFilterFlags = lParam; - break; + SendMessage(m_hwnd, GC_FIXTABICONS, 0, 0); + if (!m_si->hWnd) { + ShowRoom(m_si); + SendMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); + } + break; - case GC_SHOWFILTERMENU: - { - HWND hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_FILTER), hwndDlg, FilterWndProc, (LPARAM)si); - TranslateDialogDefault(hwnd); - GetWindowRect(GetDlgItem(hwndDlg, IDC_CHAT_FILTER), &rc); - SetWindowPos(hwnd, HWND_TOP, rc.left - 85, (IsWindowVisible(GetDlgItem(hwndDlg, IDC_CHAT_FILTER)) || IsWindowVisible(GetDlgItem(hwndDlg, IDC_CHAT_BOLD))) ? rc.top - 206 : rc.top - 186, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); - } - break; + case WM_CTLCOLORLISTBOX: + SetBkColor((HDC)wParam, g_Settings.crUserListBGColor); + return (INT_PTR)pci->hListBkgBrush; + + case WM_MEASUREITEM: + if (!MeasureMenuItem(wParam, lParam)) { + MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam; + if (mis->CtlType == ODT_MENU) + return Menu_MeasureItem(lParam); + + int ih = GetTextPixelSize(L"AQGgl'", g_Settings.UserListFont, FALSE); + int ih2 = GetTextPixelSize(L"AQGg'", g_Settings.UserListHeadingsFont, FALSE); + int font = ih > ih2 ? ih : ih2; + int height = db_get_b(NULL, CHAT_MODULE, "NicklistRowDist", 12); + // make sure we have space for icon! + if (db_get_b(NULL, CHAT_MODULE, "ShowContactStatus", 0)) + font = font > 16 ? font : 16; + mis->itemHeight = height > font ? height : font; + } + return TRUE; - case GC_SHOWCOLORCHOOSER: - pci->ColorChooser(si, lParam == IDC_CHAT_COLOR, hwndDlg, GetDlgItem(hwndDlg, IDC_MESSAGE), GetDlgItem(hwndDlg, lParam)); - break; + case WM_DRAWITEM: + if (!DrawMenuItem(wParam, lParam)) { + DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; + if (dis->CtlType == ODT_MENU) + return Menu_DrawItem(lParam); + + if (dis->CtlID == IDC_CHAT_LIST) { + int index = dis->itemID; + USERINFO *ui = pci->SM_GetUserFromIndex(m_si->ptszID, m_si->pszModule, index); + if (ui) { + int x_offset = 2; + + int height = dis->rcItem.bottom - dis->rcItem.top; + if (height & 1) + height++; + + int offset = (height == 10) ? 0 : height / 2 - 5; + HFONT hFont = (ui->iStatusEx == 0) ? g_Settings.UserListFont : g_Settings.UserListHeadingsFont; + HFONT hOldFont = (HFONT)SelectObject(dis->hDC, hFont); + SetBkMode(dis->hDC, TRANSPARENT); + + if (dis->itemAction == ODA_FOCUS && dis->itemState & ODS_SELECTED) + FillRect(dis->hDC, &dis->rcItem, pci->hListSelectedBkgBrush); + else //if (dis->itemState & ODS_INACTIVE) + FillRect(dis->hDC, &dis->rcItem, pci->hListBkgBrush); + + if (g_Settings.bShowContactStatus && g_Settings.bContactStatusFirst && ui->ContactStatus) { + hIcon = Skin_LoadProtoIcon(m_si->pszModule, ui->ContactStatus); + DrawIconEx(dis->hDC, x_offset, dis->rcItem.top + offset - 3, hIcon, 16, 16, 0, NULL, DI_NORMAL); + IcoLib_ReleaseIcon(hIcon); + x_offset += 18; + } + DrawIconEx(dis->hDC, x_offset, dis->rcItem.top + offset, pci->SM_GetStatusIcon(m_si, ui), 10, 10, 0, NULL, DI_NORMAL); + x_offset += 12; + if (g_Settings.bShowContactStatus && !g_Settings.bContactStatusFirst && ui->ContactStatus) { + hIcon = Skin_LoadProtoIcon(m_si->pszModule, ui->ContactStatus); + DrawIconEx(dis->hDC, x_offset, dis->rcItem.top + offset - 3, hIcon, 16, 16, 0, NULL, DI_NORMAL); + IcoLib_ReleaseIcon(hIcon); + x_offset += 18; + } - case GC_SCROLLTOBOTTOM: - if ((GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_STYLE) & WS_VSCROLL) != 0) { - SCROLLINFO sci = { 0 }; - sci.cbSize = sizeof(sci); - sci.fMask = SIF_PAGE | SIF_RANGE; - GetScrollInfo(GetDlgItem(hwndDlg, IDC_LOG), SB_VERT, &sci); - - sci.fMask = SIF_POS; - sci.nPos = sci.nMax - sci.nPage + 1; - SetScrollInfo(GetDlgItem(hwndDlg, IDC_LOG), SB_VERT, &sci, TRUE); - - CHARRANGE sel; - sel.cpMin = sel.cpMax = GetRichTextLength(GetDlgItem(hwndDlg, IDC_LOG), CP_ACP, FALSE); - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_EXSETSEL, 0, (LPARAM)&sel); - PostMessage(GetDlgItem(hwndDlg, IDC_LOG), WM_VSCROLL, MAKEWPARAM(SB_BOTTOM, 0), 0); - } - break; + SetTextColor(dis->hDC, ui->iStatusEx == 0 ? g_Settings.crUserListColor : g_Settings.crUserListHeadingsColor); + TextOut(dis->hDC, dis->rcItem.left + x_offset, dis->rcItem.top, ui->pszNick, (int)mir_wstrlen(ui->pszNick)); + SelectObject(dis->hDC, hOldFont); + } + return TRUE; + } + } + break; - case WM_ACTIVATE: - if (LOWORD(wParam) != WA_ACTIVE) + case GC_UPDATENICKLIST: + m_nickList.SendMsg(WM_SETREDRAW, FALSE, 0); + m_nickList.SendMsg(LB_RESETCONTENT, 0, 0); + for (int index = 0; index < m_si->nUsersInNicklist; index++) { + USERINFO *ui = pci->SM_GetUserFromIndex(m_si->ptszID, m_si->pszModule, index); + if (ui) { + char szIndicator = SM_GetStatusIndicator(m_si, ui); + if (szIndicator > '\0') { + static wchar_t ptszBuf[128]; + mir_snwprintf(ptszBuf, L"%c%s", szIndicator, ui->pszNick); + m_nickList.SendMsg(LB_ADDSTRING, 0, (LPARAM)ptszBuf); + } + else m_nickList.SendMsg(LB_ADDSTRING, 0, (LPARAM)ui->pszNick); + } + } + m_nickList.SendMsg(WM_SETREDRAW, TRUE, 0); + InvalidateRect(m_nickList.GetHwnd(), NULL, FALSE); + UpdateWindow(m_nickList.GetHwnd()); + SendMessage(m_hwnd, DM_UPDATETITLEBAR, 0, 0); break; - //fall through - case WM_MOUSEACTIVATE: - if (uMsg != WM_ACTIVATE) - SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); + case GC_CONTROL_MSG: + switch (wParam) { + case SESSION_OFFLINE: + SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); + SendMessage(m_si->hWnd, GC_UPDATENICKLIST, 0, 0); + return TRUE; - pci->SetActiveSession(si->ptszID, si->pszModule); + case SESSION_ONLINE: + SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); + return TRUE; - if (db_get_w(si->hContact, si->pszModule, "ApparentMode", 0) != 0) - db_set_w(si->hContact, si->pszModule, "ApparentMode", 0); - if (pcli->pfnGetEvent(si->hContact, 0)) - pcli->pfnRemoveEvent(si->hContact, GC_FAKE_EVENT); - break; + case WINDOW_HIDDEN: + SendMessage(m_hwnd, GC_CLOSEWINDOW, 0, 0); + return TRUE; - case WM_NOTIFY: - { - LPNMHDR pNmhdr = (LPNMHDR)lParam; - switch (pNmhdr->code) { - case EN_REQUESTRESIZE: - if (pNmhdr->idFrom == IDC_MESSAGE) { - REQRESIZE *rr = (REQRESIZE *)lParam; - int height = rr->rc.bottom - rr->rc.top + 1; - if (height < g_dat.minInputAreaHeight) - height = g_dat.minInputAreaHeight; - - if (si->desiredInputAreaHeight != height) { - si->desiredInputAreaHeight = height; - SendMessage(hwndDlg, WM_SIZE, 0, 0); - PostMessage(hwndDlg, GC_SCROLLTOBOTTOM, 0, 0); - } - } - break; + case WINDOW_CLEARLOG: + m_log.SetText(L""); + return TRUE; - case EN_MSGFILTER: - if (pNmhdr->idFrom == IDC_LOG && ((MSGFILTER *)lParam)->msg == WM_RBUTTONUP) { - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); + case SESSION_TERMINATE: + if (pcli->pfnGetEvent(m_si->hContact, 0)) + pcli->pfnRemoveEvent(m_si->hContact, GC_FAKE_EVENT); + m_si->wState &= ~STATE_TALK; + db_set_w(m_si->hContact, m_si->pszModule, "ApparentMode", 0); + SendMessage(m_hwnd, GC_CLOSEWINDOW, 0, 0); + return TRUE; + + case WINDOW_MINIMIZE: + ShowWindow(m_hwnd, SW_MINIMIZE); + goto LABEL_SHOWWINDOW; + + case WINDOW_MAXIMIZE: + ShowWindow(m_hwnd, SW_MAXIMIZE); + goto LABEL_SHOWWINDOW; + + case SESSION_INITDONE: + if (db_get_b(NULL, CHAT_MODULE, "PopupOnJoin", 0) != 0) return TRUE; - } - break; + // fall through + case WINDOW_VISIBLE: + if (IsIconic(m_hwnd)) + ShowWindow(m_hwnd, SW_NORMAL); + LABEL_SHOWWINDOW: + SendMessage(m_hwnd, WM_SIZE, 0, 0); + SendMessage(m_hwnd, GC_REDRAWLOG, 0, 0); + SendMessage(m_hwnd, GC_UPDATENICKLIST, 0, 0); + SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); + ShowWindow(m_hwnd, SW_SHOW); + SendMessage(m_hwnd, WM_SIZE, 0, 0); + SetForegroundWindow(m_hwnd); + return TRUE; + } + break; - case EN_LINK: - if (pNmhdr->idFrom == IDC_LOG) { - switch (((ENLINK *)lParam)->msg) { - case WM_RBUTTONDOWN: - case WM_LBUTTONUP: - case WM_LBUTTONDBLCLK: - if (HandleLinkClick(g_hInst, hwndDlg, GetDlgItem(hwndDlg, IDC_MESSAGE), (ENLINK*)lParam)) { - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); - return TRUE; - } - break; - } - } - break; + case GC_SPLITTERMOVED: + if ((HWND)lParam == GetDlgItem(m_hwnd, IDC_SPLITTERX)) { + GetClientRect(m_hwnd, &rc); + pt.x = wParam; pt.y = 0; + ScreenToClient(m_hwnd, &pt); + + m_si->iSplitterX = rc.right - pt.x + 1; + if (m_si->iSplitterX < 35) + m_si->iSplitterX = 35; + if (m_si->iSplitterX > rc.right - rc.left - 35) + m_si->iSplitterX = rc.right - rc.left - 35; + g_Settings.iSplitterX = m_si->iSplitterX; + } + else if ((HWND)lParam == GetDlgItem(m_hwnd, IDC_SPLITTERY)) { + GetClientRect(m_hwnd, &rc); + pt.x = 0; pt.y = wParam; + ScreenToClient(m_hwnd, &pt); + m_si->iSplitterY = rc.bottom - pt.y; + g_Settings.iSplitterY = m_si->iSplitterY; + } + PostMessage(m_hwnd, WM_SIZE, 0, 0); + break; - case TTN_NEEDTEXT: - if (pNmhdr->idFrom == (UINT_PTR)GetDlgItem(hwndDlg, IDC_CHAT_LIST)) { - LPNMTTDISPINFO lpttd = (LPNMTTDISPINFO)lParam; - SESSION_INFO* parentdat = (SESSION_INFO*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - POINT p; - GetCursorPos(&p); - ScreenToClient(GetDlgItem(hwndDlg, IDC_CHAT_LIST), &p); - int item = LOWORD(SendDlgItemMessage(hwndDlg, IDC_CHAT_LIST, LB_ITEMFROMPOINT, 0, MAKELPARAM(p.x, p.y))); - USERINFO *ui = pci->SM_GetUserFromIndex(parentdat->ptszID, parentdat->pszModule, item); - if (ui != NULL) { - static wchar_t ptszBuf[1024]; - mir_snwprintf(ptszBuf, L"%s: %s\r\n%s: %s\r\n%s: %s", - TranslateT("Nickname"), ui->pszNick, - TranslateT("Unique ID"), ui->pszUID, - TranslateT("Status"), pci->TM_WordToString(parentdat->pStatuses, ui->Status)); - lpttd->lpszText = ptszBuf; - } + case GC_FIREHOOK: + if (lParam) { + NotifyEventHooks(pci->hSendEvent, 0, lParam); + GCHOOK *gch = (GCHOOK*)lParam; + if (gch->pDest) { + mir_free((void*)gch->pDest->ptszID); + mir_free((void*)gch->pDest->pszModule); + mir_free(gch->pDest); } - break; + mir_free(gch->ptszText); + mir_free(gch->ptszUID); + mir_free(gch->ptszNick); + mir_free(gch); } - } - break; + break; - case WM_COMMAND: - if (!lParam && Clist_MenuProcessCommand(LOWORD(wParam), MPCF_CONTACTMENU, si->hContact)) + case GC_CHANGEFILTERFLAG: + m_si->iLogFilterFlags = lParam; break; - if (HIWORD(wParam) == BN_CLICKED) - if (LOWORD(wParam) >= MIN_CBUTTONID && LOWORD(wParam) <= MAX_CBUTTONID) { - Srmm_ClickToolbarIcon(si->hContact, LOWORD(wParam), GetDlgItem(hwndDlg, LOWORD(wParam)), 0); - break; + case GC_SHOWFILTERMENU: + { + HWND hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_FILTER), m_hwnd, FilterWndProc, (LPARAM)m_si); + TranslateDialogDefault(hwnd); + GetWindowRect(GetDlgItem(m_hwnd, IDC_CHAT_FILTER), &rc); + SetWindowPos(hwnd, HWND_TOP, rc.left - 85, (IsWindowVisible(GetDlgItem(m_hwnd, IDC_CHAT_FILTER)) || IsWindowVisible(GetDlgItem(m_hwnd, IDC_CHAT_BOLD))) ? rc.top - 206 : rc.top - 186, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); } + break; - switch (LOWORD(wParam)) { - case IDC_CHAT_LIST: - if (HIWORD(wParam) == LBN_DBLCLK) { - TVHITTESTINFO hti; - hti.pt.x = (short)LOWORD(GetMessagePos()); - hti.pt.y = (short)HIWORD(GetMessagePos()); - ScreenToClient(GetDlgItem(hwndDlg, IDC_CHAT_LIST), &hti.pt); + case GC_SHOWCOLORCHOOSER: + pci->ColorChooser(m_si, lParam == IDC_CHAT_COLOR, m_hwnd, m_message.GetHwnd(), GetDlgItem(m_hwnd, lParam)); + break; - int item = LOWORD(SendDlgItemMessage(hwndDlg, IDC_CHAT_LIST, LB_ITEMFROMPOINT, 0, MAKELPARAM(hti.pt.x, hti.pt.y))); - USERINFO *ui = pci->SM_GetUserFromIndex(si->ptszID, si->pszModule, item); - if (ui) { - if (GetKeyState(VK_SHIFT) & 0x8000) { - LRESULT lResult = (LRESULT)SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_GETSEL, 0, 0); - int start = LOWORD(lResult); - size_t dwNameLenMax = (mir_wstrlen(ui->pszUID) + 4); - wchar_t* pszName = (wchar_t*)alloca(sizeof(wchar_t) * dwNameLenMax); - if (start == 0) - mir_snwprintf(pszName, dwNameLenMax, L"%s: ", ui->pszUID); - else - mir_snwprintf(pszName, dwNameLenMax, L"%s ", ui->pszUID); + case GC_SCROLLTOBOTTOM: + if ((GetWindowLongPtr(m_log.GetHwnd(), GWL_STYLE) & WS_VSCROLL) != 0) { + SCROLLINFO sci = { 0 }; + sci.cbSize = sizeof(sci); + sci.fMask = SIF_PAGE | SIF_RANGE; + GetScrollInfo(m_log.GetHwnd(), SB_VERT, &sci); + + sci.fMask = SIF_POS; + sci.nPos = sci.nMax - sci.nPage + 1; + SetScrollInfo(m_log.GetHwnd(), SB_VERT, &sci, TRUE); + + CHARRANGE sel; + sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE); + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); + PostMessage(m_log.GetHwnd(), WM_VSCROLL, MAKEWPARAM(SB_BOTTOM, 0), 0); + } + break; - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_REPLACESEL, FALSE, (LPARAM)pszName); - PostMessage(hwndDlg, WM_MOUSEACTIVATE, 0, 0); - } - else pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_PRIVMESS, ui, nullptr, 0); - } + case WM_ACTIVATE: + if (LOWORD(wParam) != WA_ACTIVE) + break; - return TRUE; - } + //fall through + case WM_MOUSEACTIVATE: + if (uMsg != WM_ACTIVATE) + SetFocus(m_message.GetHwnd()); + + pci->SetActiveSession(m_si->ptszID, m_si->pszModule); - if (HIWORD(wParam) == LBN_KILLFOCUS) - RedrawWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIST), NULL, NULL, RDW_INVALIDATE); + if (db_get_w(m_si->hContact, m_si->pszModule, "ApparentMode", 0) != 0) + db_set_w(m_si->hContact, m_si->pszModule, "ApparentMode", 0); + if (pcli->pfnGetEvent(m_si->hContact, 0)) + pcli->pfnRemoveEvent(m_si->hContact, GC_FAKE_EVENT); break; - case IDOK: - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDOK))) { - char *pszRtf = GetRichTextRTF(GetDlgItem(hwndDlg, IDC_MESSAGE)); - if (pszRtf == NULL) + case WM_NOTIFY: + { + LPNMHDR pNmhdr = (LPNMHDR)lParam; + switch (pNmhdr->code) { + case EN_REQUESTRESIZE: + if (pNmhdr->idFrom == IDC_MESSAGE) { + REQRESIZE *rr = (REQRESIZE *)lParam; + int height = rr->rc.bottom - rr->rc.top + 1; + if (height < g_dat.minInputAreaHeight) + height = g_dat.minInputAreaHeight; + + if (m_si->desiredInputAreaHeight != height) { + m_si->desiredInputAreaHeight = height; + SendMessage(m_hwnd, WM_SIZE, 0, 0); + PostMessage(m_hwnd, GC_SCROLLTOBOTTOM, 0, 0); + } + } break; - MODULEINFO *mi = pci->MM_FindModule(si->pszModule); - if (mi == NULL) + case EN_MSGFILTER: + if (pNmhdr->idFrom == IDC_LOG && ((MSGFILTER *)lParam)->msg == WM_RBUTTONUP) { + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, TRUE); + return TRUE; + } break; - TCmdList *cmdListNew = tcmdlist_last(si->cmdList); - while (cmdListNew != NULL && cmdListNew->temporary) { - si->cmdList = tcmdlist_remove(si->cmdList, cmdListNew); - cmdListNew = tcmdlist_last(si->cmdList); + case TTN_NEEDTEXT: + if (pNmhdr->idFrom == (UINT_PTR)m_nickList.GetHwnd()) { + LPNMTTDISPINFO lpttd = (LPNMTTDISPINFO)lParam; + SESSION_INFO* parentdat = (SESSION_INFO*)GetWindowLongPtr(m_hwnd, GWLP_USERDATA); + + POINT p; + GetCursorPos(&p); + ScreenToClient(m_nickList.GetHwnd(), &p); + int item = LOWORD(m_nickList.SendMsg(LB_ITEMFROMPOINT, 0, MAKELPARAM(p.x, p.y))); + USERINFO *ui = pci->SM_GetUserFromIndex(parentdat->ptszID, parentdat->pszModule, item); + if (ui != NULL) { + static wchar_t ptszBuf[1024]; + mir_snwprintf(ptszBuf, L"%s: %s\r\n%s: %s\r\n%s: %s", + TranslateT("Nickname"), ui->pszNick, + TranslateT("Unique ID"), ui->pszUID, + TranslateT("Status"), pci->TM_WordToString(parentdat->pStatuses, ui->Status)); + lpttd->lpszText = ptszBuf; + } + } + break; } + } + break; - // takes pszRtf to a queue, no leak here - si->cmdList = tcmdlist_append(si->cmdList, pszRtf, 20, FALSE); - - CMStringW ptszText(ptrW(mir_utf8decodeW(pszRtf))); - pci->DoRtfToTags(ptszText, mi->nColorCount, mi->crColors); - ptszText.Trim(); - ptszText.Replace(L"%", L"%%"); + case WM_COMMAND: + if (!lParam && Clist_MenuProcessCommand(LOWORD(wParam), MPCF_CONTACTMENU, m_si->hContact)) + break; - if (mi->bAckMsg) { - EnableWindow(GetDlgItem(hwndDlg, IDC_MESSAGE), FALSE); - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETREADONLY, TRUE, 0); + if (HIWORD(wParam) == BN_CLICKED) + if (LOWORD(wParam) >= MIN_CBUTTONID && LOWORD(wParam) <= MAX_CBUTTONID) { + Srmm_ClickToolbarIcon(m_si->hContact, LOWORD(wParam), GetDlgItem(m_hwnd, LOWORD(wParam)), 0); + break; } - else SetDlgItemText(hwndDlg, IDC_MESSAGE, L""); - EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); + switch (LOWORD(wParam)) { + case IDC_CHAT_LIST: + if (HIWORD(wParam) == LBN_DBLCLK) { + TVHITTESTINFO hti; + hti.pt.x = (short)LOWORD(GetMessagePos()); + hti.pt.y = (short)HIWORD(GetMessagePos()); + ScreenToClient(m_nickList.GetHwnd(), &hti.pt); + + int item = LOWORD(m_nickList.SendMsg(LB_ITEMFROMPOINT, 0, MAKELPARAM(hti.pt.x, hti.pt.y))); + USERINFO *ui = pci->SM_GetUserFromIndex(m_si->ptszID, m_si->pszModule, item); + if (ui) { + if (GetKeyState(VK_SHIFT) & 0x8000) { + LRESULT lResult = (LRESULT)m_message.SendMsg(EM_GETSEL, 0, 0); + int start = LOWORD(lResult); + size_t dwNameLenMax = (mir_wstrlen(ui->pszUID) + 4); + wchar_t* pszName = (wchar_t*)alloca(sizeof(wchar_t) * dwNameLenMax); + if (start == 0) + mir_snwprintf(pszName, dwNameLenMax, L"%s: ", ui->pszUID); + else + mir_snwprintf(pszName, dwNameLenMax, L"%s ", ui->pszUID); + + m_message.SendMsg(EM_REPLACESEL, FALSE, (LPARAM)pszName); + PostMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); + } + else pci->DoEventHookAsync(m_hwnd, m_si->ptszID, m_si->pszModule, GC_USER_PRIVMESS, ui, nullptr, 0); + } - pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, ptszText, 0); - SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); - } - break; + return TRUE; + } - case IDC_CHAT_SHOWNICKLIST: - if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHAT_SHOWNICKLIST))) - break; - if (si->iType == GCW_SERVER) + if (HIWORD(wParam) == LBN_KILLFOCUS) + RedrawWindow(m_nickList.GetHwnd(), NULL, NULL, RDW_INVALIDATE); break; - si->bNicklistEnabled = !si->bNicklistEnabled; + case IDOK: + if (IsWindowEnabled(GetDlgItem(m_hwnd, IDOK))) { + char *pszRtf = GetRichTextRTF(m_message.GetHwnd()); + if (pszRtf == NULL) + break; - SendDlgItemMessage(hwndDlg, IDC_CHAT_SHOWNICKLIST, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(si->bNicklistEnabled ? "chat_nicklist" : "chat_nicklist2")); - SendMessage(hwndDlg, GC_SCROLLTOBOTTOM, 0, 0); - SendMessage(hwndDlg, WM_SIZE, 0, 0); - break; + MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); + if (mi == NULL) + break; - case IDC_MESSAGE: - if (HIWORD(wParam) == EN_CHANGE) { - si->cmdListCurrent = NULL; - EnableWindow(GetDlgItem(hwndDlg, IDOK), GetRichTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE), 1200, FALSE) != 0); - } - break; + TCmdList *cmdListNew = tcmdlist_last(m_si->cmdList); + while (cmdListNew != NULL && cmdListNew->temporary) { + m_si->cmdList = tcmdlist_remove(m_si->cmdList, cmdListNew); + cmdListNew = tcmdlist_last(m_si->cmdList); + } - case IDC_HISTORY: - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_HISTORY))) { - MODULEINFO *pInfo = pci->MM_FindModule(si->pszModule); - if (pInfo) - ShellExecute(hwndDlg, NULL, pci->GetChatLogsFilename(si, 0), NULL, NULL, SW_SHOW); - } - break; + // takes pszRtf to a queue, no leak here + m_si->cmdList = tcmdlist_append(m_si->cmdList, pszRtf, 20, FALSE); + + CMStringW ptszText(ptrW(mir_utf8decodeW(pszRtf))); + pci->DoRtfToTags(ptszText, mi->nColorCount, mi->crColors); + ptszText.Trim(); + ptszText.Replace(L"%", L"%%"); - case IDC_CHAT_CHANMGR: - if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHAT_CHANMGR))) + if (mi->bAckMsg) { + EnableWindow(m_message.GetHwnd(), FALSE); + m_message.SendMsg(EM_SETREADONLY, TRUE, 0); + } + else SetDlgItemText(m_hwnd, IDC_MESSAGE, L""); + + EnableWindow(GetDlgItem(m_hwnd, IDOK), FALSE); + + pci->DoEventHookAsync(m_hwnd, m_si->ptszID, m_si->pszModule, GC_USER_MESSAGE, NULL, ptszText, 0); + SetFocus(m_message.GetHwnd()); + } break; - pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_CHANMGR, NULL, NULL, 0); - break; - case IDC_CHAT_FILTER: - if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHAT_FILTER))) + case IDC_CHAT_SHOWNICKLIST: + if (!IsWindowEnabled(GetDlgItem(m_hwnd, IDC_CHAT_SHOWNICKLIST))) + break; + if (m_si->iType == GCW_SERVER) + break; + + m_si->bNicklistEnabled = !m_si->bNicklistEnabled; + + SendDlgItemMessage(m_hwnd, IDC_CHAT_SHOWNICKLIST, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_si->bNicklistEnabled ? "chat_nicklist" : "chat_nicklist2")); + SendMessage(m_hwnd, GC_SCROLLTOBOTTOM, 0, 0); + SendMessage(m_hwnd, WM_SIZE, 0, 0); break; - si->bFilterEnabled = !si->bFilterEnabled; - SendDlgItemMessage(hwndDlg, IDC_CHAT_FILTER, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(si->bFilterEnabled ? "chat_filter" : "chat_filter2")); - if (si->bFilterEnabled && db_get_b(NULL, CHAT_MODULE, "RightClickFilter", 0) == 0) { - SendMessage(hwndDlg, GC_SHOWFILTERMENU, 0, 0); + case IDC_MESSAGE: + if (HIWORD(wParam) == EN_CHANGE) { + m_si->cmdListCurrent = NULL; + EnableWindow(GetDlgItem(m_hwnd, IDOK), GetRichTextLength(m_message.GetHwnd(), 1200, FALSE) != 0); + } break; - } - SendMessage(hwndDlg, GC_REDRAWLOG, 0, 0); - break; - case IDC_CHAT_BKGCOLOR: - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHAT_BKGCOLOR))) { - MODULEINFO *pInfo = pci->MM_FindModule(si->pszModule); - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwEffects = 0; + case IDC_HISTORY: + if (IsWindowEnabled(GetDlgItem(m_hwnd, IDC_HISTORY))) { + MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); + if (pInfo) + ShellExecute(m_hwnd, NULL, pci->GetChatLogsFilename(m_si, 0), NULL, NULL, SW_SHOW); + } + break; + + case IDC_CHAT_CHANMGR: + if (!IsWindowEnabled(GetDlgItem(m_hwnd, IDC_CHAT_CHANMGR))) + break; + pci->DoEventHookAsync(m_hwnd, m_si->ptszID, m_si->pszModule, GC_USER_CHANMGR, NULL, NULL, 0); + break; + + case IDC_CHAT_FILTER: + if (!IsWindowEnabled(GetDlgItem(m_hwnd, IDC_CHAT_FILTER))) + break; + + m_si->bFilterEnabled = !m_si->bFilterEnabled; + SendDlgItemMessage(m_hwnd, IDC_CHAT_FILTER, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_si->bFilterEnabled ? "chat_filter" : "chat_filter2")); + if (m_si->bFilterEnabled && db_get_b(NULL, CHAT_MODULE, "RightClickFilter", 0) == 0) { + SendMessage(m_hwnd, GC_SHOWFILTERMENU, 0, 0); + break; + } + SendMessage(m_hwnd, GC_REDRAWLOG, 0, 0); + break; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_BKGCOLOR)) { - if (db_get_b(NULL, CHAT_MODULE, "RightClickFilter", 0) == 0) - SendMessage(hwndDlg, GC_SHOWCOLORCHOOSER, 0, IDC_CHAT_BKGCOLOR); - else if (si->bBGSet) { + case IDC_CHAT_BKGCOLOR: + if (IsWindowEnabled(GetDlgItem(m_hwnd, IDC_CHAT_BKGCOLOR))) { + MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwEffects = 0; + + if (IsDlgButtonChecked(m_hwnd, IDC_CHAT_BKGCOLOR)) { + if (db_get_b(NULL, CHAT_MODULE, "RightClickFilter", 0) == 0) + SendMessage(m_hwnd, GC_SHOWCOLORCHOOSER, 0, IDC_CHAT_BKGCOLOR); + else if (m_si->bBGSet) { + cf.dwMask = CFM_BACKCOLOR; + cf.crBackColor = pInfo->crColors[m_si->iBG]; + if (pInfo->bSingleFormat) + m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); + else + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + } + } + else { cf.dwMask = CFM_BACKCOLOR; - cf.crBackColor = pInfo->crColors[si->iBG]; + cf.crBackColor = (COLORREF)db_get_dw(NULL, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); if (pInfo->bSingleFormat) - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); else - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); } } - else { - cf.dwMask = CFM_BACKCOLOR; - cf.crBackColor = (COLORREF)db_get_dw(NULL, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); - if (pInfo->bSingleFormat) - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); - else - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); - } - } - break; + break; - case IDC_CHAT_COLOR: - { - MODULEINFO *pInfo = pci->MM_FindModule(si->pszModule); - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwEffects = 0; + case IDC_CHAT_COLOR: + { + MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwEffects = 0; - if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHAT_COLOR))) - break; + if (!IsWindowEnabled(GetDlgItem(m_hwnd, IDC_CHAT_COLOR))) + break; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_COLOR)) { - if (db_get_b(NULL, CHAT_MODULE, "RightClickFilter", 0) == 0) - SendMessage(hwndDlg, GC_SHOWCOLORCHOOSER, 0, IDC_CHAT_COLOR); - else if (si->bFGSet) { + if (IsDlgButtonChecked(m_hwnd, IDC_CHAT_COLOR)) { + if (db_get_b(NULL, CHAT_MODULE, "RightClickFilter", 0) == 0) + SendMessage(m_hwnd, GC_SHOWCOLORCHOOSER, 0, IDC_CHAT_COLOR); + else if (m_si->bFGSet) { + cf.dwMask = CFM_COLOR; + cf.crTextColor = pInfo->crColors[m_si->iFG]; + if (pInfo->bSingleFormat) + m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); + else + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + } + } + else { + COLORREF cr; + LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, NULL, &cr); cf.dwMask = CFM_COLOR; - cf.crTextColor = pInfo->crColors[si->iFG]; + cf.crTextColor = cr; if (pInfo->bSingleFormat) - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); else - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); } } - else { - COLORREF cr; - LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, NULL, &cr); - cf.dwMask = CFM_COLOR; - cf.crTextColor = cr; + break; + + case IDC_CHAT_BOLD: + case IDC_CHAT_ITALICS: + case IDC_CHAT_UNDERLINE: + { + MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE; + cf.dwEffects = 0; + + if (LOWORD(wParam) == IDC_CHAT_BOLD && !IsWindowEnabled(GetDlgItem(m_hwnd, IDC_CHAT_BOLD))) + break; + if (LOWORD(wParam) == IDC_CHAT_ITALICS && !IsWindowEnabled(GetDlgItem(m_hwnd, IDC_CHAT_ITALICS))) + break; + if (LOWORD(wParam) == IDC_CHAT_UNDERLINE && !IsWindowEnabled(GetDlgItem(m_hwnd, IDC_CHAT_UNDERLINE))) + break; + if (IsDlgButtonChecked(m_hwnd, IDC_CHAT_BOLD)) + cf.dwEffects |= CFE_BOLD; + if (IsDlgButtonChecked(m_hwnd, IDC_CHAT_ITALICS)) + cf.dwEffects |= CFE_ITALIC; + if (IsDlgButtonChecked(m_hwnd, IDC_CHAT_UNDERLINE)) + cf.dwEffects |= CFE_UNDERLINE; if (pInfo->bSingleFormat) - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); else - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); } + break; + + case IDCANCEL: + PostMessage(m_hwnd, WM_CLOSE, 0, 0); } break; - case IDC_CHAT_BOLD: - case IDC_CHAT_ITALICS: - case IDC_CHAT_UNDERLINE: + case WM_KEYDOWN: + SetFocus(m_message.GetHwnd()); + break; + + case WM_GETMINMAXINFO: { - MODULEINFO *pInfo = pci->MM_FindModule(si->pszModule); - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE; - cf.dwEffects = 0; + MINMAXINFO* mmi = (MINMAXINFO*)lParam; + mmi->ptMinTrackSize.x = m_si->iSplitterX + 43; + if (mmi->ptMinTrackSize.x < 350) + mmi->ptMinTrackSize.x = 350; - if (LOWORD(wParam) == IDC_CHAT_BOLD && !IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHAT_BOLD))) - break; - if (LOWORD(wParam) == IDC_CHAT_ITALICS && !IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHAT_ITALICS))) - break; - if (LOWORD(wParam) == IDC_CHAT_UNDERLINE && !IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHAT_UNDERLINE))) - break; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_BOLD)) - cf.dwEffects |= CFE_BOLD; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_ITALICS)) - cf.dwEffects |= CFE_ITALIC; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_UNDERLINE)) - cf.dwEffects |= CFE_UNDERLINE; - if (pInfo->bSingleFormat) - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); - else - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + mmi->ptMinTrackSize.y = m_si->minLogBoxHeight + TOOLBAR_HEIGHT + m_si->minEditBoxHeight + 5; } break; - case IDCANCEL: - PostMessage(hwndDlg, WM_CLOSE, 0, 0); - } - break; - - case WM_KEYDOWN: - SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); - break; - - case WM_GETMINMAXINFO: - { - MINMAXINFO* mmi = (MINMAXINFO*)lParam; - mmi->ptMinTrackSize.x = si->iSplitterX + 43; - if (mmi->ptMinTrackSize.x < 350) - mmi->ptMinTrackSize.x = 350; - - mmi->ptMinTrackSize.y = si->minLogBoxHeight + TOOLBAR_HEIGHT + si->minEditBoxHeight + 5; - } - break; - - case WM_LBUTTONDBLCLK: - if (LOWORD(lParam) < 30) - PostMessage(hwndDlg, GC_SCROLLTOBOTTOM, 0, 0); - else - SendMessage(GetParent(hwndDlg), WM_SYSCOMMAND, SC_MINIMIZE, 0); - break; - - case WM_LBUTTONDOWN: - SendMessage(GetParent(hwndDlg), WM_LBUTTONDOWN, wParam, lParam); - return TRUE; - - case DM_GETCONTEXTMENU: - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LPARAM)Menu_BuildContactMenu(si->hContact)); - return TRUE; - - case WM_CONTEXTMENU: - if (GetParent(hwndDlg) == (HWND)wParam) { - HMENU hMenu = Menu_BuildContactMenu(si->hContact); - GetCursorPos(&pt); - TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hwndDlg, NULL); - DestroyMenu(hMenu); - } - break; + case WM_LBUTTONDBLCLK: + if (LOWORD(lParam) < 30) + PostMessage(m_hwnd, GC_SCROLLTOBOTTOM, 0, 0); + else + SendMessage(GetParent(m_hwnd), WM_SYSCOMMAND, SC_MINIMIZE, 0); + break; - case WM_CLOSE: - SendMessage(hwndDlg, GC_CLOSEWINDOW, 0, 0); - break; + case WM_LBUTTONDOWN: + SendMessage(GetParent(m_hwnd), WM_LBUTTONDOWN, wParam, lParam); + return TRUE; - case GC_CLOSEWINDOW: - DestroyWindow(hwndDlg); - break; + case DM_GETCONTEXTMENU: + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, (LPARAM)Menu_BuildContactMenu(m_si->hContact)); + return TRUE; - case WM_DESTROY: - NotifyLocalWinEvent(si->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSING); - si->hWnd = NULL; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + case WM_CONTEXTMENU: + if (GetParent(m_hwnd) == (HWND)wParam) { + HMENU hMenu = Menu_BuildContactMenu(m_si->hContact); + GetCursorPos(&pt); + TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, m_hwnd, NULL); + DestroyMenu(hMenu); + } + break; - SendMessage(GetParent(hwndDlg), CM_REMOVECHILD, 0, (LPARAM)hwndDlg); - if (si->hwndLog != NULL) { - IEVIEWWINDOW ieWindow; - ieWindow.cbSize = sizeof(IEVIEWWINDOW); - ieWindow.iType = IEW_DESTROY; - ieWindow.hwnd = si->hwndLog; - CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); + case GC_CLOSEWINDOW: + Close(); + break; } - - NotifyLocalWinEvent(si->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSE); - break; + return CSrmmBaseDialog::DlgProc(uMsg, wParam, lParam); } - return FALSE; -} +}; void ShowRoom(SESSION_INFO *si) { @@ -1806,8 +1799,13 @@ void ShowRoom(SESSION_INFO *si) // Do we need to create a window? if (si->hWnd == NULL) { HWND hParent = GetParentWindow(si->hContact, TRUE); + + CChatRoomDlg *pDlg = new CChatRoomDlg(si); + pDlg->SetParent(hParent); + pDlg->Show(); + si->parent = (ParentWindowData*)GetWindowLongPtr(hParent, GWLP_USERDATA); - si->hWnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_CHANNEL), hParent, RoomWndProc, (LPARAM)si); + si->hWnd = pDlg->GetHwnd(); } SendMessage(si->hWnd, DM_UPDATETABCONTROL, -1, (LPARAM)si); SendMessage(GetParent(si->hWnd), CM_ACTIVATECHILD, 0, (LPARAM)si->hWnd); -- cgit v1.2.3