win: Implement tray.getBounds() API

This commit is contained in:
Cheng Zhao 2016-06-21 15:49:22 +09:00
parent db98e256f2
commit 886ef1717c
2 changed files with 17 additions and 11 deletions

View file

@ -48,26 +48,19 @@ NotifyIcon::~NotifyIcon() {
void NotifyIcon::HandleClickEvent(int modifiers,
bool left_mouse_click,
bool double_button_click) {
NOTIFYICONIDENTIFIER icon_id;
memset(&icon_id, 0, sizeof(NOTIFYICONIDENTIFIER));
icon_id.uID = icon_id_;
icon_id.hWnd = window_;
icon_id.cbSize = sizeof(NOTIFYICONIDENTIFIER);
RECT rect = { 0 };
Shell_NotifyIconGetRect(&icon_id, &rect);
gfx::Rect bounds = GetBounds();
if (left_mouse_click) {
if (double_button_click) // double left click
NotifyDoubleClicked(gfx::Rect(rect), modifiers);
NotifyDoubleClicked(bounds, modifiers);
else // single left click
NotifyClicked(gfx::Rect(rect), modifiers);
NotifyClicked(bounds, modifiers);
return;
} else if (!double_button_click) { // single right click
if (menu_model_)
PopUpContextMenu(gfx::Point(), menu_model_);
else
NotifyRightClicked(gfx::Rect(rect), modifiers);
NotifyRightClicked(bounds, modifiers);
}
}
@ -163,6 +156,18 @@ void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
menu_model_ = menu_model;
}
gfx::Rect NotifyIcon::GetBounds() {
NOTIFYICONIDENTIFIER icon_id;
memset(&icon_id, 0, sizeof(NOTIFYICONIDENTIFIER));
icon_id.uID = icon_id_;
icon_id.hWnd = window_;
icon_id.cbSize = sizeof(NOTIFYICONIDENTIFIER);
RECT rect = { 0 };
Shell_NotifyIconGetRect(&icon_id, &rect);
return gfx::Rect(rect);
}
void NotifyIcon::InitIconData(NOTIFYICONDATA* icon_data) {
memset(icon_data, 0, sizeof(NOTIFYICONDATA));
icon_data->cbSize = sizeof(NOTIFYICONDATA);

View file

@ -54,6 +54,7 @@ class NotifyIcon : public TrayIcon {
void PopUpContextMenu(const gfx::Point& pos,
ui::SimpleMenuModel* menu_model) override;
void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
gfx::Rect GetBounds() override;
private:
void InitIconData(NOTIFYICONDATA* icon_data);