Browse Source

NSViewComponentPeer: Allow restoring previous size when zooming a non-native window

v6.1.6
reuk 3 years ago
parent
commit
19536fc7a7
1 changed files with 18 additions and 14 deletions
  1. +18
    -14
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm

+ 18
- 14
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -1625,6 +1625,7 @@ public:
String stringBeingComposed; String stringBeingComposed;
NSNotificationCenter* notificationCenter = nil; NSNotificationCenter* notificationCenter = nil;
Rectangle<float> lastSizeBeforeZoom;
RectangleList<float> deferredRepaints; RectangleList<float> deferredRepaints;
uint32 lastRepaintTime; uint32 lastRepaintTime;
@@ -2384,39 +2385,42 @@ private:
#endif #endif
} }
static NSRect windowWillUseStandardFrame (id self, SEL, NSWindow*, NSRect r)
static NSRect windowWillUseStandardFrame (id self, SEL, NSWindow* window, NSRect r)
{ {
if (auto* owner = getOwner (self)) if (auto* owner = getOwner (self))
{ {
if (auto* constrainer = owner->getConstrainer()) if (auto* constrainer = owner->getConstrainer())
{ {
const auto originalBounds = [&]() -> Rectangle<float>
if (auto* screen = [window screen])
{ {
const auto screenBounds = owner->getComponent().getScreenBounds();
const auto safeScreenBounds = convertToRectFloat (flippedScreenRect (owner->hasNativeTitleBar() ? r : [screen visibleFrame]));
const auto originalBounds = owner->getFrameSize().addedTo (owner->getComponent().getScreenBounds()).toFloat();
const auto expanded = originalBounds.withWidth ((float) constrainer->getMaximumWidth())
.withHeight ((float) constrainer->getMaximumHeight());
const auto constrained = expanded.constrainedWithin (safeScreenBounds);
if (const auto frameSize = owner->getFrameSizeIfPresent())
return frameSize->addedTo (screenBounds).toFloat();
return screenBounds.toFloat();
}();
return flippedScreenRect (makeNSRect ([&]
{
if (constrained == owner->getBounds().toFloat())
return owner->lastSizeBeforeZoom.toFloat();
const auto expanded = originalBounds.withWidth ((float) constrainer->getMaximumWidth())
.withHeight ((float) constrainer->getMaximumHeight());
const auto constrained = expanded.constrainedWithin (convertToRectFloat (flippedScreenRect (r)));
return flippedScreenRect (makeNSRect (constrained));
owner->lastSizeBeforeZoom = owner->getBounds().toFloat();
return constrained;
}()));
}
} }
} }
return r; return r;
} }
static BOOL windowShouldZoomToFrame (id self, SEL, NSWindow* window, NSRect frame)
static BOOL windowShouldZoomToFrame (id self, SEL, NSWindow*, NSRect)
{ {
if (auto* owner = getOwner (self)) if (auto* owner = getOwner (self))
if (owner->hasNativeTitleBar() && (owner->getStyleFlags() & ComponentPeer::windowIsResizable) == 0) if (owner->hasNativeTitleBar() && (owner->getStyleFlags() & ComponentPeer::windowIsResizable) == 0)
return NO; return NO;
return convertToRectFloat ([window frame]).withZeroOrigin() != convertToRectFloat (frame).withZeroOrigin();
return YES;
} }
static BOOL canBecomeKeyWindow (id self, SEL) static BOOL canBecomeKeyWindow (id self, SEL)


Loading…
Cancel
Save