Browse Source

MacOS: Disable window controls for windows created by JUCE when a Component is modal

The change does not affect plugin windows, which are created by the
host.
v7.0.12
attila 2 years ago
parent
commit
fb14118771
3 changed files with 60 additions and 1 deletions
  1. +5
    -0
      modules/juce_gui_basics/components/juce_ModalComponentManager.cpp
  2. +25
    -0
      modules/juce_gui_basics/detail/juce_ComponentHelpers.h
  3. +30
    -1
      modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm

+ 5
- 0
modules/juce_gui_basics/components/juce_ModalComponentManager.cpp View File

@@ -106,7 +106,10 @@ JUCE_IMPLEMENT_SINGLETON (ModalComponentManager)
void ModalComponentManager::startModal (Component* component, bool autoDelete)
{
if (component != nullptr)
{
stack.add (new ModalItem (component, autoDelete));
detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().modalComponentManagerChanged();
}
}
void ModalComponentManager::attachCallback (Component* component, Callback* callback)
@@ -210,6 +213,8 @@ void ModalComponentManager::handleAsyncUpdate()
item->callbacks.getUnchecked (j)->modalStateFinished (item->returnValue);
compToDelete.deleteAndZero();
detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().modalComponentManagerChanged();
}
}
}


+ 25
- 0
modules/juce_gui_basics/detail/juce_ComponentHelpers.h View File

@@ -250,6 +250,31 @@ struct ComponentHelpers
if (modalWouldBlockComponent (*c, &modal))
(c->*function) (ms, SH::screenPosToLocalPos (*c, ms.getScreenPosition()), Time::getCurrentTime());
}
class ModalComponentManagerChangeNotifier
{
public:
static auto& getInstance()
{
static ModalComponentManagerChangeNotifier instance;
return instance;
}
ErasedScopeGuard addListener (std::function<void()> l)
{
return listeners.addListener (std::move (l));
}
void modalComponentManagerChanged()
{
listeners.call();
}
private:
ModalComponentManagerChangeNotifier() = default;
detail::CallbackListenerList<> listeners;
};
};
} // namespace juce::detail

+ 30
- 1
modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm View File

@@ -1712,7 +1712,7 @@ public:
NSWindow* window = nil;
NSView* view = nil;
WeakReference<Component> safeComponent;
bool isSharedWindow = false;
const bool isSharedWindow = false;
#if USE_COREGRAPHICS_RENDERING
bool usingCoreGraphics = true;
#else
@@ -1998,10 +1998,39 @@ private:
#endif
}
void modalComponentManagerChanged()
{
if (isSharedWindow)
return;
auto style = [window styleMask];
if (ModalComponentManager::getInstance()->getNumModalComponents() > 0)
{
style &= ~NSWindowStyleMaskMiniaturizable;
style &= ~NSWindowStyleMaskClosable;
}
else
{
const auto flags = getStyleFlags();
if ((flags & windowHasMinimiseButton) != 0) style |= NSWindowStyleMaskMiniaturizable;
if ((flags & windowHasCloseButton) != 0) style |= NSWindowStyleMaskClosable;
}
[window setStyleMask: style];
}
//==============================================================================
std::vector<ScopedNotificationCenterObserver> scopedObservers;
std::vector<ScopedNotificationCenterObserver> windowObservers;
ErasedScopeGuard modalChangeListenerScope =
detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().addListener ([this]
{
modalComponentManagerChanged();
});
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NSViewComponentPeer)
};


Loading…
Cancel
Save