mirror of
https://github.com/VitalickS/BrightSharp.Toolkit.git
synced 2026-03-21 02:21:15 +00:00
Menu popup position fix;
move minmaxsize logic from behavior to avoid use behavior in MarkupExtensionProperties; WindowHeaderBrush improve for DevLab colors
This commit is contained in:
78
BrightSharp/Behaviors/MinMaxSize_Logic.cs
Normal file
78
BrightSharp/Behaviors/MinMaxSize_Logic.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using BrightSharp.Interop;
|
||||
using BrightSharp.Interop.Constants;
|
||||
using BrightSharp.Interop.Structures;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace BrightSharp.Behaviors
|
||||
{
|
||||
internal class MinMaxSize_Logic
|
||||
{
|
||||
private HwndSource hwndSource;
|
||||
private Window associatedObject;
|
||||
public MinMaxSize_Logic(Window associatedObject)
|
||||
{
|
||||
this.associatedObject = associatedObject;
|
||||
}
|
||||
public void OnAttached()
|
||||
{
|
||||
this.associatedObject.SourceInitialized += AssociatedObject_SourceInitialized;
|
||||
}
|
||||
|
||||
private void AssociatedObject_SourceInitialized(object sender, EventArgs e)
|
||||
{
|
||||
IntPtr handle = new WindowInteropHelper(this.associatedObject).Handle;
|
||||
hwndSource = HwndSource.FromHwnd(handle);
|
||||
hwndSource.AddHook(WindowProc);
|
||||
}
|
||||
|
||||
public void OnDetaching()
|
||||
{
|
||||
this.associatedObject.SourceInitialized -= AssociatedObject_SourceInitialized;
|
||||
if (hwndSource != null)
|
||||
{
|
||||
hwndSource.RemoveHook(WindowProc);
|
||||
hwndSource.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case 0x0024:
|
||||
WmGetMinMaxInfo(hwnd, lParam);
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
return (IntPtr)0;
|
||||
}
|
||||
|
||||
private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
|
||||
{
|
||||
var mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
|
||||
|
||||
// Adjust the maximized size and position to fit the work area of the correct monitor
|
||||
IntPtr monitor = NativeMethods.MonitorFromWindow(hwnd, (int)MonitorFromWindowFlags.MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
if (monitor != IntPtr.Zero)
|
||||
{
|
||||
var monitorInfo = new MONITORINFO();
|
||||
NativeMethods.GetMonitorInfo(monitor, monitorInfo);
|
||||
RECT rcWorkArea = monitorInfo.rcWork;
|
||||
RECT rcMonitorArea = monitorInfo.rcMonitor;
|
||||
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left);
|
||||
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);
|
||||
mmi.ptMinTrackSize.x = (int)associatedObject.MinWidth;
|
||||
mmi.ptMinTrackSize.y = (int)associatedObject.MinHeight;
|
||||
}
|
||||
|
||||
Marshal.StructureToPtr(mmi, lParam, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,4 @@
|
||||
using BrightSharp.Interop;
|
||||
using BrightSharp.Interop.Constants;
|
||||
using BrightSharp.Interop.Structures;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Interactivity;
|
||||
using System.Windows.Interop;
|
||||
|
||||
@@ -12,67 +7,19 @@ namespace BrightSharp.Behaviors
|
||||
public class WindowMinMaxSizeBehavior : Behavior<Window>
|
||||
{
|
||||
private HwndSource hwndSource;
|
||||
|
||||
private MinMaxSize_Logic logic;
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
|
||||
AssociatedObject.SourceInitialized += AssociatedObject_SourceInitialized;
|
||||
logic = new MinMaxSize_Logic(AssociatedObject);
|
||||
logic.OnAttached();
|
||||
}
|
||||
|
||||
private void AssociatedObject_SourceInitialized(object sender, EventArgs e)
|
||||
{
|
||||
IntPtr handle = (new WindowInteropHelper(AssociatedObject)).Handle;
|
||||
hwndSource = HwndSource.FromHwnd(handle);
|
||||
hwndSource.AddHook(WindowProc);
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
AssociatedObject.SourceInitialized -= AssociatedObject_SourceInitialized;
|
||||
if (hwndSource != null)
|
||||
{
|
||||
hwndSource.RemoveHook(WindowProc);
|
||||
hwndSource.Dispose();
|
||||
}
|
||||
logic.OnDetaching();
|
||||
base.OnDetaching();
|
||||
}
|
||||
|
||||
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case 0x0024:
|
||||
WmGetMinMaxInfo(hwnd, lParam);
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
return (IntPtr)0;
|
||||
}
|
||||
|
||||
private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
|
||||
{
|
||||
var mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
|
||||
|
||||
// Adjust the maximized size and position to fit the work area of the correct monitor
|
||||
IntPtr monitor = NativeMethods.MonitorFromWindow(hwnd, (int)MonitorFromWindowFlags.MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
if (monitor != IntPtr.Zero)
|
||||
{
|
||||
var monitorInfo = new MONITORINFO();
|
||||
NativeMethods.GetMonitorInfo(monitor, monitorInfo);
|
||||
RECT rcWorkArea = monitorInfo.rcWork;
|
||||
RECT rcMonitorArea = monitorInfo.rcMonitor;
|
||||
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left);
|
||||
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);
|
||||
mmi.ptMinTrackSize.x = (int)AssociatedObject.MinWidth;
|
||||
mmi.ptMinTrackSize.y = (int)AssociatedObject.MinHeight;
|
||||
}
|
||||
|
||||
Marshal.StructureToPtr(mmi, lParam, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,9 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>G:\repositories\Tps.Next\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\System.Windows.Interactivity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -51,8 +53,9 @@
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Behaviors\FiterGridTextBoxBehavior.cs" />
|
||||
<Compile Include="Behaviors\FilterDefaultViewTextBoxBehavior.cs" />
|
||||
<Compile Include="Behaviors\SelectAllTextOnFocusBehavior.cs" />
|
||||
<Compile Include="Behaviors\MinMaxSize_Logic.cs" />
|
||||
<Compile Include="Behaviors\WindowMinMaxSizeBehavior.cs" />
|
||||
<Compile Include="Commands\AsyncCommand.cs" />
|
||||
<Compile Include="Commands\RelayCommand.cs" />
|
||||
@@ -93,6 +96,7 @@
|
||||
</Page>
|
||||
<Compile Include="Converters\ThicknessConverter.cs" />
|
||||
<Compile Include="Extensions\MarkupExtensionProperties.cs" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Themes\Theme.Static.cs">
|
||||
<DependentUpon>Theme.Static.xaml</DependentUpon>
|
||||
</None>
|
||||
@@ -170,7 +174,9 @@
|
||||
<Resource Include="Themes\icons\paste.png" />
|
||||
<Resource Include="Themes\icons\undo.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="Docking\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -3,7 +3,6 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interactivity;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace BrightSharp.Extensions
|
||||
@@ -157,12 +156,11 @@ namespace BrightSharp.Extensions
|
||||
if (window == null) return;
|
||||
if ((bool)e.NewValue)
|
||||
{
|
||||
Interaction.GetBehaviors(window).Add(new WindowMinMaxSizeBehavior());
|
||||
new MinMaxSize_Logic(window).OnAttached();
|
||||
}
|
||||
else
|
||||
{
|
||||
var beh = Interaction.GetBehaviors(window).OfType<WindowMinMaxSizeBehavior>().FirstOrDefault();
|
||||
if (beh != null) Interaction.GetBehaviors(window).Remove(beh);
|
||||
// Not supported yet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,16 +239,15 @@
|
||||
<SolidColorBrush x:Key="WindowHeaderInactiveBackgroundBrush" Color="#8888" />
|
||||
|
||||
<LinearGradientBrush x:Key="GradientWindowBackgroundBrush" EndPoint="1,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFD0D8EC" Offset="0"/>
|
||||
|
||||
<GradientStop Color="White" Offset="1"/>
|
||||
<GradientStop Color="#FFE9F2FF" Offset="0.766"/>
|
||||
<GradientStop Color="#FFE2E8F8" Offset="0.238"/>
|
||||
<GradientStop Color="#FFD0D8EC" Offset="0"/>
|
||||
</LinearGradientBrush>
|
||||
|
||||
<LinearGradientBrush x:Key="WindowHeaderBrush" EndPoint="0,1">
|
||||
<GradientStop Color="#F4F4FF" />
|
||||
<GradientStop Color="#FFB5BBC6" Offset="0.2" />
|
||||
<GradientStop Color="#FFE7E7FC" Offset="0.8" />
|
||||
<GradientStop Color="#FFD4EAFF" Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
|
||||
|
||||
@@ -36,5 +36,7 @@ namespace BrightSharp.Themes
|
||||
var window = Window.GetWindow((DependencyObject)sender);
|
||||
window.WindowState = WindowState.Minimized;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2491,6 +2491,7 @@
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1,0,1,1" />
|
||||
<Setter Property="Padding" Value="2" />
|
||||
<Setter Property="bs:MarkupExtensionProperties.HeaderPadding" Value="5,2" />
|
||||
<Setter Property="bs:MarkupExtensionProperties.SpecialBrush" Value="{DynamicResource LightBrush}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
@@ -2506,7 +2507,7 @@
|
||||
BorderBrush="{DynamicResource NormalBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="2,2,0,0" VerticalAlignment="Top" >
|
||||
<ContentPresenter
|
||||
<ContentPresenter Margin="{TemplateBinding bs:MarkupExtensionProperties.HeaderPadding}"
|
||||
ContentSource="Header"
|
||||
RecognizesAccessKey="True" />
|
||||
</Border>
|
||||
@@ -3016,13 +3017,11 @@
|
||||
<Border x:Name="Border">
|
||||
<Grid>
|
||||
<Border x:Name="MenuBackground" IsHitTestVisible="False" Background="{DynamicResource TopLevelMenuBackgroundHover}" Opacity="0" />
|
||||
<ContentPresenter
|
||||
Margin="6,3,6,3" TextBlock.Foreground="{DynamicResource MainMenuForegroundBrush}"
|
||||
ContentSource="Header"
|
||||
RecognizesAccessKey="True" />
|
||||
<Popup
|
||||
x:Name="Popup"
|
||||
Placement="Bottom"
|
||||
Placement="Relative"
|
||||
VerticalOffset="{Binding ElementName=Border, Path=ActualHeight}"
|
||||
HorizontalOffset="{Binding ElementName=SubmenuBorder, Path=ActualWidth}"
|
||||
IsOpen="{TemplateBinding IsSubmenuOpen}"
|
||||
AllowsTransparency="True"
|
||||
Focusable="False"
|
||||
@@ -3037,6 +3036,11 @@
|
||||
KeyboardNavigation.DirectionalNavigation="Cycle" />
|
||||
</Border>
|
||||
</Popup>
|
||||
<ContentPresenter
|
||||
Margin="6,3,6,3" TextBlock.Foreground="{DynamicResource MainMenuForegroundBrush}"
|
||||
ContentSource="Header"
|
||||
RecognizesAccessKey="True" />
|
||||
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
@@ -3779,7 +3783,7 @@
|
||||
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorder}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Padding" Value="1"/>
|
||||
<Setter Property="Padding" Value="4"/>
|
||||
<Setter Property="AllowDrop" Value="true"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
|
||||
@@ -4711,7 +4715,7 @@
|
||||
<Setter Property="bs:MarkupExtensionProperties.CornerRadius" Value="0" />
|
||||
<Setter Property="Background" Value="{DynamicResource WindowBackgroundBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource SolidBorderBrush}" />
|
||||
<Setter Property="Padding" Value="2,1" />
|
||||
<Setter Property="Padding" Value="4" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource OnWindowForegroundBrush}" />
|
||||
<Setter Property="ContextMenu" Value="{DynamicResource DecoTextBoxContextMenu}" />
|
||||
<Setter Property="CaretBrush" Value="{DynamicResource DisabledForegroundBrush}" />
|
||||
@@ -5631,14 +5635,14 @@
|
||||
<Style x:Key="BrightSharpWindowStyle" TargetType="{x:Type Window}">
|
||||
<Setter Property="WindowStyle" Value="None" />
|
||||
<Setter Property="bs:MarkupExtensionProperties.SpecialBrush" Value="{DynamicResource WindowInnerBorderBrush}"/>
|
||||
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource WindowBorderBrush}">
|
||||
</Setter>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource WindowBorderBrush}" />
|
||||
<Setter Property="bs:MarkupExtensionProperties.UseMinMaxSizeBehavior" Value="True" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Icon" Value="icons/app.png" />
|
||||
<Setter Property="UseLayoutRounding" Value="True" />
|
||||
<Setter Property="WindowChrome.WindowChrome">
|
||||
<Setter.Value>
|
||||
<WindowChrome CaptionHeight="30" ResizeBorderThickness="4" GlassFrameThickness="1" UseAeroCaptionButtons="False" />
|
||||
<WindowChrome CaptionHeight="30" ResizeBorderThickness="4" CornerRadius="0" GlassFrameThickness="0" UseAeroCaptionButtons="False" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Foreground" Value="{DynamicResource OnWindowForegroundBrush}"/>
|
||||
@@ -5663,16 +5667,15 @@
|
||||
<GradientStop Color="Transparent" Offset="0.0"/>
|
||||
</LinearGradientBrush>
|
||||
<LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
|
||||
<GradientStop Color="#FFE8E8E8" Offset="0.0"/>
|
||||
<GradientStop Color="WhiteSmoke" Offset="0.0"/>
|
||||
</LinearGradientBrush>
|
||||
</StackPanel.Resources>
|
||||
<Button VerticalAlignment="Top" Name="PART_MinimizeButton" Click="minimizeButton_Click" Focusable="False" WindowChrome.IsHitTestVisibleInChrome="True" Content="0" bs:MarkupExtensionProperties.CornerRadius="0" BorderBrush="Transparent" FontFamily="Webdings" />
|
||||
<Button VerticalAlignment="Top" Name="PART_MaximizeButton" Click="maximizeButton_Click" Focusable="False" WindowChrome.IsHitTestVisibleInChrome="True" Content="1" bs:MarkupExtensionProperties.CornerRadius="0" BorderBrush="Transparent" FontFamily="Webdings" />
|
||||
<Button Padding="10,6" VerticalAlignment="Top" Name="PART_MinimizeButton" Click="minimizeButton_Click" Focusable="False" WindowChrome.IsHitTestVisibleInChrome="True" Content="0" bs:MarkupExtensionProperties.CornerRadius="0" BorderBrush="Transparent" FontFamily="Webdings" />
|
||||
<Button Padding="10,6" VerticalAlignment="Top" Name="PART_MaximizeButton" Click="maximizeButton_Click" Focusable="False" WindowChrome.IsHitTestVisibleInChrome="True" Content="1" bs:MarkupExtensionProperties.CornerRadius="0" BorderBrush="Transparent" FontFamily="Webdings" />
|
||||
<Button Padding="10,6" Name="PART_CloseButton" Click="closeButton_Click" Focusable="False" WindowChrome.IsHitTestVisibleInChrome="True" Content="r" bs:MarkupExtensionProperties.CornerRadius="0" BorderBrush="Transparent" FontFamily="Webdings">
|
||||
<Button.Background>
|
||||
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFDEC3C3" Offset="0"/>
|
||||
<GradientStop Color="#FFCDA2A2" Offset="1"/>
|
||||
<GradientStop Color="Transparent" Offset="0.0"/>
|
||||
</LinearGradientBrush>
|
||||
</Button.Background>
|
||||
<Button.Resources>
|
||||
@@ -5683,7 +5686,7 @@
|
||||
</Button.Resources>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<Label Padding="0,3" Foreground="White" HorizontalContentAlignment="{TemplateBinding bs:MarkupExtensionProperties.HeaderHorizontalAlignment}" Content="{TemplateBinding bs:MarkupExtensionProperties.Header}" FontSize="14">
|
||||
<Label Padding="0,5" Foreground="White" HorizontalContentAlignment="{TemplateBinding bs:MarkupExtensionProperties.HeaderHorizontalAlignment}" Content="{TemplateBinding bs:MarkupExtensionProperties.Header}" FontSize="14">
|
||||
<Label.Effect>
|
||||
<DropShadowEffect BlurRadius="2" ShadowDepth="1" Color="Black" />
|
||||
</Label.Effect>
|
||||
@@ -5707,7 +5710,7 @@
|
||||
<Setter TargetName="InnerBorder" Property="BorderThickness" Value="0" />
|
||||
<Setter Property="WindowChrome.WindowChrome">
|
||||
<Setter.Value>
|
||||
<WindowChrome CaptionHeight="30" ResizeBorderThickness="0" GlassFrameThickness="1" UseAeroCaptionButtons="False" />
|
||||
<WindowChrome CaptionHeight="30" ResizeBorderThickness="0" GlassFrameThickness="0" UseAeroCaptionButtons="False" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter TargetName="ButtonPanel" Property="Margin" Value="-1" />
|
||||
|
||||
4
BrightSharp/packages.config
Normal file
4
BrightSharp/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="System.Windows.Interactivity.WPF" version="2.0.20525" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user