OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "app/menus/button_menu_item_model.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 |
| 9 namespace menus { |
| 10 |
| 11 ButtonMenuItemModel::ButtonMenuItemModel( |
| 12 int string_id, |
| 13 ButtonMenuItemModel::Delegate* delegate) |
| 14 : item_label_(l10n_util::GetStringUTF16(string_id)), |
| 15 delegate_(delegate) { |
| 16 } |
| 17 |
| 18 void ButtonMenuItemModel::AddItemWithStringId(int command_id, int string_id) { |
| 19 Item item = { command_id, TYPE_BUTTON, l10n_util::GetStringUTF16(string_id), |
| 20 SIDE_BOTH, -1 }; |
| 21 items_.push_back(item); |
| 22 } |
| 23 |
| 24 void ButtonMenuItemModel::AddItemWithImage(int command_id, |
| 25 int icon_idr) { |
| 26 Item item = { command_id, TYPE_BUTTON, string16(), SIDE_BOTH, icon_idr }; |
| 27 items_.push_back(item); |
| 28 } |
| 29 |
| 30 void ButtonMenuItemModel::AddSpace() { |
| 31 Item item = { 0, TYPE_SPACE, string16(), SIDE_NONE, -1 }; |
| 32 items_.push_back(item); |
| 33 } |
| 34 |
| 35 int ButtonMenuItemModel::GetItemCount() const { |
| 36 return static_cast<int>(items_.size()); |
| 37 } |
| 38 |
| 39 ButtonMenuItemModel::ButtonType ButtonMenuItemModel::GetTypeAt( |
| 40 int index) const { |
| 41 return items_[index].type; |
| 42 } |
| 43 |
| 44 int ButtonMenuItemModel::GetCommandIdAt(int index) const { |
| 45 return items_[index].command_id; |
| 46 } |
| 47 |
| 48 const string16& ButtonMenuItemModel::GetLabelAt(int index) const { |
| 49 return items_[index].label; |
| 50 } |
| 51 |
| 52 bool ButtonMenuItemModel::GetIconAt(int index, int* icon_idr) const { |
| 53 if (items_[index].icon_idr == -1) |
| 54 return false; |
| 55 |
| 56 *icon_idr = items_[index].icon_idr; |
| 57 return true; |
| 58 } |
| 59 |
| 60 void ButtonMenuItemModel::ActivatedCommand(int command_id) { |
| 61 if (delegate_) |
| 62 delegate_->ExecuteCommand(command_id); |
| 63 } |
| 64 |
| 65 } // namespace menus |
OLD | NEW |