| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "views/controls/menu/native_menu_win.h" | 5 #include "views/controls/menu/native_menu_win.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/gfx/font.h" | 8 #include "app/gfx/font.h" |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/l10n_util_win.h" | 10 #include "app/l10n_util_win.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 const wchar_t* NativeMenuWin::MenuHostWindow::kMenuHostWindowKey = | 295 const wchar_t* NativeMenuWin::MenuHostWindow::kMenuHostWindowKey = |
| 296 L"__MENU_HOST_WINDOW__"; | 296 L"__MENU_HOST_WINDOW__"; |
| 297 | 297 |
| 298 | 298 |
| 299 //////////////////////////////////////////////////////////////////////////////// | 299 //////////////////////////////////////////////////////////////////////////////// |
| 300 // NativeMenuWin, public: | 300 // NativeMenuWin, public: |
| 301 | 301 |
| 302 NativeMenuWin::NativeMenuWin(Menu2Model* model, HWND system_menu_for) | 302 NativeMenuWin::NativeMenuWin(Menu2Model* model, HWND system_menu_for) |
| 303 : model_(model), | 303 : model_(model), |
| 304 menu_(NULL), | 304 menu_(NULL), |
| 305 owner_draw_(l10n_util::NeedOverrideDefaultUIFont(NULL, NULL)), | 305 owner_draw_(false), |
| 306 system_menu_for_(system_menu_for), | 306 system_menu_for_(system_menu_for), |
| 307 first_item_index_(0) { | 307 first_item_index_(0) { |
| 308 } | 308 } |
| 309 | 309 |
| 310 NativeMenuWin::~NativeMenuWin() { | 310 NativeMenuWin::~NativeMenuWin() { |
| 311 STLDeleteContainerPointers(items_.begin(), items_.end()); | 311 STLDeleteContainerPointers(items_.begin(), items_.end()); |
| 312 DestroyMenu(menu_); | 312 DestroyMenu(menu_); |
| 313 } | 313 } |
| 314 | 314 |
| 315 //////////////////////////////////////////////////////////////////////////////// | 315 //////////////////////////////////////////////////////////////////////////////// |
| 316 // NativeMenuWin, MenuWrapper implementation: | 316 // NativeMenuWin, MenuWrapper implementation: |
| 317 | 317 |
| 318 void NativeMenuWin::RunMenuAt(const gfx::Point& point, int alignment) { | 318 void NativeMenuWin::RunMenuAt(const gfx::Point& point, int alignment) { |
| 319 CreateHostWindow(); | 319 CreateHostWindow(); |
| 320 UpdateStates(); | 320 UpdateStates(); |
| 321 UINT flags = TPM_LEFTBUTTON | TPM_RECURSE; | 321 UINT flags = TPM_LEFTBUTTON | TPM_RECURSE; |
| 322 flags |= GetAlignmentFlags(alignment); | 322 flags |= GetAlignmentFlags(alignment); |
| 323 // Command dispatch is done through WM_MENUCOMMAND, handled by the host | 323 // Command dispatch is done through WM_MENUCOMMAND, handled by the host |
| 324 // window. | 324 // window. |
| 325 TrackPopupMenuEx(menu_, flags, point.x(), point.y(), host_window_->hwnd(), | 325 TrackPopupMenuEx(menu_, flags, point.x(), point.y(), host_window_->hwnd(), |
| 326 NULL); | 326 NULL); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void NativeMenuWin::CancelMenu() { | 329 void NativeMenuWin::CancelMenu() { |
| 330 EndMenu(); | 330 EndMenu(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 void NativeMenuWin::Rebuild() { | 333 void NativeMenuWin::Rebuild() { |
| 334 ResetNativeMenu(); | 334 ResetNativeMenu(); |
| 335 owner_draw_ = model_->HasIcons() || owner_draw_; | 335 owner_draw_ = model_->HasIcons(); |
| 336 first_item_index_ = model_->GetFirstItemIndex(GetNativeMenu()); | 336 first_item_index_ = model_->GetFirstItemIndex(GetNativeMenu()); |
| 337 for (int menu_index = first_item_index_; | 337 for (int menu_index = first_item_index_; |
| 338 menu_index < first_item_index_ + model_->GetItemCount(); ++menu_index) { | 338 menu_index < first_item_index_ + model_->GetItemCount(); ++menu_index) { |
| 339 int model_index = menu_index - first_item_index_; | 339 int model_index = menu_index - first_item_index_; |
| 340 if (model_->GetTypeAt(model_index) == Menu2Model::TYPE_SEPARATOR) | 340 if (model_->GetTypeAt(model_index) == Menu2Model::TYPE_SEPARATOR) |
| 341 AddSeparatorItemAt(menu_index, model_index); | 341 AddSeparatorItemAt(menu_index, model_index); |
| 342 else | 342 else |
| 343 AddMenuItemAt(menu_index, model_index); | 343 AddMenuItemAt(menu_index, model_index); |
| 344 } | 344 } |
| 345 } | 345 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 | 533 |
| 534 //////////////////////////////////////////////////////////////////////////////// | 534 //////////////////////////////////////////////////////////////////////////////// |
| 535 // MenuWrapper, public: | 535 // MenuWrapper, public: |
| 536 | 536 |
| 537 // static | 537 // static |
| 538 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { | 538 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { |
| 539 return new NativeMenuWin(menu->model(), NULL); | 539 return new NativeMenuWin(menu->model(), NULL); |
| 540 } | 540 } |
| 541 | 541 |
| 542 } // namespace views | 542 } // namespace views |
| OLD | NEW |