From ef05f20f8191c1c3d93df3356969ce016119487e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 10 Jul 2014 18:37:52 +0000 Subject: - we don't broadcast added events anymore; - fix for User Typing notifications; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@9759 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TabSRMM/src/buttonsbar.cpp | 1 - plugins/TabSRMM/src/controls.h | 40 +++---- plugins/TabSRMM/src/generic_msghandlers.cpp | 3 +- plugins/TabSRMM/src/mim.cpp | 163 +++++++++++++++------------- plugins/TabSRMM/src/msgdialog.cpp | 3 +- plugins/TabSRMM/src/msgs.cpp | 3 +- plugins/TabSRMM/src/utils.cpp | 7 ++ plugins/TabSRMM/src/utils.h | 91 ++++++++-------- 8 files changed, 162 insertions(+), 149 deletions(-) diff --git a/plugins/TabSRMM/src/buttonsbar.cpp b/plugins/TabSRMM/src/buttonsbar.cpp index c1d5fae4ee..0d830624a8 100644 --- a/plugins/TabSRMM/src/buttonsbar.cpp +++ b/plugins/TabSRMM/src/buttonsbar.cpp @@ -526,7 +526,6 @@ void BB_UpdateIcons(HWND hdlg, TWindowData *dat) if (hwndBtn && cbd->hIcon) SendMessage(hwndBtn, BM_SETIMAGE, IMAGE_ICON, (LPARAM)Skin_GetIconByHandle(cbd->hIcon)); } - } } diff --git a/plugins/TabSRMM/src/controls.h b/plugins/TabSRMM/src/controls.h index ddf13eee7b..eb9f591df6 100644 --- a/plugins/TabSRMM/src/controls.h +++ b/plugins/TabSRMM/src/controls.h @@ -45,26 +45,26 @@ public: CMenuBar(HWND hwndParent, const TContainerData *pContainer); ~CMenuBar(); - const RECT& TSAPI getClientRect(); - void TSAPI Resize(WORD wWidth, WORD wHeight, BOOL redraw) const + const RECT& getClientRect(); + void Resize(WORD wWidth, WORD wHeight, BOOL redraw) const { ::SetWindowPos(m_hwndToolbar, 0, 4, 0, wWidth, m_size_y, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS|SWP_NOREDRAW); } - LONG TSAPI getHeight() const; - void TSAPI Show(int showCmd) const + LONG getHeight() const; + void Show(int showCmd) const { ::ShowWindow(m_hwndToolbar, showCmd); } - LONG_PTR TSAPI Handle(const NMTOOLBAR *nmtb); - void TSAPI Cancel(); - LONG_PTR TSAPI processMsg(const UINT msg, const WPARAM wParam, const LPARAM lParam); - bool TSAPI isContactMenu() const { return(m_isContactMenu); } - bool TSAPI isMainMenu() const { return(m_isMainMenu); } - void TSAPI configureMenu(void) const; - void TSAPI resetLP(void); - void TSAPI setActive(HMENU hMenu) + LONG_PTR Handle(const NMTOOLBAR *nmtb); + void Cancel(); + LONG_PTR processMsg(const UINT msg, const WPARAM wParam, const LPARAM lParam); + bool isContactMenu() const { return(m_isContactMenu); } + bool isMainMenu() const { return(m_isMainMenu); } + void configureMenu(void) const; + void resetLP(void); + void setActive(HMENU hMenu) { m_activeSubMenu = hMenu; } @@ -80,7 +80,7 @@ public: return(result); } - void TSAPI autoShow(const int showcmd = 1); + void autoShow(const int showcmd = 1); const int idToIndex(const int id) const { @@ -121,13 +121,13 @@ private: static CMenuBar *m_Owner; static int m_MimIconRefCount; private: - LONG_PTR TSAPI customDrawWorker(NMCUSTOMDRAW *nm); - void TSAPI updateState(const HMENU hMenu) const; - void TSAPI invoke(const int id); - void TSAPI cancel(const int id); - void TSAPI obtainHook(); - void TSAPI releaseHook(); - void TSAPI checkButtons(); + LONG_PTR customDrawWorker(NMCUSTOMDRAW *nm); + void updateState(const HMENU hMenu) const; + void invoke(const int id); + void cancel(const int id); + void obtainHook(); + void releaseHook(); + void checkButtons(); static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); // subclassing for the toolbar control static LRESULT CALLBACK MessageHook(int nCode, WPARAM wParam, LPARAM lParam); // message hook (only active when modal menus are active) diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp index 63b424f7ec..a45931b803 100644 --- a/plugins/TabSRMM/src/generic_msghandlers.cpp +++ b/plugins/TabSRMM/src/generic_msghandlers.cpp @@ -956,7 +956,7 @@ void TSAPI DM_ScrollToBottom(TWindowData *dat, WPARAM wParam, LPARAM lParam) if (dat->dwFlagsEx & MWF_SHOW_SCROLLINGDISABLED) return; - if ( IsIconic(dat->pContainer->hwnd)) + if (IsIconic(dat->pContainer->hwnd)) dat->dwFlags |= MWF_DEFERREDSCROLL; if (dat->hwndIEView) { @@ -1379,7 +1379,6 @@ void TSAPI DM_OptionsApplied(TWindowData *dat, WPARAM wParam, LPARAM lParam) SendMessage(hwndDlg, DM_UPDATEWINICON, 0, 0); } - void TSAPI DM_Typing(TWindowData *dat, bool fForceOff) { if (dat == 0) diff --git a/plugins/TabSRMM/src/mim.cpp b/plugins/TabSRMM/src/mim.cpp index 61265797a3..6c5e558047 100644 --- a/plugins/TabSRMM/src/mim.cpp +++ b/plugins/TabSRMM/src/mim.cpp @@ -227,92 +227,93 @@ void CMimAPI::InitAPI() ///////////////////////////////////////////////////////////////////////////////////////// // hook subscriber function for incoming message typing events -int CMimAPI::TypingMessage(WPARAM hContact, LPARAM lParam) +int CMimAPI::TypingMessage(WPARAM hContact, LPARAM mode) { - HWND hwnd = 0; - int issplit = 1, foundWin = 0, preTyping = 0; - BOOL fShowOnClist = TRUE; + int issplit = 1, foundWin = 0, preTyping = 0; + BOOL fShowOnClist = TRUE; - if (hContact) { - if ((hwnd = M.FindWindow(hContact)) && M.GetByte(SRMSGMOD, SRMSGSET_SHOWTYPING, SRMSGDEFSET_SHOWTYPING)) - preTyping = SendMessage(hwnd, DM_TYPING, 0, lParam); + HWND hwnd = M.FindWindow(hContact); + if (hwnd == NULL && db_mc_isSub(hContact)) + hwnd = M.FindWindow(db_mc_getMeta(hContact)); - if (hwnd && IsWindowVisible(hwnd)) - foundWin = MessageWindowOpened(0, (LPARAM)hwnd); - else - foundWin = 0; + if (hwnd && M.GetByte(SRMSGMOD, SRMSGSET_SHOWTYPING, SRMSGDEFSET_SHOWTYPING)) + preTyping = SendMessage(hwnd, DM_TYPING, 0, mode); - TContainerData *pContainer = NULL; - if (hwnd) { - SendMessage(hwnd, DM_QUERYCONTAINER, 0, (LPARAM)&pContainer); - if (pContainer == NULL) - return 0; // should never happen - } - - if (M.GetByte(SRMSGMOD, SRMSGSET_SHOWTYPINGCLIST, SRMSGDEFSET_SHOWTYPINGCLIST)) { - if (!hwnd && !M.GetByte(SRMSGMOD, SRMSGSET_SHOWTYPINGNOWINOPEN, 1)) - fShowOnClist = FALSE; - if (hwnd && !M.GetByte(SRMSGMOD, SRMSGSET_SHOWTYPINGWINOPEN, 1)) - fShowOnClist = FALSE; - } - else fShowOnClist = FALSE; + if (hwnd && IsWindowVisible(hwnd)) + foundWin = MessageWindowOpened(0, (LPARAM)hwnd); + else + foundWin = 0; - if ((!foundWin || !(pContainer->dwFlags & CNT_NOSOUND)) && preTyping != (lParam != 0)) - SkinPlaySound((lParam) ? "TNStart" : "TNStop"); - - if (M.GetByte(SRMSGMOD, "ShowTypingPopup", 0)) { - BOOL fShow = FALSE; - int iMode = M.GetByte("MTN_PopupMode", 0); + TContainerData *pContainer = NULL; + if (hwnd) { + SendMessage(hwnd, DM_QUERYCONTAINER, 0, (LPARAM)&pContainer); + if (pContainer == NULL) // should never happen + return 0; + } - switch (iMode) { - case 0: - fShow = TRUE; - break; - case 1: - if (!foundWin || !(pContainer && pContainer->hwndActive == hwnd && GetForegroundWindow() == pContainer->hwnd)) - fShow = TRUE; - break; - case 2: - if (hwnd == 0) - fShow = TRUE; - else { - if (PluginConfig.m_HideOnClose) { - TContainerData *pContainer = 0; - SendMessage(hwnd, DM_QUERYCONTAINER, 0, (LPARAM)&pContainer); - if (pContainer && pContainer->fHidden) - fShow = TRUE; - } + if (M.GetByte(SRMSGMOD, SRMSGSET_SHOWTYPINGCLIST, SRMSGDEFSET_SHOWTYPINGCLIST)) { + if (!hwnd && !M.GetByte(SRMSGMOD, SRMSGSET_SHOWTYPINGNOWINOPEN, 1)) + fShowOnClist = false; + if (hwnd && !M.GetByte(SRMSGMOD, SRMSGSET_SHOWTYPINGWINOPEN, 1)) + fShowOnClist = false; + } + else fShowOnClist = false; + + if ((!foundWin || !(pContainer->dwFlags & CNT_NOSOUND)) && preTyping != (mode != 0)) + SkinPlaySound(mode ? "TNStart" : "TNStop"); + + if (M.GetByte(SRMSGMOD, "ShowTypingPopup", 0)) { + BOOL fShow = false; + int iMode = M.GetByte("MTN_PopupMode", 0); + + switch (iMode) { + case 0: + fShow = true; + break; + case 1: + if (!foundWin || !(pContainer && pContainer->hwndActive == hwnd && GetForegroundWindow() == pContainer->hwnd)) + fShow = true; + break; + case 2: + if (hwnd == 0) + fShow = true; + else { + if (PluginConfig.m_HideOnClose) { + TContainerData *pContainer = 0; + SendMessage(hwnd, DM_QUERYCONTAINER, 0, (LPARAM)&pContainer); + if (pContainer && pContainer->fHidden) + fShow = true; } - break; } - if (fShow) - TN_TypingMessage(hContact, lParam); + break; } + if (fShow) + TN_TypingMessage(hContact, mode); + } - if (lParam) { - TCHAR szTip[256]; - mir_sntprintf(szTip, SIZEOF(szTip), TranslateT("%s is typing a message"), pcli->pfnGetContactDisplayName(hContact, 0)); - if (fShowOnClist && ServiceExists(MS_CLIST_SYSTRAY_NOTIFY) && M.GetByte(SRMSGMOD, "ShowTypingBalloon", 0)) { - MIRANDASYSTRAYNOTIFY tn; - tn.szProto = NULL; - tn.cbSize = sizeof(tn); - tn.tszInfoTitle = TranslateT("Typing Notification"); - tn.tszInfo = szTip; - tn.dwInfoFlags = NIIF_INFO | NIIF_INTERN_UNICODE; - tn.uTimeout = 1000 * 4; - CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&tn); - } - if (fShowOnClist) { - CLISTEVENT cle = { sizeof(cle) }; - cle.hContact = hContact; - cle.hDbEvent = (HANDLE)1; - cle.flags = CLEF_ONLYAFEW | CLEF_TCHAR; - cle.hIcon = PluginConfig.g_buttonBarIcons[ICON_DEFAULT_TYPING]; - cle.pszService = "SRMsg/TypingMessage"; - cle.ptszTooltip = szTip; - CallServiceSync(MS_CLIST_REMOVEEVENT, hContact, 1); - CallServiceSync(MS_CLIST_ADDEVENT, hContact, (LPARAM)&cle); - } + if (mode) { + TCHAR szTip[256]; + mir_sntprintf(szTip, SIZEOF(szTip), TranslateT("%s is typing a message"), pcli->pfnGetContactDisplayName(hContact, 0)); + if (fShowOnClist && ServiceExists(MS_CLIST_SYSTRAY_NOTIFY) && M.GetByte(SRMSGMOD, "ShowTypingBalloon", 0)) { + MIRANDASYSTRAYNOTIFY tn; + tn.szProto = NULL; + tn.cbSize = sizeof(tn); + tn.tszInfoTitle = TranslateT("Typing Notification"); + tn.tszInfo = szTip; + tn.dwInfoFlags = NIIF_INFO | NIIF_INTERN_UNICODE; + tn.uTimeout = 1000 * 4; + CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&tn); + } + if (fShowOnClist) { + CLISTEVENT cle = { sizeof(cle) }; + cle.hContact = hContact; + cle.hDbEvent = (HANDLE)1; + cle.flags = CLEF_ONLYAFEW | CLEF_TCHAR; + cle.hIcon = PluginConfig.g_buttonBarIcons[ICON_DEFAULT_TYPING]; + cle.pszService = "SRMsg/TypingMessage"; + cle.ptszTooltip = szTip; + CallServiceSync(MS_CLIST_REMOVEEVENT, hContact, 1); + CallServiceSync(MS_CLIST_ADDEVENT, hContact, (LPARAM)&cle); } } return 0; @@ -389,8 +390,14 @@ int CMimAPI::PrebuildContactMenu(WPARAM hContact, LPARAM lParam) int CMimAPI::DispatchNewEvent(WPARAM hContact, LPARAM lParam) { - if (hContact) - M.BroadcastMessageAsync(HM_DBEVENTADDED, hContact, lParam); + if (hContact) { + Utils::sendContactMessage(hContact, HM_DBEVENTADDED, hContact, lParam); + + // we're in meta and an event belongs to a sub + MCONTACT hReal = db_event_getContact(HANDLE(lParam)); + if (hReal != hContact) + Utils::sendContactMessage(hReal, HM_DBEVENTADDED, hContact, lParam); + } return 0; } diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 61eb020197..d3f1859f50 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -2475,8 +2475,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (!dat) return 0; if (dat->hContact) - if (dat->hContact == wParam || dat->hContact == db_event_getContact(HANDLE(lParam))) - DM_EventAdded(dat, dat->hContact, lParam); + DM_EventAdded(dat, dat->hContact, lParam); return 0; case WM_TIMER: diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp index 8fa4965b25..d7d09555e3 100644 --- a/plugins/TabSRMM/src/msgs.cpp +++ b/plugins/TabSRMM/src/msgs.cpp @@ -123,9 +123,8 @@ static INT_PTR SetStatusText(WPARAM wParam, LPARAM lParam) TWindowData *dat; HWND hwnd = M.FindWindow(wParam); - if (hwnd != NULL) { + if (hwnd != NULL) dat = (TWindowData*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - } else { SESSION_INFO *si = SM_FindSessionByHCONTACT(wParam); if (si == NULL) diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index 2103def2b8..d985a5f1be 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -831,6 +831,13 @@ AVATARCACHEENTRY* Utils::loadAvatarFromAVS(const MCONTACT hContact) return (AVATARCACHEENTRY*)CallService(MS_AV_GETAVATARBITMAP, hContact, 0); } +void Utils::sendContactMessage(MCONTACT hContact, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + HWND h = M.FindWindow(hContact); + if (h != NULL) + PostMessage(h, uMsg, wParam, lParam); +} + void Utils::getIconSize(HICON hIcon, int& sizeX, int& sizeY) { ICONINFO ii; diff --git a/plugins/TabSRMM/src/utils.h b/plugins/TabSRMM/src/utils.h index a3f83f42bc..4f081363f6 100644 --- a/plugins/TabSRMM/src/utils.h +++ b/plugins/TabSRMM/src/utils.h @@ -65,48 +65,51 @@ public: CMD_MSGDIALOG = 2, CMD_INFOPANEL = 4, }; - static int TSAPI FindRTLLocale (TWindowData *dat); - static TCHAR* TSAPI GetPreviewWithEllipsis (TCHAR *szText, size_t iMaxLen); - static TCHAR* TSAPI FilterEventMarkers (TCHAR *wszText); - static const TCHAR* TSAPI FormatRaw (TWindowData *dat, const TCHAR *msg, int flags, BOOL isSent); - static const TCHAR* TSAPI FormatTitleBar (const TWindowData *dat, const TCHAR *szFormat); - static char* TSAPI FilterEventMarkers (char *szText); - static const TCHAR* TSAPI DoubleAmpersands (TCHAR *pszText); - static void TSAPI RTF_CTableInit (); - static void TSAPI RTF_ColorAdd (const TCHAR *tszColname, size_t length); - static void TSAPI CreateColorMap (TCHAR *Text); - static int TSAPI RTFColorToIndex (int iCol); - static int TSAPI ReadContainerSettingsFromDB (const MCONTACT hContact, TContainerSettings *cs, const char *szKey = 0); - static int TSAPI WriteContainerSettingsToDB (const MCONTACT hContact, TContainerSettings *cs, const char *szKey = 0); - static void TSAPI SettingsToContainer (TContainerData *pContainer); - static void TSAPI ContainerToSettings (TContainerData *pContainer); - static void TSAPI ReadPrivateContainerSettings (TContainerData *pContainer, bool fForce = false); - static void TSAPI SaveContainerSettings (TContainerData *pContainer, const char *szSetting); - static DWORD CALLBACK StreamOut (DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb); - static LRESULT TSAPI CmdDispatcher (UINT uType, HWND hwndDlg, UINT cmd, WPARAM wParam, LPARAM lParam, TWindowData *dat = 0, - TContainerData *pContainer = 0); - static void TSAPI addMenuItem (const HMENU& m, MENUITEMINFO& mii, HICON hIcon, - const TCHAR *szText, UINT uID, UINT pos); - static void TSAPI enableDlgControl (const HWND hwnd, UINT id, BOOL fEnable = 1); - static void TSAPI showDlgControl (const HWND hwnd, UINT id, int showCmd); - static int TSAPI mustPlaySound (const TWindowData *dat); - static HICON TSAPI iconFromAvatar (const TWindowData *dat); - static void TSAPI getIconSize (HICON hIcon, int& sizeX, int& sizeY); - - static bool TSAPI extractResource (const HMODULE h, const UINT uID, const TCHAR *tszName, const TCHAR *tszPath, - const TCHAR *tszFilename, bool fForceOverwrite); - static void TSAPI scaleAvatarHeightLimited (const HBITMAP hBm, double& dNewWidth, double& dNewHeight, const LONG maxHeight); - - static AVATARCACHEENTRY* TSAPI loadAvatarFromAVS (const MCONTACT hContact); - static void TSAPI sanitizeFilename (wchar_t *tszFilename); - static void TSAPI ensureTralingBackslash (wchar_t *szPathname); - - static HMODULE TSAPI loadSystemLibrary (const wchar_t* szFilename); - - static INT_PTR CALLBACK PopupDlgProcError (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - static const TCHAR* extractURLFromRichEdit (const ENLINK* _e, const HWND hwndRich); - - template static size_t TSAPI CopyToClipBoard(T* _t, const HWND hwndOwner) + + static int FindRTLLocale(TWindowData *dat); + static TCHAR* GetPreviewWithEllipsis(TCHAR *szText, size_t iMaxLen); + static TCHAR* FilterEventMarkers(TCHAR *wszText); + static LPCTSTR FormatRaw(TWindowData *dat, const TCHAR *msg, int flags, BOOL isSent); + static LPCTSTR FormatTitleBar(const TWindowData *dat, const TCHAR *szFormat); + static char* FilterEventMarkers(char *szText); + static LPCTSTR DoubleAmpersands(TCHAR *pszText); + static void RTF_CTableInit(); + static void RTF_ColorAdd(const TCHAR *tszColname, size_t length); + static void CreateColorMap(TCHAR *Text); + static int RTFColorToIndex(int iCol); + static int ReadContainerSettingsFromDB(const MCONTACT hContact, TContainerSettings *cs, const char *szKey = 0); + static int WriteContainerSettingsToDB(const MCONTACT hContact, TContainerSettings *cs, const char *szKey = 0); + static void SettingsToContainer(TContainerData *pContainer); + static void ContainerToSettings(TContainerData *pContainer); + static void ReadPrivateContainerSettings(TContainerData *pContainer, bool fForce = false); + static void SaveContainerSettings(TContainerData *pContainer, const char *szSetting); + + static DWORD CALLBACK StreamOut(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb); + static LRESULT CmdDispatcher(UINT uType, HWND hwndDlg, UINT cmd, WPARAM wParam, LPARAM lParam, TWindowData *dat = 0, TContainerData *pContainer = 0); + + static void addMenuItem(const HMENU& m, MENUITEMINFO& mii, HICON hIcon, const TCHAR *szText, UINT uID, UINT pos); + static void enableDlgControl(const HWND hwnd, UINT id, BOOL fEnable = 1); + static void showDlgControl(const HWND hwnd, UINT id, int showCmd); + static int mustPlaySound(const TWindowData *dat); + static HICON iconFromAvatar(const TWindowData *dat); + static void getIconSize(HICON hIcon, int& sizeX, int& sizeY); + + static bool extractResource(const HMODULE h, const UINT uID, const TCHAR *tszName, const TCHAR *tszPath, const TCHAR *tszFilename, bool fForceOverwrite); + static void scaleAvatarHeightLimited(const HBITMAP hBm, double& dNewWidth, double& dNewHeight, const LONG maxHeight); + + static AVATARCACHEENTRY* loadAvatarFromAVS(const MCONTACT hContact); + + static void sanitizeFilename(wchar_t *tszFilename); + static void ensureTralingBackslash(wchar_t *szPathname); + + static void sendContactMessage(MCONTACT hContact, UINT uMsg, WPARAM wParam, LPARAM lParam); + + static HMODULE loadSystemLibrary(const wchar_t* szFilename); + + static INT_PTR CALLBACK PopupDlgProcError(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + static LPCTSTR extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich); + + template static size_t CopyToClipBoard(T* _t, const HWND hwndOwner) { if (!OpenClipboard(hwndOwner) || _t == 0) return 0; @@ -126,7 +129,7 @@ public: return(i); } - template static void AddToFileList(T ***pppFiles, int *totalCount, const TCHAR* szFilename) + template static void AddToFileList(T ***pppFiles, int *totalCount, LPCTSTR szFilename) { size_t _s = sizeof(T); @@ -184,7 +187,7 @@ public: static int rtf_ctable_size; }; -LRESULT TSAPI _dlgReturn(HWND hWnd, LRESULT result); +LRESULT _dlgReturn(HWND hWnd, LRESULT result); -- cgit v1.2.3