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_DialogWindow.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 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. Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>();
  99. if (dw != nullptr)
  100. dw->exitModalState (1234);
  101. @endcode
  102. */
  103. DialogWindow* launchAsync();
  104. /** Creates a new DialogWindow instance with these settings.
  105. This method simply creates the window, it doesn't run it modally. In most cases
  106. you'll want to use launchAsync() or runModal() instead.
  107. */
  108. DialogWindow* create();
  109. #if JUCE_MODAL_LOOPS_PERMITTED || DOXYGEN
  110. /** Launches and runs the dialog modally, returning the status code that was
  111. used to terminate the modal loop.
  112. Note that running modal loops inline is a BAD technique. If possible, always
  113. use launchAsync() instead of this method.
  114. */
  115. int runModal();
  116. #endif
  117. };
  118. //==============================================================================
  119. /** Easy way of quickly showing a dialog box containing a given component.
  120. Note: this method has been superceded by the DialogWindow::LaunchOptions structure,
  121. which does the same job with some extra flexibility. The showDialog method is here
  122. for backwards compatibility, but please use DialogWindow::LaunchOptions in new code.
  123. This will open and display a DialogWindow containing a given component, making it
  124. modal, but returning immediately to allow the dialog to finish in its own time. If
  125. you want to block and run a modal loop until the dialog is dismissed, use showModalDialog()
  126. instead.
  127. To close the dialog programmatically, you should call exitModalState (returnValue) on
  128. the DialogWindow that is created. To find a pointer to this window from your
  129. contentComponent, you can do something like this:
  130. @code
  131. Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>();
  132. if (dw != nullptr)
  133. dw->exitModalState (1234);
  134. @endcode
  135. @param dialogTitle the dialog box's title
  136. @param contentComponent the content component for the dialog box. Make sure
  137. that this has been set to the size you want it to
  138. be before calling this method. The component won't
  139. be deleted by this call, so you can re-use it or delete
  140. it afterwards
  141. @param componentToCentreAround if this is non-zero, it indicates a component that
  142. you'd like to show this dialog box in front of. See the
  143. DocumentWindow::centreAroundComponent() method for more
  144. info on this parameter
  145. @param backgroundColour a colour to use for the dialog box's background colour
  146. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  147. close button to be triggered
  148. @param shouldBeResizable if true, the dialog window has either a resizable border, or
  149. a corner resizer
  150. @param useBottomRightCornerResizer if shouldBeResizable is true, this indicates whether
  151. to use a border or corner resizer component. See ResizableWindow::setResizable()
  152. */
  153. static void showDialog (const String& dialogTitle,
  154. Component* contentComponent,
  155. Component* componentToCentreAround,
  156. Colour backgroundColour,
  157. bool escapeKeyTriggersCloseButton,
  158. bool shouldBeResizable = false,
  159. bool useBottomRightCornerResizer = false,
  160. bool useNativeTitleBar = false);
  161. #if JUCE_MODAL_LOOPS_PERMITTED || DOXYGEN
  162. /** Easy way of quickly showing a dialog box containing a given component.
  163. Note: this method has been superceded by the DialogWindow::LaunchOptions structure,
  164. which does the same job with some extra flexibility. The showDialog method is here
  165. for backwards compatibility, but please use DialogWindow::LaunchOptions in new code.
  166. This will open and display a DialogWindow containing a given component, returning
  167. when the user clicks its close button.
  168. It returns the value that was returned by the dialog box's runModalLoop() call.
  169. To close the dialog programmatically, you should call exitModalState (returnValue) on
  170. the DialogWindow that is created. To find a pointer to this window from your
  171. contentComponent, you can do something like this:
  172. @code
  173. Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>();
  174. if (dw != nullptr)
  175. dw->exitModalState (1234);
  176. @endcode
  177. @param dialogTitle the dialog box's title
  178. @param contentComponent the content component for the dialog box. Make sure
  179. that this has been set to the size you want it to
  180. be before calling this method. The component won't
  181. be deleted by this call, so you can re-use it or delete
  182. it afterwards
  183. @param componentToCentreAround if this is non-zero, it indicates a component that
  184. you'd like to show this dialog box in front of. See the
  185. DocumentWindow::centreAroundComponent() method for more
  186. info on this parameter
  187. @param backgroundColour a colour to use for the dialog box's background colour
  188. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  189. close button to be triggered
  190. @param shouldBeResizable if true, the dialog window has either a resizable border, or
  191. a corner resizer
  192. @param useBottomRightCornerResizer if shouldBeResizable is true, this indicates whether
  193. to use a border or corner resizer component. See ResizableWindow::setResizable()
  194. */
  195. static int showModalDialog (const String& dialogTitle,
  196. Component* contentComponent,
  197. Component* componentToCentreAround,
  198. Colour backgroundColour,
  199. bool escapeKeyTriggersCloseButton,
  200. bool shouldBeResizable = false,
  201. bool useBottomRightCornerResizer = false,
  202. bool useNativeTitleBar = false);
  203. #endif
  204. protected:
  205. //==============================================================================
  206. /** @internal */
  207. void resized() override;
  208. /** @internal */
  209. bool keyPressed (const KeyPress&) override;
  210. private:
  211. bool escapeKeyTriggersCloseButton;
  212. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DialogWindow)
  213. };
  214. #endif // JUCE_DIALOGWINDOW_H_INCLUDED