electron/brightray/browser/win/win32_notification.cc
Charles Kerr d663b4eaee
fix: fix gn cpplint warnings (#14583)
* chore: fix cpplint 'include_what_you_use' warnings

Typically by including <memory>, <utility> etc.

* chore: fix 'static/global string constant' warning

Use C style strings instead of std::string.

Style guide forbids non-trivial static / global variables. https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables

/home/charles/electron/electron-gn/src/electron/script/cpplint.js

* refactor: remove global string variables.

Fix 'global string variables are not permitted' linter warnings
by using the base::NoDestructor<> wrapper to make it explicit that
these variables are never destroyed.

The style guide's take on globals with nontrivial destructors:
https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables

* fix: initializer error introduced in last commit

* fix: remove WIP file that was included by accident

* fix: include order

* fix: include order

* fix: include order

* fix: include order, again
2018-09-12 19:25:56 -05:00

63 lines
1.6 KiB
C++

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include "brightray/browser/win/win32_notification.h"
#include <windows.h>
#include <string>
#include <utility>
#include <vector>
#include "third_party/skia/include/core/SkBitmap.h"
namespace brightray {
void Win32Notification::Show(const NotificationOptions& options) {
auto* presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
if (!presenter)
return;
HBITMAP image = NULL;
if (!options.icon.drawsNothing()) {
if (options.icon.colorType() == kBGRA_8888_SkColorType) {
BITMAPINFOHEADER bmi = {sizeof(BITMAPINFOHEADER)};
bmi.biWidth = options.icon.width();
bmi.biHeight = -options.icon.height();
bmi.biPlanes = 1;
bmi.biBitCount = 32;
bmi.biCompression = BI_RGB;
HDC hdcScreen = GetDC(NULL);
image =
CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, options.icon.getPixels(),
reinterpret_cast<BITMAPINFO*>(&bmi), DIB_RGB_COLORS);
ReleaseDC(NULL, hdcScreen);
}
}
Win32Notification* existing = nullptr;
if (!options.tag.empty())
existing = presenter->GetNotificationObjectByTag(options.tag);
if (existing) {
existing->tag_.clear();
this->notification_ref_ = std::move(existing->notification_ref_);
this->notification_ref_.Set(options.title, options.msg, image);
} else {
this->notification_ref_ =
presenter->AddNotification(options.title, options.msg, image);
}
this->tag_ = options.tag;
if (image)
DeleteObject(image);
}
void Win32Notification::Dismiss() {
notification_ref_.Close();
}
} // namespace brightray