1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

DropShadower: Fix bug when setOwner() is called with a component without a parent

Until now when a Component without a parent was passed to setOwner() the
ParentVisibilityChangedListener would not install any hooks to any
components, hence it would not be notified, when the owner was added
to a parent.
This commit is contained in:
attila 2022-05-17 12:45:43 +02:00
parent 2c2c21ebc9
commit 338c045719

View file

@ -93,8 +93,7 @@ public:
ParentVisibilityChangedListener (Component& r, ComponentListener& l)
: root (&r), listener (&l)
{
if (auto* firstParent = root->getParentComponent())
updateParentHierarchy (firstParent);
updateParentHierarchy();
if ((SystemStats::getOperatingSystemType() & SystemStats::Windows) != 0)
{
@ -110,16 +109,16 @@ public:
comp->removeComponentListener (this);
}
void componentVisibilityChanged (Component&) override
void componentVisibilityChanged (Component& component) override
{
listener->componentVisibilityChanged (*root);
if (root != &component)
listener->componentVisibilityChanged (*root);
}
void componentParentHierarchyChanged (Component& component) override
{
if (root == &component)
if (auto* firstParent = root->getParentComponent())
updateParentHierarchy (firstParent);
updateParentHierarchy();
}
bool isWindowOnVirtualDesktop() const noexcept { return isOnVirtualDesktop; }
@ -140,13 +139,13 @@ private:
WeakReference<Component> ref;
};
void updateParentHierarchy (Component* rootComponent)
void updateParentHierarchy()
{
const auto lastSeenComponents = std::exchange (observedComponents, [&]
{
std::set<ComponentWithWeakReference> result;
for (auto node = rootComponent; node != nullptr; node = node->getParentComponent())
for (auto node = root; node != nullptr; node = node->getParentComponent())
result.emplace (*node);
return result;