From 22fd8863b0175f11937c43441904852eda5f9c4a Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sat, 19 Sep 2015 16:46:00 +0000 Subject: Toaster: code optimization git-svn-id: http://svn.miranda-ng.org/main/trunk@15397 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Toaster/src/toast_event_handler.cpp | 6 +++--- plugins/Toaster/src/toast_event_handler.h | 8 ++++---- plugins/Toaster/src/toast_notification.cpp | 29 +++++++++++------------------ plugins/Toaster/src/toast_notification.h | 12 ++++-------- plugins/Toaster/src/version.h | 4 ++-- 5 files changed, 24 insertions(+), 35 deletions(-) (limited to 'plugins') diff --git a/plugins/Toaster/src/toast_event_handler.cpp b/plugins/Toaster/src/toast_event_handler.cpp index abb24ece06..a5b11705cc 100644 --- a/plugins/Toaster/src/toast_event_handler.cpp +++ b/plugins/Toaster/src/toast_event_handler.cpp @@ -46,7 +46,7 @@ IFACEMETHODIMP ToastEventHandler::QueryInterface(_In_ REFIID riid, _COM_Outptr_ return (*ppv ? S_OK : E_NOINTERFACE); } -IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification * /*sender*/, _In_ IInspectable* /*args*/) +IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification*, _In_ IInspectable*) { if (_thd->pPopupProc) _thd->pPopupProc((HWND)this, WM_COMMAND, 0, 0); @@ -57,7 +57,7 @@ IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification * /*sender*/, _ return S_OK; } -IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification* /* sender */, _In_ IToastDismissedEventArgs* e) +IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification*, _In_ IToastDismissedEventArgs* e) { ToastDismissalReason tdr; CHECKHR(e->get_Reason(&tdr)); @@ -87,7 +87,7 @@ IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification* /* sender */, return S_OK; } -IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification* /* sender */, _In_ IToastFailedEventArgs* /*e*/ ) +IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification*, _In_ IToastFailedEventArgs*) { mir_cslock lck(csNotifications); lstNotifications.remove(_thd->tstNotification); diff --git a/plugins/Toaster/src/toast_event_handler.h b/plugins/Toaster/src/toast_event_handler.h index 4d7a13c2f5..321b1b4764 100644 --- a/plugins/Toaster/src/toast_event_handler.h +++ b/plugins/Toaster/src/toast_event_handler.h @@ -10,7 +10,7 @@ struct ToastHandlerData; class ToastEventHandler : public Microsoft::WRL::Implements { public: - ToastEventHandler::ToastEventHandler(_In_ ToastHandlerData *pData); + ToastEventHandler::ToastEventHandler(_In_ ToastHandlerData*); ~ToastEventHandler(); IFACEMETHODIMP_(ULONG) AddRef(); @@ -18,9 +18,9 @@ public: IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppv); - IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification* sender, _In_ IInspectable* args); - IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification* /* sender */, _In_ ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e); - IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification* /* sender */, _In_ ABI::Windows::UI::Notifications::IToastFailedEventArgs* /* e */); + IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ IInspectable*); + IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ ABI::Windows::UI::Notifications::IToastDismissedEventArgs*); + IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ ABI::Windows::UI::Notifications::IToastFailedEventArgs*); void* GetPluginData(); MCONTACT GetContact(); diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index 02b190a80e..acbb5d627c 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -4,14 +4,13 @@ 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() { - notification->remove_Activated(ertActivated); - notification->remove_Dismissed(ertDismissed); - notification->remove_Failed(ertFailed); + notification->remove_Activated(_ertActivated); + notification->remove_Dismissed(_ertDismissed); + notification->remove_Failed(_ertFailed); } HRESULT ToastNotification::Initialize() @@ -53,13 +52,12 @@ HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXml HXML xmlTextNode = xmlAddChild(xmlBindingNode, L"text", _text); xmlAddAttr(xmlTextNode, L"id", L"2"); } - - TCHAR *xtmp = xmlToString(xmlToast, NULL); - size_t xlen = mir_tstrlen(xtmp); + int nLength; + TCHAR *xtmp = xmlToString(xmlToast, &nLength); xmlDestroyNode(xmlToast); - CHECKHR(xmlDocument->LoadXml(StringReferenceWrapper(xtmp, (UINT32)xlen).Get())); + CHECKHR(xmlDocument->LoadXml(StringReferenceWrapper(xtmp, nLength).Get())); return xmlDocument.CopyTo(xml); } @@ -75,19 +73,14 @@ HRESULT ToastNotification::Create(_Outptr_ ABI::Windows::UI::Notifications::IToa return factory->CreateToastNotification(xml.Get(), _notification); } -HRESULT ToastNotification::Show() -{ - return Show(new ToastEventHandler(nullptr)); -} - HRESULT ToastNotification::Show(_In_ ToastEventHandler* handler) { - ComPtr eventHandler(handler); - notification->add_Activated(eventHandler.Get(), &ertActivated); - notification->add_Dismissed(eventHandler.Get(), &ertDismissed); - notification->add_Failed(eventHandler.Get(), &ertFailed); + notification->add_Activated(eventHandler.Get(), &_ertActivated); + notification->add_Dismissed(eventHandler.Get(), &_ertDismissed); + notification->add_Failed(eventHandler.Get(), &_ertFailed); + return notifier->Show(notification.Get()); } diff --git a/plugins/Toaster/src/toast_notification.h b/plugins/Toaster/src/toast_notification.h index e56a08c418..cf86271e64 100644 --- a/plugins/Toaster/src/toast_notification.h +++ b/plugins/Toaster/src/toast_notification.h @@ -8,9 +8,9 @@ private: wchar_t* _caption; wchar_t* _imagePath; - EventRegistrationToken ertActivated; - EventRegistrationToken ertDismissed; - EventRegistrationToken ertFailed; + EventRegistrationToken _ertActivated; + EventRegistrationToken _ertDismissed; + EventRegistrationToken _ertFailed; Microsoft::WRL::ComPtr notificationManager; Microsoft::WRL::ComPtr notifier; @@ -20,14 +20,10 @@ private: HRESULT Create(_Outptr_ ABI::Windows::UI::Notifications::IToastNotification** notification); public: - COLORREF background; - COLORREF foreground; - ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption = nullptr, _In_ wchar_t* imagePath = nullptr); - HRESULT Initialize(); ~ToastNotification(); - HRESULT Show(); + HRESULT Initialize(); HRESULT Show(_In_ ToastEventHandler* handler); HRESULT Hide(); }; diff --git a/plugins/Toaster/src/version.h b/plugins/Toaster/src/version.h index 02dc95757d..39649b5bd8 100644 --- a/plugins/Toaster/src/version.h +++ b/plugins/Toaster/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 -#define __RELEASE_NUM 1 -#define __BUILD_NUM 1 +#define __RELEASE_NUM 2 +#define __BUILD_NUM 0 #include -- cgit v1.2.3