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.

258 lines
13KB

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