popupMenu.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "sim/simBase.h"
  23. #include "collection/vector.h"
  24. #include "messaging/dispatcher.h"
  25. #ifndef _POPUPMENU_H_
  26. #define _POPUPMENU_H_
  27. // Forward ref used by the platform code
  28. struct PlatformPopupMenuData;
  29. // PopupMenu represents a menu.
  30. // You can add menu items to the menu, but there is no torque object associated
  31. // with these menu items, they exist only in a platform specific manner.
  32. class PopupMenu : public SimObject, public virtual Dispatcher::IMessageListener
  33. {
  34. typedef SimObject Parent;
  35. protected:
  36. PlatformPopupMenuData *mData;
  37. SimSet *mSubmenus;
  38. bool mIsPopup;
  39. public:
  40. PopupMenu();
  41. virtual ~PopupMenu();
  42. void createPlatformPopupMenuData();
  43. void deletePlatformPopupMenuData();
  44. DECLARE_CONOBJECT(PopupMenu);
  45. static void initPersistFields();
  46. virtual bool onAdd();
  47. virtual void onRemove();
  48. /// Creates the platform specific menu object, a peer to this object.
  49. /// The platform menu *must* exist before calling any method that manipulates
  50. /// menu items or displays the menu.
  51. /// implementd on a per-platform basis.
  52. void createPlatformMenu();
  53. /// pass NULL for @p title to insert a separator
  54. /// returns the menu item's ID, or -1 on failure.
  55. /// implementd on a per-platform basis.
  56. /// TODO: factor out common code
  57. S32 insertItem(S32 pos, const char *title, const char* accelerator);
  58. /// pass NULL for @p title to insert a separator
  59. /// returns the menu item's ID, or -1 on failure.
  60. /// adds the submenu to the mSubmenus vector.
  61. /// implemented on a per-platform basis.
  62. /// TODO: factor out common code
  63. S32 insertSubMenu(S32 pos, const char *title, PopupMenu *submenu);
  64. /// remove the menu item at @p itemPos
  65. /// if the item has a submenu, it is removed from the mSubmenus list.
  66. /// implemented on a per-platform basis.
  67. /// TODO: factor out common code
  68. void removeItem(S32 itemPos);
  69. /// implemented on a per-platform basis.
  70. void enableItem(S32 pos, bool enable);
  71. /// implemented on a per-platform basis.
  72. void checkItem(S32 pos, bool checked);
  73. /// All items at positions firstPos through lastPos are unchecked, and the
  74. /// item at checkPos is checked.
  75. /// implemented on a per-platform basis.
  76. void checkRadioItem(S32 firstPos, S32 lastPos, S32 checkPos);
  77. bool isItemChecked(S32 pos);
  78. /// Places this menu in the menu bar of the application's main window.
  79. /// @param pos The relative position at which to place the menu.
  80. /// @param title The name of the menu
  81. void attachToMenuBar(S32 pos, const char *title);
  82. /// Removes this menu from the menu bar.
  83. void removeFromMenuBar();
  84. /// Displays this menu as a popup menu and blocks until the user has selected
  85. /// an item.
  86. /// @param x window local x coordinate at which to display the popup menu
  87. /// @param y window local y coordinate at which to display the popup menu
  88. /// implemented on a per-platform basis.
  89. void showPopup(S32 x = -1, S32 y = -1);
  90. /// Returns true iff this menu contains an item that matches @p iD.
  91. /// implemented on a per-platform basis.
  92. /// TODO: factor out common code
  93. bool canHandleID(U32 iD);
  94. /// A menu item in this menu has been selected by id.
  95. /// Submenus are given a chance to respond to the command first.
  96. /// If no submenu can handle the command id, this menu handles it.
  97. /// The script callback this::onSelectItem( position, text) is called.
  98. /// If @p text is null, then the text arg passed to script is the text of
  99. /// the selected menu item.
  100. /// implemented on a per-platform basis.
  101. /// TODO: factor out common code
  102. bool handleSelect(U32 command, const char *text = NULL);
  103. virtual bool onMessageReceived(StringTableEntry queue, const char* event, const char* data );
  104. virtual bool onMessageObjectReceived(StringTableEntry queue, Message *msg );
  105. };
  106. #endif // _POPUPMENU_H_