Browse Source

OSX implement SetParent

pull/3943/head
Dan Walmsley 6 years ago
parent
commit
86ac0ff5a5
  1. 5
      native/Avalonia.Native/inc/avalonia-native.h
  2. 3
      native/Avalonia.Native/src/OSX/window.h
  3. 78
      native/Avalonia.Native/src/OSX/window.mm
  4. 3
      src/Avalonia.Controls/Platform/IWindowImpl.cs
  5. 2
      src/Avalonia.Controls/Window.cs
  6. 2
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  7. 2
      src/Avalonia.DesignerSupport/Remote/Stubs.cs
  8. 5
      src/Avalonia.Native/PopupImpl.cs
  9. 9
      src/Avalonia.Native/WindowImpl.cs
  10. 2
      src/Avalonia.X11/X11Window.cs
  11. 2
      src/Windows/Avalonia.Win32/WindowImpl.cs

5
native/Avalonia.Native/inc/avalonia-native.h

@ -267,7 +267,8 @@ AVNCOM(IAvnPopup, 03) : virtual IAvnWindowBase
AVNCOM(IAvnWindow, 04) : virtual IAvnWindowBase
{
virtual HRESULT ShowDialog (IAvnWindow* parent) = 0;
virtual HRESULT SetEnabled (bool enable) = 0;
virtual HRESULT SetParent (IAvnWindow* parent) = 0;
virtual HRESULT SetCanResize(bool value) = 0;
virtual HRESULT SetDecorations(SystemDecorations value) = 0;
virtual HRESULT SetTitle (void* utf8Title) = 0;
@ -309,6 +310,8 @@ AVNCOM(IAvnWindowEvents, 06) : IAvnWindowBaseEvents
virtual bool Closing () = 0;
virtual void WindowStateChanged (AvnWindowState state) = 0;
virtual void GotInputWhenDisabled () = 0;
};
AVNCOM(IAvnMacOptions, 07) : IUnknown

3
native/Avalonia.Native/src/OSX/window.h

@ -19,8 +19,7 @@ class WindowBaseImpl;
-(void) pollModalSession: (NSModalSession _Nonnull) session;
-(void) restoreParentWindow;
-(bool) shouldTryToHandleEvents;
-(bool) isModal;
-(void) setModal: (bool) isModal;
-(void) setEnabled: (bool) enable;
-(void) showAppMenuOnly;
-(void) showWindowMenuWithAppMenu;
-(void) applyMenu:(NSMenu* _Nullable)menu;

78
native/Avalonia.Native/src/OSX/window.mm

@ -29,6 +29,7 @@ public:
NSString* _lastTitle;
IAvnMenu* _mainMenu;
bool _shown;
bool _isChild;
WindowBaseImpl(IAvnWindowBaseEvents* events, IAvnGlContext* gl)
{
@ -36,6 +37,7 @@ public:
_mainMenu = nullptr;
BaseEvents = events;
_glContext = gl;
_isChild = false;
renderTarget = [[IOSurfaceRenderTarget alloc] initWithOpenGlContext: gl];
View = [[AvnView alloc] initWithParent:this];
@ -497,12 +499,7 @@ private:
virtual HRESULT Show () override
{
@autoreleasepool
{
if([Window parentWindow] != nil)
[[Window parentWindow] removeChildWindow:Window];
[Window setModal:FALSE];
{
WindowBaseImpl::Show();
HideOrShowTrafficLights();
@ -511,7 +508,16 @@ private:
}
}
virtual HRESULT ShowDialog (IAvnWindow* parent) override
virtual HRESULT SetEnabled (bool enable) override
{
@autoreleasepool
{
[Window setEnabled:enable];
return S_OK;
}
}
virtual HRESULT SetParent (IAvnWindow* parent) override
{
@autoreleasepool
{
@ -522,12 +528,10 @@ private:
if(cparent == nullptr)
return E_INVALIDARG;
[Window setModal:TRUE];
_isChild = true;
[cparent->Window addChildWindow:Window ordered:NSWindowAbove];
WindowBaseImpl::Show();
HideOrShowTrafficLights();
UpdateStyle();
return S_OK;
}
@ -883,15 +887,15 @@ protected:
switch (_decorations)
{
case SystemDecorationsNone:
s = s | NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskMiniaturizable;
s = s | NSWindowStyleMaskFullSizeContentView;
break;
case SystemDecorationsBorderOnly:
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskMiniaturizable;
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView;
break;
case SystemDecorationsFull:
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskBorderless;
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskBorderless;
if(_canResize)
{
@ -900,6 +904,10 @@ protected:
break;
}
if(!_isChild)
{
s |= NSWindowStyleMaskMiniaturizable;
}
return s;
}
};
@ -1089,7 +1097,15 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
- (void)mouseEvent:(NSEvent *)event withType:(AvnRawMouseEventType) type
{
if([self ignoreUserInput])
{
auto window = dynamic_cast<WindowImpl*>(_parent.getRaw());
if(window != nullptr)
{
window->WindowEvents->GotInputWhenDisabled();
}
return;
}
[self becomeFirstResponder];
auto localPoint = [self convertPoint:[event locationInWindow] toView:self];
@ -1234,7 +1250,16 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
- (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type
{
if([self ignoreUserInput])
{
auto window = dynamic_cast<WindowImpl*>(_parent.getRaw());
if(window != nullptr)
{
window->WindowEvents->GotInputWhenDisabled();
}
return;
}
auto key = s_KeyMap[[event keyCode]];
auto timestamp = [event timestamp] * 1000;
@ -1416,7 +1441,7 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
ComPtr<WindowBaseImpl> _parent;
bool _canBecomeKeyAndMain;
bool _closed;
bool _isModal;
bool _isEnabled;
AvnMenu* _menu;
double _lastScaling;
}
@ -1538,6 +1563,7 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
_parent = parent;
[self setDelegate:self];
_closed = false;
_isEnabled = true;
_lastScaling = [self backingScaleFactor];
[self setOpaque:NO];
@ -1604,28 +1630,12 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
-(bool)shouldTryToHandleEvents
{
for(NSWindow* uch in [self childWindows])
{
auto ch = objc_cast<AvnWindow>(uch);
if(ch == nil)
continue;
if(![ch isModal])
continue;
return FALSE;
}
return TRUE;
}
-(bool) isModal
{
return _isModal;
return _isEnabled;
}
-(void) setModal: (bool) isModal
-(void) setEnabled:(bool)enable
{
_isModal = isModal;
_isEnabled = enable;
}
-(void)makeKeyWindow

3
src/Avalonia.Controls/Platform/IWindowImpl.cs

@ -29,8 +29,7 @@ namespace Avalonia.Platform
/// Sets the parent of the window.
/// </summary>
/// <param name="parent">The parent <see cref="IWindowImpl"/>.</param>
/// <param name="isModal">If this window is modal or not.</param>
void SetParent(IWindowImpl parent, bool isModal);
void SetParent(IWindowImpl parent);
/// <summary>
/// Disables the window for example when a modal dialog is open.

2
src/Avalonia.Controls/Window.cs

@ -539,7 +539,7 @@ namespace Avalonia.Controls
using (BeginAutoSizing())
{
PlatformImpl.SetParent(owner.PlatformImpl, true);
PlatformImpl.SetParent(owner.PlatformImpl);
Owner = owner;
owner.AddChild(this);
PlatformImpl?.Show();

2
src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs

@ -117,7 +117,7 @@ namespace Avalonia.DesignerSupport.Remote
{
}
public void SetParent(IWindowImpl parent, bool isModal)
public void SetParent(IWindowImpl parent)
{
}

2
src/Avalonia.DesignerSupport/Remote/Stubs.cs

@ -130,7 +130,7 @@ namespace Avalonia.DesignerSupport.Remote
{
}
public void SetParent(IWindowImpl parent, bool isModal)
public void SetParent(IWindowImpl parent)
{
}

5
src/Avalonia.Native/PopupImpl.cs

@ -43,6 +43,11 @@ namespace Avalonia.Native
_parent = parent;
}
public void GotInputWhenDisabled()
{
// NOP on Popup
}
bool IAvnWindowEvents.Closing()
{
return true;

9
src/Avalonia.Native/WindowImpl.cs

@ -52,6 +52,11 @@ namespace Avalonia.Native
{
_parent.WindowStateChanged?.Invoke((WindowState)state);
}
void IAvnWindowEvents.GotInputWhenDisabled ()
{
_parent.GotInputWhenDisabled?.Invoke();
}
}
public IAvnWindow Native => _native;
@ -114,12 +119,14 @@ namespace Avalonia.Native
public Action GotInputWhenDisabled { get; set; }
public void SetParent(IWindowImpl parent, bool isModal)
public void SetParent(IWindowImpl parent)
{
_native.SetParent(((WindowImpl)parent).Native);
}
public void SetEnabled(bool enable)
{
_native.SetEnabled(enable);
}
}
}

2
src/Avalonia.X11/X11Window.cs

@ -1033,7 +1033,7 @@ namespace Avalonia.X11
ChangeWMAtoms(value, _x11.Atoms._NET_WM_STATE_ABOVE);
}
public void SetParent(IWindowImpl parent, bool isModal)
public void SetParent(IWindowImpl parent)
{
SetTransientParent((X11Window)parent);
}

2
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -351,7 +351,7 @@ namespace Avalonia.Win32
public Action GotInputWhenDisabled { get; set; }
public void SetParent(IWindowImpl parent, bool isModal)
public void SetParent(IWindowImpl parent)
{
_parent = (WindowImpl)parent;
SetOwnerHandle(_parent._hwnd);

Loading…
Cancel
Save