LMMS
Loading...
Searching...
No Matches
juce_ComponentMovementWatcher.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
30 : component (comp),
31 wasShowing (comp->isShowing())
32{
33 jassert (component != nullptr); // can't use this with a null pointer..
34
35 component->addComponentListener (this);
37}
38
40{
41 if (component != nullptr)
42 component->removeComponentListener (this);
43
44 unregister();
45}
46
47//==============================================================================
49{
50 if (component != nullptr && ! reentrant)
51 {
52 const ScopedValueSetter<bool> setter (reentrant, true);
53
54 auto* peer = component->getPeer();
55 auto peerID = peer != nullptr ? peer->getUniqueID() : 0;
56
57 if (peerID != lastPeerID)
58 {
60
61 if (component == nullptr)
62 return;
63
64 lastPeerID = peerID;
65 }
66
67 unregister();
69
71
72 if (component != nullptr)
74 }
75}
77void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
78{
79 if (component != nullptr)
80 {
81 if (wasMoved)
82 {
83 Point<int> newPos;
84 auto* top = component->getTopLevelComponent();
85
86 if (top != component)
87 newPos = top->getLocalPoint (component, Point<int>());
88 else
89 newPos = top->getPosition();
90
91 wasMoved = lastBounds.getPosition() != newPos;
92 lastBounds.setPosition (newPos);
93 }
94
95 wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
96 lastBounds.setSize (component->getWidth(), component->getHeight());
97
98 if (wasMoved || wasResized)
99 componentMovedOrResized (wasMoved, wasResized);
100 }
101}
102
104{
105 registeredParentComps.removeFirstMatchingValue (&comp);
106
107 if (component == &comp)
108 unregister();
109}
110
112{
113 if (component != nullptr)
114 {
115 const bool isShowingNow = component->isShowing();
116
117 if (wasShowing != isShowingNow)
118 {
119 wasShowing = isShowingNow;
121 }
122 }
123}
124
126{
127 for (auto* p = component->getParentComponent(); p != nullptr; p = p->getParentComponent())
128 {
129 p->addComponentListener (this);
131 }
132}
133
135{
136 for (auto* c : registeredParentComps)
137 c->removeComponentListener (this);
138
139 registeredParentComps.clear();
140}
141
142} // namespace juce
Definition juce_Component.h:36
void componentBeingDeleted(Component &) override
Definition juce_ComponentMovementWatcher.cpp:103
virtual void componentMovedOrResized(bool wasMoved, bool wasResized)=0
uint32 lastPeerID
Definition juce_ComponentMovementWatcher.h:85
void componentParentHierarchyChanged(Component &) override
Definition juce_ComponentMovementWatcher.cpp:48
bool wasShowing
Definition juce_ComponentMovementWatcher.h:87
Rectangle< int > lastBounds
Definition juce_ComponentMovementWatcher.h:88
WeakReference< Component > component
Definition juce_ComponentMovementWatcher.h:84
bool reentrant
Definition juce_ComponentMovementWatcher.h:87
void registerWithParentComps()
Definition juce_ComponentMovementWatcher.cpp:125
virtual void componentPeerChanged()=0
void unregister()
Definition juce_ComponentMovementWatcher.cpp:134
virtual void componentVisibilityChanged()=0
ComponentMovementWatcher(Component *componentToWatch)
Definition juce_ComponentMovementWatcher.cpp:29
Array< Component * > registeredParentComps
Definition juce_ComponentMovementWatcher.h:86
~ComponentMovementWatcher() override
Definition juce_ComponentMovementWatcher.cpp:39
void componentMovedOrResized(bool, bool) override
Definition juce_NativeScaleFactorNotifier.h:58
Definition juce_Point.h:42
Definition juce_ScopedValueSetter.h:55
#define jassert(expression)
static int JUCE_CDECL comp(const void *a, const void *b)
Definition lsp.c:298
Definition carla_juce.cpp:31
uch * p
Definition crypt.c:594
return c
Definition crypt.c:175