Browse Source

Merge pull request #5063 from AvaloniaUI/feature/window-showactive

Added Window.ShowActivated
pull/5154/head
Dan Walmsley 6 years ago
committed by GitHub
parent
commit
6bf37a9080
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      native/Avalonia.Native/src/OSX/window.mm
  2. 6
      src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt
  3. 29
      src/Avalonia.Controls/ApiCompatBaseline.txt
  4. 4
      src/Avalonia.Controls/Platform/IWindowBaseImpl.cs
  5. 20
      src/Avalonia.Controls/Window.cs
  6. 2
      src/Avalonia.Controls/WindowBase.cs
  7. 2
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  8. 2
      src/Avalonia.DesignerSupport/Remote/Stubs.cs
  9. 7
      src/Avalonia.Headless/HeadlessWindowImpl.cs
  10. 4
      src/Avalonia.Native/PopupImpl.cs
  11. 4
      src/Avalonia.Native/WindowImplBase.cs
  12. 2
      src/Avalonia.Native/avn.idl
  13. 2
      src/Avalonia.X11/X11Window.cs
  14. 5
      src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt
  15. 3
      src/Windows/Avalonia.Win32/PopupImpl.cs
  16. 2
      src/Windows/Avalonia.Win32/Win32Platform.cs
  17. 14
      src/Windows/Avalonia.Win32/WindowImpl.cs
  18. 16
      tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
  19. 2
      tests/Avalonia.Controls.UnitTests/WindowBaseTests.cs
  20. 2
      tests/Avalonia.UnitTests/MockWindowingPlatform.cs

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

@ -106,13 +106,13 @@ public:
return Window;
}
virtual HRESULT Show() override
virtual HRESULT Show(bool activate) override
{
@autoreleasepool
{
SetPosition(lastPositionSet);
UpdateStyle();
if(ShouldTakeFocusOnShow())
if(ShouldTakeFocusOnShow() && activate)
{
[Window makeKeyAndOrderFront:Window];
[NSApp activateIgnoringOtherApps:YES];
@ -561,11 +561,11 @@ private:
}
}
virtual HRESULT Show () override
virtual HRESULT Show (bool activate) override
{
@autoreleasepool
{
WindowBaseImpl::Show();
WindowBaseImpl::Show(activate);
HideOrShowTrafficLights();

6
src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt

@ -1,5 +1 @@
Compat issues with assembly Avalonia.Controls.DataGrid:
MembersMustExist : Member 'public Avalonia.StyledProperty<System.String> Avalonia.StyledProperty<System.String> Avalonia.Controls.DataGridTextColumn.FontFamilyProperty' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.String Avalonia.Controls.DataGridTextColumn.FontFamily.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Controls.DataGridTextColumn.FontFamily.set(System.String)' does not exist in the implementation but it does exist in the contract.
Total Issues: 3
Total Issues: 0

29
src/Avalonia.Controls/ApiCompatBaseline.txt

@ -1,26 +1,5 @@
Compat issues with assembly Avalonia.Controls:
TypesMustExist : Type 'Avalonia.Controls.IndexPath' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'Avalonia.Controls.ISelectedItemInfo' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'Avalonia.Controls.ISelectionModel' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.DirectProperty<Avalonia.Controls.Primitives.SelectingItemsControl, Avalonia.Controls.ISelectionModel> Avalonia.DirectProperty<Avalonia.Controls.Primitives.SelectingItemsControl, Avalonia.Controls.ISelectionModel> Avalonia.Controls.ListBox.SelectionProperty' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.Controls.ISelectionModel Avalonia.Controls.ListBox.Selection.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Controls.ListBox.Selection.set(Avalonia.Controls.ISelectionModel)' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'Avalonia.Controls.SelectionModel' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'Avalonia.Controls.SelectionModelChildrenRequestedEventArgs' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'Avalonia.Controls.SelectionModelSelectionChangedEventArgs' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.StyledProperty<Avalonia.Controls.IControl> Avalonia.StyledProperty<Avalonia.Controls.IControl> Avalonia.Controls.SplitView.ContentProperty' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.StyledProperty<Avalonia.Controls.IControl> Avalonia.StyledProperty<Avalonia.Controls.IControl> Avalonia.Controls.SplitView.PaneProperty' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.Controls.IControl Avalonia.Controls.SplitView.Content.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Controls.SplitView.Content.set(Avalonia.Controls.IControl)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.Controls.IControl Avalonia.Controls.SplitView.Pane.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Controls.SplitView.Pane.set(Avalonia.Controls.IControl)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.DirectProperty<Avalonia.Controls.TreeView, Avalonia.Controls.ISelectionModel> Avalonia.DirectProperty<Avalonia.Controls.TreeView, Avalonia.Controls.ISelectionModel> Avalonia.Controls.TreeView.SelectionProperty' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent<Avalonia.Controls.SelectionChangedEventArgs> Avalonia.Interactivity.RoutedEvent<Avalonia.Controls.SelectionChangedEventArgs> Avalonia.Controls.TreeView.SelectionChangedEvent' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.Controls.ISelectionModel Avalonia.Controls.TreeView.Selection.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Controls.TreeView.Selection.set(Avalonia.Controls.ISelectionModel)' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.String[] Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.Args' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.String[] Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.Args.get()' is present in the implementation but not in the contract.
MembersMustExist : Member 'public Avalonia.DirectProperty<Avalonia.Controls.Primitives.SelectingItemsControl, Avalonia.Controls.ISelectionModel> Avalonia.DirectProperty<Avalonia.Controls.Primitives.SelectingItemsControl, Avalonia.Controls.ISelectionModel> Avalonia.Controls.Primitives.SelectingItemsControl.SelectionProperty' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'protected Avalonia.Controls.ISelectionModel Avalonia.Controls.Primitives.SelectingItemsControl.Selection.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'protected void Avalonia.Controls.Primitives.SelectingItemsControl.Selection.set(Avalonia.Controls.ISelectionModel)' does not exist in the implementation but it does exist in the contract.
Total Issues: 24
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IWindowBaseImpl.Show()' is present in the contract but not in the implementation.
MembersMustExist : Member 'public void Avalonia.Platform.IWindowBaseImpl.Show()' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IWindowBaseImpl.Show(System.Boolean)' is present in the implementation but not in the contract.
Total Issues: 3

4
src/Avalonia.Controls/Platform/IWindowBaseImpl.cs

@ -5,9 +5,9 @@ namespace Avalonia.Platform
public interface IWindowBaseImpl : ITopLevelImpl
{
/// <summary>
/// Shows the top level.
/// Shows the window.
/// </summary>
void Show();
void Show(bool activate);
/// <summary>
/// Hides the window.

20
src/Avalonia.Controls/Window.cs

@ -129,6 +129,12 @@ namespace Avalonia.Controls
public static readonly StyledProperty<SystemDecorations> SystemDecorationsProperty =
AvaloniaProperty.Register<Window, SystemDecorations>(nameof(SystemDecorations), SystemDecorations.Full);
/// <summary>
/// Defines the <see cref="ShowActivated"/> property.
/// </summary>
public static readonly StyledProperty<bool> ShowActivatedProperty =
AvaloniaProperty.Register<Window, bool>(nameof(ShowActivated), true);
/// <summary>
/// Enables or disables the taskbar icon
/// </summary>
@ -352,13 +358,21 @@ namespace Avalonia.Controls
/// <summary>
/// Sets the system decorations (title bar, border, etc)
/// </summary>
///
public SystemDecorations SystemDecorations
{
get { return GetValue(SystemDecorationsProperty); }
set { SetValue(SystemDecorationsProperty, value); }
}
/// <summary>
/// Gets or sets a value that indicates whether a window is activated when first shown.
/// </summary>
public bool ShowActivated
{
get { return GetValue(ShowActivatedProperty); }
set { SetValue(ShowActivatedProperty, value); }
}
/// <summary>
/// Enables or disables the taskbar icon
/// </summary>
@ -650,7 +664,7 @@ namespace Avalonia.Controls
Owner = parent;
parent?.AddChild(this, false);
PlatformImpl?.Show();
PlatformImpl?.Show(ShowActivated);
Renderer?.Start();
SetWindowStartupLocation(Owner?.PlatformImpl);
}
@ -720,7 +734,7 @@ namespace Avalonia.Controls
PlatformImpl?.SetParent(owner.PlatformImpl);
Owner = owner;
owner.AddChild(this, true);
PlatformImpl?.Show();
PlatformImpl?.Show(ShowActivated);
Renderer?.Start();

2
src/Avalonia.Controls/WindowBase.cs

@ -162,7 +162,7 @@ namespace Avalonia.Controls
LayoutManager.ExecuteInitialLayoutPass();
_hasExecutedInitialLayoutPass = true;
}
PlatformImpl?.Show();
PlatformImpl?.Show(true);
Renderer?.Start();
OnOpened(EventArgs.Empty);
}

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

@ -20,7 +20,7 @@ namespace Avalonia.DesignerSupport.Remote
ClientSize = new Size(1, 1);
}
public void Show()
public void Show(bool activate)
{
}

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

@ -77,7 +77,7 @@ namespace Avalonia.DesignerSupport.Remote
{
}
public void Show()
public void Show(bool activate)
{
}

7
src/Avalonia.Headless/HeadlessWindowImpl.cs

@ -75,9 +75,10 @@ namespace Avalonia.Headless
public Action Closed { get; set; }
public IMouseDevice MouseDevice { get; }
public void Show()
public void Show(bool activate)
{
Dispatcher.UIThread.Post(() => Activated?.Invoke(), DispatcherPriority.Input);
if (activate)
Dispatcher.UIThread.Post(() => Activated?.Invoke(), DispatcherPriority.Input);
}
public void Hide()
@ -148,7 +149,7 @@ namespace Avalonia.Headless
public void ShowDialog(IWindowImpl parent)
{
Show();
Show(true);
}
public void SetSystemDecorations(bool enabled)

4
src/Avalonia.Native/PopupImpl.cs

@ -60,14 +60,14 @@ namespace Avalonia.Native
}
}
public override void Show()
public override void Show(bool activate)
{
var parent = _parent;
while (parent is PopupImpl p)
parent = p._parent;
if (parent is WindowImpl w)
w.Native.TakeFocusFromChildren();
base.Show();
base.Show(false);
}
public override IPopupImpl CreatePopup() => new PopupImpl(_factory, _opts, _glFeature, this);

4
src/Avalonia.Native/WindowImplBase.cs

@ -351,9 +351,9 @@ namespace Avalonia.Native
}
public virtual void Show()
public virtual void Show(bool activate)
{
_native.Show();
_native.Show(activate.AsComBool());
}

2
src/Avalonia.Native/avn.idl

@ -225,7 +225,7 @@ interface IAvnString : IUnknown
[uuid(e5aca675-02b7-4129-aa79-d6e417210bda)]
interface IAvnWindowBase : IUnknown
{
HRESULT Show();
HRESULT Show(bool activate);
HRESULT Hide();
HRESULT Close();
HRESULT Activate();

2
src/Avalonia.X11/X11Window.cs

@ -823,7 +823,7 @@ namespace Avalonia.X11
XSetTransientForHint(_x11.Display, _handle, parent.Handle.Handle);
}
public void Show()
public void Show(bool activate)
{
_wasMappedAtLeastOnce = true;
XMapWindow(_x11.Display, _handle);

5
src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt

@ -1,4 +1 @@
Compat issues with assembly Avalonia.Markup.Xaml:
MembersMustExist : Member 'public Avalonia.Data.Binding Avalonia.Markup.Xaml.Templates.TreeDataTemplate.ItemsSource.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Markup.Xaml.Templates.TreeDataTemplate.ItemsSource.set(Avalonia.Data.Binding)' does not exist in the implementation but it does exist in the contract.
Total Issues: 2
Total Issues: 0

3
src/Windows/Avalonia.Win32/PopupImpl.cs

@ -17,8 +17,9 @@ namespace Avalonia.Win32
[ThreadStatic]
private static IntPtr s_parentHandle;
public override void Show()
public override void Show(bool activate)
{
// Popups are always shown non-activated.
UnmanagedMethods.ShowWindow(Handle.Handle, UnmanagedMethods.ShowWindowCommand.ShowNoActivate);
// We need to steal focus if it's held by a child window of our toplevel window

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

@ -230,7 +230,7 @@ namespace Avalonia.Win32
public IWindowImpl CreateEmbeddableWindow()
{
var embedded = new EmbeddedWindowImpl();
embedded.Show();
embedded.Show(true);
return embedded;
}

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

@ -243,7 +243,7 @@ namespace Avalonia.Win32
{
if (IsWindowVisible(_hwnd))
{
ShowWindow(value);
ShowWindow(value, true);
}
else
{
@ -567,10 +567,11 @@ namespace Avalonia.Win32
UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Hide);
}
public virtual void Show()
public virtual void Show(bool activate)
{
SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent != null ? _parent._hwnd : IntPtr.Zero);
ShowWindow(_showWindowState);
ShowWindow(_showWindowState, activate);
}
public Action GotInputWhenDisabled { get; set; }
@ -908,7 +909,7 @@ namespace Avalonia.Win32
ExtendClientAreaToDecorationsChanged?.Invoke(_isClientAreaExtended);
}
private void ShowWindow(WindowState state)
private void ShowWindow(WindowState state, bool activate)
{
ShowWindowCommand? command;
@ -918,7 +919,7 @@ namespace Avalonia.Win32
{
case WindowState.Minimized:
newWindowProperties.IsFullScreen = false;
command = ShowWindowCommand.Minimize;
command = activate ? ShowWindowCommand.Minimize : ShowWindowCommand.ShowMinNoActive;
break;
case WindowState.Maximized:
newWindowProperties.IsFullScreen = false;
@ -927,7 +928,8 @@ namespace Avalonia.Win32
case WindowState.Normal:
newWindowProperties.IsFullScreen = false;
command = ShowWindowCommand.Restore;
command = IsWindowVisible(_hwnd) ? ShowWindowCommand.Restore :
activate ? ShowWindowCommand.Normal : ShowWindowCommand.ShowNoActivate;
break;
case WindowState.FullScreen:

16
tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs

@ -79,7 +79,7 @@ namespace Avalonia.Controls.UnitTests
{
using (Application())
{
popupImpl.Setup(x => x.Show()).Verifiable();
popupImpl.Setup(x => x.Show(true)).Verifiable();
popupImpl.Setup(x => x.Hide()).Verifiable();
var sut = new ContextMenu();
@ -99,7 +99,7 @@ namespace Avalonia.Controls.UnitTests
_mouse.Click(target);
Assert.False(sut.IsOpen);
popupImpl.Verify(x => x.Show(), Times.Once);
popupImpl.Verify(x => x.Show(true), Times.Once);
popupImpl.Verify(x => x.Hide(), Times.Once);
}
}
@ -109,7 +109,7 @@ namespace Avalonia.Controls.UnitTests
{
using (Application())
{
popupImpl.Setup(x => x.Show()).Verifiable();
popupImpl.Setup(x => x.Show(true)).Verifiable();
popupImpl.Setup(x => x.Hide()).Verifiable();
var sut = new ContextMenu();
@ -130,7 +130,7 @@ namespace Avalonia.Controls.UnitTests
Assert.True(sut.IsOpen);
popupImpl.Verify(x => x.Hide(), Times.Once);
popupImpl.Verify(x => x.Show(), Times.Exactly(2));
popupImpl.Verify(x => x.Show(true), Times.Exactly(2));
}
}
@ -177,7 +177,7 @@ namespace Avalonia.Controls.UnitTests
{
using (Application())
{
popupImpl.Setup(x => x.Show()).Verifiable();
popupImpl.Setup(x => x.Show(true)).Verifiable();
bool eventCalled = false;
var sut = new ContextMenu();
@ -193,7 +193,7 @@ namespace Avalonia.Controls.UnitTests
Assert.True(eventCalled);
Assert.False(sut.IsOpen);
popupImpl.Verify(x => x.Show(), Times.Never);
popupImpl.Verify(x => x.Show(true), Times.Never);
}
}
@ -297,7 +297,7 @@ namespace Avalonia.Controls.UnitTests
{
using (Application())
{
popupImpl.Setup(x => x.Show()).Verifiable();
popupImpl.Setup(x => x.Show(true)).Verifiable();
popupImpl.Setup(x => x.Hide()).Verifiable();
bool eventCalled = false;
@ -321,7 +321,7 @@ namespace Avalonia.Controls.UnitTests
Assert.True(eventCalled);
Assert.True(sut.IsOpen);
popupImpl.Verify(x => x.Show(), Times.Once());
popupImpl.Verify(x => x.Show(true), Times.Once());
popupImpl.Verify(x => x.Hide(), Times.Never);
}
}

2
tests/Avalonia.Controls.UnitTests/WindowBaseTests.cs

@ -137,7 +137,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TestWindowBase(windowImpl.Object);
target.IsVisible = true;
windowImpl.Verify(x => x.Show());
windowImpl.Verify(x => x.Show(true));
}
}

2
tests/Avalonia.UnitTests/MockWindowingPlatform.cs

@ -58,7 +58,7 @@ namespace Avalonia.UnitTests
windowImpl.Object.Resized?.Invoke(clientSize);
});
windowImpl.Setup(x => x.Show()).Callback(() =>
windowImpl.Setup(x => x.Show(true)).Callback(() =>
{
windowImpl.Object.Activated?.Invoke();
});

Loading…
Cancel
Save