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.

259 lines
13KB

  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_DIALOGWINDOW_JUCEHEADER__
  19. #define __JUCE_DIALOGWINDOW_JUCEHEADER__
  20. #include "juce_DocumentWindow.h"
  21. //==============================================================================
  22. /**
  23. A dialog-box style window.
  24. This class is a convenient way of creating a DocumentWindow with a close button
  25. that can be triggered by pressing the escape key.
  26. Any of the methods available to a DocumentWindow or ResizableWindow are also
  27. available to this, so it can be made resizable, have a menu bar, etc.
  28. You can either override or use an instance of the DialogWindow class directly,
  29. or you can use a DialogWindow::LaunchOptions structure to quickly set up and
  30. launch a box containing a content component.
  31. If you use the class directly, you'll need to override the
  32. DocumentWindow::closeButtonPressed() method to handle the user clicking the close
  33. button - for more info, see the DocumentWindow help.
  34. @see DocumentWindow, ResizableWindow
  35. */
  36. class JUCE_API DialogWindow : public DocumentWindow
  37. {
  38. public:
  39. //==============================================================================
  40. /** Creates a DialogWindow.
  41. @param name the name to give the component - this is also
  42. the title shown at the top of the window. To change
  43. this later, use setName()
  44. @param backgroundColour the colour to use for filling the window's background.
  45. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  46. close button to be triggered
  47. @param addToDesktop if true, the window will be automatically added to the
  48. desktop; if false, you can use it as a child component
  49. */
  50. DialogWindow (const String& name,
  51. const Colour& backgroundColour,
  52. bool escapeKeyTriggersCloseButton,
  53. bool addToDesktop = true);
  54. /** Destructor.
  55. If a content component has been set with setContentOwned(), it will be deleted.
  56. */
  57. ~DialogWindow();
  58. //==============================================================================
  59. /** This class defines a collection of settings to be used to open a DialogWindow.
  60. The easiest way to open a DialogWindow is to create yourself a LaunchOptions structure,
  61. initialise its fields with the appropriate details, and then call its launchAsync()
  62. method to launch the dialog.
  63. */
  64. struct LaunchOptions
  65. {
  66. LaunchOptions() noexcept;
  67. /** The title to give the window. */
  68. String dialogTitle;
  69. /** The background colour for the window. */
  70. Colour dialogBackgroundColour;
  71. /** The content component to show in the window. This must not be null!
  72. Using an OptionalScopedPointer to hold this pointer lets you indicate whether
  73. you'd like the dialog to automatically delete the component when the dialog
  74. has terminated.
  75. */
  76. OptionalScopedPointer <Component> content;
  77. /** If this is not a nullptr, it indicates a component that you'd like to position this
  78. dialog box in front of. See the DocumentWindow::centreAroundComponent() method for
  79. more info about this parameter.
  80. */
  81. Component* componentToCentreAround;
  82. /** If true, then the escape key will trigger the dialog's close button. */
  83. bool escapeKeyTriggersCloseButton;
  84. /** If true, the dialog will use a native title bar. See TopLevelWindow::setUsingNativeTitleBar() */
  85. bool useNativeTitleBar;
  86. /** If true, the window will be resizable. See ResizableWindow::setResizable() */
  87. bool resizable;
  88. /** Indicates whether to use a border or corner resizer component. See ResizableWindow::setResizable() */
  89. bool useBottomRightCornerResizer;
  90. /** Launches a new modal dialog window.
  91. This will create a dialog based on the settings in this structure,
  92. launch it modally, and return immediately. The window that is returned
  93. will be automatically deleted when the modal state is terminated.
  94. When the dialog's close button is clicked, it'll automatically terminate its
  95. modal state, but you can also do this programatically by calling
  96. exitModalState (returnValue) on the DialogWindow.
  97. If your content component needs to find the dialog window that it is
  98. contained in, a quick trick is to do this:
  99. @code
  100. Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>();
  101. if (dw != nullptr)
  102. dw->exitModalState (1234);
  103. @endcode
  104. */
  105. DialogWindow* launchAsync();
  106. #if JUCE_MODAL_LOOPS_PERMITTED || DOXYGEN
  107. /** Launches and runs the dialog modally, returning the status code that was
  108. used to terminate the modal loop.
  109. Note that running modal loops inline is a BAD technique. If possible, always
  110. use launchAsync() instead of this method.
  111. */
  112. int runModal();
  113. #endif
  114. };
  115. //==============================================================================
  116. /** Easy way of quickly showing a dialog box containing a given component.
  117. Note: this method has been superceded by the DialogWindow::LaunchOptions structure,
  118. which does the same job with some extra flexibility. The showDialog method is here
  119. for backwards compatibility, but please use DialogWindow::LaunchOptions in new code.
  120. This will open and display a DialogWindow containing a given component, making it
  121. modal, but returning immediately to allow the dialog to finish in its own time. If
  122. you want to block and run a modal loop until the dialog is dismissed, use showModalDialog()
  123. instead.
  124. To close the dialog programatically, you should call exitModalState (returnValue) on
  125. the DialogWindow that is created. To find a pointer to this window from your
  126. contentComponent, you can do something like this:
  127. @code
  128. Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>();
  129. if (dw != nullptr)
  130. dw->exitModalState (1234);
  131. @endcode
  132. @param dialogTitle the dialog box's title
  133. @param contentComponent the content component for the dialog box. Make sure
  134. that this has been set to the size you want it to
  135. be before calling this method. The component won't
  136. be deleted by this call, so you can re-use it or delete
  137. it afterwards
  138. @param componentToCentreAround if this is non-zero, it indicates a component that
  139. you'd like to show this dialog box in front of. See the
  140. DocumentWindow::centreAroundComponent() method for more
  141. info on this parameter
  142. @param backgroundColour a colour to use for the dialog box's background colour
  143. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  144. close button to be triggered
  145. @param shouldBeResizable if true, the dialog window has either a resizable border, or
  146. a corner resizer
  147. @param useBottomRightCornerResizer if shouldBeResizable is true, this indicates whether
  148. to use a border or corner resizer component. See ResizableWindow::setResizable()
  149. */
  150. static void showDialog (const String& dialogTitle,
  151. Component* contentComponent,
  152. Component* componentToCentreAround,
  153. const Colour& backgroundColour,
  154. bool escapeKeyTriggersCloseButton,
  155. bool shouldBeResizable = false,
  156. bool useBottomRightCornerResizer = false);
  157. #if JUCE_MODAL_LOOPS_PERMITTED || DOXYGEN
  158. /** Easy way of quickly showing a dialog box containing a given component.
  159. Note: this method has been superceded by the DialogWindow::LaunchOptions structure,
  160. which does the same job with some extra flexibility. The showDialog method is here
  161. for backwards compatibility, but please use DialogWindow::LaunchOptions in new code.
  162. This will open and display a DialogWindow containing a given component, returning
  163. when the user clicks its close button.
  164. It returns the value that was returned by the dialog box's runModalLoop() call.
  165. To close the dialog programatically, you should call exitModalState (returnValue) on
  166. the DialogWindow that is created. To find a pointer to this window from your
  167. contentComponent, you can do something like this:
  168. @code
  169. Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>();
  170. if (dw != nullptr)
  171. dw->exitModalState (1234);
  172. @endcode
  173. @param dialogTitle the dialog box's title
  174. @param contentComponent the content component for the dialog box. Make sure
  175. that this has been set to the size you want it to
  176. be before calling this method. The component won't
  177. be deleted by this call, so you can re-use it or delete
  178. it afterwards
  179. @param componentToCentreAround if this is non-zero, it indicates a component that
  180. you'd like to show this dialog box in front of. See the
  181. DocumentWindow::centreAroundComponent() method for more
  182. info on this parameter
  183. @param backgroundColour a colour to use for the dialog box's background colour
  184. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  185. close button to be triggered
  186. @param shouldBeResizable if true, the dialog window has either a resizable border, or
  187. a corner resizer
  188. @param useBottomRightCornerResizer if shouldBeResizable is true, this indicates whether
  189. to use a border or corner resizer component. See ResizableWindow::setResizable()
  190. */
  191. static int showModalDialog (const String& dialogTitle,
  192. Component* contentComponent,
  193. Component* componentToCentreAround,
  194. const Colour& backgroundColour,
  195. bool escapeKeyTriggersCloseButton,
  196. bool shouldBeResizable = false,
  197. bool useBottomRightCornerResizer = false);
  198. #endif
  199. protected:
  200. //==============================================================================
  201. /** @internal */
  202. void resized();
  203. /** @internal */
  204. bool keyPressed (const KeyPress&);
  205. private:
  206. bool escapeKeyTriggersCloseButton;
  207. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DialogWindow);
  208. };
  209. #endif // __JUCE_DIALOGWINDOW_JUCEHEADER__