diff options
author | George Hazan <ghazan@miranda.im> | 2017-08-15 13:49:37 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-08-15 13:49:37 +0300 |
commit | f52b5cc86d9eff2494902157c8fc0a4e019a3c95 (patch) | |
tree | 9f668bf7b89decd53757589d74e476aac81eb451 | |
parent | d05dd78157058eea348f0d7666c7c6b0570ef25b (diff) |
fixes #799 (Crash on receiving msg in FB group chat)
26 files changed, 118 insertions, 170 deletions
diff --git a/include/delphi/m_message.inc b/include/delphi/m_message.inc index 764287720a..c564f602f6 100644 --- a/include/delphi/m_message.inc +++ b/include/delphi/m_message.inc @@ -78,19 +78,10 @@ type function Srmm_GetWindowData(hContact:TMCONTACT; pResult:PMessageWindowData) : int; stdcall; external AppDll;
-type
- PStatusTextData = ^TStatusTextData;
- TStatusTextData = record
- hIcon :HICON;
- tszText:array [0..99] of WideChar;
- end;
-
-{ wparam=(TMCONTACT)hContact
- lparam=PStatusTextData or NIL to clear statusbar
- Sets a statusbar line text for the appropriate contact
+{ wparam=0(unused)
+ lparam=(pMessageWindowEvent) event written
+ fired before SRMM writes an entered message into the database
}
-const
- MS_MSG_SETSTATUSTEXT:PAnsiChar = 'MessageAPI/SetStatusText';
type
pMessageWindowEvent = ^tMessageWindowEvent;
@@ -101,10 +92,6 @@ type end;
const
-{ wparam=0(unused)
- lparam=(pMessageWindowEvent) event written
- fired before SRMM writes an entered message into the database
-}
ME_MSG_PRECREATEEVENT:PAnsiChar = 'MessageAPI/PreCreateEvent';
{ wParam = 0
diff --git a/include/m_chat_int.h b/include/m_chat_int.h index 83d81e3405..c1bee5babe 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -457,6 +457,7 @@ public: virtual void LoadSettings() PURE;
virtual void RedrawLog() {}
virtual void ScrollToBottom() {}
+ virtual void SetStatusText(const wchar_t*, HICON) {}
virtual void ShowFilterMenu() {}
virtual void StreamInEvents(LOGINFO*, bool) {}
virtual void UpdateNickList() {}
diff --git a/include/m_message.h b/include/m_message.h index 1af56057d0..f892f10219 100644 --- a/include/m_message.h +++ b/include/m_message.h @@ -68,19 +68,6 @@ struct MessageWindowEventData #define ME_MSG_WINDOWEVENT "MessageAPI/WindowEvent"
/////////////////////////////////////////////////////////////////////////////////////////
-// wparam = (MCONTACT)hContact
-// lparam = (StatusTextData*) or NULL to clear statusbar
-// Sets a statusbar line text for the appropriate contact
-
-struct StatusTextData
-{
- HICON hIcon;
- wchar_t tszText[100];
-};
-
-#define MS_MSG_SETSTATUSTEXT "MessageAPI/SetStatusText"
-
-/////////////////////////////////////////////////////////////////////////////////////////
// retrieves some particular info about a SRMM window by contact
// returns 0 if a window was found or an error code otherwise
@@ -99,6 +86,11 @@ struct MessageWindowData EXTERN_C MIR_APP_DLL(int) Srmm_GetWindowData(MCONTACT hContact, MessageWindowData &mwd);
/////////////////////////////////////////////////////////////////////////////////////////
+// sets the status text & icon in a window associated with hContact
+
+EXTERN_C MIR_APP_DLL(void) Srmm_SetStatusText(MCONTACT hContact, const wchar_t *wszText, HICON hIcon = nullptr);
+
+/////////////////////////////////////////////////////////////////////////////////////////
// wparam = 0 (unused)
// lparam = (MessageWindowEvent*)
// fired before SRMM writes an entered message into the database
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib Binary files differindex f35f73fe35..09804a8423 100644 --- a/libs/win32/mir_app.lib +++ b/libs/win32/mir_app.lib diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib Binary files differindex 19fd4a95e6..2fc95c40ef 100644 --- a/libs/win64/mir_app.lib +++ b/libs/win64/mir_app.lib diff --git a/plugins/Scriver/src/msgs.cpp b/plugins/Scriver/src/msgs.cpp index 58d97fbf1e..a335489ee8 100644 --- a/plugins/Scriver/src/msgs.cpp +++ b/plugins/Scriver/src/msgs.cpp @@ -284,25 +284,13 @@ static void RestoreUnreadMessageAlerts(void) }
}
-static INT_PTR SetStatusText(WPARAM hContact, LPARAM lParam)
+void CScriverWindow::SetStatusText(const wchar_t *wszText, HICON hIcon)
{
- StatusTextData *st = (StatusTextData*)lParam;
- if (st == nullptr)
- return 1;
-
- HWND hwnd = Srmm_FindWindow(hContact);
- if (hwnd == nullptr)
- return 1;
-
- CScriverWindow *dat = (CScriverWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (dat == nullptr || dat->m_pParent == nullptr)
- return 1;
-
- ParentWindowData *pdat = dat->m_pParent;
-
- SendMessage(pdat->hwndStatus, SB_SETICON, 0, (LPARAM)(st == nullptr ? 0 : st->hIcon));
- SendMessage(pdat->hwndStatus, SB_SETTEXT, 0, (LPARAM)(st == nullptr ? L"" : st->tszText));
- return 0;
+ ParentWindowData *pDat = m_pParent;
+ if (pDat != nullptr) {
+ SendMessage(pDat->hwndStatus, SB_SETICON, 0, (LPARAM)hIcon);
+ SendMessage(pDat->hwndStatus, SB_SETTEXT, 0, (LPARAM)wszText);
+ }
}
static int PrebuildContactMenu(WPARAM hContact, LPARAM)
@@ -656,7 +644,7 @@ int OnLoadModule(void) CreateServiceFunction(MS_MSG_SENDMESSAGE, SendMessageCommand);
CreateServiceFunction(MS_MSG_SENDMESSAGEW, SendMessageCommandW);
- CreateServiceFunction(MS_MSG_SETSTATUSTEXT, SetStatusText);
+
CreateServiceFunction("SRMsg/ReadMessage", ReadMessageCommand);
CreateServiceFunction("SRMsg/TypingMessage", TypingMessageCommand);
diff --git a/plugins/Scriver/src/msgs.h b/plugins/Scriver/src/msgs.h index ff758a3416..86de8bf663 100644 --- a/plugins/Scriver/src/msgs.h +++ b/plugins/Scriver/src/msgs.h @@ -97,6 +97,7 @@ protected: public:
virtual void CloseTab() override;
virtual void LoadSettings() override;
+ virtual void SetStatusText(const wchar_t*, HICON) override;
void Reattach(HWND hwndContainer);
diff --git a/plugins/TabSRMM/src/chat_window.cpp b/plugins/TabSRMM/src/chat_window.cpp index 2b2080af00..b682843cd9 100644 --- a/plugins/TabSRMM/src/chat_window.cpp +++ b/plugins/TabSRMM/src/chat_window.cpp @@ -605,13 +605,10 @@ void CChatRoomDlg::OnDestroy() m_pContainer->UpdateTabs(); m_iTabID = -1; } + if (m_pWnd) { delete m_pWnd; - m_pWnd = 0; - } - if (m_sbCustom) { - delete m_sbCustom; - m_sbCustom = 0; + m_pWnd = nullptr; } NotifyEvent(MSG_WINDOW_EVT_CLOSE); diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp index 3aaf459a05..28aafb0cb5 100644 --- a/plugins/TabSRMM/src/generic_msghandlers.cpp +++ b/plugins/TabSRMM/src/generic_msghandlers.cpp @@ -772,9 +772,9 @@ void CTabBaseDlg::DM_UpdateLastMessage() const SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, (LPARAM)PluginConfig.g_buttonBarIcons[ICON_DEFAULT_TYPING]); mir_snwprintf(szBuf, TranslateT("%s is typing a message..."), m_cache->getNick()); } - else if (m_sbCustom) { - SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, (LPARAM)m_sbCustom->hIcon); - SendMessage(m_pContainer->hwndStatus, SB_SETTEXT, 0, (LPARAM)m_sbCustom->tszText); + else if (m_bStatusSet) { + SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, (LPARAM)m_szStatusIcon); + SendMessage(m_pContainer->hwndStatus, SB_SETTEXT, 0, (LPARAM)m_szStatusText.c_str()); return; } else { diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index 6447692995..d28eaad284 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -476,9 +476,9 @@ void CTabBaseDlg::tabUpdateStatusBar() const SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, (LPARAM)PluginConfig.g_buttonBarIcons[ICON_DEFAULT_TYPING]);
SendMessage(m_pContainer->hwndStatus, SB_SETTEXT, 0, (LPARAM)m_wszStatusBar);
}
- else if (m_sbCustom) {
- SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, (LPARAM)m_sbCustom->hIcon);
- SendMessage(m_pContainer->hwndStatus, SB_SETTEXT, 0, (LPARAM)m_sbCustom->tszText);
+ else if (m_bStatusSet) {
+ SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, (LPARAM)m_szStatusText.c_str());
+ SendMessage(m_pContainer->hwndStatus, SB_SETTEXT, 0, (LPARAM)m_szStatusIcon);
}
else {
SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, 0);
@@ -486,9 +486,9 @@ void CTabBaseDlg::tabUpdateStatusBar() const }
}
else {
- if (m_sbCustom) {
- SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, (LPARAM)m_sbCustom->hIcon);
- SendMessage(m_pContainer->hwndStatus, SB_SETTEXT, 0, (LPARAM)m_sbCustom->tszText);
+ if (m_bStatusSet) {
+ SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, (LPARAM)m_szStatusText.c_str());
+ SendMessage(m_pContainer->hwndStatus, SB_SETTEXT, 0, (LPARAM)m_szStatusIcon);
}
else SendMessage(m_pContainer->hwndStatus, SB_SETICON, 0, 0);
}
diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp index 7325c07702..3a88bd7ee1 100644 --- a/plugins/TabSRMM/src/msgs.cpp +++ b/plugins/TabSRMM/src/msgs.cpp @@ -74,7 +74,6 @@ CTabBaseDlg::CTabBaseDlg(int iResource, SESSION_INFO *si) CTabBaseDlg::~CTabBaseDlg()
{
delete m_pWnd;
- delete m_sbCustom;
mir_free(m_sendBuffer);
mir_free(m_hHistoryEvents);
@@ -278,31 +277,15 @@ void CTabBaseDlg::NotifyDeliveryFailure() const }
/////////////////////////////////////////////////////////////////////////////////////////
-// service function. Sets a status bar text for a contact
+// Sets a status bar text for a contact
-static INT_PTR SetStatusText(WPARAM hContact, LPARAM lParam)
+void CTabBaseDlg::SetStatusText(const wchar_t *wszText, HICON hIcon)
{
- HWND hwnd = Srmm_FindWindow(hContact);
- if (hwnd == nullptr)
- hwnd = Srmm_FindWindow(db_mc_getMeta(hContact));
- if (hwnd == nullptr)
- return 0;
-
- CTabBaseDlg *pDlg = (CTabBaseDlg*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (pDlg != nullptr) {
- // delete old custom data
- if (pDlg->m_sbCustom) {
- delete pDlg->m_sbCustom;
- pDlg->m_sbCustom = nullptr;
- }
-
- StatusTextData *st = (StatusTextData*)lParam;
- if (st != nullptr)
- pDlg->m_sbCustom = new StatusTextData(*st);
-
- pDlg->tabUpdateStatusBar();
- }
- return 0;
+ m_bStatusSet = true;
+ m_szStatusText = wszText;
+ m_szStatusIcon = hIcon;
+
+ tabUpdateStatusBar();
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1023,7 +1006,6 @@ static void TSAPI InitAPI() {
CreateServiceFunction(MS_MSG_SENDMESSAGE, SendMessageCommand);
CreateServiceFunction(MS_MSG_SENDMESSAGEW, SendMessageCommand_W);
- CreateServiceFunction(MS_MSG_SETSTATUSTEXT, SetStatusText);
CreateServiceFunction("TabSRMsg/ReloadSkin", ReloadSkin);
CreateServiceFunction("TabSRMsg/ReloadSettings", ReloadSettings);
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index 2382d0fe86..160f57504a 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -242,6 +242,7 @@ class CTabBaseDlg : public CSrmmBaseDialog protected:
virtual void LoadSettings() override;
+ virtual void SetStatusText(const wchar_t*, HICON) override;
void DM_AddDivider();
void DM_DismissTip(const POINT& pt);
@@ -278,7 +279,11 @@ protected: DWORD m_dwTickLastEvent;
HBITMAP m_hOwnPic;
SIZE m_pic;
-
+
+ CMStringW m_szStatusText;
+ HICON m_szStatusIcon;
+ bool m_bStatusSet;
+
bool m_bShowInfoAvatar, m_bShowUIElements;
bool m_bUseOffset;
bool m_bkeyProcessed;
@@ -356,7 +361,6 @@ public: CInfoPanel m_pPanel;
CContactCache *m_cache;
TContainerData *m_pContainer; // parent container description structure
- StatusTextData *m_sbCustom;
AVATARCACHEENTRY *m_ace, *m_ownAce;
CProxyWindow *m_pWnd; // proxy window object (win7+, for taskbar support).
// ALWAYS check this pointer before using it, it is not guaranteed to exist.
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 712c5daaf6..514ab9ccef 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -388,7 +388,7 @@ void facebook_client::erase_reader(MCONTACT hContact) parent->delSetting(hContact, FACEBOOK_KEY_MESSAGE_READ); readers.erase(hContact); - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact); + Srmm_SetStatusText(hContact, nullptr); } void loginError(FacebookProto *proto, std::string error_str) { diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 90ed0dd3cf..66254354b2 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -835,12 +835,10 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector<faceboo MCONTACT hChatContact = proto->ChatIDToHContact(tid); ptrW name(mir_utf8decodeW(participant->second.nick.c_str())); - if (st_.as_int() == 1) { - StatusTextData st = { 0 }; - mir_snwprintf(st.tszText, TranslateT("%s is typing a message..."), name); - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hChatContact, (LPARAM)&st); - } - else CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hChatContact); + if (st_.as_int() == 1) + Srmm_SetStatusText(hChatContact, CMStringW(FORMAT, TranslateT("%s is typing a message..."), name)); + else + Srmm_SetStatusText(hChatContact, nullptr); // TODO: support proper MS_PROTO_CONTACTISTYPING service for chatrooms (when it will be implemented) } @@ -1459,4 +1457,3 @@ int facebook_json_parser::parse_messages_count(std::string *data, int *messagesC return EXIT_SUCCESS; } - diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index c43f9c8d4c..0490710df1 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -1145,19 +1145,13 @@ void FacebookProto::MessageRead(MCONTACT hContact) wchar_t ttime[64]; wcsftime(ttime, _countof(ttime), L"%X", localtime(&time)); - StatusTextData st = { 0 }; - st.hIcon = IcoLib_GetIconByHandle(GetIconHandle("read")); + HICON hIcon = IcoLib_GetIconByHandle(GetIconHandle("read")); if (isChatRoom(hContact)) { - // FIXME: Remove this condition when #799 is fixed - if (!getBool("NoChatMessageReadNotify")) { - // Load readers names - ptrW treaders(getWStringA(hContact, FACEBOOK_KEY_MESSAGE_READERS)); - mir_snwprintf(st.tszText, TranslateT("Message read: %s by %s"), ttime, treaders ? treaders : L"???"); - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)&st); - } - } else if (!ServiceExists(MS_MESSAGESTATE_UPDATE)){ - mir_snwprintf(st.tszText, TranslateT("Message read: %s"), ttime); - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)&st); + // Load readers names + ptrW treaders(getWStringA(hContact, FACEBOOK_KEY_MESSAGE_READERS)); + Srmm_SetStatusText(hContact, CMStringW(FORMAT, TranslateT("Message read: %s by %s"), ttime, treaders ? treaders : L"???"), hIcon); } + else if (!ServiceExists(MS_MESSAGESTATE_UPDATE)) + Srmm_SetStatusText(hContact, CMStringW(FORMAT, TranslateT("Message read: %s"), ttime), hIcon); } diff --git a/protocols/Omegle/src/communication.cpp b/protocols/Omegle/src/communication.cpp index 527a42705f..65baff0dee 100644 --- a/protocols/Omegle/src/communication.cpp +++ b/protocols/Omegle/src/communication.cpp @@ -552,28 +552,22 @@ bool Omegle_client::events() // Stranger is typing, not supported by chat module yet SkinPlaySound("StrangerTyp"); - StatusTextData st = { 0 }; - st.hIcon = IcoLib_GetIconByHandle(GetIconHandle("typing_on")); - ptrW who(name == "spyTyping" ? json_as_string(json_at(item, 1)) : mir_wstrdup(L"Stranger")); - mir_snwprintf(st.tszText, TranslateT("%s is typing."), TranslateW(who)); - - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)parent->GetChatHandle(), (LPARAM)&st); + Srmm_SetStatusText(parent->GetChatHandle(), + CMStringW(FORMAT, TranslateT("%s is typing."), TranslateW(who)), + IcoLib_GetIconByHandle(GetIconHandle("typing_on"))); } else if (name == "stoppedTyping" || name == "spyStoppedTyping") { // Stranger stopped typing, not supported by chat module yet SkinPlaySound("StrangerTypStop"); - StatusTextData st = { 0 }; - st.hIcon = IcoLib_GetIconByHandle(GetIconHandle("typing_off")); - ptrW who(name == "spyTyping" ? json_as_string(json_at(item, 1)) : mir_wstrdup(L"Stranger")); - mir_snwprintf(st.tszText, TranslateT("%s stopped typing."), TranslateW(who)); - - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)parent->GetChatHandle(), (LPARAM)&st); + Srmm_SetStatusText(parent->GetChatHandle(), + CMStringW(FORMAT, TranslateT("%s stopped typing."), TranslateW(who)), + IcoLib_GetIconByHandle(GetIconHandle("typing_off"))); } else if (name == "gotMessage") { - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)parent->GetChatHandle(), NULL); + Srmm_SetStatusText(parent->GetChatHandle(), nullptr); // Play sound as we received message SkinPlaySound("StrangerMessage"); @@ -584,7 +578,7 @@ bool Omegle_client::events() } } else if (name == "spyMessage") { - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)parent->GetChatHandle(), NULL); + Srmm_SetStatusText(parent->GetChatHandle(), nullptr); // Play sound as we received message SkinPlaySound("StrangerMessage"); @@ -596,7 +590,7 @@ bool Omegle_client::events() } } else if (name == "strangerDisconnected") { - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)parent->GetChatHandle(), NULL); + Srmm_SetStatusText(parent->GetChatHandle(), nullptr); // Stranger disconnected if (db_get_b(NULL, parent->m_szModuleName, OMEGLE_KEY_DONT_STOP, 0)) @@ -608,7 +602,7 @@ bool Omegle_client::events() parent->StopChat(false); } else if (name == "spyDisconnected") { - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)parent->GetChatHandle(), NULL); + Srmm_SetStatusText(parent->GetChatHandle(), nullptr); ptrW stranger(json_as_string(json_at(item, 1))); diff --git a/protocols/Omegle/src/connection.cpp b/protocols/Omegle/src/connection.cpp index 50aa33a759..361820f2b5 100644 --- a/protocols/Omegle/src/connection.cpp +++ b/protocols/Omegle/src/connection.cpp @@ -96,7 +96,7 @@ void OmegleProto::StopChat(bool disconnect) SetTopic(); // reset topic content
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)GetChatHandle(), NULL);
+ Srmm_SetStatusText(GetChatHandle(), nullptr);
}
else
{ // disconnecting or inactive
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index f91405128d..fc64fcaf8c 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -749,10 +749,7 @@ void CVkProto::SetSrmmReadStatus(MCONTACT hContact) _wcsftime_l(ttime, _countof(ttime), L"%X - %x", localtime(&time), locale);
_free_locale(locale);
- StatusTextData st = { 0 };
- st.hIcon = IcoLib_GetIconByHandle(GetIconHandle(IDI_READMSG));
- mir_snwprintf(st.tszText, TranslateT("Message read: %s"), ttime);
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)&st);
+ Srmm_SetStatusText(hContact, CMStringW(FORMAT, TranslateT("Message read: %s"), ttime)), IcoLib_GetIconByHandle(GetIconHandle(IDI_READMSG));
}
void CVkProto::MarkDialogAsRead(MCONTACT hContact)
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 46a09beb7a..19853e553d 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -840,9 +840,7 @@ void CVkProto::ChatContactTypingThread(void *p) m_ChatsTyping.remove(cp);
m_ChatsTyping.insert(param);
- StatusTextData st = { 0 };
- mir_snwprintf(st.tszText, TranslateT("%s is typing a message..."), cu->m_wszNick);
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hChatContact, (LPARAM)&st);
+ Srmm_SetStatusText(hChatContact, CMStringW(FORMAT, TranslateT("%s is typing a message..."), cu->m_wszNick));
}
Sleep(9500);
@@ -869,13 +867,7 @@ void CVkProto::StopChatContactTyping(int iChatId, int iUserId) if (cp != NULL && cp->m_UserId == iUserId) {
m_ChatsTyping.remove(cp);
-
- StatusTextData st = { 0 };
- mir_snwprintf(st.tszText, L" ");
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hChatContact, (LPARAM)&st);
-
- // After that I call standard cleaning procedure:
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hChatContact);
+ Srmm_SetStatusText(hChatContact, nullptr);
}
}
diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp index c0bfdfc558..7ae1c8fcfa 100644 --- a/protocols/WhatsApp/src/utils.cpp +++ b/protocols/WhatsApp/src/utils.cpp @@ -47,13 +47,10 @@ std::string getLastErrorMsg() void utils::setStatusMessage(MCONTACT hContact, const wchar_t *ptszMessage)
{
- if (ptszMessage != NULL) {
- StatusTextData st = { 0 };
- st.hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE);
- wcsncpy_s(st.tszText, ptszMessage, _TRUNCATE);
- CallService(MS_MSG_SETSTATUSTEXT, hContact, (LPARAM)&st);
- }
- else CallService(MS_MSG_SETSTATUSTEXT, hContact, NULL);
+ if (ptszMessage != nullptr)
+ Srmm_SetStatusText(hContact, ptszMessage, Skin_LoadIcon(SKINICON_EVENT_MESSAGE));
+ else
+ Srmm_SetStatusText(hContact, nullptr);
}
BYTE* utils::md5string(const BYTE *data, int size, BYTE *digest)
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 758842535e..7646c4e7ed 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -561,10 +561,10 @@ void CSrmmWindow::SetupStatusBar() SendMessage(m_hwnd, DM_STATUSICONCHANGE, 0, 0);
}
-void CSrmmWindow::SetStatusData(StatusTextData *st)
+void CSrmmWindow::SetStatusText(const wchar_t *wszText, HICON hIcon)
{
- SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, (LPARAM)(st == nullptr ? 0 : st->hIcon));
- SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)(st == nullptr ? L"" : st->tszText));
+ SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, (LPARAM)hIcon);
+ SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)wszText);
}
void CSrmmWindow::UpdateReadChars()
diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index bffa4588be..6d302f3111 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -479,24 +479,6 @@ static int PrebuildContactMenu(WPARAM hContact, LPARAM) return 0;
}
-static INT_PTR SetStatusText(WPARAM wParam, LPARAM lParam)
-{
- StatusTextData *st = (StatusTextData*)lParam;
- if (st == nullptr)
- return 1;
-
- HWND hwnd = Srmm_FindWindow(wParam);
- if (hwnd == nullptr)
- return 1;
-
- CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (dat == nullptr)
- return 1;
-
- dat->SetStatusData(st);
- return 0;
-}
-
static wchar_t tszError[] = LPGENW("Miranda could not load the built-in message module, msftedit.dll is missing. Press 'Yes' to continue loading Miranda.");
int LoadSendRecvMessageModule(void)
@@ -521,7 +503,6 @@ int LoadSendRecvMessageModule(void) CreateServiceFunction(MS_MSG_SENDMESSAGE, SendMessageCommand);
CreateServiceFunction(MS_MSG_SENDMESSAGEW, SendMessageCommand_W);
- CreateServiceFunction(MS_MSG_SETSTATUSTEXT, SetStatusText);
CreateServiceFunction("SRMsg/ReadMessage", ReadMessageCommand);
SkinAddNewSoundEx("RecvMsgActive", LPGEN("Instant messages"), LPGEN("Incoming (focused window)"));
diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index fea335010a..a94cb6a08d 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -112,6 +112,7 @@ public: virtual void CloseTab() override;
virtual void LoadSettings() override {}
virtual void ScrollToBottom() override;
+ virtual void SetStatusText(const wchar_t*, HICON) override;
virtual void UpdateTitle() override {}
void OnSplitterMoved(CSplitter*);
@@ -120,7 +121,6 @@ public: void OnOptionsApplied(bool bUpdateAvatar);
- void SetStatusData(StatusTextData*);
void UpdateReadChars(void);
__forceinline MCONTACT getActiveContact() const
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 890a9eec7f..a0addf8ff5 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -451,3 +451,5 @@ Hotkey_Subclass @455 Hotkey_Unregister @456
Hotkey_Unsubclass @457
Hotkey_Check @458
+?SetStatusText@CSrmmBaseDialog@@UAEXPB_WPAUHICON__@@@Z @459 NONAME
+Srmm_SetStatusText @460
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index f5e2debc70..963f8cd9ad 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -451,3 +451,5 @@ Hotkey_Subclass @455 Hotkey_Unregister @456
Hotkey_Unsubclass @457
Hotkey_Check @458
+?SetStatusText@CSrmmBaseDialog@@UEAAXPEB_WPEAUHICON__@@@Z @459 NONAME
+Srmm_SetStatusText @460
diff --git a/src/mir_app/src/srmm_util.cpp b/src/mir_app/src/srmm_util.cpp index ad0abe21a3..f9e7ed65c5 100644 --- a/src/mir_app/src/srmm_util.cpp +++ b/src/mir_app/src/srmm_util.cpp @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "chat.h" +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(DWORD) CALLBACK Srmm_LogStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) { LOGSTREAMDATA *lstrdat = (LOGSTREAMDATA*)dwCookie; @@ -50,6 +52,8 @@ MIR_APP_DLL(DWORD) CALLBACK Srmm_LogStreamCallback(DWORD_PTR dwCookie, LPBYTE pb return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(int) Srmm_GetWindowData(MCONTACT hContact, MessageWindowData &mwd) { if (hContact == 0) @@ -71,12 +75,48 @@ MIR_APP_DLL(int) Srmm_GetWindowData(MCONTACT hContact, MessageWindowData &mwd) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(void) Srmm_Broadcast(UINT msg, WPARAM wParam, LPARAM lParam) { WindowList_Broadcast(g_hWindowList, msg, wParam, lParam); } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(HWND) Srmm_FindWindow(MCONTACT hContact) { return WindowList_Find(g_hWindowList, hContact); } + +///////////////////////////////////////////////////////////////////////////////////////// +// serializes all thread-unsafe operation to the first thread + +struct SSTParam +{ + HWND hwnd; + const wchar_t *wszText; + HICON hIcon; +}; + +static INT_PTR CALLBACK sttSetStatusText(void *_p) +{ + SSTParam *param = (SSTParam*)_p; + + CSrmmBaseDialog *pDlg = (CSrmmBaseDialog*)GetWindowLongPtr(param->hwnd, GWLP_USERDATA); + if (pDlg != nullptr) + pDlg->SetStatusText((param->wszText == nullptr) ? L"" : param->wszText, param->hIcon); + return 0; +} + +MIR_APP_DLL(void) Srmm_SetStatusText(MCONTACT hContact, const wchar_t *wszText, HICON hIcon) +{ + HWND hwnd = Srmm_FindWindow(hContact); + if (hwnd == nullptr) + hwnd = Srmm_FindWindow(db_mc_getMeta(hContact)); + if (hwnd == nullptr) + return; + + SSTParam param = { hwnd, wszText, hIcon }; + CallFunctionSync(sttSetStatusText, ¶m); +} |