forked from InteractiveComputerGraphics/Latex4CorelDRAW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectionHandler.cs
97 lines (88 loc) · 3.13 KB
/
SelectionHandler.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.PowerPoint;
namespace LatexAddin
{
public class SelectionHandler
{
Microsoft.Office.Interop.PowerPoint.EApplication_WindowSelectionChangeEventHandler m_eventHandler = null;
Microsoft.Office.Interop.PowerPoint.Shape m_oldShape = null;
public void init()
{
m_eventHandler = new Microsoft.Office.Interop.PowerPoint.EApplication_WindowSelectionChangeEventHandler(Application_WindowSelectionChange);
ThisAddIn.Current.Application.WindowSelectionChange += m_eventHandler;
}
public void cleanup()
{
ThisAddIn.Current.Application.WindowSelectionChange -= m_eventHandler;
}
void Application_WindowSelectionChange(Microsoft.Office.Interop.PowerPoint.Selection Sel)
{
Microsoft.Office.Interop.PowerPoint.Shape shape = null;
bool run = false;
if (Sel.Type == Microsoft.Office.Interop.PowerPoint.PpSelectionType.ppSelectionNone)
{
run = true;
}
else //if (Sel.Type == Microsoft.Office.Interop.PowerPoint.PpSelectionType.ppSelectionShapes)
{
if (Sel.ShapeRange.Count > 0)
{
shape = Sel.ShapeRange[1];
// Check if inline equation shape was selected
selectTextShape(shape);
if (shape != m_oldShape)
{
//removeInlineEquationShapes(shape);
run = true;
}
}
}
if (run)
{
if (m_oldShape != null)
{
InlineLatex.createInlineEquations(m_oldShape);
}
m_oldShape = shape;
}
}
/** Select the text shape if an inline equation shape was selected.
*/
private void selectTextShape(Shape eqShape)
{
// Check if inline equation shape was selected
int textShapeId = ShapeTags.getLatexTextShapeId(eqShape);
if (textShapeId != -1)
{
// Select corresponding text shape
Slide slide = (Slide)eqShape.Parent;
foreach (Shape s in slide.Shapes)
{
if (s.Id == textShapeId)
{
s.Select(Microsoft.Office.Core.MsoTriState.msoTrue);
}
}
}
}
private void removeInlineEquationShapes(Shape shape)
{
Slide slide = (Slide)shape.Parent;
List<Shape> toDelete = new List<Shape>();
foreach (Shape s in slide.Shapes)
{
if (ShapeTags.getLatexTextShapeId(s) == shape.Id)
{
toDelete.Add(s);
}
}
foreach (Shape s in toDelete)
{
s.Delete();
}
}
}
}