diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-09-12 10:36:30 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-09-12 10:36:30 +0000 |
commit | 62384056910fc8fef88e1d99c62b3fe7ac313ac2 (patch) | |
tree | 4872ca7d992bbda2974fad3ff2be1aabbd75b390 | |
parent | dbc1d7539d11a0102b3b6b89f6c711a82b0a3fda (diff) |
Toaster: removed crutches, normal event handler
git-svn-id: http://svn.miranda-ng.org/main/trunk@15330 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/Toaster/src/services.cpp | 78 | ||||
-rw-r--r-- | plugins/Toaster/src/stdafx.h | 22 | ||||
-rw-r--r-- | plugins/Toaster/src/toast_event_handler.cpp | 32 | ||||
-rw-r--r-- | plugins/Toaster/src/toast_event_handler.h | 16 |
4 files changed, 95 insertions, 53 deletions
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index cfb9e3c5c3..c7dbf2367c 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -5,31 +5,6 @@ OBJLIST<ToastNotification> lstNotifications(1); std::map<std::string, ClassData*> mp_Classes;
wchar_t wszTempDir[MAX_PATH];
-__forceinline bool isChatRoom(MCONTACT hContact)
-{ return (db_get_b(hContact, GetContactProto(hContact), "ChatRoom", 0) == 1);
-}
-
-static void __cdecl OnToastNotificationClicked(void* arg)
-{
- callbackArg *cb = (callbackArg*)arg;
- MCONTACT hContact = cb->hContact;
- if (hContact)
- {
- if (!isChatRoom(hContact))
- {
- CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact);
- }
- else
- {
- const char *szProto = GetContactProto(hContact);
- ptrT tszChatRoom(db_get_tsa(hContact, szProto, "ChatRoomID"));
- GCDEST gcd = { szProto, tszChatRoom, GC_EVENT_CONTROL };
- GCEVENT gce = { sizeof(gce), &gcd };
- CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce);
- }
- }
-}
-
void __stdcall ShowToastNotification(void* p)
{
std::unique_ptr<ToastData> td((ToastData*)p);
@@ -78,7 +53,13 @@ void __stdcall ShowToastNotification(void* p) HRESULT hr = arg->notification->Initialize();
if (SUCCEEDED(hr))
{
- arg->notification->Show(new ToastEventHandler(OnToastNotificationClicked, arg));
+ ToastHandlerData *thd = new ToastHandlerData();
+ thd->hContact = td->hContact;
+ thd->vPopupData = td->vPopupData;
+ thd->pPopupProc = td->pPopupProc;
+ thd->tstNotification = arg->notification;
+
+ arg->notification->Show(new ToastEventHandler(thd));
lstNotifications.insert(arg->notification);
}
else
@@ -88,13 +69,27 @@ void __stdcall ShowToastNotification(void* p) }
}
+static INT_PTR GetPopupData(WPARAM wParam, LPARAM)
+{
+ return (INT_PTR)((ToastEventHandler*)wParam)->_thd->vPopupData;
+}
+
+static INT_PTR GetPopupContact(WPARAM wParam, LPARAM)
+{
+ return (INT_PTR)((ToastEventHandler*)wParam)->_thd->hContact;
+}
+
static INT_PTR CreatePopup(WPARAM wParam, LPARAM)
{
POPUPDATA *ppd = (POPUPDATA*)wParam;
ptrW text(mir_a2u(ppd->lpzText));
ptrW contactName(mir_a2u(ppd->lpzContactName));
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, contactName, text, ppd->lchIcon));
+ ToastData *td = new ToastData(ppd->lchContact, contactName, text, ppd->lchIcon);
+ td->vPopupData = ppd->PluginData;
+ td->pPopupProc = ppd->PluginWindowProc;
+
+ CallFunctionAsync(&ShowToastNotification, td);
return 0;
}
@@ -102,7 +97,12 @@ static INT_PTR CreatePopup(WPARAM wParam, LPARAM) static INT_PTR CreatePopupW(WPARAM wParam, LPARAM)
{
POPUPDATAW *ppd = (POPUPDATAW*)wParam;
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, ppd->lpwzContactName, ppd->lpwzText, ppd->lchIcon));
+
+ ToastData *td = new ToastData(ppd->lchContact, ppd->lpwzContactName, ppd->lpwzText, ppd->lchIcon);
+ td->vPopupData = ppd->PluginData;
+ td->pPopupProc = ppd->PluginWindowProc;
+
+ CallFunctionAsync(&ShowToastNotification, td);
return 0;
}
@@ -122,7 +122,11 @@ static INT_PTR CreatePopup2(WPARAM wParam, LPARAM) title = mir_a2u(ppd->lpzTitle);
}
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, title, text, ppd->lchIcon));
+ ToastData *td = new ToastData(ppd->lchContact, title, text, ppd->lchIcon);
+ td->vPopupData = ppd->PluginData;
+ td->pPopupProc = ppd->PluginWindowProc;
+
+ CallFunctionAsync(&ShowToastNotification, td);
return 0;
}
@@ -132,6 +136,8 @@ static INT_PTR RegisterClass(WPARAM, LPARAM lParam) POPUPCLASS *pc = (POPUPCLASS*)lParam;
ClassData *cd = new ClassData(pc->flags, pc->hIcon);
+ cd->pPopupProc = pc->PluginWindowProc;
+
mp_Classes[pc->pszName] = cd;
return (INT_PTR)cd->handle;
@@ -144,14 +150,21 @@ static INT_PTR CreateClassPopup(WPARAM, LPARAM lParam) auto it = mp_Classes.find(ppc->pszClassName);
if (it != mp_Classes.end())
{
+ ToastData *td = NULL;
+
if (it->second->iFlags & PCF_TCHAR)
{
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppc->hContact, ppc->ptszTitle, ppc->ptszText, it->second->hIcon, 1));
+ td = new ToastData(ppc->hContact, ppc->ptszTitle, ppc->ptszText, it->second->hIcon, 1);
}
else
{
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppc->hContact, mir_utf8decodeT(ppc->pszTitle), mir_utf8decodeT(ppc->pszText), it->second->hIcon, 1));
+ td = new ToastData(ppc->hContact, mir_utf8decodeT(ppc->pszTitle), mir_utf8decodeT(ppc->pszText), it->second->hIcon, 1);
}
+
+ td->vPopupData = ppc->PluginData;
+ td->pPopupProc = it->second->pPopupProc;
+
+ CallFunctionAsync(&ShowToastNotification, td);
}
return 0;
@@ -228,4 +241,7 @@ void InitServices() CreateServiceFunction(MS_POPUP_ADDPOPUPCLASS, CreateClassPopup);
CreateServiceFunction(MS_POPUP_REGISTERCLASS, RegisterClass);
CreateServiceFunction(MS_POPUP_UNREGISTERCLASS, UnRegisterClass);
+
+ CreateServiceFunction(MS_POPUP_GETPLUGINDATA, GetPopupData);
+ CreateServiceFunction(MS_POPUP_GETCONTACT, GetPopupContact);
}
\ No newline at end of file diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h index 2e8a5bb94d..57eaf9c735 100644 --- a/plugins/Toaster/src/stdafx.h +++ b/plugins/Toaster/src/stdafx.h @@ -25,6 +25,11 @@ #include "version.h"
#include "resource.h"
+__forceinline bool isChatRoom(MCONTACT hContact)
+{
+ return (db_get_b(hContact, GetContactProto(hContact), "ChatRoom", 0) == 1);
+}
+
typedef void(__cdecl *pEventHandler)(void*);
const wchar_t AppUserModelID[] = _T("MirandaNG");
DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 5);
@@ -33,6 +38,8 @@ DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, #define CHECKHR(x) if (FAILED(x)) return x;
+class ToastNotification;
+
#include "string_reference_wrapper.h"
#include "toast_event_handler.h"
#include "toast_notification.h"
@@ -58,7 +65,16 @@ struct ToastData HICON hIcon;
bool bForcehIcon;
- ToastData(MCONTACT _hContact, const TCHAR *_tszTitle, const TCHAR *_tszText, HICON _hIcon = NULL, bool b = false) : hContact(_hContact), tszTitle(mir_tstrdup(_tszTitle)), tszText(mir_tstrdup(_tszText)), hIcon(_hIcon), bForcehIcon(b) {}
+ WNDPROC pPopupProc;
+ void *vPopupData;
+
+ ToastData(MCONTACT _hContact, const TCHAR *_tszTitle, const TCHAR *_tszText, HICON _hIcon = NULL, bool b = false) :
+ hContact(_hContact),
+ tszTitle(mir_tstrdup(_tszTitle)),
+ tszText(mir_tstrdup(_tszText)),
+ hIcon(_hIcon),
+ bForcehIcon(b)
+ {}
~ToastData()
{
mir_free(tszTitle);
@@ -71,6 +87,10 @@ struct ClassData int iFlags;
HICON hIcon;
HANDLE handle;
+
+ WNDPROC pPopupProc;
+ void *vPopupData;
+
ClassData(int f, HICON h = NULL) : iFlags(f), hIcon(h)
{
Utils_GetRandom(&handle, sizeof(handle));
diff --git a/plugins/Toaster/src/toast_event_handler.cpp b/plugins/Toaster/src/toast_event_handler.cpp index 05e9a60601..fa97240d6f 100644 --- a/plugins/Toaster/src/toast_event_handler.cpp +++ b/plugins/Toaster/src/toast_event_handler.cpp @@ -3,17 +3,20 @@ using namespace ABI::Windows::UI::Notifications;
using namespace Microsoft::WRL;
-ToastEventHandler::ToastEventHandler() : _ref(1), _callback(nullptr), _arg(nullptr)
+ToastEventHandler::ToastEventHandler() : _ref(1)
{
}
-ToastEventHandler::ToastEventHandler(_In_ pEventHandler callback, _In_ void* arg) : _ref(1), _callback(callback), _arg(arg)
+ToastEventHandler::ToastEventHandler(_In_ ToastHandlerData *pData) : _ref(1), _thd(pData)
{
}
ToastEventHandler::~ToastEventHandler()
{
- mir_free(_arg);
+ _thd->pPopupProc((HWND)this, UM_FREEPLUGINDATA, 0, 0);
+
+ mir_cslock lck(csNotifications);
+ lstNotifications.remove(_thd->tstNotification);
}
IFACEMETHODIMP_(ULONG) ToastEventHandler::AddRef()
@@ -31,17 +34,17 @@ IFACEMETHODIMP_(ULONG) ToastEventHandler::Release() IFACEMETHODIMP ToastEventHandler::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void **ppv)
{
if (IsEqualIID(riid, IID_IUnknown))
- *ppv = static_cast<IUnknown*>(static_cast<DesktopToastActivatedEventHandler*>(this));
+ *ppv = (IUnknown*)(DesktopToastActivatedEventHandler*)(this);
else if (IsEqualIID(riid, __uuidof(DesktopToastActivatedEventHandler)))
- *ppv = static_cast<DesktopToastActivatedEventHandler*>(this);
+ *ppv = (DesktopToastActivatedEventHandler*)(this);
else if (IsEqualIID(riid, __uuidof(DesktopToastDismissedEventHandler)))
- *ppv = static_cast<DesktopToastDismissedEventHandler*>(this);
+ *ppv = (DesktopToastDismissedEventHandler*)(this);
else if (IsEqualIID(riid, __uuidof(DesktopToastFailedEventHandler)))
- *ppv = static_cast<DesktopToastFailedEventHandler*>(this);
+ *ppv = (DesktopToastFailedEventHandler*)(this);
else *ppv = nullptr;
if (*ppv) {
- reinterpret_cast<IUnknown*>(*ppv)->AddRef();
+ ((IUnknown*)*ppv)->AddRef();
return S_OK;
}
@@ -50,25 +53,18 @@ IFACEMETHODIMP ToastEventHandler::QueryInterface(_In_ REFIID riid, _COM_Outptr_ IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification * /*sender*/, _In_ IInspectable* /*args*/)
{
- if (_callback != nullptr)
- _callback(_arg);
-
- mir_cslock lck(csNotifications);
- lstNotifications.remove(((callbackArg*)_arg)->notification);
+ _thd->pPopupProc((HWND)this, WM_COMMAND, 0, 0);
return S_OK;
}
IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification* /* sender */, _In_ IToastDismissedEventArgs* /*e*/)
{
- ((callbackArg*)_arg)->notification->Hide();
- mir_cslock lck(csNotifications);
- lstNotifications.remove(((callbackArg*)_arg)->notification);
+ _thd->pPopupProc((HWND)this, WM_CONTEXTMENU, 0, 0);
return S_OK;
}
IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification* /* sender */, _In_ IToastFailedEventArgs* /*e*/ )
{
- mir_cslock lck(csNotifications);
- lstNotifications.remove(((callbackArg*)_arg)->notification);
+ delete this;
return S_OK;
}
\ No newline at end of file diff --git a/plugins/Toaster/src/toast_event_handler.h b/plugins/Toaster/src/toast_event_handler.h index a5a616d81d..097a3d53c4 100644 --- a/plugins/Toaster/src/toast_event_handler.h +++ b/plugins/Toaster/src/toast_event_handler.h @@ -5,12 +5,23 @@ typedef ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notificat typedef ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification *, ABI::Windows::UI::Notifications::ToastDismissedEventArgs *> DesktopToastDismissedEventHandler;
typedef ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification *, ABI::Windows::UI::Notifications::ToastFailedEventArgs *> DesktopToastFailedEventHandler;
+struct ToastHandlerData : public MZeroedObject
+{
+ MCONTACT hContact;
+
+ WNDPROC pPopupProc;
+ void *vPopupData;
+
+ ToastNotification *tstNotification;
+};
class ToastEventHandler : public Microsoft::WRL::Implements<DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler, DesktopToastFailedEventHandler>
{
public:
+ ToastHandlerData *_thd;
+
ToastEventHandler::ToastEventHandler();
- ToastEventHandler::ToastEventHandler(_In_ pEventHandler callback, _In_ void* arg = nullptr);
+ ToastEventHandler::ToastEventHandler(_In_ ToastHandlerData *pData);
~ToastEventHandler();
IFACEMETHODIMP_(ULONG) AddRef();
@@ -23,8 +34,7 @@ public: IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification* /* sender */, _In_ ABI::Windows::UI::Notifications::IToastFailedEventArgs* /* e */);
private:
ULONG _ref;
- void* _arg;
- pEventHandler _callback;
+
};
#endif //_TOAST_EVENT_HANDLER_H_
\ No newline at end of file |