Skip to content

Commit 84170b1

Browse files
FremyCompany_cpFremyCompany_cp
authored andcommitted
First working RowLayout + TextEdit + UnicodeGlyph (display+input), Selection partially implemented
1 parent f91fdbf commit 84170b1

21 files changed

+628
-136
lines changed

FC.MathEditor/WpfMathEditor/Classes/ChildrenHelper.vb

Lines changed: 276 additions & 56 deletions
Large diffs are not rendered by default.

FC.MathEditor/WpfMathEditor/Classes/ExportHelper.vb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@
185185
Private _LocationInParent As Rect
186186
Public ReadOnly Property LocationInParent As Rect
187187
Get
188-
PerformLayout()
189188
If This.Parent Is Nothing Then
190189
Return SizeRect
191190
Else
192-
Return _LocationInParent 'This.Parent.Export.GetChildLocation(This)
191+
This.Parent.Export.PerformLayout()
192+
Return _LocationInParent
193193
End If
194194
End Get
195195
End Property
@@ -202,6 +202,7 @@
202202
Get
203203
If This.Parent Is Nothing Then Return LocationInParent
204204

205+
This.Root.Export.PerformLayout()
205206
Dim L = LocationInParent
206207
Return FitRect(LocationInParent, This.Parent.Export.SizeRect, This.Parent.Export.LocationInRoot)
207208

FC.MathEditor/WpfMathEditor/Classes/InputHelper.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
End Function
8181

8282
Public Function ProcessChar_FromRight(ByVal InputChar As Integer) As Boolean
83-
Return ProcessChar_FromRight(InputChar)
83+
Return ProcessChar_FromRight_Internal(InputChar)
8484
End Function
8585

8686
Public Sub ProcessDelete()

FC.MathEditor/WpfMathEditor/Classes/MathElement.Input.vb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,8 @@
8989
_Children = GetInitialChildrenHelper()
9090
_Export = GetInitialExportHelper()
9191
_Input = GetInitialInputHelper()
92+
If _Input Is Nothing Then
93+
Trace.TraceError("Bug!")
94+
End If
9295
End Sub
9396
End Class

FC.MathEditor/WpfMathEditor/Classes/MathElement.XmlTree.vb

Lines changed: 148 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,111 @@ Partial Public MustInherit Class MathElement
99
'++
1010

1111
Private _Parent As MathElement
12-
Public Property Parent As MathElement
12+
13+
''' <summary>
14+
''' Returns the element which attached this element.
15+
''' </summary>
16+
Public ReadOnly Property Parent As MathElement
1317
Get
1418
Return _Parent
1519
End Get
16-
Set(ByVal value As MathElement)
17-
If _Parent IsNot Nothing Then
18-
' REMOVING THE CURRENT PARENT
19-
If value Is Nothing Then
20-
If Parent.Children.Contains(Me) Then
21-
Throw New InvalidOperationException("Reseting the Parent property wasn't posssible because the parent still claims it owns the current element.")
22-
Else
23-
24-
' Perform some cleanup
25-
_Parent = Nothing
26-
_ParentDocument = Nothing
27-
_Selection = Nothing
28-
29-
' Raise the corresponding event
30-
RaiseEvent RemovedFromParent(Me, EventArgs.Empty)
31-
32-
End If
33-
Else
34-
' TODO: Maybe we can check if value is _Parent before throwing
35-
' For now, we shall not do so, in order to find duplicate
36-
' code errors
37-
Throw New InvalidOperationException("Unable to modify the parent of an element after it has been set. Use Clone() to get a parent-free copy of this element, or remove it from its current parent.")
38-
End If
20+
End Property
21+
22+
''' <summary>
23+
''' Changes the Parent of NewChild to this element
24+
''' </summary>
25+
''' <param name="NewChild">The element to attach to this element</param>
26+
Public Sub Attach(ByVal NewChild As MathElement)
27+
If NewChild Is Nothing Then Throw New ArgumentNullException("NewChild", "The Attach method can't be used with a null argument.")
28+
NewChild.SetParent(Me)
29+
End Sub
30+
31+
''' <summary>
32+
''' Reset the Parent of Child to null.
33+
''' </summary>
34+
''' <param name="Child"></param>
35+
''' <remarks></remarks>
36+
Public Sub Detach(ByVal Child As MathElement)
37+
If Child.Parent Is Me Then Child.ResetParent() _
38+
Else Throw New ArgumentException("Child must be a child of this element.")
39+
End Sub
40+
41+
''' <summary>
42+
''' Changes the value of the Parent property of this element.
43+
''' </summary>
44+
''' <param name="value">The new value for the Parent property</param>
45+
''' <exception cref="InvalidOperationException">This functions throws an InvalidOperationException when this element already have a parent.</exception>
46+
''' <exception cref="ArgumentException">This functions throws an ArgumentException when this element can't have 'value' as parent.</exception>
47+
Private Sub SetParent(ByVal value As MathElement)
48+
If _Parent IsNot Nothing Then
49+
50+
If value Is _Parent Then
51+
52+
#If DEBUG Then
53+
' DON'T DO ANYTHING
54+
Trace.TraceWarning("Multiple refefinition of the Parent property of an element. Spaghetti code suspected.")
55+
#End If
56+
3957
Else
40-
' ADDING A NEW PARENT
41-
If value.Children.IsValidChild(Me) Then
4258

43-
' Perform the change
44-
_Parent = value
59+
' REMOVE THE CURRENT PARENT, AND RETRY
60+
Try
4561

46-
' Raise the corresponding event
47-
RaiseEvent AttachedToParent(Me, EventArgs.Empty)
62+
ResetParent()
63+
SetParent(value)
64+
65+
Catch ex As Exception
66+
67+
Throw New InvalidOperationException("Unable to modify the parent of an element after it has been added to a children list. Please remove this element from its parent, or use the Clone() function to get a parent-free copy of this element.", ex)
68+
69+
End Try
4870

49-
Else
50-
Throw New ArgumentException("This element is not recognised as a valid child of its new parent.", "Parent")
51-
End If
5271
End If
53-
End Set
54-
End Property
5572

73+
Else
74+
75+
' ADD THE NEW PARENT
76+
If value.Children.CanContains(Me) Then
77+
78+
' Perform the change
79+
_Parent = value
80+
81+
' Raise the corresponding event
82+
RaiseEvent AttachedToParent(Me, EventArgs.Empty)
83+
84+
Else
85+
Throw New ArgumentException("This element is not recognised as a valid child of its new parent.", "Parent")
86+
End If
87+
88+
End If
89+
End Sub
90+
91+
''' <summary>
92+
''' Resets the Parent property for this element.
93+
''' </summary>
94+
Private Sub ResetParent()
95+
96+
If Parent.Children.Contains(Me) Then
97+
98+
Throw New InvalidOperationException("Reseting the Parent property wasn't posssible because the parent still claims it owns the current element.")
99+
100+
Else
101+
102+
' Perform some cleanup
103+
_Parent = Nothing
104+
_ParentDocument = Nothing
105+
_Selection = Nothing
106+
107+
' Raise the corresponding event
108+
RaiseDetachedFromParent()
109+
110+
End If
111+
112+
End Sub
113+
114+
''' <summary>
115+
''' Returns the last element in the Parent chain. If this element is hosted in a document, this function returns the same as ParentDocument.
116+
''' </summary>
56117
Public ReadOnly Property Root As MathElement
57118
Get
58119
If _ParentDocument IsNot Nothing Then Return _ParentDocument
@@ -62,6 +123,10 @@ Partial Public MustInherit Class MathElement
62123
End Property
63124

64125
Private _ParentDocument As MathDocument
126+
127+
''' <summary>
128+
''' Returns the document that host this element, or Nothing if this element is not currently hosted.
129+
''' </summary>
65130
Public ReadOnly Property ParentDocument As MathDocument
66131
Get
67132

@@ -134,7 +199,6 @@ Partial Public MustInherit Class MathElement
134199
Protected _Children As ChildrenHelper
135200
Public ReadOnly Property Children As ChildrenHelper
136201
Get
137-
If _Children Is Nothing Then _Children = Nothing
138202
Return _Children
139203
End Get
140204
End Property
@@ -244,18 +308,64 @@ Partial Public MustInherit Class MathElement
244308

245309
' TODO: RemovedFromParent
246310
Public Event AttachedToParent As EventHandler
311+
Public Sub RaiseAttachedToParent()
312+
RaiseEvent AttachedToParent(Me, EventArgs.Empty)
313+
End Sub
314+
315+
Public Event AddedToParent As EventHandler
316+
Public Sub RaiseAddedToParent()
317+
RaiseEvent AddedToParent(Me, EventArgs.Empty)
318+
End Sub
319+
247320
Public Event RemovedFromParent As EventHandler
321+
Public Sub RaiseRemovedFromParent()
322+
RaiseEvent RemovedFromParent(Me, EventArgs.Empty)
323+
End Sub
324+
325+
Public Event DetachedFromParent As EventHandler
326+
Public Sub RaiseDetachedFromParent()
327+
RaiseEvent DetachedFromParent(Me, EventArgs.Empty)
328+
End Sub
329+
330+
Public Event DetachedFromDocument As EventHandler
331+
Public Sub RaiseDetachedFromDocument()
332+
RaiseEvent DetachedFromDocument(Me, EventArgs.Empty)
333+
End Sub
248334

249335
Public Event ChildAdded As EventHandler(Of TreeEventArgs)
336+
Public Sub RaiseChildAdded(ByVal Child As MathElement)
337+
RaiseEvent ChildAdded(Me, New TreeEventArgs(Child))
338+
End Sub
339+
250340
Public Event ChildRemoved As EventHandler(Of TreeEventArgs)
341+
Public Sub RaiseChildRemoved(ByVal Child As MathElement)
342+
RaiseEvent ChildRemoved(Me, New TreeEventArgs(Child))
343+
End Sub
251344

252345
Public Class TreeEventArgs : Inherits EventArgs
253-
254346
Public Property Argument As MathElement
255347
Public Sub New(ByVal Argument As MathElement)
256348
Me.Argument = Argument
257349
End Sub
258-
259350
End Class
260351

352+
Private Sub MathElement_ChildAdded(ByVal sender As Object, ByVal e As TreeEventArgs) Handles Me.ChildAdded
353+
e.Argument.RaiseAddedToParent()
354+
End Sub
355+
356+
Private Sub MathElement_ChildRemoved(ByVal sender As Object, ByVal e As TreeEventArgs) Handles Me.ChildRemoved
357+
e.Argument.RaiseRemovedFromParent()
358+
End Sub
359+
360+
Private Sub MathElement_DetachedFromDocument(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DetachedFromDocument
361+
_ParentDocument = Nothing
362+
_Selection = Nothing
363+
End Sub
364+
365+
Private Sub MathElement_DetachedFromParent(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DetachedFromParent
366+
RaiseDetachedFromDocument()
367+
For Each Child In Children
368+
Child.RaiseDetachedFromDocument()
369+
Next
370+
End Sub
261371
End Class

FC.MathEditor/WpfMathEditor/Classes/SelectionHelper.vb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Partial Public Class SelectionHelper
2+
Implements IEnumerable(Of MathElement)
23

34
Private This As MathDocument
45
Public Sub New(ByVal This As MathDocument)
@@ -39,7 +40,6 @@
3940
SetSelection(CommonAncestror, NewChild, SelectionEnd)
4041
End Sub
4142

42-
4343
Private Sub SetSelection(ByVal StartPoint As Selection, ByVal EndPoint As Selection)
4444

4545
' Compute _Selection
@@ -207,4 +207,11 @@
207207
RTL = -1
208208
End Enum
209209

210+
Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of MathElement) Implements System.Collections.Generic.IEnumerable(Of MathElement).GetEnumerator
211+
Return GetSelectedElements().GetEnumerator()
212+
End Function
213+
214+
Private Function GetGenericEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
215+
Return GetEnumerator()
216+
End Function
210217
End Class

FC.MathEditor/WpfMathEditor/EquationEditor.vbproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<Compile Include="TextEdit\TextEdit.vb" />
131131
<Compile Include="TextEdit\TextEditChildrenHelper.vb" />
132132
<Compile Include="TextEdit\TextEditInputHelper.vb" />
133+
<Compile Include="TextEdit\TextEditExportHelper.vb" />
133134
<Compile Include="UserControl\GlyphDisplayer.xaml.vb">
134135
<DependentUpon>GlyphDisplayer.xaml</DependentUpon>
135136
</Compile>

FC.MathEditor/WpfMathEditor/Glyphs/GlyphChildrenHelper.vb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
Return InvalidCall()
2121
End Function
2222

23-
Public Overrides Function Contains(ByVal Element As MathElement) As Boolean
24-
Return False
25-
End Function
26-
2723
Public Overrides Function IndexOf(ByVal Element As MathElement) As Integer
2824
Return -1
2925
End Function
@@ -72,4 +68,14 @@
7268
InvalidCall()
7369
End Sub
7470

71+
Protected Overrides Function Contains_Internal(ByVal Element As MathElement) As Boolean
72+
Return False
73+
End Function
74+
75+
Public Overrides ReadOnly Property Last As MathElement
76+
Get
77+
Return Nothing
78+
End Get
79+
End Property
80+
7581
End Class

FC.MathEditor/WpfMathEditor/Glyphs/UnicodeGlyph.vb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
End Function
4747

4848
Protected Overrides Function GetInitialInputHelper() As InputHelper
49-
' TODO: InputHelper for UnicodeGlyph!
50-
Return Nothing
49+
Return New UnicodeGlyphInputHelper(Me)
5150
End Function
5251
End Class
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
Public Class UnicodeGlyphInputHelper
1+
Public Class UnicodeGlyphInputHelper : Inherits InputHelper
22

3+
Public Sub New(ByVal This As UnicodeGlyph)
4+
MyBase.New(This)
5+
End Sub
36

7+
Public Overrides Function ProcessChar_Internal(ByVal InputChar As Integer) As Boolean
8+
Return False
9+
End Function
410

511
End Class

0 commit comments

Comments
 (0)