Bring back transparent window

This commit is contained in:
Paddy Xu
2018-01-12 23:30:25 +02:00
parent c622ed748a
commit a969687b7b
13 changed files with 244 additions and 337 deletions

View File

@@ -26,7 +26,7 @@
VirtualizingPanel.IsVirtualizing="True" Width="150" VirtualizingPanel.IsVirtualizing="True" Width="150"
SelectedIndex="0" SelectedIndex="0"
Focusable="False" Focusable="False"
Background="#00FFFFFF" Background="Transparent"
ItemsSource="{Binding PageThumbnails, ElementName=thisPdfViewer}" ItemsSource="{Binding PageThumbnails, ElementName=thisPdfViewer}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderThickness="0,0,1,0" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderThickness="0,0,1,0"
ItemContainerStyle="{Binding Mode=OneWay, Source={StaticResource ListBoxItemStyleNoFocusedBorder}}"> ItemContainerStyle="{Binding Mode=OneWay, Source={StaticResource ListBoxItemStyleNoFocusedBorder}}">
@@ -61,7 +61,7 @@
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<Grid Grid.Column="1" Background="#00EFEFEF"> <Grid Grid.Column="1" Background="#FFFAFAFA">
<imageViewer:ImagePanel x:Name="pagePanel" RenderMode="NearestNeighbor" ShowZoomLevelInfo="False" <imageViewer:ImagePanel x:Name="pagePanel" RenderMode="NearestNeighbor" ShowZoomLevelInfo="False"
BackgroundVisibility="Collapsed" MetaIconVisibility="Collapsed" /> BackgroundVisibility="Collapsed" MetaIconVisibility="Collapsed" />
</Grid> </Grid>

View File

@@ -7,10 +7,9 @@
xmlns:local="clr-namespace:QuickLook.Plugin.TextViewer" xmlns:local="clr-namespace:QuickLook.Plugin.TextViewer"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="317.974" d:DesignHeight="317.974"
d:DesignWidth="448.79" d:DesignWidth="448.79">
UseLayoutRounding="True">
<Grid> <Grid>
<avalonEdit:TextEditor x:Name="viewer" Background="#00FFFFFF" FontSize="14" ShowLineNumbers="True" <avalonEdit:TextEditor x:Name="viewer" Background="Transparent" FontSize="14" ShowLineNumbers="True"
WordWrap="True" IsReadOnly="True" IsManipulationEnabled="True" /> WordWrap="True" IsReadOnly="True" IsManipulationEnabled="True" />
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -21,8 +21,9 @@
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<ffme:MediaElement x:Name="mediaElement" /> <ffme:MediaElement x:Name="mediaElement" Background="{DynamicResource MainWindowBackgroundNoTransparent}" />
<Grid x:Name="coverArtPersenter" ClipToBounds="True" Background="{StaticResource MainWindowBackground}"> <Grid x:Name="coverArtPersenter" ClipToBounds="True"
Background="{DynamicResource MainWindowBackgroundNoTransparent}">
<Grid.Style> <Grid.Style>
<Style TargetType="Grid"> <Style TargetType="Grid">
<Setter Property="Visibility" Value="Collapsed" /> <Setter Property="Visibility" Value="Collapsed" />

View File

@@ -34,10 +34,11 @@ namespace QuickLook
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
public static readonly bool IsUWP = ProcessHelper.IsRunningAsUWP();
public static readonly bool Is64Bit = Environment.Is64BitProcess;
public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location; public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location;
public static readonly string AppPath = Path.GetDirectoryName(AppFullPath); public static readonly string AppPath = Path.GetDirectoryName(AppFullPath);
public static readonly bool Is64Bit = Environment.Is64BitProcess;
public static readonly bool IsUWP = ProcessHelper.IsRunningAsUWP();
public static readonly bool IsWin10 = Environment.OSVersion.Version >= new Version(10, 0);
private bool _isFirstInstance; private bool _isFirstInstance;
private Mutex _isRunning; private Mutex _isRunning;
@@ -126,6 +127,7 @@ namespace QuickLook
Process.GetCurrentProcess().Kill(); // just kill current process to avoid subsequence executions Process.GetCurrentProcess().Kill(); // just kill current process to avoid subsequence executions
//return; //return;
} }
Settings.Default.Upgraded = false; Settings.Default.Upgraded = false;
Settings.Default.Save(); Settings.Default.Save();
} }

View File

@@ -1,54 +0,0 @@
// Copyright © 2017 Paddy Xu
//
// This file is part of QuickLook program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Windows;
using System.Windows.Interop;
using QuickLook.Helpers;
namespace QuickLook.Controls
{
public class MainWindowBase : Window
{
public MainWindowBase()
{
//WindowStyle = WindowStyle.None;
SourceInitialized += SourceInitializedHandler;
}
private void SourceInitializedHandler(object sender, EventArgs e)
{
var handle = new WindowInteropHelper(this).Handle;
var handleSource = HwndSource.FromHwnd(handle);
handleSource?.AddHook(WindowProc);
}
private static IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case 0x0024: /* WM_GETMINMAXINFO */
//WindowHelper.WmGetMinMaxInfo(hwnd, lParam);
//handled = true;
break;
}
return (IntPtr) 0;
}
}
}

View File

@@ -26,7 +26,7 @@ using QuickLook.NativeMethods;
namespace QuickLook.Helpers namespace QuickLook.Helpers
{ {
public static class WindowHelper internal static class WindowHelper
{ {
public static Rect GetCurrentWindowRect() public static Rect GetCurrentWindowRect()
{ {
@@ -57,9 +57,8 @@ namespace QuickLook.Helpers
window.TransformToPixels(left, top, window.TransformToPixels(left, top,
out pxLeft, out pxTop); out pxLeft, out pxTop);
int pxWidth, pxHeight;
window.TransformToPixels(width, height, window.TransformToPixels(width, height,
out pxWidth, out pxHeight); out var pxWidth, out var pxHeight);
User32.MoveWindow(new WindowInteropHelper(window).Handle, pxLeft, pxTop, pxWidth, pxHeight, true); User32.MoveWindow(new WindowInteropHelper(window).Handle, pxLeft, pxTop, pxWidth, pxHeight, true);
} }
@@ -84,7 +83,7 @@ namespace QuickLook.Helpers
pixelY = (int) Math.Round(matrix.M22 * unitY); pixelY = (int) Math.Round(matrix.M22 * unitY);
} }
internal static bool IsForegroundWindowBelongToSelf() public static bool IsForegroundWindowBelongToSelf()
{ {
var hwnd = User32.GetForegroundWindow(); var hwnd = User32.GetForegroundWindow();
if (hwnd == IntPtr.Zero) if (hwnd == IntPtr.Zero)
@@ -94,59 +93,65 @@ namespace QuickLook.Helpers
return procId == Process.GetCurrentProcess().Id; return procId == Process.GetCurrentProcess().Id;
} }
internal static void SetNoactivate(WindowInteropHelper window) public static void SetNoactivate(WindowInteropHelper window)
{ {
User32.SetWindowLong(window.Handle, User32.GWL_EXSTYLE, User32.SetWindowLong(window.Handle, User32.GWL_EXSTYLE,
User32.GetWindowLong(window.Handle, User32.GWL_EXSTYLE) | User32.GetWindowLong(window.Handle, User32.GWL_EXSTYLE) |
User32.WS_EX_NOACTIVATE); User32.WS_EX_NOACTIVATE);
} }
internal static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam) public static void EnableBlur(Window window)
{ {
var mmi = (MinMaxInfo) Marshal.PtrToStructure(lParam, typeof(MinMaxInfo)); var accent = new AccentPolicy();
var accentStructSize = Marshal.SizeOf(accent);
accent.AccentState = AccentState.AccentEnableBlurbehind;
accent.AccentFlags = 2;
accent.GradientColor = 0x99FFFFFF;
// Adjust the maximized size and position to fit the work area of the current monitor var accentPtr = Marshal.AllocHGlobal(accentStructSize);
var currentScreen = Screen.FromHandle(hwnd); Marshal.StructureToPtr(accent, accentPtr, false);
var workArea = currentScreen.WorkingArea;
var monitorArea = currentScreen.Bounds;
mmi.ptMaxPosition.x = Math.Abs(workArea.Left - monitorArea.Left);
mmi.ptMaxPosition.y = Math.Abs(workArea.Top - monitorArea.Top);
mmi.ptMaxSize.x = Math.Abs(workArea.Right - workArea.Left);
mmi.ptMaxSize.y = Math.Abs(workArea.Bottom - workArea.Top);
Marshal.StructureToPtr(mmi, lParam, true); var data = new WindowCompositionAttributeData
}
[StructLayout(LayoutKind.Sequential)]
public struct MinMaxInfo
{
public POINT ptReserved;
public POINT ptMaxSize;
public POINT ptMaxPosition;
public POINT ptMinTrackSize;
public POINT ptMaxTrackSize;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
/// <summary>
/// x coordinate of point.
/// </summary>
public int x;
/// <summary>
/// y coordinate of point.
/// </summary>
public int y;
/// <summary>
/// Construct a point of coordinates (x,y).
/// </summary>
public POINT(int x, int y)
{ {
this.x = x; Attribute = WindowCompositionAttribute.WcaAccentPolicy,
this.y = y; SizeOfData = accentStructSize,
} Data = accentPtr
};
User32.SetWindowCompositionAttribute(new WindowInteropHelper(window).Handle, ref data);
Marshal.FreeHGlobal(accentPtr);
}
[StructLayout(LayoutKind.Sequential)]
internal struct WindowCompositionAttributeData
{
public WindowCompositionAttribute Attribute;
public IntPtr Data;
public int SizeOfData;
}
internal enum WindowCompositionAttribute
{
WcaAccentPolicy = 19
}
private enum AccentState
{
AccentDisabled = 0,
AccentEnableGradient = 1,
AccentEnableTransparentgradient = 2,
AccentEnableBlurbehind = 3,
AccentInvalidState = 4
}
[StructLayout(LayoutKind.Sequential)]
private struct AccentPolicy
{
public AccentState AccentState;
public int AccentFlags;
public uint GradientColor;
public readonly int AnimationId;
} }
} }
} }

View File

@@ -19,6 +19,7 @@ using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using QuickLook.Helpers;
namespace QuickLook.NativeMethods namespace QuickLook.NativeMethods
{ {
@@ -69,6 +70,10 @@ namespace QuickLook.NativeMethods
[DllImport("user32.dll")] [DllImport("user32.dll")]
internal static extern IntPtr GetParent(IntPtr hWnd); internal static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll")]
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd,
ref WindowHelper.WindowCompositionAttributeData data);
internal delegate int KeyboardHookProc(int code, int wParam, ref KeyboardHookStruct lParam); internal delegate int KeyboardHookProc(int code, int wParam, ref KeyboardHookStruct lParam);
[SuppressMessage("ReSharper", "InconsistentNaming")] [SuppressMessage("ReSharper", "InconsistentNaming")]

View File

@@ -117,7 +117,6 @@
<Compile Include="Controls\GlassLayer\GlassLayer.xaml.cs"> <Compile Include="Controls\GlassLayer\GlassLayer.xaml.cs">
<DependentUpon>GlassLayer.xaml</DependentUpon> <DependentUpon>GlassLayer.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\MainWindowBase.cs" />
<Compile Include="Converters\BooleanToKeyTimeConverter.cs" /> <Compile Include="Converters\BooleanToKeyTimeConverter.cs" />
<Compile Include="Converters\BooleanToVisibilityCollapsedConverter.cs" /> <Compile Include="Converters\BooleanToVisibilityCollapsedConverter.cs" />
<Compile Include="Converters\WindowStateNormalToThicknessConverter.cs" /> <Compile Include="Converters\WindowStateNormalToThicknessConverter.cs" />

View File

@@ -1,16 +1,14 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:system="clr-namespace:System;assembly=mscorlib" <SolidColorBrush x:Key="MainWindowBackground" Color="#CC292929" />
xmlns:fa="http://schemas.fontawesome.io/icons/"> <SolidColorBrush x:Key="MainWindowBackgroundNoTransparent" Color="#FF292929" />
<Color x:Key="MainWindowShadowColor">Gray</Color> <SolidColorBrush x:Key="WindowTextForeground" Color="#FFEFEFEF" />
<SolidColorBrush x:Key="MainWindowBackground" Color="#FF565656" /> <SolidColorBrush x:Key="WindowTextForegroundAlternative" Color="#FFD4D4D4" />
<SolidColorBrush x:Key="WindowTextForeground" Color="#E5EFEFEF" /> <SolidColorBrush x:Key="CaptionTextHoverBorder" Color="#DDB9B9B9" />
<SolidColorBrush x:Key="WindowTextForegroundAlternative" Color="#E5D4D4D4" />
<SolidColorBrush x:Key="CaptionTextHoverBorder" Color="#FFB9B9B9" />
<SolidColorBrush x:Key="CaptionButtonIconForeground" Color="#E5EFEFEF" /> <SolidColorBrush x:Key="CaptionButtonIconForeground" Color="#E5EFEFEF" />
<SolidColorBrush x:Key="CaptionButtonHoverBackground" Color="#22FFFFFF" /> <SolidColorBrush x:Key="CaptionButtonHoverBackground" Color="#22FFFFFF" />
<SolidColorBrush x:Key="CaptionButtonPressBackground" Color="#44FFFFFF" /> <SolidColorBrush x:Key="CaptionButtonPressBackground" Color="#44FFFFFF" />
<SolidColorBrush x:Key="CaptionCloseButtonHoverBackground" Color="#FFE81123" /> <SolidColorBrush x:Key="CaptionCloseButtonHoverBackground" Color="#FFE81123" />
<SolidColorBrush x:Key="CaptionCloseButtonPressBackground" Color="#FFB5394B" /> <SolidColorBrush x:Key="CaptionCloseButtonPressBackground" Color="#FFB5394B" />
<SolidColorBrush x:Key="CaptionBackground" Color="#FF3B3B3B" /> <SolidColorBrush x:Key="CaptionBackground" Color="#CC0E0E0E" />
</ResourceDictionary> </ResourceDictionary>

View File

@@ -4,17 +4,17 @@
<Thickness x:Key="MainWindowShadowMarginThickness">1</Thickness> <Thickness x:Key="MainWindowShadowMarginThickness">1</Thickness>
<Thickness x:Key="MainWindowResizeThickness">6</Thickness> <Thickness x:Key="MainWindowResizeThickness">6</Thickness>
<system:Double x:Key="MainWindowCaptionHeight">32</system:Double> <system:Double x:Key="MainWindowCaptionHeight">32</system:Double>
<Color x:Key="MainWindowShadowColor">Gray</Color> <SolidColorBrush x:Key="MainWindowBackground" Color="#BBFAFAFA" />
<SolidColorBrush x:Key="MainWindowBackground" Color="#FFFAFAFA" /> <SolidColorBrush x:Key="MainWindowBackgroundNoTransparent" Color="#FFFAFAFA" />
<SolidColorBrush x:Key="WindowTextForeground" Color="#E50E0E0E" /> <SolidColorBrush x:Key="WindowTextForeground" Color="#FF0E0E0E" />
<SolidColorBrush x:Key="WindowTextForegroundAlternative" Color="#E5626262" /> <SolidColorBrush x:Key="WindowTextForegroundAlternative" Color="#FF626262" />
<SolidColorBrush x:Key="CaptionTextHoverBorder" Color="#FF3D3D3D" /> <SolidColorBrush x:Key="CaptionTextHoverBorder" Color="#FF3D3D3D" />
<SolidColorBrush x:Key="CaptionButtonIconForeground" Color="#E50E0E0E" /> <SolidColorBrush x:Key="CaptionButtonIconForeground" Color="#E50E0E0E" />
<SolidColorBrush x:Key="CaptionButtonHoverBackground" Color="#44FFFFFF" /> <SolidColorBrush x:Key="CaptionButtonHoverBackground" Color="#44FFFFFF" />
<SolidColorBrush x:Key="CaptionButtonPressBackground" Color="#88FFFFFF" /> <SolidColorBrush x:Key="CaptionButtonPressBackground" Color="#88FFFFFF" />
<SolidColorBrush x:Key="CaptionCloseButtonHoverBackground" Color="#FFE81123" /> <SolidColorBrush x:Key="CaptionCloseButtonHoverBackground" Color="#FFE81123" />
<SolidColorBrush x:Key="CaptionCloseButtonPressBackground" Color="#FFB5394B" /> <SolidColorBrush x:Key="CaptionCloseButtonPressBackground" Color="#FFB5394B" />
<SolidColorBrush x:Key="CaptionBackground" Color="#FFDADADA" /> <SolidColorBrush x:Key="CaptionBackground" Color="#BBDADADA" />
<Style x:Key="CaptionButtonBaseStyle" TargetType="Button"> <Style x:Key="CaptionButtonBaseStyle" TargetType="Button">
<Setter Property="Focusable" Value="False" /> <Setter Property="Focusable" Value="False" />

View File

@@ -69,10 +69,9 @@ namespace QuickLook
private Icon GetTrayIconByDPI() private Icon GetTrayIconByDPI()
{ {
var isWin10 = Environment.OSVersion.Version >= new Version(10, 0);
var scale = DpiHelper.GetCurrentScaleFactor().Vertical; var scale = DpiHelper.GetCurrentScaleFactor().Vertical;
if (isWin10) if (App.IsWin10)
return scale > 1 ? Resources.app_white : Resources.app_white_16; return scale > 1 ? Resources.app_white : Resources.app_white_16;
return scale > 1 ? Resources.app : Resources.app_16; return scale > 1 ? Resources.app : Resources.app_16;
} }

View File

@@ -1,4 +1,4 @@
<controls:MainWindowBase <Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -13,9 +13,10 @@
MinWidth="400" MinHeight="200" MinWidth="400" MinHeight="200"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
Focusable="False" Focusable="False"
Background="{DynamicResource CaptionBackground}" BorderBrush="{DynamicResource CaptionBackground}"
Background="{DynamicResource MainWindowBackground}"
ShowActivated="False" ShowInTaskbar="False"> ShowActivated="False" ShowInTaskbar="False">
<controls:MainWindowBase.Resources> <Window.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/MainWindowStyles.xaml" /> <ResourceDictionary Source="Styles/MainWindowStyles.xaml" />
@@ -25,165 +26,164 @@
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" /> <converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</ResourceDictionary> </ResourceDictionary>
</controls:MainWindowBase.Resources> </Window.Resources>
<WindowChrome.WindowChrome> <WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" CornerRadius="0" GlassFrameThickness="0,0,0,1" <WindowChrome CaptionHeight="{StaticResource MainWindowCaptionHeight}" CornerRadius="0"
ResizeBorderThickness="{Binding ElementName=mainWindow, Path=WindowState, Converter={StaticResource WindowStateNormalToThicknessConverter}, ConverterParameter={StaticResource MainWindowResizeThickness}}" GlassFrameThickness=" 1"
ResizeBorderThickness="{StaticResource MainWindowResizeThickness}"
UseAeroCaptionButtons="False" /> UseAeroCaptionButtons="False" />
</WindowChrome.WindowChrome> </WindowChrome.WindowChrome>
<controls:MainWindowBase.Style> <Window.Style>
<Style TargetType="controls:MainWindowBase"> <Style TargetType="Window">
<Setter Property="BorderThickness" Value="{StaticResource MainWindowShadowMarginThickness}" />
<Setter Property="Foreground" Value="{DynamicResource WindowTextForeground}" /> <Setter Property="Foreground" Value="{DynamicResource WindowTextForeground}" />
</Style> </Style>
</controls:MainWindowBase.Style> </Window.Style>
<Grid Background="{DynamicResource CaptionBackground}" <Grid x:Name="windowFrameContainer"
Margin="{Binding ElementName=mainWindow,Path=WindowState,Converter={StaticResource WindowStateNormalToThicknessConverter},ConverterParameter={StaticResource MainWindowShadowMarginThickness}}"> Margin="{Binding ElementName=mainWindow, Path=WindowState, Converter={StaticResource WindowStateMaximizedToThicknessConverter}, ConverterParameter={StaticResource MainWindowResizeThickness}}">
<Grid x:Name="windowFrameContainer" <Grid x:Name="viewerRootContainer" ZIndex="190">
Margin="{Binding ElementName=mainWindow, Path=WindowState, Converter={StaticResource WindowStateMaximizedToThicknessConverter}, ConverterParameter={StaticResource MainWindowResizeThickness}}"> <Grid x:Name="windowCaptionContainer" Height="{StaticResource MainWindowCaptionHeight}"
<Grid x:Name="viewerRootContainer" ZIndex="190"> VerticalAlignment="Top"
<Grid x:Name="windowCaptionContainer" Height="{StaticResource MainWindowCaptionHeight}" ZIndex="100">
VerticalAlignment="Top" <Grid.Resources>
ZIndex="100"> <Storyboard x:Key="ShowCaptionContainerStoryboard" Completed="AutoHideCaptionContainer">
<Grid.Resources> <DoubleAnimation
<Storyboard x:Key="ShowCaptionContainerStoryboard" Completed="AutoHideCaptionContainer"> Storyboard.Target="{Binding Source={x:Reference windowCaptionContainer}}"
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.05" />
Storyboard.Target="{Binding Source={x:Reference windowCaptionContainer}}" </Storyboard>
Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.05" /> <Storyboard x:Key="HideCaptionContainerStoryboard">
</Storyboard> <DoubleAnimationUsingKeyFrames
<Storyboard x:Key="HideCaptionContainerStoryboard"> Storyboard.Target="{Binding Source={x:Reference windowCaptionContainer}}"
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity">
Storyboard.Target="{Binding Source={x:Reference windowCaptionContainer}}" <DoubleAnimationUsingKeyFrames.KeyFrames>
Storyboard.TargetProperty="Opacity"> <LinearDoubleKeyFrame Value="1" KeyTime="0:0:0" />
<DoubleAnimationUsingKeyFrames.KeyFrames> <LinearDoubleKeyFrame Value="1" KeyTime="0:0:1" />
<LinearDoubleKeyFrame Value="1" KeyTime="0:0:0" /> <LinearDoubleKeyFrame Value="0" KeyTime="0:0:1.05" />
<LinearDoubleKeyFrame Value="1" KeyTime="0:0:1" /> </DoubleAnimationUsingKeyFrames.KeyFrames>
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:1.05" /> </DoubleAnimationUsingKeyFrames>
</DoubleAnimationUsingKeyFrames.KeyFrames> </Storyboard>
</DoubleAnimationUsingKeyFrames> </Grid.Resources>
</Storyboard> <glassLayer:GlassLayer OverlayColor="{DynamicResource CaptionBackground}"
</Grid.Resources> BlurredElement="{Binding ElementName=containerPanel}"
<glassLayer:GlassLayer OverlayColor="{DynamicResource CaptionBackground}" ColorOverlayVisibility="{Binding ContextObject.TitlebarColourVisibility, ElementName=mainWindow, Converter={StaticResource BooleanToVisibilityConverter}}"
BlurredElement="{Binding ElementName=containerPanel}" GlassVisibility="{Binding ContextObject.TitlebarBlurVisibility, ElementName=mainWindow, Converter={StaticResource BooleanToVisibilityConverter}}"
ColorOverlayVisibility="{Binding ContextObject.TitlebarColourVisibility, ElementName=mainWindow, Converter={StaticResource BooleanToVisibilityConverter}}" NoiseVisibility="Visible" />
GlassVisibility="{Binding ContextObject.TitlebarBlurVisibility, ElementName=mainWindow, Converter={StaticResource BooleanToVisibilityConverter}}" <DockPanel>
NoiseVisibility="Visible" /> <DockPanel.Effect>
<DockPanel> <DropShadowEffect ShadowDepth="0" BlurRadius="2" Opacity="0.7" Color="#B2FFFFFF" />
<DockPanel.Effect> </DockPanel.Effect>
<DropShadowEffect ShadowDepth="0" BlurRadius="2" Opacity="0.7" Color="#B2FFFFFF" /> <Button DockPanel.Dock="Right" x:Name="buttonCloseWindow"
</DockPanel.Effect> Style="{StaticResource CaptionCloseButtonStyle}" Content="&#xE894;" />
<Button DockPanel.Dock="Right" x:Name="buttonCloseWindow" <Button DockPanel.Dock="Right" x:Name="buttonWindowStatus"
Style="{StaticResource CaptionCloseButtonStyle}" Content="&#xE894;" /> Visibility="{Binding ContextObject.CanResize, ElementName=mainWindow, Converter={StaticResource BooleanToVisibilityConverter}}">
<Button DockPanel.Dock="Right" x:Name="buttonWindowStatus" <Button.Style>
Visibility="{Binding ContextObject.CanResize, ElementName=mainWindow, Converter={StaticResource BooleanToVisibilityConverter}}"> <Style TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}">
<Button.Style> <Setter Property="Content" Value="&#xE740;" />
<Style TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}"> <Style.Triggers>
<Setter Property="Content" Value="&#xE740;" /> <DataTrigger Binding="{Binding WindowState, ElementName=mainWindow}"
<Style.Triggers> Value="Maximized">
<DataTrigger Binding="{Binding WindowState, ElementName=mainWindow}" <Setter Property="Content" Value="&#xE73F;" />
Value="Maximized"> </DataTrigger>
<Setter Property="Content" Value="&#xE73F;" /> </Style.Triggers>
</DataTrigger> </Style>
</Style.Triggers> </Button.Style>
</Style> </Button>
</Button.Style> <Button x:Name="buttonOpenWith" DockPanel.Dock="Right"
</Button> Style="{StaticResource CaptionTextButtonStyle}">
<Button x:Name="buttonOpenWith" DockPanel.Dock="Right" <Button.Content>
Style="{StaticResource CaptionTextButtonStyle}"> <TextBlock x:Name="buttonOpenWithText" VerticalAlignment="Center">
<Button.Content> Open with <Bold>AppName</Bold>
<TextBlock x:Name="buttonOpenWithText" VerticalAlignment="Center"> </TextBlock>
Open with <Bold>AppName</Bold> </Button.Content>
</TextBlock> </Button>
</Button.Content> <Button DockPanel.Dock="Left" x:Name="buttonTop" Tag="Auto">
</Button> <Button.Resources>
<Button DockPanel.Dock="Left" x:Name="buttonTop" Tag="Auto"> <Grid x:Key="ContentTop">
<Button.Resources> <TextBlock>&#xE898;</TextBlock>
<Grid x:Key="ContentTop"> <TextBlock>&#xE872;</TextBlock>
<TextBlock>&#xE898;</TextBlock> </Grid>
<TextBlock>&#xE872;</TextBlock> </Button.Resources>
</Grid> <Button.Style>
</Button.Resources> <Style TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}">
<Button.Style> <Setter Property="Content" Value="&#xE898;" />
<Style TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}"> <Style.Triggers>
<Setter Property="Content" Value="&#xE898;" /> <Trigger Property="Tag" Value="Auto">
<Style.Triggers> <Setter Property="Content" Value="&#xE898;" />
<Trigger Property="Tag" Value="Auto"> </Trigger>
<Setter Property="Content" Value="&#xE898;" /> <Trigger Property="Tag" Value="Top">
</Trigger> <Setter Property="Content" Value="{StaticResource ContentTop}" />
<Trigger Property="Tag" Value="Top"> </Trigger>
<Setter Property="Content" Value="{StaticResource ContentTop}" /> </Style.Triggers>
</Trigger> </Style>
</Style.Triggers> </Button.Style>
</Style> </Button>
</Button.Style> <Button DockPanel.Dock="Left" x:Name="buttonPin" Tag="Auto">
</Button> <Button.Resources>
<Button DockPanel.Dock="Left" x:Name="buttonPin" Tag="Auto"> <Grid x:Key="ContentPin">
<Button.Resources> <TextBlock>&#xE840;</TextBlock>
<Grid x:Key="ContentPin"> <TextBlock>&#xE842;</TextBlock>
<TextBlock>&#xE840;</TextBlock> </Grid>
<TextBlock>&#xE842;</TextBlock> </Button.Resources>
</Grid> <Button.Style>
</Button.Resources> <Style TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}">
<Button.Style> <Setter Property="Content" Value="&#xE840;" />
<Style TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}"> <Style.Triggers>
<Setter Property="Content" Value="&#xE840;" /> <Trigger Property="Tag" Value="Auto">
<Style.Triggers> <Setter Property="Content" Value="&#xE840;" />
<Trigger Property="Tag" Value="Auto"> </Trigger>
<Setter Property="Content" Value="&#xE840;" /> <Trigger Property="Tag" Value="Pin">
</Trigger> <Setter Property="Content" Value="{StaticResource ContentPin}" />
<Trigger Property="Tag" Value="Pin"> </Trigger>
<Setter Property="Content" Value="{StaticResource ContentPin}" /> </Style.Triggers>
</Trigger> </Style>
</Style.Triggers> </Button.Style>
</Style> </Button>
</Button.Style> <Button DockPanel.Dock="Left" x:Name="buttonShare" Style="{StaticResource CaptionButtonStyle}"
</Button> Content="&#xE72D;" />
<Button DockPanel.Dock="Left" x:Name="buttonShare" Style="{StaticResource CaptionButtonStyle}" <Grid x:Name="titleArea" Background="Transparent">
Content="&#xE72D;" /> <TextBlock Text="{Binding ContextObject.Title, ElementName=mainWindow}" FontSize="12"
<Grid x:Name="titleArea" Background="Transparent"> HorizontalAlignment="Left" TextTrimming="CharacterEllipsis"
<TextBlock Text="{Binding ContextObject.Title, ElementName=mainWindow}" FontSize="12" VerticalAlignment="Center" Margin="5,0" />
HorizontalAlignment="Left" TextTrimming="CharacterEllipsis" </Grid>
VerticalAlignment="Center" Margin="5,0" />
</Grid>
</DockPanel>
</Grid>
<DockPanel x:Name="containerPanel" Background="{DynamicResource MainWindowBackground}" ZIndex="80">
<Grid DockPanel.Dock="Top" Height="{StaticResource MainWindowCaptionHeight}"
Visibility="{Binding ContextObject.TitlebarOverlap, ElementName=mainWindow, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" />
<ContentControl x:Name="container"
Foreground="{DynamicResource WindowTextForeground}"
Content="{Binding ContextObject.ViewerContent, ElementName=mainWindow}" />
<DockPanel.Style>
<Style TargetType="{x:Type DockPanel}">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger
Binding="{Binding ContextObject.IsBusy, ElementName=mainWindow}"
Value="True">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
</DockPanel> </DockPanel>
</Grid> </Grid>
<Grid x:Name="busyIndicatorLayer" Background="{DynamicResource MainWindowBackground}" ZIndex="200"> <DockPanel x:Name="containerPanel" ZIndex="80">
<Grid.Style> <Grid DockPanel.Dock="Top" Height="{StaticResource MainWindowCaptionHeight}"
<Style TargetType="{x:Type Grid}"> Visibility="{Binding ContextObject.TitlebarOverlap, ElementName=mainWindow, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" />
<Setter Property="Visibility" Value="Collapsed" /> <ContentControl x:Name="container"
Foreground="{DynamicResource WindowTextForeground}"
Content="{Binding ContextObject.ViewerContent, ElementName=mainWindow}" />
<DockPanel.Style>
<Style TargetType="{x:Type DockPanel}">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers> <Style.Triggers>
<DataTrigger <DataTrigger
Binding="{Binding ContextObject.IsBusy, ElementName=mainWindow}" Binding="{Binding ContextObject.IsBusy, ElementName=mainWindow}"
Value="True"> Value="True">
<Setter Property="Visibility" Value="Visible" /> <Setter Property="Visibility" Value="Hidden" />
</DataTrigger> </DataTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</Grid.Style> </DockPanel.Style>
<busyDecorator:BusyDecorator x:Name="busyDecorator" </DockPanel>
IsBusyIndicatorShowing="True" </Grid>
VerticalAlignment="Center" <Grid x:Name="busyIndicatorLayer" ZIndex="200">
HorizontalAlignment="Center" /> <Grid.Style>
</Grid> <Style TargetType="{x:Type Grid}">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger
Binding="{Binding ContextObject.IsBusy, ElementName=mainWindow}"
Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<busyDecorator:BusyDecorator x:Name="busyDecorator"
IsBusyIndicatorShowing="True"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Grid> </Grid>
</Grid> </Grid>
</controls:MainWindowBase> </Window>

View File

@@ -20,7 +20,6 @@ using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using QuickLook.Controls;
using QuickLook.Helpers; using QuickLook.Helpers;
using QuickLook.Plugin; using QuickLook.Plugin;
@@ -29,12 +28,11 @@ namespace QuickLook
/// <summary> /// <summary>
/// Interaction logic for ViewerWindow.xaml /// Interaction logic for ViewerWindow.xaml
/// </summary> /// </summary>
public partial class ViewerWindow : MainWindowBase public partial class ViewerWindow : Window
{ {
private Size _customWindowSize = Size.Empty; private Size _customWindowSize = Size.Empty;
private bool _ignoreNextWindowSizeChange; private bool _ignoreNextWindowSizeChange;
private string _path = string.Empty; private string _path = string.Empty;
private bool _restoreForDragMove;
internal ViewerWindow() internal ViewerWindow()
{ {
@@ -49,10 +47,6 @@ namespace QuickLook
StateChanged += (sender, e) => _ignoreNextWindowSizeChange = true; StateChanged += (sender, e) => _ignoreNextWindowSizeChange = true;
windowCaptionContainer.MouseLeftButtonDown += WindowDragMoveStart;
windowCaptionContainer.MouseMove += WindowDragMoving;
windowCaptionContainer.MouseLeftButtonUp += WindowDragMoveEnd;
windowFrameContainer.PreviewMouseMove += ShowWindowCaptionContainer; windowFrameContainer.PreviewMouseMove += ShowWindowCaptionContainer;
buttonTop.Click += (sender, e) => buttonTop.Click += (sender, e) =>
@@ -93,6 +87,16 @@ namespace QuickLook
buttonShare.Click += Share; buttonShare.Click += Share;
} }
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (SystemParameters.IsGlassEnabled && App.IsWin10)
WindowHelper.EnableBlur(this);
else
Background = (Brush) FindResource("MainWindowBackgroundNoTransparent");
}
private void SaveWindowSizeOnSizeChanged(object sender, SizeChangedEventArgs e) private void SaveWindowSizeOnSizeChanged(object sender, SizeChangedEventArgs e)
{ {
// first shown? // first shown?
@@ -132,56 +136,5 @@ namespace QuickLook
hide.Begin(); hide.Begin();
} }
private void WindowDragMoveEnd(object sender, MouseButtonEventArgs e)
{
_restoreForDragMove = false;
}
private void WindowDragMoving(object sender, MouseEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed)
return;
if (!_restoreForDragMove)
return;
_restoreForDragMove = false;
var scale = DpiHelper.GetCurrentScaleFactor();
var point = PointToScreen(e.MouseDevice.GetPosition(this));
point.X /= scale.Horizontal;
point.Y /= scale.Vertical;
var monitor = WindowHelper.GetCurrentWindowRect();
var precentLeft = (point.X - monitor.Left) / monitor.Width;
var precentTop = (point.Y - monitor.Top) / monitor.Height;
Left = point.X - RestoreBounds.Width * precentLeft;
Top = point.Y - RestoreBounds.Height * precentTop;
WindowState = WindowState.Normal;
if (e.LeftButton == MouseButtonState.Pressed)
DragMove();
}
private void WindowDragMoveStart(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
if (ResizeMode != ResizeMode.CanResize &&
ResizeMode != ResizeMode.CanResizeWithGrip)
return;
WindowState = WindowState == WindowState.Maximized
? WindowState.Normal
: WindowState.Maximized;
}
else
{
_restoreForDragMove = WindowState == WindowState.Maximized;
if (e.LeftButton == MouseButtonState.Pressed)
DragMove();
}
}
} }
} }