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.2KB

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