juce_ToolbarItemFactory.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A factory object which can create ToolbarItemComponent objects.
  24. A subclass of ToolbarItemFactory publishes a set of types of toolbar item
  25. that it can create.
  26. Each type of item is identified by a unique ID, and multiple instances of an
  27. item type can exist at once (even on the same toolbar, e.g. spacers or separator
  28. bars).
  29. @see Toolbar, ToolbarItemComponent, ToolbarButton
  30. @tags{GUI}
  31. */
  32. class JUCE_API ToolbarItemFactory
  33. {
  34. public:
  35. //==============================================================================
  36. ToolbarItemFactory();
  37. /** Destructor. */
  38. virtual ~ToolbarItemFactory();
  39. //==============================================================================
  40. /** A set of reserved item ID values, used for the built-in item types.
  41. */
  42. enum SpecialItemIds
  43. {
  44. separatorBarId = -1, /**< The item ID for a vertical (or horizontal) separator bar that
  45. can be placed between sets of items to break them into groups. */
  46. spacerId = -2, /**< The item ID for a fixed-width space that can be placed between
  47. items.*/
  48. flexibleSpacerId = -3 /**< The item ID for a gap that pushes outwards against the things on
  49. either side of it, filling any available space. */
  50. };
  51. //==============================================================================
  52. /** Must return a list of the IDs for all the item types that this factory can create.
  53. The ids should be added to the array that is passed-in.
  54. An item ID can be any integer you choose, except for 0, which is considered a null ID,
  55. and the predefined IDs in the SpecialItemIds enum.
  56. You should also add the built-in types (separatorBarId, spacerId and flexibleSpacerId)
  57. to this list if you want your toolbar to be able to contain those items.
  58. The list returned here is used by the ToolbarItemPalette class to obtain its list
  59. of available items, and their order on the palette will reflect the order in which
  60. they appear on this list.
  61. @see ToolbarItemPalette
  62. */
  63. virtual void getAllToolbarItemIds (Array <int>& ids) = 0;
  64. /** Must return the set of items that should be added to a toolbar as its default set.
  65. This method is used by Toolbar::addDefaultItems() to determine which items to
  66. create.
  67. The items that your method adds to the array that is passed-in will be added to the
  68. toolbar in the same order. Items can appear in the list more than once.
  69. */
  70. virtual void getDefaultItemSet (Array <int>& ids) = 0;
  71. /** Must create an instance of one of the items that the factory lists in its
  72. getAllToolbarItemIds() method.
  73. The itemId parameter can be any of the values listed by your getAllToolbarItemIds()
  74. method, except for the built-in item types from the SpecialItemIds enum, which
  75. are created internally by the toolbar code.
  76. Try not to keep a pointer to the object that is returned, as it will be deleted
  77. automatically by the toolbar, and remember that multiple instances of the same
  78. item type are likely to exist at the same time.
  79. */
  80. virtual ToolbarItemComponent* createItem (int itemId) = 0;
  81. };
  82. } // namespace juce