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.

179 lines
9.0KB

  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. #include "../buttons/juce_Button.h"
  22. //==============================================================================
  23. /**
  24. A dialog-box style window.
  25. This class is a convenient way of creating a DocumentWindow with a close button
  26. that can be triggered by pressing the escape key.
  27. Any of the methods available to a DocumentWindow or ResizableWindow are also
  28. available to this, so it can be made resizable, have a menu bar, etc.
  29. To add items to the box, see the ResizableWindow::setContentOwned() or
  30. ResizableWindow::setContentNonOwned() methods. Don't add components directly to this
  31. class - always put them in a content component!
  32. You'll need to override the DocumentWindow::closeButtonPressed() method to handle
  33. the user clicking the close button - for more info, see the DocumentWindow
  34. help.
  35. @see DocumentWindow, ResizableWindow
  36. */
  37. class JUCE_API DialogWindow : public DocumentWindow
  38. {
  39. public:
  40. //==============================================================================
  41. /** Creates a DialogWindow.
  42. @param name the name to give the component - this is also
  43. the title shown at the top of the window. To change
  44. this later, use setName()
  45. @param backgroundColour the colour to use for filling the window's background.
  46. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  47. close button to be triggered
  48. @param addToDesktop if true, the window will be automatically added to the
  49. desktop; if false, you can use it as a child component
  50. */
  51. DialogWindow (const String& name,
  52. const Colour& backgroundColour,
  53. bool escapeKeyTriggersCloseButton,
  54. bool addToDesktop = true);
  55. /** Destructor.
  56. If a content component has been set with setContentOwned(), it will be deleted.
  57. */
  58. ~DialogWindow();
  59. //==============================================================================
  60. /** Easy way of quickly showing a dialog box containing a given component.
  61. This will open and display a DialogWindow containing a given component, making it
  62. modal, but returning immediately to allow the dialog to finish in its own time. If
  63. you want to block and run a modal loop until the dialog is dismissed, use showModalDialog()
  64. instead.
  65. To close the dialog programatically, you should call exitModalState (returnValue) on
  66. the DialogWindow that is created. To find a pointer to this window from your
  67. contentComponent, you can do something like this:
  68. @code
  69. Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>();
  70. if (dw != nullptr)
  71. dw->exitModalState (1234);
  72. @endcode
  73. @param dialogTitle the dialog box's title
  74. @param contentComponent the content component for the dialog box. Make sure
  75. that this has been set to the size you want it to
  76. be before calling this method. The component won't
  77. be deleted by this call, so you can re-use it or delete
  78. it afterwards
  79. @param componentToCentreAround if this is non-zero, it indicates a component that
  80. you'd like to show this dialog box in front of. See the
  81. DocumentWindow::centreAroundComponent() method for more
  82. info on this parameter
  83. @param backgroundColour a colour to use for the dialog box's background colour
  84. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  85. close button to be triggered
  86. @param shouldBeResizable if true, the dialog window has either a resizable border, or
  87. a corner resizer
  88. @param useBottomRightCornerResizer if shouldBeResizable is true, this indicates whether
  89. to use a border or corner resizer component. See ResizableWindow::setResizable()
  90. */
  91. static void showDialog (const String& dialogTitle,
  92. Component* contentComponent,
  93. Component* componentToCentreAround,
  94. const Colour& backgroundColour,
  95. bool escapeKeyTriggersCloseButton,
  96. bool shouldBeResizable = false,
  97. bool useBottomRightCornerResizer = false);
  98. /** Easy way of quickly showing a dialog box containing a given component.
  99. This will open and display a DialogWindow containing a given component, returning
  100. when the user clicks its close button.
  101. It returns the value that was returned by the dialog box's runModalLoop() call.
  102. To close the dialog programatically, you should call exitModalState (returnValue) on
  103. the DialogWindow that is created. To find a pointer to this window from your
  104. contentComponent, you can do something like this:
  105. @code
  106. Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>();
  107. if (dw != nullptr)
  108. dw->exitModalState (1234);
  109. @endcode
  110. @param dialogTitle the dialog box's title
  111. @param contentComponent the content component for the dialog box. Make sure
  112. that this has been set to the size you want it to
  113. be before calling this method. The component won't
  114. be deleted by this call, so you can re-use it or delete
  115. it afterwards
  116. @param componentToCentreAround if this is non-zero, it indicates a component that
  117. you'd like to show this dialog box in front of. See the
  118. DocumentWindow::centreAroundComponent() method for more
  119. info on this parameter
  120. @param backgroundColour a colour to use for the dialog box's background colour
  121. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  122. close button to be triggered
  123. @param shouldBeResizable if true, the dialog window has either a resizable border, or
  124. a corner resizer
  125. @param useBottomRightCornerResizer if shouldBeResizable is true, this indicates whether
  126. to use a border or corner resizer component. See ResizableWindow::setResizable()
  127. */
  128. #if JUCE_MODAL_LOOPS_PERMITTED || DOXYGEN
  129. static int showModalDialog (const String& dialogTitle,
  130. Component* contentComponent,
  131. Component* componentToCentreAround,
  132. const Colour& backgroundColour,
  133. bool escapeKeyTriggersCloseButton,
  134. bool shouldBeResizable = false,
  135. bool useBottomRightCornerResizer = false);
  136. #endif
  137. protected:
  138. /** @internal */
  139. void resized();
  140. private:
  141. //==============================================================================
  142. bool escapeKeyTriggersCloseButton;
  143. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DialogWindow);
  144. };
  145. #endif // __JUCE_DIALOGWINDOW_JUCEHEADER__