1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
13 // * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // ---------------------------------------------------------------------------
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
37 #ifndef CEF_INCLUDE_CEF_MENU_MODEL_H_
38 #define CEF_INCLUDE_CEF_MENU_MODEL_H_
41 #include "include/cef_base.h"
44 // Supports creation and modification of menus. See cef_menu_id_t for the
45 // command ids that have default implementations. All user-defined command ids
46 // should be between MENU_ID_USER_FIRST and MENU_ID_USER_LAST. The methods of
47 // this class can only be accessed on the browser process the UI thread.
49 /*--cef(source=library)--*/
50 class CefMenuModel : public virtual CefBase {
52 typedef cef_menu_item_type_t MenuItemType;
55 // Clears the menu. Returns true on success.
58 virtual bool Clear() =0;
61 // Returns the number of items in this menu.
64 virtual int GetCount() =0;
67 // Add a separator to the menu. Returns true on success.
70 virtual bool AddSeparator() =0;
73 // Add an item to the menu. Returns true on success.
76 virtual bool AddItem(int command_id,
77 const CefString& label) =0;
80 // Add a check item to the menu. Returns true on success.
83 virtual bool AddCheckItem(int command_id,
84 const CefString& label) =0;
86 // Add a radio item to the menu. Only a single item with the specified
87 // |group_id| can be checked at a time. Returns true on success.
90 virtual bool AddRadioItem(int command_id,
91 const CefString& label,
95 // Add a sub-menu to the menu. The new sub-menu is returned.
98 virtual CefRefPtr<CefMenuModel> AddSubMenu(int command_id,
99 const CefString& label) =0;
102 // Insert a separator in the menu at the specified |index|. Returns true on
106 virtual bool InsertSeparatorAt(int index) =0;
109 // Insert an item in the menu at the specified |index|. Returns true on
113 virtual bool InsertItemAt(int index,
115 const CefString& label) =0;
118 // Insert a check item in the menu at the specified |index|. Returns true on
122 virtual bool InsertCheckItemAt(int index,
124 const CefString& label) =0;
127 // Insert a radio item in the menu at the specified |index|. Only a single
128 // item with the specified |group_id| can be checked at a time. Returns true
132 virtual bool InsertRadioItemAt(int index,
134 const CefString& label,
138 // Insert a sub-menu in the menu at the specified |index|. The new sub-menu
142 virtual CefRefPtr<CefMenuModel> InsertSubMenuAt(int index,
144 const CefString& label) =0;
147 // Removes the item with the specified |command_id|. Returns true on success.
150 virtual bool Remove(int command_id) =0;
153 // Removes the item at the specified |index|. Returns true on success.
156 virtual bool RemoveAt(int index) =0;
159 // Returns the index associated with the specified |command_id| or -1 if not
160 // found due to the command id not existing in the menu.
163 virtual int GetIndexOf(int command_id) =0;
166 // Returns the command id at the specified |index| or -1 if not found due to
167 // invalid range or the index being a separator.
170 virtual int GetCommandIdAt(int index) =0;
173 // Sets the command id at the specified |index|. Returns true on success.
176 virtual bool SetCommandIdAt(int index, int command_id) =0;
179 // Returns the label for the specified |command_id| or empty if not found.
182 virtual CefString GetLabel(int command_id) =0;
185 // Returns the label at the specified |index| or empty if not found due to
186 // invalid range or the index being a separator.
189 virtual CefString GetLabelAt(int index) =0;
192 // Sets the label for the specified |command_id|. Returns true on success.
195 virtual bool SetLabel(int command_id, const CefString& label) =0;
198 // Set the label at the specified |index|. Returns true on success.
201 virtual bool SetLabelAt(int index, const CefString& label) =0;
204 // Returns the item type for the specified |command_id|.
206 /*--cef(default_retval=MENUITEMTYPE_NONE)--*/
207 virtual MenuItemType GetType(int command_id) =0;
210 // Returns the item type at the specified |index|.
212 /*--cef(default_retval=MENUITEMTYPE_NONE)--*/
213 virtual MenuItemType GetTypeAt(int index) =0;
216 // Returns the group id for the specified |command_id| or -1 if invalid.
219 virtual int GetGroupId(int command_id) =0;
222 // Returns the group id at the specified |index| or -1 if invalid.
225 virtual int GetGroupIdAt(int index) =0;
228 // Sets the group id for the specified |command_id|. Returns true on success.
231 virtual bool SetGroupId(int command_id, int group_id) =0;
234 // Sets the group id at the specified |index|. Returns true on success.
237 virtual bool SetGroupIdAt(int index, int group_id) =0;
240 // Returns the submenu for the specified |command_id| or empty if invalid.
243 virtual CefRefPtr<CefMenuModel> GetSubMenu(int command_id) =0;
246 // Returns the submenu at the specified |index| or empty if invalid.
249 virtual CefRefPtr<CefMenuModel> GetSubMenuAt(int index) =0;
252 // Returns true if the specified |command_id| is visible.
255 virtual bool IsVisible(int command_id) =0;
258 // Returns true if the specified |index| is visible.
261 virtual bool IsVisibleAt(int index) =0;
264 // Change the visibility of the specified |command_id|. Returns true on
268 virtual bool SetVisible(int command_id, bool visible) =0;
271 // Change the visibility at the specified |index|. Returns true on success.
274 virtual bool SetVisibleAt(int index, bool visible) =0;
277 // Returns true if the specified |command_id| is enabled.
280 virtual bool IsEnabled(int command_id) =0;
283 // Returns true if the specified |index| is enabled.
286 virtual bool IsEnabledAt(int index) =0;
289 // Change the enabled status of the specified |command_id|. Returns true on
293 virtual bool SetEnabled(int command_id, bool enabled) =0;
296 // Change the enabled status at the specified |index|. Returns true on
300 virtual bool SetEnabledAt(int index, bool enabled) =0;
303 // Returns true if the specified |command_id| is checked. Only applies to
304 // check and radio items.
307 virtual bool IsChecked(int command_id) =0;
310 // Returns true if the specified |index| is checked. Only applies to check
314 virtual bool IsCheckedAt(int index) =0;
317 // Check the specified |command_id|. Only applies to check and radio items.
318 // Returns true on success.
321 virtual bool SetChecked(int command_id, bool checked) =0;
324 // Check the specified |index|. Only applies to check and radio items. Returns
328 virtual bool SetCheckedAt(int index, bool checked) =0;
331 // Returns true if the specified |command_id| has a keyboard accelerator
335 virtual bool HasAccelerator(int command_id) =0;
338 // Returns true if the specified |index| has a keyboard accelerator assigned.
341 virtual bool HasAcceleratorAt(int index) =0;
344 // Set the keyboard accelerator for the specified |command_id|. |key_code| can
345 // be any virtual key or character value. Returns true on success.
348 virtual bool SetAccelerator(int command_id,
352 bool alt_pressed) =0;
355 // Set the keyboard accelerator at the specified |index|. |key_code| can be
356 // any virtual key or character value. Returns true on success.
359 virtual bool SetAcceleratorAt(int index,
363 bool alt_pressed) =0;
366 // Remove the keyboard accelerator for the specified |command_id|. Returns
370 virtual bool RemoveAccelerator(int command_id) =0;
373 // Remove the keyboard accelerator at the specified |index|. Returns true on
377 virtual bool RemoveAcceleratorAt(int index) =0;
380 // Retrieves the keyboard accelerator for the specified |command_id|. Returns
384 virtual bool GetAccelerator(int command_id,
388 bool& alt_pressed) =0;
391 // Retrieves the keyboard accelerator for the specified |index|. Returns true
395 virtual bool GetAcceleratorAt(int index,
399 bool& alt_pressed) =0;
402 #endif // CEF_INCLUDE_CEF_MENU_MODEL_H_