2
// TextSegmentMarker.cs
5
// Mike Krüger <mkrueger@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using Mono.TextEditor.Highlighting;
30
namespace Mono.TextEditor
32
public class TextSegmentMarker : TreeSegment
35
public virtual TextLineMarkerFlags Flags {
41
bool isVisible = true;
42
public virtual bool IsVisible {
43
get { return isVisible; }
44
set { isVisible = value; }
47
public TextSegmentMarker (int offset, int length) : base (offset, length)
51
public TextSegmentMarker (TextSegment textSegment) : base (textSegment)
55
public virtual void Draw (TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
59
public virtual ChunkStyle GetStyle (ChunkStyle baseStyle)
65
public interface IChunkMarker
67
void ChangeForeColor (TextEditor editor, Chunk chunk, ref Cairo.Color color);
70
public class UnderlineTextSegmentMarker : TextSegmentMarker
72
public UnderlineTextSegmentMarker (Cairo.Color color, TextSegment textSegment) : base (textSegment)
78
public UnderlineTextSegmentMarker (string colorName, TextSegment textSegment) : base (textSegment)
80
this.ColorName = colorName;
84
public string ColorName { get; set; }
85
public Cairo.Color Color { get; set; }
86
public bool Wave { get; set; }
88
public override void Draw (TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
90
int markerStart = Segment.Offset;
91
int markerEnd = Segment.EndOffset;
92
if (markerEnd < startOffset || markerStart > endOffset)
96
if (editor.IsSomethingSelected) {
97
var range = editor.SelectionRange;
98
if (range.Contains (markerStart)) {
99
int end = System.Math.Min (markerEnd, range.EndOffset);
100
InternalDraw (markerStart, end, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
101
InternalDraw (range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
104
if (range.Contains (markerEnd)) {
105
InternalDraw (markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
106
InternalDraw (range.Offset, markerEnd, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
109
if (markerStart <= range.Offset && range.EndOffset <= markerEnd) {
110
InternalDraw (markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
111
InternalDraw (range.Offset, range.EndOffset, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
112
InternalDraw (range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
118
InternalDraw (markerStart, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
121
void InternalDraw (int markerStart, int markerEnd, TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
123
if (markerStart >= markerEnd)
127
if (markerStart < startOffset && endOffset < markerEnd) {
131
int start = startOffset < markerStart ? markerStart : startOffset;
132
int end = endOffset < markerEnd ? endOffset : markerEnd;
133
int /*lineNr,*/ x_pos;
135
x_pos = layout.IndexToPos (start - startOffset).X;
136
@from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
138
x_pos = layout.IndexToPos (end - startOffset).X;
140
to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
142
@from = System.Math.Max (@from, editor.TextViewMargin.XOffset);
143
to = System.Math.Max (to, editor.TextViewMargin.XOffset);
147
double height = editor.LineHeight / 5;
149
cr.Color = editor.ColorStyle.SelectedText.Foreground;
151
cr.Color = ColorName == null ? Color : editor.ColorStyle.GetChunkStyle (ColorName).Foreground;
154
Pango.CairoHelper.ShowErrorUnderline (cr, @from, y + editor.LineHeight - height, to - @from, height);
157
cr.MoveTo (@from, y + editor.LineHeight - 1.5);
158
cr.LineTo (to, y + editor.LineHeight - 1.5);