Skip to content

Commit

Permalink
Merge pull request #1156 from MahApps/punker76-borderless-window-alte…
Browse files Browse the repository at this point in the history
…rnative

a borderless window alternative
  • Loading branch information
punker76 committed Mar 19, 2014
2 parents f0638f0 + ea14911 commit fa26a4a
Show file tree
Hide file tree
Showing 31 changed files with 3,283 additions and 1,755 deletions.
698 changes: 248 additions & 450 deletions MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions MahApps.Metro/Controls/Glow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace MahApps.Metro.Controls
public class Glow : Control
{
public static readonly DependencyProperty GlowBrushProperty = DependencyProperty.Register("GlowBrush", typeof(SolidColorBrush), typeof(Glow), new UIPropertyMetadata(Brushes.Transparent));
public static readonly DependencyProperty NonActiveGlowBrushProperty = DependencyProperty.Register("NonActiveGlowBrush", typeof(SolidColorBrush), typeof(Glow), new UIPropertyMetadata(Brushes.Transparent));
public static readonly DependencyProperty IsGlowProperty = DependencyProperty.Register("IsGlow", typeof(bool), typeof(Glow), new UIPropertyMetadata(true));
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(Orientation), typeof(Glow), new UIPropertyMetadata(Orientation.Vertical));

Expand All @@ -21,6 +22,12 @@ public SolidColorBrush GlowBrush
set { this.SetValue(GlowBrushProperty, value); }
}

public SolidColorBrush NonActiveGlowBrush
{
get { return (SolidColorBrush)this.GetValue(NonActiveGlowBrushProperty); }
set { this.SetValue(NonActiveGlowBrushProperty, value); }
}

public bool IsGlow
{
get { return (bool)this.GetValue(IsGlowProperty); }
Expand Down
1 change: 0 additions & 1 deletion MahApps.Metro/Controls/GlowWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Width="300"
Height="300"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
ShowActivated="False"
ResizeMode="NoResize"
Expand Down
14 changes: 14 additions & 0 deletions MahApps.Metro/Controls/GlowWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Interop;
using System.Windows.Media.Animation;
using MahApps.Metro.Models.Win32;
using Microsoft.Windows.Shell;

namespace MahApps.Metro.Controls
{
Expand All @@ -28,13 +29,26 @@ public GlowWindow(Window owner, GlowDirection direction)
{
InitializeComponent();

// var windowChrome = new WindowChrome();
// windowChrome.ResizeBorderThickness = new Thickness(0);
// windowChrome.CaptionHeight = 0;
// windowChrome.CornerRadius = new CornerRadius(0);
// windowChrome.GlassFrameThickness = new Thickness(-1);
// windowChrome.UseAeroCaptionButtons = false;
// this.SetValue(WindowChrome.WindowChromeProperty, windowChrome);
this.AllowsTransparency = true;

this.Owner = owner;
glow.Visibility = Visibility.Collapsed;

var b = new Binding("GlowBrush");
b.Source = owner;
glow.SetBinding(Glow.GlowBrushProperty, b);

b = new Binding("NonActiveGlowBrush");
b.Source = owner;
glow.SetBinding(Glow.NonActiveGlowBrushProperty, b);

switch (direction)
{
case GlowDirection.Left:
Expand Down
35 changes: 32 additions & 3 deletions MahApps.Metro/Controls/MetroWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ public class MetroWindow : Window
public static readonly DependencyProperty WindowPlacementSettingsProperty = DependencyProperty.Register("WindowPlacementSettings", typeof(IWindowPlacementSettings), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty TitleForegroundProperty = DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(MetroWindow));
public static readonly DependencyProperty IgnoreTaskbarOnMaximizeProperty = DependencyProperty.Register("IgnoreTaskbarOnMaximize", typeof(bool), typeof(MetroWindow), new PropertyMetadata(false));
public static readonly DependencyProperty GlowBrushProperty = DependencyProperty.Register("GlowBrush", typeof(SolidColorBrush), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty FlyoutsProperty = DependencyProperty.Register("Flyouts", typeof(FlyoutsControl), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty WindowTransitionsEnabledProperty = DependencyProperty.Register("WindowTransitionsEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));

public static readonly DependencyProperty GlowBrushProperty = DependencyProperty.Register("GlowBrush", typeof(SolidColorBrush), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty NonActiveGlowBrushProperty = DependencyProperty.Register("NonActiveGlowBrush", typeof(SolidColorBrush), typeof(MetroWindow), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(153, 153, 153)))); // #999999
public static readonly DependencyProperty NonActiveBorderBrushProperty = DependencyProperty.Register("NonActiveBorderBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null));

public static readonly DependencyProperty IconTemplateProperty = DependencyProperty.Register("IconTemplate", typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty TitleTemplateProperty = DependencyProperty.Register("TitleTemplate", typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null));

Expand All @@ -69,7 +72,9 @@ public class MetroWindow : Window
public static readonly DependencyProperty TextBlockStyleProperty = DependencyProperty.Register("TextBlockStyle", typeof(Style), typeof(MetroWindow), new PropertyMetadata(default(Style)));
public static readonly DependencyProperty UseNoneWindowStyleProperty = DependencyProperty.Register("UseNoneWindowStyle", typeof(bool), typeof(MetroWindow), new PropertyMetadata(false, OnUseNoneWindowStylePropertyChangedCallback));
public static readonly DependencyProperty OverrideDefaultWindowCommandsBrushProperty = DependencyProperty.Register("OverrideDefaultWindowCommandsBrush", typeof(SolidColorBrush), typeof(MetroWindow));


public static readonly DependencyProperty EnableDWMDropShadowProperty = DependencyProperty.Register("EnableDWMDropShadow", typeof(bool), typeof(MetroWindow), new PropertyMetadata(false));

bool isDragging;

UIElement icon;
Expand Down Expand Up @@ -112,6 +117,12 @@ public Style TextBlockStyle
set { SetValue(TextBlockStyleProperty, value); }
}

public bool EnableDWMDropShadow
{
get { return (bool)GetValue(EnableDWMDropShadowProperty); }
set { SetValue(EnableDWMDropShadowProperty, value); }
}

/// <summary>
/// Gets/sets whether the Window Commands will show on top of a Flyout with it's position set to Top or Right.
/// </summary>
Expand Down Expand Up @@ -394,6 +405,24 @@ public SolidColorBrush GlowBrush
set { SetValue(GlowBrushProperty, value); }
}

/// <summary>
/// Gets/sets the brush used for the Window's non-active glow.
/// </summary>
public SolidColorBrush NonActiveGlowBrush
{
get { return (SolidColorBrush)GetValue(NonActiveGlowBrushProperty); }
set { SetValue(NonActiveGlowBrushProperty, value); }
}

/// <summary>
/// Gets/sets the brush used for the Window's non-active border.
/// </summary>
public Brush NonActiveBorderBrush
{
get { return (Brush)GetValue(NonActiveBorderBrushProperty); }
set { SetValue(NonActiveBorderBrushProperty, value); }
}

/// <summary>
/// Gets/sets the TitleBar/Window's Text.
/// </summary>
Expand Down Expand Up @@ -662,7 +691,7 @@ public override void OnApplyTemplate()

protected override void OnStateChanged(EventArgs e)
{
if (WindowButtonCommands != null)
if (WindowButtonCommands != null && !this.UseNoneWindowStyle)
{
WindowButtonCommands.RefreshMaximiseIconState();
}
Expand Down
17 changes: 17 additions & 0 deletions MahApps.Metro/MahApps.Metro.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@
<Compile Include="Controls\WindowCommands.cs" />
<Compile Include="Converters\ThicknessToDoubleConverter.cs" />
<Compile Include="Converters\TreeViewMarginConverter.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\ComGuids.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Debug.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\DoubleUtil.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\DpiHelper.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\ErrorCodes.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\MessageWindow.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\NativeMethods.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\ShellProvider.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\StreamHelper.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Utilities.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Utilities.Windows.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Utilities.Wpf.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Verify.cs" />
<Compile Include="Microsoft.Windows.Shell\SystemCommands.cs" />
<Compile Include="Microsoft.Windows.Shell\SystemParameters2.cs" />
<Compile Include="Microsoft.Windows.Shell\WindowChrome.cs" />
<Compile Include="Microsoft.Windows.Shell\WindowChromeWorker.cs" />
<Compile Include="Models\Win32\GWL.cs" />
<Compile Include="Models\Win32\HitTestValues.cs" />
<Compile Include="Models\Win32\NativeMethods.cs" />
Expand Down
2 changes: 2 additions & 0 deletions MahApps.Metro/MahApps.Metro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
<Compile Include="Microsoft.Windows.Shell\Standard\ShellProvider.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\StreamHelper.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Utilities.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Utilities.Windows.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Utilities.Wpf.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\Verify.cs" />
<Compile Include="Microsoft.Windows.Shell\SystemCommands.cs" />
<Compile Include="Microsoft.Windows.Shell\SystemParameters2.cs" />
Expand Down
74 changes: 69 additions & 5 deletions MahApps.Metro/Microsoft.Windows.Shell/Standard/ComGuids.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
/**************************************************************************\
Copyright Microsoft Corporation. All Rights Reserved.
\**************************************************************************/

namespace Standard
namespace Standard
{
using System.Diagnostics.CodeAnalysis;

internal static partial class IID
{
/// <summary>IID_IApplicationAssociationRegistration</summary>
public const string ApplicationAssociationRegistration = "4e530b0a-e611-4c77-a3ac-9031d022281b";
/// <summary>IID_IConnectionPoint</summary>
public const string ConnectionPoint = "B196B286-BAB4-101A-B69C-00AA00341D07";
/// <summary>IID_IConnectionPointContainer</summary>
public const string ConnectionPointContainer = "B196B284-BAB4-101A-B69C-00AA00341D07";
public const string DragSourceHelper = "DE5BF786-477A-11D2-839D-00C04FD918D0";
public const string DragSourceHelper2 = "83E07D0D-0C5F-4163-BF1A-60B274051E40";
public const string DropTargetHelper = "4657278B-411B-11D2-839A-00C04FD918D0";
/// <summary>IID_IEnumConnectionPoints</summary>
public const string EnumConnectionPoints = "B196B285-BAB4-101A-B69C-00AA00341D07";
/// <summary>IID_IEnumConnections</summary>
public const string EnumConnections = "B196B287-BAB4-101A-B69C-00AA00341D07";
/// <summary>IID_IEnumIDList</summary>
public const string EnumIdList = "000214F2-0000-0000-C000-000000000046";
/// <summary>IID_IEnumObjects</summary>
public const string EnumObjects = "2c1c7e2e-2d0e-4059-831e-1e6f82335c2e";
/// <summary>IID_IFileDialog</summary>
public const string FileDialog = "42f85136-db7e-439c-85f1-e4075d135fc8";
/// <summary>IID_IFileDialogEvents</summary>
public const string FileDialogEvents = "973510DB-7D7F-452B-8975-74A85828D354";
/// <summary>IID_IFileOpenDialog</summary>
public const string FileOpenDialog = "d57c7288-d4ad-4768-be02-9d969532d960";
/// <summary>IID_IFileSaveDialog</summary>
public const string FileSaveDialog = "84bccd23-5fde-4cdb-aea4-af64b83d78ab";
/// <summary>IID_IHTMLDocument</summary>
public const string HtmlDocument = "626FC520-A41E-11CF-A731-00A0C9082637";
/// <summary>IID_IHTMLDocument2</summary>
public const string HtmlDocument2 = "332C4425-26CB-11D0-B483-00C04FD90119";
/// <summary>IID_IModalWindow</summary>
Expand Down Expand Up @@ -40,6 +61,28 @@ internal static partial class IID
public const string TaskbarList2 = "602D4995-B13A-429b-A66E-1935E44F4317";
/// <summary>IID_IUnknown</summary>
public const string Unknown = "00000000-0000-0000-C000-000000000046";
/// <summary>IID_IWebBrowser2</summary>
public const string WebBrowser2 = "D30C1661-CDAF-11D0-8A3E-00C04FC9E26E";
/// <summary>DIID_DWebBrowserEvents</summary>
public const string WebBrowserEvents = "EAB22AC2-30C1-11CF-A7EB-0000C05BAE0B";
/// <summary>IID_DWebBrowserEvents2</summary>
public const string WebBrowserEvents2 = "34A715A0-6587-11D0-924A-0020AFC7AC4D";
/// <summary>IID_IWICBitmapDecoder</summary>
public const string WICBitmapDecoder = "9EDDE9E7-8DEE-47ea-99DF-E6FAF2ED44BF";
/// <summary>IID_IWICBitmapFlipRotator</summary>
public const string WICBitmapFlipRotator = "5009834F-2D6A-41ce-9E1B-17C5AFF7A782";
/// <summary>IID_IWICBitmapFrameDecode</summary>
public const string WICBitmapFrameDecode = "3B16811B-6A43-4ec9-A813-3D930C13B940";
/// <summary>IID_IWICBitmap</summary>
public const string WICBitmap = "00000121-a8f2-4877-ba0a-fd2b6645fb94";
/// <summary>IID_IWICBitmapSource</summary>
public const string WICBitmapSource = "00000120-a8f2-4877-ba0a-fd2b6645fb94";
/// <summary>IID_IWICFormatConverter</summary>
public const string WICFormatConverter = "00000301-a8f2-4877-ba0a-fd2b6645fb94";
/// <summary>IID_IWICImagingFactory</summary>
public const string WICImagingFactory = "ec5ec8a9-c395-4314-9c77-54d7a935ff70";
/// <summary>IID_IWICStream</summary>
public const string WICStream = "135FF860-22B7-4ddf-B0F6-218F4F299A43";

#region Win7 IIDs

Expand All @@ -61,13 +104,31 @@ internal static partial class IID
#endregion
}

internal static partial class SID
{
/// <summary>SID_SWebBrowserApp</summary>
public const string SWebBrowserApp = "0002DF05-0000-0000-C000-000000000046";
}

internal static partial class CLSID
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public static T CoCreateInstance<T>(string clsid)
{
return (T)System.Activator.CreateInstance(System.Type.GetTypeFromCLSID(new System.Guid(clsid)));
}

/// <summary>CLSID_ApplicationAssociationRegistration</summary>
/// <remarks>IID_IApplicationAssociationRegistration</remarks>
public const string ApplicationAssociationRegistration = "591209c7-767b-42b2-9fba-44ee4615f2c7";
/// <summary>CLSID_DragDropHelper</summary>
public const string DragDropHelper = "4657278A-411B-11d2-839A-00C04FD918D0";
/// <summary>CLSID_FileOpenDialog</summary>
/// <remarks>IID_IFileOpenDialog</remarks>
public const string FileOpenDialog = "DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7";
/// <summary>CLSID_FileSaveDialog</summary>
/// <remarks>IID_IFileSaveDialog</remarks>
public const string FileSaveDialog = "C0B4E2F3-BA21-4773-8DBA-335EC946EB8B";
/// <summary>CLSID_TaskbarList</summary>
/// <remarks>IID_ITaskbarList</remarks>
public const string TaskbarList = "56FDF344-FD6D-11d0-958A-006097C9A090";
Expand All @@ -78,6 +139,9 @@ public static T CoCreateInstance<T>(string clsid)
/// <remarks>IID_IShellLink</remarks>
public const string ShellLink = "00021401-0000-0000-C000-000000000046";

/// <summary>CLSID_WICImagingFactory</summary>
public const string WICImagingFactory = "cacaf262-9370-4615-a13b-9f5539da4c0a";

#region Win7 CLSIDs

/// <summary>CLSID_DestinationList</summary>
Expand Down
55 changes: 40 additions & 15 deletions MahApps.Metro/Microsoft.Windows.Shell/Standard/Debug.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**************************************************************************\
Copyright Microsoft Corporation. All Rights Reserved.
\**************************************************************************/

// Conditional to use more aggressive fail-fast behaviors when debugging.
#define DEV_DEBUG

Expand All @@ -20,13 +16,19 @@ namespace Standard
/// <summary>A static class for verifying assumptions.</summary>
internal static class Assert
{
// Blend and VS don't like Debugger.Break being called on their design surfaces. Badness will happen.
//private static readonly bool _isNotAtRuntime = (bool)System.ComponentModel.DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(System.Windows.DependencyObject)).DefaultValue;

private static void _Break()
{
//if (!_isNotAtRuntime)
{
#if DEV_DEBUG
Debugger.Break();
Debugger.Break();
#else
Debug.Assert(false);
Debug.Assert(false);
#endif
}
}

/// <summary>A function signature for Assert.Evaluate.</summary>
Expand Down Expand Up @@ -84,6 +86,29 @@ public static void AreEqual<T>(T expected, T actual)
}
}

[Conditional("DEBUG")]
public static void LazyAreEqual<T>(Func<T> expectedResult, Func<T> actualResult)
{
Assert.IsNotNull(expectedResult);
Assert.IsNotNull(actualResult);

T actual = actualResult();
T expected = expectedResult();

if (null == expected)
{
// Two nulls are considered equal, regardless of type semantics.
if (null != actual && !actual.Equals(expected))
{
_Break();
}
}
else if (!expected.Equals(actual))
{
_Break();
}
}

/// <summary>
/// Verifies that two generic type data are not equal. The assertion fails if they are.
/// </summary>
Expand Down Expand Up @@ -248,6 +273,15 @@ public static void IsTrue(bool condition)
}
}

[Conditional("DEBUG")]
public static void IsTrue<T>(Predicate<T> predicate, T arg)
{
if (!predicate(arg))
{
_Break();
}
}

/// <summary>
/// Verifies that the specified condition is true. The assertion fails if it is not.
/// </summary>
Expand Down Expand Up @@ -360,14 +394,5 @@ public static void NullableIsNull<T>(T? value) where T : struct
_Break();
}
}

[Conditional("DEBUG")]
public static void IsNotOnMainThread()
{
if (System.Windows.Application.Current.Dispatcher.CheckAccess())
{
_Break();
}
}
}
}
Loading

0 comments on commit fa26a4a

Please sign in to comment.