Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Add handle constructors to EtoWindow/EtoDialogWindow #2441

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/Eto.Mac/Forms/DialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class EtoDialogWindow : EtoWindow
get { return base.Handler as DialogHandler; }
set { base.Handler = value; }
}

public EtoDialogWindow(NativeHandle handle)
: base(handle)
{
}

public EtoDialogWindow()
: base(new CGRect(0, 0, 200, 200), NSWindowStyle.Closable | NSWindowStyle.Titled, NSBackingStore.Buffered, false)
Expand All @@ -46,15 +51,12 @@ public EtoDialogWindow()
[Export("cancelOperation:")]
public void CancelOperation(IntPtr sender)
{
if (Handler.AbortButton != null)
var handler = Handler?.AbortButton?.Handler as IMacViewHandler;
if (handler != null)
{
var handler = Handler.AbortButton.Handler as IMacViewHandler;
if (handler != null)
{
var callback = handler.Callback as Button.ICallback;
if (callback != null)
callback.OnClick(Handler.AbortButton, EventArgs.Empty);
}
var callback = handler.Callback as Button.ICallback;
if (callback != null)
callback.OnClick(Handler.AbortButton, EventArgs.Empty);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/Eto.Mac/Forms/MacWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class EtoWindow : NSWindow, IMacControl
public WeakReference WeakHandler { get; set; }

public IMacWindow Handler { get { return (IMacWindow)WeakHandler.Target; } set { WeakHandler = new WeakReference(value); } }

public EtoWindow(NativeHandle handle)
: base(handle)
{
}

public EtoWindow(CGRect rect, NSWindowStyle style, NSBackingStore store, bool flag)
: base(rect, style, store, flag)
Expand Down Expand Up @@ -59,7 +64,7 @@ public override void Zoom(NSObject sender)
base.Zoom(sender ?? this); // null when double clicking the title bar, but xammac/monomac doesn't allow it
zoom = true;
}
Handler.Callback.OnWindowStateChanged(Handler.Widget, EventArgs.Empty);
Handler?.Callback.OnWindowStateChanged(Handler.Widget, EventArgs.Empty);
}

public bool DisableSetOrigin { get; set; }
Expand Down