win: Implement menu parameter
This commit is contained in:
parent
3cdd0f35c7
commit
615ce45849
3 changed files with 12 additions and 16 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
#include "ui/gfx/geometry/point.h"
|
#include "ui/gfx/geometry/point.h"
|
||||||
#include "ui/gfx/geometry/rect.h"
|
#include "ui/gfx/geometry/rect.h"
|
||||||
|
#include "ui/gfx/screen.h"
|
||||||
#include "ui/views/controls/menu/menu_runner.h"
|
#include "ui/views/controls/menu/menu_runner.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -45,8 +46,7 @@ NotifyIcon::~NotifyIcon() {
|
||||||
Shell_NotifyIcon(NIM_DELETE, &icon_data);
|
Shell_NotifyIcon(NIM_DELETE, &icon_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
|
void NotifyIcon::HandleClickEvent(int modifiers,
|
||||||
int modifiers,
|
|
||||||
bool left_mouse_click,
|
bool left_mouse_click,
|
||||||
bool double_button_click) {
|
bool double_button_click) {
|
||||||
NOTIFYICONIDENTIFIER icon_id;
|
NOTIFYICONIDENTIFIER icon_id;
|
||||||
|
@ -66,7 +66,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
|
||||||
return;
|
return;
|
||||||
} else if (!double_button_click) { // single right click
|
} else if (!double_button_click) { // single right click
|
||||||
if (menu_model_)
|
if (menu_model_)
|
||||||
PopUpContextMenu(cursor_pos, menu_model_);
|
PopUpContextMenu(gfx::Point(), menu_model_);
|
||||||
else
|
else
|
||||||
NotifyRightClicked(gfx::Rect(rect), modifiers);
|
NotifyRightClicked(gfx::Rect(rect), modifiers);
|
||||||
}
|
}
|
||||||
|
@ -145,22 +145,23 @@ void NotifyIcon::DisplayBalloon(const gfx::Image& icon,
|
||||||
void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
|
void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
|
||||||
ui::SimpleMenuModel* menu_model) {
|
ui::SimpleMenuModel* menu_model) {
|
||||||
// Returns if context menu isn't set.
|
// Returns if context menu isn't set.
|
||||||
if (!menu_model_)
|
if (!menu_model)
|
||||||
return;
|
return;
|
||||||
// Set our window as the foreground window, so the context menu closes when
|
// Set our window as the foreground window, so the context menu closes when
|
||||||
// we click away from it.
|
// we click away from it.
|
||||||
if (!SetForegroundWindow(window_))
|
if (!SetForegroundWindow(window_))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Show menu at mouse's position by default.
|
||||||
|
gfx::Rect rect(pos, gfx::Size());
|
||||||
|
if (pos.IsOrigin())
|
||||||
|
rect.set_origin(gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
|
||||||
|
|
||||||
views::MenuRunner menu_runner(
|
views::MenuRunner menu_runner(
|
||||||
menu_model_,
|
menu_model,
|
||||||
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
|
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
|
||||||
ignore_result(menu_runner.RunMenuAt(
|
ignore_result(menu_runner.RunMenuAt(
|
||||||
NULL,
|
NULL, NULL, rect, views::MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_MOUSE));
|
||||||
NULL,
|
|
||||||
gfx::Rect(pos, gfx::Size()),
|
|
||||||
views::MENU_ANCHOR_TOPLEFT,
|
|
||||||
ui::MENU_SOURCE_MOUSE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||||
|
|
|
@ -33,8 +33,7 @@ class NotifyIcon : public TrayIcon {
|
||||||
// Handles a click event from the user - if |left_button_click| is true and
|
// Handles a click event from the user - if |left_button_click| is true and
|
||||||
// there is a registered observer, passes the click event to the observer,
|
// there is a registered observer, passes the click event to the observer,
|
||||||
// otherwise displays the context menu if there is one.
|
// otherwise displays the context menu if there is one.
|
||||||
void HandleClickEvent(const gfx::Point& cursor_pos,
|
void HandleClickEvent(int modifiers,
|
||||||
int modifiers,
|
|
||||||
bool left_button_click,
|
bool left_button_click,
|
||||||
bool double_button_click);
|
bool double_button_click);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "base/win/win_util.h"
|
#include "base/win/win_util.h"
|
||||||
#include "base/win/wrapped_window_proc.h"
|
#include "base/win/wrapped_window_proc.h"
|
||||||
#include "ui/events/event_constants.h"
|
#include "ui/events/event_constants.h"
|
||||||
#include "ui/gfx/screen.h"
|
|
||||||
#include "ui/gfx/win/hwnd_util.h"
|
#include "ui/gfx/win/hwnd_util.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -172,10 +171,7 @@ LRESULT CALLBACK NotifyIconHost::WndProc(HWND hwnd,
|
||||||
case WM_CONTEXTMENU:
|
case WM_CONTEXTMENU:
|
||||||
// Walk our icons, find which one was clicked on, and invoke its
|
// Walk our icons, find which one was clicked on, and invoke its
|
||||||
// HandleClickEvent() method.
|
// HandleClickEvent() method.
|
||||||
gfx::Point cursor_pos(
|
|
||||||
gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
|
|
||||||
win_icon->HandleClickEvent(
|
win_icon->HandleClickEvent(
|
||||||
cursor_pos,
|
|
||||||
GetKeyboardModifers(),
|
GetKeyboardModifers(),
|
||||||
(lparam == WM_LBUTTONDOWN || lparam == WM_LBUTTONDBLCLK),
|
(lparam == WM_LBUTTONDOWN || lparam == WM_LBUTTONDBLCLK),
|
||||||
(lparam == WM_LBUTTONDBLCLK || lparam == WM_RBUTTONDBLCLK));
|
(lparam == WM_LBUTTONDBLCLK || lparam == WM_RBUTTONDBLCLK));
|
||||||
|
|
Loading…
Reference in a new issue