Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

735 lines
32KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_POPUPMENU_H_INCLUDED
  18. #define JUCE_POPUPMENU_H_INCLUDED
  19. //==============================================================================
  20. /** Creates and displays a popup-menu.
  21. To show a popup-menu, you create one of these, add some items to it, then
  22. call its show() method, which returns the id of the item the user selects.
  23. E.g. @code
  24. void MyWidget::mouseDown (const MouseEvent& e)
  25. {
  26. PopupMenu m;
  27. m.addItem (1, "item 1");
  28. m.addItem (2, "item 2");
  29. const int result = m.show();
  30. if (result == 0)
  31. {
  32. // user dismissed the menu without picking anything
  33. }
  34. else if (result == 1)
  35. {
  36. // user picked item 1
  37. }
  38. else if (result == 2)
  39. {
  40. // user picked item 2
  41. }
  42. }
  43. @endcode
  44. Submenus are easy too: @code
  45. void MyWidget::mouseDown (const MouseEvent& e)
  46. {
  47. PopupMenu subMenu;
  48. subMenu.addItem (1, "item 1");
  49. subMenu.addItem (2, "item 2");
  50. PopupMenu mainMenu;
  51. mainMenu.addItem (3, "item 3");
  52. mainMenu.addSubMenu ("other choices", subMenu);
  53. const int result = m.show();
  54. ...etc
  55. }
  56. @endcode
  57. */
  58. class JUCE_API PopupMenu
  59. {
  60. private:
  61. class Window;
  62. public:
  63. class CustomComponent;
  64. class CustomCallback;
  65. //==============================================================================
  66. /** Creates an empty popup menu. */
  67. PopupMenu();
  68. /** Creates a copy of another menu. */
  69. PopupMenu (const PopupMenu& other);
  70. /** Destructor. */
  71. ~PopupMenu();
  72. /** Copies this menu from another one. */
  73. PopupMenu& operator= (const PopupMenu& other);
  74. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  75. PopupMenu (PopupMenu&& other) noexcept;
  76. PopupMenu& operator= (PopupMenu&& other) noexcept;
  77. #endif
  78. //==============================================================================
  79. /** Resets the menu, removing all its items. */
  80. void clear();
  81. /** Describes a popup menu item. */
  82. struct JUCE_API Item
  83. {
  84. /** Creates a null item.
  85. You'll need to set some fields after creating an Item before you
  86. can add it to a PopupMenu
  87. */
  88. Item() noexcept;
  89. /** Creates a copy of an item. */
  90. Item (const Item&);
  91. /** Creates a copy of an item. */
  92. Item& operator= (const Item&);
  93. /** The menu item's name. */
  94. String text;
  95. /** The menu item's ID. This can not be 0 if you want the item to be triggerable! */
  96. int itemID;
  97. /** A sub-menu, or nullptr if there isn't one. */
  98. ScopedPointer<PopupMenu> subMenu;
  99. /** A drawable to use as an icon, or nullptr if there isn't one. */
  100. ScopedPointer<Drawable> image;
  101. /** A custom component for the item to display, or nullptr if there isn't one. */
  102. ReferenceCountedObjectPtr<CustomComponent> customComponent;
  103. /** A custom callback for the item to use, or nullptr if there isn't one. */
  104. ReferenceCountedObjectPtr<CustomCallback> customCallback;
  105. /** A command manager to use to automatically invoke the command, or nullptr if none is specified. */
  106. ApplicationCommandManager* commandManager;
  107. /** An optional string describing the shortcut key for this item.
  108. This is only used for displaying at the right-hand edge of a menu item - the
  109. menu won't attempt to actually catch or process the key. If you supply a
  110. commandManager parameter then the menu will attempt to fill-in this field
  111. automatically.
  112. */
  113. String shortcutKeyDescription;
  114. /** A colour to use to draw the menu text.
  115. By default this is transparent black, which means that the LookAndFeel should choose the colour.
  116. */
  117. Colour colour;
  118. /** True if this menu item is enabled. */
  119. bool isEnabled;
  120. /** True if this menu item should have a tick mark next to it. */
  121. bool isTicked;
  122. /** True if this menu item is a separator line. */
  123. bool isSeparator;
  124. /** True if this menu item is a section header. */
  125. bool isSectionHeader;
  126. };
  127. /** Adds an item to the menu.
  128. You can call this method for full control over the item that is added, or use the other
  129. addItem helper methods if you want to pass arguments rather than creating an Item object.
  130. */
  131. void addItem (const Item& newItem);
  132. /** Appends a new text item for this menu to show.
  133. @param itemResultID the number that will be returned from the show() method
  134. if the user picks this item. The value should never be
  135. zero, because that's used to indicate that the user didn't
  136. select anything.
  137. @param itemText the text to show.
  138. @param isEnabled if false, the item will be shown 'greyed-out' and can't be picked
  139. @param isTicked if true, the item will be shown with a tick next to it
  140. @see addSeparator, addColouredItem, addCustomItem, addSubMenu
  141. */
  142. void addItem (int itemResultID,
  143. const String& itemText,
  144. bool isEnabled = true,
  145. bool isTicked = false);
  146. /** Appends a new item with an icon.
  147. @param itemResultID the number that will be returned from the show() method
  148. if the user picks this item. The value should never be
  149. zero, because that's used to indicate that the user didn't
  150. select anything.
  151. @param itemText the text to show.
  152. @param isEnabled if false, the item will be shown 'greyed-out' and can't be picked
  153. @param isTicked if true, the item will be shown with a tick next to it
  154. @param iconToUse if this is a valid image, it will be displayed to the left of the item.
  155. @see addSeparator, addColouredItem, addCustomItem, addSubMenu
  156. */
  157. void addItem (int itemResultID,
  158. const String& itemText,
  159. bool isEnabled,
  160. bool isTicked,
  161. const Image& iconToUse);
  162. /** Appends a new item with an icon.
  163. @param itemResultID the number that will be returned from the show() method
  164. if the user picks this item. The value should never be
  165. zero, because that's used to indicate that the user didn't
  166. select anything.
  167. @param itemText the text to show.
  168. @param isEnabled if false, the item will be shown 'greyed-out' and can't be picked
  169. @param isTicked if true, the item will be shown with a tick next to it
  170. @param iconToUse a Drawable object to use as the icon to the left of the item.
  171. The menu will take ownership of this drawable object and will
  172. delete it later when no longer needed
  173. @see addSeparator, addColouredItem, addCustomItem, addSubMenu
  174. */
  175. void addItem (int itemResultID,
  176. const String& itemText,
  177. bool isEnabled,
  178. bool isTicked,
  179. Drawable* iconToUse);
  180. /** Adds an item that represents one of the commands in a command manager object.
  181. @param commandManager the manager to use to trigger the command and get information
  182. about it
  183. @param commandID the ID of the command
  184. @param displayName if this is non-empty, then this string will be used instead of
  185. the command's registered name
  186. @param iconToUse an optional Drawable object to use as the icon to the left of the item.
  187. The menu will take ownership of this drawable object and will
  188. delete it later when no longer needed
  189. */
  190. void addCommandItem (ApplicationCommandManager* commandManager,
  191. CommandID commandID,
  192. const String& displayName = String(),
  193. Drawable* iconToUse = nullptr);
  194. /** Appends a text item with a special colour.
  195. This is the same as addItem(), but specifies a colour to use for the
  196. text, which will override the default colours that are used by the
  197. current look-and-feel. See addItem() for a description of the parameters.
  198. */
  199. void addColouredItem (int itemResultID,
  200. const String& itemText,
  201. Colour itemTextColour,
  202. bool isEnabled = true,
  203. bool isTicked = false,
  204. const Image& iconToUse = Image());
  205. /** Appends a text item with a special colour.
  206. This is the same as addItem(), but specifies a colour to use for the
  207. text, which will override the default colours that are used by the
  208. current look-and-feel. See addItem() for a description of the parameters.
  209. */
  210. void addColouredItem (int itemResultID,
  211. const String& itemText,
  212. Colour itemTextColour,
  213. bool isEnabled,
  214. bool isTicked,
  215. Drawable* iconToUse);
  216. /** Appends a custom menu item.
  217. This will add a user-defined component to use as a menu item. The component
  218. passed in will be deleted by this menu when it's no longer needed.
  219. @see CustomComponent
  220. */
  221. void addCustomItem (int itemResultID,
  222. CustomComponent* customComponent,
  223. const PopupMenu* optionalSubMenu = nullptr);
  224. /** Appends a custom menu item that can't be used to trigger a result.
  225. This will add a user-defined component to use as a menu item.
  226. It's the caller's responsibility to delete the component that is passed-in
  227. when it's no longer needed after the menu has been hidden.
  228. If triggerMenuItemAutomaticallyWhenClicked is true, the menu itself will handle
  229. detection of a mouse-click on your component, and use that to trigger the
  230. menu ID specified in itemResultID. If this is false, the menu item can't
  231. be triggered, so itemResultID is not used.
  232. */
  233. void addCustomItem (int itemResultID,
  234. Component* customComponent,
  235. int idealWidth,
  236. int idealHeight,
  237. bool triggerMenuItemAutomaticallyWhenClicked,
  238. const PopupMenu* optionalSubMenu = nullptr);
  239. /** Appends a sub-menu.
  240. If the menu that's passed in is empty, it will appear as an inactive item.
  241. If the itemResultID argument is non-zero, then the sub-menu item itself can be
  242. clicked to trigger it as a command.
  243. */
  244. void addSubMenu (const String& subMenuName,
  245. const PopupMenu& subMenu,
  246. bool isEnabled = true);
  247. /** Appends a sub-menu with an icon.
  248. If the menu that's passed in is empty, it will appear as an inactive item.
  249. If the itemResultID argument is non-zero, then the sub-menu item itself can be
  250. clicked to trigger it as a command.
  251. */
  252. void addSubMenu (const String& subMenuName,
  253. const PopupMenu& subMenu,
  254. bool isEnabled,
  255. const Image& iconToUse,
  256. bool isTicked = false,
  257. int itemResultID = 0);
  258. /** Appends a sub-menu with an icon.
  259. If the menu that's passed in is empty, it will appear as an inactive item.
  260. If the itemResultID argument is non-zero, then the sub-menu item itself can be
  261. clicked to trigger it as a command.
  262. The iconToUse parameter is a Drawable object to use as the icon to the left of
  263. the item. The menu will take ownership of this drawable object and will delete it
  264. later when no longer needed
  265. */
  266. void addSubMenu (const String& subMenuName,
  267. const PopupMenu& subMenu,
  268. bool isEnabled,
  269. Drawable* iconToUse,
  270. bool isTicked = false,
  271. int itemResultID = 0);
  272. /** Appends a separator to the menu, to help break it up into sections.
  273. The menu class is smart enough not to display separators at the top or bottom
  274. of the menu, and it will replace mutliple adjacent separators with a single
  275. one, so your code can be quite free and easy about adding these, and it'll
  276. always look ok.
  277. */
  278. void addSeparator();
  279. /** Adds a non-clickable text item to the menu.
  280. This is a bold-font items which can be used as a header to separate the items
  281. into named groups.
  282. */
  283. void addSectionHeader (const String& title);
  284. /** Returns the number of items that the menu currently contains.
  285. (This doesn't count separators).
  286. */
  287. int getNumItems() const noexcept;
  288. /** Returns true if the menu contains a command item that triggers the given command. */
  289. bool containsCommandItem (int commandID) const;
  290. /** Returns true if the menu contains any items that can be used. */
  291. bool containsAnyActiveItems() const noexcept;
  292. //==============================================================================
  293. /** Class used to create a set of options to pass to the show() method.
  294. You can chain together a series of calls to this class's methods to create
  295. a set of whatever options you want to specify.
  296. E.g. @code
  297. PopupMenu menu;
  298. ...
  299. menu.showMenu (PopupMenu::Options().withMinimumWidth (100)
  300. .withMaximumNumColumns (3)
  301. .withTargetComponent (myComp));
  302. @endcode
  303. */
  304. class JUCE_API Options
  305. {
  306. public:
  307. Options();
  308. //==============================================================================
  309. Options withTargetComponent (Component* targetComponent) const noexcept;
  310. Options withTargetScreenArea (const Rectangle<int>& targetArea) const noexcept;
  311. Options withMinimumWidth (int minWidth) const noexcept;
  312. Options withMaximumNumColumns (int maxNumColumns) const noexcept;
  313. Options withStandardItemHeight (int standardHeight) const noexcept;
  314. Options withItemThatMustBeVisible (int idOfItemToBeVisible) const noexcept;
  315. Options withParentComponent (Component* parentComponent) const noexcept;
  316. //==============================================================================
  317. Component* getParentComponent() const noexcept { return parentComponent; }
  318. Component* getTargetComponent() const noexcept { return targetComponent; }
  319. Rectangle<int> getTargetScreenArea() const noexcept { return targetArea; }
  320. int getMinimumWidth() const noexcept { return minWidth; }
  321. int getMaximumNumColumns() const noexcept { return maxColumns; }
  322. int getStandardItemHeight() const noexcept { return standardHeight; }
  323. int getItemThatMustBeVisible() const noexcept { return visibleItemID; }
  324. private:
  325. //==============================================================================
  326. friend class PopupMenu;
  327. friend class PopupMenu::Window;
  328. Rectangle<int> targetArea;
  329. Component* targetComponent;
  330. Component* parentComponent;
  331. int visibleItemID, minWidth, maxColumns, standardHeight;
  332. };
  333. //==============================================================================
  334. #if JUCE_MODAL_LOOPS_PERMITTED
  335. /** Displays the menu and waits for the user to pick something.
  336. This will display the menu modally, and return the ID of the item that the
  337. user picks. If they click somewhere off the menu to get rid of it without
  338. choosing anything, this will return 0.
  339. The current location of the mouse will be used as the position to show the
  340. menu - to explicitly set the menu's position, use showAt() instead. Depending
  341. on where this point is on the screen, the menu will appear above, below or
  342. to the side of the point.
  343. @param itemIDThatMustBeVisible if you set this to the ID of one of the menu items,
  344. then when the menu first appears, it will make sure
  345. that this item is visible. So if the menu has too many
  346. items to fit on the screen, it will be scrolled to a
  347. position where this item is visible.
  348. @param minimumWidth a minimum width for the menu, in pixels. It may be wider
  349. than this if some items are too long to fit.
  350. @param maximumNumColumns if there are too many items to fit on-screen in a single
  351. vertical column, the menu may be laid out as a series of
  352. columns - this is the maximum number allowed. To use the
  353. default value for this (probably about 7), you can pass
  354. in zero.
  355. @param standardItemHeight if this is non-zero, it will be used as the standard
  356. height for menu items (apart from custom items)
  357. @param callback if this is not a nullptr, the menu will be launched
  358. asynchronously, returning immediately, and the callback
  359. will receive a call when the menu is either dismissed or
  360. has an item selected. This object will be owned and
  361. deleted by the system, so make sure that it works safely
  362. and that any pointers that it uses are safely within scope.
  363. @see showAt
  364. */
  365. int show (int itemIDThatMustBeVisible = 0,
  366. int minimumWidth = 0,
  367. int maximumNumColumns = 0,
  368. int standardItemHeight = 0,
  369. ModalComponentManager::Callback* callback = nullptr);
  370. /** Displays the menu at a specific location.
  371. This is the same as show(), but uses a specific location (in global screen
  372. coordinates) rather than the current mouse position.
  373. The screenAreaToAttachTo parameter indicates a screen area to which the menu
  374. will be adjacent. Depending on where this is, the menu will decide which edge to
  375. attach itself to, in order to fit itself fully on-screen. If you just want to
  376. trigger a menu at a specific point, you can pass in a rectangle of size (0, 0)
  377. with the position that you want.
  378. @see show()
  379. */
  380. int showAt (const Rectangle<int>& screenAreaToAttachTo,
  381. int itemIDThatMustBeVisible = 0,
  382. int minimumWidth = 0,
  383. int maximumNumColumns = 0,
  384. int standardItemHeight = 0,
  385. ModalComponentManager::Callback* callback = nullptr);
  386. /** Displays the menu as if it's attached to a component such as a button.
  387. This is similar to showAt(), but will position it next to the given component, e.g.
  388. so that the menu's edge is aligned with that of the component. This is intended for
  389. things like buttons that trigger a pop-up menu.
  390. */
  391. int showAt (Component* componentToAttachTo,
  392. int itemIDThatMustBeVisible = 0,
  393. int minimumWidth = 0,
  394. int maximumNumColumns = 0,
  395. int standardItemHeight = 0,
  396. ModalComponentManager::Callback* callback = nullptr);
  397. /** Displays and runs the menu modally, with a set of options.
  398. */
  399. int showMenu (const Options& options);
  400. #endif
  401. /** Runs the menu asynchronously, with a user-provided callback that will receive the result. */
  402. void showMenuAsync (const Options& options,
  403. ModalComponentManager::Callback* callback);
  404. //==============================================================================
  405. /** Closes any menus that are currently open.
  406. This might be useful if you have a situation where your window is being closed
  407. by some means other than a user action, and you'd like to make sure that menus
  408. aren't left hanging around.
  409. */
  410. static bool JUCE_CALLTYPE dismissAllActiveMenus();
  411. //==============================================================================
  412. /** Specifies a look-and-feel for the menu and any sub-menus that it has.
  413. This can be called before show() if you need a customised menu. Be careful
  414. not to delete the LookAndFeel object before the menu has been deleted.
  415. */
  416. void setLookAndFeel (LookAndFeel* newLookAndFeel);
  417. //==============================================================================
  418. /** A set of colour IDs to use to change the colour of various aspects of the menu.
  419. These constants can be used either via the LookAndFeel::setColour()
  420. method for the look and feel that is set for this menu with setLookAndFeel()
  421. @see setLookAndFeel, LookAndFeel::setColour, LookAndFeel::findColour
  422. */
  423. enum ColourIds
  424. {
  425. backgroundColourId = 0x1000700, /**< The colour to fill the menu's background with. */
  426. textColourId = 0x1000600, /**< The colour for normal menu item text, (unless the
  427. colour is specified when the item is added). */
  428. headerTextColourId = 0x1000601, /**< The colour for section header item text (see the
  429. addSectionHeader() method). */
  430. highlightedBackgroundColourId = 0x1000900, /**< The colour to fill the background of the currently
  431. highlighted menu item. */
  432. highlightedTextColourId = 0x1000800, /**< The colour to use for the text of the currently
  433. highlighted item. */
  434. };
  435. //==============================================================================
  436. /**
  437. Allows you to iterate through the items in a pop-up menu, and examine
  438. their properties.
  439. To use this, just create one and repeatedly call its next() method. When this
  440. returns true, all the member variables of the iterator are filled-out with
  441. information describing the menu item. When it returns false, the end of the
  442. list has been reached.
  443. */
  444. class JUCE_API MenuItemIterator
  445. {
  446. public:
  447. //==============================================================================
  448. /** Creates an iterator that will scan through the items in the specified
  449. menu.
  450. Be careful not to add any items to a menu while it is being iterated,
  451. or things could get out of step.
  452. */
  453. MenuItemIterator (const PopupMenu& menu);
  454. /** Destructor. */
  455. ~MenuItemIterator();
  456. /** Returns true if there is another item, and sets up all this object's
  457. member variables to reflect that item's properties.
  458. */
  459. bool next();
  460. /** Returns a reference to the description of the current item.
  461. It is only valid to call this after next() has returned true!
  462. */
  463. const Item& getItem() const noexcept;
  464. private:
  465. //==============================================================================
  466. const PopupMenu& menu;
  467. int index;
  468. MenuItemIterator& operator= (const MenuItemIterator&);
  469. JUCE_LEAK_DETECTOR (MenuItemIterator)
  470. };
  471. //==============================================================================
  472. /** A user-defined component that can be used as an item in a popup menu.
  473. @see PopupMenu::addCustomItem
  474. */
  475. class JUCE_API CustomComponent : public Component,
  476. public SingleThreadedReferenceCountedObject
  477. {
  478. public:
  479. /** Creates a custom item.
  480. If isTriggeredAutomatically is true, then the menu will automatically detect
  481. a mouse-click on this component and use that to invoke the menu item. If it's
  482. false, then it's up to your class to manually trigger the item when it wants to.
  483. */
  484. CustomComponent (bool isTriggeredAutomatically = true);
  485. /** Destructor. */
  486. ~CustomComponent();
  487. /** Returns a rectangle with the size that this component would like to have.
  488. Note that the size which this method returns isn't necessarily the one that
  489. the menu will give it, as the items will be stretched to have a uniform width.
  490. */
  491. virtual void getIdealSize (int& idealWidth, int& idealHeight) = 0;
  492. /** Dismisses the menu, indicating that this item has been chosen.
  493. This will cause the menu to exit from its modal state, returning
  494. this item's id as the result.
  495. */
  496. void triggerMenuItem();
  497. /** Returns true if this item should be highlighted because the mouse is over it.
  498. You can call this method in your paint() method to find out whether
  499. to draw a highlight.
  500. */
  501. bool isItemHighlighted() const noexcept { return isHighlighted; }
  502. /** @internal */
  503. bool isTriggeredAutomatically() const noexcept { return triggeredAutomatically; }
  504. /** @internal */
  505. void setHighlighted (bool shouldBeHighlighted);
  506. private:
  507. //==============================================================================
  508. bool isHighlighted, triggeredAutomatically;
  509. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CustomComponent)
  510. };
  511. //==============================================================================
  512. /** A user-defined callback that can be used for specific items in a popup menu.
  513. @see PopupMenu::Item::customCallback
  514. */
  515. class JUCE_API CustomCallback : public SingleThreadedReferenceCountedObject
  516. {
  517. public:
  518. CustomCallback();
  519. ~CustomCallback();
  520. /** Callback to indicate this item has been triggered.
  521. @returns true if the itemID should be sent to the exitModalState method, or
  522. false if it should send 0, indicating no further action should be taken
  523. */
  524. virtual bool menuItemTriggered() = 0;
  525. private:
  526. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CustomCallback)
  527. };
  528. //==============================================================================
  529. /** This abstract base class is implemented by LookAndFeel classes to provide
  530. menu drawing functionality.
  531. */
  532. struct JUCE_API LookAndFeelMethods
  533. {
  534. virtual ~LookAndFeelMethods() {}
  535. /** Fills the background of a popup menu component. */
  536. virtual void drawPopupMenuBackground (Graphics&, int width, int height) = 0;
  537. /** Draws one of the items in a popup menu. */
  538. virtual void drawPopupMenuItem (Graphics&, const Rectangle<int>& area,
  539. bool isSeparator, bool isActive, bool isHighlighted,
  540. bool isTicked, bool hasSubMenu,
  541. const String& text,
  542. const String& shortcutKeyText,
  543. const Drawable* icon,
  544. const Colour* textColour) = 0;
  545. virtual void drawPopupMenuSectionHeader (Graphics&, const Rectangle<int>& area,
  546. const String& sectionName) = 0;
  547. /** Returns the size and style of font to use in popup menus. */
  548. virtual Font getPopupMenuFont() = 0;
  549. virtual void drawPopupMenuUpDownArrow (Graphics&,
  550. int width, int height,
  551. bool isScrollUpArrow) = 0;
  552. /** Finds the best size for an item in a popup menu. */
  553. virtual void getIdealPopupMenuItemSize (const String& text,
  554. bool isSeparator,
  555. int standardMenuItemHeight,
  556. int& idealWidth,
  557. int& idealHeight) = 0;
  558. virtual int getMenuWindowFlags() = 0;
  559. virtual void drawMenuBarBackground (Graphics&, int width, int height,
  560. bool isMouseOverBar,
  561. MenuBarComponent&) = 0;
  562. virtual int getDefaultMenuBarHeight() = 0;
  563. virtual int getMenuBarItemWidth (MenuBarComponent&, int itemIndex, const String& itemText) = 0;
  564. virtual Font getMenuBarFont (MenuBarComponent&, int itemIndex, const String& itemText) = 0;
  565. virtual void drawMenuBarItem (Graphics&, int width, int height,
  566. int itemIndex,
  567. const String& itemText,
  568. bool isMouseOverItem,
  569. bool isMenuOpen,
  570. bool isMouseOverBar,
  571. MenuBarComponent&) = 0;
  572. virtual Component* getParentComponentForMenuOptions (const PopupMenu::Options& options) = 0;
  573. virtual void preparePopupMenuWindow (Component& newWindow) = 0;
  574. };
  575. private:
  576. //==============================================================================
  577. JUCE_PUBLIC_IN_DLL_BUILD (struct HelperClasses)
  578. friend struct HelperClasses;
  579. friend class MenuBarComponent;
  580. OwnedArray<Item> items;
  581. WeakReference<LookAndFeel> lookAndFeel;
  582. Component* createWindow (const Options&, ApplicationCommandManager**) const;
  583. int showWithOptionalCallback (const Options&, ModalComponentManager::Callback*, bool);
  584. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  585. // These methods have new implementations now - see its new definition
  586. int drawPopupMenuItem (Graphics&, int, int, bool, bool, bool, bool, bool, const String&, const String&, Image*, const Colour*) { return 0; }
  587. #endif
  588. JUCE_LEAK_DETECTOR (PopupMenu)
  589. };
  590. #endif // JUCE_POPUPMENU_H_INCLUDED