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.

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