diff options
author | George Hazan <ghazan@miranda.im> | 2022-06-29 13:53:31 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-06-29 13:53:31 +0300 |
commit | 3bace5a63029cc6210256523a0f0a658e34bc4b7 (patch) | |
tree | 6a18574e4b8a94fcf060840572398971e37886b4 /plugins | |
parent | 0bab63af012c9d2da217d13b7a24242710f10f62 (diff) |
Toaster: code cleaning
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Toaster/src/services.cpp | 15 | ||||
-rw-r--r-- | plugins/Toaster/src/stdafx.h | 3 | ||||
-rw-r--r-- | plugins/Toaster/src/toast_notification.cpp | 26 | ||||
-rw-r--r-- | plugins/Toaster/src/toast_notification.h | 12 |
4 files changed, 30 insertions, 26 deletions
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index b75719acb3..7f2ce75ab7 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -1,7 +1,5 @@ #include "stdafx.h"
-mir_cs csNotifications;
-OBJLIST<ToastNotification> lstNotifications(2, PtrKeySortT);
std::map<std::string, ClassData*> mp_Classes;
wchar_t wszTempDir[MAX_PATH];
@@ -182,20 +180,11 @@ static INT_PTR ShowMessage(WPARAM wParam, LPARAM lParam) static INT_PTR HideToast(WPARAM, LPARAM lParam)
{
- ToastNotification *pNotification = reinterpret_cast<ToastNotification *>(lParam);
- mir_cslock lck(csNotifications);
- if (lstNotifications.getIndex(pNotification) != -1)
- lstNotifications.remove(pNotification);
+ auto *pNotification = (ToastNotification*)lParam;
+ pNotification->Destroy();
return 0;
}
-void HideAllToasts()
-{
- mir_cslock lck(csNotifications);
- while (lstNotifications.getCount())
- lstNotifications.remove(0);
-}
-
void InitServices()
{
CreateServiceFunction(MS_POPUP_SHOWMESSAGE, ShowMessage);
diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h index 4d61dfc837..e3211c31c2 100644 --- a/plugins/Toaster/src/stdafx.h +++ b/plugins/Toaster/src/stdafx.h @@ -41,10 +41,7 @@ struct CMPlugin : public PLUGIN<CMPlugin> int Load() override;
};
-class ToastNotification;
-extern mir_cs csNotifications;
extern wchar_t wszTempDir[MAX_PATH];
-extern OBJLIST<ToastNotification> lstNotifications;
#include "string_reference_wrapper.h"
#include "utils.h"
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index 040047ff6f..11700b7287 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -2,6 +2,21 @@ #include <wrl.h>
using namespace Microsoft::WRL;
+static mir_cs csNotifications;
+static LIST<ToastNotification> lstNotifications(10, PtrKeySortT);
+
+void HideAllToasts()
+{
+ mir_cslock lck(csNotifications);
+ for (auto &it : lstNotifications.rev_iter())
+ if (it->IsValid())
+ delete it;
+
+ lstNotifications.destroy();
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
ToastNotification::ToastNotification(
_In_ wchar_t *text,
_In_ wchar_t *caption,
@@ -28,9 +43,6 @@ ToastNotification::ToastNotification( ToastNotification::~ToastNotification()
{
- if (_signature != TOAST_SIGNATURE)
- return;
-
_signature = 0;
if (_pvPopupData != nullptr)
CallPopupProc(UM_FREEPLUGINDATA);
@@ -72,7 +84,7 @@ HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXml tinyxml2::XMLPrinter printer(0, true);
doc.Print(&printer);
Utf2T xtmp(printer.CStr());
- CHECKHR(xmlDocument->LoadXml(StringReferenceWrapper(xtmp, mir_wstrlen(xtmp)).Get()));
+ CHECKHR(xmlDocument->LoadXml(StringReferenceWrapper(xtmp, (UINT32)mir_wstrlen(xtmp)).Get()));
return xmlDocument.CopyTo(xml);
}
@@ -116,6 +128,8 @@ HRESULT ToastNotification::OnFail(_In_ ABI::Windows::UI::Notifications::IToastNo void ToastNotification::Destroy()
{
- mir_cslock lck(csNotifications);
- lstNotifications.remove(this);
+ { mir_cslock lck(csNotifications);
+ lstNotifications.remove(this);
+ }
+ delete this;
}
diff --git a/plugins/Toaster/src/toast_notification.h b/plugins/Toaster/src/toast_notification.h index 55add011e3..2b730c1d23 100644 --- a/plugins/Toaster/src/toast_notification.h +++ b/plugins/Toaster/src/toast_notification.h @@ -8,7 +8,6 @@ typedef __FITypedEventHandler_2_Windows__CUI__CNotifications__CToastNotification class ToastNotification
{
-private:
uint32_t _signature = TOAST_SIGNATURE;
MCONTACT _hContact;
@@ -38,14 +37,19 @@ public: HRESULT OnDismiss(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ ABI::Windows::UI::Notifications::IToastDismissedEventArgs*);
HRESULT OnFail(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ ABI::Windows::UI::Notifications::IToastFailedEventArgs*);
- inline void* GetPluginData()
+ __forceinline bool IsValid() const
+ { return _signature == TOAST_SIGNATURE;
+ }
+
+ __forceinline void* GetPluginData() const
{ return _pvPopupData;
}
- inline MCONTACT GetContact()
+
+ __forceinline MCONTACT GetContact() const
{ return _hContact;
}
- inline LRESULT CallPopupProc(UINT uMsg)
+ __forceinline LRESULT CallPopupProc(UINT uMsg)
{ return (_pfnPopupProc ? _pfnPopupProc((HWND)this, uMsg, 0, 0) : 0);
}
|