1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 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 12 // distribution. 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. 17 // 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. 29 // 30 // --------------------------------------------------------------------------- 31 // 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. 35 // 36 37 #ifndef CEF_INCLUDE_CEF_MENU_MODEL_H_ 38 #define CEF_INCLUDE_CEF_MENU_MODEL_H_ 39 #pragma once 40 41 #include "include/cef_base.h" 42 #include "include/cef_menu_model_delegate.h" 43 44 /// 45 // Supports creation and modification of menus. See cef_menu_id_t for the 46 // command ids that have default implementations. All user-defined command ids 47 // should be between MENU_ID_USER_FIRST and MENU_ID_USER_LAST. The methods of 48 // this class can only be accessed on the browser process the UI thread. 49 /// 50 /*--cef(source=library)--*/ 51 class CefMenuModel : public virtual CefBaseRefCounted { 52 public: 53 typedef cef_menu_item_type_t MenuItemType; 54 55 /// 56 // Create a new MenuModel with the specified |delegate|. 57 /// 58 /*--cef()--*/ 59 static CefRefPtr<CefMenuModel> CreateMenuModel( 60 CefRefPtr<CefMenuModelDelegate> delegate); 61 62 /// 63 // Returns true if this menu is a submenu. 64 /// 65 /*--cef()--*/ 66 virtual bool IsSubMenu() = 0; 67 68 /// 69 // Clears the menu. Returns true on success. 70 /// 71 /*--cef()--*/ 72 virtual bool Clear() = 0; 73 74 /// 75 // Returns the number of items in this menu. 76 /// 77 /*--cef()--*/ 78 virtual int GetCount() = 0; 79 80 /// 81 // Add a separator to the menu. Returns true on success. 82 /// 83 /*--cef()--*/ 84 virtual bool AddSeparator() = 0; 85 86 /// 87 // Add an item to the menu. Returns true on success. 88 /// 89 /*--cef()--*/ 90 virtual bool AddItem(int command_id, const CefString& label) = 0; 91 92 /// 93 // Add a check item to the menu. Returns true on success. 94 /// 95 /*--cef()--*/ 96 virtual bool AddCheckItem(int command_id, const CefString& label) = 0; 97 /// 98 // Add a radio item to the menu. Only a single item with the specified 99 // |group_id| can be checked at a time. Returns true on success. 100 /// 101 /*--cef()--*/ 102 virtual bool AddRadioItem(int command_id, 103 const CefString& label, 104 int group_id) = 0; 105 106 /// 107 // Add a sub-menu to the menu. The new sub-menu is returned. 108 /// 109 /*--cef()--*/ 110 virtual CefRefPtr<CefMenuModel> AddSubMenu(int command_id, 111 const CefString& label) = 0; 112 113 /// 114 // Insert a separator in the menu at the specified |index|. Returns true on 115 // success. 116 /// 117 /*--cef()--*/ 118 virtual bool InsertSeparatorAt(int index) = 0; 119 120 /// 121 // Insert an item in the menu at the specified |index|. Returns true on 122 // success. 123 /// 124 /*--cef()--*/ 125 virtual bool InsertItemAt(int index, 126 int command_id, 127 const CefString& label) = 0; 128 129 /// 130 // Insert a check item in the menu at the specified |index|. Returns true on 131 // success. 132 /// 133 /*--cef()--*/ 134 virtual bool InsertCheckItemAt(int index, 135 int command_id, 136 const CefString& label) = 0; 137 138 /// 139 // Insert a radio item in the menu at the specified |index|. Only a single 140 // item with the specified |group_id| can be checked at a time. Returns true 141 // on success. 142 /// 143 /*--cef()--*/ 144 virtual bool InsertRadioItemAt(int index, 145 int command_id, 146 const CefString& label, 147 int group_id) = 0; 148 149 /// 150 // Insert a sub-menu in the menu at the specified |index|. The new sub-menu 151 // is returned. 152 /// 153 /*--cef()--*/ 154 virtual CefRefPtr<CefMenuModel> InsertSubMenuAt(int index, 155 int command_id, 156 const CefString& label) = 0; 157 158 /// 159 // Removes the item with the specified |command_id|. Returns true on success. 160 /// 161 /*--cef()--*/ 162 virtual bool Remove(int command_id) = 0; 163 164 /// 165 // Removes the item at the specified |index|. Returns true on success. 166 /// 167 /*--cef()--*/ 168 virtual bool RemoveAt(int index) = 0; 169 170 /// 171 // Returns the index associated with the specified |command_id| or -1 if not 172 // found due to the command id not existing in the menu. 173 /// 174 /*--cef()--*/ 175 virtual int GetIndexOf(int command_id) = 0; 176 177 /// 178 // Returns the command id at the specified |index| or -1 if not found due to 179 // invalid range or the index being a separator. 180 /// 181 /*--cef()--*/ 182 virtual int GetCommandIdAt(int index) = 0; 183 184 /// 185 // Sets the command id at the specified |index|. Returns true on success. 186 /// 187 /*--cef()--*/ 188 virtual bool SetCommandIdAt(int index, int command_id) = 0; 189 190 /// 191 // Returns the label for the specified |command_id| or empty if not found. 192 /// 193 /*--cef()--*/ 194 virtual CefString GetLabel(int command_id) = 0; 195 196 /// 197 // Returns the label at the specified |index| or empty if not found due to 198 // invalid range or the index being a separator. 199 /// 200 /*--cef()--*/ 201 virtual CefString GetLabelAt(int index) = 0; 202 203 /// 204 // Sets the label for the specified |command_id|. Returns true on success. 205 /// 206 /*--cef()--*/ 207 virtual bool SetLabel(int command_id, const CefString& label) = 0; 208 209 /// 210 // Set the label at the specified |index|. Returns true on success. 211 /// 212 /*--cef()--*/ 213 virtual bool SetLabelAt(int index, const CefString& label) = 0; 214 215 /// 216 // Returns the item type for the specified |command_id|. 217 /// 218 /*--cef(default_retval=MENUITEMTYPE_NONE)--*/ 219 virtual MenuItemType GetType(int command_id) = 0; 220 221 /// 222 // Returns the item type at the specified |index|. 223 /// 224 /*--cef(default_retval=MENUITEMTYPE_NONE)--*/ 225 virtual MenuItemType GetTypeAt(int index) = 0; 226 227 /// 228 // Returns the group id for the specified |command_id| or -1 if invalid. 229 /// 230 /*--cef()--*/ 231 virtual int GetGroupId(int command_id) = 0; 232 233 /// 234 // Returns the group id at the specified |index| or -1 if invalid. 235 /// 236 /*--cef()--*/ 237 virtual int GetGroupIdAt(int index) = 0; 238 239 /// 240 // Sets the group id for the specified |command_id|. Returns true on success. 241 /// 242 /*--cef()--*/ 243 virtual bool SetGroupId(int command_id, int group_id) = 0; 244 245 /// 246 // Sets the group id at the specified |index|. Returns true on success. 247 /// 248 /*--cef()--*/ 249 virtual bool SetGroupIdAt(int index, int group_id) = 0; 250 251 /// 252 // Returns the submenu for the specified |command_id| or empty if invalid. 253 /// 254 /*--cef()--*/ 255 virtual CefRefPtr<CefMenuModel> GetSubMenu(int command_id) = 0; 256 257 /// 258 // Returns the submenu at the specified |index| or empty if invalid. 259 /// 260 /*--cef()--*/ 261 virtual CefRefPtr<CefMenuModel> GetSubMenuAt(int index) = 0; 262 263 /// 264 // Returns true if the specified |command_id| is visible. 265 /// 266 /*--cef()--*/ 267 virtual bool IsVisible(int command_id) = 0; 268 269 /// 270 // Returns true if the specified |index| is visible. 271 /// 272 /*--cef()--*/ 273 virtual bool IsVisibleAt(int index) = 0; 274 275 /// 276 // Change the visibility of the specified |command_id|. Returns true on 277 // success. 278 /// 279 /*--cef()--*/ 280 virtual bool SetVisible(int command_id, bool visible) = 0; 281 282 /// 283 // Change the visibility at the specified |index|. Returns true on success. 284 /// 285 /*--cef()--*/ 286 virtual bool SetVisibleAt(int index, bool visible) = 0; 287 288 /// 289 // Returns true if the specified |command_id| is enabled. 290 /// 291 /*--cef()--*/ 292 virtual bool IsEnabled(int command_id) = 0; 293 294 /// 295 // Returns true if the specified |index| is enabled. 296 /// 297 /*--cef()--*/ 298 virtual bool IsEnabledAt(int index) = 0; 299 300 /// 301 // Change the enabled status of the specified |command_id|. Returns true on 302 // success. 303 /// 304 /*--cef()--*/ 305 virtual bool SetEnabled(int command_id, bool enabled) = 0; 306 307 /// 308 // Change the enabled status at the specified |index|. Returns true on 309 // success. 310 /// 311 /*--cef()--*/ 312 virtual bool SetEnabledAt(int index, bool enabled) = 0; 313 314 /// 315 // Returns true if the specified |command_id| is checked. Only applies to 316 // check and radio items. 317 /// 318 /*--cef()--*/ 319 virtual bool IsChecked(int command_id) = 0; 320 321 /// 322 // Returns true if the specified |index| is checked. Only applies to check 323 // and radio items. 324 /// 325 /*--cef()--*/ 326 virtual bool IsCheckedAt(int index) = 0; 327 328 /// 329 // Check the specified |command_id|. Only applies to check and radio items. 330 // Returns true on success. 331 /// 332 /*--cef()--*/ 333 virtual bool SetChecked(int command_id, bool checked) = 0; 334 335 /// 336 // Check the specified |index|. Only applies to check and radio items. Returns 337 // true on success. 338 /// 339 /*--cef()--*/ 340 virtual bool SetCheckedAt(int index, bool checked) = 0; 341 342 /// 343 // Returns true if the specified |command_id| has a keyboard accelerator 344 // assigned. 345 /// 346 /*--cef()--*/ 347 virtual bool HasAccelerator(int command_id) = 0; 348 349 /// 350 // Returns true if the specified |index| has a keyboard accelerator assigned. 351 /// 352 /*--cef()--*/ 353 virtual bool HasAcceleratorAt(int index) = 0; 354 355 /// 356 // Set the keyboard accelerator for the specified |command_id|. |key_code| can 357 // be any virtual key or character value. Returns true on success. 358 /// 359 /*--cef()--*/ 360 virtual bool SetAccelerator(int command_id, 361 int key_code, 362 bool shift_pressed, 363 bool ctrl_pressed, 364 bool alt_pressed) = 0; 365 366 /// 367 // Set the keyboard accelerator at the specified |index|. |key_code| can be 368 // any virtual key or character value. Returns true on success. 369 /// 370 /*--cef()--*/ 371 virtual bool SetAcceleratorAt(int index, 372 int key_code, 373 bool shift_pressed, 374 bool ctrl_pressed, 375 bool alt_pressed) = 0; 376 377 /// 378 // Remove the keyboard accelerator for the specified |command_id|. Returns 379 // true on success. 380 /// 381 /*--cef()--*/ 382 virtual bool RemoveAccelerator(int command_id) = 0; 383 384 /// 385 // Remove the keyboard accelerator at the specified |index|. Returns true on 386 // success. 387 /// 388 /*--cef()--*/ 389 virtual bool RemoveAcceleratorAt(int index) = 0; 390 391 /// 392 // Retrieves the keyboard accelerator for the specified |command_id|. Returns 393 // true on success. 394 /// 395 /*--cef()--*/ 396 virtual bool GetAccelerator(int command_id, 397 int& key_code, 398 bool& shift_pressed, 399 bool& ctrl_pressed, 400 bool& alt_pressed) = 0; 401 402 /// 403 // Retrieves the keyboard accelerator for the specified |index|. Returns true 404 // on success. 405 /// 406 /*--cef()--*/ 407 virtual bool GetAcceleratorAt(int index, 408 int& key_code, 409 bool& shift_pressed, 410 bool& ctrl_pressed, 411 bool& alt_pressed) = 0; 412 413 /// 414 // Set the explicit color for |command_id| and |color_type| to |color|. 415 // Specify a |color| value of 0 to remove the explicit color. If no explicit 416 // color or default color is set for |color_type| then the system color will 417 // be used. Returns true on success. 418 /// 419 /*--cef()--*/ 420 virtual bool SetColor(int command_id, 421 cef_menu_color_type_t color_type, 422 cef_color_t color) = 0; 423 424 /// 425 // Set the explicit color for |command_id| and |index| to |color|. Specify a 426 // |color| value of 0 to remove the explicit color. Specify an |index| value 427 // of -1 to set the default color for items that do not have an explicit 428 // color set. If no explicit color or default color is set for |color_type| 429 // then the system color will be used. Returns true on success. 430 /// 431 /*--cef()--*/ 432 virtual bool SetColorAt(int index, 433 cef_menu_color_type_t color_type, 434 cef_color_t color) = 0; 435 436 /// 437 // Returns in |color| the color that was explicitly set for |command_id| and 438 // |color_type|. If a color was not set then 0 will be returned in |color|. 439 // Returns true on success. 440 /// 441 /*--cef()--*/ 442 virtual bool GetColor(int command_id, 443 cef_menu_color_type_t color_type, 444 cef_color_t& color) = 0; 445 446 /// 447 // Returns in |color| the color that was explicitly set for |command_id| and 448 // |color_type|. Specify an |index| value of -1 to return the default color 449 // in |color|. If a color was not set then 0 will be returned in |color|. 450 // Returns true on success. 451 /// 452 /*--cef()--*/ 453 virtual bool GetColorAt(int index, 454 cef_menu_color_type_t color_type, 455 cef_color_t& color) = 0; 456 457 /// 458 // Sets the font list for the specified |command_id|. If |font_list| is empty 459 // the system font will be used. Returns true on success. The format is 460 // "<FONT_FAMILY_LIST>,[STYLES] <SIZE>", where: 461 // - FONT_FAMILY_LIST is a comma-separated list of font family names, 462 // - STYLES is an optional space-separated list of style names (case-sensitive 463 // "Bold" and "Italic" are supported), and 464 // - SIZE is an integer font size in pixels with the suffix "px". 465 // 466 // Here are examples of valid font description strings: 467 // - "Arial, Helvetica, Bold Italic 14px" 468 // - "Arial, 14px" 469 /// 470 /*--cef(optional_param=font_list)--*/ 471 virtual bool SetFontList(int command_id, const CefString& font_list) = 0; 472 473 /// 474 // Sets the font list for the specified |index|. Specify an |index| value of 475 // -1 to set the default font. If |font_list| is empty the system font will 476 // be used. Returns true on success. The format is 477 // "<FONT_FAMILY_LIST>,[STYLES] <SIZE>", where: 478 // - FONT_FAMILY_LIST is a comma-separated list of font family names, 479 // - STYLES is an optional space-separated list of style names (case-sensitive 480 // "Bold" and "Italic" are supported), and 481 // - SIZE is an integer font size in pixels with the suffix "px". 482 // 483 // Here are examples of valid font description strings: 484 // - "Arial, Helvetica, Bold Italic 14px" 485 // - "Arial, 14px" 486 /// 487 /*--cef(optional_param=font_list)--*/ 488 virtual bool SetFontListAt(int index, const CefString& font_list) = 0; 489 }; 490 491 #endif // CEF_INCLUDE_CEF_MENU_MODEL_H_ 492