improve:PPT联动
This commit is contained in:
@@ -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<object> SlideShowBegin;
|
||||
public event Action<object> SlideShowNextSlide;
|
||||
public event Action<object> SlideShowEnd;
|
||||
public event Action<object> PresentationOpen;
|
||||
public event Action<object> PresentationClose;
|
||||
public event Action<bool> PPTConnectionChanged;
|
||||
public event Action<bool> 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,14 +105,14 @@ namespace Ink_Canvas
|
||||
#endregion
|
||||
|
||||
#region PPT Managers
|
||||
private PPTManager _pptManager;
|
||||
private IPPTLinkManager _pptManager;
|
||||
private PPTInkManager _singlePPTInkManager;
|
||||
private PPTUIManager _pptUIManager;
|
||||
|
||||
/// <summary>
|
||||
/// 获取PPT管理器实例
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user