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

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

Issue 6304013: Fix regression in submenus not working. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 | « no previous file | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the 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/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 wcex.cbSize = sizeof(WNDCLASSEX); 81 wcex.cbSize = sizeof(WNDCLASSEX);
82 wcex.style = CS_DBLCLKS; 82 wcex.style = CS_DBLCLKS;
83 wcex.lpfnWndProc = &MenuHostWindowProc; 83 wcex.lpfnWndProc = &MenuHostWindowProc;
84 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1); 84 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);
85 wcex.lpszClassName = kWindowClassName; 85 wcex.lpszClassName = kWindowClassName;
86 ATOM clazz = RegisterClassEx(&wcex); 86 ATOM clazz = RegisterClassEx(&wcex);
87 DCHECK(clazz); 87 DCHECK(clazz);
88 registered = true; 88 registered = true;
89 } 89 }
90 90
91 NativeMenuWin* GetNativeMenuWinFromHMENU(HMENU hmenu) const {
92 MENUINFO mi = {0};
93 mi.cbSize = sizeof(mi);
94 mi.fMask = MIM_MENUDATA | MIM_STYLE;
95 GetMenuInfo(hmenu, &mi);
96 return reinterpret_cast<NativeMenuWin*>(mi.dwMenuData);
97 }
98
91 // Converts the WPARAM value passed to WM_MENUSELECT into an index 99 // Converts the WPARAM value passed to WM_MENUSELECT into an index
92 // corresponding to the menu item that was selected. 100 // corresponding to the menu item that was selected.
93 int GetMenuItemIndexFromWPARAM(HMENU menu, WPARAM w_param) const { 101 int GetMenuItemIndexFromWPARAM(HMENU menu, WPARAM w_param) const {
94 int count = GetMenuItemCount(menu); 102 int count = GetMenuItemCount(menu);
95 // For normal command menu items, Windows passes a command id as the LOWORD 103 // For normal command menu items, Windows passes a command id as the LOWORD
96 // of WPARAM for WM_MENUSELECT. We need to walk forward through the menu 104 // of WPARAM for WM_MENUSELECT. We need to walk forward through the menu
97 // items to find an item with a matching ID. Ugh! 105 // items to find an item with a matching ID. Ugh!
98 for (int i = 0; i < count; ++i) { 106 for (int i = 0; i < count; ++i) {
99 MENUITEMINFO mii = {0}; 107 MENUITEMINFO mii = {0};
100 mii.cbSize = sizeof(mii); 108 mii.cbSize = sizeof(mii);
101 mii.fMask = MIIM_ID; 109 mii.fMask = MIIM_ID;
102 GetMenuItemInfo(menu, i, MF_BYPOSITION, &mii); 110 GetMenuItemInfo(menu, i, MF_BYPOSITION, &mii);
103 if (mii.wID == w_param) 111 if (mii.wID == w_param)
104 return i; 112 return i;
105 } 113 }
106 // If we didn't find a matching command ID, this means a submenu has been 114 // If we didn't find a matching command ID, this means a submenu has been
107 // selected instead, and rather than passing a command ID in 115 // selected instead, and rather than passing a command ID in
108 // LOWORD(w_param), Windows has actually passed us a position, so we just 116 // LOWORD(w_param), Windows has actually passed us a position, so we just
109 // return it. 117 // return it.
110 return w_param; 118 return w_param;
111 } 119 }
112 120
113 NativeMenuWin::ItemData* GetItemData(ULONG_PTR item_data) { 121 NativeMenuWin::ItemData* GetItemData(ULONG_PTR item_data) {
114 return reinterpret_cast<NativeMenuWin::ItemData*>(item_data); 122 return reinterpret_cast<NativeMenuWin::ItemData*>(item_data);
115 } 123 }
116 124
117 // Called when the user selects a specific item. 125 // Called when the user selects a specific item.
118 void OnMenuCommand(int position, HMENU menu) { 126 void OnMenuCommand(int position, HMENU menu) {
119 parent_->model_->ActivatedAt(position); 127 NativeMenuWin* intergoat = GetNativeMenuWinFromHMENU(menu);
asargent_no_longer_on_chrome 2011/01/20 19:56:57 Does the name "intergoat" actually mean something
jam 2011/01/20 20:24:30 I think it's an inside joke :) This is just resur
128 ui::MenuModel* model = intergoat->model_;
129 model->ActivatedAt(position);
120 } 130 }
121 131
122 // Called as the user moves their mouse or arrows through the contents of the 132 // Called as the user moves their mouse or arrows through the contents of the
123 // menu. 133 // menu.
124 void OnMenuSelect(WPARAM w_param, HMENU menu) { 134 void OnMenuSelect(WPARAM w_param, HMENU menu) {
135 if (!menu)
136 return; // menu is null when closing on XP.
137
125 int position = GetMenuItemIndexFromWPARAM(menu, w_param); 138 int position = GetMenuItemIndexFromWPARAM(menu, w_param);
126 if (position >= 0) 139 if (position >= 0)
127 parent_->model_->HighlightChangedTo(position); 140 GetNativeMenuWinFromHMENU(menu)->model_->HighlightChangedTo(position);
128 } 141 }
129 142
130 // Called by Windows to measure the size of an owner-drawn menu item. 143 // Called by Windows to measure the size of an owner-drawn menu item.
131 void OnMeasureItem(WPARAM w_param, MEASUREITEMSTRUCT* measure_item_struct) { 144 void OnMeasureItem(WPARAM w_param, MEASUREITEMSTRUCT* measure_item_struct) {
132 NativeMenuWin::ItemData* data = GetItemData(measure_item_struct->itemData); 145 NativeMenuWin::ItemData* data = GetItemData(measure_item_struct->itemData);
133 if (data) { 146 if (data) {
134 gfx::Font font; 147 gfx::Font font;
135 measure_item_struct->itemWidth = font.GetStringWidth(data->label) + 148 measure_item_struct->itemWidth = font.GetStringWidth(data->label) +
136 kIconWidth + kItemLeftMargin + kItemRightMargin - 149 kIconWidth + kItemLeftMargin + kItemRightMargin -
137 GetSystemMetrics(SM_CXMENUCHECK); 150 GetSystemMetrics(SM_CXMENUCHECK);
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 644
632 //////////////////////////////////////////////////////////////////////////////// 645 ////////////////////////////////////////////////////////////////////////////////
633 // MenuWrapper, public: 646 // MenuWrapper, public:
634 647
635 // static 648 // static
636 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { 649 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) {
637 return new NativeMenuWin(menu->model(), NULL); 650 return new NativeMenuWin(menu->model(), NULL);
638 } 651 }
639 652
640 } // namespace views 653 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698