improve:PPT墨迹管理

This commit is contained in:
2026-02-21 15:23:42 +08:00
parent b1e384e52d
commit b1513ca587
2 changed files with 35 additions and 79 deletions
-32
View File
@@ -2802,38 +2802,6 @@ namespace Ink_Canvas
private IntPtr KeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0)
{
if (Settings.Advanced.IsNoFocusMode &&
BtnPPTSlideShowEnd.Visibility == Visibility.Visible &&
currentMode == 0)
{
KBDLLHOOKSTRUCT hookStruct = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
uint vkCode = hookStruct.vkCode;
if (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN)
{
if (vkCode == 0x22 || vkCode == 0x28 || vkCode == 0x27 ||
vkCode == 0x4E || vkCode == 0x20)
{
Dispatcher.BeginInvoke(new Action(() =>
{
BtnPPTSlidesDown_Click(null, null);
}), DispatcherPriority.Normal);
return (IntPtr)1;
}
else if (vkCode == 0x21 || vkCode == 0x26 || vkCode == 0x25 ||
vkCode == 0x50)
{
Dispatcher.BeginInvoke(new Action(() =>
{
BtnPPTSlidesUp_Click(null, null);
}), DispatcherPriority.Normal);
return (IntPtr)1;
}
}
}
}
return CallNextHookEx(_keyboardHookId, nCode, wParam, lParam);
}
+22 -34
View File
@@ -948,20 +948,9 @@ namespace Ink_Canvas
if (currentSlide == _previousSlideID) return;
lock (_slideSwitchLock)
{
if (currentSlide == _currentSlideShowPosition) return;
if (_isProcessingSlideSwitch) return;
_isProcessingSlideSwitch = true;
}
int prev = _currentSlideShowPosition;
int prev = _previousSlideID;
Application.Current.Dispatcher.Invoke(() =>
{
try
{
if (inkCanvas.Strokes.Count > 0 && prev > 0 && prev != currentSlide)
{
var ms = new MemoryStream();
inkCanvas.Strokes.Save(ms);
@@ -969,46 +958,45 @@ namespace Ink_Canvas
if (_memoryStreams.ContainsKey(prev))
_memoryStreams[prev]?.Dispose();
_memoryStreams[prev] = ms;
}
ClearStrokes(true);
timeMachine.ClearStrokeHistory();
// 从内存流加载新页墨迹(无文件I/O)
try
{
_currentSlideShowPosition = currentSlide;
_singlePPTInkManager?.LockInkForSlide(currentSlide);
_pptUIManager?.UpdateCurrentSlideNumber(currentSlide, totalSlides);
if (_memoryStreams.ContainsKey(currentSlide) && _memoryStreams[currentSlide] != null)
{
_memoryStreams[currentSlide].Position = 0;
inkCanvas.Strokes.Add(new StrokeCollection(_memoryStreams[currentSlide]));
}
byte[] bytes = _memoryStreams[currentSlide].ToArray();
int loadingPage = currentSlide;
Task.Run(() =>
{
try
{
return new StrokeCollection(new MemoryStream(bytes));
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"从内存流加载第 {currentSlide} 页墨迹失败: {ex}", LogHelper.LogType.Warning);
LogHelper.WriteLogToFile($"从内存流加载第 {loadingPage} 页墨迹失败: {ex}", LogHelper.LogType.Warning);
return null;
}
_singlePPTInkManager?.LockInkForSlide(currentSlide);
_pptUIManager?.UpdateCurrentSlideNumber(currentSlide, totalSlides);
}
finally
}).ContinueWith(t =>
{
_currentSlideShowPosition = currentSlide;
_previousSlideID = currentSlide;
lock (_slideSwitchLock)
if (t.IsFaulted || t.Result == null) return;
Application.Current.Dispatcher.Invoke(() =>
{
_isProcessingSlideSwitch = false;
}
if (_currentSlideShowPosition != loadingPage) return;
inkCanvas.Strokes.Add(t.Result);
});
});
}
});
_previousSlideID = currentSlide;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"处理幻灯片切换事件失败: {ex}", LogHelper.LogType.Error);
lock (_slideSwitchLock)
{
_isProcessingSlideSwitch = false;
}
}
}