Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use theme to create DocumentGridPage borders #2574

Merged
merged 14 commits into from
Mar 27, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,13 @@ protected override Visual GetVisualChild(int index)
{
CheckDisposed();

// count is either 0 or 3
// count is either 0 or 1
if (VisualChildrenCount != 0)
{
switch (index)
{
case 0:
return _dropShadowRight;
case 1:
return _dropShadowBottom;
case 2:
return _pageBorder;
return _documentContainer;
default:
throw new ArgumentOutOfRangeException("index", index, SR.Get(SRID.Visual_ArgumentOutOfRange));
}
Expand All @@ -215,7 +211,7 @@ protected override int VisualChildrenCount
get
{
if (!_disposed && hasAddedChildren)
return 3;
return 1;
else
return 0;
}
Expand All @@ -233,12 +229,7 @@ protected override sealed Size MeasureOverride(Size availableSize)

if (!hasAddedChildren)
{
//Add the drop shadow
this.AddVisualChild(_dropShadowRight);
this.AddVisualChild(_dropShadowBottom);

//Add the page (inside the pageBorder)
this.AddVisualChild(_pageBorder);
this.AddVisualChild(_documentContainer);

hasAddedChildren = true;
}
Expand All @@ -247,23 +238,16 @@ protected override sealed Size MeasureOverride(Size availableSize)
//state of the ShowPageBorders property.
if (ShowPageBorders)
{
_pageBorder.BorderThickness = _pageBorderVisibleThickness;
_pageBorder.Background = Brushes.White;
_dropShadowRight.Opacity = _dropShadowOpacity;
_dropShadowBottom.Opacity = _dropShadowOpacity;
var key = new ComponentResourceKey(typeof(FrameworkElement), "DocumentGridPageContainerWithBorder");
_documentContainer.SetCurrentValue(StyleProperty, TryFindResource(key));
}
else
{
_pageBorder.BorderThickness = _pageBorderInvisibleThickness;
_pageBorder.Background = Brushes.Transparent;
_dropShadowRight.Opacity = 0.0;
_dropShadowBottom.Opacity = 0.0;
_documentContainer.SetCurrentValue(StyleProperty, TryFindResource(typeof(ContentControl)));
}

//Measure our children.
_dropShadowRight.Measure(availableSize);
_dropShadowBottom.Measure(availableSize);
_pageBorder.Measure(availableSize);
_documentContainer.Measure(availableSize);

//Set the Page Zoom on the DocumentPageView to the ratio between our measure constraint
//and the actual size of the page; this will cause the DPV to scale our page appropriately.
Expand All @@ -283,26 +267,8 @@ protected override sealed Size ArrangeOverride(Size arrangeSize)
{
CheckDisposed();

//Arrange the page, no offset.
_pageBorder.Arrange(new Rect(new Point(0.0, 0.0), arrangeSize));

//Arrange the drop shadow parts along the right
//and bottom edges of the page.

//Right edge - as tall as the page (minus the shadow width so we don't overlap
//with the bottom edge), 5px wide. Offset vertically by 5px.
_dropShadowRight.Arrange(
new Rect(
new Point(arrangeSize.Width, _dropShadowWidth),
new Size(_dropShadowWidth, Math.Max(0.0, arrangeSize.Height - _dropShadowWidth))
));

//Bottom edge - 5px tall, and as wide as the page. Offset horizontally by 5px.
_dropShadowBottom.Arrange(
new Rect(
new Point(_dropShadowWidth, arrangeSize.Height),
new Size(arrangeSize.Width, _dropShadowWidth)
));
//Arrange the page container, no offset.
_documentContainer.Arrange(new Rect(new Point(0.0, 0.0), arrangeSize));

base.ArrangeOverride(arrangeSize);
return arrangeSize;
Expand Down Expand Up @@ -330,20 +296,9 @@ private void Init()
_documentPageView.StretchDirection = StretchDirection.Both;
_documentPageView.PageNumber = int.MaxValue;

//Create the border that goes around the page content.
_pageBorder = new Border();
_pageBorder.BorderBrush = Brushes.Black;
_pageBorder.Child = _documentPageView;

//Create the drop shadow that goes behind the page, made
//of two rectangles in an "L" shape.
_dropShadowRight = new Rectangle();
_dropShadowRight.Fill = Brushes.Black;
_dropShadowRight.Opacity = _dropShadowOpacity;

_dropShadowBottom = new Rectangle();
_dropShadowBottom.Fill = Brushes.Black;
_dropShadowBottom.Opacity = _dropShadowOpacity;
//Create the content control that contains the page content.
_documentContainer = new ContentControl();
_documentContainer.Content = _documentPageView;

_loaded = false;
}
Expand Down Expand Up @@ -439,20 +394,11 @@ void IDisposable.Dispose()
private bool hasAddedChildren;
private DocumentPaginator _paginator;
private DocumentPageView _documentPageView;
private Rectangle _dropShadowRight;
private Rectangle _dropShadowBottom;
private Border _pageBorder;
private ContentControl _documentContainer;

private bool _showPageBorders;
private bool _loaded;


//Constants
private const double _dropShadowOpacity = 0.35;
private const double _dropShadowWidth = 5.0;
private readonly Thickness _pageBorderVisibleThickness = new Thickness(1, 1, 1, 1);
private readonly Thickness _pageBorderInvisibleThickness = new Thickness(0, 0, 0, 0);

private bool _disposed;

#endregion Private Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="dogfood">
<Project DefaultTargets="GenerateThemes" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(_NTDRIVE)$(_NTROOT)\wpf\src\Microsoft.WPF.Product.Settings.targets" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props'))" />

<PropertyGroup>
<TargetType>COPY</TargetType>
</PropertyGroup>

<ItemGroup>
<ThemeXaml Include="..\Aero\Themes\Aero.NormalColor.xaml" />
<ThemeXaml Include="..\Aero2\Themes\Aero2.NormalColor.xaml" />
<ThemeXaml Include="..\AeroLite\Themes\AeroLite.NormalColor.xaml" />
<ThemeXaml Include="..\Classic\Themes\Classic.xaml" />
<ThemeXaml Include="..\Luna\Themes\Luna.Homestead.xaml" />
<ThemeXaml Include="..\Luna\Themes\Luna.NormalColor.xaml" />
<ThemeXaml Include="..\Luna\Themes\Luna.Metallic.xaml" />
<ThemeXaml Include="..\Royale\Themes\Royale.NormalColor.xaml" />
<ThemeXaml Include="..\PresentationFramework.Aero\Themes\Aero.NormalColor.xaml" />
<ThemeXaml Include="..\PresentationFramework.Aero2\Themes\Aero2.NormalColor.xaml" />
<ThemeXaml Include="..\PresentationFramework.AeroLite\Themes\AeroLite.NormalColor.xaml" />
<ThemeXaml Include="..\PresentationFramework.Classic\Themes\Classic.xaml" />
<ThemeXaml Include="..\PresentationFramework.Luna\Themes\Luna.Homestead.xaml" />
<ThemeXaml Include="..\PresentationFramework.Luna\Themes\Luna.NormalColor.xaml" />
<ThemeXaml Include="..\PresentationFramework.Luna\Themes\Luna.Metallic.xaml" />
<ThemeXaml Include="..\PresentationFramework.Royale\Themes\Royale.NormalColor.xaml" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -68,30 +64,14 @@
<StyleXaml Include="..\XAML\Window.xaml" />
</ItemGroup>

<Import Project="$(_NTDRIVE)$(_NTROOT)\tools\Microsoft.DevDiv.Native.targets" />

<PropertyGroup>
<BuildGeneratedDependsOn>
GenerateThemes;
$(BuildGeneratedDependsOn)
</BuildGeneratedDependsOn>
</PropertyGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets'))" />

<Target Name="GenerateThemes"
Inputs="@(StyleXaml);@(ThemeXaml)"
Outputs="$(OutputPath)sdk\%(ThemeXaml.FileName)%(ThemeXaml.Extension).sdk" >

<MakeDir Condition="!Exists('$(IntermediateOutputDirectory)')" Directories="$(IntermediateOutputDirectory)" />

<Exec Command="$(PerlCommand) ThemeGenerator.pl $(IntermediateOutputDirectory)\%(ThemeXaml.FileName)%(ThemeXaml.Extension).sdk $(IntermediateOutputDirectory)\%(ThemeXaml.FileName)%(ThemeXaml.Extension) %(ThemeXaml.Identity) @(StyleXaml, ' ')"
Outputs="$(IntermediateOutputDirectory)\%(ThemeXaml.FileName)%(ThemeXaml.Extension).sdk;$(IntermediateOutputDirectory)\%(ThemeXaml.FileName)%(ThemeXaml.Extension)"
Outputs="@(ThemeXaml)">
<Exec Command="$(PerlCommand) ThemeGenerator.pl %(ThemeXaml.RelativeDir)%(ThemeXaml.FileName)%(ThemeXaml.Extension).sdk %(ThemeXaml.Identity) %(ThemeXaml.Identity) @(StyleXaml, ' ')"
Outputs="$(IntermediateOutputDirectory)\%(ThemeXaml.FileName)%(ThemeXaml.Extension).sdk;%(ThemeXaml.Identity)"
StandardOutputImportance="normal" />

<ItemGroup>
<DataFile Include="$(IntermediateOutputDirectory)\%(ThemeXaml.FileName)%(ThemeXaml.Extension).sdk">
<SubFolder>sdk</SubFolder>
</DataFile>
</ItemGroup>
</Target>

</Project>
Loading