2023-05-29 12:35:52 +08:00
|
|
|
|
using Ink_Canvas.Helpers;
|
2024-03-08 13:53:21 +08:00
|
|
|
|
using iNKORE.UI.WPF.Modern;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Ink;
|
|
|
|
|
using System.Windows.Media;
|
2024-05-02 20:21:36 +08:00
|
|
|
|
using System.Diagnostics;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
using File = System.IO.File;
|
2024-03-16 12:00:51 +08:00
|
|
|
|
using MessageBox = System.Windows.MessageBox;
|
2024-05-04 19:46:20 +08:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Interop;
|
2024-06-07 21:27:16 +08:00
|
|
|
|
using System.Windows.Controls.Primitives;
|
2024-06-12 11:40:26 +08:00
|
|
|
|
using System.Drawing;
|
2024-06-12 21:04:10 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Win32;
|
2024-07-23 12:48:00 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using Ink_Canvas.Popups;
|
|
|
|
|
using iNKORE.UI.WPF.Modern.Controls;
|
2024-07-28 22:04:21 +08:00
|
|
|
|
using System.Windows.Forms;
|
2024-08-03 11:25:08 +08:00
|
|
|
|
using System.Windows.Input;
|
2024-09-08 21:42:18 +08:00
|
|
|
|
using Ink_Canvas.Resources.ICCConfiguration;
|
2024-08-08 21:57:58 +08:00
|
|
|
|
using Vanara.PInvoke;
|
2024-07-31 18:27:37 +08:00
|
|
|
|
using Application = System.Windows.Application;
|
2024-07-28 22:04:21 +08:00
|
|
|
|
using Button = System.Windows.Controls.Button;
|
|
|
|
|
using TextBox = System.Windows.Controls.TextBox;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
namespace Ink_Canvas {
|
2024-09-16 22:38:33 +08:00
|
|
|
|
public partial class MainWindow : PerformanceTransparentWin {
|
2024-07-15 22:11:47 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnPropertyChanged(e);
|
|
|
|
|
|
|
|
|
|
if (e.Property.Name == nameof(Topmost) && isLoaded) {
|
|
|
|
|
if (Topmost && Settings.Advanced.IsEnableForceFullScreen) {
|
|
|
|
|
Trace.WriteLine("Topmost true");
|
2024-09-07 21:43:16 +08:00
|
|
|
|
SetWindowPos(new WindowInteropHelper(this).Handle, new IntPtr(-1), 0, 0, 0, 0, 0x0002|0x0040|0x0001);
|
2024-07-15 22:11:47 +08:00
|
|
|
|
} else if (!Topmost && Settings.Advanced.IsEnableForceFullScreen) {
|
|
|
|
|
Trace.WriteLine("Topmost false");
|
2024-09-07 21:43:16 +08:00
|
|
|
|
SetWindowPos(new WindowInteropHelper(this).Handle, new IntPtr(-2), 0, 0, 0, 0, 0x0002|0x0040|0x0001);
|
2024-07-15 22:11:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 16:05:03 +08:00
|
|
|
|
#region Window Initialization
|
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
public MainWindow() {
|
2023-12-22 00:14:15 +08:00
|
|
|
|
/*
|
|
|
|
|
处于画板模式内:Topmost == false / currentMode != 0
|
|
|
|
|
处于 PPT 放映内:BtnPPTSlideShowEnd.Visibility
|
|
|
|
|
*/
|
2023-04-05 16:05:03 +08:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2023-12-22 00:14:15 +08:00
|
|
|
|
BlackboardLeftSide.Visibility = Visibility.Collapsed;
|
|
|
|
|
BlackboardCenterSide.Visibility = Visibility.Collapsed;
|
|
|
|
|
BlackboardRightSide.Visibility = Visibility.Collapsed;
|
|
|
|
|
BorderTools.Visibility = Visibility.Collapsed;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
BorderSettings.Visibility = Visibility.Collapsed;
|
2023-12-22 00:14:15 +08:00
|
|
|
|
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
|
|
|
|
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
2024-05-23 02:38:44 +08:00
|
|
|
|
BorderSettings.Margin = new Thickness(0, 0, 0, 0);
|
2023-12-22 00:14:15 +08:00
|
|
|
|
TwoFingerGestureBorder.Visibility = Visibility.Collapsed;
|
|
|
|
|
BoardTwoFingerGestureBorder.Visibility = Visibility.Collapsed;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
BorderDrawShape.Visibility = Visibility.Collapsed;
|
2023-12-22 00:14:15 +08:00
|
|
|
|
BoardBorderDrawShape.Visibility = Visibility.Collapsed;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
ViewboxFloatingBar.Margin = new Thickness((SystemParameters.WorkArea.Width - 284) / 2,
|
|
|
|
|
SystemParameters.WorkArea.Height - 60, -2000, -200);
|
2024-05-23 02:38:44 +08:00
|
|
|
|
ViewboxFloatingBarMarginAnimation(100, true);
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
try {
|
2023-12-22 00:14:15 +08:00
|
|
|
|
if (File.Exists("debug.ini")) Label.Visibility = Visibility.Visible;
|
2024-05-23 02:38:44 +08:00
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
catch (Exception ex) {
|
2023-12-22 00:14:15 +08:00
|
|
|
|
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
|
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (File.Exists("Log.txt")) {
|
|
|
|
|
var fileInfo = new FileInfo("Log.txt");
|
|
|
|
|
var fileSizeInKB = fileInfo.Length / 1024;
|
2024-05-23 02:38:44 +08:00
|
|
|
|
if (fileSizeInKB > 512)
|
2024-06-05 20:25:26 +08:00
|
|
|
|
try {
|
2024-03-08 13:53:21 +08:00
|
|
|
|
File.Delete("Log.txt");
|
2024-06-05 20:25:26 +08:00
|
|
|
|
LogHelper.WriteLogToFile(
|
|
|
|
|
"The Log.txt file has been successfully deleted. Original file size: " + fileSizeInKB +
|
|
|
|
|
" KB", LogHelper.LogType.Info);
|
2024-05-23 02:38:44 +08:00
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
LogHelper.WriteLogToFile(
|
|
|
|
|
ex + " | Can not delete the Log.txt file. File size: " + fileSizeInKB + " KB",
|
|
|
|
|
LogHelper.LogType.Error);
|
2024-03-08 13:53:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-23 02:38:44 +08:00
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
catch (Exception ex) {
|
2024-03-08 13:53:21 +08:00
|
|
|
|
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
|
|
|
|
|
}
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
|
|
|
|
InitTimers();
|
2023-04-15 19:07:01 +08:00
|
|
|
|
timeMachine.OnRedoStateChanged += TimeMachine_OnRedoStateChanged;
|
|
|
|
|
timeMachine.OnUndoStateChanged += TimeMachine_OnUndoStateChanged;
|
2023-04-21 20:44:01 +08:00
|
|
|
|
inkCanvas.Strokes.StrokesChanged += StrokesOnStrokesChanged;
|
2023-05-27 21:56:25 +08:00
|
|
|
|
|
2024-09-16 22:38:33 +08:00
|
|
|
|
//Microsoft.Win32.SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
|
2024-06-05 20:25:26 +08:00
|
|
|
|
try {
|
2023-12-22 00:14:15 +08:00
|
|
|
|
if (File.Exists("SpecialVersion.ini")) SpecialVersionResetToSuggestion_Click();
|
2024-05-23 02:38:44 +08:00
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
catch (Exception ex) {
|
2023-12-22 00:14:15 +08:00
|
|
|
|
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CheckColorTheme(true);
|
2024-05-12 14:23:50 +08:00
|
|
|
|
CheckPenTypeUIState();
|
2023-04-05 16:05:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Ink Canvas Functions
|
2024-05-23 02:38:44 +08:00
|
|
|
|
|
2024-06-12 11:40:26 +08:00
|
|
|
|
private System.Windows.Media.Color Ink_DefaultColor = Colors.Red;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
private DrawingAttributes drawingAttributes;
|
2024-05-02 20:21:36 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
private void loadPenCanvas() {
|
|
|
|
|
try {
|
2023-04-05 16:05:03 +08:00
|
|
|
|
//drawingAttributes = new DrawingAttributes();
|
|
|
|
|
drawingAttributes = inkCanvas.DefaultDrawingAttributes;
|
|
|
|
|
drawingAttributes.Color = Ink_DefaultColor;
|
|
|
|
|
|
2024-06-12 11:40:26 +08:00
|
|
|
|
|
2023-04-05 16:05:03 +08:00
|
|
|
|
drawingAttributes.Height = 2.5;
|
|
|
|
|
drawingAttributes.Width = 2.5;
|
2024-05-03 19:07:46 +08:00
|
|
|
|
drawingAttributes.IsHighlighter = false;
|
2024-05-04 01:01:16 +08:00
|
|
|
|
drawingAttributes.FitToCurve = Settings.Canvas.FitToCurve;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
|
|
|
|
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
2024-08-08 21:57:58 +08:00
|
|
|
|
inkCanvas.DeleteKeyCommandFired += InkCanvasDeleteCommandFiredEvent;
|
2024-07-23 12:48:00 +08:00
|
|
|
|
//inkCanvas.Gesture += InkCanvas_Gesture;
|
2024-05-23 02:38:44 +08:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
2023-04-05 16:05:03 +08:00
|
|
|
|
}
|
2023-04-16 00:08:52 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
private void inkCanvas_EditingModeChanged(object sender, RoutedEventArgs e) {
|
2023-04-05 16:05:03 +08:00
|
|
|
|
var inkCanvas1 = sender as InkCanvas;
|
|
|
|
|
if (inkCanvas1 == null) return;
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (Settings.Canvas.IsShowCursor) {
|
2024-05-23 02:38:44 +08:00
|
|
|
|
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink || drawingShapeMode != 0)
|
2023-04-05 16:05:03 +08:00
|
|
|
|
inkCanvas1.ForceCursor = true;
|
2024-05-23 02:38:44 +08:00
|
|
|
|
else
|
2023-04-05 16:05:03 +08:00
|
|
|
|
inkCanvas1.ForceCursor = false;
|
2024-06-12 11:40:26 +08:00
|
|
|
|
} else {
|
2023-04-05 16:05:03 +08:00
|
|
|
|
inkCanvas1.ForceCursor = false;
|
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
|
2023-04-05 16:05:03 +08:00
|
|
|
|
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink) forcePointEraser = !forcePointEraser;
|
2024-07-23 12:48:00 +08:00
|
|
|
|
|
|
|
|
|
if ((inkCanvas1.EditingMode == InkCanvasEditingMode.EraseByPoint &&
|
|
|
|
|
SelectedMode == ICCToolsEnum.EraseByGeometryMode) || (inkCanvas1.EditingMode == InkCanvasEditingMode.EraseByStroke &&
|
|
|
|
|
SelectedMode == ICCToolsEnum.EraseByStrokeMode)) {
|
|
|
|
|
GridEraserOverlay.Visibility = Visibility.Visible;
|
|
|
|
|
} else {
|
|
|
|
|
GridEraserOverlay.Visibility = Visibility.Collapsed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inkCanvas1.EditingModeInverted = inkCanvas1.EditingMode;
|
|
|
|
|
|
|
|
|
|
RectangleSelectionHitTestBorder.Visibility = inkCanvas1.EditingMode == InkCanvasEditingMode.Select ? Visibility.Visible : Visibility.Collapsed;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Ink Canvas
|
|
|
|
|
|
2024-07-15 22:11:47 +08:00
|
|
|
|
#region Definitions and Loading
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
|
|
|
|
public static Settings Settings = new Settings();
|
2024-09-08 21:42:18 +08:00
|
|
|
|
public static ICCConfiguration SettingsV2 = new ICCConfiguration();
|
2023-04-05 16:05:03 +08:00
|
|
|
|
public static string settingsFileName = "Settings.json";
|
2024-08-02 20:37:49 +08:00
|
|
|
|
public bool isLoaded = false;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
2024-07-12 14:01:39 +08:00
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
|
|
|
|
|
|
2024-07-15 22:11:47 +08:00
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
|
|
|
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, UInt32 uFlags);
|
|
|
|
|
|
2024-07-12 14:01:39 +08:00
|
|
|
|
const uint MF_BYCOMMAND = 0x00000000;
|
|
|
|
|
const uint MF_GRAYED = 0x00000001;
|
|
|
|
|
const uint SC_CLOSE = 0xF060;
|
|
|
|
|
|
2024-08-08 21:57:58 +08:00
|
|
|
|
private static void PreloadIALibrary() {
|
2024-08-03 11:25:08 +08:00
|
|
|
|
GC.KeepAlive(typeof(InkAnalyzer));
|
|
|
|
|
GC.KeepAlive(typeof(AnalysisAlternate));
|
|
|
|
|
GC.KeepAlive(typeof(InkDrawingNode));
|
|
|
|
|
var analyzer = new InkAnalyzer();
|
|
|
|
|
analyzer.AddStrokes(new StrokeCollection() {
|
|
|
|
|
new Stroke(new StylusPointCollection() {
|
|
|
|
|
new StylusPoint(114,514),
|
|
|
|
|
new StylusPoint(191,9810),
|
|
|
|
|
new StylusPoint(7,21),
|
|
|
|
|
new StylusPoint(123,789),
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
analyzer.Analyze();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-28 22:04:21 +08:00
|
|
|
|
private async void Window_Loaded(object sender, RoutedEventArgs e) {
|
2023-04-05 16:05:03 +08:00
|
|
|
|
loadPenCanvas();
|
|
|
|
|
//加载设置
|
2024-03-08 23:00:38 +08:00
|
|
|
|
LoadSettings(true);
|
2024-05-05 09:58:31 +08:00
|
|
|
|
// HasNewUpdateWindow hasNewUpdateWindow = new HasNewUpdateWindow();
|
2024-07-11 21:59:31 +08:00
|
|
|
|
if (Environment.Is64BitProcess) SettingsInkRecognitionGroupBox.Visibility = Visibility.Collapsed;
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
|
|
|
|
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
|
2024-09-16 22:38:33 +08:00
|
|
|
|
//SystemEvents_UserPreferenceChanged(null, null);
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
2023-12-22 00:14:15 +08:00
|
|
|
|
//TextBlockVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
2023-04-05 16:05:03 +08:00
|
|
|
|
LogHelper.WriteLogToFile("Ink Canvas Loaded", LogHelper.LogType.Event);
|
2024-06-07 21:27:16 +08:00
|
|
|
|
|
2024-09-08 21:42:18 +08:00
|
|
|
|
var app = Application.Current;
|
|
|
|
|
|
2023-04-05 16:05:03 +08:00
|
|
|
|
isLoaded = true;
|
2024-06-09 21:29:03 +08:00
|
|
|
|
|
2024-09-16 22:38:33 +08:00
|
|
|
|
InitFloatingToolbarV2();
|
2024-09-02 22:14:25 +08:00
|
|
|
|
|
2024-06-13 21:45:11 +08:00
|
|
|
|
BlackBoardLeftSidePageListView.ItemsSource = blackBoardSidePageListViewObservableCollection;
|
|
|
|
|
BlackBoardRightSidePageListView.ItemsSource = blackBoardSidePageListViewObservableCollection;
|
|
|
|
|
|
2024-06-12 11:40:26 +08:00
|
|
|
|
BtnLeftWhiteBoardSwitchPreviousGeometry.Brush =
|
|
|
|
|
new SolidColorBrush(System.Windows.Media.Color.FromArgb(127, 24, 24, 27));
|
2024-06-10 22:06:58 +08:00
|
|
|
|
BtnLeftWhiteBoardSwitchPreviousLabel.Opacity = 0.5;
|
2024-06-13 21:45:11 +08:00
|
|
|
|
BtnRightWhiteBoardSwitchPreviousGeometry.Brush =
|
|
|
|
|
new SolidColorBrush(System.Windows.Media.Color.FromArgb(127, 24, 24, 27));
|
|
|
|
|
BtnRightWhiteBoardSwitchPreviousLabel.Opacity = 0.5;
|
|
|
|
|
|
2024-06-11 13:55:19 +08:00
|
|
|
|
BorderInkReplayToolBox.Visibility = Visibility.Collapsed;
|
2024-07-12 21:33:36 +08:00
|
|
|
|
BoardBackgroundPopup.Visibility = Visibility.Collapsed;
|
2024-06-12 21:04:10 +08:00
|
|
|
|
|
2024-06-14 14:27:22 +08:00
|
|
|
|
// 提前加载IA库,优化第一笔等待时间
|
2024-08-08 21:57:58 +08:00
|
|
|
|
PreloadIALibrary();
|
2024-06-14 14:27:22 +08:00
|
|
|
|
|
2024-06-12 21:04:10 +08:00
|
|
|
|
SystemEvents.DisplaySettingsChanged += SystemEventsOnDisplaySettingsChanged;
|
2024-07-12 14:01:39 +08:00
|
|
|
|
|
|
|
|
|
if (Settings.Advanced.IsDisableCloseWindow) {
|
|
|
|
|
// Disable close button
|
|
|
|
|
IntPtr hwnd = new WindowInteropHelper(this).Handle;
|
|
|
|
|
IntPtr hMenu = GetSystemMenu(hwnd, false);
|
|
|
|
|
if (hMenu != IntPtr.Zero) {
|
|
|
|
|
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-13 21:55:03 +08:00
|
|
|
|
|
|
|
|
|
UpdateFloatingBarIconsLayout();
|
2024-07-23 12:48:00 +08:00
|
|
|
|
|
|
|
|
|
StylusInvertedListenerInit();
|
2024-07-28 22:04:21 +08:00
|
|
|
|
|
|
|
|
|
PenPaletteV2Init();
|
2024-08-05 21:53:56 +08:00
|
|
|
|
SelectionV2Init();
|
2024-08-12 21:21:13 +08:00
|
|
|
|
ShapeDrawingV2Init();
|
2024-08-01 15:57:42 +08:00
|
|
|
|
|
|
|
|
|
InitStorageManagementModule();
|
2024-08-08 21:57:58 +08:00
|
|
|
|
|
|
|
|
|
InitFreezeWindow(new HWND[] {
|
|
|
|
|
new HWND(new WindowInteropHelper(this).Handle)
|
|
|
|
|
});
|
2024-08-09 21:34:02 +08:00
|
|
|
|
|
|
|
|
|
UpdateIndexInfoDisplay();
|
2024-09-07 21:43:16 +08:00
|
|
|
|
|
|
|
|
|
SetWindowPos(new WindowInteropHelper(this).Handle, new IntPtr(-1), 0, 0, 0, 0, 0x0002|0x0040|0x0001);
|
2024-06-12 21:04:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SystemEventsOnDisplaySettingsChanged(object sender, EventArgs e) {
|
|
|
|
|
if (!Settings.Advanced.IsEnableResolutionChangeDetection) return;
|
2024-07-28 22:04:21 +08:00
|
|
|
|
ShowNotification($"检测到显示器信息变化,变为{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width}x{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height}");
|
2024-06-12 21:04:10 +08:00
|
|
|
|
new Thread(() => {
|
|
|
|
|
var isFloatingBarOutsideScreen = false;
|
|
|
|
|
var isInPPTPresentationMode = false;
|
|
|
|
|
Dispatcher.Invoke(() => {
|
|
|
|
|
isFloatingBarOutsideScreen = IsOutsideOfScreenHelper.IsOutsideOfScreen(ViewboxFloatingBar);
|
2024-07-23 12:48:00 +08:00
|
|
|
|
isInPPTPresentationMode = BorderFloatingBarExitPPTBtn.Visibility == Visibility.Visible;
|
2024-06-12 21:04:10 +08:00
|
|
|
|
});
|
|
|
|
|
if (isFloatingBarOutsideScreen) dpiChangedDelayAction.DebounceAction(3000, null, () => {
|
|
|
|
|
if (!isFloatingBarFolded)
|
|
|
|
|
{
|
|
|
|
|
if (isInPPTPresentationMode) ViewboxFloatingBarMarginAnimation(60);
|
|
|
|
|
else ViewboxFloatingBarMarginAnimation(100, true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}).Start();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 19:34:37 +08:00
|
|
|
|
public DelayAction dpiChangedDelayAction = new DelayAction();
|
2024-06-12 21:04:10 +08:00
|
|
|
|
|
2024-07-28 22:04:21 +08:00
|
|
|
|
private void MainWindow_OnDpiChanged(object sender, System.Windows.DpiChangedEventArgs e)
|
2024-06-12 21:04:10 +08:00
|
|
|
|
{
|
|
|
|
|
if (e.OldDpi.DpiScaleX != e.NewDpi.DpiScaleX && e.OldDpi.DpiScaleY != e.NewDpi.DpiScaleY && Settings.Advanced.IsEnableDPIChangeDetection)
|
|
|
|
|
{
|
2024-07-28 22:04:21 +08:00
|
|
|
|
ShowNotification($"系统DPI发生变化,从 {e.OldDpi.DpiScaleX}x{e.OldDpi.DpiScaleY} 变化为 {e.NewDpi.DpiScaleX}x{e.NewDpi.DpiScaleY}");
|
2024-06-12 21:04:10 +08:00
|
|
|
|
|
|
|
|
|
new Thread(() => {
|
|
|
|
|
var isFloatingBarOutsideScreen = false;
|
|
|
|
|
var isInPPTPresentationMode = false;
|
|
|
|
|
Dispatcher.Invoke(() => {
|
|
|
|
|
isFloatingBarOutsideScreen = IsOutsideOfScreenHelper.IsOutsideOfScreen(ViewboxFloatingBar);
|
2024-07-23 12:48:00 +08:00
|
|
|
|
isInPPTPresentationMode = BorderFloatingBarExitPPTBtn.Visibility == Visibility.Visible;
|
2024-06-12 21:04:10 +08:00
|
|
|
|
});
|
|
|
|
|
if (isFloatingBarOutsideScreen) dpiChangedDelayAction.DebounceAction(3000,null, () => {
|
|
|
|
|
if (!isFloatingBarFolded)
|
|
|
|
|
{
|
|
|
|
|
if (isInPPTPresentationMode) ViewboxFloatingBarMarginAnimation(60);
|
|
|
|
|
else ViewboxFloatingBarMarginAnimation(100, true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}).Start();
|
|
|
|
|
}
|
2023-04-05 16:05:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
|
2023-04-05 16:05:03 +08:00
|
|
|
|
LogHelper.WriteLogToFile("Ink Canvas closing", LogHelper.LogType.Event);
|
2024-07-12 14:01:39 +08:00
|
|
|
|
if (!CloseIsFromButton) {
|
2023-04-05 16:05:03 +08:00
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
|
|
|
|
|
if (e.Cancel) LogHelper.WriteLogToFile("Ink Canvas closing cancelled", LogHelper.LogType.Event);
|
2024-08-08 21:57:58 +08:00
|
|
|
|
else {
|
|
|
|
|
DisposeFreezeFrame();
|
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
|
}
|
2023-04-05 16:05:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 11:40:26 +08:00
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
2024-06-13 19:34:37 +08:00
|
|
|
|
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
|
2024-06-12 11:40:26 +08:00
|
|
|
|
|
|
|
|
|
private void MainWindow_OnSizeChanged(object sender, SizeChangedEventArgs e) {
|
|
|
|
|
if (Settings.Advanced.IsEnableForceFullScreen) {
|
2024-07-28 22:04:21 +08:00
|
|
|
|
if (isLoaded) ShowNotification(
|
2024-06-12 11:40:26 +08:00
|
|
|
|
$"检测到窗口大小变化,已自动恢复到全屏:{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width}x{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height}(缩放比例为{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth}x{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / SystemParameters.PrimaryScreenHeight})");
|
|
|
|
|
WindowState = WindowState.Maximized;
|
|
|
|
|
MoveWindow(new WindowInteropHelper(this).Handle, 0, 0,
|
|
|
|
|
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
|
|
|
|
|
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
private void Window_Closed(object sender, EventArgs e) {
|
2024-06-12 21:04:10 +08:00
|
|
|
|
SystemEvents.DisplaySettingsChanged -= SystemEventsOnDisplaySettingsChanged;
|
|
|
|
|
|
2023-04-05 16:05:03 +08:00
|
|
|
|
LogHelper.WriteLogToFile("Ink Canvas closed", LogHelper.LogType.Event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
private async void AutoUpdate() {
|
2024-05-04 18:56:19 +08:00
|
|
|
|
AvailableLatestVersion = await AutoUpdateHelper.CheckForUpdates();
|
2023-12-22 00:14:15 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (AvailableLatestVersion != null) {
|
|
|
|
|
var IsDownloadSuccessful = false;
|
2024-05-04 18:56:19 +08:00
|
|
|
|
IsDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileAndSaveStatus(AvailableLatestVersion);
|
2023-12-22 00:14:15 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (IsDownloadSuccessful) {
|
|
|
|
|
if (!Settings.Startup.IsAutoUpdateWithSilence) {
|
|
|
|
|
if (MessageBox.Show("InkCanvasForClass 新版本安装包已下载完成,是否立即更新?",
|
|
|
|
|
"InkCanvasForClass New Version Available", MessageBoxButton.YesNo,
|
|
|
|
|
MessageBoxImage.Question) ==
|
|
|
|
|
MessageBoxResult.Yes) AutoUpdateHelper.InstallNewVersionApp(AvailableLatestVersion, false);
|
2024-06-12 11:40:26 +08:00
|
|
|
|
} else {
|
2023-12-22 00:14:15 +08:00
|
|
|
|
timerCheckAutoUpdateWithSilence.Start();
|
|
|
|
|
}
|
2023-04-05 16:05:03 +08:00
|
|
|
|
}
|
2024-06-12 11:40:26 +08:00
|
|
|
|
} else {
|
2023-12-22 00:14:15 +08:00
|
|
|
|
AutoUpdateHelper.DeleteUpdatesFolder();
|
2023-04-05 16:05:03 +08:00
|
|
|
|
}
|
2023-12-22 00:14:15 +08:00
|
|
|
|
}
|
2023-04-05 16:05:03 +08:00
|
|
|
|
|
|
|
|
|
#endregion Definations and Loading
|
|
|
|
|
}
|
2024-05-01 18:23:32 +08:00
|
|
|
|
}
|