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_TopLevelWindowManager.h
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::detail
27{
28
29/* Keeps track of the active top level window. */
31 private DeletedAtShutdown
32{
33public:
34 TopLevelWindowManager() = default;
35
36 ~TopLevelWindowManager() override
37 {
39 }
40
42
43 static void checkCurrentlyFocusedTopLevelWindow()
44 {
45 if (auto* wm = TopLevelWindowManager::getInstanceWithoutCreating())
46 wm->checkFocusAsync();
47 }
48
49 void checkFocusAsync()
50 {
51 startTimer (10);
52 }
53
54 void checkFocus()
55 {
56 startTimer (jmin (1731, getTimerInterval() * 2));
57
58 auto* newActive = findCurrentlyActiveWindow();
59
60 if (newActive != currentActive)
61 {
62 currentActive = newActive;
63
64 for (int i = windows.size(); --i >= 0;)
65 if (auto* tlw = windows[i])
66 tlw->setWindowActive (isWindowActive (tlw));
67
68 Desktop::getInstance().triggerFocusCallback();
69 }
70 }
71
72 bool addWindow (TopLevelWindow* const w)
73 {
74 windows.add (w);
75 checkFocusAsync();
76
77 return isWindowActive (w);
78 }
79
80 void removeWindow (TopLevelWindow* const w)
81 {
82 checkFocusAsync();
83
84 if (currentActive == w)
85 currentActive = nullptr;
86
87 windows.removeFirstMatchingValue (w);
88
89 if (windows.isEmpty())
90 deleteInstance();
91 }
92
94
95private:
96 TopLevelWindow* currentActive = nullptr;
97
98 void timerCallback() override
99 {
100 checkFocus();
101 }
102
103 bool isWindowActive (TopLevelWindow* const tlw) const
104 {
105 return (tlw == currentActive
106 || tlw->isParentOf (currentActive)
107 || tlw->hasKeyboardFocus (true))
108 && tlw->isShowing();
109 }
110
111 TopLevelWindow* findCurrentlyActiveWindow() const
112 {
114 {
116 auto* w = dynamic_cast<TopLevelWindow*> (focusedComp);
117
118 if (w == nullptr && focusedComp != nullptr)
120
121 if (w == nullptr)
122 w = currentActive;
123
124 if (w != nullptr && w->isShowing())
125 return w;
126 }
127
128 return nullptr;
129 }
130
132};
133
135
136} // namespace juce::detail
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
static Component *JUCE_CALLTYPE getCurrentlyFocusedComponent() noexcept
Returns the component that currently has the keyboard focus.
bool isShowing() const
Tests whether this component and all its parents are visible.
bool isParentOf(const Component *possibleChild) const noexcept
Checks whether a component is anywhere inside this component or its children.
TargetClass * findParentComponentOfClass() const
Searches the parent components for a component of a specified class.
Classes derived from this will be automatically deleted when the application exits.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
static bool JUCE_CALLTYPE isForegroundProcess()
Returns true if this application process is the one that the user is currently using.
Makes repeated callbacks to a virtual method at a specified time interval.
Definition juce_Timer.h:52
int getTimerInterval() const noexcept
Returns the timer's interval.
Definition juce_Timer.h:116
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
A base class for top-level windows.
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
#define JUCE_IMPLEMENT_SINGLETON(Classname)
This is a counterpart to the JUCE_DECLARE_SINGLETON macros.
#define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL(Classname)
Macro to declare member variables and methods for a singleton class.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
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