Browse Source

Added Window::HasSystemDecorations property

pull/372/head
Nikita Tsukanov 11 years ago
parent
commit
8f24ccf441
  1. 3
      src/Android/Perspex.Android/Platform/SkiaPlatform/WindowImpl.cs
  2. 2
      src/Gtk/Perspex.Gtk/WindowImpl.cs
  3. 5
      src/Perspex.Controls/Platform/IWindowImpl.cs
  4. 1
      src/Perspex.Controls/Platform/PlatformManager.cs
  5. 18
      src/Perspex.Controls/Window.cs
  6. 3
      src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs
  7. 43
      src/Windows/Perspex.Win32/WindowImpl.cs
  8. 5
      src/iOS/Perspex.iOS/PerspexView.cs

3
src/Android/Perspex.Android/Platform/SkiaPlatform/WindowImpl.cs

@ -94,6 +94,9 @@ namespace Perspex.Android.Platform.SkiaPlatform
this.Visibility = ViewStates.Invisible;
}
public void SetSystemDecorations(bool enabled)
{
}
public void Invalidate(Rect rect)
{
if (Holder?.Surface?.IsValid == true) base.Invalidate();

2
src/Gtk/Perspex.Gtk/WindowImpl.cs

@ -170,6 +170,8 @@ namespace Perspex.Gtk
return Disposable.Empty;
}
public void SetSystemDecorations(bool enabled) => Decorated = enabled;
void ITopLevelImpl.Activate()
{
Activate();

5
src/Perspex.Controls/Platform/IWindowImpl.cs

@ -33,5 +33,10 @@ namespace Perspex.Platform
/// Hides the window.
/// </summary>
void Hide();
/// <summary>
/// Enables of disables system window decorations (title bar, buttons, etc)
/// </summary>
void SetSystemDecorations(bool enabled);
}
}

1
src/Perspex.Controls/Platform/PlatformManager.cs

@ -178,6 +178,7 @@ namespace Perspex.Controls.Platform
public IDisposable ShowDialog() => _window.ShowDialog();
public void Hide() => _popup.Hide();
public void SetSystemDecorations(bool enabled) => _window.SetSystemDecorations(enabled);
}
public static IWindowImpl CreateWindow()

18
src/Perspex.Controls/Window.cs

@ -49,6 +49,12 @@ namespace Perspex.Controls
public static readonly PerspexProperty<SizeToContent> SizeToContentProperty =
PerspexProperty.Register<Window, SizeToContent>(nameof(SizeToContent));
/// <summary>
/// Enables of disables system window decorations (title bar, buttons, etc)
/// </summary>
public static readonly PerspexProperty<bool> HasSystemDecorationsProperty =
PerspexProperty.Register<Window, bool>(nameof(HasSystemDecorations), true);
/// <summary>
/// Defines the <see cref="Title"/> property.
/// </summary>
@ -66,6 +72,8 @@ namespace Perspex.Controls
{
BackgroundProperty.OverrideDefaultValue(typeof(Window), Brushes.White);
TitleProperty.Changed.AddClassHandler<Window>((s, e) => s.PlatformImpl.SetTitle((string)e.NewValue));
HasSystemDecorationsProperty.Changed.AddClassHandler<Window>(
(s, e) => s.PlatformImpl.SetSystemDecorations((bool) e.NewValue));
}
/// <summary>
@ -114,6 +122,16 @@ namespace Perspex.Controls
set { SetValue(TitleProperty, value); }
}
/// <summary>
/// Enables of disables system window decorations (title bar, buttons, etc)
/// </summary>
///
public bool HasSystemDecorations
{
get { return GetValue(HasSystemDecorationsProperty); }
set { SetValue(HasSystemDecorationsProperty, value); }
}
/// <inheritdoc/>
Type IStyleable.StyleKey => typeof(Window);

3
src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs

@ -571,6 +571,9 @@ namespace Perspex.Win32.Interop
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
public static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint value);
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);

43
src/Windows/Perspex.Win32/WindowImpl.cs

@ -37,6 +37,8 @@ namespace Perspex.Win32
private bool _isActive;
private bool _decorated = true;
public WindowImpl()
{
CreateWindow();
@ -145,6 +147,47 @@ namespace Perspex.Win32
UnmanagedMethods.ShowWindow(_hwnd, UnmanagedMethods.ShowWindowCommand.Hide);
}
public void SetSystemDecorations(bool value)
{
if (value == _decorated)
return;
var style = (UnmanagedMethods.WindowStyles) UnmanagedMethods.GetWindowLong(_hwnd, -16);
style |= UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW;
if (!value)
style ^= UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW;
UnmanagedMethods.RECT windowRect;
UnmanagedMethods.GetWindowRect(_hwnd, out windowRect);
Rect newRect;
var oldThickness = BorderThickness;
UnmanagedMethods.SetWindowLong(_hwnd, -16, (uint) style);
if (value)
{
var thickness = BorderThickness;
newRect = new Rect(
windowRect.left - thickness.Left,
windowRect.top - thickness.Top,
(windowRect.right - windowRect.left) + (thickness.Left + thickness.Right),
(windowRect.bottom - windowRect.top) + (thickness.Top + thickness.Bottom));
}
else
newRect = new Rect(
windowRect.left + oldThickness.Left,
windowRect.top + oldThickness.Top,
(windowRect.right - windowRect.left) - (oldThickness.Left + oldThickness.Right),
(windowRect.bottom - windowRect.top) - (oldThickness.Top + oldThickness.Bottom));
UnmanagedMethods.SetWindowPos(_hwnd, IntPtr.Zero, (int) newRect.X, (int) newRect.Y, (int) newRect.Width,
(int) newRect.Height,
UnmanagedMethods.SetWindowPosFlags.SWP_NOZORDER | UnmanagedMethods.SetWindowPosFlags.SWP_NOACTIVATE);
_decorated = value;
}
public void Invalidate(Rect rect)
{
var r = new UnmanagedMethods.RECT

5
src/iOS/Perspex.iOS/PerspexView.cs

@ -124,6 +124,11 @@ namespace Perspex.iOS
//Not supported
}
public void SetSystemDecorations(bool enabled)
{
//Not supported
}
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
var touch = touches.AnyObject as UITouch;

Loading…
Cancel
Save