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

7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A base class for top-level windows.
  24. This class is used for components that are considered a major part of your
  25. application - e.g. ResizableWindow, DocumentWindow, DialogWindow, AlertWindow,
  26. etc. Things like menus that pop up briefly aren't derived from it.
  27. A TopLevelWindow is probably on the desktop, but this isn't mandatory - it
  28. could itself be the child of another component.
  29. The class manages a list of all instances of top-level windows that are in use,
  30. and each one is also given the concept of being "active". The active window is
  31. one that is actively being used by the user. This isn't quite the same as the
  32. component with the keyboard focus, because there may be a popup menu or other
  33. temporary window which gets keyboard focus while the active top level window is
  34. unchanged.
  35. A top-level window also has an optional drop-shadow.
  36. @see ResizableWindow, DocumentWindow, DialogWindow
  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();
  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 = false, isCurrentlyActive = false;
  122. ScopedPointer<DropShadower> shadower;
  123. void setWindowActive (bool);
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TopLevelWindow)
  125. };
  126. } // namespace juce