1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team |
---|
2 | // |
---|
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this |
---|
4 | // software and associated documentation files (the "Software"), to deal in the Software |
---|
5 | // without restriction, including without limitation the rights to use, copy, modify, merge, |
---|
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons |
---|
7 | // to whom the Software is furnished to do so, subject to the following conditions: |
---|
8 | // |
---|
9 | // The above copyright notice and this permission notice shall be included in all copies or |
---|
10 | // substantial portions of the Software. |
---|
11 | // |
---|
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
---|
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
---|
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
---|
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
---|
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
17 | // DEALINGS IN THE SOFTWARE. |
---|
18 | |
---|
19 | using System; |
---|
20 | using System.Collections.Generic; |
---|
21 | using System.Windows; |
---|
22 | using System.Windows.Input; |
---|
23 | using System.Windows.Media; |
---|
24 | |
---|
25 | namespace ICSharpCode.AvalonEdit.Rendering |
---|
26 | { |
---|
27 | /// <summary> |
---|
28 | /// The control that contains the text. |
---|
29 | /// |
---|
30 | /// This control is used to allow other UIElements to be placed inside the TextView but |
---|
31 | /// behind the text. |
---|
32 | /// The text rendering process (VisualLine creation) is controlled by the TextView, this |
---|
33 | /// class simply displays the created Visual Lines. |
---|
34 | /// </summary> |
---|
35 | /// <remarks> |
---|
36 | /// This class does not contain any input handling and is invisible to hit testing. Input |
---|
37 | /// is handled by the TextView. |
---|
38 | /// This allows UIElements that are displayed behind the text, but still can react to mouse input. |
---|
39 | /// </remarks> |
---|
40 | sealed class TextLayer : Layer |
---|
41 | { |
---|
42 | /// <summary> |
---|
43 | /// the index of the text layer in the layers collection |
---|
44 | /// </summary> |
---|
45 | internal int index; |
---|
46 | |
---|
47 | public TextLayer(TextView textView) : base(textView, KnownLayer.Text) |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | List<VisualLineDrawingVisual> visuals = new List<VisualLineDrawingVisual>(); |
---|
52 | |
---|
53 | internal void SetVisualLines(ICollection<VisualLine> visualLines) |
---|
54 | { |
---|
55 | foreach (VisualLineDrawingVisual v in visuals) { |
---|
56 | if (v.VisualLine.IsDisposed) |
---|
57 | RemoveVisualChild(v); |
---|
58 | } |
---|
59 | visuals.Clear(); |
---|
60 | foreach (VisualLine newLine in visualLines) { |
---|
61 | VisualLineDrawingVisual v = newLine.Render(); |
---|
62 | if (!v.IsAdded) { |
---|
63 | AddVisualChild(v); |
---|
64 | v.IsAdded = true; |
---|
65 | } |
---|
66 | visuals.Add(v); |
---|
67 | } |
---|
68 | InvalidateArrange(); |
---|
69 | } |
---|
70 | |
---|
71 | protected override int VisualChildrenCount { |
---|
72 | get { return visuals.Count; } |
---|
73 | } |
---|
74 | |
---|
75 | protected override Visual GetVisualChild(int index) |
---|
76 | { |
---|
77 | return visuals[index]; |
---|
78 | } |
---|
79 | |
---|
80 | protected override void ArrangeCore(Rect finalRect) |
---|
81 | { |
---|
82 | textView.ArrangeTextLayer(visuals); |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|