|
|
@ -10,6 +10,7 @@ |
|
|
#include "WindowProtocol.h" |
|
|
#include "WindowProtocol.h" |
|
|
|
|
|
|
|
|
WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBaseImpl(events, gl) { |
|
|
WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBaseImpl(events, gl) { |
|
|
|
|
|
_children = std::list<WindowImpl*>(); |
|
|
_isClientAreaExtended = false; |
|
|
_isClientAreaExtended = false; |
|
|
_extendClientHints = AvnDefaultChrome; |
|
|
_extendClientHints = AvnDefaultChrome; |
|
|
_fullScreenActive = false; |
|
|
_fullScreenActive = false; |
|
|
@ -20,6 +21,7 @@ WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBase |
|
|
_lastWindowState = Normal; |
|
|
_lastWindowState = Normal; |
|
|
_actualWindowState = Normal; |
|
|
_actualWindowState = Normal; |
|
|
_lastTitle = @""; |
|
|
_lastTitle = @""; |
|
|
|
|
|
_parent = nullptr; |
|
|
WindowEvents = events; |
|
|
WindowEvents = events; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -28,24 +30,12 @@ void WindowImpl::HideOrShowTrafficLights() { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (id subview in Window.contentView.superview.subviews) { |
|
|
bool wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome); |
|
|
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) { |
|
|
bool hasTrafficLights = _isClientAreaExtended ? !wantsChrome : _decorations != SystemDecorationsFull; |
|
|
NSView *titlebarView = [subview subviews][0]; |
|
|
|
|
|
for (id button in titlebarView.subviews) { |
|
|
[[Window standardWindowButton:NSWindowCloseButton] setHidden:hasTrafficLights]; |
|
|
if ([button isKindOfClass:[NSButton class]]) { |
|
|
[[Window standardWindowButton:NSWindowMiniaturizeButton] setHidden:hasTrafficLights]; |
|
|
if (_isClientAreaExtended) { |
|
|
[[Window standardWindowButton:NSWindowZoomButton] setHidden:hasTrafficLights]; |
|
|
auto wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome); |
|
|
|
|
|
|
|
|
|
|
|
[button setHidden:!wantsChrome]; |
|
|
|
|
|
} else { |
|
|
|
|
|
[button setHidden:(_decorations != SystemDecorationsFull)]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[button setWantsLayer:true]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void WindowImpl::OnInitialiseNSWindow(){ |
|
|
void WindowImpl::OnInitialiseNSWindow(){ |
|
|
@ -61,6 +51,11 @@ void WindowImpl::OnInitialiseNSWindow(){ |
|
|
[GetWindowProtocol() setIsExtended:true]; |
|
|
[GetWindowProtocol() setIsExtended:true]; |
|
|
SetExtendClientArea(true); |
|
|
SetExtendClientArea(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(_parent != nullptr) |
|
|
|
|
|
{ |
|
|
|
|
|
SetParent(_parent); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
HRESULT WindowImpl::Show(bool activate, bool isDialog) { |
|
|
HRESULT WindowImpl::Show(bool activate, bool isDialog) { |
|
|
@ -90,26 +85,68 @@ HRESULT WindowImpl::SetParent(IAvnWindow *parent) { |
|
|
START_COM_CALL; |
|
|
START_COM_CALL; |
|
|
|
|
|
|
|
|
@autoreleasepool { |
|
|
@autoreleasepool { |
|
|
if (parent == nullptr) |
|
|
if(_parent != nullptr) |
|
|
return E_POINTER; |
|
|
{ |
|
|
|
|
|
_parent->_children.remove(this); |
|
|
|
|
|
auto parent = _parent; |
|
|
|
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
|
|
|
parent->BringToFront(); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
auto cparent = dynamic_cast<WindowImpl *>(parent); |
|
|
auto cparent = dynamic_cast<WindowImpl *>(parent); |
|
|
if (cparent == nullptr) |
|
|
|
|
|
return E_INVALIDARG; |
|
|
_parent = cparent; |
|
|
|
|
|
|
|
|
// If one tries to show a child window with a minimized parent window, then the parent window will be |
|
|
if(_parent != nullptr && Window != nullptr){ |
|
|
// restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive |
|
|
// If one tries to show a child window with a minimized parent window, then the parent window will be |
|
|
// state. Detect this and explicitly restore the parent window ourselves to avoid this situation. |
|
|
// restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive |
|
|
if (cparent->WindowState() == Minimized) |
|
|
// state. Detect this and explicitly restore the parent window ourselves to avoid this situation. |
|
|
cparent->SetWindowState(Normal); |
|
|
if (cparent->WindowState() == Minimized) |
|
|
|
|
|
cparent->SetWindowState(Normal); |
|
|
|
|
|
|
|
|
|
|
|
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary]; |
|
|
|
|
|
|
|
|
|
|
|
cparent->_children.push_back(this); |
|
|
|
|
|
|
|
|
|
|
|
UpdateStyle(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary]; |
|
|
return S_OK; |
|
|
[cparent->Window addChildWindow:Window ordered:NSWindowAbove]; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
UpdateStyle(); |
|
|
void WindowImpl::BringToFront() |
|
|
|
|
|
{ |
|
|
|
|
|
if(IsDialog()) |
|
|
|
|
|
{ |
|
|
|
|
|
Activate(); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
[Window orderFront:nullptr]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Window invalidateShadow]; |
|
|
|
|
|
|
|
|
|
|
|
for(auto iterator = _children.begin(); iterator != _children.end(); iterator++) |
|
|
|
|
|
{ |
|
|
|
|
|
(*iterator)->BringToFront(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return S_OK; |
|
|
bool WindowImpl::CanBecomeKeyWindow() |
|
|
|
|
|
{ |
|
|
|
|
|
for(auto iterator = _children.begin(); iterator != _children.end(); iterator++) |
|
|
|
|
|
{ |
|
|
|
|
|
if((*iterator)->IsDialog()) |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void WindowImpl::StartStateTransition() { |
|
|
void WindowImpl::StartStateTransition() { |
|
|
@ -523,7 +560,7 @@ bool WindowImpl::IsDialog() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
NSWindowStyleMask WindowImpl::GetStyle() { |
|
|
NSWindowStyleMask WindowImpl::GetStyle() { |
|
|
unsigned long s = this->_isDialog ? NSWindowStyleMaskDocModalWindow : NSWindowStyleMaskBorderless; |
|
|
unsigned long s = NSWindowStyleMaskBorderless; |
|
|
|
|
|
|
|
|
switch (_decorations) { |
|
|
switch (_decorations) { |
|
|
case SystemDecorationsNone: |
|
|
case SystemDecorationsNone: |
|
|
@ -535,7 +572,7 @@ NSWindowStyleMask WindowImpl::GetStyle() { |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case SystemDecorationsFull: |
|
|
case SystemDecorationsFull: |
|
|
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskBorderless; |
|
|
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable; |
|
|
|
|
|
|
|
|
if (_canResize) { |
|
|
if (_canResize) { |
|
|
s = s | NSWindowStyleMaskResizable; |
|
|
s = s | NSWindowStyleMaskResizable; |
|
|
@ -543,7 +580,7 @@ NSWindowStyleMask WindowImpl::GetStyle() { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ([Window parentWindow] == nullptr) { |
|
|
if (!IsDialog()) { |
|
|
s |= NSWindowStyleMaskMiniaturizable; |
|
|
s |= NSWindowStyleMaskMiniaturizable; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|