2013-07-05 01:44:56 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-07-05 01:44:56 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/api/atom_api_menu_win.h"
|
2013-07-05 01:44:56 +00:00
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/native_window_win.h"
|
|
|
|
#include "atom/browser/ui/win/menu_2.h"
|
2013-08-06 13:08:52 +00:00
|
|
|
#include "ui/gfx/point.h"
|
2013-10-02 13:43:52 +00:00
|
|
|
#include "ui/gfx/screen.h"
|
2013-08-06 13:08:52 +00:00
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
2013-12-17 10:34:45 +00:00
|
|
|
|
2013-07-05 01:44:56 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2014-05-26 03:34:36 +00:00
|
|
|
MenuWin::MenuWin() : menu_(NULL) {
|
2013-07-05 01:44:56 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void MenuWin::Popup(Window* window) {
|
2013-10-02 13:43:52 +00:00
|
|
|
gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
|
2014-05-26 03:34:36 +00:00
|
|
|
popup_menu_.reset(new atom::Menu2(model_.get()));
|
|
|
|
menu_ = popup_menu_.get();
|
2013-10-02 13:43:52 +00:00
|
|
|
menu_->RunContextMenuAt(cursor);
|
2013-07-05 01:44:56 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 03:34:36 +00:00
|
|
|
void MenuWin::UpdateStates() {
|
|
|
|
MenuWin* top = this;
|
|
|
|
while (top->parent_)
|
|
|
|
top = static_cast<MenuWin*>(top->parent_);
|
|
|
|
if (top->menu_)
|
|
|
|
top->menu_->UpdateStates();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuWin::AttachToWindow(Window* window) {
|
|
|
|
NativeWindowWin* nw = static_cast<NativeWindowWin*>(window->window());
|
|
|
|
nw->SetMenu(model_.get());
|
|
|
|
menu_ = nw->menu();
|
2013-10-02 13:24:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 01:44:56 +00:00
|
|
|
// static
|
2014-04-21 15:40:10 +00:00
|
|
|
mate::Wrappable* Menu::Create() {
|
|
|
|
return new MenuWin();
|
2013-07-05 01:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|