OLD | NEW |
---|---|
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/menu_item_view.h" | 5 #include "views/controls/menu/menu_item_view.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/menus/menu_model.h" | |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "gfx/canvas.h" | 10 #include "gfx/canvas.h" |
10 #include "grit/app_strings.h" | 11 #include "grit/app_strings.h" |
11 #include "views/controls/button/text_button.h" | 12 #include "views/controls/button/text_button.h" |
12 #include "views/controls/button/menu_button.h" | 13 #include "views/controls/button/menu_button.h" |
13 #include "views/controls/menu/menu_config.h" | 14 #include "views/controls/menu/menu_config.h" |
14 #include "views/controls/menu/menu_controller.h" | 15 #include "views/controls/menu/menu_controller.h" |
15 #include "views/controls/menu/menu_separator.h" | 16 #include "views/controls/menu/menu_separator.h" |
16 #include "views/controls/menu/submenu_view.h" | 17 #include "views/controls/menu/submenu_view.h" |
17 | 18 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 controller_->Run(parent, NULL, this, bounds, anchor, NULL); | 231 controller_->Run(parent, NULL, this, bounds, anchor, NULL); |
231 } | 232 } |
232 | 233 |
233 void MenuItemView::Cancel() { | 234 void MenuItemView::Cancel() { |
234 if (controller_ && !canceled_) { | 235 if (controller_ && !canceled_) { |
235 canceled_ = true; | 236 canceled_ = true; |
236 controller_->Cancel(MenuController::EXIT_ALL); | 237 controller_->Cancel(MenuController::EXIT_ALL); |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
241 MenuItemView* MenuItemView::AppendMenuItemFromModel(menus::MenuModel* model, | |
242 int index, int id) { | |
sky
2010/11/22 19:23:01
id should be on its own line.
sadrul
2010/11/22 19:42:38
Done.
| |
243 SkBitmap icon; | |
244 std::wstring label; | |
245 MenuItemView::Type type; | |
246 menus::MenuModel::ItemType menu_type = model->GetTypeAt(index); | |
247 switch (menu_type) { | |
248 case menus::MenuModel::TYPE_COMMAND: | |
249 model->GetIconAt(index, &icon); | |
250 type = MenuItemView::NORMAL; | |
251 label = UTF16ToWide(model->GetLabelAt(index)); | |
252 break; | |
253 case menus::MenuModel::TYPE_CHECK: | |
254 type = MenuItemView::CHECKBOX; | |
255 label = UTF16ToWide(model->GetLabelAt(index)); | |
256 break; | |
257 case menus::MenuModel::TYPE_RADIO: | |
258 type = MenuItemView::RADIO; | |
259 label = UTF16ToWide(model->GetLabelAt(index)); | |
260 break; | |
261 case menus::MenuModel::TYPE_SEPARATOR: | |
262 type = MenuItemView::SEPARATOR; | |
263 break; | |
264 case menus::MenuModel::TYPE_SUBMENU: | |
265 type = MenuItemView::SUBMENU; | |
266 label = UTF16ToWide(model->GetLabelAt(index)); | |
267 break; | |
268 default: | |
269 NOTREACHED(); | |
270 type = MenuItemView::NORMAL; | |
271 break; | |
272 } | |
273 | |
274 return AppendMenuItemImpl(id, label, icon, type); | |
275 } | |
276 | |
240 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, | 277 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, |
241 const std::wstring& label, | 278 const std::wstring& label, |
242 const SkBitmap& icon, | 279 const SkBitmap& icon, |
243 Type type) { | 280 Type type) { |
244 if (!submenu_) | 281 if (!submenu_) |
245 CreateSubmenu(); | 282 CreateSubmenu(); |
246 if (type == SEPARATOR) { | 283 if (type == SEPARATOR) { |
247 submenu_->AddChildView(new MenuSeparator()); | 284 submenu_->AddChildView(new MenuSeparator()); |
248 return NULL; | 285 return NULL; |
249 } | 286 } |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 } | 655 } |
619 | 656 |
620 std::wstring MenuItemView::GetAcceleratorText() { | 657 std::wstring MenuItemView::GetAcceleratorText() { |
621 Accelerator accelerator; | 658 Accelerator accelerator; |
622 return (GetDelegate() && | 659 return (GetDelegate() && |
623 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? | 660 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? |
624 accelerator.GetShortcutText() : std::wstring(); | 661 accelerator.GetShortcutText() : std::wstring(); |
625 } | 662 } |
626 | 663 |
627 } // namespace views | 664 } // namespace views |
OLD | NEW |