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.

juce_TopLevelWindow.h 6.5KB

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