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.

117 lines
4.8KB

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