Skip to content

Commit

Permalink
Merge pull request #1 from MahApps/master
Browse files Browse the repository at this point in the history
Rebase master
  • Loading branch information
Cornyfisch committed Jul 25, 2013
2 parents ffa5bf8 + 0c2e115 commit f4e1cb3
Show file tree
Hide file tree
Showing 57 changed files with 9,899 additions and 35,218 deletions.
6 changes: 6 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Binary file added .nuget/NuGet.exe
Binary file not shown.
133 changes: 133 additions & 0 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>

<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
<PackagesConfig>packages.config</PackagesConfig>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>

<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>

<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) " </RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>

<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />

<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
13 changes: 7 additions & 6 deletions MahApps.Metro.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{72C27A3B-930A-45E7-B073-C9D7BF046E4B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MahApps.Metro.NET45", "MahApps.Metro\MahApps.Metro.NET45.csproj", "{942D11C4-29F5-46C4-8C14-4B976D56C637}"
ProjectSection(ProjectDependencies) = postProject
{5B1710D2-5DC8-4754-91B2-19165DE49B3D} = {5B1710D2-5DC8-4754-91B2-19165DE49B3D}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{F80ABBD3-DDB4-4797-8979-80926F03C94B}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -24,14 +21,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{F80ABB
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetroDemo.NET45", "samples\MetroDemo\MetroDemo.NET45.csproj", "{67174E59-0A40-4E8F-A82B-02FD317DD801}"
ProjectSection(ProjectDependencies) = postProject
{56E8080F-FFEB-47CD-ADB9-92245F92565B} = {56E8080F-FFEB-47CD-ADB9-92245F92565B}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Caliburn.Metro.Demo", "samples\Caliburn.Metro.Demo\Caliburn.Metro.Demo.csproj", "{9F9B7559-E8B6-43C3-BEE8-9A977BACE0FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Caliburn.Metro.Demo.NET45", "samples\Caliburn.Metro.Demo\Caliburn.Metro.Demo.NET45.csproj", "{6107F8A7-28DB-45D9-B822-0BB8C1AE2095}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4166BE4A-2746-40AA-B38B-70D7C3054C37}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
95 changes: 89 additions & 6 deletions MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@ public class BorderlessWindowBehavior : Behavior<Window>
{
public static readonly DependencyProperty ResizeWithGripProperty = DependencyProperty.Register("ResizeWithGrip", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(true));
public static readonly DependencyProperty AutoSizeToContentProperty = DependencyProperty.Register("AutoSizeToContent", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(false));
public static readonly DependencyProperty EnableDWMDropShadowProperty = DependencyProperty.Register("EnableDWMDropShadow", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(false));
public static readonly DependencyProperty EnableDWMDropShadowProperty = DependencyProperty.Register("EnableDWMDropShadow", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(false, new PropertyChangedCallback((obj, args) =>
{
var behaviorClass = ((BorderlessWindowBehavior)obj);

if (behaviorClass.AssociatedObject != null)
if ((bool)args.NewValue && behaviorClass.AssociatedObject.AllowsTransparency)
throw new InvalidOperationException("EnableDWMDropShadow cannot be set to True when AllowsTransparency is True.");
})));

public static readonly DependencyProperty AllowsTransparencyProperty =
DependencyProperty.Register("AllowsTransparency", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(true, new PropertyChangedCallback((obj, args) =>
{
var behaviorClass = ((BorderlessWindowBehavior)obj);

if (behaviorClass.AssociatedObject != null)
behaviorClass.AssociatedObject.AllowsTransparency = (bool)args.NewValue;
{
if ((bool)args.NewValue && behaviorClass.EnableDWMDropShadow)
throw new InvalidOperationException("AllowsTransparency cannot be set to True when EnableDWMDropShadow is True.");
else
behaviorClass.AssociatedObject.AllowsTransparency = (bool)args.NewValue;
}
})));

public bool AllowsTransparency
Expand Down Expand Up @@ -67,7 +79,7 @@ private static IntPtr SetClassLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
return new IntPtr(UnsafeNativeMethods.SetClassLongPtr32(hWnd, nIndex, unchecked((uint)dwNewLong.ToInt32())));
}

private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
var mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));

Expand All @@ -84,6 +96,15 @@ private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
mmi.ptMaxPosition.Y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
mmi.ptMaxSize.X = Math.Abs(rcWorkArea.right - rcWorkArea.left);
mmi.ptMaxSize.Y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);

bool ignoreTaskBar = AssociatedObject as MetroWindow != null && ((MetroWindow)this.AssociatedObject).IgnoreTaskbarOnMaximize;

if (!ignoreTaskBar)
{
mmi.ptMaxTrackSize.X = mmi.ptMaxSize.X;
mmi.ptMaxTrackSize.Y = mmi.ptMaxSize.Y;
mmi = AdjustWorkingAreaForAutoHide(monitor, mmi);
}
}

Marshal.StructureToPtr(mmi, lParam, true);
Expand All @@ -96,6 +117,9 @@ protected override void OnAttached()
else
AssociatedObject.SourceInitialized += AssociatedObject_SourceInitialized;

if (AllowsTransparency && EnableDWMDropShadow)
throw new InvalidOperationException("EnableDWMDropShadow cannot be set to True when AllowsTransparency is True.");

AssociatedObject.WindowStyle = WindowStyle.None;
AssociatedObject.AllowsTransparency = AllowsTransparency;
AssociatedObject.StateChanged += AssociatedObjectStateChanged;
Expand Down Expand Up @@ -188,13 +212,72 @@ private void HandleMaximize()
var x = ignoreTaskBar ? monitorInfo.rcMonitor.left : monitorInfo.rcWork.left;
var y = ignoreTaskBar ? monitorInfo.rcMonitor.top : monitorInfo.rcWork.top;
var cx = ignoreTaskBar ? Math.Abs(monitorInfo.rcMonitor.right - x) : Math.Abs(monitorInfo.rcWork.right - x);

// Pull off one pixel as a taskbar set to auto-hide wouldn't reappear otherwise
var cy = ignoreTaskBar ? Math.Abs(monitorInfo.rcMonitor.bottom - y) : Math.Abs(monitorInfo.rcWork.bottom - y - 1);
var cy = ignoreTaskBar ? Math.Abs(monitorInfo.rcMonitor.bottom - y) : Math.Abs(monitorInfo.rcWork.bottom - y);
UnsafeNativeMethods.SetWindowPos(_mHWND, new IntPtr(-2), x, y, cx, cy, 0x0040);
}
}

private static int GetEdge(RECT rc)
{
int uEdge;
if (rc.top == rc.left && rc.bottom > rc.right)
uEdge = (int)ABEdge.ABE_LEFT;
else if (rc.top == rc.left && rc.bottom < rc.right)
uEdge = (int)ABEdge.ABE_TOP;
else if (rc.top > rc.left)
uEdge = (int)ABEdge.ABE_BOTTOM;
else
uEdge = (int)ABEdge.ABE_RIGHT;
return uEdge;
}

/// <summary>
/// This method handles the window size if the taskbar is set to auto-hide.
/// </summary>
private static MINMAXINFO AdjustWorkingAreaForAutoHide(IntPtr monitorContainingApplication, MINMAXINFO mmi)
{
IntPtr hwnd = UnsafeNativeMethods.FindWindow("Shell_TrayWnd", null);
IntPtr monitorWithTaskbarOnIt = UnsafeNativeMethods.MonitorFromWindow(hwnd, Constants.MONITOR_DEFAULTTONEAREST);

if (!monitorContainingApplication.Equals(monitorWithTaskbarOnIt))
return mmi;

var abd = new APPBARDATA();
abd.cbSize = Marshal.SizeOf(abd);
abd.hWnd = hwnd;
UnsafeNativeMethods.SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref abd);
int uEdge = GetEdge(abd.rc);
bool autoHide = Convert.ToBoolean(UnsafeNativeMethods.SHAppBarMessage((int)ABMsg.ABM_GETSTATE, ref abd));

if (!autoHide)
return mmi;

switch (uEdge)
{
case (int)ABEdge.ABE_LEFT:
mmi.ptMaxPosition.X += 2;
mmi.ptMaxTrackSize.X -= 2;
mmi.ptMaxSize.X -= 2;
break;
case (int)ABEdge.ABE_RIGHT:
mmi.ptMaxSize.X -= 2;
mmi.ptMaxTrackSize.X -= 2;
break;
case (int)ABEdge.ABE_TOP:
mmi.ptMaxPosition.Y += 2;
mmi.ptMaxTrackSize.Y -= 2;
mmi.ptMaxSize.Y -= 2;
break;
case (int)ABEdge.ABE_BOTTOM:
mmi.ptMaxSize.Y -= 2;
mmi.ptMaxTrackSize.Y -= 2;
break;
default:
return mmi;
}
return mmi;
}

protected override void OnDetaching()
{
RemoveHwndHook();
Expand Down
12 changes: 11 additions & 1 deletion MahApps.Metro/Controls/MetroContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ private void MetroContentControlLoaded(object sender, RoutedEventArgs e)
{
var root = ((Grid)GetTemplateChild("root"));
root.Opacity = 1.0;
((System.Windows.Media.TranslateTransform)root.RenderTransform).X = 0;
var transform = ((System.Windows.Media.TranslateTransform) root.RenderTransform);
if (transform.IsFrozen)
{
var modifiedTransform = transform.Clone();
modifiedTransform.X = 0;
root.RenderTransform = modifiedTransform;
}
else
{
transform.X = 0;
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions MahApps.Metro/Controls/MetroTabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ void BaseMetroTabControl_Unloaded(object sender, RoutedEventArgs e)

void BaseMetroTabControl_Loaded(object sender, RoutedEventArgs e)
{
this.Loaded += BaseMetroTabControl_Loaded;

//Ensure each tabitem knows what the owning tab is.

if (ItemsSource == null)
Expand Down
5 changes: 5 additions & 0 deletions MahApps.Metro/MahApps.Metro.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\NET45\</OutputPath>
<IntermediateOutputPath>obj\NET45\Debug\</IntermediateOutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -31,6 +32,7 @@
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\NET45\</OutputPath>
<IntermediateOutputPath>obj\NET45\Release\</IntermediateOutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -106,6 +108,9 @@
<Compile Include="Models\Win32\WM.cs" />
<Compile Include="Models\Win32\WS.cs" />
<Compile Include="Models\Win32\WSEX.cs" />
<Compile Include="Native\ABEdge.cs" />
<Compile Include="Native\ABMsg.cs" />
<Compile Include="Native\APPBARDATA.cs" />
<Compile Include="Native\WINDOWPLACEMENT.cs" />
<Compile Include="Controls\WindowSettings.cs" />
<Compile Include="Native\Constants.cs" />
Expand Down
Loading

0 comments on commit f4e1cb3

Please sign in to comment.