2017-03-15 12:56:06 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/win/win32_notification.h"
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2017-03-15 12:56:06 +00:00
|
|
|
#include <windows.h>
|
2017-05-18 22:06:57 +00:00
|
|
|
#include <string>
|
2017-06-23 10:39:42 +00:00
|
|
|
#include <vector>
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2017-04-03 08:48:18 +00:00
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
2017-03-15 12:56:06 +00:00
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
2017-06-24 11:03:27 +00:00
|
|
|
void Win32Notification::Show(const NotificationOptions& options) {
|
2017-03-15 12:56:06 +00:00
|
|
|
auto presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
|
2017-04-03 11:34:01 +00:00
|
|
|
if (!presenter) return;
|
2017-03-15 12:56:06 +00:00
|
|
|
|
|
|
|
HBITMAP image = NULL;
|
|
|
|
|
2017-06-24 11:03:27 +00:00
|
|
|
if (!options.icon.drawsNothing()) {
|
|
|
|
if (options.icon.colorType() == kBGRA_8888_SkColorType) {
|
2017-03-15 12:56:06 +00:00
|
|
|
BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) };
|
2017-06-24 11:03:27 +00:00
|
|
|
bmi.biWidth = options.icon.width();
|
|
|
|
bmi.biHeight = -options.icon.height();
|
2017-03-15 12:56:06 +00:00
|
|
|
bmi.biPlanes = 1;
|
|
|
|
bmi.biBitCount = 32;
|
|
|
|
bmi.biCompression = BI_RGB;
|
|
|
|
|
|
|
|
HDC hdcScreen = GetDC(NULL);
|
2017-06-24 11:03:27 +00:00
|
|
|
image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT,
|
|
|
|
options.icon.getPixels(),
|
2017-04-05 09:53:37 +00:00
|
|
|
reinterpret_cast<BITMAPINFO*>(&bmi),
|
|
|
|
DIB_RGB_COLORS);
|
2017-03-15 12:56:06 +00:00
|
|
|
ReleaseDC(NULL, hdcScreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Win32Notification* existing = nullptr;
|
2017-06-24 11:03:27 +00:00
|
|
|
if (!options.tag.empty())
|
|
|
|
existing = presenter->GetNotificationObjectByTag(options.tag);
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2017-04-03 11:34:01 +00:00
|
|
|
if (existing) {
|
2017-03-17 13:41:22 +00:00
|
|
|
existing->tag_.clear();
|
|
|
|
this->notification_ref_ = std::move(existing->notification_ref_);
|
2017-06-24 11:03:27 +00:00
|
|
|
this->notification_ref_.Set(options.title, options.msg, image);
|
2017-04-05 10:00:35 +00:00
|
|
|
} else {
|
2017-06-24 11:03:27 +00:00
|
|
|
this->notification_ref_ = presenter->AddNotification(options.title,
|
|
|
|
options.msg,
|
|
|
|
image);
|
2017-03-15 12:56:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-24 11:03:27 +00:00
|
|
|
this->tag_ = options.tag;
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2017-04-03 11:34:01 +00:00
|
|
|
if (image) DeleteObject(image);
|
2017-03-15 12:56:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-03 10:11:39 +00:00
|
|
|
void Win32Notification::Dismiss() {
|
2017-03-17 13:41:22 +00:00
|
|
|
notification_ref_.Close();
|
2017-03-15 12:56:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 11:10:28 +00:00
|
|
|
} // namespace brightray
|