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.

296 lines
13KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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_DOCUMENTWINDOW_H_INCLUDED
  18. #define JUCE_DOCUMENTWINDOW_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A resizable window with a title bar and maximise, minimise and close buttons.
  22. This subclass of ResizableWindow creates a fairly standard type of window with
  23. a title bar and various buttons. The name of the component is shown in the
  24. title bar, and an icon can optionally be specified with setIcon().
  25. All the methods available to a ResizableWindow are also available to this,
  26. so it can easily be made resizable, minimised, maximised, etc.
  27. It's not advisable to add child components directly to a DocumentWindow: put them
  28. inside your content component instead. And overriding methods like resized(), moved(), etc
  29. is also not recommended - instead override these methods for your content component.
  30. (If for some obscure reason you do need to override these methods, always remember to
  31. call the super-class's resized() method too, otherwise it'll fail to lay out the window
  32. decorations correctly).
  33. You can also automatically add a menu bar to the window, using the setMenuBar()
  34. method.
  35. @see ResizableWindow, DialogWindow
  36. */
  37. class JUCE_API DocumentWindow : public ResizableWindow
  38. {
  39. public:
  40. //==============================================================================
  41. /** The set of available button-types that can be put on the title bar.
  42. @see setTitleBarButtonsRequired
  43. */
  44. enum TitleBarButtons
  45. {
  46. minimiseButton = 1,
  47. maximiseButton = 2,
  48. closeButton = 4,
  49. /** A combination of all the buttons above. */
  50. allButtons = 7
  51. };
  52. //==============================================================================
  53. /** Creates a DocumentWindow.
  54. @param name the name to give the component - this is also
  55. the title shown at the top of the window. To change
  56. this later, use setName()
  57. @param backgroundColour the colour to use for filling the window's background.
  58. @param requiredButtons specifies which of the buttons (close, minimise, maximise)
  59. should be shown on the title bar. This value is a bitwise
  60. combination of values from the TitleBarButtons enum. Note
  61. that it can be "allButtons" to get them all. You
  62. can change this later with the setTitleBarButtonsRequired()
  63. method, which can also specify where they are positioned.
  64. @param addToDesktop if true, the window will be automatically added to the
  65. desktop; if false, you can use it as a child component
  66. @see TitleBarButtons
  67. */
  68. DocumentWindow (const String& name,
  69. Colour backgroundColour,
  70. int requiredButtons,
  71. bool addToDesktop = true);
  72. /** Destructor.
  73. If a content component has been set with setContentOwned(), it will be deleted.
  74. */
  75. ~DocumentWindow();
  76. //==============================================================================
  77. /** Changes the component's name.
  78. (This is overridden from Component::setName() to cause a repaint, as
  79. the name is what gets drawn across the window's title bar).
  80. */
  81. void setName (const String& newName) override;
  82. /** Sets an icon to show in the title bar, next to the title.
  83. A copy is made internally of the image, so the caller can delete the
  84. image after calling this. If 0 is passed-in, any existing icon will be
  85. removed.
  86. */
  87. void setIcon (const Image& imageToUse);
  88. /** Changes the height of the title-bar. */
  89. void setTitleBarHeight (int newHeight);
  90. /** Returns the current title bar height. */
  91. int getTitleBarHeight() const;
  92. /** Changes the set of title-bar buttons being shown.
  93. @param requiredButtons specifies which of the buttons (close, minimise, maximise)
  94. should be shown on the title bar. This value is a bitwise
  95. combination of values from the TitleBarButtons enum. Note
  96. that it can be "allButtons" to get them all.
  97. @param positionTitleBarButtonsOnLeft if true, the buttons should go at the
  98. left side of the bar; if false, they'll be placed at the right
  99. */
  100. void setTitleBarButtonsRequired (int requiredButtons,
  101. bool positionTitleBarButtonsOnLeft);
  102. /** Sets whether the title should be centred within the window.
  103. If true, the title text is shown in the middle of the title-bar; if false,
  104. it'll be shown at the left of the bar.
  105. */
  106. void setTitleBarTextCentred (bool textShouldBeCentred);
  107. //==============================================================================
  108. /** Creates a menu inside this window.
  109. @param menuBarModel this specifies a MenuBarModel that should be used to
  110. generate the contents of a menu bar that will be placed
  111. just below the title bar, and just above any content
  112. component. If this value is zero, any existing menu bar
  113. will be removed from the component; if non-zero, one will
  114. be added if it's required.
  115. @param menuBarHeight the height of the menu bar component, if one is needed. Pass a value of zero
  116. or less to use the look-and-feel's default size.
  117. */
  118. void setMenuBar (MenuBarModel* menuBarModel,
  119. int menuBarHeight = 0);
  120. /** Returns the current menu bar component, or null if there isn't one.
  121. This is probably a MenuBarComponent, unless a custom one has been set using
  122. setMenuBarComponent().
  123. */
  124. Component* getMenuBarComponent() const noexcept;
  125. /** Replaces the current menu bar with a custom component.
  126. The component will be owned and deleted by the document window.
  127. */
  128. void setMenuBarComponent (Component* newMenuBarComponent);
  129. //==============================================================================
  130. /** This method is called when the user tries to close the window.
  131. This is triggered by the user clicking the close button, or using some other
  132. OS-specific key shortcut or OS menu for getting rid of a window.
  133. If the window is just a pop-up, you should override this closeButtonPressed()
  134. method and make it delete the window in whatever way is appropriate for your
  135. app. E.g. you might just want to call "delete this".
  136. If your app is centred around this window such that the whole app should quit when
  137. the window is closed, then you will probably want to use this method as an opportunity
  138. to call JUCEApplicationBase::quit(), and leave the window to be deleted later by your
  139. JUCEApplicationBase::shutdown() method. (Doing it this way means that your window will
  140. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  141. or closing it via the taskbar icon on Windows).
  142. (Note that the DocumentWindow class overrides Component::userTriedToCloseWindow() and
  143. redirects it to call this method, so any methods of closing the window that are
  144. caught by userTriedToCloseWindow() will also end up here).
  145. */
  146. virtual void closeButtonPressed();
  147. /** Callback that is triggered when the minimise button is pressed.
  148. The default implementation of this calls ResizableWindow::setMinimised(), but
  149. you can override it to do more customised behaviour.
  150. */
  151. virtual void minimiseButtonPressed();
  152. /** Callback that is triggered when the maximise button is pressed, or when the
  153. title-bar is double-clicked.
  154. The default implementation of this calls ResizableWindow::setFullScreen(), but
  155. you can override it to do more customised behaviour.
  156. */
  157. virtual void maximiseButtonPressed();
  158. //==============================================================================
  159. /** Returns the close button, (or nullptr if there isn't one). */
  160. Button* getCloseButton() const noexcept;
  161. /** Returns the minimise button, (or nullptr if there isn't one). */
  162. Button* getMinimiseButton() const noexcept;
  163. /** Returns the maximise button, (or nullptr if there isn't one). */
  164. Button* getMaximiseButton() const noexcept;
  165. //==============================================================================
  166. /** A set of colour IDs to use to change the colour of various aspects of the window.
  167. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  168. methods.
  169. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  170. */
  171. enum ColourIds
  172. {
  173. textColourId = 0x1005701, /**< The colour to draw any text with. It's up to the look
  174. and feel class how this is used. */
  175. };
  176. //==============================================================================
  177. /** This abstract base class is implemented by LookAndFeel classes to provide
  178. window drawing functionality.
  179. */
  180. struct JUCE_API LookAndFeelMethods
  181. {
  182. virtual ~LookAndFeelMethods() {}
  183. virtual void drawDocumentWindowTitleBar (DocumentWindow&,
  184. Graphics&, int w, int h,
  185. int titleSpaceX, int titleSpaceW,
  186. const Image* icon,
  187. bool drawTitleTextOnLeft) = 0;
  188. virtual Button* createDocumentWindowButton (int buttonType) = 0;
  189. virtual void positionDocumentWindowButtons (DocumentWindow&,
  190. int titleBarX, int titleBarY, int titleBarW, int titleBarH,
  191. Button* minimiseButton,
  192. Button* maximiseButton,
  193. Button* closeButton,
  194. bool positionTitleBarButtonsOnLeft) = 0;
  195. };
  196. //==============================================================================
  197. #ifndef DOXYGEN
  198. /** @internal */
  199. void paint (Graphics&) override;
  200. /** @internal */
  201. void resized() override;
  202. /** @internal */
  203. void lookAndFeelChanged() override;
  204. /** @internal */
  205. BorderSize<int> getBorderThickness() override;
  206. /** @internal */
  207. BorderSize<int> getContentComponentBorder() override;
  208. /** @internal */
  209. void mouseDoubleClick (const MouseEvent&) override;
  210. /** @internal */
  211. void userTriedToCloseWindow() override;
  212. /** @internal */
  213. void activeWindowStatusChanged() override;
  214. /** @internal */
  215. int getDesktopWindowStyleFlags() const override;
  216. /** @internal */
  217. void parentHierarchyChanged() override;
  218. /** @internal */
  219. Rectangle<int> getTitleBarArea();
  220. #endif
  221. private:
  222. //==============================================================================
  223. int titleBarHeight, menuBarHeight, requiredButtons;
  224. bool positionTitleBarButtonsOnLeft, drawTitleTextCentred;
  225. ScopedPointer <Button> titleBarButtons [3];
  226. Image titleBarIcon;
  227. ScopedPointer <Component> menuBar;
  228. MenuBarModel* menuBarModel;
  229. class ButtonListenerProxy;
  230. friend struct ContainerDeletePolicy<ButtonListenerProxy>;
  231. ScopedPointer<ButtonListenerProxy> buttonListener;
  232. void repaintTitleBar();
  233. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DocumentWindow)
  234. };
  235. #endif // JUCE_DOCUMENTWINDOW_H_INCLUDED