Changed member variable naming style to snake case

This commit is contained in:
Ales Pergl 2017-03-17 14:41:22 +01:00
parent 0fa6c82b3f
commit 392d606848
7 changed files with 251 additions and 251 deletions

View file

@ -8,7 +8,7 @@ struct NotificationData
DesktopNotificationController* controller = nullptr; DesktopNotificationController* controller = nullptr;
std::wstring caption; std::wstring caption;
std::wstring bodyText; std::wstring body_text;
HBITMAP image = NULL; HBITMAP image = NULL;
@ -31,7 +31,7 @@ inline T ScaleForDpi(T value, unsigned dpi)
struct ScreenMetrics struct ScreenMetrics
{ {
UINT dpiX, dpiY; UINT dpi_x, dpi_y;
ScreenMetrics() ScreenMetrics()
{ {
@ -40,18 +40,18 @@ struct ScreenMetrics
if(GetDpiForMonitor) if(GetDpiForMonitor)
{ {
auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY);
if(GetDpiForMonitor(monitor, 0, &dpiX, &dpiY) == S_OK) if(GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK)
return; return;
} }
HDC hdc = GetDC(NULL); HDC hdc = GetDC(NULL);
dpiX = GetDeviceCaps(hdc, LOGPIXELSX); dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
dpiY = GetDeviceCaps(hdc, LOGPIXELSY); dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc); ReleaseDC(NULL, hdc);
} }
template<typename T> T X(T value) const { return ScaleForDpi(value, dpiX); } template<typename T> T X(T value) const { return ScaleForDpi(value, dpi_x); }
template<typename T> T Y(T value) const { return ScaleForDpi(value, dpiY); } template<typename T> T Y(T value) const { return ScaleForDpi(value, dpi_y); }
}; };
} }

View file

@ -53,7 +53,7 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses()
WNDCLASSEX wc = { sizeof(wc) }; WNDCLASSEX wc = { sizeof(wc) };
wc.lpfnWndProc = &WndProc; wc.lpfnWndProc = &WndProc;
wc.lpszClassName = className; wc.lpszClassName = class_name_;
wc.cbWndExtra = sizeof(DesktopNotificationController*); wc.cbWndExtra = sizeof(DesktopNotificationController*);
wc.hInstance = module; wc.hInstance = module;
@ -66,13 +66,13 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses()
DesktopNotificationController::DesktopNotificationController(unsigned maximumToasts) DesktopNotificationController::DesktopNotificationController(unsigned maximumToasts)
{ {
instances.reserve(maximumToasts); instances_.reserve(maximumToasts);
} }
DesktopNotificationController::~DesktopNotificationController() DesktopNotificationController::~DesktopNotificationController()
{ {
for(auto&& inst : instances) DestroyToast(inst); for(auto&& inst : instances_) DestroyToast(inst);
if(hwndController) DestroyWindow(hwndController); if(hwnd_controller_) DestroyWindow(hwnd_controller_);
ClearAssets(); ClearAssets();
} }
@ -115,33 +115,33 @@ LRESULT CALLBACK DesktopNotificationController::WndProc(HWND hWnd, UINT message,
void DesktopNotificationController::StartAnimation() void DesktopNotificationController::StartAnimation()
{ {
_ASSERT(hwndController); _ASSERT(hwnd_controller_);
if(!isAnimating && hwndController) if(!is_animating_ && hwnd_controller_)
{ {
// NOTE: 15ms is shorter than what we'd need for 60 fps, but since the timer // NOTE: 15ms is shorter than what we'd need for 60 fps, but since the timer
// is not accurate we must request a higher frame rate to get at least 60 // is not accurate we must request a higher frame rate to get at least 60
SetTimer(hwndController, TimerID_Animate, 15, nullptr); SetTimer(hwnd_controller_, TimerID_Animate, 15, nullptr);
isAnimating = true; is_animating_ = true;
} }
} }
HFONT DesktopNotificationController::GetCaptionFont() HFONT DesktopNotificationController::GetCaptionFont()
{ {
InitializeFonts(); InitializeFonts();
return captionFont; return caption_font_;
} }
HFONT DesktopNotificationController::GetBodyFont() HFONT DesktopNotificationController::GetBodyFont()
{ {
InitializeFonts(); InitializeFonts();
return bodyFont; return body_font_;
} }
void DesktopNotificationController::InitializeFonts() void DesktopNotificationController::InitializeFonts()
{ {
if(!bodyFont) if(!body_font_)
{ {
NONCLIENTMETRICS metrics = { sizeof(metrics) }; NONCLIENTMETRICS metrics = { sizeof(metrics) };
if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0))
@ -153,19 +153,19 @@ void DesktopNotificationController::InitializeFonts()
ReleaseDC(NULL, hdc); ReleaseDC(NULL, hdc);
metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.1f, dpiY); metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.1f, dpiY);
bodyFont = CreateFontIndirect(&metrics.lfMessageFont); body_font_ = CreateFontIndirect(&metrics.lfMessageFont);
if(captionFont) DeleteFont(captionFont); if(caption_font_) DeleteFont(caption_font_);
metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.4f, dpiY); metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.4f, dpiY);
captionFont = CreateFontIndirect(&metrics.lfMessageFont); caption_font_ = CreateFontIndirect(&metrics.lfMessageFont);
} }
} }
} }
void DesktopNotificationController::ClearAssets() void DesktopNotificationController::ClearAssets()
{ {
if(captionFont) { DeleteFont(captionFont); captionFont = NULL; } if(caption_font_) { DeleteFont(caption_font_); caption_font_ = NULL; }
if(bodyFont) { DeleteFont(bodyFont); bodyFont = NULL; } if(body_font_) { DeleteFont(body_font_); body_font_ = NULL; }
} }
void DesktopNotificationController::AnimateAll() void DesktopNotificationController::AnimateAll()
@ -176,17 +176,17 @@ void DesktopNotificationController::AnimateAll()
bool keepAnimating = false; bool keepAnimating = false;
if(!instances.empty()) if(!instances_.empty())
{ {
RECT workArea; RECT workArea;
if(SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0)) if(SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0))
{ {
ScreenMetrics metrics; ScreenMetrics metrics;
POINT origin = { workArea.right, POINT origin = { workArea.right,
workArea.bottom - metrics.Y(toastMargin<int>) }; workArea.bottom - metrics.Y(toast_margin_<int>) };
auto hdwp = BeginDeferWindowPos((int)instances.size()); auto hdwp = BeginDeferWindowPos((int)instances_.size());
for(auto&& inst : instances) for(auto&& inst : instances_)
{ {
if(!inst.hwnd) continue; if(!inst.hwnd) continue;
@ -201,14 +201,14 @@ void DesktopNotificationController::AnimateAll()
if(!keepAnimating) if(!keepAnimating)
{ {
_ASSERT(hwndController); _ASSERT(hwnd_controller_);
if(hwndController) KillTimer(hwndController, TimerID_Animate); if(hwnd_controller_) KillTimer(hwnd_controller_, TimerID_Animate);
isAnimating = false; is_animating_ = false;
} }
// Purge dismissed notifications and collapse the stack between // Purge dismissed notifications and collapse the stack between
// items which are highlighted // items which are highlighted
if(!instances.empty()) if(!instances_.empty())
{ {
auto isAlive = [](ToastInstance& inst) { auto isAlive = [](ToastInstance& inst) {
return inst.hwnd && IsWindowVisible(inst.hwnd); return inst.hwnd && IsWindowVisible(inst.hwnd);
@ -218,10 +218,10 @@ void DesktopNotificationController::AnimateAll()
return inst.hwnd && Toast::Get(inst.hwnd)->IsHighlighted(); return inst.hwnd && Toast::Get(inst.hwnd)->IsHighlighted();
}; };
for(auto it = instances.begin();; ++it) for(auto it = instances_.begin();; ++it)
{ {
// find next highlighted item // find next highlighted item
auto it2 = find_if(it, instances.end(), isHighlighted); auto it2 = find_if(it, instances_.end(), isHighlighted);
// collapse the stack in front of the highlighted item // collapse the stack in front of the highlighted item
it = stable_partition(it, it2, isAlive); it = stable_partition(it, it2, isAlive);
@ -229,9 +229,9 @@ void DesktopNotificationController::AnimateAll()
// purge the dead items // purge the dead items
for_each(it, it2, [this](auto&& inst) { DestroyToast(inst); }); for_each(it, it2, [this](auto&& inst) { DestroyToast(inst); });
if(it2 == instances.end()) if(it2 == instances_.end())
{ {
instances.erase(it, it2); instances_.erase(it, it2);
break; break;
} }
@ -240,13 +240,13 @@ void DesktopNotificationController::AnimateAll()
} }
// Set new toast positions // Set new toast positions
if(!instances.empty()) if(!instances_.empty())
{ {
ScreenMetrics metrics; ScreenMetrics metrics;
auto margin = metrics.Y(toastMargin<int>); auto margin = metrics.Y(toast_margin_<int>);
int targetPos = 0; int targetPos = 0;
for(auto&& inst : instances) for(auto&& inst : instances_)
{ {
if(inst.hwnd) if(inst.hwnd)
{ {
@ -271,11 +271,11 @@ DesktopNotificationController::Notification DesktopNotificationController::AddNo
NotificationLink data(this); NotificationLink data(this);
data->caption = move(caption); data->caption = move(caption);
data->bodyText = move(bodyText); data->body_text = move(bodyText);
data->image = CopyBitmap(image); data->image = CopyBitmap(image);
// Enqueue new notification // Enqueue new notification
Notification ret = *queue.insert(queue.end(), move(data)); Notification ret = *queue_.insert(queue_.end(), move(data));
CheckQueue(); CheckQueue();
return ret; return ret;
} }
@ -283,16 +283,16 @@ DesktopNotificationController::Notification DesktopNotificationController::AddNo
void DesktopNotificationController::CloseNotification(Notification& notification) void DesktopNotificationController::CloseNotification(Notification& notification)
{ {
// Remove it from the queue // Remove it from the queue
auto it = find(queue.begin(), queue.end(), notification.data); auto it = find(queue_.begin(), queue_.end(), notification.data_);
if(it != queue.end()) if(it != queue_.end())
{ {
queue.erase(it); queue_.erase(it);
this->OnNotificationClosed(notification); this->OnNotificationClosed(notification);
return; return;
} }
// Dismiss active toast // Dismiss active toast
auto hwnd = GetToast(notification.data.get()); auto hwnd = GetToast(notification.data_.get());
if(hwnd) if(hwnd)
{ {
auto toast = Toast::Get(hwnd); auto toast = Toast::Get(hwnd);
@ -302,10 +302,10 @@ void DesktopNotificationController::CloseNotification(Notification& notification
void DesktopNotificationController::CheckQueue() void DesktopNotificationController::CheckQueue()
{ {
while(instances.size() < instances.capacity() && !queue.empty()) while(instances_.size() < instances_.capacity() && !queue_.empty())
{ {
CreateToast(move(queue.front())); CreateToast(move(queue_.front()));
queue.pop_front(); queue_.pop_front();
} }
} }
@ -316,22 +316,22 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data)
if(hwnd) if(hwnd)
{ {
int toastPos = 0; int toastPos = 0;
if(!instances.empty()) if(!instances_.empty())
{ {
auto& item = instances.back(); auto& item = instances_.back();
_ASSERT(item.hwnd); _ASSERT(item.hwnd);
ScreenMetrics scr; ScreenMetrics scr;
auto toast = Toast::Get(item.hwnd); auto toast = Toast::Get(item.hwnd);
toastPos = toast->GetVerticalPosition() + toast->GetHeight() + scr.Y(toastMargin<int>); toastPos = toast->GetVerticalPosition() + toast->GetHeight() + scr.Y(toast_margin_<int>);
} }
instances.push_back({ hwnd, move(data) }); instances_.push_back({ hwnd, move(data) });
if(!hwndController) if(!hwnd_controller_)
{ {
// NOTE: We cannot use a message-only window because we need to receive system notifications // NOTE: We cannot use a message-only window because we need to receive system notifications
hwndController = CreateWindow(className, nullptr, 0, 0, 0, 0, 0, NULL, NULL, hInstance, this); hwnd_controller_ = CreateWindow(class_name_, nullptr, 0, 0, 0, 0, 0, NULL, NULL, hInstance, this);
} }
auto toast = Toast::Get(hwnd); auto toast = Toast::Get(hwnd);
@ -341,12 +341,12 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data)
HWND DesktopNotificationController::GetToast(const NotificationData* data) const HWND DesktopNotificationController::GetToast(const NotificationData* data) const
{ {
auto it = find_if(instances.cbegin(), instances.cend(), [data](auto&& inst) { auto it = find_if(instances_.cbegin(), instances_.cend(), [data](auto&& inst) {
auto toast = Toast::Get(inst.hwnd); auto toast = Toast::Get(inst.hwnd);
return data == toast->GetNotification().get(); return data == toast->GetNotification().get();
}); });
return (it != instances.cend()) ? it->hwnd : NULL; return (it != instances_.cend()) ? it->hwnd : NULL;
} }
void DesktopNotificationController::DestroyToast(ToastInstance& inst) void DesktopNotificationController::DestroyToast(ToastInstance& inst)
@ -365,41 +365,41 @@ void DesktopNotificationController::DestroyToast(ToastInstance& inst)
DesktopNotificationController::Notification::Notification(const shared_ptr<NotificationData>& data) : DesktopNotificationController::Notification::Notification(const shared_ptr<NotificationData>& data) :
data(data) data_(data)
{ {
_ASSERT(data != nullptr); _ASSERT(data != nullptr);
} }
bool DesktopNotificationController::Notification::operator==(const Notification& other) const bool DesktopNotificationController::Notification::operator==(const Notification& other) const
{ {
return data == other.data; return data_ == other.data_;
} }
void DesktopNotificationController::Notification::Close() void DesktopNotificationController::Notification::Close()
{ {
// No business calling this when not pointing to a valid instance // No business calling this when not pointing to a valid instance
_ASSERT(data); _ASSERT(data_);
if(data->controller) if(data_->controller)
data->controller->CloseNotification(*this); data_->controller->CloseNotification(*this);
} }
void DesktopNotificationController::Notification::Set(std::wstring caption, std::wstring bodyText, HBITMAP image) void DesktopNotificationController::Notification::Set(std::wstring caption, std::wstring bodyText, HBITMAP image)
{ {
// No business calling this when not pointing to a valid instance // No business calling this when not pointing to a valid instance
_ASSERT(data); _ASSERT(data_);
// Do nothing when the notification has been closed // Do nothing when the notification has been closed
if(!data->controller) if(!data_->controller)
return; return;
if(data->image) DeleteBitmap(data->image); if(data_->image) DeleteBitmap(data_->image);
data->caption = move(caption); data_->caption = move(caption);
data->bodyText = move(bodyText); data_->body_text = move(bodyText);
data->image = CopyBitmap(image); data_->image = CopyBitmap(image);
auto hwnd = data->controller->GetToast(data.get()); auto hwnd = data_->controller->GetToast(data_.get());
if(hwnd) if(hwnd)
{ {
auto toast = Toast::Get(hwnd); auto toast = Toast::Get(hwnd);
@ -407,7 +407,7 @@ void DesktopNotificationController::Notification::Set(std::wstring caption, std:
} }
// Change of contents can affect size and position of all toasts // Change of contents can affect size and position of all toasts
data->controller->StartAnimation(); data_->controller->StartAnimation();
} }

View file

@ -37,7 +37,7 @@ private:
}; };
template<typename T> template<typename T>
static constexpr T toastMargin = 20; static constexpr T toast_margin_ = 20;
// Wrapper around `NotificationData` which makes sure that // Wrapper around `NotificationData` which makes sure that
// the `controller` member is cleared when the controller object // the `controller` member is cleared when the controller object
@ -75,12 +75,12 @@ private:
void DestroyToast(ToastInstance& inst); void DestroyToast(ToastInstance& inst);
private: private:
static constexpr const TCHAR className[] = TEXT("DesktopNotificationController"); static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationController");
HWND hwndController = NULL; HWND hwnd_controller_ = NULL;
HFONT captionFont = NULL, bodyFont = NULL; HFONT caption_font_ = NULL, body_font_ = NULL;
std::vector<ToastInstance> instances; std::vector<ToastInstance> instances_;
std::deque<NotificationLink> queue; std::deque<NotificationLink> queue_;
bool isAnimating = false; bool is_animating_ = false;
}; };
class DesktopNotificationController::Notification class DesktopNotificationController::Notification
@ -95,7 +95,7 @@ public:
void Set(std::wstring caption, std::wstring bodyText, HBITMAP image); void Set(std::wstring caption, std::wstring bodyText, HBITMAP image);
private: private:
std::shared_ptr<NotificationData> data; std::shared_ptr<NotificationData> data_;
friend class DesktopNotificationController; friend class DesktopNotificationController;
}; };

View file

@ -167,25 +167,25 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height)
} }
DesktopNotificationController::Toast::Toast(HWND hWnd, shared_ptr<NotificationData>* data) : DesktopNotificationController::Toast::Toast(HWND hWnd, shared_ptr<NotificationData>* data) :
hWnd(hWnd), data(*data) hwnd_(hWnd), data_(*data)
{ {
HDC hdcScreen = GetDC(NULL); HDC hdcScreen = GetDC(NULL);
hdc = CreateCompatibleDC(hdcScreen); hdc_ = CreateCompatibleDC(hdcScreen);
ReleaseDC(NULL, hdcScreen); ReleaseDC(NULL, hdcScreen);
} }
DesktopNotificationController::Toast::~Toast() DesktopNotificationController::Toast::~Toast()
{ {
DeleteDC(hdc); DeleteDC(hdc_);
if(bitmap) DeleteBitmap(bitmap); if(bitmap_) DeleteBitmap(bitmap_);
if(scaledImage) DeleteBitmap(scaledImage); if(scaled_image_) DeleteBitmap(scaled_image_);
} }
void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) void DesktopNotificationController::Toast::Register(HINSTANCE hInstance)
{ {
WNDCLASSEX wc = { sizeof(wc) }; WNDCLASSEX wc = { sizeof(wc) };
wc.lpfnWndProc = &Toast::WndProc; wc.lpfnWndProc = &Toast::WndProc;
wc.lpszClassName = className; wc.lpszClassName = class_name_;
wc.cbWndExtra = sizeof(Toast*); wc.cbWndExtra = sizeof(Toast*);
wc.hInstance = hInstance; wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hCursor = LoadCursor(NULL, IDC_ARROW);
@ -226,29 +226,29 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W
inst->Dismiss(); inst->Dismiss();
Notification notification(inst->data); Notification notification(inst->data_);
if(inst->isCloseHot) if(inst->is_close_hot_)
inst->data->controller->OnNotificationDismissed(notification); inst->data_->controller->OnNotificationDismissed(notification);
else else
inst->data->controller->OnNotificationClicked(notification); inst->data_->controller->OnNotificationClicked(notification);
} }
return 0; return 0;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
{ {
auto inst = Get(hWnd); auto inst = Get(hWnd);
if(!inst->isHighlighted) if(!inst->is_highlighted_)
{ {
inst->isHighlighted = true; inst->is_highlighted_ = true;
TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hWnd }; TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hWnd };
TrackMouseEvent(&tme); TrackMouseEvent(&tme);
} }
POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
inst->isCloseHot = (PtInRect(&inst->closeButtonRect, cursor) != FALSE); inst->is_close_hot_ = (PtInRect(&inst->close_button_rect_, cursor) != FALSE);
if(!inst->isNonInteractive) if(!inst->is_non_interactive_)
inst->CancelDismiss(); inst->CancelDismiss();
inst->UpdateContents(); inst->UpdateContents();
@ -258,15 +258,15 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W
case WM_MOUSELEAVE: case WM_MOUSELEAVE:
{ {
auto inst = Get(hWnd); auto inst = Get(hWnd);
inst->isHighlighted = false; inst->is_highlighted_ = false;
inst->isCloseHot = false; inst->is_close_hot_ = false;
inst->UpdateContents(); inst->UpdateContents();
if(!inst->easeOutActive && inst->easeInPos == 1.0f) if(!inst->ease_out_active_ && inst->ease_in_pos_ == 1.0f)
inst->ScheduleDismissal(); inst->ScheduleDismissal();
// Make sure stack collapse happens if needed // Make sure stack collapse happens if needed
inst->data->controller->StartAnimation(); inst->data_->controller->StartAnimation();
} }
return 0; return 0;
@ -276,7 +276,7 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W
if(wp->flags & SWP_HIDEWINDOW) if(wp->flags & SWP_HIDEWINDOW)
{ {
if(!IsWindowVisible(hWnd)) if(!IsWindowVisible(hWnd))
Get(hWnd)->isHighlighted = false; Get(hWnd)->is_highlighted_ = false;
} }
} }
break; break;
@ -287,7 +287,7 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W
HWND DesktopNotificationController::Toast::Create(HINSTANCE hInstance, shared_ptr<NotificationData>& data) HWND DesktopNotificationController::Toast::Create(HINSTANCE hInstance, shared_ptr<NotificationData>& data)
{ {
return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, className, nullptr, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, &data); return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, class_name_, nullptr, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, &data);
} }
void DesktopNotificationController::Toast::Draw() void DesktopNotificationController::Toast::Draw()
@ -299,7 +299,7 @@ void DesktopNotificationController::Toast::Draw()
// base background color is 2/3 of accent // base background color is 2/3 of accent
// highlighted adds a bit of intensity to every channel // highlighted adds a bit of intensity to every channel
int h = isHighlighted ? (0xff / 20) : 0; int h = is_highlighted_ ? (0xff / 20) : 0;
backColor = RGB(min(0xff, (GetRValue(accent) * 2 / 3) + h), backColor = RGB(min(0xff, (GetRValue(accent) * 2 / 3) + h),
min(0xff, (GetGValue(accent) * 2 / 3) + h), min(0xff, (GetGValue(accent) * 2 / 3) + h),
@ -347,55 +347,55 @@ void DesktopNotificationController::Toast::Draw()
{ {
auto brush = CreateSolidBrush(backColor); auto brush = CreateSolidBrush(backColor);
RECT rc = { 0, 0, toastSize.cx, toastSize.cy }; RECT rc = { 0, 0, toast_size_.cx, toast_size_.cy };
FillRect(hdc, &rc, brush); FillRect(hdc_, &rc, brush);
DeleteBrush(brush); DeleteBrush(brush);
} }
SetBkMode(hdc, TRANSPARENT); SetBkMode(hdc_, TRANSPARENT);
const auto close = L'\x2715'; const auto close = L'\x2715';
auto captionFont = data->controller->GetCaptionFont(); auto captionFont = data_->controller->GetCaptionFont();
auto bodyFont = data->controller->GetBodyFont(); auto bodyFont = data_->controller->GetBodyFont();
TEXTMETRIC tmCap; TEXTMETRIC tmCap;
SelectFont(hdc, captionFont); SelectFont(hdc_, captionFont);
GetTextMetrics(hdc, &tmCap); GetTextMetrics(hdc_, &tmCap);
auto textOffsetX = margin.cx; auto textOffsetX = margin_.cx;
BITMAP imageInfo = {}; BITMAP imageInfo = {};
if(scaledImage) if(scaled_image_)
{ {
GetObject(scaledImage, sizeof(imageInfo), &imageInfo); GetObject(scaled_image_, sizeof(imageInfo), &imageInfo);
textOffsetX += margin.cx + imageInfo.bmWidth; textOffsetX += margin_.cx + imageInfo.bmWidth;
} }
// calculate close button rect // calculate close button rect
POINT closePos; POINT closePos;
{ {
SIZE extent = {}; SIZE extent = {};
GetTextExtentPoint32W(hdc, &close, 1, &extent); GetTextExtentPoint32W(hdc_, &close, 1, &extent);
closeButtonRect.right = toastSize.cx; close_button_rect_.right = toast_size_.cx;
closeButtonRect.top = 0; close_button_rect_.top = 0;
closePos.x = closeButtonRect.right - margin.cy - extent.cx; closePos.x = close_button_rect_.right - margin_.cy - extent.cx;
closePos.y = closeButtonRect.top + margin.cy; closePos.y = close_button_rect_.top + margin_.cy;
closeButtonRect.left = closePos.x - margin.cy; close_button_rect_.left = closePos.x - margin_.cy;
closeButtonRect.bottom = closePos.y + extent.cy + margin.cy; close_button_rect_.bottom = closePos.y + extent.cy + margin_.cy;
} }
// image // image
if(scaledImage) if(scaled_image_)
{ {
HDC hdcImage = CreateCompatibleDC(NULL); HDC hdcImage = CreateCompatibleDC(NULL);
SelectBitmap(hdcImage, scaledImage); SelectBitmap(hdcImage, scaled_image_);
BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
AlphaBlend(hdc, margin.cx, margin.cy, imageInfo.bmWidth, imageInfo.bmHeight, hdcImage, 0, 0, imageInfo.bmWidth, imageInfo.bmHeight, blend); AlphaBlend(hdc_, margin_.cx, margin_.cy, imageInfo.bmWidth, imageInfo.bmHeight, hdcImage, 0, 0, imageInfo.bmWidth, imageInfo.bmHeight, blend);
DeleteDC(hdcImage); DeleteDC(hdcImage);
} }
@ -403,85 +403,85 @@ void DesktopNotificationController::Toast::Draw()
{ {
RECT rc = { RECT rc = {
textOffsetX, textOffsetX,
margin.cy, margin_.cy,
closeButtonRect.left, close_button_rect_.left,
toastSize.cy toast_size_.cy
}; };
SelectFont(hdc, captionFont); SelectFont(hdc_, captionFont);
SetTextColor(hdc, foreColor); SetTextColor(hdc_, foreColor);
DrawText(hdc, data->caption.data(), (UINT)data->caption.length(), &rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); DrawText(hdc_, data_->caption.data(), (UINT)data_->caption.length(), &rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX);
} }
// body text // body text
if(!data->bodyText.empty()) if(!data_->body_text.empty())
{ {
RECT rc = { RECT rc = {
textOffsetX, textOffsetX,
2 * margin.cy + tmCap.tmAscent, 2 * margin_.cy + tmCap.tmAscent,
toastSize.cx - margin.cx, toast_size_.cx - margin_.cx,
toastSize.cy - margin.cy toast_size_.cy - margin_.cy
}; };
SelectFont(hdc, bodyFont); SelectFont(hdc_, bodyFont);
SetTextColor(hdc, dimmedColor); SetTextColor(hdc_, dimmedColor);
DrawText(hdc, data->bodyText.data(), (UINT)data->bodyText.length(), &rc, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS | DT_EDITCONTROL); DrawText(hdc_, data_->body_text.data(), (UINT)data_->body_text.length(), &rc, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS | DT_EDITCONTROL);
} }
// close button // close button
{ {
SelectFont(hdc, captionFont); SelectFont(hdc_, captionFont);
SetTextColor(hdc, isCloseHot ? foreColor : dimmedColor); SetTextColor(hdc_, is_close_hot_ ? foreColor : dimmedColor);
ExtTextOut(hdc, closePos.x, closePos.y, 0, nullptr, &close, 1, nullptr); ExtTextOut(hdc_, closePos.x, closePos.y, 0, nullptr, &close, 1, nullptr);
} }
isContentUpdated = true; is_content_updated_ = true;
} }
void DesktopNotificationController::Toast::Invalidate() void DesktopNotificationController::Toast::Invalidate()
{ {
isContentUpdated = false; is_content_updated_ = false;
} }
bool DesktopNotificationController::Toast::IsRedrawNeeded() const bool DesktopNotificationController::Toast::IsRedrawNeeded() const
{ {
return !isContentUpdated; return !is_content_updated_;
} }
void DesktopNotificationController::Toast::UpdateBufferSize() void DesktopNotificationController::Toast::UpdateBufferSize()
{ {
if(hdc) if(hdc_)
{ {
SIZE newSize; SIZE newSize;
{ {
TEXTMETRIC tmCap = {}; TEXTMETRIC tmCap = {};
HFONT font = data->controller->GetCaptionFont(); HFONT font = data_->controller->GetCaptionFont();
if(font) if(font)
{ {
SelectFont(hdc, font); SelectFont(hdc_, font);
if(!GetTextMetrics(hdc, &tmCap)) return; if(!GetTextMetrics(hdc_, &tmCap)) return;
} }
TEXTMETRIC tmBody = {}; TEXTMETRIC tmBody = {};
font = data->controller->GetBodyFont(); font = data_->controller->GetBodyFont();
if(font) if(font)
{ {
SelectFont(hdc, font); SelectFont(hdc_, font);
if(!GetTextMetrics(hdc, &tmBody)) return; if(!GetTextMetrics(hdc_, &tmBody)) return;
} }
this->margin = { tmCap.tmAveCharWidth * 2, tmCap.tmAscent / 2 }; this->margin_ = { tmCap.tmAveCharWidth * 2, tmCap.tmAscent / 2 };
newSize.cx = margin.cx + (32 * tmCap.tmAveCharWidth) + margin.cx; newSize.cx = margin_.cx + (32 * tmCap.tmAveCharWidth) + margin_.cx;
newSize.cy = margin.cy + (tmCap.tmHeight) + margin.cy; newSize.cy = margin_.cy + (tmCap.tmHeight) + margin_.cy;
if(!data->bodyText.empty()) if(!data_->body_text.empty())
newSize.cy += margin.cy + (3 * tmBody.tmHeight); newSize.cy += margin_.cy + (3 * tmBody.tmHeight);
if(data->image) if(data_->image)
{ {
BITMAP bm; BITMAP bm;
if(GetObject(data->image, sizeof(bm), &bm)) if(GetObject(data_->image, sizeof(bm), &bm))
{ {
// cap the image size // cap the image size
const int maxDimSize = 80; const int maxDimSize = 80;
@ -508,9 +508,9 @@ void DesktopNotificationController::Toast::UpdateBufferSize()
ScreenMetrics scr; ScreenMetrics scr;
SIZE imageDrawSize = { scr.X(width), scr.Y(height) }; SIZE imageDrawSize = { scr.X(width), scr.Y(height) };
newSize.cx += imageDrawSize.cx + margin.cx; newSize.cx += imageDrawSize.cx + margin_.cx;
auto heightWithImage = margin.cy + (imageDrawSize.cy) + margin.cy; auto heightWithImage = margin_.cy + (imageDrawSize.cy) + margin_.cy;
if(newSize.cy < heightWithImage) newSize.cy = heightWithImage; if(newSize.cy < heightWithImage) newSize.cy = heightWithImage;
UpdateScaledImage(imageDrawSize); UpdateScaledImage(imageDrawSize);
@ -518,7 +518,7 @@ void DesktopNotificationController::Toast::UpdateBufferSize()
} }
} }
if(newSize.cx != this->toastSize.cx || newSize.cy != this->toastSize.cy) if(newSize.cx != this->toast_size_.cx || newSize.cy != this->toast_size_.cy)
{ {
HDC hdcScreen = GetDC(NULL); HDC hdcScreen = GetDC(NULL);
auto newBitmap = CreateCompatibleBitmap(hdcScreen, newSize.cx, newSize.cy); auto newBitmap = CreateCompatibleBitmap(hdcScreen, newSize.cx, newSize.cy);
@ -526,15 +526,15 @@ void DesktopNotificationController::Toast::UpdateBufferSize()
if(newBitmap) if(newBitmap)
{ {
if(SelectBitmap(hdc, newBitmap)) if(SelectBitmap(hdc_, newBitmap))
{ {
RECT dirty1 = {}, dirty2 = {}; RECT dirty1 = {}, dirty2 = {};
if(toastSize.cx < newSize.cx) dirty1 = { toastSize.cx, 0, newSize.cx, toastSize.cy }; if(toast_size_.cx < newSize.cx) dirty1 = { toast_size_.cx, 0, newSize.cx, toast_size_.cy };
if(toastSize.cy < newSize.cy) dirty2 = { 0, toastSize.cy, newSize.cx, newSize.cy }; if(toast_size_.cy < newSize.cy) dirty2 = { 0, toast_size_.cy, newSize.cx, newSize.cy };
if(this->bitmap) DeleteBitmap(this->bitmap); if(this->bitmap_) DeleteBitmap(this->bitmap_);
this->bitmap = newBitmap; this->bitmap_ = newBitmap;
this->toastSize = newSize; this->toast_size_ = newSize;
Invalidate(); Invalidate();
@ -547,16 +547,16 @@ void DesktopNotificationController::Toast::UpdateBufferSize()
ulw.cbSize = sizeof(ulw); ulw.cbSize = sizeof(ulw);
ulw.hdcDst = NULL; ulw.hdcDst = NULL;
ulw.pptDst = nullptr; ulw.pptDst = nullptr;
ulw.psize = &toastSize; ulw.psize = &toast_size_;
ulw.hdcSrc = hdc; ulw.hdcSrc = hdc_;
ulw.pptSrc = &origin; ulw.pptSrc = &origin;
ulw.crKey = 0; ulw.crKey = 0;
ulw.pblend = nullptr; ulw.pblend = nullptr;
ulw.dwFlags = 0; ulw.dwFlags = 0;
ulw.prcDirty = &dirty1; ulw.prcDirty = &dirty1;
auto b1 = UpdateLayeredWindowIndirect(hWnd, &ulw); auto b1 = UpdateLayeredWindowIndirect(hwnd_, &ulw);
ulw.prcDirty = &dirty2; ulw.prcDirty = &dirty2;
auto b2 = UpdateLayeredWindowIndirect(hWnd, &ulw); auto b2 = UpdateLayeredWindowIndirect(hwnd_, &ulw);
_ASSERT(b1 && b2); _ASSERT(b1 && b2);
} }
@ -572,12 +572,12 @@ void DesktopNotificationController::Toast::UpdateBufferSize()
void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size) void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size)
{ {
BITMAP bm; BITMAP bm;
if(!GetObject(scaledImage, sizeof(bm), &bm) || if(!GetObject(scaled_image_, sizeof(bm), &bm) ||
bm.bmWidth != size.cx || bm.bmWidth != size.cx ||
bm.bmHeight != size.cy) bm.bmHeight != size.cy)
{ {
if(scaledImage) DeleteBitmap(scaledImage); if(scaled_image_) DeleteBitmap(scaled_image_);
scaledImage = StretchBitmap(data->image, size.cx, size.cy); scaled_image_ = StretchBitmap(data_->image, size.cx, size.cy);
} }
} }
@ -585,24 +585,24 @@ void DesktopNotificationController::Toast::UpdateContents()
{ {
Draw(); Draw();
if(IsWindowVisible(hWnd)) if(IsWindowVisible(hwnd_))
{ {
RECT rc; RECT rc;
GetWindowRect(hWnd, &rc); GetWindowRect(hwnd_, &rc);
POINT origin = { 0, 0 }; POINT origin = { 0, 0 };
SIZE size = { rc.right - rc.left, rc.bottom - rc.top }; SIZE size = { rc.right - rc.left, rc.bottom - rc.top };
UpdateLayeredWindow(hWnd, NULL, nullptr, &size, hdc, &origin, 0, nullptr, 0); UpdateLayeredWindow(hwnd_, NULL, nullptr, &size, hdc_, &origin, 0, nullptr, 0);
} }
} }
void DesktopNotificationController::Toast::Dismiss() void DesktopNotificationController::Toast::Dismiss()
{ {
if(!isNonInteractive) if(!is_non_interactive_)
{ {
// Set a flag to prevent further interaction. We don't disable the HWND because // Set a flag to prevent further interaction. We don't disable the HWND because
// we still want to receive mouse move messages in order to keep the toast under // we still want to receive mouse move messages in order to keep the toast under
// the cursor and not collapse it while dismissing. // the cursor and not collapse it while dismissing.
isNonInteractive = true; is_non_interactive_ = true;
AutoDismiss(); AutoDismiss();
} }
@ -610,28 +610,28 @@ void DesktopNotificationController::Toast::Dismiss()
void DesktopNotificationController::Toast::AutoDismiss() void DesktopNotificationController::Toast::AutoDismiss()
{ {
KillTimer(hWnd, TimerID_AutoDismiss); KillTimer(hwnd_, TimerID_AutoDismiss);
StartEaseOut(); StartEaseOut();
} }
void DesktopNotificationController::Toast::CancelDismiss() void DesktopNotificationController::Toast::CancelDismiss()
{ {
KillTimer(hWnd, TimerID_AutoDismiss); KillTimer(hwnd_, TimerID_AutoDismiss);
easeOutActive = false; ease_out_active_ = false;
easeOutPos = 0; ease_out_pos_ = 0;
} }
void DesktopNotificationController::Toast::ScheduleDismissal() void DesktopNotificationController::Toast::ScheduleDismissal()
{ {
SetTimer(hWnd, TimerID_AutoDismiss, 4000, nullptr); SetTimer(hwnd_, TimerID_AutoDismiss, 4000, nullptr);
} }
void DesktopNotificationController::Toast::ResetContents() void DesktopNotificationController::Toast::ResetContents()
{ {
if(scaledImage) if(scaled_image_)
{ {
DeleteBitmap(scaledImage); DeleteBitmap(scaled_image_);
scaledImage = NULL; scaled_image_ = NULL;
} }
Invalidate(); Invalidate();
@ -639,23 +639,23 @@ void DesktopNotificationController::Toast::ResetContents()
void DesktopNotificationController::Toast::PopUp(int y) void DesktopNotificationController::Toast::PopUp(int y)
{ {
verticalPosTarget = verticalPos = y; vertical_pos_target_ = vertical_pos_ = y;
StartEaseIn(); StartEaseIn();
} }
void DesktopNotificationController::Toast::SetVerticalPosition(int y) void DesktopNotificationController::Toast::SetVerticalPosition(int y)
{ {
// Don't restart animation if current target is the same // Don't restart animation if current target is the same
if(y == verticalPosTarget) if(y == vertical_pos_target_)
return; return;
// Make sure the new animation's origin is at the current position // Make sure the new animation's origin is at the current position
verticalPos += (int)((verticalPosTarget - verticalPos) * stackCollapsePos); vertical_pos_ += (int)((vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_);
// Set new target position and start the animation // Set new target position and start the animation
verticalPosTarget = y; vertical_pos_target_ = y;
stackCollapseStart = GetTickCount(); stack_collapse_start_ = GetTickCount();
data->controller->StartAnimation(); data_->controller->StartAnimation();
} }
HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origin) HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origin)
@ -672,7 +672,7 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi
ulw.hdcDst = NULL; ulw.hdcDst = NULL;
ulw.pptDst = nullptr; ulw.pptDst = nullptr;
ulw.psize = nullptr; ulw.psize = nullptr;
ulw.hdcSrc = hdc; ulw.hdcSrc = hdc_;
ulw.pptSrc = &srcOrigin; ulw.pptSrc = &srcOrigin;
ulw.crKey = 0; ulw.crKey = 0;
ulw.pblend = nullptr; ulw.pblend = nullptr;
@ -688,27 +688,27 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi
auto easeOutPos = AnimateEaseOut(); auto easeOutPos = AnimateEaseOut();
auto stackCollapsePos = AnimateStackCollapse(); auto stackCollapsePos = AnimateStackCollapse();
auto yOffset = (verticalPosTarget - verticalPos) * stackCollapsePos; auto yOffset = (vertical_pos_target_ - vertical_pos_) * stackCollapsePos;
size.cx = (int)(toastSize.cx * easeInPos); size.cx = (int)(toast_size_.cx * easeInPos);
size.cy = toastSize.cy; size.cy = toast_size_.cy;
pt.x = origin.x - size.cx; pt.x = origin.x - size.cx;
pt.y = (int)(origin.y - verticalPos - yOffset - size.cy); pt.y = (int)(origin.y - vertical_pos_ - yOffset - size.cy);
ulw.pptDst = &pt; ulw.pptDst = &pt;
ulw.psize = &size; ulw.psize = &size;
if(easeInActive && easeInPos == 1.0f) if(ease_in_active_ && easeInPos == 1.0f)
{ {
easeInActive = false; ease_in_active_ = false;
ScheduleDismissal(); ScheduleDismissal();
} }
this->easeInPos = easeInPos; this->ease_in_pos_ = easeInPos;
this->stackCollapsePos = stackCollapsePos; this->stack_collapse_pos_ = stackCollapsePos;
if(easeOutPos != this->easeOutPos) if(easeOutPos != this->ease_out_pos_)
{ {
blend.BlendOp = AC_SRC_OVER; blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0; blend.BlendFlags = 0;
@ -718,11 +718,11 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi
ulw.pblend = &blend; ulw.pblend = &blend;
ulw.dwFlags = ULW_ALPHA; ulw.dwFlags = ULW_ALPHA;
this->easeOutPos = easeOutPos; this->ease_out_pos_ = easeOutPos;
if(easeOutPos == 1.0f) if(easeOutPos == 1.0f)
{ {
easeOutActive = false; ease_out_active_ = false;
dwpFlags &= ~SWP_SHOWWINDOW; dwpFlags &= ~SWP_SHOWWINDOW;
dwpFlags |= SWP_HIDEWINDOW; dwpFlags |= SWP_HIDEWINDOW;
@ -731,46 +731,46 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi
if(stackCollapsePos == 1.0f) if(stackCollapsePos == 1.0f)
{ {
verticalPos = verticalPosTarget; vertical_pos_ = vertical_pos_target_;
} }
// `UpdateLayeredWindowIndirect` updates position, size, and transparency. // `UpdateLayeredWindowIndirect` updates position, size, and transparency.
// `DeferWindowPos` updates z-order, and also position and size in case ULWI fails, // `DeferWindowPos` updates z-order, and also position and size in case ULWI fails,
// which can happen when one of the dimensions is zero (e.g. at the beginning of ease-in). // which can happen when one of the dimensions is zero (e.g. at the beginning of ease-in).
auto ulwResult = UpdateLayeredWindowIndirect(hWnd, &ulw); auto ulwResult = UpdateLayeredWindowIndirect(hwnd_, &ulw);
hdwp = DeferWindowPos(hdwp, hWnd, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, dwpFlags); hdwp = DeferWindowPos(hdwp, hwnd_, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, dwpFlags);
return hdwp; return hdwp;
} }
void DesktopNotificationController::Toast::StartEaseIn() void DesktopNotificationController::Toast::StartEaseIn()
{ {
_ASSERT(!easeInActive); _ASSERT(!ease_in_active_);
easeInStart = GetTickCount(); ease_in_start_ = GetTickCount();
easeInActive = true; ease_in_active_ = true;
data->controller->StartAnimation(); data_->controller->StartAnimation();
} }
void DesktopNotificationController::Toast::StartEaseOut() void DesktopNotificationController::Toast::StartEaseOut()
{ {
_ASSERT(!easeOutActive); _ASSERT(!ease_out_active_);
easeOutStart = GetTickCount(); ease_out_start_ = GetTickCount();
easeOutActive = true; ease_out_active_ = true;
data->controller->StartAnimation(); data_->controller->StartAnimation();
} }
bool DesktopNotificationController::Toast::IsStackCollapseActive() const bool DesktopNotificationController::Toast::IsStackCollapseActive() const
{ {
return (verticalPos != verticalPosTarget); return (vertical_pos_ != vertical_pos_target_);
} }
float DesktopNotificationController::Toast::AnimateEaseIn() float DesktopNotificationController::Toast::AnimateEaseIn()
{ {
if(!easeInActive) if(!ease_in_active_)
return easeInPos; return ease_in_pos_;
constexpr float duration = 500.0f; constexpr float duration = 500.0f;
float time = std::min(duration, (float)(GetTickCount() - easeInStart)) / duration; float time = std::min(duration, (float)(GetTickCount() - ease_in_start_)) / duration;
// decelerating exponential ease // decelerating exponential ease
const float a = -8.0f; const float a = -8.0f;
@ -781,11 +781,11 @@ float DesktopNotificationController::Toast::AnimateEaseIn()
float DesktopNotificationController::Toast::AnimateEaseOut() float DesktopNotificationController::Toast::AnimateEaseOut()
{ {
if(!easeOutActive) if(!ease_out_active_)
return easeOutPos; return ease_out_pos_;
constexpr float duration = 120.0f; constexpr float duration = 120.0f;
float time = std::min(duration, (float)(GetTickCount() - easeOutStart)) / duration; float time = std::min(duration, (float)(GetTickCount() - ease_out_start_)) / duration;
// accelerating circle ease // accelerating circle ease
auto pos = 1.0f - std::sqrt(1 - time * time); auto pos = 1.0f - std::sqrt(1 - time * time);
@ -796,10 +796,10 @@ float DesktopNotificationController::Toast::AnimateEaseOut()
float DesktopNotificationController::Toast::AnimateStackCollapse() float DesktopNotificationController::Toast::AnimateStackCollapse()
{ {
if(!IsStackCollapseActive()) if(!IsStackCollapseActive())
return stackCollapsePos; return stack_collapse_pos_;
constexpr float duration = 500.0f; constexpr float duration = 500.0f;
float time = std::min(duration, (float)(GetTickCount() - stackCollapseStart)) / duration; float time = std::min(duration, (float)(GetTickCount() - stack_collapse_start_)) / duration;
// decelerating exponential ease // decelerating exponential ease
const float a = -8.0f; const float a = -8.0f;

View file

@ -17,7 +17,7 @@ public:
const std::shared_ptr<NotificationData>& GetNotification() const const std::shared_ptr<NotificationData>& GetNotification() const
{ {
return data; return data_;
} }
void ResetContents(); void ResetContents();
@ -28,21 +28,21 @@ public:
void SetVerticalPosition(int y); void SetVerticalPosition(int y);
int GetVerticalPosition() const int GetVerticalPosition() const
{ {
return verticalPosTarget; return vertical_pos_target_;
} }
int GetHeight() const int GetHeight() const
{ {
return toastSize.cy; return toast_size_.cy;
} }
HDWP Animate(HDWP hdwp, const POINT& origin); HDWP Animate(HDWP hdwp, const POINT& origin);
bool IsAnimationActive() const bool IsAnimationActive() const
{ {
return easeInActive || easeOutActive || IsStackCollapseActive(); return ease_in_active_ || ease_out_active_ || IsStackCollapseActive();
} }
bool IsHighlighted() const bool IsHighlighted() const
{ {
_ASSERT(!(isHighlighted && !IsWindowVisible(hWnd))); _ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_)));
return isHighlighted; return is_highlighted_;
} }
private: private:
@ -73,27 +73,27 @@ private:
float AnimateStackCollapse(); float AnimateStackCollapse();
private: private:
static constexpr const TCHAR className[] = TEXT("DesktopNotificationToast"); static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationToast");
const HWND hWnd; const HWND hwnd_;
HDC hdc; HDC hdc_;
HBITMAP bitmap = NULL; HBITMAP bitmap_ = NULL;
const std::shared_ptr<NotificationData> data; // never null const std::shared_ptr<NotificationData> data_; // never null
SIZE toastSize = {}; SIZE toast_size_ = {};
SIZE margin = {}; SIZE margin_ = {};
RECT closeButtonRect = {}; RECT close_button_rect_ = {};
HBITMAP scaledImage = NULL; HBITMAP scaled_image_ = NULL;
int verticalPos = 0; int vertical_pos_ = 0;
int verticalPosTarget = 0; int vertical_pos_target_ = 0;
bool isNonInteractive = false; bool is_non_interactive_ = false;
bool easeInActive = false; bool ease_in_active_ = false;
bool easeOutActive = false; bool ease_out_active_ = false;
bool isContentUpdated = false, isHighlighted = false, isCloseHot = false; bool is_content_updated_ = false, is_highlighted_ = false, is_close_hot_ = false;
DWORD easeInStart, easeOutStart, stackCollapseStart; DWORD ease_in_start_, ease_out_start_, stack_collapse_start_;
float easeInPos = 0, easeOutPos = 0, stackCollapsePos = 0; float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0;
}; };
} }

View file

@ -38,23 +38,23 @@ void Win32Notification::Show(const base::string16& title, const base::string16&
if(existing) if(existing)
{ {
existing->tag.clear(); existing->tag_.clear();
this->notificationRef = std::move(existing->notificationRef); this->notification_ref_ = std::move(existing->notification_ref_);
this->notificationRef.Set(title, msg, image); this->notification_ref_.Set(title, msg, image);
} }
else else
{ {
this->notificationRef = presenter->AddNotification(title, msg, image); this->notification_ref_ = presenter->AddNotification(title, msg, image);
} }
this->tag = tag; this->tag_ = tag;
if(image) DeleteObject(image); if(image) DeleteObject(image);
} }
void Win32Notification::Dismiss() void Win32Notification::Dismiss()
{ {
notificationRef.Close(); notification_ref_.Close();
} }
} }

View file

@ -13,18 +13,18 @@ public:
const DesktopNotificationController::Notification& GetRef() const const DesktopNotificationController::Notification& GetRef() const
{ {
return notificationRef; return notification_ref_;
} }
const std::string& GetTag() const const std::string& GetTag() const
{ {
return tag; return tag_;
} }
private: private:
DISALLOW_COPY_AND_ASSIGN(Win32Notification); DISALLOW_COPY_AND_ASSIGN(Win32Notification);
DesktopNotificationController::Notification notificationRef; DesktopNotificationController::Notification notification_ref_;
std::string tag; std::string tag_;
}; };
} }