The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

150 lines
6.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_PREFERENCESPANEL_JUCEHEADER__
  19. #define __JUCE_PREFERENCESPANEL_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. A component with a set of buttons at the top for changing between pages of
  23. preferences.
  24. This is just a handy way of writing a Mac-style preferences panel where you
  25. have a row of buttons along the top for the different preference categories,
  26. each button having an icon above its name. Clicking these will show an
  27. appropriate prefs page below it.
  28. You can either put one of these inside your own component, or just use the
  29. showInDialogBox() method to show it in a window and run it modally.
  30. To use it, just add a set of named pages with the addSettingsPage() method,
  31. and implement the createComponentForPage() method to create suitable components
  32. for each of these pages.
  33. */
  34. class JUCE_API PreferencesPanel : public Component,
  35. private ButtonListener // (can't use Button::Listener due to idiotic VC2005 bug)
  36. {
  37. public:
  38. //==============================================================================
  39. /** Creates an empty panel.
  40. Use addSettingsPage() to add some pages to it in your constructor.
  41. */
  42. PreferencesPanel();
  43. /** Destructor. */
  44. ~PreferencesPanel();
  45. //==============================================================================
  46. /** Creates a page using a set of drawables to define the page's icon.
  47. Note that the other version of this method is much easier if you're using
  48. an image instead of a custom drawable.
  49. @param pageTitle the name of this preferences page - you'll need to
  50. make sure your createComponentForPage() method creates
  51. a suitable component when it is passed this name
  52. @param normalIcon the drawable to display in the page's button normally
  53. @param overIcon the drawable to display in the page's button when the mouse is over
  54. @param downIcon the drawable to display in the page's button when the button is down
  55. @see DrawableButton
  56. */
  57. void addSettingsPage (const String& pageTitle,
  58. const Drawable* normalIcon,
  59. const Drawable* overIcon,
  60. const Drawable* downIcon);
  61. /** Creates a page using a set of drawables to define the page's icon.
  62. The other version of this method gives you more control over the icon, but this
  63. one is much easier if you're just loading it from a file.
  64. @param pageTitle the name of this preferences page - you'll need to
  65. make sure your createComponentForPage() method creates
  66. a suitable component when it is passed this name
  67. @param imageData a block of data containing an image file, e.g. a jpeg, png or gif.
  68. For this to look good, you'll probably want to use a nice
  69. transparent png file.
  70. @param imageDataSize the size of the image data, in bytes
  71. */
  72. void addSettingsPage (const String& pageTitle,
  73. const void* imageData,
  74. int imageDataSize);
  75. /** Utility method to display this panel in a DialogWindow.
  76. Calling this will create a DialogWindow containing this panel with the
  77. given size and title, and will run it modally, returning when the user
  78. closes the dialog box.
  79. */
  80. void showInDialogBox (const String& dialogTitle,
  81. int dialogWidth,
  82. int dialogHeight,
  83. const Colour& backgroundColour = Colours::white);
  84. //==============================================================================
  85. /** Subclasses must override this to return a component for each preferences page.
  86. The subclass should return a pointer to a new component representing the named
  87. page, which the panel will then display.
  88. The panel will delete the component later when the user goes to another page
  89. or deletes the panel.
  90. */
  91. virtual Component* createComponentForPage (const String& pageName) = 0;
  92. //==============================================================================
  93. /** Changes the current page being displayed. */
  94. void setCurrentPage (const String& pageName);
  95. /** Returns the size of the buttons shown along the top. */
  96. int getButtonSize() const noexcept;
  97. /** Changes the size of the buttons shown along the top. */
  98. void setButtonSize (int newSize);
  99. //==============================================================================
  100. /** @internal */
  101. void resized();
  102. /** @internal */
  103. void paint (Graphics& g);
  104. /** @internal */
  105. void buttonClicked (Button* button);
  106. private:
  107. //==============================================================================
  108. String currentPageName;
  109. ScopedPointer <Component> currentPage;
  110. OwnedArray<DrawableButton> buttons;
  111. int buttonSize;
  112. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PreferencesPanel);
  113. };
  114. #endif // __JUCE_PREFERENCESPANEL_JUCEHEADER__