diff --git a/Ink Canvas/Helpers/ComPPTLinkManager.cs b/Ink Canvas/Helpers/ComPPTLinkManager.cs new file mode 100644 index 00000000..0b688c04 --- /dev/null +++ b/Ink Canvas/Helpers/ComPPTLinkManager.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.Office.Interop.PowerPoint; + +namespace Ink_Canvas.Helpers +{ + public class ComPPTLinkManager : IPPTLinkManager + { + private readonly PPTManager _inner; + + public ComPPTLinkManager() + { + _inner = new PPTManager(); + + _inner.SlideShowBegin += wn => SlideShowBegin?.Invoke(wn); + _inner.SlideShowNextSlide += wn => SlideShowNextSlide?.Invoke(wn); + _inner.SlideShowEnd += pres => SlideShowEnd?.Invoke(pres); + _inner.PresentationOpen += pres => PresentationOpen?.Invoke(pres); + _inner.PresentationClose += pres => PresentationClose?.Invoke(pres); + _inner.PPTConnectionChanged += connected => PPTConnectionChanged?.Invoke(connected); + _inner.SlideShowStateChanged += inSlideShow => SlideShowStateChanged?.Invoke(inSlideShow); + } + + #region IPPTLinkManager 事件 + public event Action SlideShowBegin; + public event Action SlideShowNextSlide; + public event Action SlideShowEnd; + public event Action PresentationOpen; + public event Action PresentationClose; + public event Action PPTConnectionChanged; + public event Action SlideShowStateChanged; + #endregion + + #region IPPTLinkManager 属性 + public bool IsConnected => _inner.IsConnected; + + public bool IsInSlideShow => _inner.IsInSlideShow; + + public bool IsSupportWPS + { + get => _inner.IsSupportWPS; + set => _inner.IsSupportWPS = value; + } + + public int SlidesCount => _inner.SlidesCount; + + public object PPTApplication => _inner.PPTApplication; + #endregion + + #region 生命周期管理 + public void StartMonitoring() => _inner.StartMonitoring(); + + public void StopMonitoring() => _inner.StopMonitoring(); + #endregion + + #region 放映控制 + public bool TryStartSlideShow() => _inner.TryStartSlideShow(); + + public bool TryEndSlideShow() => _inner.TryEndSlideShow(); + #endregion + + #region 导航控制 + public bool TryNavigateToSlide(int slideNumber) => _inner.TryNavigateToSlide(slideNumber); + + public bool TryNavigateNext() => _inner.TryNavigateNext(); + + public bool TryNavigatePrevious() => _inner.TryNavigatePrevious(); + #endregion + + #region 查询 + public int GetCurrentSlideNumber() => _inner.GetCurrentSlideNumber(); + + public string GetPresentationName() => _inner.GetPresentationName(); + + public bool TryShowSlideNavigation() => _inner.TryShowSlideNavigation(); + + public object GetCurrentActivePresentation() => _inner.GetCurrentActivePresentation(); + #endregion + + #region IDisposable + public void Dispose() + { + _inner?.Dispose(); + } + #endregion + } +} + diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index 307607b3..3f0ae7a6 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -105,14 +105,14 @@ namespace Ink_Canvas #endregion #region PPT Managers - private PPTManager _pptManager; + private IPPTLinkManager _pptManager; private PPTInkManager _singlePPTInkManager; private PPTUIManager _pptUIManager; /// /// 获取PPT管理器实例 /// - public PPTManager PPTManager => _pptManager; + public IPPTLinkManager PPTManager => _pptManager; #endregion #region PPT Manager Initialization @@ -123,17 +123,34 @@ namespace Ink_Canvas // 初始化长按定时器 InitializeLongPressTimer(); - // 初始化PPT管理器 - _pptManager = new PPTManager(); + // 如有旧实例,先停止监控,避免重复 + try + { + _pptManager?.StopMonitoring(); + } + catch + { + } + + // 根据设置选择 COM / ROT 架构 + if (Settings.PowerPointSettings.UseRotPptLink) + { + _pptManager = new ROTPPTManager(); + } + else + { + _pptManager = new ComPPTLinkManager(); + } + _pptManager.IsSupportWPS = Settings.PowerPointSettings.IsSupportWPS; // 注册事件 _pptManager.PPTConnectionChanged += OnPPTConnectionChanged; - _pptManager.SlideShowBegin += OnPPTSlideShowBegin; - _pptManager.SlideShowNextSlide += OnPPTSlideShowNextSlide; - _pptManager.SlideShowEnd += OnPPTSlideShowEnd; - _pptManager.PresentationOpen += OnPPTPresentationOpen; - _pptManager.PresentationClose += OnPPTPresentationClose; + _pptManager.SlideShowBegin += o => OnPPTSlideShowBegin(o as SlideShowWindow); + _pptManager.SlideShowNextSlide += o => OnPPTSlideShowNextSlide(o as SlideShowWindow); + _pptManager.SlideShowEnd += o => OnPPTSlideShowEnd(o as Presentation); + _pptManager.PresentationOpen += o => OnPPTPresentationOpen(o as Presentation); + _pptManager.PresentationClose += o => OnPPTPresentationClose(o as Presentation); _pptManager.SlideShowStateChanged += OnPPTSlideShowStateChanged; _singlePPTInkManager = new PPTInkManager(); @@ -645,7 +662,7 @@ namespace Ink_Canvas } else { - activePresentation = _pptManager?.GetCurrentActivePresentation(); + activePresentation = _pptManager?.GetCurrentActivePresentation() as Presentation; currentSlide = _pptManager?.GetCurrentSlideNumber() ?? 0; totalSlides = _pptManager?.SlidesCount ?? 0; // 初始化当前播放页码跟踪 @@ -988,9 +1005,10 @@ namespace Ink_Canvas { try { - if (_pptManager?.PPTApplication != null) + var pptApp = _pptManager?.PPTApplication as Microsoft.Office.Interop.PowerPoint.Application; + if (pptApp != null) { - if (_pptManager.PPTApplication.SlideShowWindows.Count >= 1) + if (pptApp.SlideShowWindows.Count >= 1) { pres.SlideShowWindow.View.GotoSlide(page); }