-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// This file contains two methods taken from MahApps.Metro to be able to remove the NuGet dependency. | ||
|
||
// Taken from | ||
// MahApps.Metro/src/MahApps.Metro/Controls/WinApiHelper.cs | ||
// MahApps.Metro/src/MahApps.Metro/Controls/TreeHelper.cs | ||
|
||
// Original license header: | ||
// | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using ControlzEx.Standard; | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Interop; | ||
using System.Windows.Media; | ||
|
||
namespace StageManager.Native | ||
{ | ||
public static class VisualHelper | ||
{ | ||
/// <summary> | ||
/// Get the working area size of the monitor from where the visual stays. | ||
/// </summary> | ||
/// <param name="visual">The visual element to get the monitor information.</param> | ||
/// <returns>The working area size of the monitor.</returns> | ||
public static Size GetMonitorWorkSize(this Visual visual) | ||
{ | ||
if (visual != null) | ||
{ | ||
var hwndSource = PresentationSource.FromVisual(visual) as HwndSource; | ||
if (hwndSource != null && !hwndSource.IsDisposed && hwndSource.RootVisual != null && hwndSource.Handle != IntPtr.Zero) | ||
{ | ||
IntPtr intPtr = NativeMethods.MonitorFromWindow(hwndSource.Handle, MonitorOptions.MONITOR_DEFAULTTONEAREST); | ||
if (intPtr != IntPtr.Zero) | ||
{ | ||
var monitorInfoW = NativeMethods.GetMonitorInfoW(intPtr); | ||
return new Size(monitorInfoW.rcWork.Width, monitorInfoW.rcWork.Height); | ||
} | ||
} | ||
} | ||
|
||
return default; | ||
} | ||
|
||
/// <summary> | ||
/// This method is an alternative to WPF's <see cref="VisualTreeHelper.GetParent"/> method, which also supports content elements. Keep in mind that for content element, this method falls back to the logical tree of the element! | ||
/// </summary> | ||
/// <param name="child">The item to be processed.</param> | ||
/// <returns>The submitted item's parent, if available. Otherwise null.</returns> | ||
public static DependencyObject? GetParentObject(this DependencyObject? child) | ||
{ | ||
if (child is null) | ||
return null; | ||
|
||
// handle content elements separately | ||
if (child is ContentElement contentElement) | ||
{ | ||
DependencyObject parent = ContentOperations.GetParent(contentElement); | ||
if (parent is not null) | ||
return parent; | ||
|
||
return contentElement is FrameworkContentElement fce ? fce.Parent : null; | ||
} | ||
|
||
var childParent = VisualTreeHelper.GetParent(child); | ||
if (childParent is not null) | ||
return childParent; | ||
|
||
// also try searching for parent in framework elements (such as DockPanel, etc) | ||
if (child is FrameworkElement frameworkElement) | ||
{ | ||
DependencyObject parent = frameworkElement.Parent; | ||
if (parent is not null) | ||
return parent; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net7.0-windows</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<UseWPF>true</UseWPF> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<ApplicationIcon>StageManager.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net7.0-windows</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<UseWPF>true</UseWPF> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<ApplicationIcon>StageManager.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Resource Include="StageManager.ico" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Resource Include="StageManager.ico" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AsyncAwaitBestPractices" Version="6.0.6" /> | ||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" /> | ||
<PackageReference Include="MahApps.Metro" Version="2.4.10" /> | ||
<PackageReference Include="SharpHook" Version="4.2.1" /> | ||
<PackageReference Include="WpfScreenHelper" Version="2.1.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AsyncAwaitBestPractices" Version="6.0.6" /> | ||
<PackageReference Include="ControlzEx" Version="4.4.0" /> | ||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" /> | ||
<PackageReference Include="SharpHook" Version="4.2.1" /> | ||
<PackageReference Include="WpfScreenHelper" Version="2.1.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |