summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2015-09-12 12:22:24 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2015-09-12 12:22:24 +0000
commit364e8cd84bf31e34a7c3730f814e58acd18e72b8 (patch)
tree8380991627434f6e83aa75083c7d6270b09822bb /plugins
parentc9dfef255429860a87b96c44fc40683ad00fa676 (diff)
Toaster: code optimization
git-svn-id: http://svn.miranda-ng.org/main/trunk@15335 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Toaster/src/images.cpp32
-rw-r--r--plugins/Toaster/src/images.h66
-rw-r--r--plugins/Toaster/src/services.cpp6
-rw-r--r--plugins/Toaster/src/toast_event_handler.cpp8
4 files changed, 66 insertions, 46 deletions
diff --git a/plugins/Toaster/src/images.cpp b/plugins/Toaster/src/images.cpp
deleted file mode 100644
index 5ea6779627..0000000000
--- a/plugins/Toaster/src/images.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#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
index ff8c2e3d1f..cc22359bc9 100644
--- a/plugins/Toaster/src/images.h
+++ b/plugins/Toaster/src/images.h
@@ -1,5 +1,61 @@
-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);
-}
+extern wchar_t wszTempDir[];
+
+class ToasterImage
+{
+ HBITMAP _hBitmap;
+ ptrT tszId;
+
+public:
+ ToasterImage(HICON hIcon)
+ {
+ ICONINFO icon;
+ if (GetIconInfo(hIcon, &icon))
+ {
+ _hBitmap = icon.hbmColor;
+ DeleteObject(icon.hbmMask);
+ }
+ tszId = CMString(FORMAT, _T("%p"), hIcon).Detach();
+ }
+
+ inline ToasterImage(HBITMAP bmp) : _hBitmap(bmp)
+ {
+ tszId = CMString(FORMAT, _T("%p"), bmp).Detach();
+ }
+
+ ToasterImage(const char *szProto)
+ {
+ ICONINFO icon;
+ if (GetIconInfo(Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1), &icon))
+ {
+ _hBitmap = icon.hbmColor;
+ DeleteObject(icon.hbmMask);
+ }
+ tszId = mir_a2t(szProto);
+ }
+
+ inline ~ToasterImage()
+ {
+ DeleteObject(_hBitmap);
+ }
+
+ wchar_t* Save()
+ {
+ wchar_t wszSavePath[MAX_PATH];
+ mir_snwprintf(wszSavePath, L"%s\\MirandaToaster.%s.png", wszTempDir, tszId);
+
+ if (!(GetFileAttributes(wszSavePath) < 0xFFFFFFF))
+ {
+ IMGSRVC_INFO isi = { sizeof(isi) };
+ isi.wszName = mir_wstrdup(wszSavePath);
+ isi.hbm = _hBitmap;
+ isi.dwMask = IMGI_HBITMAP;
+ isi.fif = FREE_IMAGE_FORMAT::FIF_PNG;
+ CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_WCHAR);
+ }
+ return mir_wstrdup(wszSavePath);
+ }
+
+ inline operator wchar_t*()
+ { return Save();
+ }
+}; \ No newline at end of file
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp
index 81d737525a..02a92f24ab 100644
--- a/plugins/Toaster/src/services.cpp
+++ b/plugins/Toaster/src/services.cpp
@@ -30,11 +30,11 @@ void __stdcall ShowToastNotification(void* p)
{
if ((td->hIcon && td->bForcehIcon) || !szProto)
{
- imagePath = SaveHIcon(td->hIcon, CMStringA(FORMAT, "%p", td->hIcon));
+ imagePath = ToasterImage(td->hIcon);
}
else if (szProto)
{
- imagePath = ProtoIcon(szProto);
+ imagePath = ToasterImage(szProto);
}
}
}
@@ -42,7 +42,7 @@ void __stdcall ShowToastNotification(void* p)
{
if (td->hIcon)
{
- imagePath = SaveHIcon(td->hIcon, CMStringA(FORMAT, "%p", td->hIcon));
+ imagePath = ToasterImage(td->hIcon);
}
}
diff --git a/plugins/Toaster/src/toast_event_handler.cpp b/plugins/Toaster/src/toast_event_handler.cpp
index 305ca120f7..31c3a97eef 100644
--- a/plugins/Toaster/src/toast_event_handler.cpp
+++ b/plugins/Toaster/src/toast_event_handler.cpp
@@ -46,12 +46,8 @@ IFACEMETHODIMP ToastEventHandler::QueryInterface(_In_ REFIID riid, _COM_Outptr_
*ppv = (DesktopToastFailedEventHandler*)(this);
else *ppv = nullptr;
- if (*ppv) {
- ((IUnknown*)*ppv)->AddRef();
- return S_OK;
- }
-
- return E_NOINTERFACE;
+ if (*ppv) ((IUnknown*)*ppv)->AddRef();
+ return (*ppv ? S_OK : E_NOINTERFACE);
}
IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification * /*sender*/, _In_ IInspectable* /*args*/)