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.

80 lines
2.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #pragma once
  18. //==============================================================================
  19. struct FloatingToolWindow : public DialogWindow
  20. {
  21. FloatingToolWindow (const String& title,
  22. const String& windowPosPropertyName,
  23. Component* content,
  24. ScopedPointer<Component>& ownerPointer,
  25. int defaultW, int defaultH,
  26. int minW, int minH,
  27. int maxW, int maxH)
  28. : DialogWindow (title, Colours::darkgrey, true, true),
  29. windowPosProperty (windowPosPropertyName),
  30. owner (ownerPointer)
  31. {
  32. setUsingNativeTitleBar (true);
  33. setResizable (true, true);
  34. setResizeLimits (minW, minH, maxW, maxH);
  35. setContentOwned (content, false);
  36. const String windowState (getGlobalProperties().getValue (windowPosProperty));
  37. if (windowState.isNotEmpty())
  38. restoreWindowStateFromString (windowState);
  39. else
  40. centreAroundComponent (Component::getCurrentlyFocusedComponent(), defaultW, defaultH);
  41. setVisible (true);
  42. owner = this;
  43. }
  44. ~FloatingToolWindow()
  45. {
  46. getGlobalProperties().setValue (windowPosProperty, getWindowStateAsString());
  47. }
  48. void closeButtonPressed() override
  49. {
  50. owner = nullptr;
  51. }
  52. bool escapeKeyPressed() override
  53. {
  54. closeButtonPressed();
  55. return true;
  56. }
  57. private:
  58. String windowPosProperty;
  59. ScopedPointer<Component>& owner;
  60. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FloatingToolWindow)
  61. };