Browse Source

Merge branch 'master' into t/lvyi/fix-1516

pull/1517/head
danwalmsley 8 years ago
committed by GitHub
parent
commit
415d4d5b99
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/Avalonia.Base/AvaloniaObject.cs
  2. 4
      src/Avalonia.Controls/AutoCompleteBox.cs
  3. 4
      src/Avalonia.Controls/Window.cs
  4. 10
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  5. 8
      src/Windows/Avalonia.Win32/OleContext.cs
  6. 47
      src/Windows/Avalonia.Win32/WindowImpl.cs
  7. 27
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Attached.cs

13
src/Avalonia.Base/AvaloniaObject.cs

@ -71,7 +71,8 @@ namespace Avalonia
public AvaloniaObject() public AvaloniaObject()
{ {
VerifyAccess(); VerifyAccess();
foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegistered(this))
void Notify(AvaloniaProperty property)
{ {
object value = property.IsDirect ? object value = property.IsDirect ?
((IDirectPropertyAccessor)property).GetValue(this) : ((IDirectPropertyAccessor)property).GetValue(this) :
@ -86,6 +87,16 @@ namespace Avalonia
property.NotifyInitialized(e); property.NotifyInitialized(e);
} }
foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegistered(this))
{
Notify(property);
}
foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegisteredAttached(this.GetType()))
{
Notify(property);
}
} }
/// <summary> /// <summary>

4
src/Avalonia.Controls/AutoCompleteBox.cs

@ -1954,6 +1954,10 @@ namespace Avalonia.Controls
// 1. Minimum prefix length // 1. Minimum prefix length
// 2. If a delay timer is in use, use it // 2. If a delay timer is in use, use it
bool populateReady = newText.Length >= MinimumPrefixLength && MinimumPrefixLength >= 0; bool populateReady = newText.Length >= MinimumPrefixLength && MinimumPrefixLength >= 0;
if(populateReady && MinimumPrefixLength == 0 && String.IsNullOrEmpty(newText) && String.IsNullOrEmpty(SearchText))
{
populateReady = false;
}
_userCalledPopulate = populateReady ? userInitiated : false; _userCalledPopulate = populateReady ? userInitiated : false;
// Update the interface and values only as necessary // Update the interface and values only as necessary

4
src/Avalonia.Controls/Window.cs

@ -214,7 +214,9 @@ namespace Avalonia.Controls
} }
/// <summary> /// <summary>
/// Enables or disables resizing of the window /// Enables or disables resizing of the window.
/// Note that if <see cref="HasSystemDecorations"/> is set to False then this property
/// has no effect and should be treated as a recommendation for the user setting HasSystemDecorations.
/// </summary> /// </summary>
public bool CanResize public bool CanResize
{ {

10
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -1187,27 +1187,21 @@ namespace Avalonia.Win32.Interop
[Flags] [Flags]
public enum OpenFileNameFlags public enum OpenFileNameFlags
{ {
OFN_ALLOWMULTISELECT = 0x00000200, OFN_ALLOWMULTISELECT = 0x00000200,
OFN_EXPLORER = 0x00080000, OFN_EXPLORER = 0x00080000,
OFN_HIDEREADONLY = 0x00000004, OFN_HIDEREADONLY = 0x00000004,
OFN_NOREADONLYRETURN = 0x00008000, OFN_NOREADONLYRETURN = 0x00008000,
OFN_OVERWRITEPROMPT = 0x00000002 OFN_OVERWRITEPROMPT = 0x00000002
} }
public enum HRESULT : long public enum HRESULT : uint
{ {
S_FALSE = 0x0001, S_FALSE = 0x0001,
S_OK = 0x0000, S_OK = 0x0000,
E_INVALIDARG = 0x80070057, E_INVALIDARG = 0x80070057,
E_OUTOFMEMORY = 0x8007000E, E_OUTOFMEMORY = 0x8007000E,
E_NOTIMPL = 0x80004001, E_NOTIMPL = 0x80004001,
E_UNEXPECTED = 0x8000FFFF, E_UNEXPECTED = 0x8000FFFF
} }
public enum Icons public enum Icons

8
src/Windows/Avalonia.Win32/OleContext.cs

@ -1,4 +1,5 @@
using System; using System;
using System.ComponentModel;
using System.Threading; using System.Threading;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Threading; using Avalonia.Threading;
@ -26,8 +27,11 @@ namespace Avalonia.Win32
private OleContext() private OleContext()
{ {
if (UnmanagedMethods.OleInitialize(IntPtr.Zero) != UnmanagedMethods.HRESULT.S_OK) UnmanagedMethods.HRESULT res = UnmanagedMethods.OleInitialize(IntPtr.Zero);
throw new SystemException("Failed to initialize OLE");
if (res != UnmanagedMethods.HRESULT.S_OK &&
res != UnmanagedMethods.HRESULT.S_FALSE /*already initialized*/)
throw new Win32Exception((int)res, "Failed to initialize OLE");
} }
private static bool IsValidOleThread() private static bool IsValidOleThread()

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

@ -245,19 +245,13 @@ namespace Avalonia.Win32
return; return;
} }
var style = (UnmanagedMethods.WindowStyles)UnmanagedMethods.GetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE); var style = (UnmanagedMethods.WindowStyles)UnmanagedMethods.GetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE);
var systemDecorationStyles = UnmanagedMethods.WindowStyles.WS_OVERLAPPED style |= UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW;
| UnmanagedMethods.WindowStyles.WS_CAPTION
| UnmanagedMethods.WindowStyles.WS_SYSMENU
| UnmanagedMethods.WindowStyles.WS_MINIMIZEBOX
| UnmanagedMethods.WindowStyles.WS_MAXIMIZEBOX;
style |= systemDecorationStyles;
if (!value) if (!value)
{ {
style ^= systemDecorationStyles; style ^= UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW;
} }
UnmanagedMethods.RECT windowRect; UnmanagedMethods.RECT windowRect;
@ -293,6 +287,21 @@ namespace Avalonia.Win32
UnmanagedMethods.SetWindowPosFlags.SWP_NOZORDER | UnmanagedMethods.SetWindowPosFlags.SWP_NOACTIVATE); UnmanagedMethods.SetWindowPosFlags.SWP_NOZORDER | UnmanagedMethods.SetWindowPosFlags.SWP_NOACTIVATE);
_decorated = value; _decorated = value;
if(_decorated)
{
if (_resizable)
{
// If we switch decorations back on we need to restore WS_SizeFrame.
_resizable = false;
CanResize(true);
}
else
{
_resizable = true;
CanResize(false);
}
}
} }
public void Invalidate(Rect rect) public void Invalidate(Rect rect)
@ -863,14 +872,18 @@ namespace Avalonia.Win32
return; return;
} }
var style = (UnmanagedMethods.WindowStyles)UnmanagedMethods.GetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE); if (_decorated)
{
if (value) var style = (UnmanagedMethods.WindowStyles)UnmanagedMethods.GetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE);
style |= UnmanagedMethods.WindowStyles.WS_SIZEFRAME;
else if (value)
style &= ~(UnmanagedMethods.WindowStyles.WS_SIZEFRAME); style |= UnmanagedMethods.WindowStyles.WS_SIZEFRAME;
else
UnmanagedMethods.SetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE, (uint)style); style &= ~(UnmanagedMethods.WindowStyles.WS_SIZEFRAME);
UnmanagedMethods.SetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE, (uint)style);
}
_resizable = value; _resizable = value;
} }
} }

27
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Attached.cs

@ -24,10 +24,27 @@ namespace Avalonia.Base.UnitTests
Assert.Throws<IndexOutOfRangeException>(() => target.SetValue(Class2.FooProperty, "throw")); Assert.Throws<IndexOutOfRangeException>(() => target.SetValue(Class2.FooProperty, "throw"));
} }
private class Class1 : AvaloniaObject [Fact]
public void AvaloniaProperty_Initialized_Is_Called_For_Attached_Property()
{
bool raised = false;
using (Class1.FooProperty.Initialized.Subscribe(x => raised = true))
{
new Class3();
}
Assert.True(raised);
}
private class Base : AvaloniaObject
{
}
private class Class1 : Base
{ {
public static readonly AttachedProperty<string> FooProperty = public static readonly AttachedProperty<string> FooProperty =
AvaloniaProperty.RegisterAttached<Class1, Class2, string>( AvaloniaProperty.RegisterAttached<Class1, Base, string>(
"Foo", "Foo",
"foodefault", "foodefault",
validate: ValidateFoo); validate: ValidateFoo);
@ -43,10 +60,14 @@ namespace Avalonia.Base.UnitTests
} }
} }
private class Class2 : AvaloniaObject private class Class2 : Base
{ {
public static readonly AttachedProperty<string> FooProperty = public static readonly AttachedProperty<string> FooProperty =
Class1.FooProperty.AddOwner<Class2>(); Class1.FooProperty.AddOwner<Class2>();
} }
private class Class3 : Base
{
}
} }
} }

Loading…
Cancel
Save