Audio plugin host https://kx.studio/carla
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.

165 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_TOPLEVELWINDOW_H_INCLUDED
  18. #define JUCE_TOPLEVELWINDOW_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A base class for top-level windows.
  22. This class is used for components that are considered a major part of your
  23. application - e.g. ResizableWindow, DocumentWindow, DialogWindow, AlertWindow,
  24. etc. Things like menus that pop up briefly aren't derived from it.
  25. A TopLevelWindow is probably on the desktop, but this isn't mandatory - it
  26. could itself be the child of another component.
  27. The class manages a list of all instances of top-level windows that are in use,
  28. and each one is also given the concept of being "active". The active window is
  29. one that is actively being used by the user. This isn't quite the same as the
  30. component with the keyboard focus, because there may be a popup menu or other
  31. temporary window which gets keyboard focus while the active top level window is
  32. unchanged.
  33. A top-level window also has an optional drop-shadow.
  34. @see ResizableWindow, DocumentWindow, DialogWindow
  35. */
  36. class JUCE_API TopLevelWindow : public Component
  37. {
  38. public:
  39. //==============================================================================
  40. /** Creates a TopLevelWindow.
  41. @param name the name to give the component
  42. @param addToDesktop if true, the window will be automatically added to the
  43. desktop; if false, you can use it as a child component
  44. */
  45. TopLevelWindow (const String& name, bool addToDesktop);
  46. /** Destructor. */
  47. ~TopLevelWindow();
  48. //==============================================================================
  49. /** True if this is currently the TopLevelWindow that is actively being used.
  50. This isn't quite the same as having keyboard focus, because the focus may be
  51. on a child component or a temporary pop-up menu, etc, while this window is
  52. still considered to be active.
  53. @see activeWindowStatusChanged
  54. */
  55. bool isActiveWindow() const noexcept { return isCurrentlyActive; }
  56. //==============================================================================
  57. /** This will set the bounds of the window so that it's centred in front of another
  58. window.
  59. If your app has a few windows open and want to pop up a dialog box for one of
  60. them, you can use this to show it in front of the relevent parent window, which
  61. is a bit neater than just having it appear in the middle of the screen.
  62. If componentToCentreAround is 0, then the currently active TopLevelWindow will
  63. be used instead. If no window is focused, it'll just default to the middle of the
  64. screen.
  65. */
  66. void centreAroundComponent (Component* componentToCentreAround,
  67. int width, int height);
  68. //==============================================================================
  69. /** Turns the drop-shadow on and off. */
  70. void setDropShadowEnabled (bool useShadow);
  71. /** True if drop-shadowing is enabled. */
  72. bool isDropShadowEnabled() const noexcept { return useDropShadow; }
  73. /** Sets whether an OS-native title bar will be used, or a Juce one.
  74. @see isUsingNativeTitleBar
  75. */
  76. void setUsingNativeTitleBar (bool useNativeTitleBar);
  77. /** Returns true if the window is currently using an OS-native title bar.
  78. @see setUsingNativeTitleBar
  79. */
  80. bool isUsingNativeTitleBar() const noexcept;
  81. //==============================================================================
  82. /** Returns the number of TopLevelWindow objects currently in use.
  83. @see getTopLevelWindow
  84. */
  85. static int getNumTopLevelWindows() noexcept;
  86. /** Returns one of the TopLevelWindow objects currently in use.
  87. The index is 0 to (getNumTopLevelWindows() - 1).
  88. */
  89. static TopLevelWindow* getTopLevelWindow (int index) noexcept;
  90. /** Returns the currently-active top level window.
  91. There might not be one, of course, so this can return nullptr.
  92. */
  93. static TopLevelWindow* getActiveTopLevelWindow() noexcept;
  94. /** Adds the window to the desktop using the default flags. */
  95. void addToDesktop();
  96. //==============================================================================
  97. /** @internal */
  98. virtual void addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo = nullptr) override;
  99. protected:
  100. //==============================================================================
  101. /** This callback happens when this window becomes active or inactive.
  102. @see isActiveWindow
  103. */
  104. virtual void activeWindowStatusChanged();
  105. //==============================================================================
  106. /** @internal */
  107. void focusOfChildComponentChanged (FocusChangeType) override;
  108. /** @internal */
  109. void parentHierarchyChanged() override;
  110. /** @internal */
  111. virtual int getDesktopWindowStyleFlags() const;
  112. /** @internal */
  113. void recreateDesktopWindow();
  114. /** @internal */
  115. void visibilityChanged() override;
  116. private:
  117. friend class TopLevelWindowManager;
  118. friend class ResizableWindow;
  119. bool useDropShadow, useNativeTitleBar, isCurrentlyActive;
  120. ScopedPointer<DropShadower> shadower;
  121. void setWindowActive (bool);
  122. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TopLevelWindow)
  123. };
  124. #endif // JUCE_TOPLEVELWINDOW_H_INCLUDED