| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_WIN_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_WIN_H_ |
| 6 #define UI_VIEWS_CONTROLS_MENU_MENU_WIN_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_MENU_WIN_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // Alternatively, a Menu object can be constructed wrapping an existing | 41 // Alternatively, a Menu object can be constructed wrapping an existing |
| 42 // HMENU. This can be used to use the convenience methods to insert | 42 // HMENU. This can be used to use the convenience methods to insert |
| 43 // menu items and manage label string ownership. However this kind of | 43 // menu items and manage label string ownership. However this kind of |
| 44 // Menu object cannot use the delegate. | 44 // Menu object cannot use the delegate. |
| 45 explicit MenuWin(HMENU hmenu); | 45 explicit MenuWin(HMENU hmenu); |
| 46 virtual ~MenuWin(); | 46 virtual ~MenuWin(); |
| 47 | 47 |
| 48 // Overridden from Menu: | 48 // Overridden from Menu: |
| 49 virtual void AddMenuItemWithIcon(int index, | 49 virtual void AddMenuItemWithIcon(int index, |
| 50 int item_id, | 50 int item_id, |
| 51 const string16& label, | 51 const base::string16& label, |
| 52 const gfx::ImageSkia& icon) OVERRIDE; | 52 const gfx::ImageSkia& icon) OVERRIDE; |
| 53 virtual Menu* AddSubMenuWithIcon(int index, | 53 virtual Menu* AddSubMenuWithIcon(int index, |
| 54 int item_id, | 54 int item_id, |
| 55 const string16& label, | 55 const base::string16& label, |
| 56 const gfx::ImageSkia& icon) OVERRIDE; | 56 const gfx::ImageSkia& icon) OVERRIDE; |
| 57 virtual void AddSeparator(int index) OVERRIDE; | 57 virtual void AddSeparator(int index) OVERRIDE; |
| 58 virtual void EnableMenuItemByID(int item_id, bool enabled) OVERRIDE; | 58 virtual void EnableMenuItemByID(int item_id, bool enabled) OVERRIDE; |
| 59 virtual void EnableMenuItemAt(int index, bool enabled) OVERRIDE; | 59 virtual void EnableMenuItemAt(int index, bool enabled) OVERRIDE; |
| 60 virtual void SetMenuLabel(int item_id, const string16& label) OVERRIDE; | 60 virtual void SetMenuLabel(int item_id, const base::string16& label) OVERRIDE; |
| 61 virtual bool SetIcon(const gfx::ImageSkia& icon, int item_id) OVERRIDE; | 61 virtual bool SetIcon(const gfx::ImageSkia& icon, int item_id) OVERRIDE; |
| 62 virtual void RunMenuAt(int x, int y) OVERRIDE; | 62 virtual void RunMenuAt(int x, int y) OVERRIDE; |
| 63 virtual void Cancel() OVERRIDE; | 63 virtual void Cancel() OVERRIDE; |
| 64 virtual int ItemCount() OVERRIDE; | 64 virtual int ItemCount() OVERRIDE; |
| 65 | 65 |
| 66 virtual HMENU GetMenuHandle() const { | 66 virtual HMENU GetMenuHandle() const { |
| 67 return menu_; | 67 return menu_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Gets the Win32 TPM alignment flags for the specified AnchorPoint. | 70 // Gets the Win32 TPM alignment flags for the specified AnchorPoint. |
| 71 DWORD GetTPMAlignFlags() const; | 71 DWORD GetTPMAlignFlags() const; |
| 72 | 72 |
| 73 protected: | 73 protected: |
| 74 virtual void AddMenuItemInternal(int index, | 74 virtual void AddMenuItemInternal(int index, |
| 75 int item_id, | 75 int item_id, |
| 76 const string16& label, | 76 const base::string16& label, |
| 77 const gfx::ImageSkia& icon, | 77 const gfx::ImageSkia& icon, |
| 78 MenuItemType type) OVERRIDE; | 78 MenuItemType type) OVERRIDE; |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 friend class MenuHostWindow; | 81 friend class MenuHostWindow; |
| 82 | 82 |
| 83 // The data of menu items needed to display. | 83 // The data of menu items needed to display. |
| 84 struct ItemData; | 84 struct ItemData; |
| 85 | 85 |
| 86 void AddMenuItemInternal(int index, | 86 void AddMenuItemInternal(int index, |
| 87 int item_id, | 87 int item_id, |
| 88 const string16& label, | 88 const base::string16& label, |
| 89 const gfx::ImageSkia& icon, | 89 const gfx::ImageSkia& icon, |
| 90 HMENU submenu, | 90 HMENU submenu, |
| 91 MenuItemType type); | 91 MenuItemType type); |
| 92 | 92 |
| 93 explicit MenuWin(MenuWin* parent); | 93 explicit MenuWin(MenuWin* parent); |
| 94 | 94 |
| 95 // Sets menu information before displaying, including sub-menus. | 95 // Sets menu information before displaying, including sub-menus. |
| 96 void SetMenuInfo(); | 96 void SetMenuInfo(); |
| 97 | 97 |
| 98 // Get all the state flags for the |fState| field of MENUITEMINFO for the | 98 // Get all the state flags for the |fState| field of MENUITEMINFO for the |
| 99 // item with the specified id. |delegate| is consulted if non-NULL about | 99 // item with the specified id. |delegate| is consulted if non-NULL about |
| 100 // the state of the item in preference to |controller_|. | 100 // the state of the item in preference to |controller_|. |
| 101 UINT GetStateFlagsForItemID(int item_id) const; | 101 UINT GetStateFlagsForItemID(int item_id) const; |
| 102 | 102 |
| 103 // The Win32 Menu Handle we wrap | 103 // The Win32 Menu Handle we wrap |
| 104 HMENU menu_; | 104 HMENU menu_; |
| 105 | 105 |
| 106 // The window that would receive WM_COMMAND messages when the user selects | 106 // The window that would receive WM_COMMAND messages when the user selects |
| 107 // an item from the menu. | 107 // an item from the menu. |
| 108 HWND owner_; | 108 HWND owner_; |
| 109 | 109 |
| 110 // This list is used to store the default labels for the menu items. | 110 // This list is used to store the default labels for the menu items. |
| 111 // We may use contextual labels when RunMenu is called, so we must save | 111 // We may use contextual labels when RunMenu is called, so we must save |
| 112 // a copy of default ones here. | 112 // a copy of default ones here. |
| 113 std::vector<string16> labels_; | 113 std::vector<base::string16> labels_; |
| 114 | 114 |
| 115 // A flag to indicate whether this menu will be drawn by the Menu class. | 115 // A flag to indicate whether this menu will be drawn by the Menu class. |
| 116 // If it's true, all the menu items will be owner drawn. Otherwise, | 116 // If it's true, all the menu items will be owner drawn. Otherwise, |
| 117 // all the drawing will be done by Windows. | 117 // all the drawing will be done by Windows. |
| 118 bool owner_draw_; | 118 bool owner_draw_; |
| 119 | 119 |
| 120 // This list is to store the string labels and icons to display. It's used | 120 // This list is to store the string labels and icons to display. It's used |
| 121 // when owner_draw_ is true. We give MENUITEMINFO pointers to these | 121 // when owner_draw_ is true. We give MENUITEMINFO pointers to these |
| 122 // structures to specify what we'd like to draw. If owner_draw_ is false, | 122 // structures to specify what we'd like to draw. If owner_draw_ is false, |
| 123 // we only give MENUITEMINFO pointers to the labels_. | 123 // we only give MENUITEMINFO pointers to the labels_. |
| 124 // The label member of the ItemData structure comes from either labels_ or | 124 // The label member of the ItemData structure comes from either labels_ or |
| 125 // the GetContextualLabel. | 125 // the GetContextualLabel. |
| 126 std::vector<ItemData*> item_data_; | 126 std::vector<ItemData*> item_data_; |
| 127 | 127 |
| 128 // Our sub-menus, if any. | 128 // Our sub-menus, if any. |
| 129 std::vector<MenuWin*> submenus_; | 129 std::vector<MenuWin*> submenus_; |
| 130 | 130 |
| 131 // Whether the menu is visible. | 131 // Whether the menu is visible. |
| 132 bool is_menu_visible_; | 132 bool is_menu_visible_; |
| 133 | 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(MenuWin); | 134 DISALLOW_COPY_AND_ASSIGN(MenuWin); |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 } // namespace views | 137 } // namespace views |
| 138 | 138 |
| 139 #endif // UI_VIEWS_CONTROLS_MENU_MENU_WIN_H_ | 139 #endif // UI_VIEWS_CONTROLS_MENU_MENU_WIN_H_ |
| OLD | NEW |