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.

110 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "../../../core/juce_StandardHeader.h"
  19. BEGIN_JUCE_NAMESPACE
  20. #include "juce_DialogWindow.h"
  21. #include "../../../application/juce_Application.h"
  22. //==============================================================================
  23. DialogWindow::DialogWindow (const String& name,
  24. const Colour& backgroundColour_,
  25. const bool escapeKeyTriggersCloseButton_,
  26. const bool addToDesktop_)
  27. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  28. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  29. {
  30. }
  31. DialogWindow::~DialogWindow()
  32. {
  33. }
  34. //==============================================================================
  35. void DialogWindow::resized()
  36. {
  37. DocumentWindow::resized();
  38. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  39. if (escapeKeyTriggersCloseButton
  40. && getCloseButton() != 0
  41. && ! getCloseButton()->isRegisteredForShortcut (esc))
  42. {
  43. getCloseButton()->addShortcut (esc);
  44. }
  45. }
  46. //==============================================================================
  47. class TempDialogWindow : public DialogWindow
  48. {
  49. public:
  50. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  51. : DialogWindow (title, colour, escapeCloses, true)
  52. {
  53. if (! JUCEApplication::isStandaloneApp())
  54. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  55. }
  56. ~TempDialogWindow()
  57. {
  58. }
  59. void closeButtonPressed()
  60. {
  61. setVisible (false);
  62. }
  63. private:
  64. TempDialogWindow (const TempDialogWindow&);
  65. TempDialogWindow& operator= (const TempDialogWindow&);
  66. };
  67. int DialogWindow::showModalDialog (const String& dialogTitle,
  68. Component* contentComponent,
  69. Component* componentToCentreAround,
  70. const Colour& colour,
  71. const bool escapeKeyTriggersCloseButton,
  72. const bool shouldBeResizable,
  73. const bool useBottomRightCornerResizer)
  74. {
  75. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  76. dw.setContentComponent (contentComponent, true, true);
  77. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  78. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  79. const int result = dw.runModalLoop();
  80. dw.setContentComponent (0, false);
  81. return result;
  82. }
  83. END_JUCE_NAMESPACE