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.

juce_MultiDocumentPanel.h 12KB

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