JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_TopLevelWindow.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
31 : Component (name)
32{
33 setTitle (name);
34
35 setOpaque (true);
36
38 Component::addToDesktop (TopLevelWindow::getDesktopWindowStyleFlags());
39 else
41
44 isCurrentlyActive = detail::TopLevelWindowManager::getInstance()->addWindow (this);
45}
46
48{
49 shadower = nullptr;
50 detail::TopLevelWindowManager::getInstance()->removeWindow (this);
51}
52
53//==============================================================================
55{
56 auto* wm = detail::TopLevelWindowManager::getInstance();
57
58 if (hasKeyboardFocus (true))
59 wm->checkFocus();
60 else
61 wm->checkFocusAsync();
62}
63
64void TopLevelWindow::setWindowActive (const bool isNowActive)
65{
66 if (isCurrentlyActive != isNowActive)
67 {
68 isCurrentlyActive = isNowActive;
70 }
71}
72
76
78{
79 return useNativeTitleBar && (isOnDesktop() || ! isShowing());
80}
81
83{
84 if (isShowing())
85 if (auto* p = getPeer())
86 if ((p->getStyleFlags() & (ComponentPeer::windowIsTemporary
88 toFront (true);
89}
90
95
96int TopLevelWindow::getDesktopWindowStyleFlags() const
97{
99
100 if (useDropShadow) styleFlags |= ComponentPeer::windowHasDropShadow;
101 if (useNativeTitleBar) styleFlags |= ComponentPeer::windowHasTitleBar;
102
103 return styleFlags;
104}
105
107{
108 useDropShadow = useShadow;
109
110 if (isOnDesktop())
111 {
112 shadower = nullptr;
113 Component::addToDesktop (getDesktopWindowStyleFlags());
114 }
115 else
116 {
117 if (useShadow && isOpaque())
118 {
119 if (shadower == nullptr)
120 {
122
123 if (shadower != nullptr)
124 shadower->setOwner (this);
125 }
126 }
127 else
129 shadower = nullptr;
130 }
131 }
133
135{
136 if (useNativeTitleBar != shouldUseNativeTitleBar)
137 {
139 useNativeTitleBar = shouldUseNativeTitleBar;
140 recreateDesktopWindow();
142 }
143}
144
145void TopLevelWindow::recreateDesktopWindow()
146{
147 if (isOnDesktop())
148 {
149 Component::addToDesktop (getDesktopWindowStyleFlags());
150 toFront (true);
151 }
152}
153
155{
156 shadower = nullptr;
157 Component::addToDesktop (getDesktopWindowStyleFlags());
158 setDropShadowEnabled (isDropShadowEnabled()); // force an update to clear away any fake shadows if necessary.
159}
160
162{
163 /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
164 because this class needs to make sure its layout corresponds with settings like whether
165 it's got a native title bar or not.
166
167 If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
168 method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
169 method, then add or remove whatever flags are necessary from this value before returning it.
170 */
172 == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
173
175
176 if (windowStyleFlags != getDesktopWindowStyleFlags())
178}
179
181{
182 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::window);
183}
184
185//==============================================================================
186void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
187{
188 if (c == nullptr)
190
191 if (c == nullptr || c->getBounds().isEmpty())
192 {
193 centreWithSize (width, height);
194 }
195 else
196 {
198
199 const auto [targetCentre, parentArea] = [&]
200 {
201 const auto globalTargetCentre = c->localPointToGlobal (c->getLocalBounds().getCentre()) / scale;
202
203 if (auto* parent = getParentComponent())
204 return std::make_pair (parent->getLocalPoint (nullptr, globalTargetCentre), parent->getLocalBounds());
205
207 }();
208
209 setBounds (Rectangle<int> (targetCentre.x - width / 2,
210 targetCentre.y - height / 2,
211 width, height)
212 .constrainedWithin (parentArea.reduced (12, 12)));
213 }
214}
215
216//==============================================================================
218{
219 return detail::TopLevelWindowManager::getInstance()->windows.size();
220}
221
223{
224 return detail::TopLevelWindowManager::getInstance()->windows [index];
225}
226
228{
229 TopLevelWindow* best = nullptr;
230 int bestNumTWLParents = -1;
231
232 for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
233 {
235
236 if (tlw->isActiveWindow())
237 {
238 int numTWLParents = 0;
239
240 for (auto* c = tlw->getParentComponent(); c != nullptr; c = c->getParentComponent())
241 if (dynamic_cast<const TopLevelWindow*> (c) != nullptr)
243
245 {
246 best = tlw;
248 }
249 }
250 }
251
252 return best;
253}
254
255} // namespace juce
@ windowIsTemporary
Indicates that the window is a temporary popup, like a menu, tooltip, etc.
@ windowIgnoresKeyPresses
Tells the window not to catch any keypresses.
@ windowHasDropShadow
Indicates that the window should have a drop-shadow (this may not be possible on all platforms).
@ windowAppearsOnTaskbar
Indicates that the window should have a corresponding entry on the taskbar (ignored on MacOSX)
@ windowIsSemiTransparent
Not intended for public use - makes a window transparent.
@ windowHasTitleBar
Indicates that the window should have a normal OS-specific title bar and frame.
The base class for all JUCE user-interface objects.
void setBroughtToFrontOnMouseClick(bool shouldBeBroughtToFront) noexcept
Indicates whether the component should be brought to the front when clicked.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
void setTitle(const String &newTitle)
Sets the title for this component.
bool isOpaque() const noexcept
Returns true if no parts of this component are transparent.
void toFront(bool shouldAlsoGainKeyboardFocus)
Brings the component to the front of its siblings.
bool isShowing() const
Tests whether this component and all its parents are visible.
void sendLookAndFeelChange()
Calls the methods repaint(), lookAndFeelChanged(), and colourChanged() in this component and all its ...
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
bool hasKeyboardFocus(bool trueIfChildIsFocused) const
Returns true if this component currently has the keyboard focus.
void setOpaque(bool shouldBeOpaque)
Indicates whether any parts of the component might be transparent.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
bool isOnDesktop() const noexcept
Returns true if this component is currently showing on the desktop.
virtual void addToDesktop(int windowStyleFlags, void *nativeWindowToAttachTo=nullptr)
Makes this component appear as a window on the desktop.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
Rectangle< int > getParentMonitorArea() const
Returns the screen coordinates of the monitor that contains this component.
Point< int > localPointToGlobal(Point< int > localPoint) const
Converts a point relative to this component's top-left into a screen coordinate.
ComponentPeer * getPeer() const
Returns the heavyweight window that contains this component.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
void centreWithSize(int width, int height)
Changes the component's size and centres it within its parent.
virtual float getDesktopScaleFactor() const
Returns the default scale factor to use for this component when it is placed on the desktop.
float getGlobalScaleFactor() const noexcept
Returns the current global scale factor, as set by setGlobalScaleFactor().
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
virtual std::unique_ptr< DropShadower > createDropShadowerForComponent(Component &)=0
Creates a drop-shadower for a given component, if required.
Manages a rectangle and allows geometric operations to be performed on it.
Point< ValueType > getCentre() const noexcept
Returns the centre point of the rectangle.
Rectangle constrainedWithin(Rectangle areaToFitWithin) const noexcept
Tries to fit this rectangle within a target area, returning the result.
bool isEmpty() const noexcept
Returns true if the rectangle's width or height are zero or less.
The JUCE String class!
Definition juce_String.h:53
A base class for top-level windows.
bool isDropShadowEnabled() const noexcept
True if drop-shadowing is enabled.
void centreAroundComponent(Component *componentToCentreAround, int width, int height)
This will set the bounds of the window so that it's centred in front of another window.
void visibilityChanged() override
Called when this component's visibility changes.
~TopLevelWindow() override
Destructor.
static int getNumTopLevelWindows() noexcept
Returns the number of TopLevelWindow objects currently in use.
void setDropShadowEnabled(bool useShadow)
Turns the drop-shadow on and off.
static TopLevelWindow * getTopLevelWindow(int index) noexcept
Returns one of the TopLevelWindow objects currently in use.
static TopLevelWindow * getActiveTopLevelWindow() noexcept
Returns the currently-active top level window.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
bool isUsingNativeTitleBar() const noexcept
Returns true if the window is currently using an OS-native title bar.
void parentHierarchyChanged() override
Called to indicate that the component's parents have changed.
TopLevelWindow(const String &name, bool addToDesktop)
Creates a TopLevelWindow.
virtual void activeWindowStatusChanged()
This callback happens when this window becomes active or inactive.
void focusOfChildComponentChanged(FocusChangeType) override
Called to indicate a change in whether or not this component is the parent of the currently-focused c...
void setUsingNativeTitleBar(bool useNativeTitleBar)
Sets whether an OS-native title bar will be used, or a JUCE one.
void addToDesktop()
Adds the window to the desktop using the default flags.
#define jassert(expression)
Platform-independent assertion macro.
T make_pair(T... args)
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88