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.

309 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_MULTIDOCUMENTPANEL_JUCEHEADER__
  19. #define __JUCE_MULTIDOCUMENTPANEL_JUCEHEADER__
  20. #include "juce_TabbedComponent.h"
  21. #include "../windows/juce_DocumentWindow.h"
  22. class MultiDocumentPanel;
  23. //==============================================================================
  24. /**
  25. This is a derivative of DocumentWindow that is used inside a MultiDocumentPanel
  26. component.
  27. It's like a normal DocumentWindow but has some extra functionality to make sure
  28. everything works nicely inside a MultiDocumentPanel.
  29. @see MultiDocumentPanel
  30. */
  31. class JUCE_API MultiDocumentPanelWindow : public DocumentWindow
  32. {
  33. public:
  34. //==============================================================================
  35. /**
  36. */
  37. MultiDocumentPanelWindow (const Colour& backgroundColour);
  38. /** Destructor. */
  39. ~MultiDocumentPanelWindow();
  40. //==============================================================================
  41. /** @internal */
  42. void maximiseButtonPressed();
  43. /** @internal */
  44. void closeButtonPressed();
  45. /** @internal */
  46. void activeWindowStatusChanged();
  47. /** @internal */
  48. void broughtToFront();
  49. private:
  50. //==============================================================================
  51. void updateOrder();
  52. MultiDocumentPanel* getOwner() const noexcept;
  53. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiDocumentPanelWindow);
  54. };
  55. //==============================================================================
  56. /**
  57. A component that contains a set of other components either in floating windows
  58. or tabs.
  59. This acts as a panel that can be used to hold a set of open document windows, with
  60. different layout modes.
  61. Use addDocument() and closeDocument() to add or remove components from the
  62. panel - never use any of the Component methods to access the panel's child
  63. components directly, as these are managed internally.
  64. */
  65. class JUCE_API MultiDocumentPanel : public Component,
  66. private ComponentListener
  67. {
  68. public:
  69. //==============================================================================
  70. /** Creates an empty panel.
  71. Use addDocument() and closeDocument() to add or remove components from the
  72. panel - never use any of the Component methods to access the panel's child
  73. components directly, as these are managed internally.
  74. */
  75. MultiDocumentPanel();
  76. /** Destructor.
  77. When deleted, this will call closeAllDocuments (false) to make sure all its
  78. components are deleted. If you need to make sure all documents are saved
  79. before closing, then you should call closeAllDocuments (true) and check that
  80. it returns true before deleting the panel.
  81. */
  82. ~MultiDocumentPanel();
  83. //==============================================================================
  84. /** Tries to close all the documents.
  85. If checkItsOkToCloseFirst is true, then the tryToCloseDocument() method will
  86. be called for each open document, and any of these calls fails, this method
  87. will stop and return false, leaving some documents still open.
  88. If checkItsOkToCloseFirst is false, then all documents will be closed
  89. unconditionally.
  90. @see closeDocument
  91. */
  92. bool closeAllDocuments (bool checkItsOkToCloseFirst);
  93. /** Adds a document component to the panel.
  94. If the number of documents would exceed the limit set by setMaximumNumDocuments() then
  95. this will fail and return false. (If it does fail, the component passed-in will not be
  96. deleted, even if deleteWhenRemoved was set to true).
  97. The MultiDocumentPanel will deal with creating a window border to go around your component,
  98. so just pass in the bare content component here, no need to give it a ResizableWindow
  99. or DocumentWindow.
  100. @param component the component to add
  101. @param backgroundColour the background colour to use to fill the component's
  102. window or tab
  103. @param deleteWhenRemoved if true, then when the component is removed by closeDocument()
  104. or closeAllDocuments(), then it will be deleted. If false, then
  105. the caller must handle the component's deletion
  106. */
  107. bool addDocument (Component* component,
  108. const Colour& backgroundColour,
  109. bool deleteWhenRemoved);
  110. /** Closes one of the documents.
  111. If checkItsOkToCloseFirst is true, then the tryToCloseDocument() method will
  112. be called, and if it fails, this method will return false without closing the
  113. document.
  114. If checkItsOkToCloseFirst is false, then the documents will be closed
  115. unconditionally.
  116. The component will be deleted if the deleteWhenRemoved parameter was set to
  117. true when it was added with addDocument.
  118. @see addDocument, closeAllDocuments
  119. */
  120. bool closeDocument (Component* component,
  121. bool checkItsOkToCloseFirst);
  122. /** Returns the number of open document windows.
  123. @see getDocument
  124. */
  125. int getNumDocuments() const noexcept;
  126. /** Returns one of the open documents.
  127. The order of the documents in this array may change when they are added, removed
  128. or moved around.
  129. @see getNumDocuments
  130. */
  131. Component* getDocument (int index) const noexcept;
  132. /** Returns the document component that is currently focused or on top.
  133. If currently using floating windows, then this will be the component in the currently
  134. active window, or the top component if none are active.
  135. If it's currently in tabbed mode, then it'll return the component in the active tab.
  136. @see setActiveDocument
  137. */
  138. Component* getActiveDocument() const noexcept;
  139. /** Makes one of the components active and brings it to the top.
  140. @see getActiveDocument
  141. */
  142. void setActiveDocument (Component* component);
  143. /** Callback which gets invoked when the currently-active document changes. */
  144. virtual void activeDocumentChanged();
  145. /** Sets a limit on how many windows can be open at once.
  146. If this is zero or less there's no limit (the default). addDocument() will fail
  147. if this number is exceeded.
  148. */
  149. void setMaximumNumDocuments (int maximumNumDocuments);
  150. /** Sets an option to make the document fullscreen if there's only one document open.
  151. If set to true, then if there's only one document, it'll fill the whole of this
  152. component without tabs or a window border. If false, then tabs or a window
  153. will always be shown, even if there's only one document. If there's more than
  154. one document open, then this option makes no difference.
  155. */
  156. void useFullscreenWhenOneDocument (bool shouldUseTabs);
  157. /** Returns the result of the last time useFullscreenWhenOneDocument() was called.
  158. */
  159. bool isFullscreenWhenOneDocument() const noexcept;
  160. //==============================================================================
  161. /** The different layout modes available. */
  162. enum LayoutMode
  163. {
  164. FloatingWindows, /**< In this mode, there are overlapping DocumentWindow components for each document. */
  165. MaximisedWindowsWithTabs /**< In this mode, a TabbedComponent is used to show one document at a time. */
  166. };
  167. /** Changes the panel's mode.
  168. @see LayoutMode, getLayoutMode
  169. */
  170. void setLayoutMode (LayoutMode newLayoutMode);
  171. /** Returns the current layout mode. */
  172. LayoutMode getLayoutMode() const noexcept { return mode; }
  173. /** Sets the background colour for the whole panel.
  174. Each document has its own background colour, but this is the one used to fill the areas
  175. behind them.
  176. */
  177. void setBackgroundColour (const Colour& newBackgroundColour);
  178. /** Returns the current background colour.
  179. @see setBackgroundColour
  180. */
  181. const Colour& getBackgroundColour() const noexcept { return backgroundColour; }
  182. /** If the panel is being used in tabbed mode, this returns the TabbedComponent that's involved. */
  183. TabbedComponent* getCurrentTabbedComponent() const noexcept { return tabComponent; }
  184. //==============================================================================
  185. /** A subclass must override this to say whether its currently ok for a document
  186. to be closed.
  187. This method is called by closeDocument() and closeAllDocuments() to indicate that
  188. a document should be saved if possible, ready for it to be closed.
  189. If this method returns true, then it means the document is ok and can be closed.
  190. If it returns false, then it means that the closeDocument() method should stop
  191. and not close.
  192. Normally, you'd use this method to ask the user if they want to save any changes,
  193. then return true if the save operation went ok. If the user cancelled the save
  194. operation you could return false here to abort the close operation.
  195. If your component is based on the FileBasedDocument class, then you'd probably want
  196. to call FileBasedDocument::saveIfNeededAndUserAgrees() and return true if this returned
  197. FileBasedDocument::savedOk
  198. @see closeDocument, FileBasedDocument::saveIfNeededAndUserAgrees()
  199. */
  200. virtual bool tryToCloseDocument (Component* component) = 0;
  201. /** Creates a new window to be used for a document.
  202. The default implementation of this just returns a basic MultiDocumentPanelWindow object,
  203. but you might want to override it to return a custom component.
  204. */
  205. virtual MultiDocumentPanelWindow* createNewDocumentWindow();
  206. //==============================================================================
  207. /** @internal */
  208. void paint (Graphics& g);
  209. /** @internal */
  210. void resized();
  211. /** @internal */
  212. void componentNameChanged (Component&);
  213. private:
  214. //==============================================================================
  215. LayoutMode mode;
  216. Array <Component*> components;
  217. ScopedPointer<TabbedComponent> tabComponent;
  218. Colour backgroundColour;
  219. int maximumNumDocuments, numDocsBeforeTabsUsed;
  220. class TabbedComponentInternal;
  221. friend class MultiDocumentPanelWindow;
  222. friend class TabbedComponentInternal;
  223. Component* getContainerComp (Component* c) const;
  224. void updateOrder();
  225. void addWindow (Component* component);
  226. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiDocumentPanel);
  227. };
  228. #endif // __JUCE_MULTIDOCUMENTPANEL_JUCEHEADER__