Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: views/controls/menu/native_menu_win.cc

Issue 122027: Remove the Menu object, converting all the remaining callers to use Menu2. I'... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/menu/menu_2.cc ('k') | views/controls/textfield/native_textfield_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/l10n_util_win.h" 8 #include "app/l10n_util_win.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1); 56 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);
57 wcex.lpszClassName = kWindowClassName; 57 wcex.lpszClassName = kWindowClassName;
58 ATOM clazz = RegisterClassEx(&wcex); 58 ATOM clazz = RegisterClassEx(&wcex);
59 DCHECK(clazz); 59 DCHECK(clazz);
60 registered = true; 60 registered = true;
61 } 61 }
62 62
63 NativeMenuWin* GetNativeMenuWinFromHMENU(HMENU hmenu) const { 63 NativeMenuWin* GetNativeMenuWinFromHMENU(HMENU hmenu) const {
64 MENUINFO mi = {0}; 64 MENUINFO mi = {0};
65 mi.cbSize = sizeof(mi); 65 mi.cbSize = sizeof(mi);
66 mi.fMask = MIM_MENUDATA; 66 mi.fMask = MIM_MENUDATA | MIM_STYLE;
67 GetMenuInfo(hmenu, &mi); 67 GetMenuInfo(hmenu, &mi);
68 return reinterpret_cast<NativeMenuWin*>(mi.dwMenuData); 68 return reinterpret_cast<NativeMenuWin*>(mi.dwMenuData);
69 } 69 }
70 70
71 // Converts the WPARAM value passed to WM_MENUSELECT into an index 71 // Converts the WPARAM value passed to WM_MENUSELECT into an index
72 // corresponding to the menu item that was selected. 72 // corresponding to the menu item that was selected.
73 int GetMenuItemIndexFromWPARAM(HMENU menu, WPARAM w_param) const { 73 int GetMenuItemIndexFromWPARAM(HMENU menu, WPARAM w_param) const {
74 int count = GetMenuItemCount(menu); 74 int count = GetMenuItemCount(menu);
75 // For normal command menu items, Windows passes a command id as the LOWORD 75 // For normal command menu items, Windows passes a command id as the LOWORD
76 // of WPARAM for WM_MENUSELECT. We need to walk forward through the menu 76 // of WPARAM for WM_MENUSELECT. We need to walk forward through the menu
77 // items to find an item with a matching ID. Ugh! 77 // items to find an item with a matching ID. Ugh!
78 for (int i = 0; i < count; ++i) { 78 for (int i = 0; i < count; ++i) {
79 MENUITEMINFO mii = {0}; 79 MENUITEMINFO mii = {0};
80 mii.cbSize = sizeof(mii); 80 mii.cbSize = sizeof(mii);
81 mii.fMask = MIIM_ID; 81 mii.fMask = MIIM_ID;
82 GetMenuItemInfo(menu, i, MF_BYPOSITION, &mii); 82 GetMenuItemInfo(menu, i, MF_BYPOSITION, &mii);
83 if (mii.wID == w_param) 83 if (mii.wID == w_param)
84 return i; 84 return i;
85 } 85 }
86 // If we didn't find a matching command ID, this means a submenu has been 86 // If we didn't find a matching command ID, this means a submenu has been
87 // selected instead, and rather than passing a command ID in 87 // selected instead, and rather than passing a command ID in
88 // LOWORD(w_param), Windows has actually passed us a position, so we just 88 // LOWORD(w_param), Windows has actually passed us a position, so we just
89 // return it. 89 // return it.
90 return w_param; 90 return w_param;
91 } 91 }
92 92
93 // Called when the user selects a specific item. 93 // Called when the user selects a specific item.
94 void OnMenuCommand(int position, HMENU menu) { 94 void OnMenuCommand(int position, HMENU menu) {
95 GetNativeMenuWinFromHMENU(menu)->model_->ActivatedAt(position); 95 NativeMenuWin* intergoat = GetNativeMenuWinFromHMENU(menu);
96 Menu2Model* model = intergoat->model_;
97 model->ActivatedAt(position);
96 } 98 }
97 99
98 // Called as the user moves their mouse or arrows through the contents of the 100 // Called as the user moves their mouse or arrows through the contents of the
99 // menu. 101 // menu.
100 void OnMenuSelect(WPARAM w_param, HMENU menu) { 102 void OnMenuSelect(WPARAM w_param, HMENU menu) {
101 if (!menu) 103 if (!menu)
102 return; // menu is null when closing on XP. 104 return; // menu is null when closing on XP.
103 105
104 int position = GetMenuItemIndexFromWPARAM(menu, w_param); 106 int position = GetMenuItemIndexFromWPARAM(menu, w_param);
105 if (position >= 0) 107 if (position >= 0)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 NativeMenuWin::NativeMenuWin(Menu2Model* model, HWND system_menu_for) 160 NativeMenuWin::NativeMenuWin(Menu2Model* model, HWND system_menu_for)
159 : model_(model), 161 : model_(model),
160 menu_(NULL), 162 menu_(NULL),
161 owner_draw_(false), 163 owner_draw_(false),
162 system_menu_for_(system_menu_for), 164 system_menu_for_(system_menu_for),
163 first_item_index_(0) { 165 first_item_index_(0) {
164 } 166 }
165 167
166 NativeMenuWin::~NativeMenuWin() { 168 NativeMenuWin::~NativeMenuWin() {
167 STLDeleteContainerPointers(items_.begin(), items_.end()); 169 STLDeleteContainerPointers(items_.begin(), items_.end());
170 DestroyMenu(menu_);
168 } 171 }
169 172
170 //////////////////////////////////////////////////////////////////////////////// 173 ////////////////////////////////////////////////////////////////////////////////
171 // NativeMenuWin, MenuWrapper implementation: 174 // NativeMenuWin, MenuWrapper implementation:
172 175
173 void NativeMenuWin::RunMenuAt(const gfx::Point& point, int alignment) { 176 void NativeMenuWin::RunMenuAt(const gfx::Point& point, int alignment) {
174 CreateHostWindow(); 177 CreateHostWindow();
175 UpdateStates(); 178 UpdateStates();
176 UINT flags = TPM_LEFTBUTTON | TPM_RECURSE; 179 UINT flags = TPM_LEFTBUTTON | TPM_RECURSE;
177 flags |= GetAlignmentFlags(alignment); 180 flags |= GetAlignmentFlags(alignment);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 405
403 //////////////////////////////////////////////////////////////////////////////// 406 ////////////////////////////////////////////////////////////////////////////////
404 // MenuWrapper, public: 407 // MenuWrapper, public:
405 408
406 // static 409 // static
407 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { 410 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) {
408 return new NativeMenuWin(menu->model(), NULL); 411 return new NativeMenuWin(menu->model(), NULL);
409 } 412 }
410 413
411 } // namespace views 414 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/menu/menu_2.cc ('k') | views/controls/textfield/native_textfield_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698