diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-09-03 09:58:59 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-09-03 09:58:59 +0000 |
commit | 645809725d48605f0fa0d3a5f909667324be326a (patch) | |
tree | f89fa1f13406a3f2b539fba6bed18904d2886714 /plugins/Toaster | |
parent | 9c39d74383197c1848a47b81831b08326c8f0884 (diff) |
Toaster: classes support part 2 (icons)
git-svn-id: http://svn.miranda-ng.org/main/trunk@15163 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster')
-rw-r--r-- | plugins/Toaster/src/images.cpp | 32 | ||||
-rw-r--r-- | plugins/Toaster/src/images.h | 5 | ||||
-rw-r--r-- | plugins/Toaster/src/main.cpp | 1 | ||||
-rw-r--r-- | plugins/Toaster/src/services.cpp | 76 | ||||
-rw-r--r-- | plugins/Toaster/src/stdafx.h | 13 | ||||
-rw-r--r-- | plugins/Toaster/src/toast_notification.cpp | 1 |
6 files changed, 85 insertions, 43 deletions
diff --git a/plugins/Toaster/src/images.cpp b/plugins/Toaster/src/images.cpp new file mode 100644 index 0000000000..5ea6779627 --- /dev/null +++ b/plugins/Toaster/src/images.cpp @@ -0,0 +1,32 @@ +#include "stdafx.h"
+
+wchar_t* SaveBitmap(HBITMAP bmp, const char *szId)
+{
+ wchar_t wszSavePath[MAX_PATH];
+ mir_snwprintf(wszSavePath, L"%s\\MirandaToaster.%s.png", wszTempDir, _A2T(szId));
+
+ if (!(GetFileAttributes(wszSavePath) < 0xFFFFFFF))
+ {
+ IMGSRVC_INFO isi = { sizeof(isi) };
+ isi.wszName = mir_wstrdup(wszSavePath);
+ isi.hbm = bmp;
+ isi.dwMask = IMGI_HBITMAP;
+ isi.fif = FREE_IMAGE_FORMAT::FIF_PNG;
+ CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_WCHAR);
+ }
+ return mir_wstrdup(wszSavePath);
+}
+
+wchar_t* SaveHIcon(HICON hIcon, const char *szId)
+{
+ wchar_t *wszResult = NULL;
+ ICONINFO icon;
+ if (GetIconInfo(hIcon, &icon))
+ {
+ wszResult = SaveBitmap(icon.hbmColor, szId);
+
+ DeleteObject(icon.hbmMask);
+ DeleteObject(icon.hbmColor);
+ }
+ return wszResult;
+}
\ No newline at end of file diff --git a/plugins/Toaster/src/images.h b/plugins/Toaster/src/images.h new file mode 100644 index 0000000000..ff8c2e3d1f --- /dev/null +++ b/plugins/Toaster/src/images.h @@ -0,0 +1,5 @@ +wchar_t* SaveBitmap(HBITMAP bmp, const char *szId);
+wchar_t* SaveHIcon(HICON hIcon, const char *szId);
+__forceinline wchar_t* ProtoIcon(const char *szProto)
+{ return SaveHIcon(Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1), szProto);
+}
diff --git a/plugins/Toaster/src/main.cpp b/plugins/Toaster/src/main.cpp index ac60b0a8b2..af76da6955 100644 --- a/plugins/Toaster/src/main.cpp +++ b/plugins/Toaster/src/main.cpp @@ -79,5 +79,6 @@ extern "C" int __declspec(dllexport) Unload(void) int OnPreShutdown(WPARAM, LPARAM)
{
CallFunctionAsync(&HideAllToasts, NULL);
+ CleanupClasses();
return 0;
}
\ No newline at end of file diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index 36edadc576..9063cf3113 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -2,48 +2,13 @@ mir_cs csNotifications;
OBJLIST<ToastNotification> lstNotifications(1);
-std::map<std::string, int> mp_Classes;
+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);
}
-wchar_t* SaveBitmap(HBITMAP bmp, const char *szId)
-{
- wchar_t wszSavePath[MAX_PATH];
- mir_snwprintf(wszSavePath, L"%s\\MirandaToaster.%s.png", wszTempDir, _A2T(szId));
-
- if (!(GetFileAttributes(wszSavePath) < 0xFFFFFFF))
- {
- IMGSRVC_INFO isi = { sizeof(isi) };
- isi.wszName = mir_wstrdup(wszSavePath);
- isi.hbm = bmp;
- isi.dwMask = IMGI_HBITMAP;
- isi.fif = FREE_IMAGE_FORMAT::FIF_PNG;
- CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_WCHAR);
- }
- return mir_wstrdup(wszSavePath);
-}
-
-wchar_t* SaveHIcon(HICON hIcon, const char *szId)
-{
- wchar_t *wszResult = NULL;
- ICONINFO icon;
- if (GetIconInfo(hIcon, &icon))
- {
- wszResult = SaveBitmap(icon.hbmColor, szId);
-
- DeleteObject(icon.hbmMask);
- DeleteObject(icon.hbmColor);
- }
- return wszResult;
-}
-
-__forceinline wchar_t* ProtoIcon(const char *szProto)
-{ return SaveHIcon(Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1), szProto);
-}
-
static void __cdecl OnToastNotificationClicked(void* arg)
{
callbackArg *cb = (callbackArg*)arg;
@@ -165,11 +130,11 @@ static INT_PTR CreatePopup2(WPARAM wParam, LPARAM) static INT_PTR RegisterClass(WPARAM, LPARAM lParam)
{
POPUPCLASS *pc = (POPUPCLASS*)lParam;
- mp_Classes[pc->pszName] = pc->flags;
- HANDLE h;
- Utils_GetRandom(&h, sizeof(h));
- return (INT_PTR)h;
+ ClassData *cd = new ClassData(pc->flags, pc->hIcon);
+ mp_Classes[pc->pszName] = cd;
+
+ return (INT_PTR)cd->handle;
}
static INT_PTR CreateClassPopup(WPARAM, LPARAM lParam)
@@ -179,19 +144,43 @@ static INT_PTR CreateClassPopup(WPARAM, LPARAM lParam) auto it = mp_Classes.find(ppc->pszClassName);
if (it != mp_Classes.end())
{
- if (it->second & PCF_TCHAR)
+ if (it->second->iFlags & PCF_TCHAR)
{
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppc->hContact, ppc->ptszTitle, ppc->ptszText));
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppc->hContact, ppc->ptszTitle, ppc->ptszText, it->second->hIcon));
}
else
{
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppc->hContact, mir_utf8decodeT(ppc->pszTitle), mir_utf8decodeT(ppc->pszText)));
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppc->hContact, mir_utf8decodeT(ppc->pszTitle), mir_utf8decodeT(ppc->pszText), it->second->hIcon));
}
}
return 0;
}
+static INT_PTR UnRegisterClass(WPARAM, LPARAM lParam)
+{
+ HANDLE h = (HANDLE)lParam;
+
+ for (auto it = mp_Classes.begin(); it != mp_Classes.end(); it++)
+ {
+ if (it->second->handle == h)
+ {
+ delete it->second;
+ mp_Classes.erase(it);
+ }
+ }
+ return 0;
+}
+
+void CleanupClasses()
+{
+ for (auto it = mp_Classes.begin(); it != mp_Classes.end(); it++)
+ {
+ delete it->second;
+ mp_Classes.erase(it);
+ }
+}
+
static INT_PTR PopupQuery(WPARAM wParam, LPARAM)
{
switch (wParam) {
@@ -237,4 +226,5 @@ void InitServices() CreateServiceFunction(MS_POPUP_QUERY, PopupQuery);
CreateServiceFunction(MS_POPUP_ADDPOPUPCLASS, CreateClassPopup);
CreateServiceFunction(MS_POPUP_REGISTERCLASS, RegisterClass);
+ CreateServiceFunction(MS_POPUP_UNREGISTERCLASS, UnRegisterClass);
}
\ No newline at end of file diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h index 5d8fa45407..ca50132957 100644 --- a/plugins/Toaster/src/stdafx.h +++ b/plugins/Toaster/src/stdafx.h @@ -37,6 +37,7 @@ DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, #include "toast_event_handler.h"
#include "toast_notification.h"
#include "add_to_start_menu.h"
+#include "images.h"
extern HINSTANCE g_hInstance;
extern mir_cs csNotifications;
@@ -64,6 +65,18 @@ struct ToastData }
};
+struct ClassData
+{
+ int iFlags;
+ HICON hIcon;
+ HANDLE handle;
+ ClassData(int f, HICON h = NULL) : iFlags(f), hIcon(h)
+ {
+ Utils_GetRandom(&handle, sizeof(handle));
+ }
+};
+
+void CleanupClasses();
void InitServices();
int OnPreShutdown(WPARAM, LPARAM);
void __stdcall HideAllToasts(void*);
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index c19566f767..70bd8865ca 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -22,6 +22,7 @@ HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXml {
ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocumentIO> xmlDocument;
CHECKHR(Windows::Foundation::ActivateInstance(StringReferenceWrapper(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument).Get(), &xmlDocument));
+
HXML xmlToast = xmlCreateNode(L"toast", NULL, 0);
HXML xmlAudioNode = xmlAddChild(xmlToast, L"audio", NULL);
|