|
|
|
@ -269,11 +269,6 @@ namespace Avalonia.Win32 |
|
|
|
|
|
|
|
style |= UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW; |
|
|
|
|
|
|
|
if (!value) |
|
|
|
{ |
|
|
|
style ^= UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW; |
|
|
|
} |
|
|
|
|
|
|
|
UnmanagedMethods.RECT windowRect; |
|
|
|
|
|
|
|
UnmanagedMethods.GetWindowRect(_hwnd, out windowRect); |
|
|
|
@ -282,32 +277,29 @@ namespace Avalonia.Win32 |
|
|
|
var oldThickness = BorderThickness; |
|
|
|
|
|
|
|
UnmanagedMethods.SetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE, (uint)style); |
|
|
|
|
|
|
|
var thickness = BorderThickness; |
|
|
|
|
|
|
|
_decorated = value; |
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
|
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 |
|
|
|
if(!value) |
|
|
|
{ |
|
|
|
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)); |
|
|
|
RECT rc = new RECT(); |
|
|
|
uint style1 = UnmanagedMethods.GetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE); |
|
|
|
uint styleEx1 = UnmanagedMethods.GetWindowLong(_hwnd, (int)UnmanagedMethods.WindowLongParam.GWL_EXSTYLE); |
|
|
|
UnmanagedMethods.AdjustWindowRectEx(ref rc, style1, false, styleEx1); |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
if(_decorated) |
|
|
|
{ |
|
|
|
if (_resizable) |
|
|
|
@ -455,54 +447,6 @@ namespace Avalonia.Win32 |
|
|
|
IntPtr.Zero); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected int BorderTop { get; private set; } |
|
|
|
protected int BorderLeft { get; private set; } |
|
|
|
protected int BorderRight { get; private set; } |
|
|
|
protected int BorderBottom { get; private set; } |
|
|
|
|
|
|
|
private HitTestValues NCHitText(uint m, IntPtr LParam, IntPtr wParam) |
|
|
|
{ |
|
|
|
int lParam = (int)LParam; |
|
|
|
Point pt = new Point(lParam & 0xffff, lParam >> 16); |
|
|
|
|
|
|
|
var rc = new Rect(Position, ClientSize); |
|
|
|
|
|
|
|
int row = 1; |
|
|
|
int col = 1; |
|
|
|
bool onResizeBorder = false; |
|
|
|
|
|
|
|
// Determine if we are on the top or bottom border
|
|
|
|
if (pt.Y >= rc.Top && pt.Y < rc.Top + BorderTop) |
|
|
|
{ |
|
|
|
onResizeBorder = pt.Y < (rc.Top + BorderBottom); |
|
|
|
row = 0; |
|
|
|
} |
|
|
|
else if (pt.Y < rc.Bottom && pt.Y > rc.Bottom - BorderBottom) |
|
|
|
{ |
|
|
|
row = 2; |
|
|
|
} |
|
|
|
|
|
|
|
// Determine if we are on the left border or the right border
|
|
|
|
if (pt.X >= rc.Left && pt.X < rc.Left + BorderLeft) |
|
|
|
{ |
|
|
|
col = 0; |
|
|
|
} |
|
|
|
else if (pt.X < rc.Right && pt.X >= rc.Right - BorderRight) |
|
|
|
{ |
|
|
|
col = 2; |
|
|
|
} |
|
|
|
|
|
|
|
HitTestValues[,] hitTests = new HitTestValues[,] |
|
|
|
{ |
|
|
|
{HitTestValues.HTTOPLEFT, onResizeBorder ? HitTestValues.HTTOP : HitTestValues.HTCAPTION, HitTestValues.HTTOPRIGHT}, |
|
|
|
{HitTestValues.HTLEFT, HitTestValues.HTNOWHERE, HitTestValues.HTRIGHT}, |
|
|
|
{HitTestValues.HTBOTTOMLEFT, HitTestValues.HTBOTTOM, HitTestValues.HTBOTTOMRIGHT} |
|
|
|
}; |
|
|
|
|
|
|
|
return hitTests[row, col]; |
|
|
|
} |
|
|
|
|
|
|
|
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")] |
|
|
|
protected virtual IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) |
|
|
|
{ |
|
|
|
@ -513,8 +457,6 @@ namespace Avalonia.Win32 |
|
|
|
|
|
|
|
RawInputEventArgs e = null; |
|
|
|
|
|
|
|
bool callDWP = false; |
|
|
|
|
|
|
|
WindowsMouseDevice.Instance.CurrentWindow = this; |
|
|
|
|
|
|
|
switch ((UnmanagedMethods.WindowsMessage)msg) |
|
|
|
@ -534,53 +476,14 @@ namespace Avalonia.Win32 |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
MARGINS margins = new MARGINS(); |
|
|
|
|
|
|
|
margins.leftWidth = Math.Abs(BorderLeft); |
|
|
|
margins.rightWidth = Math.Abs(BorderRight); |
|
|
|
margins.bottomHeight = Math.Abs(BorderBottom); |
|
|
|
margins.topHeight = Math.Abs(BorderTop); |
|
|
|
|
|
|
|
// int hr = UnmanagedMethods.DwmExtendFrameIntoClientArea(hWnd, ref margins);
|
|
|
|
|
|
|
|
return IntPtr.Zero; |
|
|
|
|
|
|
|
case WindowsMessage.WM_NCCALCSIZE: |
|
|
|
return IntPtr.Zero; |
|
|
|
//break;
|
|
|
|
|
|
|
|
case WindowsMessage.WM_CREATE: |
|
|
|
RECT rcClient; |
|
|
|
UnmanagedMethods.GetWindowRect(hWnd, out rcClient); |
|
|
|
|
|
|
|
|
|
|
|
RECT rc = new RECT(); |
|
|
|
uint style = UnmanagedMethods.GetWindowLong(hWnd, (int)UnmanagedMethods.WindowLongParam.GWL_STYLE); |
|
|
|
uint styleEx = UnmanagedMethods.GetWindowLong(hWnd, (int)UnmanagedMethods.WindowLongParam.GWL_EXSTYLE); |
|
|
|
UnmanagedMethods.AdjustWindowRectEx(ref rc, style, false, styleEx); |
|
|
|
|
|
|
|
BorderTop = Math.Abs(rc.top); |
|
|
|
BorderLeft = Math.Abs(0); |
|
|
|
BorderRight = Math.Abs(0); |
|
|
|
BorderBottom = Math.Abs(0); |
|
|
|
break; |
|
|
|
|
|
|
|
case WindowsMessage.WM_NCHITTEST: |
|
|
|
var ht = NCHitText(msg, lParam, wParam); |
|
|
|
|
|
|
|
|
|
|
|
callDWP = (ht == HitTestValues.HTNOWHERE); |
|
|
|
|
|
|
|
if (callDWP) |
|
|
|
if (!_decorated) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return new IntPtr((int)ht); |
|
|
|
return IntPtr.Zero; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case UnmanagedMethods.WindowsMessage.WM_CLOSE: |
|
|
|
bool? preventClosing = Closing?.Invoke(); |
|
|
|
|