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.

277 lines
12KB

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