Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

[Xwt] Adds Focus change handling #1048

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions Xwt.Gtk/Xwt.GtkBackend/WindowBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ public class WindowBackend: WindowFrameBackend, IWindowBackend, IConstraintProvi
Gtk.Alignment alignment;
Gtk.MenuBar mainMenu;
Gtk.VBox mainBox;

public event Action<object> FocusChanged;

public override void Initialize ()
{
Window = new Gtk.Window ("");
Window = new Gtk.Window("");
Window.FocusChildSet += (s, e) => {
FocusChanged?.Invoke (e.Widget);
};
Window.Add (CreateMainLayout ());
}

Expand Down
7 changes: 7 additions & 0 deletions Xwt.XamMac/Xwt.Mac/PopupWindowBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public class PopupWindowBackend : NSPanel, IPopupWindowBackend, IUtilityWindowBa
bool sensitive = true;
bool isPopup = false;
PopupWindow.PopupType windowType;
public event Action<object> FocusChanged;

public override bool MakeFirstResponder(NSResponder aResponder)
{
FocusChanged?.Invoke (aResponder);
return base.MakeFirstResponder(aResponder);
}

public PopupWindowBackend ()
{
Expand Down
8 changes: 8 additions & 0 deletions Xwt.XamMac/Xwt.Mac/WindowBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ public void SetMainMenu (IMenuBackend menu)

bool disposing, disposed;

public event Action<object> FocusChanged;

public override bool MakeFirstResponder(NSResponder aResponder)
{
FocusChanged?.Invoke(aResponder);
return base.MakeFirstResponder(aResponder);
}

protected override void Dispose(bool disposing)
{
if (!disposed && disposing)
Expand Down
2 changes: 2 additions & 0 deletions Xwt/Xwt.Backends/IWindowBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public interface IWindowBackend: IWindowFrameBackend, IChildPlacementHandler
/// Sets the minimum size of the window
/// </summary>
void SetMinSize (Size size);

event Action<object> FocusChanged;
}

public interface IWindowEventSink: IWindowFrameEventSink
Expand Down
12 changes: 11 additions & 1 deletion Xwt/Xwt/WindowFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public WindowFrame ()
{
if (!(base.BackendHost is WindowBackendHost))
throw new InvalidOperationException ("CreateBackendHost for WindowFrame did not return a WindowBackendHost instance");

var windowBackend = ((WindowBackendHost)base.BackendHost).Backend as IWindowBackend;
if (windowBackend != null) {
windowBackend.FocusChanged += OnFocusChanged;
}
}

public WindowFrame (string title): this ()
Expand All @@ -144,7 +149,12 @@ protected override void Dispose (bool disposing)
IWindowFrameBackend Backend {
get { return (IWindowFrameBackend) BackendHost.Backend; }
}


public virtual void OnFocusChanged (object focused)
{

}

protected override BackendHost CreateBackendHost ()
{
return new WindowBackendHost ();
Expand Down