From 1e7b2b400a5ac674c00c2c0ad01f51646edd2de3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 21 Mar 2017 13:41:54 +0300 Subject: Scriver: standardizing file names --- plugins/Scriver/scriver.vcxproj | 10 +- plugins/Scriver/src/chat.h | 96 ++ plugins/Scriver/src/chat/chat.h | 96 -- plugins/Scriver/src/chat/log.cpp | 123 --- plugins/Scriver/src/chat/main.cpp | 163 ---- plugins/Scriver/src/chat/manager.cpp | 86 -- plugins/Scriver/src/chat/options.cpp | 729 --------------- plugins/Scriver/src/chat/tools.cpp | 120 --- plugins/Scriver/src/chat/window.cpp | 1637 ---------------------------------- plugins/Scriver/src/chat_log.cpp | 123 +++ plugins/Scriver/src/chat_main.cpp | 163 ++++ plugins/Scriver/src/chat_manager.cpp | 86 ++ plugins/Scriver/src/chat_options.cpp | 729 +++++++++++++++ plugins/Scriver/src/chat_tools.cpp | 120 +++ plugins/Scriver/src/chat_window.cpp | 1637 ++++++++++++++++++++++++++++++++++ plugins/Scriver/src/stdafx.h | 2 +- 16 files changed, 2956 insertions(+), 2964 deletions(-) create mode 100644 plugins/Scriver/src/chat.h delete mode 100644 plugins/Scriver/src/chat/chat.h delete mode 100644 plugins/Scriver/src/chat/log.cpp delete mode 100644 plugins/Scriver/src/chat/main.cpp delete mode 100644 plugins/Scriver/src/chat/manager.cpp delete mode 100644 plugins/Scriver/src/chat/options.cpp delete mode 100644 plugins/Scriver/src/chat/tools.cpp delete mode 100644 plugins/Scriver/src/chat/window.cpp create mode 100644 plugins/Scriver/src/chat_log.cpp create mode 100644 plugins/Scriver/src/chat_main.cpp create mode 100644 plugins/Scriver/src/chat_manager.cpp create mode 100644 plugins/Scriver/src/chat_options.cpp create mode 100644 plugins/Scriver/src/chat_tools.cpp create mode 100644 plugins/Scriver/src/chat_window.cpp (limited to 'plugins/Scriver') diff --git a/plugins/Scriver/scriver.vcxproj b/plugins/Scriver/scriver.vcxproj index 02d2c10008..15831ec0b1 100644 --- a/plugins/Scriver/scriver.vcxproj +++ b/plugins/Scriver/scriver.vcxproj @@ -25,12 +25,4 @@ - - - ..\stdafx.h - - - - - - \ No newline at end of file + diff --git a/plugins/Scriver/src/chat.h b/plugins/Scriver/src/chat.h new file mode 100644 index 0000000000..ca620576f1 --- /dev/null +++ b/plugins/Scriver/src/chat.h @@ -0,0 +1,96 @@ +/* +Chat module plugin for Miranda IM + +Copyright (C) 2003 Jörgen Persson +Copyright 2003-2009 Miranda ICQ/IM project, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef _CHAT_H_ +#define _CHAT_H_ + +#define EM_ACTIVATE (WM_USER+202) + +#define TIMERID_MSGSEND 201 +#define TIMERID_TYPE 202 +#define TIMERID_UNREAD 203 +#define TIMEOUT_TYPEOFF 10000 // send type off after 10 seconds of inactivity +#define TIMEOUT_UNREAD 800 // multiple-send bombproofing: send max 3 messages every 4 seconds + +#ifndef TVM_GETITEMSTATE +#define TVM_GETITEMSTATE (TV_FIRST + 39) +#endif + +#ifndef TreeView_GetItemState +#define TreeView_GetItemState(hwndTV, hti, mask) \ + (UINT)SNDMSG((hwndTV), TVM_GETITEMSTATE, (WPARAM)(hti), (LPARAM)(mask)) +#endif + +#ifndef CFM_BACKCOLOR +#define CFM_BACKCOLOR 0x04000000 +#endif + +// structs + +struct MODULEINFO : public GCModuleInfoBase +{ + HICON hOnlineIconBig; + HICON hOfflineIconBig; +}; + +struct LOGSTREAMDATA : public GCLogStreamDataBase +{ + BOOL isFirst; +}; + +struct SESSION_INFO : public GCSessionInfoBase +{ +}; + +struct GlobalLogSettings : public GlobalLogSettingsBase +{ + HFONT MessageBoxFont; +}; +extern GlobalLogSettings g_Settings; + +// main.c +void UpgradeCheck(void); + +// log.c +void LoadMsgLogBitmaps(void); +void FreeMsgLogBitmaps(void); + +// window.c +int GetTextPixelSize( wchar_t* pszText, HFONT hFont, BOOL bWidth); + +// services.c +void ShowRoom(SESSION_INFO *si); + +// manager.c +HWND SM_FindWindowByContact(MCONTACT hContact); +SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO* currSession, SESSION_INFO* prevSession, const wchar_t* pszOriginal, const wchar_t* pszCurrent); +char SM_GetStatusIndicator(SESSION_INFO *si, USERINFO *ui); + +// tools.c +BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix); +wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2) ; +UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText); +void DestroyGCMenu(HMENU *hMenu, int iIndex); + +///////////////////////////////////////////////////////////////////////////////////////// + +#define DEFLOGFILENAME L"%miranda_logpath%\\%proto%\\%userid%.log" +#endif diff --git a/plugins/Scriver/src/chat/chat.h b/plugins/Scriver/src/chat/chat.h deleted file mode 100644 index ca620576f1..0000000000 --- a/plugins/Scriver/src/chat/chat.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright (C) 2003 Jörgen Persson -Copyright 2003-2009 Miranda ICQ/IM project, - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#ifndef _CHAT_H_ -#define _CHAT_H_ - -#define EM_ACTIVATE (WM_USER+202) - -#define TIMERID_MSGSEND 201 -#define TIMERID_TYPE 202 -#define TIMERID_UNREAD 203 -#define TIMEOUT_TYPEOFF 10000 // send type off after 10 seconds of inactivity -#define TIMEOUT_UNREAD 800 // multiple-send bombproofing: send max 3 messages every 4 seconds - -#ifndef TVM_GETITEMSTATE -#define TVM_GETITEMSTATE (TV_FIRST + 39) -#endif - -#ifndef TreeView_GetItemState -#define TreeView_GetItemState(hwndTV, hti, mask) \ - (UINT)SNDMSG((hwndTV), TVM_GETITEMSTATE, (WPARAM)(hti), (LPARAM)(mask)) -#endif - -#ifndef CFM_BACKCOLOR -#define CFM_BACKCOLOR 0x04000000 -#endif - -// structs - -struct MODULEINFO : public GCModuleInfoBase -{ - HICON hOnlineIconBig; - HICON hOfflineIconBig; -}; - -struct LOGSTREAMDATA : public GCLogStreamDataBase -{ - BOOL isFirst; -}; - -struct SESSION_INFO : public GCSessionInfoBase -{ -}; - -struct GlobalLogSettings : public GlobalLogSettingsBase -{ - HFONT MessageBoxFont; -}; -extern GlobalLogSettings g_Settings; - -// main.c -void UpgradeCheck(void); - -// log.c -void LoadMsgLogBitmaps(void); -void FreeMsgLogBitmaps(void); - -// window.c -int GetTextPixelSize( wchar_t* pszText, HFONT hFont, BOOL bWidth); - -// services.c -void ShowRoom(SESSION_INFO *si); - -// manager.c -HWND SM_FindWindowByContact(MCONTACT hContact); -SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO* currSession, SESSION_INFO* prevSession, const wchar_t* pszOriginal, const wchar_t* pszCurrent); -char SM_GetStatusIndicator(SESSION_INFO *si, USERINFO *ui); - -// tools.c -BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix); -wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2) ; -UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText); -void DestroyGCMenu(HMENU *hMenu, int iIndex); - -///////////////////////////////////////////////////////////////////////////////////////// - -#define DEFLOGFILENAME L"%miranda_logpath%\\%proto%\\%userid%.log" -#endif diff --git a/plugins/Scriver/src/chat/log.cpp b/plugins/Scriver/src/chat/log.cpp deleted file mode 100644 index 02ba38a147..0000000000 --- a/plugins/Scriver/src/chat/log.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright (C) 2003 Jörgen Persson -Copyright 2003-2009 Miranda ICQ/IM project, - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "../stdafx.h" - -#ifndef EM_GETSCROLLPOS -#define EM_GETSCROLLPOS (WM_USER+221) -#endif - -void CChatRoomDlg::StreamInEvents(LOGINFO* lin, bool bRedraw) -{ - if (m_hwnd == nullptr || lin == nullptr || m_si == nullptr) - return; - - if (!bRedraw && (m_si->iType == GCW_CHATROOM || m_si->iType == GCW_PRIVMESS) && m_bFilterEnabled && !(m_iLogFilterFlags & lin->iType)) - return; - - LOGSTREAMDATA streamData; - memset(&streamData, 0, sizeof(streamData)); - streamData.hwnd = m_log.GetHwnd(); - streamData.si = m_si; - streamData.lin = lin; - streamData.bStripFormat = FALSE; - streamData.isFirst = bRedraw ? 1 : (GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE) == 0); - - EDITSTREAM stream = { 0 }; - stream.pfnCallback = Srmm_LogStreamCallback; - stream.dwCookie = (DWORD_PTR)&streamData; - - SCROLLINFO scroll; - scroll.cbSize = sizeof(SCROLLINFO); - scroll.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; - GetScrollInfo(m_log.GetHwnd(), SB_VERT, &scroll); - - POINT point = { 0 }; - m_log.SendMsg(EM_GETSCROLLPOS, 0, (LPARAM)&point); - - // do not scroll to bottom if there is a selection - CHARRANGE oldsel, sel, newsel; - m_log.SendMsg(EM_EXGETSEL, 0, (LPARAM)&oldsel); - if (oldsel.cpMax != oldsel.cpMin) - m_log.SendMsg(WM_SETREDRAW, FALSE, 0); - - // set the insertion point at the bottom - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE); - m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); - m_log.SendMsg(EM_EXGETSEL, 0, (LPARAM)&sel); - - // fix for the indent... must be a M$ bug - if (sel.cpMax == 0) - bRedraw = TRUE; - - // should the event(s) be appended to the current log - WPARAM wp = bRedraw ? SF_RTF : SFF_SELECTION | SF_RTF; - - // get the number of pixels per logical inch - bool bFlag = false; - if (bRedraw) { - m_log.SendMsg(WM_SETREDRAW, FALSE, 0); - bFlag = true; - } - - // stream in the event(s) - streamData.lin = lin; - streamData.bRedraw = bRedraw; - m_log.SendMsg(EM_STREAMIN, wp, (LPARAM)&stream); - - // do smileys - if (g_dat.smileyAddInstalled && (bRedraw || (lin->ptszText && lin->iType != GC_EVENT_JOIN && lin->iType != GC_EVENT_NICK && lin->iType != GC_EVENT_ADDSTATUS && lin->iType != GC_EVENT_REMOVESTATUS))) { - newsel.cpMax = -1; - newsel.cpMin = sel.cpMin; - if (newsel.cpMin < 0) - newsel.cpMin = 0; - - SMADD_RICHEDIT3 sm = { sizeof(sm) }; - sm.hwndRichEditControl = m_log.GetHwnd(); - sm.Protocolname = m_si->pszModule; - sm.rangeToReplace = bRedraw ? nullptr : &newsel; - sm.flags = 0; - sm.disableRedraw = TRUE; - sm.hContact = m_hContact; - CallService(MS_SMILEYADD_REPLACESMILEYS, 0, (LPARAM)&sm); - } - - // scroll log to bottom if the log was previously scrolled to bottom, else restore old position - if (bRedraw || (UINT)scroll.nPos >= (UINT)scroll.nMax - scroll.nPage - 5 || scroll.nMax - scroll.nMin - scroll.nPage < 50) - ScrollToBottom(); - else - m_log.SendMsg(EM_SETSCROLLPOS, 0, (LPARAM)&point); - - // do we need to restore the selection - if (oldsel.cpMax != oldsel.cpMin) { - m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&oldsel); - m_log.SendMsg(WM_SETREDRAW, TRUE, 0); - InvalidateRect(m_log.GetHwnd(), nullptr, TRUE); - } - - // need to invalidate the window - if (bFlag) { - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE); - m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); - m_log.SendMsg(WM_SETREDRAW, TRUE, 0); - InvalidateRect(m_log.GetHwnd(), nullptr, TRUE); - } -} diff --git a/plugins/Scriver/src/chat/main.cpp b/plugins/Scriver/src/chat/main.cpp deleted file mode 100644 index 086b64c529..0000000000 --- a/plugins/Scriver/src/chat/main.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright (C) 2003 Jörgen Persson -Copyright 2003-2009 Miranda ICQ/IM project, - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "../stdafx.h" - -// globals -CHAT_MANAGER *pci; -HMENU g_hMenu = nullptr; - -pfnDoTrayIcon oldDoTrayIcon; -pfnDoPopup oldDoPopup; - -GlobalLogSettings g_Settings; - -void LoadModuleIcons(MODULEINFO *mi) -{ - HIMAGELIST hList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 0); - - int overlayIcon = ImageList_AddIcon(hList, GetCachedIcon("chat_overlay")); - ImageList_SetOverlayImage(hList, overlayIcon, 1); - - int index = ImageList_AddIcon(hList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE)); - mi->hOnlineIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT); - mi->hOnlineTalkIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1)); - - index = ImageList_AddIcon(hList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE)); - mi->hOfflineIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT); - mi->hOfflineTalkIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1)); - - ImageList_Destroy(hList); -} - -static void OnReplaceSession(SESSION_INFO *si) -{ - if (si->pDlg) - RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_CHAT_LIST), nullptr, nullptr, RDW_INVALIDATE); -} - -static void OnNewUser(SESSION_INFO *si, USERINFO*) -{ - if (si->pDlg) - si->pDlg->UpdateNickList(); -} - -static void OnSetStatus(SESSION_INFO *si, int) -{ - if (si->pDlg) - si->pDlg->FixTabIcons(); -} - -static void OnFlashHighlight(SESSION_INFO *si, int bInactive) -{ - if (!bInactive || !si->pDlg) - return; - - if (g_Settings.bFlashWindowHighlight) - SendMessage(GetParent(si->pDlg->GetHwnd()), CM_STARTFLASHING, 0, 0); - - si->wState |= GC_EVENT_HIGHLIGHT; - si->pDlg->FixTabIcons(); - si->pDlg->UpdateTitle(); - - HWND hwndParent = GetParent(si->pDlg->GetHwnd()); - if (g_Settings.bFlashWindowHighlight && GetActiveWindow() != si->pDlg->GetHwnd() && GetForegroundWindow() != hwndParent) - SendMessage(hwndParent, CM_STARTFLASHING, 0, 0); -} - -static void OnFlashWindow(SESSION_INFO *si, int bInactive) -{ - if (!bInactive || !si->pDlg) - return; - - if (g_Settings.bFlashWindow) - SendMessage(GetParent(si->pDlg->GetHwnd()), CM_STARTFLASHING, 0, 0); - - si->pDlg->FixTabIcons(); - si->pDlg->UpdateTitle(); - - HWND hwndParent = GetParent(si->pDlg->GetHwnd()); - if (g_Settings.bFlashWindow && GetActiveWindow() != hwndParent && GetForegroundWindow() != hwndParent) - SendMessage(hwndParent, CM_STARTFLASHING, 0, 0); -} - -static void OnCreateModule(MODULEINFO *mi) -{ - LoadModuleIcons(mi); - mi->hOnlineIconBig = Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE, true); - mi->hOfflineIconBig = Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE, true); -} - -static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) -{ - if (gce->pDest->iType & g_Settings.dwTrayIconFlags) - return oldDoTrayIcon(si, gce); - return TRUE; -} - -static BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce) -{ - if (gce->pDest->iType & g_Settings.dwPopupFlags) - return oldDoPopup(si, gce); - return TRUE; -} - -static void OnLoadSettings() -{ - if (g_Settings.MessageBoxFont) - DeleteObject(g_Settings.MessageBoxFont); - - LOGFONT lf; - LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, &lf, nullptr); - g_Settings.MessageBoxFont = CreateFontIndirect(&lf); -} - -int Chat_Load() -{ - CHAT_MANAGER_INITDATA data = { &g_Settings, sizeof(MODULEINFO), sizeof(SESSION_INFO), LPGENW("Messaging") L"/" LPGENW("Group chats"), FONTMODE_SKIP }; - pci = Chat_GetInterface(&data); - - pci->OnCreateModule = OnCreateModule; - pci->OnNewUser = OnNewUser; - pci->OnLoadSettings = OnLoadSettings; - - pci->OnSetStatus = OnSetStatus; - - pci->OnReplaceSession = OnReplaceSession; - - pci->OnFlashWindow = OnFlashWindow; - pci->OnFlashHighlight = OnFlashHighlight; - pci->ShowRoom = ShowRoom; - - oldDoPopup = pci->DoPopup; pci->DoPopup = DoPopup; - oldDoTrayIcon = pci->DoTrayIcon; pci->DoTrayIcon = DoTrayIcon; - pci->ReloadSettings(); - - g_hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU)); - TranslateMenu(g_hMenu); - return 0; -} - -int Chat_Unload(void) -{ - DestroyMenu(g_hMenu); - return 0; -} diff --git a/plugins/Scriver/src/chat/manager.cpp b/plugins/Scriver/src/chat/manager.cpp deleted file mode 100644 index 307059dfd8..0000000000 --- a/plugins/Scriver/src/chat/manager.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright (C) 2003 Jörgen Persson -Copyright 2003-2009 Miranda ICQ/IM project, - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "../stdafx.h" - -HWND SM_FindWindowByContact(MCONTACT hContact) -{ - for (int i = 0; i < pci->arSessions.getCount(); i++) { - SESSION_INFO *si = pci->arSessions[i]; - if (si->hContact == hContact) - return (si->pDlg) ? si->pDlg->GetHwnd() : nullptr; - } - return nullptr; -} - -SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO *currSession, SESSION_INFO *prevSession, const wchar_t *pszOriginal, const wchar_t *pszCurrent) -{ - SESSION_INFO* pResult = nullptr; - if (prevSession == nullptr && my_strstri(currSession->ptszName, pszOriginal) == currSession->ptszName) - pResult = currSession; - else { - wchar_t* pszName = nullptr; - if (currSession == prevSession) - pszCurrent = pszOriginal; - - for (int i = 0; i < pci->arSessions.getCount(); i++) { - SESSION_INFO *si = pci->arSessions[i]; - if (si != currSession && !mir_strcmpi(pszModule, si->pszModule)) { - if (my_strstri(si->ptszName, pszOriginal) == si->ptszName) { - if (prevSession != si && mir_wstrcmpi(si->ptszName, pszCurrent) > 0 && (!pszName || mir_wstrcmpi(si->ptszName, pszName) < 0)) { - pResult = si; - pszName = si->ptszName; - } - } - } - } - } - return pResult; -} - -char SM_GetStatusIndicator(SESSION_INFO *si, USERINFO *ui) -{ - STATUSINFO * ti; - if (!ui || !si) - return '\0'; - - ti = pci->TM_FindStatus(si->pStatuses, pci->TM_WordToString(si->pStatuses, ui->Status)); - if (ti) { - if ((INT_PTR)ti->hIcon < STATUSICONCOUNT) { - INT_PTR id = si->iStatusCount - (INT_PTR)ti->hIcon - 1; - if (id == 0) - return '\0'; - if (id == 1) - return '+'; - if (id == 2) - return '%'; - if (id == 3) - return '@'; - if (id == 4) - return '!'; - if (id == 5) - return '*'; - } - else - return '\0'; - } - return '\0'; -} diff --git a/plugins/Scriver/src/chat/options.cpp b/plugins/Scriver/src/chat/options.cpp deleted file mode 100644 index 8ee73f0592..0000000000 --- a/plugins/Scriver/src/chat/options.cpp +++ /dev/null @@ -1,729 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright (C) 2003 Jörgen Persson -Copyright 2003-2009 Miranda ICQ/IM project, - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "../stdafx.h" - -#define UM_CHECKSTATECHANGE (WM_USER+100) - -static HWND hPathTip = 0; - -struct branch_t -{ - wchar_t* szDescr; - char* szDBName; - int iMode; - BYTE bDefault; - HTREEITEM hItem; -}; - -static struct branch_t branch1[] = { - { LPGENW("Flash when someone speaks"), "FlashWindow", 0, 0, nullptr }, - { LPGENW("Flash when a word is highlighted"), "FlashWindowHighlight", 0, 1, nullptr }, - { LPGENW("Show chat nick list"), "ShowNicklist", 0, 1, nullptr }, - { LPGENW("Enable button context menus"), "RightClickFilter", 0, 0, nullptr }, - { LPGENW("Show topic on your contact list (if supported)"), "TopicOnClist", 0, 0, nullptr }, - { LPGENW("Do not play sounds when focused"), "SoundsFocus", 0, 0, nullptr }, - { LPGENW("Do not pop up when joining"), "PopupOnJoin", 0, 0, nullptr }, - { LPGENW("Show and hide by double clicking in the contact list"), "ToggleVisibility", 0, 0, nullptr }, - { LPGENW("Show contact statuses (if supported)"), "ShowContactStatus", 0, 0, nullptr }, - { LPGENW("Display contact status icon before role icon"), "ContactStatusFirst", 0, 0, nullptr }, - { LPGENW("Add ':' to auto-completed names"), "AddColonToAutoComplete", 0, 1, nullptr } -}; - -static struct branch_t branch2[] = { - { LPGENW("Show icons"), "IconFlags", GC_EVENT_TOPIC | GC_EVENT_JOIN | GC_EVENT_QUIT | - GC_EVENT_MESSAGE | GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT | GC_EVENT_PART | - GC_EVENT_KICK | GC_EVENT_NOTICE | GC_EVENT_NICK | GC_EVENT_INFORMATION | GC_EVENT_ADDSTATUS, 0, nullptr }, - { LPGENW("Prefix all events with a timestamp"), "ShowTimeStamp", 0, 1, nullptr }, - { LPGENW("Only prefix with timestamp if it has changed"), "ShowTimeStampIfChanged", 0, 0, nullptr }, - { LPGENW("Timestamp has same color as event"), "TimeStampEventColour", 0, 0, nullptr }, - { LPGENW("Indent the second line of a message"), "LogIndentEnabled", 0, 1, nullptr }, - { LPGENW("Limit user names to 20 characters"), "LogLimitNames", 0, 1, nullptr }, - { LPGENW("Strip colors from messages"), "StripFormatting", 0, 0, nullptr }, - { LPGENW("Enable 'event filter' for new rooms"), "FilterEnabled", 0, 0, nullptr } -}; - -static struct branch_t branch3[] = { - { LPGENW("Show topic changes"), "FilterFlags", GC_EVENT_TOPIC, 0, nullptr }, - { LPGENW("Show users joining"), "FilterFlags", GC_EVENT_JOIN, 0, nullptr }, - { LPGENW("Show users disconnecting"), "FilterFlags", GC_EVENT_QUIT, 0, nullptr }, - { LPGENW("Show messages"), "FilterFlags", GC_EVENT_MESSAGE, 1, nullptr }, - { LPGENW("Show actions"), "FilterFlags", GC_EVENT_ACTION, 1, nullptr }, - { LPGENW("Show users leaving"), "FilterFlags", GC_EVENT_PART, 0, nullptr }, - { LPGENW("Show users being kicked"), "FilterFlags", GC_EVENT_KICK, 1, nullptr }, - { LPGENW("Show notices"), "FilterFlags", GC_EVENT_NOTICE, 1, nullptr }, - { LPGENW("Show users changing name"), "FilterFlags", GC_EVENT_NICK, 0, nullptr }, - { LPGENW("Show information messages"), "FilterFlags", GC_EVENT_INFORMATION, 1, nullptr }, - { LPGENW("Show status changes of users"), "FilterFlags", GC_EVENT_ADDSTATUS, 0, nullptr }, -}; - -static struct branch_t branch4[] = { - { LPGENW("Show icons in tray only when the chat room is not active"), "TrayIconInactiveOnly", 0, 1, nullptr }, - { LPGENW("Show icon in tray for topic changes"), "TrayIconFlags", GC_EVENT_TOPIC, 0, nullptr }, - { LPGENW("Show icon in tray for users joining"), "TrayIconFlags", GC_EVENT_JOIN, 0, nullptr }, - { LPGENW("Show icon in tray for users disconnecting"), "TrayIconFlags", GC_EVENT_QUIT, 0, nullptr }, - { LPGENW("Show icon in tray for messages"), "TrayIconFlags", GC_EVENT_MESSAGE, 0, nullptr }, - { LPGENW("Show icon in tray for actions"), "TrayIconFlags", GC_EVENT_ACTION, 0, nullptr }, - { LPGENW("Show icon in tray for highlights"), "TrayIconFlags", GC_EVENT_HIGHLIGHT, 1, nullptr }, - { LPGENW("Show icon in tray for users leaving"), "TrayIconFlags", GC_EVENT_PART, 0, nullptr }, - { LPGENW("Show icon in tray for users kicking other user"), "TrayIconFlags", GC_EVENT_KICK, 0, nullptr }, - { LPGENW("Show icon in tray for notices"), "TrayIconFlags", GC_EVENT_NOTICE, 0, nullptr }, - { LPGENW("Show icon in tray for name changes"), "TrayIconFlags", GC_EVENT_NICK, 0, nullptr }, - { LPGENW("Show icon in tray for information messages"), "TrayIconFlags", GC_EVENT_INFORMATION, 0, nullptr }, - { LPGENW("Show icon in tray for status changes"), "TrayIconFlags", GC_EVENT_ADDSTATUS, 0, nullptr }, -}; - -static struct branch_t branch6[] = { - { LPGENW("Show popups only when the chat room is not active"), "PopupInactiveOnly", 0, 1, nullptr }, - { LPGENW("Show popup for topic changes"), "PopupFlags", GC_EVENT_TOPIC, 0, nullptr }, - { LPGENW("Show popup for users joining"), "PopupFlags", GC_EVENT_JOIN, 0, nullptr }, - { LPGENW("Show popup for users disconnecting"), "PopupFlags", GC_EVENT_QUIT, 0, nullptr }, - { LPGENW("Show popup for messages"), "PopupFlags", GC_EVENT_MESSAGE, 0, nullptr }, - { LPGENW("Show popup for actions"), "PopupFlags", GC_EVENT_ACTION, 0, nullptr }, - { LPGENW("Show popup for highlights"), "PopupFlags", GC_EVENT_HIGHLIGHT, 0, nullptr }, - { LPGENW("Show popup for users leaving"), "PopupFlags", GC_EVENT_PART, 0, nullptr }, - { LPGENW("Show popup for users kicking other user"), "PopupFlags", GC_EVENT_KICK, 0, nullptr }, - { LPGENW("Show popup for notices"), "PopupFlags", GC_EVENT_NOTICE, 0, nullptr }, - { LPGENW("Show popup for name changes"), "PopupFlags", GC_EVENT_NICK, 0, nullptr }, - { LPGENW("Show popup for information messages"), "PopupFlags", GC_EVENT_INFORMATION, 0, nullptr }, - { LPGENW("Show popup for status changes"), "PopupFlags", GC_EVENT_ADDSTATUS, 0, nullptr }, -}; - -static HTREEITEM InsertBranch(HWND hwndTree, wchar_t* pszDescr, BOOL bExpanded) -{ - TVINSERTSTRUCT tvis; - tvis.hParent = nullptr; - tvis.hInsertAfter = TVI_LAST; - tvis.item.mask = TVIF_TEXT | TVIF_STATE; - tvis.item.pszText = TranslateW(pszDescr); - tvis.item.stateMask = bExpanded ? TVIS_STATEIMAGEMASK | TVIS_EXPANDED : TVIS_STATEIMAGEMASK; - tvis.item.state = bExpanded ? INDEXTOSTATEIMAGEMASK(1) | TVIS_EXPANDED : INDEXTOSTATEIMAGEMASK(1); - return TreeView_InsertItem(hwndTree, &tvis); -} - -static void FillBranch(HWND hwndTree, HTREEITEM hParent, struct branch_t *branch, int nValues, DWORD defaultval) -{ - int iState; - - TVINSERTSTRUCT tvis; - tvis.hParent = hParent; - tvis.hInsertAfter = TVI_LAST; - tvis.item.mask = TVIF_TEXT | TVIF_STATE; - for (int i = 0; i < nValues; i++) { - tvis.item.pszText = TranslateW(branch[i].szDescr); - tvis.item.stateMask = TVIS_STATEIMAGEMASK; - if (branch[i].iMode) - iState = ((db_get_dw(0, CHAT_MODULE, branch[i].szDBName, defaultval)&branch[i].iMode)&branch[i].iMode) != 0 ? 2 : 1; - else - iState = db_get_b(0, CHAT_MODULE, branch[i].szDBName, branch[i].bDefault) != 0 ? 2 : 1; - tvis.item.state = INDEXTOSTATEIMAGEMASK(iState); - branch[i].hItem = TreeView_InsertItem(hwndTree, &tvis); - } -} - -static void SaveBranch(HWND hwndTree, struct branch_t *branch, int nValues) -{ - int iState = 0; - - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_STATE; - for (int i = 0; i < nValues; i++) { - tvi.hItem = branch[i].hItem; - TreeView_GetItem(hwndTree, &tvi); - BYTE bChecked = ((tvi.state&TVIS_STATEIMAGEMASK) >> 12 == 1) ? 0 : 1; - if (branch[i].iMode) { - if (bChecked) - iState |= branch[i].iMode; - if (iState&GC_EVENT_ADDSTATUS) - iState |= GC_EVENT_REMOVESTATUS; - db_set_dw(0, CHAT_MODULE, branch[i].szDBName, (DWORD)iState); - } - else db_set_b(0, CHAT_MODULE, branch[i].szDBName, bChecked); - } -} - -static void CheckHeading(HWND hwndTree, HTREEITEM hHeading) -{ - BOOL bChecked = TRUE; - - if (hHeading == 0) - return; - - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_STATE; - tvi.hItem = TreeView_GetNextItem(hwndTree, hHeading, TVGN_CHILD); - while (tvi.hItem && bChecked) { - if (tvi.hItem != branch1[0].hItem && tvi.hItem != branch1[1].hItem) { - TreeView_GetItem(hwndTree, &tvi); - if (((tvi.state&TVIS_STATEIMAGEMASK) >> 12 == 1)) - bChecked = FALSE; - } - tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); - } - tvi.stateMask = TVIS_STATEIMAGEMASK; - tvi.state = INDEXTOSTATEIMAGEMASK(bChecked ? 2 : 1); - tvi.hItem = hHeading; - TreeView_SetItem(hwndTree, &tvi); -} - -static void CheckBranches(HWND hwndTree, HTREEITEM hHeading) -{ - BOOL bChecked = TRUE; - TVITEM tvi; - - if (hHeading == 0) - return; - - tvi.mask = TVIF_HANDLE | TVIF_STATE; - tvi.hItem = hHeading; - TreeView_GetItem(hwndTree, &tvi); - if (((tvi.state & TVIS_STATEIMAGEMASK) >> 12 == 2)) - bChecked = FALSE; - tvi.hItem = TreeView_GetNextItem(hwndTree, hHeading, TVGN_CHILD); - tvi.stateMask = TVIS_STATEIMAGEMASK; - while (tvi.hItem) { - tvi.state = INDEXTOSTATEIMAGEMASK(bChecked ? 2 : 1); - if (tvi.hItem != branch1[0].hItem && tvi.hItem != branch1[1].hItem) - TreeView_SetItem(hwndTree, &tvi); - tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); - } -} - -static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) -{ - char szDir[MAX_PATH]; - switch (uMsg) { - case BFFM_INITIALIZED: - SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); - break; - case BFFM_SELCHANGED: - if (SHGetPathFromIDListA((LPITEMIDLIST)lp, szDir)) - SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir); - break; - } - return 0; -} - -static void InitSetting(wchar_t **ppPointer, char *pszSetting, wchar_t *pszDefault) -{ - DBVARIANT dbv; - if (!db_get_ws(0, CHAT_MODULE, pszSetting, &dbv)) { - replaceStrW(*ppPointer, dbv.ptszVal); - db_free(&dbv); - } - else replaceStrW(*ppPointer, pszDefault); -} - -#define OPT_FIXHEADINGS (WM_USER+1) - -INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - static HTREEITEM hListHeading1 = 0; - static HTREEITEM hListHeading4 = 0; - switch (uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); - SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_SETRANGE, 0, MAKELONG(255, 10)); - SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_SETPOS, 0, MAKELONG(db_get_b(0, CHAT_MODULE, "NicklistRowDist", 12), 0)); - hListHeading1 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), TranslateT("Appearance and functionality of chat windows"), db_get_b(0, CHAT_MODULE, "Branch1Exp", 0) ? TRUE : FALSE); - hListHeading4 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), TranslateT("Icons to display in the tray"), db_get_b(0, CHAT_MODULE, "Branch5Exp", 0) ? TRUE : FALSE); - FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1, branch1, _countof(branch1), 0); - FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4, branch4, _countof(branch4), 0x1000); - SendMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); - { - wchar_t* pszGroup = nullptr; - InitSetting(&pszGroup, "AddToGroup", L"Chat rooms"); - SetDlgItemText(hwndDlg, IDC_CHAT_GROUP, pszGroup); - mir_free(pszGroup); - } - break; - - case OPT_FIXHEADINGS: - CheckHeading(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1); - CheckHeading(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4); - break; - - case WM_COMMAND: - if ((LOWORD(wParam) == IDC_CHAT_NICKROW || LOWORD(wParam) == IDC_CHAT_GROUP) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) - return 0; - - if (lParam != 0) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - - case UM_CHECKSTATECHANGE: - { - TVITEM tvi = { 0 }; - tvi.mask = TVIF_HANDLE | TVIF_STATE; - tvi.hItem = (HTREEITEM)lParam; - TreeView_GetItem((HWND)wParam, &tvi); - if (tvi.hItem == hListHeading1) - CheckBranches(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1); - else if (tvi.hItem == hListHeading4) - CheckBranches(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4); - else - PostMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case IDC_CHAT_CHECKBOXES: - if (((LPNMHDR)lParam)->code == NM_CLICK) { - TVHITTESTINFO hti; - hti.pt.x = (short)LOWORD(GetMessagePos()); - hti.pt.y = (short)HIWORD(GetMessagePos()); - ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); - if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) - if (hti.flags&TVHT_ONITEMSTATEICON) { - SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, (LPARAM)hti.hItem); - } - - } - else if (((LPNMHDR)lParam)->code == TVN_KEYDOWN) { - if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE) - SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, - (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom)); - } - break; - - case 0: - switch (((LPNMHDR)lParam)->code) { - case PSN_APPLY: - int iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_GROUP)); - if (iLen > 0) { - ptrA pszText((char*)mir_alloc(iLen + 1)); - GetDlgItemTextA(hwndDlg, IDC_CHAT_GROUP, pszText, iLen + 1); - db_set_s(0, CHAT_MODULE, "AddToGroup", pszText); - } - else db_set_s(0, CHAT_MODULE, "AddToGroup", ""); - - iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_GETPOS, 0, 0); - if (iLen > 0) - db_set_b(0, CHAT_MODULE, "NicklistRowDist", (BYTE)iLen); - else - db_unset(0, CHAT_MODULE, "NicklistRowDist"); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch1, _countof(branch1)); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch4, _countof(branch4)); - - pci->ReloadSettings(); - Chat_UpdateOptions(); - } - return TRUE; - } - break; - - case WM_DESTROY: - BYTE b = TreeView_GetItemState(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1, TVIS_EXPANDED)&TVIS_EXPANDED ? 1 : 0; - db_set_b(0, CHAT_MODULE, "Branch1Exp", b); - b = TreeView_GetItemState(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4, TVIS_EXPANDED)&TVIS_EXPANDED ? 1 : 0; - db_set_b(0, CHAT_MODULE, "Branch5Exp", b); - break; - } - return FALSE; -} - -INT_PTR CALLBACK DlgProcOptions2(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - static HTREEITEM hListHeading2 = 0; - static HTREEITEM hListHeading3 = 0; - - switch (uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); - SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_SETRANGE, 0, MAKELONG(5000, 0)); - SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_SETPOS, 0, MAKELONG(db_get_w(0, CHAT_MODULE, "LogLimit", 100), 0)); - SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN3, UDM_SETRANGE, 0, MAKELONG(10000, 0)); - SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN3, UDM_SETPOS, 0, MAKELONG(db_get_w(0, CHAT_MODULE, "LoggingLimit", 100), 0)); - { - wchar_t tszTemp[MAX_PATH]; - PathToRelativeW(g_Settings.pszLogDir, tszTemp); - SetDlgItemText(hwndDlg, IDC_CHAT_LOGDIRECTORY, tszTemp); - } - - wchar_t tszTooltipText[2048]; - RECT rect; - - mir_snwprintf(tszTooltipText, - L"%s - %s\n%s - %s\n%s - %s\n%s - %s\n\n" - L"%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n\n" - L"%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s", - // contact vars - L"%nick%", TranslateT("nick of current contact (if defined)"), - L"%proto%", TranslateT("protocol name of current contact (if defined). Account name is used when protocol supports multiple accounts"), - L"%accountname%", TranslateT("user-defined account name of current contact (if defined)."), - L"%userid%", TranslateT("user ID of current contact (if defined). It is like UIN for ICQ, JID for Jabber, etc."), - // global vars - L"%miranda_path%", TranslateT("path to Miranda root folder"), - L"%miranda_profilesdir%", TranslateT("path to folder containing Miranda profiles"), - L"%miranda_profilename%", TranslateT("name of current Miranda profile (filename, without extension)"), - L"%miranda_userdata%", TranslateT("will return parsed string %miranda_profilesdir%\\%miranda_profilename%"), - L"%miranda_logpath%", TranslateT("will return parsed string %miranda_userdata%\\Logs"), - L"%appdata%", TranslateT("same as environment variable %APPDATA% for currently logged-on Windows user"), - L"%username%", TranslateT("username for currently logged-on Windows user"), - L"%mydocuments%", TranslateT("\"My Documents\" folder for currently logged-on Windows user"), - L"%desktop%", TranslateT("\"Desktop\" folder for currently logged-on Windows user"), - L"%xxxxxxx%", TranslateT("any environment variable defined in current Windows session (like %systemroot%, %allusersprofile%, etc.)"), - // date/time vars - L"%d%", TranslateT("day of month, 1-31"), - L"%dd%", TranslateT("day of month, 01-31"), - L"%m%", TranslateT("month number, 1-12"), - L"%mm%", TranslateT("month number, 01-12"), - L"%mon%", TranslateT("abbreviated month name"), - L"%month%", TranslateT("full month name"), - L"%yy%", TranslateT("year without century, 01-99"), - L"%yyyy%", TranslateT("year with century, 1901-9999"), - L"%wday%", TranslateT("abbreviated weekday name"), - L"%weekday%", TranslateT("full weekday name")); - GetClientRect(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY), &rect); - rect.left = -85; - hPathTip = CreateToolTip(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY), tszTooltipText, TranslateT("Variables"), &rect); - SetTimer(hwndDlg, 0, 3000, nullptr); - - SetDlgItemText(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS, g_Settings.pszHighlightWords); - SetDlgItemText(hwndDlg, IDC_CHAT_LOGTIMESTAMP, g_Settings.pszTimeStampLog); - SetDlgItemText(hwndDlg, IDC_CHAT_TIMESTAMP, g_Settings.pszTimeStamp); - SetDlgItemText(hwndDlg, IDC_CHAT_OUTSTAMP, g_Settings.pszOutgoingNick); - SetDlgItemText(hwndDlg, IDC_CHAT_INSTAMP, g_Settings.pszIncomingNick); - CheckDlgButton(hwndDlg, IDC_CHAT_HIGHLIGHT, g_Settings.bHighlightEnabled ? BST_CHECKED : BST_UNCHECKED); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS), g_Settings.bHighlightEnabled ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHAT_LOGGING, g_Settings.bLoggingEnabled ? BST_CHECKED : BST_UNCHECKED); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY), g_Settings.bLoggingEnabled ? TRUE : FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRCHOOSE), g_Settings.bLoggingEnabled ? TRUE : FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIMIT), g_Settings.bLoggingEnabled ? TRUE : FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIMITTEXT2), g_Settings.bLoggingEnabled ? TRUE : FALSE); - - hListHeading2 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), TranslateT("Appearance"), db_get_b(0, CHAT_MODULE, "Branch2Exp", 0) ? TRUE : FALSE); - hListHeading3 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), TranslateT("Default events to show in new chat rooms if the 'event filter' is enabled"), db_get_b(0, CHAT_MODULE, "Branch3Exp", 0) ? TRUE : FALSE); - FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading2, branch2, _countof(branch2), 0x0); - FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading3, branch3, _countof(branch3), 0x03E0); - SendMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); - break; - - case OPT_FIXHEADINGS: - CheckHeading(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading2); - CheckHeading(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading3); - break; - - case WM_COMMAND: - if ((LOWORD(wParam) == IDC_CHAT_INSTAMP - || LOWORD(wParam) == IDC_CHAT_OUTSTAMP - || LOWORD(wParam) == IDC_CHAT_TIMESTAMP - || LOWORD(wParam) == IDC_CHAT_LOGLIMIT - || LOWORD(wParam) == IDC_CHAT_HIGHLIGHTWORDS - || LOWORD(wParam) == IDC_CHAT_LOGDIRECTORY - || LOWORD(wParam) == IDC_CHAT_LOGTIMESTAMP - || LOWORD(wParam) == IDC_CHAT_LIMIT) - && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0; - - switch (LOWORD(wParam)) { - case IDC_CHAT_LOGGING: - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY), IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRCHOOSE), IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIMIT), IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIMITTEXT2), IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE); - break; - - case IDC_CHAT_HIGHLIGHT: - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS), IsDlgButtonChecked(hwndDlg, IDC_CHAT_HIGHLIGHT) == BST_CHECKED ? TRUE : FALSE); - break; - - case IDC_CHAT_LOGDIRCHOOSE: - LPMALLOC psMalloc; - if (SUCCEEDED(CoGetMalloc(1, &psMalloc))) { - wchar_t tszDirectory[MAX_PATH], tszTemp[MAX_PATH]; - BROWSEINFO bi = { 0 }; - bi.hwndOwner = hwndDlg; - bi.pszDisplayName = tszDirectory; - bi.lpszTitle = TranslateT("Select folder"); - bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX | BIF_RETURNONLYFSDIRS; - bi.lpfn = BrowseCallbackProc; - bi.lParam = (LPARAM)tszDirectory; - - LPITEMIDLIST idList = SHBrowseForFolder(&bi); - if (idList) { - SHGetPathFromIDList(idList, tszDirectory); - mir_wstrcat(tszDirectory, L"\\"); - PathToRelativeW(tszDirectory, tszTemp); - SetDlgItemText(hwndDlg, IDC_CHAT_LOGDIRECTORY, mir_wstrlen(tszTemp) > 1 ? tszTemp : DEFLOGFILENAME); - } - psMalloc->Free(idList); - psMalloc->Release(); - } - break; - } - - if (lParam != 0) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - - case UM_CHECKSTATECHANGE: - { - TVITEM tvi = { 0 }; - tvi.mask = TVIF_HANDLE | TVIF_STATE; - tvi.hItem = (HTREEITEM)lParam; - TreeView_GetItem((HWND)wParam, &tvi); - if (tvi.hItem == hListHeading2) - CheckBranches(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading2); - else if (tvi.hItem == hListHeading3) - CheckBranches(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading3); - else - PostMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - break; - - case WM_NOTIFY: - if (((LPNMHDR)lParam)->idFrom == IDC_CHAT_CHECKBOXES) { - if (((LPNMHDR)lParam)->code == NM_CLICK) { - TVHITTESTINFO hti; - hti.pt.x = (short)LOWORD(GetMessagePos()); - hti.pt.y = (short)HIWORD(GetMessagePos()); - ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); - if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) - if (hti.flags&TVHT_ONITEMSTATEICON) { - SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, (LPARAM)hti.hItem); - } - } - else if (((LPNMHDR)lParam)->code == TVN_KEYDOWN) { - if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE) { - SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, - (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom)); - } - } - } - else if (((LPNMHDR)lParam)->idFrom == 0 && ((LPNMHDR)lParam)->code == PSN_APPLY) { - char *pszText = nullptr; - int iLen; - - iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS)); - if (iLen > 0) { - wchar_t *ptszText = (wchar_t*)mir_alloc((iLen + 2) * sizeof(wchar_t)); - wchar_t *p2 = nullptr; - - if (ptszText) { - GetDlgItemText(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS, ptszText, iLen + 1); - p2 = wcschr(ptszText, (wchar_t)','); - while (p2) { - *p2 = ' '; - p2 = wcschr(ptszText, (wchar_t)','); - } - db_set_ws(0, CHAT_MODULE, "HighlightWords", ptszText); - mir_free(ptszText); - } - } - else db_unset(0, CHAT_MODULE, "HighlightWords"); - - iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY)); - if (iLen > 0) { - wchar_t *pszText1 = (wchar_t*)malloc(iLen*sizeof(wchar_t) + 2); - GetDlgItemText(hwndDlg, IDC_CHAT_LOGDIRECTORY, pszText1, iLen + 1); - db_set_ws(0, CHAT_MODULE, "LogDirectory", pszText1); - free(pszText1); - } - else { - mir_wstrncpy(g_Settings.pszLogDir, DEFLOGFILENAME, MAX_PATH); - db_unset(0, CHAT_MODULE, "LogDirectory"); - } - pci->SM_InvalidateLogDirectories(); - - iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_LOGTIMESTAMP)); - if (iLen > 0) { - pszText = (char*)mir_realloc(pszText, iLen + 1); - GetDlgItemTextA(hwndDlg, IDC_CHAT_LOGTIMESTAMP, pszText, iLen + 1); - db_set_s(0, CHAT_MODULE, "LogTimestamp", pszText); - } - else db_unset(0, CHAT_MODULE, "LogTimestamp"); - - iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_TIMESTAMP)); - if (iLen > 0) { - pszText = (char*)mir_realloc(pszText, iLen + 1); - GetDlgItemTextA(hwndDlg, IDC_CHAT_TIMESTAMP, pszText, iLen + 1); - db_set_s(0, CHAT_MODULE, "HeaderTime", pszText); - } - else db_unset(0, CHAT_MODULE, "HeaderTime"); - - iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_INSTAMP)); - if (iLen > 0) { - pszText = (char*)mir_realloc(pszText, iLen + 1); - GetDlgItemTextA(hwndDlg, IDC_CHAT_INSTAMP, pszText, iLen + 1); - db_set_s(0, CHAT_MODULE, "HeaderIncoming", pszText); - } - else db_unset(0, CHAT_MODULE, "HeaderIncoming"); - - iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_OUTSTAMP)); - if (iLen > 0) { - pszText = (char*)mir_realloc(pszText, iLen + 1); - GetDlgItemTextA(hwndDlg, IDC_CHAT_OUTSTAMP, pszText, iLen + 1); - db_set_s(0, CHAT_MODULE, "HeaderOutgoing", pszText); - } - else db_unset(0, CHAT_MODULE, "HeaderOutgoing"); - - g_Settings.bHighlightEnabled = IsDlgButtonChecked(hwndDlg, IDC_CHAT_HIGHLIGHT) == BST_CHECKED ? TRUE : FALSE; - db_set_b(0, CHAT_MODULE, "HighlightEnabled", (BYTE)g_Settings.bHighlightEnabled); - - g_Settings.bLoggingEnabled = IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE; - db_set_b(0, CHAT_MODULE, "LoggingEnabled", (BYTE)g_Settings.bLoggingEnabled); - - iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_GETPOS, 0, 0); - db_set_w(0, CHAT_MODULE, "LogLimit", (WORD)iLen); - iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN3, UDM_GETPOS, 0, 0); - db_set_w(0, CHAT_MODULE, "LoggingLimit", (WORD)iLen); - - SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch2, _countof(branch2)); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch3, _countof(branch3)); - - mir_free(pszText); - - g_Settings.dwIconFlags = db_get_dw(0, CHAT_MODULE, "IconFlags", 0x0000); - g_Settings.dwTrayIconFlags = db_get_dw(0, CHAT_MODULE, "TrayIconFlags", 0x1000); - g_Settings.dwPopupFlags = db_get_dw(0, CHAT_MODULE, "PopupFlags", 0x0000); - g_Settings.bStripFormat = db_get_b(0, CHAT_MODULE, "TrimFormatting", 0) != 0; - g_Settings.bTrayIconInactiveOnly = db_get_b(0, CHAT_MODULE, "TrayIconInactiveOnly", 1) != 0; - g_Settings.bPopupInactiveOnly = db_get_b(0, CHAT_MODULE, "PopUpInactiveOnly", 1) != 0; - g_Settings.bLogIndentEnabled = (db_get_b(0, CHAT_MODULE, "LogIndentEnabled", 1) != 0) ? TRUE : FALSE; - - pci->MM_FontsChanged(); - pci->ReloadSettings(); - Chat_UpdateOptions(); - return TRUE; - } - break; - - case WM_TIMER: - if (IsWindow(hPathTip)) - KillTimer(hPathTip, 4); // It will prevent tooltip autoclosing - break; - - case WM_DESTROY: - if (hPathTip) { - KillTimer(hwndDlg, 0); - DestroyWindow(hPathTip); - hPathTip = 0; - } - - BYTE b = TreeView_GetItemState(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading2, TVIS_EXPANDED)&TVIS_EXPANDED ? 1 : 0; - db_set_b(0, CHAT_MODULE, "Branch2Exp", b); - b = TreeView_GetItemState(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading3, TVIS_EXPANDED)&TVIS_EXPANDED ? 1 : 0; - db_set_b(0, CHAT_MODULE, "Branch3Exp", b); - break; - } - return FALSE; -} - -INT_PTR CALLBACK DlgProcOptionsPopup(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch (uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); - SendDlgItemMessage(hwndDlg, IDC_CHAT_BKG, CPM_SETCOLOUR, 0, g_Settings.crPUBkgColour); - SendDlgItemMessage(hwndDlg, IDC_CHAT_TEXT, CPM_SETCOLOUR, 0, g_Settings.crPUTextColour); - - if (g_Settings.iPopupStyle == 2) - CheckDlgButton(hwndDlg, IDC_CHAT_RADIO2, BST_CHECKED); - else if (g_Settings.iPopupStyle == 3) - CheckDlgButton(hwndDlg, IDC_CHAT_RADIO3, BST_CHECKED); - else - CheckDlgButton(hwndDlg, IDC_CHAT_RADIO1, BST_CHECKED); - - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_BKG), IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED ? TRUE : FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_TEXT), IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED ? TRUE : FALSE); - - SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN1, UDM_SETRANGE, 0, MAKELONG(100, -1)); - SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN1, UDM_SETPOS, 0, MAKELONG(g_Settings.iPopupTimeout, 0)); - FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), nullptr, branch6, _countof(branch6), 0x0000); - break; - - case WM_COMMAND: - if ((LOWORD(wParam) == IDC_CHAT_TIMEOUT) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) - return 0; - - if (lParam) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - - switch (LOWORD(wParam)) { - case IDC_CHAT_RADIO1: - case IDC_CHAT_RADIO2: - case IDC_CHAT_RADIO3: - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_BKG), IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED ? TRUE : FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_TEXT), IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED ? TRUE : FALSE); - } - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case IDC_CHAT_CHECKBOXES: - if (((LPNMHDR)lParam)->code == NM_CLICK) { - TVHITTESTINFO hti; - hti.pt.x = (short)LOWORD(GetMessagePos()); - hti.pt.y = (short)HIWORD(GetMessagePos()); - ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); - if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) - if (hti.flags & TVHT_ONITEMSTATEICON) - SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, (LPARAM)hti.hItem); - } - else if (((LPNMHDR)lParam)->code == TVN_KEYDOWN) { - if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE) - SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, - (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom)); - } - break; - - case 0: - switch (((LPNMHDR)lParam)->code) { - case PSN_APPLY: - int iLen; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO2) == BST_CHECKED) - iLen = 2; - else if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED) - iLen = 3; - else - iLen = 1; - - g_Settings.iPopupStyle = iLen; - db_set_b(0, CHAT_MODULE, "PopupStyle", (BYTE)iLen); - - iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN1, UDM_GETPOS, 0, 0); - g_Settings.iPopupTimeout = iLen; - db_set_w(0, CHAT_MODULE, "PopupTimeout", (WORD)iLen); - - g_Settings.crPUBkgColour = SendDlgItemMessage(hwndDlg, IDC_CHAT_BKG, CPM_GETCOLOUR, 0, 0); - db_set_dw(0, CHAT_MODULE, "PopupColorBG", (DWORD)SendDlgItemMessage(hwndDlg, IDC_CHAT_BKG, CPM_GETCOLOUR, 0, 0)); - g_Settings.crPUTextColour = SendDlgItemMessage(hwndDlg, IDC_CHAT_TEXT, CPM_GETCOLOUR, 0, 0); - db_set_dw(0, CHAT_MODULE, "PopupColorText", (DWORD)SendDlgItemMessage(hwndDlg, IDC_CHAT_TEXT, CPM_GETCOLOUR, 0, 0)); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch6, _countof(branch6)); - } - return TRUE; - } - break; - - case UM_CHECKSTATECHANGE: - PostMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - return FALSE; -} diff --git a/plugins/Scriver/src/chat/tools.cpp b/plugins/Scriver/src/chat/tools.cpp deleted file mode 100644 index 148410d125..0000000000 --- a/plugins/Scriver/src/chat/tools.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright (C) 2003 Jörgen Persson -Copyright 2003-2009 Miranda ICQ/IM project, - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "../stdafx.h" - -wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2) -{ - for (int i = 0; s1[i]; i++) - for (int j = i, k = 0; towlower(s1[j]) == towlower(s2[k]); j++, k++) - if (!s2[k + 1]) - return (wchar_t*)(s1 + i); - - return nullptr; -} - -UINT CreateGCMenu(HWND hwnd, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText) -{ - GCMENUITEMS gcmi = { 0 }; - HMENU hSubMenu = 0; - - *hMenu = GetSubMenu(g_hMenu, iIndex); - gcmi.pszID = si->ptszID; - gcmi.pszModule = si->pszModule; - gcmi.pszUID = pszUID; - - if (iIndex == 1) { - int iLen = GetRichTextLength(hwnd, CP_ACP, FALSE); - - EnableMenuItem(*hMenu, IDM_CLEAR, MF_ENABLED); - EnableMenuItem(*hMenu, ID_COPYALL, MF_ENABLED); - if (!iLen) { - EnableMenuItem(*hMenu, ID_COPYALL, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(*hMenu, IDM_CLEAR, MF_BYCOMMAND | MF_GRAYED); - } - - if (pszWordText && pszWordText[0]) { - wchar_t szMenuText[4096]; - mir_snwprintf(szMenuText, TranslateT("Look up '%s':"), pszWordText); - ModifyMenu(*hMenu, 4, MF_STRING | MF_BYPOSITION, 4, szMenuText); - SetSearchEngineIcons(*hMenu, g_dat.hSearchEngineIconList); - } - else ModifyMenu(*hMenu, 4, MF_STRING | MF_GRAYED | MF_BYPOSITION, 4, TranslateT("No word to look up")); - gcmi.Type = MENU_ON_LOG; - } - else if (iIndex == 0) { - wchar_t szTemp[50]; - if (pszWordText) - mir_snwprintf(szTemp, TranslateT("&Message %s"), pszWordText); - else - mir_wstrncpy(szTemp, TranslateT("&Message"), _countof(szTemp) - 1); - - if (mir_wstrlen(szTemp) > 40) - mir_wstrncpy(szTemp + 40, L"...", 4); - ModifyMenu(*hMenu, ID_MESS, MF_STRING | MF_BYCOMMAND, ID_MESS, szTemp); - gcmi.Type = MENU_ON_NICKLIST; - } - - NotifyEventHooks(pci->hBuildMenuEvent, 0, (WPARAM)&gcmi); - - if (gcmi.nItems > 0) - AppendMenu(*hMenu, MF_SEPARATOR, 0, 0); - - for (int i = 0; i < gcmi.nItems; i++) { - wchar_t *ptszText = TranslateW(gcmi.Item[i].pszDesc); - DWORD dwState = gcmi.Item[i].bDisabled ? MF_GRAYED : 0; - - if (gcmi.Item[i].uType == MENU_NEWPOPUP) { - hSubMenu = CreateMenu(); - AppendMenu(*hMenu, dwState | MF_POPUP, (UINT_PTR)hSubMenu, ptszText); - } - else if (gcmi.Item[i].uType == MENU_POPUPHMENU) - AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_POPUP, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_POPUPITEM) - AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_STRING, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_POPUPCHECK) - AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_CHECKED | MF_STRING, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_POPUPSEPARATOR) - AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, MF_SEPARATOR, 0, ptszText); - else if (gcmi.Item[i].uType == MENU_SEPARATOR) - AppendMenu(*hMenu, MF_SEPARATOR, 0, ptszText); - else if (gcmi.Item[i].uType == MENU_HMENU) - AppendMenu(*hMenu, dwState | MF_POPUP, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_ITEM) - AppendMenu(*hMenu, dwState | MF_STRING, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_CHECK) - AppendMenu(*hMenu, dwState | MF_CHECKED | MF_STRING, gcmi.Item[i].dwID, ptszText); - } - return TrackPopupMenu(*hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, nullptr); -} - -void DestroyGCMenu(HMENU *hMenu, int iIndex) -{ - MENUITEMINFO mii = { 0 }; - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_SUBMENU; - while(GetMenuItemInfo(*hMenu, iIndex, TRUE, &mii)) - { - if (mii.hSubMenu != nullptr) - DestroyMenu(mii.hSubMenu); - RemoveMenu(*hMenu, iIndex, MF_BYPOSITION); - } -} diff --git a/plugins/Scriver/src/chat/window.cpp b/plugins/Scriver/src/chat/window.cpp deleted file mode 100644 index ebdfc49dee..0000000000 --- a/plugins/Scriver/src/chat/window.cpp +++ /dev/null @@ -1,1637 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright (C) 2003 Jörgen Persson -Copyright 2003-2009 Miranda ICQ/IM project, - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "../stdafx.h" - -struct MESSAGESUBDATA -{ - time_t lastEnterTime; - wchar_t *szSearchQuery; - wchar_t *szSearchResult; - SESSION_INFO *lastSession; -}; - -static void TabAutoComplete(HWND hwnd, MESSAGESUBDATA *dat, SESSION_INFO *si) -{ - LRESULT lResult = (LRESULT)SendMessage(hwnd, EM_GETSEL, 0, 0); - int start = LOWORD(lResult), end = HIWORD(lResult); - SendMessage(hwnd, EM_SETSEL, end, end); - - GETTEXTEX gt = { 0 }; - gt.codepage = 1200; - int iLen = GetRichTextLength(hwnd, gt.codepage, TRUE); - if (iLen <= 0) - return; - - bool isTopic = false, isRoom = false; - wchar_t *pszName = nullptr; - wchar_t* pszText = (wchar_t*)mir_alloc(iLen + 100 * sizeof(wchar_t)); - gt.cb = iLen + 99 * sizeof(wchar_t); - gt.flags = GT_DEFAULT; - - SendMessage(hwnd, EM_GETTEXTEX, (WPARAM)>, (LPARAM)pszText); - if (start > 1 && pszText[start - 1] == ' ' && pszText[start - 2] == ':') - start -= 2; - - if (dat->szSearchResult != nullptr) { - int cbResult = (int)mir_wstrlen(dat->szSearchResult); - if (start >= cbResult && !wcsnicmp(dat->szSearchResult, pszText + start - cbResult, cbResult)) { - start -= cbResult; - goto LBL_SkipEnd; - } - } - - while (start > 0 && pszText[start - 1] != ' ' && pszText[start - 1] != 13 && pszText[start - 1] != VK_TAB) - start--; - -LBL_SkipEnd: - while (end < iLen && pszText[end] != ' ' && pszText[end] != 13 && pszText[end - 1] != VK_TAB) - end++; - - if (pszText[start] == '#') - isRoom = true; - else { - int topicStart = start; - while (topicStart >0 && (pszText[topicStart - 1] == ' ' || pszText[topicStart - 1] == 13 || pszText[topicStart - 1] == VK_TAB)) - topicStart--; - if (topicStart > 5 && wcsstr(&pszText[topicStart - 6], L"/topic") == &pszText[topicStart - 6]) - isTopic = true; - } - - if (dat->szSearchQuery == nullptr) { - dat->szSearchQuery = (wchar_t*)mir_alloc(sizeof(wchar_t)*(end - start + 1)); - mir_wstrncpy(dat->szSearchQuery, pszText + start, end - start + 1); - dat->szSearchResult = mir_wstrdup(dat->szSearchQuery); - dat->lastSession = nullptr; - } - - if (isTopic) - pszName = si->ptszTopic; - else if (isRoom) { - dat->lastSession = SM_FindSessionAutoComplete(si->pszModule, si, dat->lastSession, dat->szSearchQuery, dat->szSearchResult); - if (dat->lastSession != nullptr) - pszName = dat->lastSession->ptszName; - } - else pszName = pci->UM_FindUserAutoComplete(si->pUsers, dat->szSearchQuery, dat->szSearchResult); - - mir_free(pszText); - replaceStrW(dat->szSearchResult, nullptr); - - if (pszName == nullptr) { - if (end != start) { - SendMessage(hwnd, EM_SETSEL, start, end); - SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)dat->szSearchQuery); - } - replaceStrW(dat->szSearchQuery, nullptr); - } - else { - dat->szSearchResult = mir_wstrdup(pszName); - if (end != start) { - ptrW szReplace; - if (!isRoom && !isTopic && g_Settings.bAddColonToAutoComplete && start == 0) { - szReplace = (wchar_t*)mir_alloc((mir_wstrlen(pszName) + 4) * sizeof(wchar_t)); - mir_wstrcpy(szReplace, pszName); - mir_wstrcat(szReplace, L": "); - pszName = szReplace; - } - SendMessage(hwnd, EM_SETSEL, start, end); - SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)pszName); - } - } -} - -LRESULT CALLBACK CChatRoomDlg::MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - BOOL isShift = GetKeyState(VK_SHIFT) & 0x8000; - BOOL isCtrl = GetKeyState(VK_CONTROL) & 0x8000; - BOOL isAlt = GetKeyState(VK_MENU) & 0x8000; - - MESSAGESUBDATA *dat = (MESSAGESUBDATA *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - CChatRoomDlg *pDlg = (CChatRoomDlg*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - - int result = InputAreaShortcuts(hwnd, msg, wParam, lParam, pDlg); - if (result != -1) - return result; - - switch (msg) { - case EM_SUBCLASSED: - dat = (MESSAGESUBDATA*)mir_calloc(sizeof(MESSAGESUBDATA)); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat); - return 0; - - case WM_MOUSEWHEEL: - if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_VSCROLL) == 0) - SendDlgItemMessage(GetParent(hwnd), IDC_LOG, WM_MOUSEWHEEL, wParam, lParam); - - dat->lastEnterTime = 0; - return TRUE; - - case EM_REPLACESEL: - PostMessage(hwnd, EM_ACTIVATE, 0, 0); - break; - - case EM_ACTIVATE: - SetActiveWindow(GetParent(hwnd)); - break; - - case WM_KEYDOWN: - if (wParam == VK_RETURN) { - mir_free(dat->szSearchQuery); - dat->szSearchQuery = nullptr; - mir_free(dat->szSearchResult); - dat->szSearchResult = nullptr; - if ((isCtrl != 0) ^ (0 != db_get_b(0, SRMMMOD, SRMSGSET_SENDONENTER, SRMSGDEFSET_SENDONENTER))) { - PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); - return 0; - } - if (db_get_b(0, SRMMMOD, SRMSGSET_SENDONDBLENTER, SRMSGDEFSET_SENDONDBLENTER)) { - if (dat->lastEnterTime + 2 < time(nullptr)) - dat->lastEnterTime = time(nullptr); - else { - SendMessage(hwnd, WM_KEYDOWN, VK_BACK, 0); - SendMessage(hwnd, WM_KEYUP, VK_BACK, 0); - PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); - return 0; - } - } - } - else dat->lastEnterTime = 0; - - if (wParam == VK_TAB && isShift && !isCtrl) { // SHIFT-TAB (go to nick list) - SetFocus(GetDlgItem(GetParent(hwnd), IDC_CHAT_LIST)); - return TRUE; - } - - if (wParam == VK_TAB && !isCtrl && !isShift) { //tab-autocomplete - SendMessage(hwnd, WM_SETREDRAW, FALSE, 0); - TabAutoComplete(hwnd, dat, pDlg->m_si); - SendMessage(hwnd, WM_SETREDRAW, TRUE, 0); - RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE); - return 0; - } - if (wParam != VK_RIGHT && wParam != VK_LEFT) { - mir_free(dat->szSearchQuery); - dat->szSearchQuery = nullptr; - mir_free(dat->szSearchResult); - dat->szSearchResult = nullptr; - } - if (wParam == 0x49 && isCtrl && !isAlt) { // ctrl-i (italics) - CheckDlgButton(GetParent(hwnd), IDC_ITALICS, IsDlgButtonChecked(GetParent(hwnd), IDC_ITALICS) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_ITALICS, 0), 0); - return TRUE; - } - - if (wParam == 0x42 && isCtrl && !isAlt) { // ctrl-b (bold) - CheckDlgButton(GetParent(hwnd), IDC_BOLD, IsDlgButtonChecked(GetParent(hwnd), IDC_BOLD) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BOLD, 0), 0); - return TRUE; - } - - if (wParam == 0x55 && isCtrl && !isAlt) { // ctrl-u (paste clean text) - CheckDlgButton(GetParent(hwnd), IDC_UNDERLINE, IsDlgButtonChecked(GetParent(hwnd), IDC_UNDERLINE) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_UNDERLINE, 0), 0); - return TRUE; - } - - if (wParam == 0x4b && isCtrl && !isAlt) { // ctrl-k (paste clean text) - CheckDlgButton(GetParent(hwnd), IDC_COLOR, IsDlgButtonChecked(GetParent(hwnd), IDC_COLOR) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_COLOR, 0), 0); - return TRUE; - } - - if (wParam == VK_SPACE && isCtrl && !isAlt) { // ctrl-space (paste clean text) - CheckDlgButton(GetParent(hwnd), IDC_BKGCOLOR, BST_UNCHECKED); - CheckDlgButton(GetParent(hwnd), IDC_COLOR, BST_UNCHECKED); - CheckDlgButton(GetParent(hwnd), IDC_BOLD, BST_UNCHECKED); - CheckDlgButton(GetParent(hwnd), IDC_UNDERLINE, BST_UNCHECKED); - CheckDlgButton(GetParent(hwnd), IDC_ITALICS, BST_UNCHECKED); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BKGCOLOR, 0), 0); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_COLOR, 0), 0); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BOLD, 0), 0); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_UNDERLINE, 0), 0); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_ITALICS, 0), 0); - return TRUE; - } - - if (wParam == 0x4c && isCtrl && !isAlt) { // ctrl-l (paste clean text) - CheckDlgButton(GetParent(hwnd), IDC_BKGCOLOR, IsDlgButtonChecked(GetParent(hwnd), IDC_BKGCOLOR) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BKGCOLOR, 0), 0); - return TRUE; - } - - if (wParam == 0x46 && isCtrl && !isAlt) { // ctrl-f (paste clean text) - if (IsWindowEnabled(GetDlgItem(GetParent(hwnd), IDC_FILTER))) - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_FILTER, 0), 0); - return TRUE; - } - - if (wParam == 0x4e && isCtrl && !isAlt) { // ctrl-n (nicklist) - if (IsWindowEnabled(GetDlgItem(GetParent(hwnd), IDC_SHOWNICKLIST))) - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_SHOWNICKLIST, 0), 0); - return TRUE; - } - - if (wParam == 0x48 && isCtrl && !isAlt) { // ctrl-h (history) - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_HISTORY, 0), 0); - return TRUE; - } - - if (wParam == 0x4f && isCtrl && !isAlt) { // ctrl-o (options) - if (IsWindowEnabled(GetDlgItem(GetParent(hwnd), IDC_CHANMGR))) - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_CHANMGR, 0), 0); - return TRUE; - } - - if (((wParam == VK_INSERT && isShift) || (wParam == 'V' && isCtrl)) && !isAlt) { // ctrl-v (paste clean text) - SendMessage(hwnd, EM_PASTESPECIAL, CF_UNICODETEXT, 0); - return TRUE; - } - - if (wParam == VK_NEXT || wParam == VK_PRIOR) { - HWND htemp = GetParent(hwnd); - SendDlgItemMessage(htemp, IDC_LOG, msg, wParam, lParam); - return TRUE; - } - break; - - case WM_LBUTTONDOWN: - case WM_MBUTTONDOWN: - case WM_KILLFOCUS: - dat->lastEnterTime = 0; - break; - - case WM_CONTEXTMENU: - InputAreaContextMenu(hwnd, wParam, lParam, pDlg->m_hContact); - return TRUE; - - case WM_KEYUP: - case WM_LBUTTONUP: - case WM_RBUTTONUP: - case WM_MBUTTONUP: - { - UINT u = 0; - UINT u2 = 0; - COLORREF cr; - SESSION_INFO *si = pDlg->m_si; - - LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, nullptr, &cr); - - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_BACKCOLOR | CFM_COLOR; - SendMessage(hwnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); - - if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bColor) { - int index = pci->GetColorIndex(si->pszModule, cf.crTextColor); - u = IsDlgButtonChecked(GetParent(hwnd), IDC_COLOR); - - if (index >= 0) { - pDlg->m_bFGSet = true; - pDlg->m_iFG = index; - } - - if (u == BST_UNCHECKED && cf.crTextColor != cr) - CheckDlgButton(GetParent(hwnd), IDC_COLOR, BST_CHECKED); - else if (u == BST_CHECKED && cf.crTextColor == cr) - CheckDlgButton(GetParent(hwnd), IDC_COLOR, BST_UNCHECKED); - } - - if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bBkgColor) { - int index = pci->GetColorIndex(si->pszModule, cf.crBackColor); - COLORREF crB = db_get_dw(0, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); - u = IsDlgButtonChecked(GetParent(hwnd), IDC_BKGCOLOR); - - if (index >= 0) { - pDlg->m_bBGSet = TRUE; - pDlg->m_iBG = index; - } - if (u == BST_UNCHECKED && cf.crBackColor != crB) - CheckDlgButton(GetParent(hwnd), IDC_BKGCOLOR, BST_CHECKED); - else if (u == BST_CHECKED && cf.crBackColor == crB) - CheckDlgButton(GetParent(hwnd), IDC_BKGCOLOR, BST_UNCHECKED); - } - - if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bBold) { - u = IsDlgButtonChecked(GetParent(hwnd), IDC_BOLD); - u2 = cf.dwEffects; - u2 &= CFE_BOLD; - if (u == BST_UNCHECKED && u2) - CheckDlgButton(GetParent(hwnd), IDC_BOLD, BST_CHECKED); - else if (u == BST_CHECKED && u2 == 0) - CheckDlgButton(GetParent(hwnd), IDC_BOLD, BST_UNCHECKED); - } - - if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bItalics) { - u = IsDlgButtonChecked(GetParent(hwnd), IDC_ITALICS); - u2 = cf.dwEffects; - u2 &= CFE_ITALIC; - if (u == BST_UNCHECKED && u2) - CheckDlgButton(GetParent(hwnd), IDC_ITALICS, BST_CHECKED); - else if (u == BST_CHECKED && u2 == 0) - CheckDlgButton(GetParent(hwnd), IDC_ITALICS, BST_UNCHECKED); - } - - if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bUnderline) { - u = IsDlgButtonChecked(GetParent(hwnd), IDC_UNDERLINE); - u2 = cf.dwEffects; - u2 &= CFE_UNDERLINE; - if (u == BST_UNCHECKED && u2) - CheckDlgButton(GetParent(hwnd), IDC_UNDERLINE, BST_CHECKED); - else if (u == BST_CHECKED && u2 == 0) - CheckDlgButton(GetParent(hwnd), IDC_UNDERLINE, BST_UNCHECKED); - } - } - break; - - case WM_DESTROY: - mir_free(dat->szSearchQuery); - mir_free(dat->szSearchResult); - mir_free(dat); - return 0; - } - - return mir_callNextSubclass(hwnd, MessageSubclassProc, msg, wParam, lParam); -} - -INT_PTR CALLBACK CChatRoomDlg::FilterWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - static CChatRoomDlg *pDlg = nullptr; - switch (uMsg) { - case WM_INITDIALOG: - pDlg = (CChatRoomDlg*)lParam; - CheckDlgButton(hwndDlg, IDC_CHAT_1, pDlg->m_iLogFilterFlags & GC_EVENT_ACTION ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_2, pDlg->m_iLogFilterFlags & GC_EVENT_MESSAGE ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_3, pDlg->m_iLogFilterFlags & GC_EVENT_NICK ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_4, pDlg->m_iLogFilterFlags & GC_EVENT_JOIN ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_5, pDlg->m_iLogFilterFlags & GC_EVENT_PART ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_6, pDlg->m_iLogFilterFlags & GC_EVENT_TOPIC ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_7, pDlg->m_iLogFilterFlags & GC_EVENT_ADDSTATUS ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_8, pDlg->m_iLogFilterFlags & GC_EVENT_INFORMATION ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_9, pDlg->m_iLogFilterFlags & GC_EVENT_QUIT ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_10, pDlg->m_iLogFilterFlags & GC_EVENT_KICK ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHAT_11, pDlg->m_iLogFilterFlags & GC_EVENT_NOTICE ? BST_CHECKED : BST_UNCHECKED); - break; - - case WM_CTLCOLOREDIT: - case WM_CTLCOLORSTATIC: - SetTextColor((HDC)wParam, RGB(60, 60, 150)); - SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); - return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); - - case WM_ACTIVATE: - if (LOWORD(wParam) == WA_INACTIVE) { - int iFlags = 0; - - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_1) == BST_CHECKED) - iFlags |= GC_EVENT_ACTION; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_2) == BST_CHECKED) - iFlags |= GC_EVENT_MESSAGE; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_3) == BST_CHECKED) - iFlags |= GC_EVENT_NICK; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_4) == BST_CHECKED) - iFlags |= GC_EVENT_JOIN; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_5) == BST_CHECKED) - iFlags |= GC_EVENT_PART; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_6) == BST_CHECKED) - iFlags |= GC_EVENT_TOPIC; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_7) == BST_CHECKED) - iFlags |= GC_EVENT_ADDSTATUS; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_8) == BST_CHECKED) - iFlags |= GC_EVENT_INFORMATION; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_9) == BST_CHECKED) - iFlags |= GC_EVENT_QUIT; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_10) == BST_CHECKED) - iFlags |= GC_EVENT_KICK; - if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_11) == BST_CHECKED) - iFlags |= GC_EVENT_NOTICE; - - if (iFlags & GC_EVENT_ADDSTATUS) - iFlags |= GC_EVENT_REMOVESTATUS; - - pDlg->m_iLogFilterFlags = iFlags; - if (pDlg->m_bFilterEnabled) - pDlg->RedrawLog(); - PostMessage(hwndDlg, WM_CLOSE, 0, 0); - } - break; - - case WM_CLOSE: - DestroyWindow(hwndDlg); - break; - } - - return FALSE; -} - -LRESULT CALLBACK CChatRoomDlg::LogSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - static BOOL inMenu = FALSE; - CChatRoomDlg *pDlg = (CChatRoomDlg*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - - int result = InputAreaShortcuts(hwnd, msg, wParam, lParam, pDlg); - if (result != -1) - return result; - - CHARRANGE sel; - - switch (msg) { - case WM_MEASUREITEM: - MeasureMenuItem(wParam, lParam); - return TRUE; - - case WM_DRAWITEM: - return DrawMenuItem(wParam, lParam); - - case WM_SETCURSOR: - if (inMenu) { - SetCursor(LoadCursor(nullptr, IDC_ARROW)); - return TRUE; - } - break; - - case WM_LBUTTONUP: - SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); - if (sel.cpMin != sel.cpMax) { - SendMessage(hwnd, WM_COPY, 0, 0); - sel.cpMin = sel.cpMax; - SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); - } - SetFocus(GetDlgItem(GetParent(hwnd), IDC_MESSAGE)); - break; - - case WM_ACTIVATE: - if (LOWORD(wParam) == WA_INACTIVE) { - SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); - if (sel.cpMin != sel.cpMax) { - sel.cpMin = sel.cpMax; - SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); - } - } - break; - - case WM_CONTEXTMENU: - POINT pt; - POINTL ptl; - SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); - if (lParam == 0xFFFFFFFF) { - SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM)sel.cpMax); - ClientToScreen(hwnd, &pt); - } - else { - pt.x = GET_X_LPARAM(lParam); - pt.y = GET_Y_LPARAM(lParam); - } - ptl.x = (LONG)pt.x; - ptl.y = (LONG)pt.y; - ScreenToClient(hwnd, (LPPOINT)&ptl); - { - ptrW pszWord(GetRichTextWord(hwnd, &ptl)); - inMenu = TRUE; - - SESSION_INFO *si = pDlg->m_si; - CHARRANGE all = { 0, -1 }; - HMENU hMenu = nullptr; - UINT uID = CreateGCMenu(hwnd, &hMenu, 1, pt, si, nullptr, pszWord); - inMenu = FALSE; - switch (uID) { - case 0: - PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); - break; - - case ID_COPYALL: - SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); - SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&all); - SendMessage(hwnd, WM_COPY, 0, 0); - SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); - PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); - break; - - case IDM_CLEAR: - if (si) { - SetWindowText(hwnd, L""); - pci->LM_RemoveAll(&si->pLog, &si->pLogEnd); - si->iEventCount = 0; - si->LastTime = 0; - PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); - } - break; - - case IDM_SEARCH_GOOGLE: - case IDM_SEARCH_BING: - case IDM_SEARCH_YANDEX: - case IDM_SEARCH_YAHOO: - case IDM_SEARCH_WIKIPEDIA: - case IDM_SEARCH_FOODNETWORK: - case IDM_SEARCH_GOOGLE_MAPS: - case IDM_SEARCH_GOOGLE_TRANSLATE: - SearchWord(pszWord, uID - IDM_SEARCH_GOOGLE + SEARCHENGINE_GOOGLE); - PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); - break; - - default: - PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); - pDlg->DoEventHook(GC_USER_LOGMENU, nullptr, nullptr, uID); - break; - } - DestroyGCMenu(&hMenu, 5); - } - break; - - case WM_CHAR: - SetFocus(GetDlgItem(GetParent(hwnd), IDC_MESSAGE)); - SendDlgItemMessage(GetParent(hwnd), IDC_MESSAGE, WM_CHAR, wParam, lParam); - break; - } - - return mir_callNextSubclass(hwnd, LogSubclassProc, msg, wParam, lParam); -} - -LRESULT CALLBACK CChatRoomDlg::NicklistSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - CChatRoomDlg *pDlg = (CChatRoomDlg*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - - int result = InputAreaShortcuts(hwnd, msg, wParam, lParam, pDlg); - if (result != -1) - return result; - - switch (msg) { - case WM_ERASEBKGND: - { - HDC dc = (HDC)wParam; - if (dc) { - int index = SendMessage(hwnd, LB_GETTOPINDEX, 0, 0); - if (index == LB_ERR || pDlg->m_si->nUsersInNicklist <= 0) - return 0; - - int items = pDlg->m_si->nUsersInNicklist - index; - int height = SendMessage(hwnd, LB_GETITEMHEIGHT, 0, 0); - - if (height != LB_ERR) { - RECT rc = { 0 }; - GetClientRect(hwnd, &rc); - - if (rc.bottom - rc.top > items * height) { - rc.top = items*height; - FillRect(dc, &rc, pci->hListBkgBrush); - } - } - } - } - return 1; - - case WM_RBUTTONDOWN: - SendMessage(hwnd, WM_LBUTTONDOWN, wParam, lParam); - break; - - case WM_RBUTTONUP: - SendMessage(hwnd, WM_LBUTTONUP, wParam, lParam); - break; - - case WM_MEASUREITEM: - { - MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam; - if (mis->CtlType == ODT_MENU) - return Menu_MeasureItem(lParam); - } - return FALSE; - - case WM_DRAWITEM: - { - DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; - if (dis->CtlType == ODT_MENU) - return Menu_DrawItem(lParam); - } - return FALSE; - - case WM_CONTEXTMENU: - { - int height = 0; - - TVHITTESTINFO hti; - hti.pt.x = GET_X_LPARAM(lParam); - hti.pt.y = GET_Y_LPARAM(lParam); - if (hti.pt.x == -1 && hti.pt.y == -1) { - int index = SendMessage(hwnd, LB_GETCURSEL, 0, 0); - int top = SendMessage(hwnd, LB_GETTOPINDEX, 0, 0); - height = SendMessage(hwnd, LB_GETITEMHEIGHT, 0, 0); - hti.pt.x = 4; - hti.pt.y = (index - top)*height + 1; - } - else ScreenToClient(hwnd, &hti.pt); - - DWORD item = (DWORD)(SendMessage(hwnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(hti.pt.x, hti.pt.y))); - if (HIWORD(item) == 1) - item = (DWORD)(-1); - else - item &= 0xFFFF; - - USERINFO *ui = pci->SM_GetUserFromIndex(pDlg->m_si->ptszID, pDlg->m_si->pszModule, (int)item); - if (ui) { - HMENU hMenu = 0; - UINT uID; - USERINFO uinew; - - memcpy(&uinew, ui, sizeof(USERINFO)); - if (hti.pt.x == -1 && hti.pt.y == -1) - hti.pt.y += height - 4; - ClientToScreen(hwnd, &hti.pt); - uID = CreateGCMenu(hwnd, &hMenu, 0, hti.pt, pDlg->m_si, uinew.pszUID, uinew.pszNick); - - switch (uID) { - case 0: - break; - - case ID_MESS: - pDlg->DoEventHook(GC_USER_PRIVMESS, ui, nullptr, 0); - break; - - default: - pDlg->DoEventHook(GC_USER_NICKLISTMENU, ui, nullptr, uID); - break; - } - DestroyGCMenu(&hMenu, 1); - return TRUE; - } - } - break; - - case WM_GETDLGCODE: - { - BOOL isAlt = GetKeyState(VK_MENU) & 0x8000; - BOOL isCtrl = (GetKeyState(VK_CONTROL) & 0x8000) && !isAlt; - - LPMSG lpmsg; - if ((lpmsg = (LPMSG)lParam) != nullptr) { - if (lpmsg->message == WM_KEYDOWN - && (lpmsg->wParam == VK_RETURN || lpmsg->wParam == VK_ESCAPE || (lpmsg->wParam == VK_TAB && (isAlt || isCtrl)))) - return DLGC_WANTALLKEYS; - } - } - break; - - case WM_KEYDOWN: - if (wParam == VK_RETURN) { - int index = SendMessage(hwnd, LB_GETCURSEL, 0, 0); - if (index != LB_ERR) { - USERINFO *ui = pci->SM_GetUserFromIndex(pDlg->m_si->ptszID, pDlg->m_si->pszModule, index); - pDlg->DoEventHook(GC_USER_PRIVMESS, ui, nullptr, 0); - } - break; - } - if (wParam == VK_ESCAPE || wParam == VK_UP || wParam == VK_DOWN || wParam == VK_NEXT || - wParam == VK_PRIOR || wParam == VK_TAB || wParam == VK_HOME || wParam == VK_END) { - pDlg->m_wszSearch[0] = 0; - } - break; - - case WM_CHAR: - case WM_UNICHAR: - /* - * simple incremental search for the user (nick) - list control - * typing esc or movement keys will clear the current search string - */ - if (wParam == 27 && pDlg->m_wszSearch[0]) { // escape - reset everything - pDlg->m_wszSearch[0] = 0; - break; - } - else if (wParam == '\b' && pDlg->m_wszSearch[0]) // backspace - pDlg->m_wszSearch[mir_wstrlen(pDlg->m_wszSearch) - 1] = '\0'; - else if (wParam < ' ') - break; - else { - wchar_t szNew[2]; - szNew[0] = (wchar_t)wParam; - szNew[1] = '\0'; - if (mir_wstrlen(pDlg->m_wszSearch) >= _countof(pDlg->m_wszSearch) - 2) { - MessageBeep(MB_OK); - break; - } - mir_wstrcat(pDlg->m_wszSearch, szNew); - } - if (pDlg->m_wszSearch[0]) { - // iterate over the (sorted) list of nicknames and search for the - // string we have - int iItems = SendMessage(hwnd, LB_GETCOUNT, 0, 0); - for (int i = 0; i < iItems; i++) { - USERINFO *ui = pci->UM_FindUserFromIndex(pDlg->m_si->pUsers, i); - if (ui) { - if (!wcsnicmp(ui->pszNick, pDlg->m_wszSearch, mir_wstrlen(pDlg->m_wszSearch))) { - SendMessage(hwnd, LB_SETCURSEL, i, 0); - InvalidateRect(hwnd, nullptr, FALSE); - return 0; - } - } - } - - MessageBeep(MB_OK); - pDlg->m_wszSearch[mir_wstrlen(pDlg->m_wszSearch) - 1] = '\0'; - return 0; - } - break; - - case WM_MOUSEMOVE: - Chat_HoverMouse(pDlg->m_si, hwnd, lParam, ServiceExists("mToolTip/HideTip")); - break; - } - - return mir_callNextSubclass(hwnd, NicklistSubclassProc, msg, wParam, lParam); -} - -int GetTextPixelSize(wchar_t* pszText, HFONT hFont, BOOL bWidth) -{ - if (!pszText || !hFont) - return 0; - - HDC hdc = GetDC(nullptr); - HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); - - RECT rc = { 0 }; - DrawText(hdc, pszText, -1, &rc, DT_CALCRECT); - SelectObject(hdc, hOldFont); - ReleaseDC(nullptr, hdc); - return bWidth ? rc.right - rc.left : rc.bottom - rc.top; -} - -static void __cdecl phase2(void *lParam) -{ - Thread_SetName("Scriver: phase2"); - - SESSION_INFO *si = (SESSION_INFO*)lParam; - Sleep(30); - if (si && si->pDlg) - si->pDlg->RedrawLog2(); -} - -void CChatRoomDlg::FixTabIcons() -{ - HICON hIcon; - 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; - - TabControlData tcd = {}; - tcd.iFlags = TCDF_ICON; - tcd.hIcon = hIcon; - SendMessage(m_hwndParent, CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)m_hwnd); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -void CChatRoomDlg::MessageDialogResize(int w, int h) -{ - bool bNick = m_si->iType != GCW_SERVER && m_bNicklistEnabled; - bool bToolbar = SendMessage(m_hwndParent, CM_GETTOOLBARSTATUS, 0, 0) != 0; - int hSplitterMinTop = TOOLBAR_HEIGHT + m_minLogBoxHeight, hSplitterMinBottom = m_minEditBoxHeight; - int toolbarHeight = bToolbar ? TOOLBAR_HEIGHT : 0; - - if (h - m_pParent->iSplitterY < hSplitterMinTop) - m_pParent->iSplitterY = h - hSplitterMinTop; - if (m_pParent->iSplitterY < hSplitterMinBottom) - m_pParent->iSplitterY = hSplitterMinBottom; - - ShowWindow(m_splitterX.GetHwnd(), bNick ? SW_SHOW : SW_HIDE); - if (m_si->iType != GCW_SERVER) - ShowWindow(m_nickList.GetHwnd(), m_bNicklistEnabled ? SW_SHOW : SW_HIDE); - else - ShowWindow(m_nickList.GetHwnd(), SW_HIDE); - - if (m_si->iType == GCW_SERVER) { - m_btnShowList.Enable(false); - m_btnFilter.Enable(false); - m_btnChanMgr.Enable(false); - } - else { - m_btnShowList.Enable(true); - m_btnFilter.Enable(true); - if (m_si->iType == GCW_CHATROOM) - m_btnChanMgr.Enable(pci->MM_FindModule(m_si->pszModule)->bChanMgr); - } - - int toolbarTopY = bToolbar ? h - m_pParent->iSplitterY - toolbarHeight : h - m_pParent->iSplitterY; - int logBottom = (m_hwndIeview != nullptr) ? toolbarTopY / 2 : toolbarTopY; - - HDWP hdwp = BeginDeferWindowPos(5); - hdwp = DeferWindowPos(hdwp, m_log.GetHwnd(), 0, 1, 0, bNick ? w - m_pParent->iSplitterX - 1 : w - 2, logBottom, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, m_nickList.GetHwnd(), 0, w - m_pParent->iSplitterX + 2, 0, m_pParent->iSplitterX - 3, toolbarTopY, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, m_splitterX.GetHwnd(), 0, w - m_pParent->iSplitterX, 1, 2, toolbarTopY - 1, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, m_splitterY.GetHwnd(), 0, 0, h - m_pParent->iSplitterY, w, SPLITTER_HEIGHT, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, m_message.GetHwnd(), 0, 1, h - m_pParent->iSplitterY + SPLITTER_HEIGHT, w - 2, m_pParent->iSplitterY - SPLITTER_HEIGHT - 1, SWP_NOZORDER); - EndDeferWindowPos(hdwp); - - SetButtonsPos(m_hwnd, m_hContact, bToolbar); - - if (m_hwndIeview != nullptr) { - IEVIEWWINDOW ieWindow; - ieWindow.cbSize = sizeof(IEVIEWWINDOW); - ieWindow.iType = IEW_SETPOS; - ieWindow.parent = m_hwnd; - ieWindow.hwnd = m_hwndIeview; - ieWindow.x = 0; - ieWindow.y = logBottom + 1; - ieWindow.cx = bNick ? w - m_pParent->iSplitterX : w; - ieWindow.cy = logBottom; - CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); - } - else RedrawWindow(m_log.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); - - RedrawWindow(m_nickList.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); - RedrawWindow(m_message.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); -} - -CChatRoomDlg::CChatRoomDlg(SESSION_INFO *si) - : CScriverWindow(IDD_CHANNEL, si), - - m_log(this, IDC_LOG), - m_message(this, IDC_MESSAGE), - m_nickList(this, IDC_CHAT_LIST), - - m_splitterX(this, IDC_SPLITTERX), - m_splitterY(this, IDC_SPLITTERY), - - m_btnOk(this, IDOK), - m_btnBold(this, IDC_BOLD), - m_btnColor(this, IDC_COLOR), - m_btnFilter(this, IDC_FILTER), - m_btnItalic(this, IDC_ITALICS), - m_btnHistory(this, IDC_HISTORY), - m_btnChanMgr(this, IDC_CHANMGR), - m_btnBkColor(this, IDC_BKGCOLOR), - m_btnShowList(this, IDC_SHOWNICKLIST), - m_btnUnderline(this, IDC_UNDERLINE) -{ - m_pLog = &m_log; - m_pEntry = &m_message; - m_pColor = &m_btnColor; - m_pBkColor = &m_btnBkColor; - m_pFilter = &m_btnFilter; - - m_btnOk.OnClick = Callback(this, &CChatRoomDlg::onClick_Ok); - m_btnFilter.OnClick = Callback(this, &CChatRoomDlg::onClick_Filter); - m_btnHistory.OnClick = Callback(this, &CChatRoomDlg::onClick_History); - m_btnChanMgr.OnClick = Callback(this, &CChatRoomDlg::onClick_ChanMgr); - m_btnShowList.OnClick = Callback(this, &CChatRoomDlg::onClick_ShowList); - - m_btnBold.OnClick = Callback(this, &CChatRoomDlg::onClick_BIU); - m_btnItalic.OnClick = Callback(this, &CChatRoomDlg::onClick_BIU); - m_btnUnderline.OnClick = Callback(this, &CChatRoomDlg::onClick_BIU); - - m_btnColor.OnClick = Callback(this, &CChatRoomDlg::onClick_Color); - m_btnBkColor.OnClick = Callback(this, &CChatRoomDlg::onClick_BkColor); - - m_nickList.OnDblClick = Callback(this, &CChatRoomDlg::onDblClick_List); - - m_message.OnChange = Callback(this, &CChatRoomDlg::onChange_Message); - - m_splitterX.OnChange = Callback(this, &CChatRoomDlg::OnSplitterX); - m_splitterY.OnChange = Callback(this, &CChatRoomDlg::OnSplitterY); -} - -void CChatRoomDlg::OnInitDialog() -{ - m_si->pDlg = this; - - NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_OPENING); - - SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); - m_pParent = (ParentWindowData *)GetWindowLongPtr(m_hwndParent, GWLP_USERDATA); - - RichUtil_SubClass(m_message.GetHwnd()); - RichUtil_SubClass(m_log.GetHwnd()); - RichUtil_SubClass(m_nickList.GetHwnd()); - - mir_subclassWindow(m_log.GetHwnd(), LogSubclassProc); - mir_subclassWindow(m_message.GetHwnd(), MessageSubclassProc); - mir_subclassWindow(m_nickList.GetHwnd(), NicklistSubclassProc); - - mir_subclassWindow(m_btnFilter.GetHwnd(), Srmm_ButtonSubclassProc); - mir_subclassWindow(m_btnColor.GetHwnd(), Srmm_ButtonSubclassProc); - mir_subclassWindow(m_btnBkColor.GetHwnd(), Srmm_ButtonSubclassProc); - - Srmm_CreateToolbarIcons(m_hwnd, BBBF_ISCHATBUTTON); - - RECT rc; - GetWindowRect(m_message.GetHwnd(), &rc); - m_minLogBoxHeight = m_minEditBoxHeight = rc.bottom - rc.top; - if (m_pParent->iSplitterY == -1) - m_pParent->iSplitterY = m_minEditBoxHeight; - - if (m_pParent->iSplitterX == -1) { - GetWindowRect(m_nickList.GetHwnd(), &rc); - m_pParent->iSplitterX = rc.right - rc.left; - } - - 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(0, 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); - - m_hwndIeview = ieWindow.hwnd; - - IEVIEWEVENT iee = { sizeof(iee) }; - iee.iType = IEE_CLEAR_LOG; - iee.hwnd = m_hwndIeview; - iee.hContact = m_hContact; - iee.pszProto = m_si->pszModule; - CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&iee); - } - - m_log.SendMsg(EM_HIDESELECTION, TRUE, 0); - - UpdateOptions(); - UpdateStatusBar(); - UpdateTitle(); - - SendMessage(m_hwndParent, CM_ADDCHILD, (WPARAM)this, 0); - UpdateNickList(); - NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_OPEN); -} - -void CChatRoomDlg::OnDestroy() -{ - NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_CLOSING); - - m_si->pDlg = nullptr; - SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0); - - SendMessage(m_hwndParent, CM_REMOVECHILD, 0, (LPARAM)m_hwnd); - if (m_hwndIeview != nullptr) { - IEVIEWWINDOW ieWindow; - ieWindow.cbSize = sizeof(IEVIEWWINDOW); - ieWindow.iType = IEW_DESTROY; - ieWindow.hwnd = m_hwndIeview; - CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); - } - - NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_CLOSE); -} - -void CChatRoomDlg::OnSplitterX(CSplitter *pSplitter) -{ - RECT rc; - GetClientRect(m_hwnd, &rc); - - m_pParent->iSplitterX = rc.right - pSplitter->GetPos() + 1; - if (m_pParent->iSplitterX < 35) - m_pParent->iSplitterX = 35; - if (m_pParent->iSplitterX > rc.right - rc.left - 35) - m_pParent->iSplitterX = rc.right - rc.left - 35; -} - -void CChatRoomDlg::OnSplitterY(CSplitter *pSplitter) -{ - RECT rc; - GetClientRect(m_hwnd, &rc); - m_pParent->iSplitterY = rc.bottom - pSplitter->GetPos(); -} - -void CChatRoomDlg::onDblClick_List(CCtrlListBox*) -{ - 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 DoEventHook(GC_USER_PRIVMESS, ui, nullptr, 0); - } -} - -void CChatRoomDlg::onClick_Ok(CCtrlButton *pButton) -{ - if (!pButton->Enabled()) - return; - - char *pszRtf = GetRichTextRTF(m_message.GetHwnd()); - if (pszRtf == nullptr) - return; - - MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); - if (mi == nullptr) - return; - - TCmdList *cmdListNew = tcmdlist_last(cmdList); - while (cmdListNew != nullptr && cmdListNew->temporary) { - cmdList = tcmdlist_remove(cmdList, cmdListNew); - cmdListNew = tcmdlist_last(cmdList); - } - - // takes pszRtf to a queue, no leak here - cmdList = tcmdlist_append(cmdList, pszRtf, 20, FALSE); - - CMStringW ptszText(ptrW(mir_utf8decodeW(pszRtf))); - pci->DoRtfToTags(ptszText, mi->nColorCount, mi->crColors); - ptszText.Trim(); - ptszText.Replace(L"%", L"%%"); - - if (mi->bAckMsg) { - EnableWindow(m_message.GetHwnd(), FALSE); - m_message.SendMsg(EM_SETREADONLY, TRUE, 0); - } - else SetDlgItemText(m_hwnd, IDC_MESSAGE, L""); - - EnableWindow(m_btnOk.GetHwnd(), FALSE); - - DoEventHook(GC_USER_MESSAGE, nullptr, ptszText, 0); - SetFocus(m_message.GetHwnd()); -} - -void CChatRoomDlg::onClick_History(CCtrlButton *pButton) -{ - if (!pButton->Enabled()) - return; - - MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); - if (pInfo) - ShellExecute(m_hwnd, nullptr, pci->GetChatLogsFilename(m_si, 0), nullptr, nullptr, SW_SHOW); -} - -void CChatRoomDlg::onClick_ChanMgr(CCtrlButton *pButton) -{ - if (pButton->Enabled()) - DoEventHook(GC_USER_CHANMGR, nullptr, nullptr, 0); -} - -void CChatRoomDlg::onClick_ShowList(CCtrlButton *pButton) -{ - if (!pButton->Enabled() || m_si->iType == GCW_SERVER) - return; - - m_bNicklistEnabled = !m_bNicklistEnabled; - pButton->SendMsg(BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_bNicklistEnabled ? "chat_nicklist" : "chat_nicklist2")); - ScrollToBottom(); - SendMessage(m_hwnd, WM_SIZE, 0, 0); -} - -void CChatRoomDlg::onClick_Filter(CCtrlButton *pButton) -{ - if (!pButton->Enabled()) - return; - - m_bFilterEnabled = !m_bFilterEnabled; - pButton->SendMsg(BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_bFilterEnabled ? "chat_filter" : "chat_filter2")); - if (m_bFilterEnabled && db_get_b(0, CHAT_MODULE, "RightClickFilter", 0) == 0) - ShowFilterMenu(); - else - RedrawLog(); -} - -void CChatRoomDlg::onClick_BIU(CCtrlButton *pButton) -{ - if (!pButton->Enabled()) - return; - - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE; - cf.dwEffects = 0; - - if (IsDlgButtonChecked(m_hwnd, IDC_BOLD)) - cf.dwEffects |= CFE_BOLD; - if (IsDlgButtonChecked(m_hwnd, IDC_ITALICS)) - cf.dwEffects |= CFE_ITALIC; - if (IsDlgButtonChecked(m_hwnd, IDC_UNDERLINE)) - cf.dwEffects |= CFE_UNDERLINE; - m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); -} - -void CChatRoomDlg::onClick_Color(CCtrlButton *pButton) -{ - if (!pButton->Enabled()) - return; - - MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwEffects = 0; - - if (IsDlgButtonChecked(m_hwnd, IDC_COLOR)) { - if (db_get_b(0, CHAT_MODULE, "RightClickFilter", 0) == 0) - ShowColorChooser(IDC_COLOR); - else if (m_bFGSet) { - cf.dwMask = CFM_COLOR; - cf.crTextColor = pInfo->crColors[m_iFG]; - m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); - } - } - else { - COLORREF cr; - LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, nullptr, &cr); - cf.dwMask = CFM_COLOR; - cf.crTextColor = cr; - m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); - } -} - -void CChatRoomDlg::onClick_BkColor(CCtrlButton *pButton) -{ - if (!pButton->Enabled()) - return; - - MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwEffects = 0; - - if (IsDlgButtonChecked(m_hwnd, IDC_BKGCOLOR)) { - if (db_get_b(0, CHAT_MODULE, "RightClickFilter", 0) == 0) - ShowColorChooser(IDC_BKGCOLOR); - else if (m_bBGSet) { - cf.dwMask = CFM_BACKCOLOR; - cf.crBackColor = pInfo->crColors[m_iBG]; - m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); - } - } - else { - cf.dwMask = CFM_BACKCOLOR; - cf.crBackColor = (COLORREF)db_get_dw(0, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); - m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); - } -} - -void CChatRoomDlg::onChange_Message(CCtrlEdit *pEdit) -{ - cmdListCurrent = nullptr; - m_btnOk.Enable(GetRichTextLength(pEdit->GetHwnd(), 1200, FALSE) != 0); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -void CChatRoomDlg::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 == nullptr) - break; - - pLog = pLog->next; - if ((m_si->iType != GCW_CHATROOM && m_si->iType != GCW_PRIVMESS) || !m_bFilterEnabled || (m_iLogFilterFlags & pLog->iType) != 0) - index++; - } - StreamInEvents(pLog, true); - mir_forkthread(phase2, m_si); - } - else StreamInEvents(m_si->pLogEnd, true); - } - else ClearLog(); -} - -void CChatRoomDlg::ScrollToBottom() -{ - if ((GetWindowLongPtr(m_log.GetHwnd(), GWL_STYLE) & WS_VSCROLL) == 0) - return; - - 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); -} - -void CChatRoomDlg::ShowFilterMenu() -{ - HWND hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_FILTER), m_hwnd, FilterWndProc, (LPARAM)this); - TranslateDialogDefault(hwnd); - - RECT rc; - GetWindowRect(m_btnFilter.GetHwnd(), &rc); - SetWindowPos(hwnd, HWND_TOP, rc.left - 85, (IsWindowVisible(m_btnFilter.GetHwnd()) || IsWindowVisible(m_btnBold.GetHwnd())) ? rc.top - 206 : rc.top - 186, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); -} - -void CChatRoomDlg::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(), nullptr, FALSE); - UpdateWindow(m_nickList.GetHwnd()); - UpdateTitle(); -} - -void CChatRoomDlg::UpdateOptions() -{ - m_btnShowList.SendMsg(BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_bNicklistEnabled ? "chat_nicklist" : "chat_nicklist2")); - m_btnFilter.SendMsg(BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_bFilterEnabled ? "chat_filter" : "chat_filter2")); - { - MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); - if (pInfo) { - m_btnBold.Enable(pInfo->bBold); - m_btnItalic.Enable(pInfo->bItalics); - m_btnUnderline.Enable(pInfo->bUnderline); - m_btnColor.Enable(pInfo->bColor); - m_btnBkColor.Enable(pInfo->bBkgColor); - if (m_si->iType == GCW_CHATROOM) - m_btnChanMgr.Enable(pInfo->bChanMgr); - } - } - - UpdateStatusBar(); - UpdateTitle(); - FixTabIcons(); - - m_log.SendMsg(EM_SETBKGNDCOLOR, 0, g_Settings.crLogBackground); - - // messagebox - COLORREF crFore; - LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, nullptr, &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(0, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); - m_message.SendMsg(EM_SETBKGNDCOLOR, 0, db_get_dw(0, 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(0, CHAT_MODULE, "NicklistRowDist", 12); - int font = ih > ih2 ? ih : ih2; - // make sure we have space for icon! - if (db_get_b(0, CHAT_MODULE, "ShowContactStatus", 0)) - font = font > 16 ? font : 16; - - m_nickList.SendMsg(LB_SETITEMHEIGHT, 0, height > font ? height : font); - InvalidateRect(m_nickList.GetHwnd(), nullptr, TRUE); - } - m_message.SendMsg(EM_REQUESTRESIZE, 0, 0); - SendMessage(m_hwnd, WM_SIZE, 0, 0); - RedrawLog2(); -} - -void CChatRoomDlg::UpdateStatusBar() -{ - MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); - wchar_t szTemp[512]; - 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 = m_si->wStatus == ID_STATUS_ONLINE ? mi->hOnlineIcon : mi->hOfflineIcon; - sbd.pszText = szTemp; - SendMessage(m_hwndParent, CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)m_hwnd); - - sbd.iItem = 1; - sbd.hIcon = nullptr; - sbd.pszText = L""; - SendMessage(m_hwndParent, CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)m_hwnd); - - StatusIconData sid = { sizeof(sid) }; - sid.szModule = SRMMMOD; - Srmm_ModifyIcon(m_hContact, &sid); -} - -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; - RECT rc; - POINT pt; - HICON hIcon; - TabControlData tcd; - - switch (uMsg) { - case DM_SWITCHINFOBAR: - case DM_SWITCHTOOLBAR: - SendMessage(m_hwnd, WM_SIZE, 0, 0); - break; - - case WM_SIZE: - if (wParam == SIZE_MAXIMIZED) - ScrollToBottom(); - - if (IsIconic(m_hwnd)) break; - - if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) { - GetClientRect(m_hwnd, &rc); - MessageDialogResize(rc.right - rc.left, rc.bottom - rc.top); - } - break; - - case DM_UPDATETABCONTROL: - tcd.iFlags = TCDF_TEXT; - tcd.pszText = m_si->ptszName; - SendMessage(m_hwndParent, CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)m_hwnd); - // fall through - - case DM_ACTIVATE: - if (m_si->wState & STATE_TALK) { - m_si->wState &= ~STATE_TALK; - db_set_w(m_hContact, m_si->pszModule, "ApparentMode", 0); - } - - if (m_si->wState & GC_EVENT_HIGHLIGHT) { - m_si->wState &= ~GC_EVENT_HIGHLIGHT; - - if (pcli->pfnGetEvent(m_hContact, 0)) - pcli->pfnRemoveEvent(m_hContact, GC_FAKE_EVENT); - } - - FixTabIcons(); - if (!m_si->pDlg) { - ShowRoom(m_si); - SendMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); - } - 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(0, CHAT_MODULE, "NicklistRowDist", 12); - // make sure we have space for icon! - if (db_get_b(0, CHAT_MODULE, "ShowContactStatus", 0)) - font = font > 16 ? font : 16; - mis->itemHeight = height > font ? height : font; - } - return TRUE; - - 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, nullptr, 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, nullptr, 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, nullptr, DI_NORMAL); - IcoLib_ReleaseIcon(hIcon); - x_offset += 18; - } - - 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) - break; - - // fall through - case WM_MOUSEACTIVATE: - if (uMsg != WM_ACTIVATE) - SetFocus(m_message.GetHwnd()); - - pci->SetActiveSession(m_si); - - if (db_get_w(m_hContact, m_si->pszModule, "ApparentMode", 0) != 0) - db_set_w(m_hContact, m_si->pszModule, "ApparentMode", 0); - if (pcli->pfnGetEvent(m_hContact, 0)) - pcli->pfnRemoveEvent(m_hContact, GC_FAKE_EVENT); - break; - - case WM_NOTIFY: - { - LPNMHDR pNmhdr = (LPNMHDR)lParam; - switch (pNmhdr->code) { - case EN_MSGFILTER: - if (pNmhdr->idFrom == IDC_LOG && ((MSGFILTER *)lParam)->msg == WM_RBUTTONUP) { - SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, TRUE); - return TRUE; - } - break; - - 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 != nullptr) { - 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; - - case WM_KEYDOWN: - SetFocus(m_message.GetHwnd()); - break; - - case WM_GETMINMAXINFO: - { - MINMAXINFO *mmi = (MINMAXINFO*)lParam; - mmi->ptMinTrackSize.x = m_pParent->iSplitterX + 43; - if (mmi->ptMinTrackSize.x < 350) - mmi->ptMinTrackSize.x = 350; - - mmi->ptMinTrackSize.y = m_minLogBoxHeight + TOOLBAR_HEIGHT + m_minEditBoxHeight + 5; - } - break; - - case WM_LBUTTONDBLCLK: - if (LOWORD(lParam) < 30) - ScrollToBottom(); - else - SendMessage(m_hwndParent, WM_SYSCOMMAND, SC_MINIMIZE, 0); - break; - - case WM_LBUTTONDOWN: - SendMessage(m_hwndParent, WM_LBUTTONDOWN, wParam, lParam); - return TRUE; - - case DM_GETCONTEXTMENU: - SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, (LPARAM)Menu_BuildContactMenu(m_hContact)); - return TRUE; - - case WM_CONTEXTMENU: - if (m_hwndParent == (HWND)wParam) { - HMENU hMenu = Menu_BuildContactMenu(m_hContact); - GetCursorPos(&pt); - TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, m_hwnd, nullptr); - DestroyMenu(hMenu); - } - break; - } - return CScriverWindow::DlgProc(uMsg, wParam, lParam); -} - -void ShowRoom(SESSION_INFO *si) -{ - if (si == nullptr) - return; - - // Do we need to create a window? - if (si->pDlg == nullptr) { - HWND hParent = GetParentWindow(si->hContact, TRUE); - - CChatRoomDlg *pDlg = new CChatRoomDlg(si); - pDlg->SetParent(hParent); - pDlg->Show(); - - pDlg->m_pParent = (ParentWindowData*)GetWindowLongPtr(hParent, GWLP_USERDATA); - si->pDlg = pDlg; - } - SendMessage(si->pDlg->GetHwnd(), DM_UPDATETABCONTROL, -1, (LPARAM)si); - SendMessage(GetParent(si->pDlg->GetHwnd()), CM_ACTIVATECHILD, 0, (LPARAM)si->pDlg->GetHwnd()); - SendMessage(GetParent(si->pDlg->GetHwnd()), CM_POPUPWINDOW, 0, (LPARAM)si->pDlg->GetHwnd()); - SendMessage(si->pDlg->GetHwnd(), WM_MOUSEACTIVATE, 0, 0); - SetFocus(GetDlgItem(si->pDlg->GetHwnd(), IDC_MESSAGE)); -} diff --git a/plugins/Scriver/src/chat_log.cpp b/plugins/Scriver/src/chat_log.cpp new file mode 100644 index 0000000000..3d8ea3eb55 --- /dev/null +++ b/plugins/Scriver/src/chat_log.cpp @@ -0,0 +1,123 @@ +/* +Chat module plugin for Miranda IM + +Copyright (C) 2003 Jörgen Persson +Copyright 2003-2009 Miranda ICQ/IM project, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +#ifndef EM_GETSCROLLPOS +#define EM_GETSCROLLPOS (WM_USER+221) +#endif + +void CChatRoomDlg::StreamInEvents(LOGINFO* lin, bool bRedraw) +{ + if (m_hwnd == nullptr || lin == nullptr || m_si == nullptr) + return; + + if (!bRedraw && (m_si->iType == GCW_CHATROOM || m_si->iType == GCW_PRIVMESS) && m_bFilterEnabled && !(m_iLogFilterFlags & lin->iType)) + return; + + LOGSTREAMDATA streamData; + memset(&streamData, 0, sizeof(streamData)); + streamData.hwnd = m_log.GetHwnd(); + streamData.si = m_si; + streamData.lin = lin; + streamData.bStripFormat = FALSE; + streamData.isFirst = bRedraw ? 1 : (GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE) == 0); + + EDITSTREAM stream = { 0 }; + stream.pfnCallback = Srmm_LogStreamCallback; + stream.dwCookie = (DWORD_PTR)&streamData; + + SCROLLINFO scroll; + scroll.cbSize = sizeof(SCROLLINFO); + scroll.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; + GetScrollInfo(m_log.GetHwnd(), SB_VERT, &scroll); + + POINT point = { 0 }; + m_log.SendMsg(EM_GETSCROLLPOS, 0, (LPARAM)&point); + + // do not scroll to bottom if there is a selection + CHARRANGE oldsel, sel, newsel; + m_log.SendMsg(EM_EXGETSEL, 0, (LPARAM)&oldsel); + if (oldsel.cpMax != oldsel.cpMin) + m_log.SendMsg(WM_SETREDRAW, FALSE, 0); + + // set the insertion point at the bottom + sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE); + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); + m_log.SendMsg(EM_EXGETSEL, 0, (LPARAM)&sel); + + // fix for the indent... must be a M$ bug + if (sel.cpMax == 0) + bRedraw = TRUE; + + // should the event(s) be appended to the current log + WPARAM wp = bRedraw ? SF_RTF : SFF_SELECTION | SF_RTF; + + // get the number of pixels per logical inch + bool bFlag = false; + if (bRedraw) { + m_log.SendMsg(WM_SETREDRAW, FALSE, 0); + bFlag = true; + } + + // stream in the event(s) + streamData.lin = lin; + streamData.bRedraw = bRedraw; + m_log.SendMsg(EM_STREAMIN, wp, (LPARAM)&stream); + + // do smileys + if (g_dat.smileyAddInstalled && (bRedraw || (lin->ptszText && lin->iType != GC_EVENT_JOIN && lin->iType != GC_EVENT_NICK && lin->iType != GC_EVENT_ADDSTATUS && lin->iType != GC_EVENT_REMOVESTATUS))) { + newsel.cpMax = -1; + newsel.cpMin = sel.cpMin; + if (newsel.cpMin < 0) + newsel.cpMin = 0; + + SMADD_RICHEDIT3 sm = { sizeof(sm) }; + sm.hwndRichEditControl = m_log.GetHwnd(); + sm.Protocolname = m_si->pszModule; + sm.rangeToReplace = bRedraw ? nullptr : &newsel; + sm.flags = 0; + sm.disableRedraw = TRUE; + sm.hContact = m_hContact; + CallService(MS_SMILEYADD_REPLACESMILEYS, 0, (LPARAM)&sm); + } + + // scroll log to bottom if the log was previously scrolled to bottom, else restore old position + if (bRedraw || (UINT)scroll.nPos >= (UINT)scroll.nMax - scroll.nPage - 5 || scroll.nMax - scroll.nMin - scroll.nPage < 50) + ScrollToBottom(); + else + m_log.SendMsg(EM_SETSCROLLPOS, 0, (LPARAM)&point); + + // do we need to restore the selection + if (oldsel.cpMax != oldsel.cpMin) { + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&oldsel); + m_log.SendMsg(WM_SETREDRAW, TRUE, 0); + InvalidateRect(m_log.GetHwnd(), nullptr, TRUE); + } + + // need to invalidate the window + if (bFlag) { + sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE); + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); + m_log.SendMsg(WM_SETREDRAW, TRUE, 0); + InvalidateRect(m_log.GetHwnd(), nullptr, TRUE); + } +} diff --git a/plugins/Scriver/src/chat_main.cpp b/plugins/Scriver/src/chat_main.cpp new file mode 100644 index 0000000000..f4b4755e56 --- /dev/null +++ b/plugins/Scriver/src/chat_main.cpp @@ -0,0 +1,163 @@ +/* +Chat module plugin for Miranda IM + +Copyright (C) 2003 Jörgen Persson +Copyright 2003-2009 Miranda ICQ/IM project, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +// globals +CHAT_MANAGER *pci; +HMENU g_hMenu = nullptr; + +pfnDoTrayIcon oldDoTrayIcon; +pfnDoPopup oldDoPopup; + +GlobalLogSettings g_Settings; + +void LoadModuleIcons(MODULEINFO *mi) +{ + HIMAGELIST hList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 0); + + int overlayIcon = ImageList_AddIcon(hList, GetCachedIcon("chat_overlay")); + ImageList_SetOverlayImage(hList, overlayIcon, 1); + + int index = ImageList_AddIcon(hList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE)); + mi->hOnlineIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT); + mi->hOnlineTalkIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1)); + + index = ImageList_AddIcon(hList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE)); + mi->hOfflineIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT); + mi->hOfflineTalkIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1)); + + ImageList_Destroy(hList); +} + +static void OnReplaceSession(SESSION_INFO *si) +{ + if (si->pDlg) + RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_CHAT_LIST), nullptr, nullptr, RDW_INVALIDATE); +} + +static void OnNewUser(SESSION_INFO *si, USERINFO*) +{ + if (si->pDlg) + si->pDlg->UpdateNickList(); +} + +static void OnSetStatus(SESSION_INFO *si, int) +{ + if (si->pDlg) + si->pDlg->FixTabIcons(); +} + +static void OnFlashHighlight(SESSION_INFO *si, int bInactive) +{ + if (!bInactive || !si->pDlg) + return; + + if (g_Settings.bFlashWindowHighlight) + SendMessage(GetParent(si->pDlg->GetHwnd()), CM_STARTFLASHING, 0, 0); + + si->wState |= GC_EVENT_HIGHLIGHT; + si->pDlg->FixTabIcons(); + si->pDlg->UpdateTitle(); + + HWND hwndParent = GetParent(si->pDlg->GetHwnd()); + if (g_Settings.bFlashWindowHighlight && GetActiveWindow() != si->pDlg->GetHwnd() && GetForegroundWindow() != hwndParent) + SendMessage(hwndParent, CM_STARTFLASHING, 0, 0); +} + +static void OnFlashWindow(SESSION_INFO *si, int bInactive) +{ + if (!bInactive || !si->pDlg) + return; + + if (g_Settings.bFlashWindow) + SendMessage(GetParent(si->pDlg->GetHwnd()), CM_STARTFLASHING, 0, 0); + + si->pDlg->FixTabIcons(); + si->pDlg->UpdateTitle(); + + HWND hwndParent = GetParent(si->pDlg->GetHwnd()); + if (g_Settings.bFlashWindow && GetActiveWindow() != hwndParent && GetForegroundWindow() != hwndParent) + SendMessage(hwndParent, CM_STARTFLASHING, 0, 0); +} + +static void OnCreateModule(MODULEINFO *mi) +{ + LoadModuleIcons(mi); + mi->hOnlineIconBig = Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE, true); + mi->hOfflineIconBig = Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE, true); +} + +static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) +{ + if (gce->pDest->iType & g_Settings.dwTrayIconFlags) + return oldDoTrayIcon(si, gce); + return TRUE; +} + +static BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce) +{ + if (gce->pDest->iType & g_Settings.dwPopupFlags) + return oldDoPopup(si, gce); + return TRUE; +} + +static void OnLoadSettings() +{ + if (g_Settings.MessageBoxFont) + DeleteObject(g_Settings.MessageBoxFont); + + LOGFONT lf; + LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, &lf, nullptr); + g_Settings.MessageBoxFont = CreateFontIndirect(&lf); +} + +int Chat_Load() +{ + CHAT_MANAGER_INITDATA data = { &g_Settings, sizeof(MODULEINFO), sizeof(SESSION_INFO), LPGENW("Messaging") L"/" LPGENW("Group chats"), FONTMODE_SKIP }; + pci = Chat_GetInterface(&data); + + pci->OnCreateModule = OnCreateModule; + pci->OnNewUser = OnNewUser; + pci->OnLoadSettings = OnLoadSettings; + + pci->OnSetStatus = OnSetStatus; + + pci->OnReplaceSession = OnReplaceSession; + + pci->OnFlashWindow = OnFlashWindow; + pci->OnFlashHighlight = OnFlashHighlight; + pci->ShowRoom = ShowRoom; + + oldDoPopup = pci->DoPopup; pci->DoPopup = DoPopup; + oldDoTrayIcon = pci->DoTrayIcon; pci->DoTrayIcon = DoTrayIcon; + pci->ReloadSettings(); + + g_hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU)); + TranslateMenu(g_hMenu); + return 0; +} + +int Chat_Unload(void) +{ + DestroyMenu(g_hMenu); + return 0; +} diff --git a/plugins/Scriver/src/chat_manager.cpp b/plugins/Scriver/src/chat_manager.cpp new file mode 100644 index 0000000000..f86764560a --- /dev/null +++ b/plugins/Scriver/src/chat_manager.cpp @@ -0,0 +1,86 @@ +/* +Chat module plugin for Miranda IM + +Copyright (C) 2003 Jörgen Persson +Copyright 2003-2009 Miranda ICQ/IM project, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +HWND SM_FindWindowByContact(MCONTACT hContact) +{ + for (int i = 0; i < pci->arSessions.getCount(); i++) { + SESSION_INFO *si = pci->arSessions[i]; + if (si->hContact == hContact) + return (si->pDlg) ? si->pDlg->GetHwnd() : nullptr; + } + return nullptr; +} + +SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO *currSession, SESSION_INFO *prevSession, const wchar_t *pszOriginal, const wchar_t *pszCurrent) +{ + SESSION_INFO* pResult = nullptr; + if (prevSession == nullptr && my_strstri(currSession->ptszName, pszOriginal) == currSession->ptszName) + pResult = currSession; + else { + wchar_t* pszName = nullptr; + if (currSession == prevSession) + pszCurrent = pszOriginal; + + for (int i = 0; i < pci->arSessions.getCount(); i++) { + SESSION_INFO *si = pci->arSessions[i]; + if (si != currSession && !mir_strcmpi(pszModule, si->pszModule)) { + if (my_strstri(si->ptszName, pszOriginal) == si->ptszName) { + if (prevSession != si && mir_wstrcmpi(si->ptszName, pszCurrent) > 0 && (!pszName || mir_wstrcmpi(si->ptszName, pszName) < 0)) { + pResult = si; + pszName = si->ptszName; + } + } + } + } + } + return pResult; +} + +char SM_GetStatusIndicator(SESSION_INFO *si, USERINFO *ui) +{ + STATUSINFO * ti; + if (!ui || !si) + return '\0'; + + ti = pci->TM_FindStatus(si->pStatuses, pci->TM_WordToString(si->pStatuses, ui->Status)); + if (ti) { + if ((INT_PTR)ti->hIcon < STATUSICONCOUNT) { + INT_PTR id = si->iStatusCount - (INT_PTR)ti->hIcon - 1; + if (id == 0) + return '\0'; + if (id == 1) + return '+'; + if (id == 2) + return '%'; + if (id == 3) + return '@'; + if (id == 4) + return '!'; + if (id == 5) + return '*'; + } + else + return '\0'; + } + return '\0'; +} diff --git a/plugins/Scriver/src/chat_options.cpp b/plugins/Scriver/src/chat_options.cpp new file mode 100644 index 0000000000..ee3b0647df --- /dev/null +++ b/plugins/Scriver/src/chat_options.cpp @@ -0,0 +1,729 @@ +/* +Chat module plugin for Miranda IM + +Copyright (C) 2003 Jörgen Persson +Copyright 2003-2009 Miranda ICQ/IM project, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +#define UM_CHECKSTATECHANGE (WM_USER+100) + +static HWND hPathTip = 0; + +struct branch_t +{ + wchar_t* szDescr; + char* szDBName; + int iMode; + BYTE bDefault; + HTREEITEM hItem; +}; + +static struct branch_t branch1[] = { + { LPGENW("Flash when someone speaks"), "FlashWindow", 0, 0, nullptr }, + { LPGENW("Flash when a word is highlighted"), "FlashWindowHighlight", 0, 1, nullptr }, + { LPGENW("Show chat nick list"), "ShowNicklist", 0, 1, nullptr }, + { LPGENW("Enable button context menus"), "RightClickFilter", 0, 0, nullptr }, + { LPGENW("Show topic on your contact list (if supported)"), "TopicOnClist", 0, 0, nullptr }, + { LPGENW("Do not play sounds when focused"), "SoundsFocus", 0, 0, nullptr }, + { LPGENW("Do not pop up when joining"), "PopupOnJoin", 0, 0, nullptr }, + { LPGENW("Show and hide by double clicking in the contact list"), "ToggleVisibility", 0, 0, nullptr }, + { LPGENW("Show contact statuses (if supported)"), "ShowContactStatus", 0, 0, nullptr }, + { LPGENW("Display contact status icon before role icon"), "ContactStatusFirst", 0, 0, nullptr }, + { LPGENW("Add ':' to auto-completed names"), "AddColonToAutoComplete", 0, 1, nullptr } +}; + +static struct branch_t branch2[] = { + { LPGENW("Show icons"), "IconFlags", GC_EVENT_TOPIC | GC_EVENT_JOIN | GC_EVENT_QUIT | + GC_EVENT_MESSAGE | GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT | GC_EVENT_PART | + GC_EVENT_KICK | GC_EVENT_NOTICE | GC_EVENT_NICK | GC_EVENT_INFORMATION | GC_EVENT_ADDSTATUS, 0, nullptr }, + { LPGENW("Prefix all events with a timestamp"), "ShowTimeStamp", 0, 1, nullptr }, + { LPGENW("Only prefix with timestamp if it has changed"), "ShowTimeStampIfChanged", 0, 0, nullptr }, + { LPGENW("Timestamp has same color as event"), "TimeStampEventColour", 0, 0, nullptr }, + { LPGENW("Indent the second line of a message"), "LogIndentEnabled", 0, 1, nullptr }, + { LPGENW("Limit user names to 20 characters"), "LogLimitNames", 0, 1, nullptr }, + { LPGENW("Strip colors from messages"), "StripFormatting", 0, 0, nullptr }, + { LPGENW("Enable 'event filter' for new rooms"), "FilterEnabled", 0, 0, nullptr } +}; + +static struct branch_t branch3[] = { + { LPGENW("Show topic changes"), "FilterFlags", GC_EVENT_TOPIC, 0, nullptr }, + { LPGENW("Show users joining"), "FilterFlags", GC_EVENT_JOIN, 0, nullptr }, + { LPGENW("Show users disconnecting"), "FilterFlags", GC_EVENT_QUIT, 0, nullptr }, + { LPGENW("Show messages"), "FilterFlags", GC_EVENT_MESSAGE, 1, nullptr }, + { LPGENW("Show actions"), "FilterFlags", GC_EVENT_ACTION, 1, nullptr }, + { LPGENW("Show users leaving"), "FilterFlags", GC_EVENT_PART, 0, nullptr }, + { LPGENW("Show users being kicked"), "FilterFlags", GC_EVENT_KICK, 1, nullptr }, + { LPGENW("Show notices"), "FilterFlags", GC_EVENT_NOTICE, 1, nullptr }, + { LPGENW("Show users changing name"), "FilterFlags", GC_EVENT_NICK, 0, nullptr }, + { LPGENW("Show information messages"), "FilterFlags", GC_EVENT_INFORMATION, 1, nullptr }, + { LPGENW("Show status changes of users"), "FilterFlags", GC_EVENT_ADDSTATUS, 0, nullptr }, +}; + +static struct branch_t branch4[] = { + { LPGENW("Show icons in tray only when the chat room is not active"), "TrayIconInactiveOnly", 0, 1, nullptr }, + { LPGENW("Show icon in tray for topic changes"), "TrayIconFlags", GC_EVENT_TOPIC, 0, nullptr }, + { LPGENW("Show icon in tray for users joining"), "TrayIconFlags", GC_EVENT_JOIN, 0, nullptr }, + { LPGENW("Show icon in tray for users disconnecting"), "TrayIconFlags", GC_EVENT_QUIT, 0, nullptr }, + { LPGENW("Show icon in tray for messages"), "TrayIconFlags", GC_EVENT_MESSAGE, 0, nullptr }, + { LPGENW("Show icon in tray for actions"), "TrayIconFlags", GC_EVENT_ACTION, 0, nullptr }, + { LPGENW("Show icon in tray for highlights"), "TrayIconFlags", GC_EVENT_HIGHLIGHT, 1, nullptr }, + { LPGENW("Show icon in tray for users leaving"), "TrayIconFlags", GC_EVENT_PART, 0, nullptr }, + { LPGENW("Show icon in tray for users kicking other user"), "TrayIconFlags", GC_EVENT_KICK, 0, nullptr }, + { LPGENW("Show icon in tray for notices"), "TrayIconFlags", GC_EVENT_NOTICE, 0, nullptr }, + { LPGENW("Show icon in tray for name changes"), "TrayIconFlags", GC_EVENT_NICK, 0, nullptr }, + { LPGENW("Show icon in tray for information messages"), "TrayIconFlags", GC_EVENT_INFORMATION, 0, nullptr }, + { LPGENW("Show icon in tray for status changes"), "TrayIconFlags", GC_EVENT_ADDSTATUS, 0, nullptr }, +}; + +static struct branch_t branch6[] = { + { LPGENW("Show popups only when the chat room is not active"), "PopupInactiveOnly", 0, 1, nullptr }, + { LPGENW("Show popup for topic changes"), "PopupFlags", GC_EVENT_TOPIC, 0, nullptr }, + { LPGENW("Show popup for users joining"), "PopupFlags", GC_EVENT_JOIN, 0, nullptr }, + { LPGENW("Show popup for users disconnecting"), "PopupFlags", GC_EVENT_QUIT, 0, nullptr }, + { LPGENW("Show popup for messages"), "PopupFlags", GC_EVENT_MESSAGE, 0, nullptr }, + { LPGENW("Show popup for actions"), "PopupFlags", GC_EVENT_ACTION, 0, nullptr }, + { LPGENW("Show popup for highlights"), "PopupFlags", GC_EVENT_HIGHLIGHT, 0, nullptr }, + { LPGENW("Show popup for users leaving"), "PopupFlags", GC_EVENT_PART, 0, nullptr }, + { LPGENW("Show popup for users kicking other user"), "PopupFlags", GC_EVENT_KICK, 0, nullptr }, + { LPGENW("Show popup for notices"), "PopupFlags", GC_EVENT_NOTICE, 0, nullptr }, + { LPGENW("Show popup for name changes"), "PopupFlags", GC_EVENT_NICK, 0, nullptr }, + { LPGENW("Show popup for information messages"), "PopupFlags", GC_EVENT_INFORMATION, 0, nullptr }, + { LPGENW("Show popup for status changes"), "PopupFlags", GC_EVENT_ADDSTATUS, 0, nullptr }, +}; + +static HTREEITEM InsertBranch(HWND hwndTree, wchar_t* pszDescr, BOOL bExpanded) +{ + TVINSERTSTRUCT tvis; + tvis.hParent = nullptr; + tvis.hInsertAfter = TVI_LAST; + tvis.item.mask = TVIF_TEXT | TVIF_STATE; + tvis.item.pszText = TranslateW(pszDescr); + tvis.item.stateMask = bExpanded ? TVIS_STATEIMAGEMASK | TVIS_EXPANDED : TVIS_STATEIMAGEMASK; + tvis.item.state = bExpanded ? INDEXTOSTATEIMAGEMASK(1) | TVIS_EXPANDED : INDEXTOSTATEIMAGEMASK(1); + return TreeView_InsertItem(hwndTree, &tvis); +} + +static void FillBranch(HWND hwndTree, HTREEITEM hParent, struct branch_t *branch, int nValues, DWORD defaultval) +{ + int iState; + + TVINSERTSTRUCT tvis; + tvis.hParent = hParent; + tvis.hInsertAfter = TVI_LAST; + tvis.item.mask = TVIF_TEXT | TVIF_STATE; + for (int i = 0; i < nValues; i++) { + tvis.item.pszText = TranslateW(branch[i].szDescr); + tvis.item.stateMask = TVIS_STATEIMAGEMASK; + if (branch[i].iMode) + iState = ((db_get_dw(0, CHAT_MODULE, branch[i].szDBName, defaultval)&branch[i].iMode)&branch[i].iMode) != 0 ? 2 : 1; + else + iState = db_get_b(0, CHAT_MODULE, branch[i].szDBName, branch[i].bDefault) != 0 ? 2 : 1; + tvis.item.state = INDEXTOSTATEIMAGEMASK(iState); + branch[i].hItem = TreeView_InsertItem(hwndTree, &tvis); + } +} + +static void SaveBranch(HWND hwndTree, struct branch_t *branch, int nValues) +{ + int iState = 0; + + TVITEM tvi; + tvi.mask = TVIF_HANDLE | TVIF_STATE; + for (int i = 0; i < nValues; i++) { + tvi.hItem = branch[i].hItem; + TreeView_GetItem(hwndTree, &tvi); + BYTE bChecked = ((tvi.state&TVIS_STATEIMAGEMASK) >> 12 == 1) ? 0 : 1; + if (branch[i].iMode) { + if (bChecked) + iState |= branch[i].iMode; + if (iState&GC_EVENT_ADDSTATUS) + iState |= GC_EVENT_REMOVESTATUS; + db_set_dw(0, CHAT_MODULE, branch[i].szDBName, (DWORD)iState); + } + else db_set_b(0, CHAT_MODULE, branch[i].szDBName, bChecked); + } +} + +static void CheckHeading(HWND hwndTree, HTREEITEM hHeading) +{ + BOOL bChecked = TRUE; + + if (hHeading == 0) + return; + + TVITEM tvi; + tvi.mask = TVIF_HANDLE | TVIF_STATE; + tvi.hItem = TreeView_GetNextItem(hwndTree, hHeading, TVGN_CHILD); + while (tvi.hItem && bChecked) { + if (tvi.hItem != branch1[0].hItem && tvi.hItem != branch1[1].hItem) { + TreeView_GetItem(hwndTree, &tvi); + if (((tvi.state&TVIS_STATEIMAGEMASK) >> 12 == 1)) + bChecked = FALSE; + } + tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); + } + tvi.stateMask = TVIS_STATEIMAGEMASK; + tvi.state = INDEXTOSTATEIMAGEMASK(bChecked ? 2 : 1); + tvi.hItem = hHeading; + TreeView_SetItem(hwndTree, &tvi); +} + +static void CheckBranches(HWND hwndTree, HTREEITEM hHeading) +{ + BOOL bChecked = TRUE; + TVITEM tvi; + + if (hHeading == 0) + return; + + tvi.mask = TVIF_HANDLE | TVIF_STATE; + tvi.hItem = hHeading; + TreeView_GetItem(hwndTree, &tvi); + if (((tvi.state & TVIS_STATEIMAGEMASK) >> 12 == 2)) + bChecked = FALSE; + tvi.hItem = TreeView_GetNextItem(hwndTree, hHeading, TVGN_CHILD); + tvi.stateMask = TVIS_STATEIMAGEMASK; + while (tvi.hItem) { + tvi.state = INDEXTOSTATEIMAGEMASK(bChecked ? 2 : 1); + if (tvi.hItem != branch1[0].hItem && tvi.hItem != branch1[1].hItem) + TreeView_SetItem(hwndTree, &tvi); + tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); + } +} + +static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) +{ + char szDir[MAX_PATH]; + switch (uMsg) { + case BFFM_INITIALIZED: + SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); + break; + case BFFM_SELCHANGED: + if (SHGetPathFromIDListA((LPITEMIDLIST)lp, szDir)) + SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir); + break; + } + return 0; +} + +static void InitSetting(wchar_t **ppPointer, char *pszSetting, wchar_t *pszDefault) +{ + DBVARIANT dbv; + if (!db_get_ws(0, CHAT_MODULE, pszSetting, &dbv)) { + replaceStrW(*ppPointer, dbv.ptszVal); + db_free(&dbv); + } + else replaceStrW(*ppPointer, pszDefault); +} + +#define OPT_FIXHEADINGS (WM_USER+1) + +INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + static HTREEITEM hListHeading1 = 0; + static HTREEITEM hListHeading4 = 0; + switch (uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); + SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_SETRANGE, 0, MAKELONG(255, 10)); + SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_SETPOS, 0, MAKELONG(db_get_b(0, CHAT_MODULE, "NicklistRowDist", 12), 0)); + hListHeading1 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), TranslateT("Appearance and functionality of chat windows"), db_get_b(0, CHAT_MODULE, "Branch1Exp", 0) ? TRUE : FALSE); + hListHeading4 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), TranslateT("Icons to display in the tray"), db_get_b(0, CHAT_MODULE, "Branch5Exp", 0) ? TRUE : FALSE); + FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1, branch1, _countof(branch1), 0); + FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4, branch4, _countof(branch4), 0x1000); + SendMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); + { + wchar_t* pszGroup = nullptr; + InitSetting(&pszGroup, "AddToGroup", L"Chat rooms"); + SetDlgItemText(hwndDlg, IDC_CHAT_GROUP, pszGroup); + mir_free(pszGroup); + } + break; + + case OPT_FIXHEADINGS: + CheckHeading(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1); + CheckHeading(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4); + break; + + case WM_COMMAND: + if ((LOWORD(wParam) == IDC_CHAT_NICKROW || LOWORD(wParam) == IDC_CHAT_GROUP) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) + return 0; + + if (lParam != 0) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case UM_CHECKSTATECHANGE: + { + TVITEM tvi = { 0 }; + tvi.mask = TVIF_HANDLE | TVIF_STATE; + tvi.hItem = (HTREEITEM)lParam; + TreeView_GetItem((HWND)wParam, &tvi); + if (tvi.hItem == hListHeading1) + CheckBranches(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1); + else if (tvi.hItem == hListHeading4) + CheckBranches(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4); + else + PostMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + break; + + case WM_NOTIFY: + switch (((LPNMHDR)lParam)->idFrom) { + case IDC_CHAT_CHECKBOXES: + if (((LPNMHDR)lParam)->code == NM_CLICK) { + TVHITTESTINFO hti; + hti.pt.x = (short)LOWORD(GetMessagePos()); + hti.pt.y = (short)HIWORD(GetMessagePos()); + ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); + if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) + if (hti.flags&TVHT_ONITEMSTATEICON) { + SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, (LPARAM)hti.hItem); + } + + } + else if (((LPNMHDR)lParam)->code == TVN_KEYDOWN) { + if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE) + SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, + (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom)); + } + break; + + case 0: + switch (((LPNMHDR)lParam)->code) { + case PSN_APPLY: + int iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_GROUP)); + if (iLen > 0) { + ptrA pszText((char*)mir_alloc(iLen + 1)); + GetDlgItemTextA(hwndDlg, IDC_CHAT_GROUP, pszText, iLen + 1); + db_set_s(0, CHAT_MODULE, "AddToGroup", pszText); + } + else db_set_s(0, CHAT_MODULE, "AddToGroup", ""); + + iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_GETPOS, 0, 0); + if (iLen > 0) + db_set_b(0, CHAT_MODULE, "NicklistRowDist", (BYTE)iLen); + else + db_unset(0, CHAT_MODULE, "NicklistRowDist"); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch1, _countof(branch1)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch4, _countof(branch4)); + + pci->ReloadSettings(); + Chat_UpdateOptions(); + } + return TRUE; + } + break; + + case WM_DESTROY: + BYTE b = TreeView_GetItemState(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1, TVIS_EXPANDED)&TVIS_EXPANDED ? 1 : 0; + db_set_b(0, CHAT_MODULE, "Branch1Exp", b); + b = TreeView_GetItemState(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4, TVIS_EXPANDED)&TVIS_EXPANDED ? 1 : 0; + db_set_b(0, CHAT_MODULE, "Branch5Exp", b); + break; + } + return FALSE; +} + +INT_PTR CALLBACK DlgProcOptions2(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + static HTREEITEM hListHeading2 = 0; + static HTREEITEM hListHeading3 = 0; + + switch (uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); + SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_SETRANGE, 0, MAKELONG(5000, 0)); + SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_SETPOS, 0, MAKELONG(db_get_w(0, CHAT_MODULE, "LogLimit", 100), 0)); + SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN3, UDM_SETRANGE, 0, MAKELONG(10000, 0)); + SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN3, UDM_SETPOS, 0, MAKELONG(db_get_w(0, CHAT_MODULE, "LoggingLimit", 100), 0)); + { + wchar_t tszTemp[MAX_PATH]; + PathToRelativeW(g_Settings.pszLogDir, tszTemp); + SetDlgItemText(hwndDlg, IDC_CHAT_LOGDIRECTORY, tszTemp); + } + + wchar_t tszTooltipText[2048]; + RECT rect; + + mir_snwprintf(tszTooltipText, + L"%s - %s\n%s - %s\n%s - %s\n%s - %s\n\n" + L"%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n\n" + L"%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s", + // contact vars + L"%nick%", TranslateT("nick of current contact (if defined)"), + L"%proto%", TranslateT("protocol name of current contact (if defined). Account name is used when protocol supports multiple accounts"), + L"%accountname%", TranslateT("user-defined account name of current contact (if defined)."), + L"%userid%", TranslateT("user ID of current contact (if defined). It is like UIN for ICQ, JID for Jabber, etc."), + // global vars + L"%miranda_path%", TranslateT("path to Miranda root folder"), + L"%miranda_profilesdir%", TranslateT("path to folder containing Miranda profiles"), + L"%miranda_profilename%", TranslateT("name of current Miranda profile (filename, without extension)"), + L"%miranda_userdata%", TranslateT("will return parsed string %miranda_profilesdir%\\%miranda_profilename%"), + L"%miranda_logpath%", TranslateT("will return parsed string %miranda_userdata%\\Logs"), + L"%appdata%", TranslateT("same as environment variable %APPDATA% for currently logged-on Windows user"), + L"%username%", TranslateT("username for currently logged-on Windows user"), + L"%mydocuments%", TranslateT("\"My Documents\" folder for currently logged-on Windows user"), + L"%desktop%", TranslateT("\"Desktop\" folder for currently logged-on Windows user"), + L"%xxxxxxx%", TranslateT("any environment variable defined in current Windows session (like %systemroot%, %allusersprofile%, etc.)"), + // date/time vars + L"%d%", TranslateT("day of month, 1-31"), + L"%dd%", TranslateT("day of month, 01-31"), + L"%m%", TranslateT("month number, 1-12"), + L"%mm%", TranslateT("month number, 01-12"), + L"%mon%", TranslateT("abbreviated month name"), + L"%month%", TranslateT("full month name"), + L"%yy%", TranslateT("year without century, 01-99"), + L"%yyyy%", TranslateT("year with century, 1901-9999"), + L"%wday%", TranslateT("abbreviated weekday name"), + L"%weekday%", TranslateT("full weekday name")); + GetClientRect(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY), &rect); + rect.left = -85; + hPathTip = CreateToolTip(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY), tszTooltipText, TranslateT("Variables"), &rect); + SetTimer(hwndDlg, 0, 3000, nullptr); + + SetDlgItemText(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS, g_Settings.pszHighlightWords); + SetDlgItemText(hwndDlg, IDC_CHAT_LOGTIMESTAMP, g_Settings.pszTimeStampLog); + SetDlgItemText(hwndDlg, IDC_CHAT_TIMESTAMP, g_Settings.pszTimeStamp); + SetDlgItemText(hwndDlg, IDC_CHAT_OUTSTAMP, g_Settings.pszOutgoingNick); + SetDlgItemText(hwndDlg, IDC_CHAT_INSTAMP, g_Settings.pszIncomingNick); + CheckDlgButton(hwndDlg, IDC_CHAT_HIGHLIGHT, g_Settings.bHighlightEnabled ? BST_CHECKED : BST_UNCHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS), g_Settings.bHighlightEnabled ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHAT_LOGGING, g_Settings.bLoggingEnabled ? BST_CHECKED : BST_UNCHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY), g_Settings.bLoggingEnabled ? TRUE : FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRCHOOSE), g_Settings.bLoggingEnabled ? TRUE : FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIMIT), g_Settings.bLoggingEnabled ? TRUE : FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIMITTEXT2), g_Settings.bLoggingEnabled ? TRUE : FALSE); + + hListHeading2 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), TranslateT("Appearance"), db_get_b(0, CHAT_MODULE, "Branch2Exp", 0) ? TRUE : FALSE); + hListHeading3 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), TranslateT("Default events to show in new chat rooms if the 'event filter' is enabled"), db_get_b(0, CHAT_MODULE, "Branch3Exp", 0) ? TRUE : FALSE); + FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading2, branch2, _countof(branch2), 0x0); + FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading3, branch3, _countof(branch3), 0x03E0); + SendMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); + break; + + case OPT_FIXHEADINGS: + CheckHeading(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading2); + CheckHeading(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading3); + break; + + case WM_COMMAND: + if ((LOWORD(wParam) == IDC_CHAT_INSTAMP + || LOWORD(wParam) == IDC_CHAT_OUTSTAMP + || LOWORD(wParam) == IDC_CHAT_TIMESTAMP + || LOWORD(wParam) == IDC_CHAT_LOGLIMIT + || LOWORD(wParam) == IDC_CHAT_HIGHLIGHTWORDS + || LOWORD(wParam) == IDC_CHAT_LOGDIRECTORY + || LOWORD(wParam) == IDC_CHAT_LOGTIMESTAMP + || LOWORD(wParam) == IDC_CHAT_LIMIT) + && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0; + + switch (LOWORD(wParam)) { + case IDC_CHAT_LOGGING: + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY), IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRCHOOSE), IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIMIT), IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_LIMITTEXT2), IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE); + break; + + case IDC_CHAT_HIGHLIGHT: + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS), IsDlgButtonChecked(hwndDlg, IDC_CHAT_HIGHLIGHT) == BST_CHECKED ? TRUE : FALSE); + break; + + case IDC_CHAT_LOGDIRCHOOSE: + LPMALLOC psMalloc; + if (SUCCEEDED(CoGetMalloc(1, &psMalloc))) { + wchar_t tszDirectory[MAX_PATH], tszTemp[MAX_PATH]; + BROWSEINFO bi = { 0 }; + bi.hwndOwner = hwndDlg; + bi.pszDisplayName = tszDirectory; + bi.lpszTitle = TranslateT("Select folder"); + bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX | BIF_RETURNONLYFSDIRS; + bi.lpfn = BrowseCallbackProc; + bi.lParam = (LPARAM)tszDirectory; + + LPITEMIDLIST idList = SHBrowseForFolder(&bi); + if (idList) { + SHGetPathFromIDList(idList, tszDirectory); + mir_wstrcat(tszDirectory, L"\\"); + PathToRelativeW(tszDirectory, tszTemp); + SetDlgItemText(hwndDlg, IDC_CHAT_LOGDIRECTORY, mir_wstrlen(tszTemp) > 1 ? tszTemp : DEFLOGFILENAME); + } + psMalloc->Free(idList); + psMalloc->Release(); + } + break; + } + + if (lParam != 0) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case UM_CHECKSTATECHANGE: + { + TVITEM tvi = { 0 }; + tvi.mask = TVIF_HANDLE | TVIF_STATE; + tvi.hItem = (HTREEITEM)lParam; + TreeView_GetItem((HWND)wParam, &tvi); + if (tvi.hItem == hListHeading2) + CheckBranches(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading2); + else if (tvi.hItem == hListHeading3) + CheckBranches(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading3); + else + PostMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + break; + + case WM_NOTIFY: + if (((LPNMHDR)lParam)->idFrom == IDC_CHAT_CHECKBOXES) { + if (((LPNMHDR)lParam)->code == NM_CLICK) { + TVHITTESTINFO hti; + hti.pt.x = (short)LOWORD(GetMessagePos()); + hti.pt.y = (short)HIWORD(GetMessagePos()); + ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); + if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) + if (hti.flags&TVHT_ONITEMSTATEICON) { + SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, (LPARAM)hti.hItem); + } + } + else if (((LPNMHDR)lParam)->code == TVN_KEYDOWN) { + if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE) { + SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, + (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom)); + } + } + } + else if (((LPNMHDR)lParam)->idFrom == 0 && ((LPNMHDR)lParam)->code == PSN_APPLY) { + char *pszText = nullptr; + int iLen; + + iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS)); + if (iLen > 0) { + wchar_t *ptszText = (wchar_t*)mir_alloc((iLen + 2) * sizeof(wchar_t)); + wchar_t *p2 = nullptr; + + if (ptszText) { + GetDlgItemText(hwndDlg, IDC_CHAT_HIGHLIGHTWORDS, ptszText, iLen + 1); + p2 = wcschr(ptszText, (wchar_t)','); + while (p2) { + *p2 = ' '; + p2 = wcschr(ptszText, (wchar_t)','); + } + db_set_ws(0, CHAT_MODULE, "HighlightWords", ptszText); + mir_free(ptszText); + } + } + else db_unset(0, CHAT_MODULE, "HighlightWords"); + + iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_LOGDIRECTORY)); + if (iLen > 0) { + wchar_t *pszText1 = (wchar_t*)malloc(iLen*sizeof(wchar_t) + 2); + GetDlgItemText(hwndDlg, IDC_CHAT_LOGDIRECTORY, pszText1, iLen + 1); + db_set_ws(0, CHAT_MODULE, "LogDirectory", pszText1); + free(pszText1); + } + else { + mir_wstrncpy(g_Settings.pszLogDir, DEFLOGFILENAME, MAX_PATH); + db_unset(0, CHAT_MODULE, "LogDirectory"); + } + pci->SM_InvalidateLogDirectories(); + + iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_LOGTIMESTAMP)); + if (iLen > 0) { + pszText = (char*)mir_realloc(pszText, iLen + 1); + GetDlgItemTextA(hwndDlg, IDC_CHAT_LOGTIMESTAMP, pszText, iLen + 1); + db_set_s(0, CHAT_MODULE, "LogTimestamp", pszText); + } + else db_unset(0, CHAT_MODULE, "LogTimestamp"); + + iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_TIMESTAMP)); + if (iLen > 0) { + pszText = (char*)mir_realloc(pszText, iLen + 1); + GetDlgItemTextA(hwndDlg, IDC_CHAT_TIMESTAMP, pszText, iLen + 1); + db_set_s(0, CHAT_MODULE, "HeaderTime", pszText); + } + else db_unset(0, CHAT_MODULE, "HeaderTime"); + + iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_INSTAMP)); + if (iLen > 0) { + pszText = (char*)mir_realloc(pszText, iLen + 1); + GetDlgItemTextA(hwndDlg, IDC_CHAT_INSTAMP, pszText, iLen + 1); + db_set_s(0, CHAT_MODULE, "HeaderIncoming", pszText); + } + else db_unset(0, CHAT_MODULE, "HeaderIncoming"); + + iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_OUTSTAMP)); + if (iLen > 0) { + pszText = (char*)mir_realloc(pszText, iLen + 1); + GetDlgItemTextA(hwndDlg, IDC_CHAT_OUTSTAMP, pszText, iLen + 1); + db_set_s(0, CHAT_MODULE, "HeaderOutgoing", pszText); + } + else db_unset(0, CHAT_MODULE, "HeaderOutgoing"); + + g_Settings.bHighlightEnabled = IsDlgButtonChecked(hwndDlg, IDC_CHAT_HIGHLIGHT) == BST_CHECKED ? TRUE : FALSE; + db_set_b(0, CHAT_MODULE, "HighlightEnabled", (BYTE)g_Settings.bHighlightEnabled); + + g_Settings.bLoggingEnabled = IsDlgButtonChecked(hwndDlg, IDC_CHAT_LOGGING) == BST_CHECKED ? TRUE : FALSE; + db_set_b(0, CHAT_MODULE, "LoggingEnabled", (BYTE)g_Settings.bLoggingEnabled); + + iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_GETPOS, 0, 0); + db_set_w(0, CHAT_MODULE, "LogLimit", (WORD)iLen); + iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN3, UDM_GETPOS, 0, 0); + db_set_w(0, CHAT_MODULE, "LoggingLimit", (WORD)iLen); + + SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch2, _countof(branch2)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch3, _countof(branch3)); + + mir_free(pszText); + + g_Settings.dwIconFlags = db_get_dw(0, CHAT_MODULE, "IconFlags", 0x0000); + g_Settings.dwTrayIconFlags = db_get_dw(0, CHAT_MODULE, "TrayIconFlags", 0x1000); + g_Settings.dwPopupFlags = db_get_dw(0, CHAT_MODULE, "PopupFlags", 0x0000); + g_Settings.bStripFormat = db_get_b(0, CHAT_MODULE, "TrimFormatting", 0) != 0; + g_Settings.bTrayIconInactiveOnly = db_get_b(0, CHAT_MODULE, "TrayIconInactiveOnly", 1) != 0; + g_Settings.bPopupInactiveOnly = db_get_b(0, CHAT_MODULE, "PopUpInactiveOnly", 1) != 0; + g_Settings.bLogIndentEnabled = (db_get_b(0, CHAT_MODULE, "LogIndentEnabled", 1) != 0) ? TRUE : FALSE; + + pci->MM_FontsChanged(); + pci->ReloadSettings(); + Chat_UpdateOptions(); + return TRUE; + } + break; + + case WM_TIMER: + if (IsWindow(hPathTip)) + KillTimer(hPathTip, 4); // It will prevent tooltip autoclosing + break; + + case WM_DESTROY: + if (hPathTip) { + KillTimer(hwndDlg, 0); + DestroyWindow(hPathTip); + hPathTip = 0; + } + + BYTE b = TreeView_GetItemState(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading2, TVIS_EXPANDED)&TVIS_EXPANDED ? 1 : 0; + db_set_b(0, CHAT_MODULE, "Branch2Exp", b); + b = TreeView_GetItemState(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading3, TVIS_EXPANDED)&TVIS_EXPANDED ? 1 : 0; + db_set_b(0, CHAT_MODULE, "Branch3Exp", b); + break; + } + return FALSE; +} + +INT_PTR CALLBACK DlgProcOptionsPopup(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); + SendDlgItemMessage(hwndDlg, IDC_CHAT_BKG, CPM_SETCOLOUR, 0, g_Settings.crPUBkgColour); + SendDlgItemMessage(hwndDlg, IDC_CHAT_TEXT, CPM_SETCOLOUR, 0, g_Settings.crPUTextColour); + + if (g_Settings.iPopupStyle == 2) + CheckDlgButton(hwndDlg, IDC_CHAT_RADIO2, BST_CHECKED); + else if (g_Settings.iPopupStyle == 3) + CheckDlgButton(hwndDlg, IDC_CHAT_RADIO3, BST_CHECKED); + else + CheckDlgButton(hwndDlg, IDC_CHAT_RADIO1, BST_CHECKED); + + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_BKG), IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED ? TRUE : FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_TEXT), IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED ? TRUE : FALSE); + + SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN1, UDM_SETRANGE, 0, MAKELONG(100, -1)); + SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN1, UDM_SETPOS, 0, MAKELONG(g_Settings.iPopupTimeout, 0)); + FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), nullptr, branch6, _countof(branch6), 0x0000); + break; + + case WM_COMMAND: + if ((LOWORD(wParam) == IDC_CHAT_TIMEOUT) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) + return 0; + + if (lParam) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + + switch (LOWORD(wParam)) { + case IDC_CHAT_RADIO1: + case IDC_CHAT_RADIO2: + case IDC_CHAT_RADIO3: + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_BKG), IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED ? TRUE : FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHAT_TEXT), IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED ? TRUE : FALSE); + } + break; + + case WM_NOTIFY: + switch (((LPNMHDR)lParam)->idFrom) { + case IDC_CHAT_CHECKBOXES: + if (((LPNMHDR)lParam)->code == NM_CLICK) { + TVHITTESTINFO hti; + hti.pt.x = (short)LOWORD(GetMessagePos()); + hti.pt.y = (short)HIWORD(GetMessagePos()); + ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); + if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) + if (hti.flags & TVHT_ONITEMSTATEICON) + SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, (LPARAM)hti.hItem); + } + else if (((LPNMHDR)lParam)->code == TVN_KEYDOWN) { + if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE) + SendMessage(hwndDlg, UM_CHECKSTATECHANGE, (WPARAM)((LPNMHDR)lParam)->hwndFrom, + (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom)); + } + break; + + case 0: + switch (((LPNMHDR)lParam)->code) { + case PSN_APPLY: + int iLen; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO2) == BST_CHECKED) + iLen = 2; + else if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_RADIO3) == BST_CHECKED) + iLen = 3; + else + iLen = 1; + + g_Settings.iPopupStyle = iLen; + db_set_b(0, CHAT_MODULE, "PopupStyle", (BYTE)iLen); + + iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN1, UDM_GETPOS, 0, 0); + g_Settings.iPopupTimeout = iLen; + db_set_w(0, CHAT_MODULE, "PopupTimeout", (WORD)iLen); + + g_Settings.crPUBkgColour = SendDlgItemMessage(hwndDlg, IDC_CHAT_BKG, CPM_GETCOLOUR, 0, 0); + db_set_dw(0, CHAT_MODULE, "PopupColorBG", (DWORD)SendDlgItemMessage(hwndDlg, IDC_CHAT_BKG, CPM_GETCOLOUR, 0, 0)); + g_Settings.crPUTextColour = SendDlgItemMessage(hwndDlg, IDC_CHAT_TEXT, CPM_GETCOLOUR, 0, 0); + db_set_dw(0, CHAT_MODULE, "PopupColorText", (DWORD)SendDlgItemMessage(hwndDlg, IDC_CHAT_TEXT, CPM_GETCOLOUR, 0, 0)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), branch6, _countof(branch6)); + } + return TRUE; + } + break; + + case UM_CHECKSTATECHANGE: + PostMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + return FALSE; +} diff --git a/plugins/Scriver/src/chat_tools.cpp b/plugins/Scriver/src/chat_tools.cpp new file mode 100644 index 0000000000..050d4656c5 --- /dev/null +++ b/plugins/Scriver/src/chat_tools.cpp @@ -0,0 +1,120 @@ +/* +Chat module plugin for Miranda IM + +Copyright (C) 2003 Jörgen Persson +Copyright 2003-2009 Miranda ICQ/IM project, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2) +{ + for (int i = 0; s1[i]; i++) + for (int j = i, k = 0; towlower(s1[j]) == towlower(s2[k]); j++, k++) + if (!s2[k + 1]) + return (wchar_t*)(s1 + i); + + return nullptr; +} + +UINT CreateGCMenu(HWND hwnd, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText) +{ + GCMENUITEMS gcmi = { 0 }; + HMENU hSubMenu = 0; + + *hMenu = GetSubMenu(g_hMenu, iIndex); + gcmi.pszID = si->ptszID; + gcmi.pszModule = si->pszModule; + gcmi.pszUID = pszUID; + + if (iIndex == 1) { + int iLen = GetRichTextLength(hwnd, CP_ACP, FALSE); + + EnableMenuItem(*hMenu, IDM_CLEAR, MF_ENABLED); + EnableMenuItem(*hMenu, ID_COPYALL, MF_ENABLED); + if (!iLen) { + EnableMenuItem(*hMenu, ID_COPYALL, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(*hMenu, IDM_CLEAR, MF_BYCOMMAND | MF_GRAYED); + } + + if (pszWordText && pszWordText[0]) { + wchar_t szMenuText[4096]; + mir_snwprintf(szMenuText, TranslateT("Look up '%s':"), pszWordText); + ModifyMenu(*hMenu, 4, MF_STRING | MF_BYPOSITION, 4, szMenuText); + SetSearchEngineIcons(*hMenu, g_dat.hSearchEngineIconList); + } + else ModifyMenu(*hMenu, 4, MF_STRING | MF_GRAYED | MF_BYPOSITION, 4, TranslateT("No word to look up")); + gcmi.Type = MENU_ON_LOG; + } + else if (iIndex == 0) { + wchar_t szTemp[50]; + if (pszWordText) + mir_snwprintf(szTemp, TranslateT("&Message %s"), pszWordText); + else + mir_wstrncpy(szTemp, TranslateT("&Message"), _countof(szTemp) - 1); + + if (mir_wstrlen(szTemp) > 40) + mir_wstrncpy(szTemp + 40, L"...", 4); + ModifyMenu(*hMenu, ID_MESS, MF_STRING | MF_BYCOMMAND, ID_MESS, szTemp); + gcmi.Type = MENU_ON_NICKLIST; + } + + NotifyEventHooks(pci->hBuildMenuEvent, 0, (WPARAM)&gcmi); + + if (gcmi.nItems > 0) + AppendMenu(*hMenu, MF_SEPARATOR, 0, 0); + + for (int i = 0; i < gcmi.nItems; i++) { + wchar_t *ptszText = TranslateW(gcmi.Item[i].pszDesc); + DWORD dwState = gcmi.Item[i].bDisabled ? MF_GRAYED : 0; + + if (gcmi.Item[i].uType == MENU_NEWPOPUP) { + hSubMenu = CreateMenu(); + AppendMenu(*hMenu, dwState | MF_POPUP, (UINT_PTR)hSubMenu, ptszText); + } + else if (gcmi.Item[i].uType == MENU_POPUPHMENU) + AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_POPUP, gcmi.Item[i].dwID, ptszText); + else if (gcmi.Item[i].uType == MENU_POPUPITEM) + AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_STRING, gcmi.Item[i].dwID, ptszText); + else if (gcmi.Item[i].uType == MENU_POPUPCHECK) + AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_CHECKED | MF_STRING, gcmi.Item[i].dwID, ptszText); + else if (gcmi.Item[i].uType == MENU_POPUPSEPARATOR) + AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, MF_SEPARATOR, 0, ptszText); + else if (gcmi.Item[i].uType == MENU_SEPARATOR) + AppendMenu(*hMenu, MF_SEPARATOR, 0, ptszText); + else if (gcmi.Item[i].uType == MENU_HMENU) + AppendMenu(*hMenu, dwState | MF_POPUP, gcmi.Item[i].dwID, ptszText); + else if (gcmi.Item[i].uType == MENU_ITEM) + AppendMenu(*hMenu, dwState | MF_STRING, gcmi.Item[i].dwID, ptszText); + else if (gcmi.Item[i].uType == MENU_CHECK) + AppendMenu(*hMenu, dwState | MF_CHECKED | MF_STRING, gcmi.Item[i].dwID, ptszText); + } + return TrackPopupMenu(*hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, nullptr); +} + +void DestroyGCMenu(HMENU *hMenu, int iIndex) +{ + MENUITEMINFO mii = { 0 }; + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_SUBMENU; + while(GetMenuItemInfo(*hMenu, iIndex, TRUE, &mii)) + { + if (mii.hSubMenu != nullptr) + DestroyMenu(mii.hSubMenu); + RemoveMenu(*hMenu, iIndex, MF_BYPOSITION); + } +} diff --git a/plugins/Scriver/src/chat_window.cpp b/plugins/Scriver/src/chat_window.cpp new file mode 100644 index 0000000000..b6a9cd29d3 --- /dev/null +++ b/plugins/Scriver/src/chat_window.cpp @@ -0,0 +1,1637 @@ +/* +Chat module plugin for Miranda IM + +Copyright (C) 2003 Jörgen Persson +Copyright 2003-2009 Miranda ICQ/IM project, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +struct MESSAGESUBDATA +{ + time_t lastEnterTime; + wchar_t *szSearchQuery; + wchar_t *szSearchResult; + SESSION_INFO *lastSession; +}; + +static void TabAutoComplete(HWND hwnd, MESSAGESUBDATA *dat, SESSION_INFO *si) +{ + LRESULT lResult = (LRESULT)SendMessage(hwnd, EM_GETSEL, 0, 0); + int start = LOWORD(lResult), end = HIWORD(lResult); + SendMessage(hwnd, EM_SETSEL, end, end); + + GETTEXTEX gt = { 0 }; + gt.codepage = 1200; + int iLen = GetRichTextLength(hwnd, gt.codepage, TRUE); + if (iLen <= 0) + return; + + bool isTopic = false, isRoom = false; + wchar_t *pszName = nullptr; + wchar_t* pszText = (wchar_t*)mir_alloc(iLen + 100 * sizeof(wchar_t)); + gt.cb = iLen + 99 * sizeof(wchar_t); + gt.flags = GT_DEFAULT; + + SendMessage(hwnd, EM_GETTEXTEX, (WPARAM)>, (LPARAM)pszText); + if (start > 1 && pszText[start - 1] == ' ' && pszText[start - 2] == ':') + start -= 2; + + if (dat->szSearchResult != nullptr) { + int cbResult = (int)mir_wstrlen(dat->szSearchResult); + if (start >= cbResult && !wcsnicmp(dat->szSearchResult, pszText + start - cbResult, cbResult)) { + start -= cbResult; + goto LBL_SkipEnd; + } + } + + while (start > 0 && pszText[start - 1] != ' ' && pszText[start - 1] != 13 && pszText[start - 1] != VK_TAB) + start--; + +LBL_SkipEnd: + while (end < iLen && pszText[end] != ' ' && pszText[end] != 13 && pszText[end - 1] != VK_TAB) + end++; + + if (pszText[start] == '#') + isRoom = true; + else { + int topicStart = start; + while (topicStart >0 && (pszText[topicStart - 1] == ' ' || pszText[topicStart - 1] == 13 || pszText[topicStart - 1] == VK_TAB)) + topicStart--; + if (topicStart > 5 && wcsstr(&pszText[topicStart - 6], L"/topic") == &pszText[topicStart - 6]) + isTopic = true; + } + + if (dat->szSearchQuery == nullptr) { + dat->szSearchQuery = (wchar_t*)mir_alloc(sizeof(wchar_t)*(end - start + 1)); + mir_wstrncpy(dat->szSearchQuery, pszText + start, end - start + 1); + dat->szSearchResult = mir_wstrdup(dat->szSearchQuery); + dat->lastSession = nullptr; + } + + if (isTopic) + pszName = si->ptszTopic; + else if (isRoom) { + dat->lastSession = SM_FindSessionAutoComplete(si->pszModule, si, dat->lastSession, dat->szSearchQuery, dat->szSearchResult); + if (dat->lastSession != nullptr) + pszName = dat->lastSession->ptszName; + } + else pszName = pci->UM_FindUserAutoComplete(si->pUsers, dat->szSearchQuery, dat->szSearchResult); + + mir_free(pszText); + replaceStrW(dat->szSearchResult, nullptr); + + if (pszName == nullptr) { + if (end != start) { + SendMessage(hwnd, EM_SETSEL, start, end); + SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)dat->szSearchQuery); + } + replaceStrW(dat->szSearchQuery, nullptr); + } + else { + dat->szSearchResult = mir_wstrdup(pszName); + if (end != start) { + ptrW szReplace; + if (!isRoom && !isTopic && g_Settings.bAddColonToAutoComplete && start == 0) { + szReplace = (wchar_t*)mir_alloc((mir_wstrlen(pszName) + 4) * sizeof(wchar_t)); + mir_wstrcpy(szReplace, pszName); + mir_wstrcat(szReplace, L": "); + pszName = szReplace; + } + SendMessage(hwnd, EM_SETSEL, start, end); + SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)pszName); + } + } +} + +LRESULT CALLBACK CChatRoomDlg::MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + BOOL isShift = GetKeyState(VK_SHIFT) & 0x8000; + BOOL isCtrl = GetKeyState(VK_CONTROL) & 0x8000; + BOOL isAlt = GetKeyState(VK_MENU) & 0x8000; + + MESSAGESUBDATA *dat = (MESSAGESUBDATA *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + CChatRoomDlg *pDlg = (CChatRoomDlg*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); + + int result = InputAreaShortcuts(hwnd, msg, wParam, lParam, pDlg); + if (result != -1) + return result; + + switch (msg) { + case EM_SUBCLASSED: + dat = (MESSAGESUBDATA*)mir_calloc(sizeof(MESSAGESUBDATA)); + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat); + return 0; + + case WM_MOUSEWHEEL: + if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_VSCROLL) == 0) + SendDlgItemMessage(GetParent(hwnd), IDC_LOG, WM_MOUSEWHEEL, wParam, lParam); + + dat->lastEnterTime = 0; + return TRUE; + + case EM_REPLACESEL: + PostMessage(hwnd, EM_ACTIVATE, 0, 0); + break; + + case EM_ACTIVATE: + SetActiveWindow(GetParent(hwnd)); + break; + + case WM_KEYDOWN: + if (wParam == VK_RETURN) { + mir_free(dat->szSearchQuery); + dat->szSearchQuery = nullptr; + mir_free(dat->szSearchResult); + dat->szSearchResult = nullptr; + if ((isCtrl != 0) ^ (0 != db_get_b(0, SRMMMOD, SRMSGSET_SENDONENTER, SRMSGDEFSET_SENDONENTER))) { + PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); + return 0; + } + if (db_get_b(0, SRMMMOD, SRMSGSET_SENDONDBLENTER, SRMSGDEFSET_SENDONDBLENTER)) { + if (dat->lastEnterTime + 2 < time(nullptr)) + dat->lastEnterTime = time(nullptr); + else { + SendMessage(hwnd, WM_KEYDOWN, VK_BACK, 0); + SendMessage(hwnd, WM_KEYUP, VK_BACK, 0); + PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); + return 0; + } + } + } + else dat->lastEnterTime = 0; + + if (wParam == VK_TAB && isShift && !isCtrl) { // SHIFT-TAB (go to nick list) + SetFocus(GetDlgItem(GetParent(hwnd), IDC_CHAT_LIST)); + return TRUE; + } + + if (wParam == VK_TAB && !isCtrl && !isShift) { //tab-autocomplete + SendMessage(hwnd, WM_SETREDRAW, FALSE, 0); + TabAutoComplete(hwnd, dat, pDlg->m_si); + SendMessage(hwnd, WM_SETREDRAW, TRUE, 0); + RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE); + return 0; + } + if (wParam != VK_RIGHT && wParam != VK_LEFT) { + mir_free(dat->szSearchQuery); + dat->szSearchQuery = nullptr; + mir_free(dat->szSearchResult); + dat->szSearchResult = nullptr; + } + if (wParam == 0x49 && isCtrl && !isAlt) { // ctrl-i (italics) + CheckDlgButton(GetParent(hwnd), IDC_ITALICS, IsDlgButtonChecked(GetParent(hwnd), IDC_ITALICS) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_ITALICS, 0), 0); + return TRUE; + } + + if (wParam == 0x42 && isCtrl && !isAlt) { // ctrl-b (bold) + CheckDlgButton(GetParent(hwnd), IDC_BOLD, IsDlgButtonChecked(GetParent(hwnd), IDC_BOLD) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BOLD, 0), 0); + return TRUE; + } + + if (wParam == 0x55 && isCtrl && !isAlt) { // ctrl-u (paste clean text) + CheckDlgButton(GetParent(hwnd), IDC_UNDERLINE, IsDlgButtonChecked(GetParent(hwnd), IDC_UNDERLINE) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_UNDERLINE, 0), 0); + return TRUE; + } + + if (wParam == 0x4b && isCtrl && !isAlt) { // ctrl-k (paste clean text) + CheckDlgButton(GetParent(hwnd), IDC_COLOR, IsDlgButtonChecked(GetParent(hwnd), IDC_COLOR) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_COLOR, 0), 0); + return TRUE; + } + + if (wParam == VK_SPACE && isCtrl && !isAlt) { // ctrl-space (paste clean text) + CheckDlgButton(GetParent(hwnd), IDC_BKGCOLOR, BST_UNCHECKED); + CheckDlgButton(GetParent(hwnd), IDC_COLOR, BST_UNCHECKED); + CheckDlgButton(GetParent(hwnd), IDC_BOLD, BST_UNCHECKED); + CheckDlgButton(GetParent(hwnd), IDC_UNDERLINE, BST_UNCHECKED); + CheckDlgButton(GetParent(hwnd), IDC_ITALICS, BST_UNCHECKED); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BKGCOLOR, 0), 0); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_COLOR, 0), 0); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BOLD, 0), 0); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_UNDERLINE, 0), 0); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_ITALICS, 0), 0); + return TRUE; + } + + if (wParam == 0x4c && isCtrl && !isAlt) { // ctrl-l (paste clean text) + CheckDlgButton(GetParent(hwnd), IDC_BKGCOLOR, IsDlgButtonChecked(GetParent(hwnd), IDC_BKGCOLOR) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BKGCOLOR, 0), 0); + return TRUE; + } + + if (wParam == 0x46 && isCtrl && !isAlt) { // ctrl-f (paste clean text) + if (IsWindowEnabled(GetDlgItem(GetParent(hwnd), IDC_FILTER))) + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_FILTER, 0), 0); + return TRUE; + } + + if (wParam == 0x4e && isCtrl && !isAlt) { // ctrl-n (nicklist) + if (IsWindowEnabled(GetDlgItem(GetParent(hwnd), IDC_SHOWNICKLIST))) + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_SHOWNICKLIST, 0), 0); + return TRUE; + } + + if (wParam == 0x48 && isCtrl && !isAlt) { // ctrl-h (history) + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_HISTORY, 0), 0); + return TRUE; + } + + if (wParam == 0x4f && isCtrl && !isAlt) { // ctrl-o (options) + if (IsWindowEnabled(GetDlgItem(GetParent(hwnd), IDC_CHANMGR))) + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_CHANMGR, 0), 0); + return TRUE; + } + + if (((wParam == VK_INSERT && isShift) || (wParam == 'V' && isCtrl)) && !isAlt) { // ctrl-v (paste clean text) + SendMessage(hwnd, EM_PASTESPECIAL, CF_UNICODETEXT, 0); + return TRUE; + } + + if (wParam == VK_NEXT || wParam == VK_PRIOR) { + HWND htemp = GetParent(hwnd); + SendDlgItemMessage(htemp, IDC_LOG, msg, wParam, lParam); + return TRUE; + } + break; + + case WM_LBUTTONDOWN: + case WM_MBUTTONDOWN: + case WM_KILLFOCUS: + dat->lastEnterTime = 0; + break; + + case WM_CONTEXTMENU: + InputAreaContextMenu(hwnd, wParam, lParam, pDlg->m_hContact); + return TRUE; + + case WM_KEYUP: + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + { + UINT u = 0; + UINT u2 = 0; + COLORREF cr; + SESSION_INFO *si = pDlg->m_si; + + LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, nullptr, &cr); + + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_BACKCOLOR | CFM_COLOR; + SendMessage(hwnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + + if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bColor) { + int index = pci->GetColorIndex(si->pszModule, cf.crTextColor); + u = IsDlgButtonChecked(GetParent(hwnd), IDC_COLOR); + + if (index >= 0) { + pDlg->m_bFGSet = true; + pDlg->m_iFG = index; + } + + if (u == BST_UNCHECKED && cf.crTextColor != cr) + CheckDlgButton(GetParent(hwnd), IDC_COLOR, BST_CHECKED); + else if (u == BST_CHECKED && cf.crTextColor == cr) + CheckDlgButton(GetParent(hwnd), IDC_COLOR, BST_UNCHECKED); + } + + if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bBkgColor) { + int index = pci->GetColorIndex(si->pszModule, cf.crBackColor); + COLORREF crB = db_get_dw(0, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); + u = IsDlgButtonChecked(GetParent(hwnd), IDC_BKGCOLOR); + + if (index >= 0) { + pDlg->m_bBGSet = TRUE; + pDlg->m_iBG = index; + } + if (u == BST_UNCHECKED && cf.crBackColor != crB) + CheckDlgButton(GetParent(hwnd), IDC_BKGCOLOR, BST_CHECKED); + else if (u == BST_CHECKED && cf.crBackColor == crB) + CheckDlgButton(GetParent(hwnd), IDC_BKGCOLOR, BST_UNCHECKED); + } + + if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bBold) { + u = IsDlgButtonChecked(GetParent(hwnd), IDC_BOLD); + u2 = cf.dwEffects; + u2 &= CFE_BOLD; + if (u == BST_UNCHECKED && u2) + CheckDlgButton(GetParent(hwnd), IDC_BOLD, BST_CHECKED); + else if (u == BST_CHECKED && u2 == 0) + CheckDlgButton(GetParent(hwnd), IDC_BOLD, BST_UNCHECKED); + } + + if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bItalics) { + u = IsDlgButtonChecked(GetParent(hwnd), IDC_ITALICS); + u2 = cf.dwEffects; + u2 &= CFE_ITALIC; + if (u == BST_UNCHECKED && u2) + CheckDlgButton(GetParent(hwnd), IDC_ITALICS, BST_CHECKED); + else if (u == BST_CHECKED && u2 == 0) + CheckDlgButton(GetParent(hwnd), IDC_ITALICS, BST_UNCHECKED); + } + + if (pci->MM_FindModule(si->pszModule) && pci->MM_FindModule(si->pszModule)->bUnderline) { + u = IsDlgButtonChecked(GetParent(hwnd), IDC_UNDERLINE); + u2 = cf.dwEffects; + u2 &= CFE_UNDERLINE; + if (u == BST_UNCHECKED && u2) + CheckDlgButton(GetParent(hwnd), IDC_UNDERLINE, BST_CHECKED); + else if (u == BST_CHECKED && u2 == 0) + CheckDlgButton(GetParent(hwnd), IDC_UNDERLINE, BST_UNCHECKED); + } + } + break; + + case WM_DESTROY: + mir_free(dat->szSearchQuery); + mir_free(dat->szSearchResult); + mir_free(dat); + return 0; + } + + return mir_callNextSubclass(hwnd, MessageSubclassProc, msg, wParam, lParam); +} + +INT_PTR CALLBACK CChatRoomDlg::FilterWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + static CChatRoomDlg *pDlg = nullptr; + switch (uMsg) { + case WM_INITDIALOG: + pDlg = (CChatRoomDlg*)lParam; + CheckDlgButton(hwndDlg, IDC_CHAT_1, pDlg->m_iLogFilterFlags & GC_EVENT_ACTION ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_2, pDlg->m_iLogFilterFlags & GC_EVENT_MESSAGE ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_3, pDlg->m_iLogFilterFlags & GC_EVENT_NICK ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_4, pDlg->m_iLogFilterFlags & GC_EVENT_JOIN ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_5, pDlg->m_iLogFilterFlags & GC_EVENT_PART ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_6, pDlg->m_iLogFilterFlags & GC_EVENT_TOPIC ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_7, pDlg->m_iLogFilterFlags & GC_EVENT_ADDSTATUS ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_8, pDlg->m_iLogFilterFlags & GC_EVENT_INFORMATION ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_9, pDlg->m_iLogFilterFlags & GC_EVENT_QUIT ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_10, pDlg->m_iLogFilterFlags & GC_EVENT_KICK ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHAT_11, pDlg->m_iLogFilterFlags & GC_EVENT_NOTICE ? BST_CHECKED : BST_UNCHECKED); + break; + + case WM_CTLCOLOREDIT: + case WM_CTLCOLORSTATIC: + SetTextColor((HDC)wParam, RGB(60, 60, 150)); + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); + return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); + + case WM_ACTIVATE: + if (LOWORD(wParam) == WA_INACTIVE) { + int iFlags = 0; + + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_1) == BST_CHECKED) + iFlags |= GC_EVENT_ACTION; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_2) == BST_CHECKED) + iFlags |= GC_EVENT_MESSAGE; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_3) == BST_CHECKED) + iFlags |= GC_EVENT_NICK; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_4) == BST_CHECKED) + iFlags |= GC_EVENT_JOIN; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_5) == BST_CHECKED) + iFlags |= GC_EVENT_PART; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_6) == BST_CHECKED) + iFlags |= GC_EVENT_TOPIC; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_7) == BST_CHECKED) + iFlags |= GC_EVENT_ADDSTATUS; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_8) == BST_CHECKED) + iFlags |= GC_EVENT_INFORMATION; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_9) == BST_CHECKED) + iFlags |= GC_EVENT_QUIT; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_10) == BST_CHECKED) + iFlags |= GC_EVENT_KICK; + if (IsDlgButtonChecked(hwndDlg, IDC_CHAT_11) == BST_CHECKED) + iFlags |= GC_EVENT_NOTICE; + + if (iFlags & GC_EVENT_ADDSTATUS) + iFlags |= GC_EVENT_REMOVESTATUS; + + pDlg->m_iLogFilterFlags = iFlags; + if (pDlg->m_bFilterEnabled) + pDlg->RedrawLog(); + PostMessage(hwndDlg, WM_CLOSE, 0, 0); + } + break; + + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + } + + return FALSE; +} + +LRESULT CALLBACK CChatRoomDlg::LogSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + static BOOL inMenu = FALSE; + CChatRoomDlg *pDlg = (CChatRoomDlg*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); + + int result = InputAreaShortcuts(hwnd, msg, wParam, lParam, pDlg); + if (result != -1) + return result; + + CHARRANGE sel; + + switch (msg) { + case WM_MEASUREITEM: + MeasureMenuItem(wParam, lParam); + return TRUE; + + case WM_DRAWITEM: + return DrawMenuItem(wParam, lParam); + + case WM_SETCURSOR: + if (inMenu) { + SetCursor(LoadCursor(nullptr, IDC_ARROW)); + return TRUE; + } + break; + + case WM_LBUTTONUP: + SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); + if (sel.cpMin != sel.cpMax) { + SendMessage(hwnd, WM_COPY, 0, 0); + sel.cpMin = sel.cpMax; + SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); + } + SetFocus(GetDlgItem(GetParent(hwnd), IDC_MESSAGE)); + break; + + case WM_ACTIVATE: + if (LOWORD(wParam) == WA_INACTIVE) { + SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); + if (sel.cpMin != sel.cpMax) { + sel.cpMin = sel.cpMax; + SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); + } + } + break; + + case WM_CONTEXTMENU: + POINT pt; + POINTL ptl; + SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); + if (lParam == 0xFFFFFFFF) { + SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM)sel.cpMax); + ClientToScreen(hwnd, &pt); + } + else { + pt.x = GET_X_LPARAM(lParam); + pt.y = GET_Y_LPARAM(lParam); + } + ptl.x = (LONG)pt.x; + ptl.y = (LONG)pt.y; + ScreenToClient(hwnd, (LPPOINT)&ptl); + { + ptrW pszWord(GetRichTextWord(hwnd, &ptl)); + inMenu = TRUE; + + SESSION_INFO *si = pDlg->m_si; + CHARRANGE all = { 0, -1 }; + HMENU hMenu = nullptr; + UINT uID = CreateGCMenu(hwnd, &hMenu, 1, pt, si, nullptr, pszWord); + inMenu = FALSE; + switch (uID) { + case 0: + PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); + break; + + case ID_COPYALL: + SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); + SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&all); + SendMessage(hwnd, WM_COPY, 0, 0); + SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); + PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); + break; + + case IDM_CLEAR: + if (si) { + SetWindowText(hwnd, L""); + pci->LM_RemoveAll(&si->pLog, &si->pLogEnd); + si->iEventCount = 0; + si->LastTime = 0; + PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); + } + break; + + case IDM_SEARCH_GOOGLE: + case IDM_SEARCH_BING: + case IDM_SEARCH_YANDEX: + case IDM_SEARCH_YAHOO: + case IDM_SEARCH_WIKIPEDIA: + case IDM_SEARCH_FOODNETWORK: + case IDM_SEARCH_GOOGLE_MAPS: + case IDM_SEARCH_GOOGLE_TRANSLATE: + SearchWord(pszWord, uID - IDM_SEARCH_GOOGLE + SEARCHENGINE_GOOGLE); + PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); + break; + + default: + PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0); + pDlg->DoEventHook(GC_USER_LOGMENU, nullptr, nullptr, uID); + break; + } + DestroyGCMenu(&hMenu, 5); + } + break; + + case WM_CHAR: + SetFocus(GetDlgItem(GetParent(hwnd), IDC_MESSAGE)); + SendDlgItemMessage(GetParent(hwnd), IDC_MESSAGE, WM_CHAR, wParam, lParam); + break; + } + + return mir_callNextSubclass(hwnd, LogSubclassProc, msg, wParam, lParam); +} + +LRESULT CALLBACK CChatRoomDlg::NicklistSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + CChatRoomDlg *pDlg = (CChatRoomDlg*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); + + int result = InputAreaShortcuts(hwnd, msg, wParam, lParam, pDlg); + if (result != -1) + return result; + + switch (msg) { + case WM_ERASEBKGND: + { + HDC dc = (HDC)wParam; + if (dc) { + int index = SendMessage(hwnd, LB_GETTOPINDEX, 0, 0); + if (index == LB_ERR || pDlg->m_si->nUsersInNicklist <= 0) + return 0; + + int items = pDlg->m_si->nUsersInNicklist - index; + int height = SendMessage(hwnd, LB_GETITEMHEIGHT, 0, 0); + + if (height != LB_ERR) { + RECT rc = { 0 }; + GetClientRect(hwnd, &rc); + + if (rc.bottom - rc.top > items * height) { + rc.top = items*height; + FillRect(dc, &rc, pci->hListBkgBrush); + } + } + } + } + return 1; + + case WM_RBUTTONDOWN: + SendMessage(hwnd, WM_LBUTTONDOWN, wParam, lParam); + break; + + case WM_RBUTTONUP: + SendMessage(hwnd, WM_LBUTTONUP, wParam, lParam); + break; + + case WM_MEASUREITEM: + { + MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam; + if (mis->CtlType == ODT_MENU) + return Menu_MeasureItem(lParam); + } + return FALSE; + + case WM_DRAWITEM: + { + DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; + if (dis->CtlType == ODT_MENU) + return Menu_DrawItem(lParam); + } + return FALSE; + + case WM_CONTEXTMENU: + { + int height = 0; + + TVHITTESTINFO hti; + hti.pt.x = GET_X_LPARAM(lParam); + hti.pt.y = GET_Y_LPARAM(lParam); + if (hti.pt.x == -1 && hti.pt.y == -1) { + int index = SendMessage(hwnd, LB_GETCURSEL, 0, 0); + int top = SendMessage(hwnd, LB_GETTOPINDEX, 0, 0); + height = SendMessage(hwnd, LB_GETITEMHEIGHT, 0, 0); + hti.pt.x = 4; + hti.pt.y = (index - top)*height + 1; + } + else ScreenToClient(hwnd, &hti.pt); + + DWORD item = (DWORD)(SendMessage(hwnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(hti.pt.x, hti.pt.y))); + if (HIWORD(item) == 1) + item = (DWORD)(-1); + else + item &= 0xFFFF; + + USERINFO *ui = pci->SM_GetUserFromIndex(pDlg->m_si->ptszID, pDlg->m_si->pszModule, (int)item); + if (ui) { + HMENU hMenu = 0; + UINT uID; + USERINFO uinew; + + memcpy(&uinew, ui, sizeof(USERINFO)); + if (hti.pt.x == -1 && hti.pt.y == -1) + hti.pt.y += height - 4; + ClientToScreen(hwnd, &hti.pt); + uID = CreateGCMenu(hwnd, &hMenu, 0, hti.pt, pDlg->m_si, uinew.pszUID, uinew.pszNick); + + switch (uID) { + case 0: + break; + + case ID_MESS: + pDlg->DoEventHook(GC_USER_PRIVMESS, ui, nullptr, 0); + break; + + default: + pDlg->DoEventHook(GC_USER_NICKLISTMENU, ui, nullptr, uID); + break; + } + DestroyGCMenu(&hMenu, 1); + return TRUE; + } + } + break; + + case WM_GETDLGCODE: + { + BOOL isAlt = GetKeyState(VK_MENU) & 0x8000; + BOOL isCtrl = (GetKeyState(VK_CONTROL) & 0x8000) && !isAlt; + + LPMSG lpmsg; + if ((lpmsg = (LPMSG)lParam) != nullptr) { + if (lpmsg->message == WM_KEYDOWN + && (lpmsg->wParam == VK_RETURN || lpmsg->wParam == VK_ESCAPE || (lpmsg->wParam == VK_TAB && (isAlt || isCtrl)))) + return DLGC_WANTALLKEYS; + } + } + break; + + case WM_KEYDOWN: + if (wParam == VK_RETURN) { + int index = SendMessage(hwnd, LB_GETCURSEL, 0, 0); + if (index != LB_ERR) { + USERINFO *ui = pci->SM_GetUserFromIndex(pDlg->m_si->ptszID, pDlg->m_si->pszModule, index); + pDlg->DoEventHook(GC_USER_PRIVMESS, ui, nullptr, 0); + } + break; + } + if (wParam == VK_ESCAPE || wParam == VK_UP || wParam == VK_DOWN || wParam == VK_NEXT || + wParam == VK_PRIOR || wParam == VK_TAB || wParam == VK_HOME || wParam == VK_END) { + pDlg->m_wszSearch[0] = 0; + } + break; + + case WM_CHAR: + case WM_UNICHAR: + /* + * simple incremental search for the user (nick) - list control + * typing esc or movement keys will clear the current search string + */ + if (wParam == 27 && pDlg->m_wszSearch[0]) { // escape - reset everything + pDlg->m_wszSearch[0] = 0; + break; + } + else if (wParam == '\b' && pDlg->m_wszSearch[0]) // backspace + pDlg->m_wszSearch[mir_wstrlen(pDlg->m_wszSearch) - 1] = '\0'; + else if (wParam < ' ') + break; + else { + wchar_t szNew[2]; + szNew[0] = (wchar_t)wParam; + szNew[1] = '\0'; + if (mir_wstrlen(pDlg->m_wszSearch) >= _countof(pDlg->m_wszSearch) - 2) { + MessageBeep(MB_OK); + break; + } + mir_wstrcat(pDlg->m_wszSearch, szNew); + } + if (pDlg->m_wszSearch[0]) { + // iterate over the (sorted) list of nicknames and search for the + // string we have + int iItems = SendMessage(hwnd, LB_GETCOUNT, 0, 0); + for (int i = 0; i < iItems; i++) { + USERINFO *ui = pci->UM_FindUserFromIndex(pDlg->m_si->pUsers, i); + if (ui) { + if (!wcsnicmp(ui->pszNick, pDlg->m_wszSearch, mir_wstrlen(pDlg->m_wszSearch))) { + SendMessage(hwnd, LB_SETCURSEL, i, 0); + InvalidateRect(hwnd, nullptr, FALSE); + return 0; + } + } + } + + MessageBeep(MB_OK); + pDlg->m_wszSearch[mir_wstrlen(pDlg->m_wszSearch) - 1] = '\0'; + return 0; + } + break; + + case WM_MOUSEMOVE: + Chat_HoverMouse(pDlg->m_si, hwnd, lParam, ServiceExists("mToolTip/HideTip")); + break; + } + + return mir_callNextSubclass(hwnd, NicklistSubclassProc, msg, wParam, lParam); +} + +int GetTextPixelSize(wchar_t* pszText, HFONT hFont, BOOL bWidth) +{ + if (!pszText || !hFont) + return 0; + + HDC hdc = GetDC(nullptr); + HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); + + RECT rc = { 0 }; + DrawText(hdc, pszText, -1, &rc, DT_CALCRECT); + SelectObject(hdc, hOldFont); + ReleaseDC(nullptr, hdc); + return bWidth ? rc.right - rc.left : rc.bottom - rc.top; +} + +static void __cdecl phase2(void *lParam) +{ + Thread_SetName("Scriver: phase2"); + + SESSION_INFO *si = (SESSION_INFO*)lParam; + Sleep(30); + if (si && si->pDlg) + si->pDlg->RedrawLog2(); +} + +void CChatRoomDlg::FixTabIcons() +{ + HICON hIcon; + 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; + + TabControlData tcd = {}; + tcd.iFlags = TCDF_ICON; + tcd.hIcon = hIcon; + SendMessage(m_hwndParent, CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)m_hwnd); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +void CChatRoomDlg::MessageDialogResize(int w, int h) +{ + bool bNick = m_si->iType != GCW_SERVER && m_bNicklistEnabled; + bool bToolbar = SendMessage(m_hwndParent, CM_GETTOOLBARSTATUS, 0, 0) != 0; + int hSplitterMinTop = TOOLBAR_HEIGHT + m_minLogBoxHeight, hSplitterMinBottom = m_minEditBoxHeight; + int toolbarHeight = bToolbar ? TOOLBAR_HEIGHT : 0; + + if (h - m_pParent->iSplitterY < hSplitterMinTop) + m_pParent->iSplitterY = h - hSplitterMinTop; + if (m_pParent->iSplitterY < hSplitterMinBottom) + m_pParent->iSplitterY = hSplitterMinBottom; + + ShowWindow(m_splitterX.GetHwnd(), bNick ? SW_SHOW : SW_HIDE); + if (m_si->iType != GCW_SERVER) + ShowWindow(m_nickList.GetHwnd(), m_bNicklistEnabled ? SW_SHOW : SW_HIDE); + else + ShowWindow(m_nickList.GetHwnd(), SW_HIDE); + + if (m_si->iType == GCW_SERVER) { + m_btnShowList.Enable(false); + m_btnFilter.Enable(false); + m_btnChanMgr.Enable(false); + } + else { + m_btnShowList.Enable(true); + m_btnFilter.Enable(true); + if (m_si->iType == GCW_CHATROOM) + m_btnChanMgr.Enable(pci->MM_FindModule(m_si->pszModule)->bChanMgr); + } + + int toolbarTopY = bToolbar ? h - m_pParent->iSplitterY - toolbarHeight : h - m_pParent->iSplitterY; + int logBottom = (m_hwndIeview != nullptr) ? toolbarTopY / 2 : toolbarTopY; + + HDWP hdwp = BeginDeferWindowPos(5); + hdwp = DeferWindowPos(hdwp, m_log.GetHwnd(), 0, 1, 0, bNick ? w - m_pParent->iSplitterX - 1 : w - 2, logBottom, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, m_nickList.GetHwnd(), 0, w - m_pParent->iSplitterX + 2, 0, m_pParent->iSplitterX - 3, toolbarTopY, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, m_splitterX.GetHwnd(), 0, w - m_pParent->iSplitterX, 1, 2, toolbarTopY - 1, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, m_splitterY.GetHwnd(), 0, 0, h - m_pParent->iSplitterY, w, SPLITTER_HEIGHT, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, m_message.GetHwnd(), 0, 1, h - m_pParent->iSplitterY + SPLITTER_HEIGHT, w - 2, m_pParent->iSplitterY - SPLITTER_HEIGHT - 1, SWP_NOZORDER); + EndDeferWindowPos(hdwp); + + SetButtonsPos(m_hwnd, m_hContact, bToolbar); + + if (m_hwndIeview != nullptr) { + IEVIEWWINDOW ieWindow; + ieWindow.cbSize = sizeof(IEVIEWWINDOW); + ieWindow.iType = IEW_SETPOS; + ieWindow.parent = m_hwnd; + ieWindow.hwnd = m_hwndIeview; + ieWindow.x = 0; + ieWindow.y = logBottom + 1; + ieWindow.cx = bNick ? w - m_pParent->iSplitterX : w; + ieWindow.cy = logBottom; + CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); + } + else RedrawWindow(m_log.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); + + RedrawWindow(m_nickList.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); + RedrawWindow(m_message.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); +} + +CChatRoomDlg::CChatRoomDlg(SESSION_INFO *si) + : CScriverWindow(IDD_CHANNEL, si), + + m_log(this, IDC_LOG), + m_message(this, IDC_MESSAGE), + m_nickList(this, IDC_CHAT_LIST), + + m_splitterX(this, IDC_SPLITTERX), + m_splitterY(this, IDC_SPLITTERY), + + m_btnOk(this, IDOK), + m_btnBold(this, IDC_BOLD), + m_btnColor(this, IDC_COLOR), + m_btnFilter(this, IDC_FILTER), + m_btnItalic(this, IDC_ITALICS), + m_btnHistory(this, IDC_HISTORY), + m_btnChanMgr(this, IDC_CHANMGR), + m_btnBkColor(this, IDC_BKGCOLOR), + m_btnShowList(this, IDC_SHOWNICKLIST), + m_btnUnderline(this, IDC_UNDERLINE) +{ + m_pLog = &m_log; + m_pEntry = &m_message; + m_pColor = &m_btnColor; + m_pBkColor = &m_btnBkColor; + m_pFilter = &m_btnFilter; + + m_btnOk.OnClick = Callback(this, &CChatRoomDlg::onClick_Ok); + m_btnFilter.OnClick = Callback(this, &CChatRoomDlg::onClick_Filter); + m_btnHistory.OnClick = Callback(this, &CChatRoomDlg::onClick_History); + m_btnChanMgr.OnClick = Callback(this, &CChatRoomDlg::onClick_ChanMgr); + m_btnShowList.OnClick = Callback(this, &CChatRoomDlg::onClick_ShowList); + + m_btnBold.OnClick = Callback(this, &CChatRoomDlg::onClick_BIU); + m_btnItalic.OnClick = Callback(this, &CChatRoomDlg::onClick_BIU); + m_btnUnderline.OnClick = Callback(this, &CChatRoomDlg::onClick_BIU); + + m_btnColor.OnClick = Callback(this, &CChatRoomDlg::onClick_Color); + m_btnBkColor.OnClick = Callback(this, &CChatRoomDlg::onClick_BkColor); + + m_nickList.OnDblClick = Callback(this, &CChatRoomDlg::onDblClick_List); + + m_message.OnChange = Callback(this, &CChatRoomDlg::onChange_Message); + + m_splitterX.OnChange = Callback(this, &CChatRoomDlg::OnSplitterX); + m_splitterY.OnChange = Callback(this, &CChatRoomDlg::OnSplitterY); +} + +void CChatRoomDlg::OnInitDialog() +{ + m_si->pDlg = this; + + NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_OPENING); + + SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); + m_pParent = (ParentWindowData *)GetWindowLongPtr(m_hwndParent, GWLP_USERDATA); + + RichUtil_SubClass(m_message.GetHwnd()); + RichUtil_SubClass(m_log.GetHwnd()); + RichUtil_SubClass(m_nickList.GetHwnd()); + + mir_subclassWindow(m_log.GetHwnd(), LogSubclassProc); + mir_subclassWindow(m_message.GetHwnd(), MessageSubclassProc); + mir_subclassWindow(m_nickList.GetHwnd(), NicklistSubclassProc); + + mir_subclassWindow(m_btnFilter.GetHwnd(), Srmm_ButtonSubclassProc); + mir_subclassWindow(m_btnColor.GetHwnd(), Srmm_ButtonSubclassProc); + mir_subclassWindow(m_btnBkColor.GetHwnd(), Srmm_ButtonSubclassProc); + + Srmm_CreateToolbarIcons(m_hwnd, BBBF_ISCHATBUTTON); + + RECT rc; + GetWindowRect(m_message.GetHwnd(), &rc); + m_minLogBoxHeight = m_minEditBoxHeight = rc.bottom - rc.top; + if (m_pParent->iSplitterY == -1) + m_pParent->iSplitterY = m_minEditBoxHeight; + + if (m_pParent->iSplitterX == -1) { + GetWindowRect(m_nickList.GetHwnd(), &rc); + m_pParent->iSplitterX = rc.right - rc.left; + } + + 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(0, 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); + + m_hwndIeview = ieWindow.hwnd; + + IEVIEWEVENT iee = { sizeof(iee) }; + iee.iType = IEE_CLEAR_LOG; + iee.hwnd = m_hwndIeview; + iee.hContact = m_hContact; + iee.pszProto = m_si->pszModule; + CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&iee); + } + + m_log.SendMsg(EM_HIDESELECTION, TRUE, 0); + + UpdateOptions(); + UpdateStatusBar(); + UpdateTitle(); + + SendMessage(m_hwndParent, CM_ADDCHILD, (WPARAM)this, 0); + UpdateNickList(); + NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_OPEN); +} + +void CChatRoomDlg::OnDestroy() +{ + NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_CLOSING); + + m_si->pDlg = nullptr; + SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0); + + SendMessage(m_hwndParent, CM_REMOVECHILD, 0, (LPARAM)m_hwnd); + if (m_hwndIeview != nullptr) { + IEVIEWWINDOW ieWindow; + ieWindow.cbSize = sizeof(IEVIEWWINDOW); + ieWindow.iType = IEW_DESTROY; + ieWindow.hwnd = m_hwndIeview; + CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow); + } + + NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_CLOSE); +} + +void CChatRoomDlg::OnSplitterX(CSplitter *pSplitter) +{ + RECT rc; + GetClientRect(m_hwnd, &rc); + + m_pParent->iSplitterX = rc.right - pSplitter->GetPos() + 1; + if (m_pParent->iSplitterX < 35) + m_pParent->iSplitterX = 35; + if (m_pParent->iSplitterX > rc.right - rc.left - 35) + m_pParent->iSplitterX = rc.right - rc.left - 35; +} + +void CChatRoomDlg::OnSplitterY(CSplitter *pSplitter) +{ + RECT rc; + GetClientRect(m_hwnd, &rc); + m_pParent->iSplitterY = rc.bottom - pSplitter->GetPos(); +} + +void CChatRoomDlg::onDblClick_List(CCtrlListBox*) +{ + 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 DoEventHook(GC_USER_PRIVMESS, ui, nullptr, 0); + } +} + +void CChatRoomDlg::onClick_Ok(CCtrlButton *pButton) +{ + if (!pButton->Enabled()) + return; + + char *pszRtf = GetRichTextRTF(m_message.GetHwnd()); + if (pszRtf == nullptr) + return; + + MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); + if (mi == nullptr) + return; + + TCmdList *cmdListNew = tcmdlist_last(cmdList); + while (cmdListNew != nullptr && cmdListNew->temporary) { + cmdList = tcmdlist_remove(cmdList, cmdListNew); + cmdListNew = tcmdlist_last(cmdList); + } + + // takes pszRtf to a queue, no leak here + cmdList = tcmdlist_append(cmdList, pszRtf, 20, FALSE); + + CMStringW ptszText(ptrW(mir_utf8decodeW(pszRtf))); + pci->DoRtfToTags(ptszText, mi->nColorCount, mi->crColors); + ptszText.Trim(); + ptszText.Replace(L"%", L"%%"); + + if (mi->bAckMsg) { + EnableWindow(m_message.GetHwnd(), FALSE); + m_message.SendMsg(EM_SETREADONLY, TRUE, 0); + } + else SetDlgItemText(m_hwnd, IDC_MESSAGE, L""); + + EnableWindow(m_btnOk.GetHwnd(), FALSE); + + DoEventHook(GC_USER_MESSAGE, nullptr, ptszText, 0); + SetFocus(m_message.GetHwnd()); +} + +void CChatRoomDlg::onClick_History(CCtrlButton *pButton) +{ + if (!pButton->Enabled()) + return; + + MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); + if (pInfo) + ShellExecute(m_hwnd, nullptr, pci->GetChatLogsFilename(m_si, 0), nullptr, nullptr, SW_SHOW); +} + +void CChatRoomDlg::onClick_ChanMgr(CCtrlButton *pButton) +{ + if (pButton->Enabled()) + DoEventHook(GC_USER_CHANMGR, nullptr, nullptr, 0); +} + +void CChatRoomDlg::onClick_ShowList(CCtrlButton *pButton) +{ + if (!pButton->Enabled() || m_si->iType == GCW_SERVER) + return; + + m_bNicklistEnabled = !m_bNicklistEnabled; + pButton->SendMsg(BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_bNicklistEnabled ? "chat_nicklist" : "chat_nicklist2")); + ScrollToBottom(); + SendMessage(m_hwnd, WM_SIZE, 0, 0); +} + +void CChatRoomDlg::onClick_Filter(CCtrlButton *pButton) +{ + if (!pButton->Enabled()) + return; + + m_bFilterEnabled = !m_bFilterEnabled; + pButton->SendMsg(BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_bFilterEnabled ? "chat_filter" : "chat_filter2")); + if (m_bFilterEnabled && db_get_b(0, CHAT_MODULE, "RightClickFilter", 0) == 0) + ShowFilterMenu(); + else + RedrawLog(); +} + +void CChatRoomDlg::onClick_BIU(CCtrlButton *pButton) +{ + if (!pButton->Enabled()) + return; + + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE; + cf.dwEffects = 0; + + if (IsDlgButtonChecked(m_hwnd, IDC_BOLD)) + cf.dwEffects |= CFE_BOLD; + if (IsDlgButtonChecked(m_hwnd, IDC_ITALICS)) + cf.dwEffects |= CFE_ITALIC; + if (IsDlgButtonChecked(m_hwnd, IDC_UNDERLINE)) + cf.dwEffects |= CFE_UNDERLINE; + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); +} + +void CChatRoomDlg::onClick_Color(CCtrlButton *pButton) +{ + if (!pButton->Enabled()) + return; + + MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwEffects = 0; + + if (IsDlgButtonChecked(m_hwnd, IDC_COLOR)) { + if (db_get_b(0, CHAT_MODULE, "RightClickFilter", 0) == 0) + ShowColorChooser(IDC_COLOR); + else if (m_bFGSet) { + cf.dwMask = CFM_COLOR; + cf.crTextColor = pInfo->crColors[m_iFG]; + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + } + } + else { + COLORREF cr; + LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, nullptr, &cr); + cf.dwMask = CFM_COLOR; + cf.crTextColor = cr; + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + } +} + +void CChatRoomDlg::onClick_BkColor(CCtrlButton *pButton) +{ + if (!pButton->Enabled()) + return; + + MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwEffects = 0; + + if (IsDlgButtonChecked(m_hwnd, IDC_BKGCOLOR)) { + if (db_get_b(0, CHAT_MODULE, "RightClickFilter", 0) == 0) + ShowColorChooser(IDC_BKGCOLOR); + else if (m_bBGSet) { + cf.dwMask = CFM_BACKCOLOR; + cf.crBackColor = pInfo->crColors[m_iBG]; + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + } + } + else { + cf.dwMask = CFM_BACKCOLOR; + cf.crBackColor = (COLORREF)db_get_dw(0, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + } +} + +void CChatRoomDlg::onChange_Message(CCtrlEdit *pEdit) +{ + cmdListCurrent = nullptr; + m_btnOk.Enable(GetRichTextLength(pEdit->GetHwnd(), 1200, FALSE) != 0); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +void CChatRoomDlg::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 == nullptr) + break; + + pLog = pLog->next; + if ((m_si->iType != GCW_CHATROOM && m_si->iType != GCW_PRIVMESS) || !m_bFilterEnabled || (m_iLogFilterFlags & pLog->iType) != 0) + index++; + } + StreamInEvents(pLog, true); + mir_forkthread(phase2, m_si); + } + else StreamInEvents(m_si->pLogEnd, true); + } + else ClearLog(); +} + +void CChatRoomDlg::ScrollToBottom() +{ + if ((GetWindowLongPtr(m_log.GetHwnd(), GWL_STYLE) & WS_VSCROLL) == 0) + return; + + 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); +} + +void CChatRoomDlg::ShowFilterMenu() +{ + HWND hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_FILTER), m_hwnd, FilterWndProc, (LPARAM)this); + TranslateDialogDefault(hwnd); + + RECT rc; + GetWindowRect(m_btnFilter.GetHwnd(), &rc); + SetWindowPos(hwnd, HWND_TOP, rc.left - 85, (IsWindowVisible(m_btnFilter.GetHwnd()) || IsWindowVisible(m_btnBold.GetHwnd())) ? rc.top - 206 : rc.top - 186, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); +} + +void CChatRoomDlg::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(), nullptr, FALSE); + UpdateWindow(m_nickList.GetHwnd()); + UpdateTitle(); +} + +void CChatRoomDlg::UpdateOptions() +{ + m_btnShowList.SendMsg(BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_bNicklistEnabled ? "chat_nicklist" : "chat_nicklist2")); + m_btnFilter.SendMsg(BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetCachedIcon(m_bFilterEnabled ? "chat_filter" : "chat_filter2")); + { + MODULEINFO *pInfo = pci->MM_FindModule(m_si->pszModule); + if (pInfo) { + m_btnBold.Enable(pInfo->bBold); + m_btnItalic.Enable(pInfo->bItalics); + m_btnUnderline.Enable(pInfo->bUnderline); + m_btnColor.Enable(pInfo->bColor); + m_btnBkColor.Enable(pInfo->bBkgColor); + if (m_si->iType == GCW_CHATROOM) + m_btnChanMgr.Enable(pInfo->bChanMgr); + } + } + + UpdateStatusBar(); + UpdateTitle(); + FixTabIcons(); + + m_log.SendMsg(EM_SETBKGNDCOLOR, 0, g_Settings.crLogBackground); + + // messagebox + COLORREF crFore; + LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, nullptr, &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(0, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR); + m_message.SendMsg(EM_SETBKGNDCOLOR, 0, db_get_dw(0, 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(0, CHAT_MODULE, "NicklistRowDist", 12); + int font = ih > ih2 ? ih : ih2; + // make sure we have space for icon! + if (db_get_b(0, CHAT_MODULE, "ShowContactStatus", 0)) + font = font > 16 ? font : 16; + + m_nickList.SendMsg(LB_SETITEMHEIGHT, 0, height > font ? height : font); + InvalidateRect(m_nickList.GetHwnd(), nullptr, TRUE); + } + m_message.SendMsg(EM_REQUESTRESIZE, 0, 0); + SendMessage(m_hwnd, WM_SIZE, 0, 0); + RedrawLog2(); +} + +void CChatRoomDlg::UpdateStatusBar() +{ + MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); + wchar_t szTemp[512]; + 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 = m_si->wStatus == ID_STATUS_ONLINE ? mi->hOnlineIcon : mi->hOfflineIcon; + sbd.pszText = szTemp; + SendMessage(m_hwndParent, CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)m_hwnd); + + sbd.iItem = 1; + sbd.hIcon = nullptr; + sbd.pszText = L""; + SendMessage(m_hwndParent, CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)m_hwnd); + + StatusIconData sid = { sizeof(sid) }; + sid.szModule = SRMMMOD; + Srmm_ModifyIcon(m_hContact, &sid); +} + +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; + RECT rc; + POINT pt; + HICON hIcon; + TabControlData tcd; + + switch (uMsg) { + case DM_SWITCHINFOBAR: + case DM_SWITCHTOOLBAR: + SendMessage(m_hwnd, WM_SIZE, 0, 0); + break; + + case WM_SIZE: + if (wParam == SIZE_MAXIMIZED) + ScrollToBottom(); + + if (IsIconic(m_hwnd)) break; + + if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) { + GetClientRect(m_hwnd, &rc); + MessageDialogResize(rc.right - rc.left, rc.bottom - rc.top); + } + break; + + case DM_UPDATETABCONTROL: + tcd.iFlags = TCDF_TEXT; + tcd.pszText = m_si->ptszName; + SendMessage(m_hwndParent, CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)m_hwnd); + // fall through + + case DM_ACTIVATE: + if (m_si->wState & STATE_TALK) { + m_si->wState &= ~STATE_TALK; + db_set_w(m_hContact, m_si->pszModule, "ApparentMode", 0); + } + + if (m_si->wState & GC_EVENT_HIGHLIGHT) { + m_si->wState &= ~GC_EVENT_HIGHLIGHT; + + if (pcli->pfnGetEvent(m_hContact, 0)) + pcli->pfnRemoveEvent(m_hContact, GC_FAKE_EVENT); + } + + FixTabIcons(); + if (!m_si->pDlg) { + ShowRoom(m_si); + SendMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); + } + 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(0, CHAT_MODULE, "NicklistRowDist", 12); + // make sure we have space for icon! + if (db_get_b(0, CHAT_MODULE, "ShowContactStatus", 0)) + font = font > 16 ? font : 16; + mis->itemHeight = height > font ? height : font; + } + return TRUE; + + 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, nullptr, 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, nullptr, 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, nullptr, DI_NORMAL); + IcoLib_ReleaseIcon(hIcon); + x_offset += 18; + } + + 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) + break; + + // fall through + case WM_MOUSEACTIVATE: + if (uMsg != WM_ACTIVATE) + SetFocus(m_message.GetHwnd()); + + pci->SetActiveSession(m_si); + + if (db_get_w(m_hContact, m_si->pszModule, "ApparentMode", 0) != 0) + db_set_w(m_hContact, m_si->pszModule, "ApparentMode", 0); + if (pcli->pfnGetEvent(m_hContact, 0)) + pcli->pfnRemoveEvent(m_hContact, GC_FAKE_EVENT); + break; + + case WM_NOTIFY: + { + LPNMHDR pNmhdr = (LPNMHDR)lParam; + switch (pNmhdr->code) { + case EN_MSGFILTER: + if (pNmhdr->idFrom == IDC_LOG && ((MSGFILTER *)lParam)->msg == WM_RBUTTONUP) { + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, TRUE); + return TRUE; + } + break; + + 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 != nullptr) { + 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; + + case WM_KEYDOWN: + SetFocus(m_message.GetHwnd()); + break; + + case WM_GETMINMAXINFO: + { + MINMAXINFO *mmi = (MINMAXINFO*)lParam; + mmi->ptMinTrackSize.x = m_pParent->iSplitterX + 43; + if (mmi->ptMinTrackSize.x < 350) + mmi->ptMinTrackSize.x = 350; + + mmi->ptMinTrackSize.y = m_minLogBoxHeight + TOOLBAR_HEIGHT + m_minEditBoxHeight + 5; + } + break; + + case WM_LBUTTONDBLCLK: + if (LOWORD(lParam) < 30) + ScrollToBottom(); + else + SendMessage(m_hwndParent, WM_SYSCOMMAND, SC_MINIMIZE, 0); + break; + + case WM_LBUTTONDOWN: + SendMessage(m_hwndParent, WM_LBUTTONDOWN, wParam, lParam); + return TRUE; + + case DM_GETCONTEXTMENU: + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, (LPARAM)Menu_BuildContactMenu(m_hContact)); + return TRUE; + + case WM_CONTEXTMENU: + if (m_hwndParent == (HWND)wParam) { + HMENU hMenu = Menu_BuildContactMenu(m_hContact); + GetCursorPos(&pt); + TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, m_hwnd, nullptr); + DestroyMenu(hMenu); + } + break; + } + return CScriverWindow::DlgProc(uMsg, wParam, lParam); +} + +void ShowRoom(SESSION_INFO *si) +{ + if (si == nullptr) + return; + + // Do we need to create a window? + if (si->pDlg == nullptr) { + HWND hParent = GetParentWindow(si->hContact, TRUE); + + CChatRoomDlg *pDlg = new CChatRoomDlg(si); + pDlg->SetParent(hParent); + pDlg->Show(); + + pDlg->m_pParent = (ParentWindowData*)GetWindowLongPtr(hParent, GWLP_USERDATA); + si->pDlg = pDlg; + } + SendMessage(si->pDlg->GetHwnd(), DM_UPDATETABCONTROL, -1, (LPARAM)si); + SendMessage(GetParent(si->pDlg->GetHwnd()), CM_ACTIVATECHILD, 0, (LPARAM)si->pDlg->GetHwnd()); + SendMessage(GetParent(si->pDlg->GetHwnd()), CM_POPUPWINDOW, 0, (LPARAM)si->pDlg->GetHwnd()); + SendMessage(si->pDlg->GetHwnd(), WM_MOUSEACTIVATE, 0, 0); + SetFocus(GetDlgItem(si->pDlg->GetHwnd(), IDC_MESSAGE)); +} diff --git a/plugins/Scriver/src/stdafx.h b/plugins/Scriver/src/stdafx.h index 15dde61b6f..c276c7e0fa 100644 --- a/plugins/Scriver/src/stdafx.h +++ b/plugins/Scriver/src/stdafx.h @@ -120,7 +120,7 @@ int StatusIconPressed(WPARAM wParam, LPARAM lParam); #include "input.h" #include "richutil.h" #include "statusicon.h" -#include "chat/chat.h" +#include "chat.h" extern GlobalMessageData g_dat; -- cgit v1.2.3