diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-12-29 17:40:24 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-12-29 17:40:24 +0000 |
commit | 79cd4ccc87c8a4f380bd29139c71c0995e565913 (patch) | |
tree | 217fdf7d3a3777149f45978ae75b081df7dc85a5 /plugins/Toaster/src/toast_notification.cpp | |
parent | c9a1a90b67f5df583174bd48c8202666c3986005 (diff) |
Toaster: big refactoring
git-svn-id: http://svn.miranda-ng.org/main/trunk@15964 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster/src/toast_notification.cpp')
-rw-r--r-- | plugins/Toaster/src/toast_notification.cpp | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index bc9f6a7b98..0b48c5c235 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -1,22 +1,34 @@ #include "stdafx.h"
-
+#include <wrl.h>
using namespace Microsoft::WRL;
-ToastNotification::ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption, _In_ wchar_t* imagePath)
- : _text(text), _caption(caption), _imagePath(imagePath)
-{}
-
-ToastNotification::~ToastNotification()
+ToastNotification::ToastNotification(
+ _In_ wchar_t* text,
+ _In_ wchar_t* caption,
+ _In_ wchar_t* imagePath,
+ MCONTACT hContact,
+ WNDPROC pWndProc,
+ void *pData )
+ : _text(text), _caption(caption), _imagePath(imagePath), _hContact(hContact), _pfnPopupProc(pWndProc), _pvPopupData(pData)
{
+ lstNotifications.insert(this);
+ Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), ¬ificationManager);
+ notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), ¬ifier);
+ Create(¬ification);
+
+ notification->add_Activated(Callback<ToastActivationHandler>(this, &ToastNotification::OnActivate).Get(), &_ertActivated);
+ notification->add_Dismissed(Callback<ToastDismissHandler>(this, &ToastNotification::OnDismiss).Get(), &_ertDismissed);
+ notification->add_Failed(Callback<ToastFailHandler>(this, &ToastNotification::OnFail).Get(), &_ertFailed);
+ notifier->Show(notification.Get());
+
}
-HRESULT ToastNotification::Initialize()
+ToastNotification::~ToastNotification()
{
- CHECKHR(Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), ¬ificationManager));
- CHECKHR(notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), ¬ifier))
- return Create(¬ification);
+ notifier->Hide(notification.Get());
}
+
HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXmlDocument** xml)
{
ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocumentIO> xmlDocument;
@@ -66,19 +78,25 @@ HRESULT ToastNotification::Create(_Outptr_ ABI::Windows::UI::Notifications::IToa return factory->CreateToastNotification(xml.Get(), _notification);
}
-HRESULT ToastNotification::Show(_In_ ToastHandlerData* thd)
+HRESULT ToastNotification::OnActivate(_In_ ABI::Windows::UI::Notifications::IToastNotification*, IInspectable*)
{
- ComPtr<ToastEventHandler> eventHandler(new ToastEventHandler(thd));
-
- CHECKHR(notification->add_Activated(eventHandler.Get(), &_ertActivated));
- CHECKHR(notification->add_Dismissed(eventHandler.Get(), &_ertDismissed));
- CHECKHR(notification->add_Failed(eventHandler.Get(), &_ertFailed));
-
- return notifier->Show(notification.Get());
+ CallPopupProc(WM_COMMAND);
+ Destroy();
+ return S_OK;
}
-HRESULT ToastNotification::Hide()
+HRESULT ToastNotification::OnDismiss(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ ABI::Windows::UI::Notifications::IToastDismissedEventArgs *e)
{
- return notifier->Hide(notification.Get());
+ ABI::Windows::UI::Notifications::ToastDismissalReason tdr;
+ CHECKHR(e->get_Reason(&tdr));
+ if (tdr == ABI::Windows::UI::Notifications::ToastDismissalReason_UserCanceled)
+ CallPopupProc(WM_CONTEXTMENU);
+ Destroy();
+ return S_OK;
}
+HRESULT ToastNotification::OnFail(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ ABI::Windows::UI::Notifications::IToastFailedEventArgs*)
+{
+ Destroy();
+ return S_OK;
+}
\ No newline at end of file |