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.

172 lines
6.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_TOPLEVELWINDOW_JUCEHEADER__
  19. #define __JUCE_TOPLEVELWINDOW_JUCEHEADER__
  20. #include "../components/juce_Component.h"
  21. #include "../misc/juce_DropShadower.h"
  22. //==============================================================================
  23. /**
  24. A base class for top-level windows.
  25. This class is used for components that are considered a major part of your
  26. application - e.g. ResizableWindow, DocumentWindow, DialogWindow, AlertWindow,
  27. etc. Things like menus that pop up briefly aren't derived from it.
  28. A TopLevelWindow is probably on the desktop, but this isn't mandatory - it
  29. could itself be the child of another component.
  30. The class manages a list of all instances of top-level windows that are in use,
  31. and each one is also given the concept of being "active". The active window is
  32. one that is actively being used by the user. This isn't quite the same as the
  33. component with the keyboard focus, because there may be a popup menu or other
  34. temporary window which gets keyboard focus while the active top level window is
  35. unchanged.
  36. A top-level window also has an optional drop-shadow.
  37. @see ResizableWindow, DocumentWindow, DialogWindow
  38. */
  39. class JUCE_API TopLevelWindow : public Component
  40. {
  41. public:
  42. //==============================================================================
  43. /** Creates a TopLevelWindow.
  44. @param name the name to give the component
  45. @param addToDesktop if true, the window will be automatically added to the
  46. desktop; if false, you can use it as a child component
  47. */
  48. TopLevelWindow (const String& name, bool addToDesktop);
  49. /** Destructor. */
  50. ~TopLevelWindow();
  51. //==============================================================================
  52. /** True if this is currently the TopLevelWindow that is actively being used.
  53. This isn't quite the same as having keyboard focus, because the focus may be
  54. on a child component or a temporary pop-up menu, etc, while this window is
  55. still considered to be active.
  56. @see activeWindowStatusChanged
  57. */
  58. bool isActiveWindow() const noexcept { return windowIsActive_; }
  59. //==============================================================================
  60. /** This will set the bounds of the window so that it's centred in front of another
  61. window.
  62. If your app has a few windows open and want to pop up a dialog box for one of
  63. them, you can use this to show it in front of the relevent parent window, which
  64. is a bit neater than just having it appear in the middle of the screen.
  65. If componentToCentreAround is 0, then the currently active TopLevelWindow will
  66. be used instead. If no window is focused, it'll just default to the middle of the
  67. screen.
  68. */
  69. void centreAroundComponent (Component* componentToCentreAround,
  70. int width, int height);
  71. //==============================================================================
  72. /** Turns the drop-shadow on and off. */
  73. void setDropShadowEnabled (bool useShadow);
  74. /** True if drop-shadowing is enabled. */
  75. bool isDropShadowEnabled() const noexcept { return useDropShadow; }
  76. /** Sets whether an OS-native title bar will be used, or a Juce one.
  77. @see isUsingNativeTitleBar
  78. */
  79. void setUsingNativeTitleBar (bool useNativeTitleBar);
  80. /** Returns true if the window is currently using an OS-native title bar.
  81. @see setUsingNativeTitleBar
  82. */
  83. bool isUsingNativeTitleBar() const noexcept { return useNativeTitleBar && isOnDesktop(); }
  84. //==============================================================================
  85. /** Returns the number of TopLevelWindow objects currently in use.
  86. @see getTopLevelWindow
  87. */
  88. static int getNumTopLevelWindows() noexcept;
  89. /** Returns one of the TopLevelWindow objects currently in use.
  90. The index is 0 to (getNumTopLevelWindows() - 1).
  91. */
  92. static TopLevelWindow* getTopLevelWindow (int index) noexcept;
  93. /** Returns the currently-active top level window.
  94. There might not be one, of course, so this can return 0.
  95. */
  96. static TopLevelWindow* getActiveTopLevelWindow() noexcept;
  97. //==============================================================================
  98. /** @internal */
  99. virtual void addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo = nullptr);
  100. protected:
  101. //==============================================================================
  102. /** This callback happens when this window becomes active or inactive.
  103. @see isActiveWindow
  104. */
  105. virtual void activeWindowStatusChanged();
  106. //==============================================================================
  107. /** @internal */
  108. void focusOfChildComponentChanged (FocusChangeType cause);
  109. /** @internal */
  110. void parentHierarchyChanged();
  111. /** @internal */
  112. virtual int getDesktopWindowStyleFlags() const;
  113. /** @internal */
  114. void recreateDesktopWindow();
  115. /** @internal */
  116. void visibilityChanged();
  117. private:
  118. friend class TopLevelWindowManager;
  119. bool useDropShadow, useNativeTitleBar, windowIsActive_;
  120. ScopedPointer <DropShadower> shadower;
  121. void setWindowActive (bool isNowActive);
  122. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TopLevelWindow);
  123. };
  124. #endif // __JUCE_TOPLEVELWINDOW_JUCEHEADER__