From 79cd4ccc87c8a4f380bd29139c71c0995e565913 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Tue, 29 Dec 2015 17:40:24 +0000 Subject: Toaster: big refactoring git-svn-id: http://svn.miranda-ng.org/main/trunk@15964 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Toaster/src/toast_notification.cpp | 58 +++++++++++++++++++----------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'plugins/Toaster/src/toast_notification.cpp') 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 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(this, &ToastNotification::OnActivate).Get(), &_ertActivated); + notification->add_Dismissed(Callback(this, &ToastNotification::OnDismiss).Get(), &_ertDismissed); + notification->add_Failed(Callback(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 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 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 -- cgit v1.2.3