-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThisAddIn.cs
131 lines (117 loc) · 4.53 KB
/
ThisAddIn.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Threading;
using Microsoft.Office.Interop.PowerPoint;
using PowerPointTimer.Core;
namespace PowerPointTimer
{
/// <summary>
/// API PowerPoint VSTO:
/// https://docs.microsoft.com/en-US/office/vba/api/overview/powerpoint/object-model
/// </summary>
public partial class ThisAddIn
{
List<CountDown> runningCountDowns = new List<CountDown>();
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.SlideShowEnd += OnSlideShowEnd;
Application.SlideShowNextSlide += OnSlideShowNextSlide;
Application.SlideShowNextClick += OnSlideShowNextClick;
Application.SlideShowOnPrevious += OnSlideShowOnPrevious;
//Application.WindowSelectionChange += OnWindowSelectionChange;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { }
void OnWindowSelectionChange(Selection selection)
{
}
/// <summary>
/// Called each time a slide is loaded. Effect will tell if an effect is eligible on the next click,
/// if so, mark the corresponding timer as "elligible" for start on the next click
/// </summary>
/// <param name="SlideShowWindow"></param>
/// <param name="Effect"></param>
void OnSlideShowNextClick(SlideShowWindow SlideShowWindow, Effect Effect)
{
// Detect which CountDown will start at next click
if (Effect != null)
{
if (Effect.Shape.Tags[Constants.TimerLauncher] == Constants.TimerLauncherValue)
{
runningCountDowns
.FirstOrDefault<CountDown>(cd => cd.UnderlyingLauncherShapeId == Effect.Shape.Id)?.Init();
}
}
else
{
runningCountDowns.FirstOrDefault<CountDown>(cd => cd.Status == CountDownStatusEnum.Ready)
?.Start();
}
}
void OnSlideShowOnPrevious(SlideShowWindow SlideShowWindow)
{
if (runningCountDowns.Count > 0)
{
runningCountDowns.ForEach(cd => cd.Stop());
}
}
/// <summary>
/// Called when the slide show ends. This handler kills all countdowns
/// </summary>
/// <param name="Presentation">The current presentation</param>
void OnSlideShowEnd(Presentation Presentation)
{
disposeCountDowns();
}
/// <summary>
/// Called when a slide is loaded, in a slide show mode. Kills existing countdown, and start thoses on the
/// loaded slide
/// </summary>
/// <param name="SlideShowWindow">The current slide show window</param>
void OnSlideShowNextSlide(SlideShowWindow SlideShowWindow)
{
// If timers are running, kill them before starting them on the new slide
disposeCountDowns();
// If a timer is on the slide, init it!
var currentSlide = SlideShowWindow.View.Slide;
runningCountDowns = getCountDowns(currentSlide)
.Select(shape => new CountDown(shape))
.ToList();
}
/// <summary>
/// stop all countdowns registered into the runningCountDowns list.
/// </summary>
void disposeCountDowns()
{
if (runningCountDowns.Count > 0)
{
runningCountDowns.ForEach(cd => cd.Stop());
runningCountDowns.Clear();
}
}
/// <summary>
/// Returns all Shape of a given slide that are "CountDown"
/// </summary>
/// <param name="slide">the slide to look into!</param>
/// <returns></returns>
IEnumerable<Shape> getCountDowns(Slide slide)
{
return slide.Shapes.OfType<Shape>().Where(s =>
{
return s.Tags[Constants.TimerGroup] == Constants.TimerGroupValue;
});
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}