Skip to content

Commit f1e585a

Browse files
committed
Refactor Tools
1 parent 734af67 commit f1e585a

25 files changed

+632
-379
lines changed

src/Shared/HandyControl_Shared/Tools/Extension/ColorExtension.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
namespace HandyControl.Tools.Extension;
66

77
/// <summary>
8-
/// 颜色扩展类
8+
/// Color extension class
99
/// </summary>
1010
public static class ColorExtension
1111
{
1212
/// <summary>
13-
/// 将颜色转换为10进制表示(rgb顺序颠倒)
13+
/// Convert color to decimal representation (rgb order is reversed)
1414
/// </summary>
1515
/// <param name="color"></param>
1616
/// <returns></returns>
1717
public static int ToInt32(this Color color) => color.R << 16 | color.G << 8 | color.B;
1818

1919
/// <summary>
20-
/// 将颜色转换为10进制表示(rgb顺序颠倒)
20+
/// Convert color to decimal representation (rgb order is reversed)
2121
/// </summary>
2222
/// <param name="color"></param>
2323
/// <returns></returns>

src/Shared/HandyControl_Shared/Tools/Extension/GeometryExtension.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace HandyControl.Tools.Extension;
88
public static class GeometryExtension
99
{
1010
/// <summary>
11-
/// 获取路径总长度
11+
/// Get the total length of the path
1212
/// </summary>
1313
/// <param name="geometry"></param>
1414
/// <returns></returns>
@@ -24,7 +24,7 @@ public static double GetTotalLength(this Geometry geometry)
2424
}
2525

2626
/// <summary>
27-
/// 获取路径总长度
27+
/// Get the total length of the path
2828
/// </summary>
2929
/// <param name="geometry"></param>
3030
/// <param name="size"></param>

src/Shared/HandyControl_Shared/Tools/Extension/UIElementExtension.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ namespace HandyControl.Tools.Extension;
66
public static class UIElementExtension
77
{
88
/// <summary>
9-
/// 显示元素
9+
/// Display element
1010
/// </summary>
1111
/// <param name="element"></param>
1212
public static void Show(this UIElement element) => element.Visibility = Visibility.Visible;
1313

1414
/// <summary>
15-
/// 显示元素
15+
/// Display element
1616
/// </summary>
1717
/// <param name="element"></param>
1818
/// <param name="show"></param>
1919
public static void Show(this UIElement element, bool show) => element.Visibility = show ? Visibility.Visible : Visibility.Collapsed;
2020

2121
/// <summary>
22-
/// 不现实元素,但保留空间
22+
/// Unrealistic elements, but reserve space
2323
/// </summary>
2424
/// <param name="element"></param>
2525
public static void Hide(this UIElement element) => element.Visibility = Visibility.Hidden;
2626

2727
/// <summary>
28-
/// 不显示元素,且不保留空间
28+
/// No elements are displayed, and no space is reserved
2929
/// </summary>
3030
/// <param name="element"></param>
3131
public static void Collapse(this UIElement element) => element.Visibility = Visibility.Collapsed;

src/Shared/HandyControl_Shared/Tools/Helper/ColorHelper.cs

-19
This file was deleted.

src/Shared/HandyControl_Shared/Tools/Helper/ConfigHelper.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@
66
#endif
77
using System.Windows;
88
using System.Windows.Markup;
9-
using System.Windows.Media.Animation;
109
using System.Windows.Navigation;
1110
using HandyControl.Data;
1211
using HandyControl.Properties.Langs;
13-
12+
using Timeline = System.Windows.Media.Animation.Timeline;
1413
namespace HandyControl.Tools;
1514

1615
public class ConfigHelper : INotifyPropertyChanged
1716
{
1817
private ConfigHelper()
1918
{
20-
19+
2120
}
2221

2322
public static ConfigHelper Instance = new Lazy<ConfigHelper>(() => new ConfigHelper()).Value;
2423

25-
private XmlLanguage _lang = XmlLanguage.GetLanguage("zh-cn");
24+
private XmlLanguage _lang = XmlLanguage.GetLanguage("en");
2625

2726
public XmlLanguage Lang
2827
{
@@ -42,6 +41,7 @@ public void SetLang(string lang)
4241
LangProvider.Culture = new CultureInfo(lang);
4342
Application.Current.Dispatcher.Thread.CurrentUICulture = new CultureInfo(lang);
4443
Lang = XmlLanguage.GetLanguage(lang);
44+
LocalizationManager.Instance.OnCultureChanged(new CultureInfo(lang));
4545
}
4646

4747
public void SetConfig(HandyControlConfig config)

src/Shared/HandyControl_Shared/Tools/Helper/DpiHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace HandyControl.Tools;
88

9-
internal static class DpiHelper
9+
public static class DpiHelper
1010
{
1111
private const double LogicalDpi = 96.0;
1212

src/Shared/HandyControl_Shared/Tools/Helper/FullScreenHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace HandyControl.Controls;
1212
/// 采用设置窗口位置和尺寸,确保盖住整个屏幕的方式来实现全屏
1313
/// 目前已知需要满足的条件是:窗口盖住整个屏幕、窗口没有WS_THICKFRAME样式、窗口不能有标题栏且最大化
1414
/// </summary>
15-
internal static class FullScreenHelper
15+
public static class FullScreenHelper
1616
{
1717
/// <summary>
1818
/// 用于记录窗口全屏前位置的附加属性

src/Shared/HandyControl_Shared/Tools/Helper/IconHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace HandyControl.Tools;
1212

1313
[SuppressMessage("ReSharper", "ArrangeRedundantParentheses")]
1414
[SuppressMessage("ReSharper", "IntVariableOverflowInUncheckedContext")]
15-
internal static class IconHelper
15+
public static class IconHelper
1616
{
1717
private static Size SmallIconSize;
1818

Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
using System;
2-
using System.Reflection;
3-
using System.Windows;
4-
using HandyControl.Data;
1+
using System.Windows;
52

63
namespace HandyControl.Tools;
74

85
/// <summary>
9-
/// 资源帮助类
6+
/// Resource help class
107
/// </summary>
118
public class ResourceHelper
129
{
1310
private static ResourceDictionary _theme;
1411

1512
/// <summary>
16-
/// 获取资源
13+
/// Get Resource
1714
/// </summary>
1815
/// <param name="key"></param>
1916
/// <returns></returns>
@@ -37,38 +34,6 @@ internal static T GetResourceInternal<T>(string key)
3734
return default;
3835
}
3936

40-
/// <summary>
41-
/// 获取皮肤
42-
/// </summary>
43-
public static ResourceDictionary GetSkin(Assembly assembly, string themePath, SkinType skin)
44-
{
45-
try
46-
{
47-
var uri = new Uri($"pack://application:,,,/{assembly.GetName().Name};component/{themePath}/Skin{skin}.xaml");
48-
return new ResourceDictionary
49-
{
50-
Source = uri
51-
};
52-
}
53-
catch
54-
{
55-
return new ResourceDictionary
56-
{
57-
Source = new Uri($"pack://application:,,,/{assembly.GetName().Name};component/{themePath}/Skin{SkinType.Default}.xaml")
58-
};
59-
}
60-
}
61-
62-
/// <summary>
63-
/// get HandyControl skin
64-
/// </summary>
65-
/// <param name="skin"></param>
66-
/// <returns></returns>
67-
public static ResourceDictionary GetSkin(SkinType skin) => new()
68-
{
69-
Source = new Uri($"pack://application:,,,/HandyControl;component/Themes/Skin{skin}.xaml")
70-
};
71-
7237
/// <summary>
7338
/// get HandyControl theme
7439
/// </summary>
@@ -78,7 +43,7 @@ public static ResourceDictionary GetStandaloneTheme()
7843
{
7944
return new()
8045
{
81-
Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
46+
Source = ApplicationHelper.GetAbsoluteUri("Themes/Theme.xaml")
8247
};
8348
}
8449
}

src/Shared/HandyControl_Shared/Tools/Helper/ScreenHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace HandyControl.Tools;
88

9-
internal class ScreenHelper
9+
public class ScreenHelper
1010
{
1111
internal static void FindMaximumSingleMonitorRectangle(Rect windowRect, out Rect screenSubRect, out Rect monitorRect)
1212
{

src/Shared/HandyControl_Shared/Tools/Helper/SingleOpenHelper.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
namespace HandyControl.Tools;
77

88
/// <summary>
9-
/// 该类可以为可视化元素提供单开的功能
9+
/// This class can provide single-open functions for visual elements
1010
/// </summary>
1111
public class SingleOpenHelper
1212
{
1313
private static readonly Dictionary<string, ISingleOpen> OpenDic = new();
1414

1515
/// <summary>
16-
/// 根据指定的类型创建实例
16+
/// Create an instance based on the specified type
1717
/// </summary>
1818
/// <typeparam name="T"></typeparam>
1919
/// <returns></returns>

src/Shared/HandyControl_Shared/Tools/Helper/SystemHelper.cs

-28
This file was deleted.

src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
namespace HandyControl.Tools;
1616

17-
public static class WindowHelper
17+
public static partial class WindowHelper
1818
{
1919
/// <summary>
20-
/// 获取当前应用中处于激活的一个窗口
20+
/// Get the active window in the current application
2121
/// </summary>
2222
/// <returns></returns>
2323
public static Window GetActiveWindow() => Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
@@ -145,7 +145,7 @@ public static Thickness WindowMaximizedPadding
145145
InteropMethods.ReleaseDC(IntPtr.Zero, hdc);
146146
return WindowResizeBorderThickness.Add(new Thickness((autoHide ? -4 : 4) * scale));
147147
#else
148-
return WindowResizeBorderThickness.Add(new Thickness(autoHide ? -4 : 4));
148+
return WindowResizeBorderThickness.Add(new Thickness(autoHide ? -4 : 4));
149149
#endif
150150
}
151151
}
@@ -157,12 +157,12 @@ public static Thickness WindowMaximizedPadding
157157
public static HwndSource GetHwndSource(this Window window) => HwndSource.FromHwnd(window.GetHandle());
158158

159159
/// <summary>
160-
/// 让窗口激活作为前台最上层窗口
160+
/// Make the window active as the topmost window in the foreground
161161
/// </summary>
162162
/// <param name="window"></param>
163163
public static void SetWindowToForeground(Window window)
164164
{
165-
// [WPF 让窗口激活作为前台最上层窗口的方法 - lindexi - 博客园](https://www.cnblogs.com/lindexi/p/12749671.html)
165+
// [WPF Make the window active as the uppermost window in the foreground - lindexi - Blog](https://www.cnblogs.com/lindexi/p/12749671.html)
166166
var interopHelper = new WindowInteropHelper(window);
167167
var thisWindowThreadId = InteropMethods.GetWindowThreadProcessId(interopHelper.Handle, out _);
168168
var currentForegroundWindow = InteropMethods.GetForegroundWindow();
@@ -171,11 +171,11 @@ public static void SetWindowToForeground(Window window)
171171
// [c# - Bring a window to the front in WPF - Stack Overflow](https://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf )
172172
// [SetForegroundWindow的正确用法 - 子坞 - 博客园](https://www.cnblogs.com/ziwuge/archive/2012/01/06/2315342.html )
173173
/*
174-
1.得到窗口句柄FindWindow
175-
2.切换键盘输入焦点AttachThreadInput
176-
3.显示窗口ShowWindow(有些窗口被最小化/隐藏了)
177-
4.更改窗口的Z Order,SetWindowPos使之最上,为了不影响后续窗口的Z Order,改完之后,再还原
178-
5.最后SetForegroundWindow
174+
  1.得到窗口句柄FindWindow
175+
    2.切换键盘输入焦点AttachThreadInput
176+
    3.显示窗口ShowWindow(有些窗口被最小化/隐藏了)
177+
    4.更改窗口的Z Order,SetWindowPos使之最上,为了不影响后续窗口的Z Order,改完之后,再还原
178+
    5.最后SetForegroundWindow
179179
*/
180180

181181
InteropMethods.AttachThreadInput(currentForegroundWindowThreadId, thisWindowThreadId, true);

src/Shared/HandyControl_Shared/Tools/Hook/MouseHook.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace HandyControl.Tools;
88

9-
internal class MouseHook
9+
public class MouseHook
1010
{
1111
public static event EventHandler<MouseHookEventArgs> StatusChanged;
1212

src/Shared/HandyControl_Shared/Tools/Hook/SystemMenuHook.cs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Windows;
4+
using System.Windows.Controls;
45
using System.Windows.Interop;
56
using HandyControl.Tools.Interop;
67

@@ -9,9 +10,20 @@ namespace HandyControl.Tools;
910
public class SystemMenuHook
1011
{
1112
private static readonly Dictionary<int, HwndSource> DataDic = new();
12-
13+
private static ContextMenu context = null;
1314
public static event Action<int> Click;
1415

16+
public static void SetCustomContextMenu(Window window, ContextMenu contextMenu)
17+
{
18+
context = contextMenu;
19+
var hookId = window.GetHandle();
20+
var source = HwndSource.FromHwnd(hookId);
21+
if (source != null)
22+
{
23+
source.AddHook(new HwndSourceHook(WndProc));
24+
}
25+
}
26+
1527
public static void Insert(int index, int id, string text, Window window)
1628
{
1729
var hookId = window.GetHandle();
@@ -49,4 +61,14 @@ private static IntPtr WinProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam
4961
}
5062
return IntPtr.Zero;
5163
}
64+
65+
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
66+
{
67+
if ((msg == InteropValues.WM_NCRBUTTONDOWN) && (wParam.ToInt32() == InteropValues.HTCAPTION))
68+
{
69+
context.IsOpen = true;
70+
handled = true;
71+
}
72+
return IntPtr.Zero;
73+
}
5274
}

src/Shared/HandyControl_Shared/Tools/Interop/Handle/BitmapHandle.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace HandyControl.Tools.Interop;
88

99
[SuppressMessage("ReSharper", "UnusedMember.Local")]
10-
internal sealed class BitmapHandle : WpfSafeHandle
10+
public sealed class BitmapHandle : WpfSafeHandle
1111
{
1212
[SecurityCritical]
1313
private BitmapHandle() : this(true)

0 commit comments

Comments
 (0)