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.

122 lines
4.9KB

  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. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. DialogWindow::DialogWindow (const String& name,
  21. const Colour& backgroundColour_,
  22. const bool escapeKeyTriggersCloseButton_,
  23. const bool addToDesktop_)
  24. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  25. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  26. {
  27. }
  28. DialogWindow::~DialogWindow()
  29. {
  30. }
  31. //==============================================================================
  32. void DialogWindow::resized()
  33. {
  34. DocumentWindow::resized();
  35. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  36. if (escapeKeyTriggersCloseButton
  37. && getCloseButton() != nullptr
  38. && ! getCloseButton()->isRegisteredForShortcut (esc))
  39. {
  40. getCloseButton()->addShortcut (esc);
  41. }
  42. }
  43. //==============================================================================
  44. class TempDialogWindow : public DialogWindow
  45. {
  46. public:
  47. TempDialogWindow (const String& title,
  48. Component* contentComponent_,
  49. Component* componentToCentreAround,
  50. const Colour& colour,
  51. const bool escapeKeyTriggersCloseButton_,
  52. const bool shouldBeResizable,
  53. const bool useBottomRightCornerResizer)
  54. : DialogWindow (title, colour, escapeKeyTriggersCloseButton_, true)
  55. {
  56. if (! JUCEApplication::isStandaloneApp())
  57. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  58. setContentNonOwned (contentComponent_, true);
  59. centreAroundComponent (componentToCentreAround, getWidth(), getHeight());
  60. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61. }
  62. void closeButtonPressed()
  63. {
  64. setVisible (false);
  65. }
  66. private:
  67. JUCE_DECLARE_NON_COPYABLE (TempDialogWindow);
  68. };
  69. //==============================================================================
  70. void DialogWindow::showDialog (const String& dialogTitle,
  71. Component* const contentComponent,
  72. Component* const componentToCentreAround,
  73. const Colour& backgroundColour,
  74. const bool escapeKeyTriggersCloseButton,
  75. const bool shouldBeResizable,
  76. const bool useBottomRightCornerResizer)
  77. {
  78. TempDialogWindow* dw = new TempDialogWindow (dialogTitle, contentComponent, componentToCentreAround,
  79. backgroundColour, escapeKeyTriggersCloseButton,
  80. shouldBeResizable, useBottomRightCornerResizer);
  81. dw->enterModalState (true, 0, true);
  82. }
  83. #if JUCE_MODAL_LOOPS_PERMITTED
  84. int DialogWindow::showModalDialog (const String& dialogTitle,
  85. Component* const contentComponent,
  86. Component* const componentToCentreAround,
  87. const Colour& backgroundColour,
  88. const bool escapeKeyTriggersCloseButton,
  89. const bool shouldBeResizable,
  90. const bool useBottomRightCornerResizer)
  91. {
  92. TempDialogWindow dw (dialogTitle, contentComponent, componentToCentreAround,
  93. backgroundColour, escapeKeyTriggersCloseButton,
  94. shouldBeResizable, useBottomRightCornerResizer);
  95. return dw.runModalLoop();
  96. }
  97. #endif
  98. END_JUCE_NAMESPACE