137
132
textEditor.Document.LineChanged += TextEditorDocumentLineChanged;
138
133
textEditor.GetTextEditorData ().SearchChanged += HandleSearchChanged;
139
134
markerLayout = PangoUtil.CreateLayout (textEditor);
135
defaultLayout = PangoUtil.CreateLayout (textEditor);
141
137
textEditor.Document.EndUndo += HandleEndUndo;
142
138
textEditor.SelectionChanged += UpdateBracketHighlighting;
143
139
textEditor.Document.Undone += HandleUndone;
144
140
textEditor.Document.Redone += HandleUndone;
141
textEditor.TextArea.FocusInEvent += HandleFocusInEvent;
142
textEditor.TextArea.FocusOutEvent += HandleFocusOutEvent;
146
143
Caret.PositionChanged += UpdateBracketHighlighting;
147
144
textEditor.VScroll += HandleVAdjustmentValueChanged;
147
void HandleFocusInEvent (object o, FocusInEventArgs args)
149
selectionColor = ColorStyle.SelectedText;
150
currentLineColor = ColorStyle.LineMarker;
153
void HandleFocusOutEvent (object o, FocusOutEventArgs args)
155
selectionColor = ColorStyle.SelectedInactiveText;
156
currentLineColor = ColorStyle.LineMarkerInactive;
150
159
void HandleUndone (object sender, EventArgs e)
152
161
UpdateBracketHighlighting (this, EventArgs.Empty);
415
428
highlightBracketWorker = null;
431
Pango.Rectangle unixEolLayoutRect;
432
Pango.Rectangle macEolLayoutRect;
433
Pango.Rectangle windowsEolLayoutRect;
434
Pango.Rectangle eofEolLayoutRect;
418
436
protected internal override void OptionsChanged ()
422
markerLayout.FontDescription = textEditor.Options.Font;
440
var markerFont = textEditor.Options.Font.Copy ();
441
markerFont.Size = markerFont.Size * 8 / 10;
442
markerLayout.FontDescription = markerFont;
423
443
markerLayout.FontDescription.Weight = Pango.Weight.Normal;
424
markerLayout.FontDescription.Style = Pango.Style.Italic;
425
markerLayout.SetText ("_");
427
markerLayout.GetSize (out w, out h);
429
this.charWidth = w / Pango.Scale.PangoScale;
444
markerLayout.FontDescription.Style = Pango.Style.Normal;
430
446
if (textEditor.preeditString != null && textEditor.preeditAttrs != null) {
431
447
using (var preeditLayout = PangoUtil.CreateLayout (textEditor)) {
432
448
preeditLayout.SetText (textEditor.preeditString);
433
449
preeditLayout.Attributes = textEditor.preeditAttrs;
434
preeditLayout.GetSize (out w, out h);
437
this.textEditor.GetTextEditorData ().LineHeight = System.Math.Ceiling (h / Pango.Scale.PangoScale);
439
markerLayout.FontDescription.Weight = Pango.Weight.Normal;
441
Pango.Font font = textEditor.PangoContext.LoadFont (markerLayout.FontDescription);
443
Pango.FontMetrics metrics = font.GetMetrics (null);
453
defaultLayout.FontDescription = textEditor.Options.Font;
454
using (var metrics = textEditor.PangoContext.GetMetrics (textEditor.Options.Font, textEditor.PangoContext.Language)) {
455
this.textEditor.GetTextEditorData ().LineHeight = System.Math.Ceiling (0.5 + (metrics.Ascent + metrics.Descent) / Pango.Scale.PangoScale);
444
456
this.charWidth = metrics.ApproximateCharWidth / Pango.Scale.PangoScale;
459
// Gutter font may be bigger
460
using (var metrics = textEditor.PangoContext.GetMetrics (textEditor.Options.GutterFont, textEditor.PangoContext.Language)) {
461
this.textEditor.GetTextEditorData ().LineHeight = System.Math.Max (this.textEditor.GetTextEditorData ().LineHeight, System.Math.Ceiling (0.5 + (metrics.Ascent + metrics.Descent) / Pango.Scale.PangoScale));
449
464
textEditor.LineHeight = System.Math.Max (1, LineHeight);
451
if (textEditor.Options.ShowInvalidLines && invalidLineLayout == null) {
452
invalidLineLayout = PangoUtil.CreateLayout (textEditor);
453
invalidLineLayout.SetText ("~");
456
if (invalidLineLayout != null)
457
invalidLineLayout.FontDescription = textEditor.Options.Font;
459
if (textEditor.Options.ShowEolMarkers && unixEolLayout == null) {
466
if (unixEolLayout == null) {
460
467
unixEolLayout = PangoUtil.CreateLayout (textEditor);
461
unixEolLayout.SetText ("\\n");
462
468
macEolLayout = PangoUtil.CreateLayout (textEditor);
463
macEolLayout.SetText ("\\r");
464
windowEolLayout = PangoUtil.CreateLayout (textEditor);
465
windowEolLayout.SetText ("\\r\\n");
469
windowsEolLayout = PangoUtil.CreateLayout (textEditor);
466
470
eofEolLayout = PangoUtil.CreateLayout (textEditor);
467
eofEolLayout.SetText ("<EOF>");
470
if (unixEolLayout != null)
471
unixEolLayout.FontDescription = macEolLayout.FontDescription = windowEolLayout.FontDescription = eofEolLayout.FontDescription = textEditor.Options.Font;
473
if (textEditor.Options.ShowTabs && tabMarkerLayout == null) {
474
tabMarkerLayout = PangoUtil.CreateLayout (textEditor);
475
tabMarkerLayout.SetText ("Ā»");
477
if (tabMarkerLayout != null)
478
tabMarkerLayout.FontDescription = textEditor.Options.Font;
480
if (textEditor.Options.ShowSpaces && spaceMarkerLayout == null) {
481
spaceMarkerLayout = PangoUtil.CreateLayout (textEditor);
482
spaceMarkerLayout.SetText ("Ā·");
484
if (spaceMarkerLayout != null)
485
spaceMarkerLayout.FontDescription = textEditor.Options.Font;
487
DecorateLineFg -= DecorateTabs;
488
DecorateLineFg -= DecorateSpaces;
489
DecorateLineFg -= DecorateTabsAndSpaces;
491
if (textEditor.Options.ShowTabs && textEditor.Options.ShowSpaces) {
492
DecorateLineFg += DecorateTabsAndSpaces;
493
} else if (textEditor.Options.ShowTabs) {
494
DecorateLineFg += DecorateTabs;
495
} else if (textEditor.Options.ShowSpaces) {
496
DecorateLineFg += DecorateSpaces;
473
var font = textEditor.Options.Font.Copy ();
474
font.Size = font.Size * 3 / 4;
475
unixEolLayout.FontDescription = macEolLayout.FontDescription = windowsEolLayout.FontDescription = eofEolLayout.FontDescription = font;
477
unixEolLayout.SetText ("\\n");
478
Pango.Rectangle logRect;
479
unixEolLayout.GetPixelExtents (out logRect, out unixEolLayoutRect);
481
macEolLayout.SetText ("\\r");
482
macEolLayout.GetPixelExtents (out logRect, out macEolLayoutRect);
484
windowsEolLayout.SetText ("\\r\\n");
485
windowsEolLayout.GetPixelExtents (out logRect, out windowsEolLayoutRect);
487
eofEolLayout.SetText ("<EOF>");
488
eofEolLayout.GetPixelExtents (out logRect, out eofEolLayoutRect);
499
490
DecorateLineBg -= DecorateMatchingBracket;
500
491
if (textEditor.Options.HighlightMatchingBracket && !Document.ReadOnly)
501
492
DecorateLineBg += DecorateMatchingBracket;
595
590
bool UpdateCaret ()
597
592
caretBlink = !caretBlink;
598
// int multiplier = caretBlink ? cursorOnMultiplier : cursorOffMultiplier;
601
DrawCaret (textEditor.GdkWindow, textEditor.Allocation);
603
textEditor.QueueDrawArea (caretRectangle.X,
604
(int)(caretRectangle.Y + (textEditor.VAdjustment.Value - caretVAdjustmentValue)),
605
caretRectangle.Width,
606
caretRectangle.Height);
593
textEditor.TextArea.QueueDrawArea (caretRectangle.X - (int)textEditor.Options.Zoom,
594
(int)(caretRectangle.Y + (textEditor.VAdjustment.Value - caretVAdjustmentValue)),
595
caretRectangle.Width + 2 * (int)textEditor.Options.Zoom,
596
caretRectangle.Height);
597
OnCaretBlink (EventArgs.Empty);
601
internal event EventHandler CaretBlink;
602
void OnCaretBlink (EventArgs e)
604
var handler = CaretBlink;
612
610
internal double caretX;
613
611
internal double caretY;
613
public Cairo.PointD CaretVisualLocation {
615
return new Cairo.PointD (caretX, caretY);
615
619
void SetVisibleCaretPosition (double x, double y)
617
621
if (x == caretX && y == caretY)
669
664
if (win == null || Settings.Default.CursorBlink && !Caret.IsVisible || !caretBlink)
671
666
using (Cairo.Context cr = Gdk.CairoHelper.Create (win)) {
672
cr.LineWidth = textEditor.Options.Zoom;
667
cr.Rectangle (XOffset, 0, textEditor.Allocation.Width - XOffset, textEditor.Allocation.Height);
669
cr.LineWidth = System.Math.Max (1, System.Math.Floor (textEditor.Options.Zoom));
673
670
cr.Antialias = Cairo.Antialias.None;
674
671
var curRect = new Gdk.Rectangle ((int)caretX, (int)caretY, (int)this.charWidth, (int)LineHeight - 1);
675
672
if (curRect != caretRectangle) {
676
673
caretRectangle = curRect;
677
textEditor.QueueDrawArea (caretRectangle.X,
674
textEditor.TextArea.QueueDrawArea (caretRectangle.X - (int)textEditor.Options.Zoom,
678
675
(int)(caretRectangle.Y + (-textEditor.VAdjustment.Value + caretVAdjustmentValue)),
679
caretRectangle.Width + 1,
676
caretRectangle.Width + (int)textEditor.Options.Zoom,
680
677
caretRectangle.Height + 1);
681
678
caretVAdjustmentValue = textEditor.VAdjustment.Value;
683
cr.Color = textEditor.ColorStyle.Default.CairoColor;
682
var fgColor = textEditor.ColorStyle.PlainText.Foreground;
683
// var bgColor = textEditor.ColorStyle.Default.CairoBackgroundColor;
684
var line = Document.GetLine (Caret.Line);
686
foreach (var marker in line.Markers) {
687
var style = marker as StyleTextLineMarker;
690
// if (style.IncludedStyles.HasFlag (StyleTextLineMarker.StyleFlag.BackgroundColor))
691
// bgColor = style.BackgroundColor;
692
if (style.IncludedStyles.HasFlag (StyleTextLineMarker.StyleFlag.Color))
693
fgColor = style.Color;
697
var foreground = ((HslColor)fgColor).ToPixel ();
698
var background = ((HslColor)color).ToPixel ();
699
var caretColor = (foreground ^ background) & 0xFFFFFF;
700
color = HslColor.FromPixel (caretColor);*/
684
703
switch (Caret.Mode) {
685
704
case CaretMode.Insert:
686
cr.DrawLine (textEditor.ColorStyle.Default.CairoColor,
687
706
caretRectangle.X + 0.5,
688
707
caretRectangle.Y + 0.5,
689
708
caretRectangle.X + 0.5,
690
709
caretRectangle.Y + caretRectangle.Height);
692
711
case CaretMode.Block:
693
713
cr.Rectangle (caretRectangle.X + 0.5, caretRectangle.Y + 0.5, caretRectangle.Width, caretRectangle.Height);
695
715
char caretChar = GetCaretChar ();
852
877
var wrapper = new LayoutWrapper (PangoUtil.CreateLayout (textEditor));
853
878
wrapper.IsUncached = containsPreedit;
855
879
if (logicalRulerColumn < 0)
856
880
logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn);
857
881
var atts = new FastPangoAttrList ();
858
882
wrapper.Layout.Alignment = Pango.Alignment.Left;
859
883
wrapper.Layout.FontDescription = textEditor.Options.Font;
860
884
wrapper.Layout.Tabs = tabArray;
885
if (textEditor.Options.WrapLines) {
886
wrapper.Layout.Wrap = Pango.WrapMode.WordChar;
887
wrapper.Layout.Width = (int)((textEditor.Allocation.Width - XOffset - TextStartPosition) * Pango.Scale.PangoScale);
861
889
StringBuilder textBuilder = new StringBuilder ();
862
890
var chunks = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, offset, length);
891
wrapper.Chunks = chunks;
863
892
foreach (var chunk in chunks) {
865
894
textBuilder.Append (Document.GetTextAt (chunk));
904
933
var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
905
934
var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
906
atts.AddForegroundAttribute (chunkStyle.Color, si, ei);
935
var color = ColorStyle.GetForeground (chunkStyle);
936
foreach (var marker in markers) {
937
var chunkMarker = marker as IChunkMarker;
938
if (chunkMarker == null)
940
chunkMarker.ChangeForeColor (textEditor, chunk, ref color);
942
atts.AddForegroundAttribute ((HslColor)color, si, ei);
908
if (!chunkStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (chunkStyle.BackgroundColor)) {
909
wrapper.AddBackground (chunkStyle.CairoBackgroundColor, (int)si, (int)ei);
944
if (!chunkStyle.TransparentBackground && GetPixel (ColorStyle.PlainText.Background) != GetPixel (chunkStyle.Background)) {
945
wrapper.AddBackground (chunkStyle.Background, (int)si, (int)ei);
910
946
} else if (chunk.SpanStack != null && ColorStyle != null) {
911
947
foreach (var span in chunk.SpanStack) {
948
if (span == null || string.IsNullOrEmpty (span.Color))
914
950
var spanStyle = ColorStyle.GetChunkStyle (span.Color);
915
if (!spanStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (spanStyle.BackgroundColor)) {
916
wrapper.AddBackground (spanStyle.CairoBackgroundColor, (int)si, (int)ei);
951
if (spanStyle != null && !spanStyle.TransparentBackground && GetPixel (ColorStyle.PlainText.Background) != GetPixel (spanStyle.Background)) {
952
wrapper.AddBackground (spanStyle.Background, (int)si, (int)ei);
936
979
var translatedStartIndex = TranslateToUTF8Index (lineChars, (uint)startIndex, ref curChunkIndex, ref byteChunkIndex);
937
980
var translatedEndIndex = TranslateToUTF8Index (lineChars, (uint)endIndex, ref curChunkIndex, ref byteChunkIndex);
940
atts.AddWeightAttribute (Pango.Weight.Bold, translatedStartIndex, translatedEndIndex);
982
if (chunkStyle.FontWeight != Xwt.Drawing.FontWeight.Normal)
983
atts.AddWeightAttribute ((Pango.Weight)chunkStyle.FontWeight, translatedStartIndex, translatedEndIndex);
942
if (chunkStyle.Italic)
943
atts.AddStyleAttribute (Pango.Style.Italic, translatedStartIndex, translatedEndIndex);
985
if (chunkStyle.FontStyle != Xwt.Drawing.FontStyle.Normal)
986
atts.AddStyleAttribute ((Pango.Style)chunkStyle.FontStyle, translatedStartIndex, translatedEndIndex);
945
988
if (chunkStyle.Underline)
946
989
atts.AddUnderlineAttribute (Pango.Underline.Single, translatedStartIndex, translatedEndIndex);
1207
public delegate void LineDecorator (Cairo.Context ctx, LayoutWrapper layout, int offset, int length, double xPos, double y, int selectionStart, int selectionEnd);
1291
public delegate void LineDecorator (Cairo.Context ctx,LayoutWrapper layout,int offset,int length,double xPos,double y,int selectionStart,int selectionEnd);
1208
1293
public event LineDecorator DecorateLineBg;
1209
public event LineDecorator DecorateLineFg;
1211
void DrawSpaceMarker (Cairo.Context cr, bool selected, double x, double y)
1214
cr.Translate (x, y);
1215
cr.ShowLayout (spaceMarkerLayout);
1219
void DecorateSpaces (Cairo.Context ctx, LayoutWrapper layout, int offset, int length, double xPos, double y, int selectionStart, int selectionEnd)
1221
uint curIndex = 0, byteIndex = 0;
1222
bool first = true, oldSelected = false;
1223
int index, trailing;
1224
layout.Layout.XyToIndex ((int)textEditor.HAdjustment.Value, 0, out index, out trailing);
1226
for (int i = index; i < layout.LineChars.Length; i++) {
1227
if (layout.LineChars [i] == ' ') {
1228
bool selected = selectionStart <= offset + i && offset + i < selectionEnd;
1229
if (first || oldSelected != selected) {
1230
ctx.Color = selected ? SelectionColor.CairoColor : ColorStyle.WhitespaceMarker;
1232
oldSelected = selected;
1234
Pango.Rectangle pos = layout.Layout.IndexToPos ((int)TranslateToUTF8Index (layout.LineChars, (uint)i, ref curIndex, ref byteIndex));
1235
double xpos = xPos + pos.X / Pango.Scale.PangoScale;
1236
if (xpos > textEditor.Allocation.Width)
1238
DrawSpaceMarker (ctx, selected, xpos, y);
1243
void DrawTabMarker (Cairo.Context cr, bool selected, double x, double y)
1246
cr.Translate (x, y);
1247
cr.ShowLayout (tabMarkerLayout);
1251
void DecorateTabs (Cairo.Context ctx, LayoutWrapper layout, int offset, int length, double xPos, double y, int selectionStart, int selectionEnd)
1253
uint curIndex = 0, byteIndex = 0;
1254
bool first = true, oldSelected = false;
1255
int index, trailing;
1256
layout.Layout.XyToIndex ((int)textEditor.HAdjustment.Value, 0, out index, out trailing);
1258
for (int i = index; i < layout.LineChars.Length; i++) {
1259
if (layout.LineChars[i] == '\t') {
1260
bool selected = selectionStart <= offset + i && offset + i < selectionEnd;
1261
if (first || oldSelected != selected) {
1262
ctx.Color = selected ? SelectionColor.CairoColor : ColorStyle.WhitespaceMarker;
1264
oldSelected = selected;
1266
Pango.Rectangle pos = layout.Layout.IndexToPos ((int)TranslateToUTF8Index (layout.LineChars, (uint)i, ref curIndex, ref byteIndex));
1267
double xpos = xPos + pos.X / Pango.Scale.PangoScale;
1268
if (xpos > textEditor.Allocation.Width)
1270
DrawTabMarker (ctx, selected, xpos, y);
1295
void DrawSpaceMarker (Cairo.Context cr, bool selected, double x, double x2, double y)
1297
var d = textEditor.Options.Zoom * 2;
1298
var py = (int)(y + (LineHeight - d) / 2);
1299
cr.Rectangle (x + (x2 - x - d) / 2, py, d, d);
1303
void DrawTabMarker (Cairo.Context cr, bool selected, double x, double x2, double y)
1305
var py = (int)(y + LineHeight / 2);
1306
cr.MoveTo (0.5 + x, 0.5 + py);
1307
cr.LineTo (0.5 + x2 - charWidth / 2, 0.5 + py);
1311
const double whitespaceMarkerAlpha = 0.3;
1275
1313
void DecorateTabsAndSpaces (Cairo.Context ctx, LayoutWrapper layout, int offset, int length, double xPos, double y, int selectionStart, int selectionEnd)
1278
1316
bool first = true, oldSelected = false;
1279
1317
int index, trailing;
1280
1318
layout.Layout.XyToIndex ((int)textEditor.HAdjustment.Value, 0, out index, out trailing);
1319
var curchunk = layout.Chunks != null ? layout.Chunks.FirstOrDefault () : null;
1282
1320
for (int i = index; i < layout.LineChars.Length; i++) {
1283
1321
char ch = layout.LineChars [i];
1284
1322
if (ch != ' ' && ch != '\t')
1324
if (ch == ' ' && !textEditor.Options.IncludeWhitespaces.HasFlag (IncludeWhitespaces.Space))
1326
if (ch == '\t' && !textEditor.Options.IncludeWhitespaces.HasFlag (IncludeWhitespaces.Tab))
1286
1328
bool selected = selectionStart <= offset + i && offset + i < selectionEnd;
1287
1329
if (first || oldSelected != selected) {
1288
ctx.Color = selected ? SelectionColor.CairoColor : ColorStyle.WhitespaceMarker;
1290
1331
oldSelected = selected;
1333
if (!selected && textEditor.Options.ShowWhitespaces != ShowWhitespaces.Always)
1292
1335
Pango.Rectangle pos = layout.Layout.IndexToPos ((int)TranslateToUTF8Index (layout.LineChars, (uint)i, ref curIndex, ref byteIndex));
1293
1336
double xpos = xPos + pos.X / Pango.Scale.PangoScale;
1294
1337
if (xpos > textEditor.Allocation.Width)
1339
Pango.Rectangle pos2 = layout.Layout.IndexToPos ((int)TranslateToUTF8Index (layout.LineChars, (uint)i + 1, ref curIndex, ref byteIndex));
1340
double xpos2 = xPos + pos2.X / Pango.Scale.PangoScale;
1341
Cairo.Color col = new Cairo.Color (0, 0, 0);
1342
if (SelectionColor.TransparentForeground) {
1343
while (curchunk != null && curchunk.EndOffset < offset + i)
1344
curchunk = curchunk.Next;
1345
if (curchunk != null && curchunk.SpanStack.Count > 0 && curchunk.SpanStack.Peek ().Color != "Plain Text") {
1346
var chunkStyle = ColorStyle.GetChunkStyle (curchunk.SpanStack.Peek ().Color);
1347
if (chunkStyle != null)
1348
col = ColorStyle.GetForeground (chunkStyle);
1350
col = ColorStyle.PlainText.Foreground;
1353
col = selected ? SelectionColor.Foreground : col = ColorStyle.PlainText.Foreground;
1355
ctx.Color = new Cairo.Color (col.R, col.G, col.B, whitespaceMarkerAlpha);
1296
1357
if (ch == '\t') {
1297
DrawTabMarker (ctx, selected, xpos, y);
1358
DrawTabMarker (ctx, selected, xpos, xpos2, y);
1299
DrawSpaceMarker (ctx, selected, xpos, y);
1360
DrawSpaceMarker (ctx, selected, xpos, xpos2, y);
1325
1386
return CreateLinePartLayout (mode, line, line.Offset, line.Length, -1, -1);
1328
public void DrawCaretLineMarker (Cairo.Context cr, double xPos, double y, double width)
1389
public void DrawCaretLineMarker (Cairo.Context cr, double xPos, double y, double width, double lineHeight)
1330
cr.Rectangle (xPos, y, width, LineHeight);
1331
var color = ColorStyle.LineMarker;
1332
cr.Color = new Cairo.Color (color.R, color.G, color.B, 0.5);
1391
if (BackgroundRenderer != null)
1393
xPos = System.Math.Floor (xPos);
1394
cr.Rectangle (xPos, y, width, lineHeight);
1395
var color = CurrentLineColor;
1396
cr.Color = color.Color;
1334
1398
double halfLine = (cr.LineWidth / 2.0);
1335
1399
cr.MoveTo (xPos, y + halfLine);
1336
1400
cr.LineTo (xPos + width, y + halfLine);
1337
cr.MoveTo (xPos, y + LineHeight - halfLine);
1338
cr.LineTo (xPos + width, y + LineHeight - halfLine);
1401
cr.MoveTo (xPos, y + lineHeight - halfLine);
1402
cr.LineTo (xPos + width, y + lineHeight - halfLine);
1403
cr.Color = color.SecondColor;
1343
void DrawLinePart (Cairo.Context cr, DocumentLine line, int lineNumber, int logicalRulerColumn, int offset, int length, ref double pangoPosition, ref bool isSelectionDrawn, double y, double maxX)
1407
void DrawIndent (Cairo.Context cr, LayoutWrapper layout, DocumentLine line, double xPos, double y)
1409
if (!textEditor.Options.DrawIndentationMarkers)
1411
if (line.Length == 0) {
1412
var nextLine = line.NextLine;
1413
while (nextLine != null && nextLine.Length == 0)
1414
nextLine = nextLine.NextLine;
1415
if (nextLine != null)
1416
layout = GetLayout (nextLine);
1418
if (layout.IndentSize == 0)
1421
var dotted = new [] { textEditor.Options.Zoom };
1422
cr.SetDash (dotted, (int)y + textEditor.VAdjustment.Value);
1424
var bottom = y + LineHeight;
1425
if (Caret.Line == line.LineNumber && textEditor.Options.HighlightCaretLine) {
1426
top += textEditor.Options.Zoom;
1427
bottom -= textEditor.Options.Zoom;
1429
for (int i = 0; i < layout.IndentSize; i += textEditor.Options.IndentationSize) {
1430
var x = System.Math.Floor (xPos + i * charWidth);
1431
cr.MoveTo (x + 0.5, top);
1432
cr.LineTo (x + 0.5, bottom);
1434
cr.Color = ColorStyle.IndentationGuide.Color;
1440
void DrawLinePart (Cairo.Context cr, DocumentLine line, int lineNumber, int logicalRulerColumn, int offset, int length, ref double pangoPosition, ref bool isSelectionDrawn, double y, double maxX, double _lineHeight)
1345
1442
ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document);
1346
1443
int selectionStart;
1357
1454
double width = layout.PangoWidth / Pango.Scale.PangoScale;
1358
1455
double xPos = pangoPosition / Pango.Scale.PangoScale;
1457
// The caret line marker must be drawn below the text markers otherwise the're invisible
1458
if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber)
1459
DrawCaretLineMarker (cr, xPos, y, layout.PangoWidth / Pango.Scale.PangoScale, _lineHeight);
1360
1461
// if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Document.GetLine(Caret.Line) != line) {
1361
foreach (var bg in layout.BackgroundColors) {
1363
x1 = layout.Layout.IndexToPos (bg.FromIdx).X;
1364
x2 = layout.Layout.IndexToPos (bg.ToIdx).X;
1365
DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition,
1366
new Cairo.Rectangle ((x1 + pangoPosition) / Pango.Scale.PangoScale, y, (x2 - x1) / Pango.Scale.PangoScale + 1, LineHeight),
1462
if (BackgroundRenderer == null) {
1463
foreach (var bg in layout.BackgroundColors) {
1465
x1 = layout.Layout.IndexToPos (bg.FromIdx).X;
1466
x2 = layout.Layout.IndexToPos (bg.ToIdx).X;
1467
DrawRectangleWithRuler (
1468
cr, xPos + textEditor.HAdjustment.Value - TextStartPosition,
1469
new Cairo.Rectangle ((x1 + pangoPosition) / Pango.Scale.PangoScale, y, (x2 - x1) / Pango.Scale.PangoScale + 1, _lineHeight),
1367
1470
bg.Color, true);
1371
1475
bool drawBg = true;
1372
1476
bool drawText = true;
1373
foreach (TextMarker marker in line.Markers) {
1477
foreach (TextLineMarker marker in line.Markers) {
1374
1478
IBackgroundMarker bgMarker = marker as IBackgroundMarker;
1375
1479
if (bgMarker == null || !marker.IsVisible)
1377
isSelectionDrawn |= (marker.Flags & TextMarkerFlags.DrawsSelection) == TextMarkerFlags.DrawsSelection;
1481
isSelectionDrawn |= (marker.Flags & TextLineMarkerFlags.DrawsSelection) == TextLineMarkerFlags.DrawsSelection;
1378
1482
drawText &= bgMarker.DrawBackground (textEditor, cr, layout, selectionStart, selectionEnd, offset, offset + length, y, xPos, xPos + width, ref drawBg);
1381
1485
if (DecorateLineBg != null)
1382
1486
DecorateLineBg (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd);
1384
if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber)
1385
DrawCaretLineMarker (cr, xPos, y, layout.PangoWidth / Pango.Scale.PangoScale);
1387
if (!isSelectionDrawn && (layout.StartSet || selectionStart == offset + length)) {
1489
if (!isSelectionDrawn && (layout.StartSet || selectionStart == offset + length) && BackgroundRenderer == null) {
1391
1493
if (selectionStart != offset + length) {
1392
1494
var start = layout.Layout.IndexToPos ((int)layout.SelectionStartIndex);
1393
startX = start.X / Pango.Scale.PangoScale;
1495
startX = System.Math.Floor (start.X / Pango.Scale.PangoScale);
1394
1496
var end = layout.Layout.IndexToPos ((int)layout.SelectionEndIndex);
1395
endX = end.X / Pango.Scale.PangoScale;
1497
endX = System.Math.Ceiling (end.X / Pango.Scale.PangoScale);
1397
1499
startX = width;
1422
1524
layout.Layout.IndexToLineX ((int)startTranslated, false, out l, out x1);
1423
1525
layout.Layout.IndexToLineX ((int)endTranslated, false, out l, out x2);
1426
x1 /= (int)Pango.Scale.PangoScale;
1427
x2 /= (int)Pango.Scale.PangoScale;
1429
cr.Color = MainSearchResult.IsInvalid || MainSearchResult.Offset != firstSearch.Offset ? ColorStyle.SearchTextBg : ColorStyle.SearchTextMainBg;
1430
FoldingScreenbackgroundRenderer.DrawRoundRectangle (cr, true, true, x1, y, System.Math.Min (10, width) * textEditor.Options.Zoom, x2 - x1, LineHeight);
1526
int w = (int) System.Math.Ceiling ((x2 - x1) / Pango.Scale.PangoScale);
1527
int s = (int) System.Math.Floor ((x1 + x) / Pango.Scale.PangoScale);
1528
double corner = System.Math.Min (4, width) * textEditor.Options.Zoom;
1530
cr.Color = MainSearchResult.IsInvalid || MainSearchResult.Offset != firstSearch.Offset ? ColorStyle.SearchResult.Color : ColorStyle.SearchResultMain.Color;
1531
FoldingScreenbackgroundRenderer.DrawRoundRectangle (cr, true, true, s, y, corner, w + 1, LineHeight);
1440
1541
cr.Translate (xPos, y);
1441
1542
cr.ShowLayout (layout.Layout);
1444
if (DecorateLineFg != null)
1445
DecorateLineFg (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd);
1544
if (offset == line.Offset) {
1545
DrawIndent (cr, layout, line, xPos, y);
1548
if (textEditor.Options.ShowWhitespaces != ShowWhitespaces.Never && !(BackgroundRenderer != null && textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection))
1549
DecorateTabsAndSpaces (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd);
1447
1551
if (lineNumber == Caret.Line) {
1448
1552
int caretOffset = Caret.Offset;
1468
1572
SetVisibleCaretPosition (((pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale), y);
1469
1573
xPos = (pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale;
1471
if (!isSelectionDrawn && (selectionEnd == lineOffset + line.Length)) {
1575
if (!isSelectionDrawn && (selectionEnd == lineOffset + line.Length) && BackgroundRenderer == null) {
1475
1579
endX = (pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale;
1476
DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (startX, y, endX - startX, LineHeight), this.SelectionColor.CairoBackgroundColor, true);
1580
DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (startX, y, endX - startX, _lineHeight), this.SelectionColor.Background, true);
1478
if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber)
1479
DrawCaretLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y, vx / Pango.Scale.PangoScale);
1481
1583
// When drawing virtual space before the selection start paint it as unselected.
1482
1584
var virtualSpaceMod = selectionStart < caretOffset ? 0 : virtualSpace.Length;
1586
if ((!textEditor.IsSomethingSelected || (selectionStart >= offset && selectionStart != selectionEnd)) && (HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber)
1587
DrawCaretLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y, vx / Pango.Scale.PangoScale, _lineHeight);
1484
1589
if (DecorateLineBg != null)
1485
1590
DecorateLineBg (cr, wrapper, offset, length, xPos, y, selectionStart + virtualSpaceMod, selectionEnd + virtualSpace.Length);
1486
if (DecorateLineFg != null)
1487
DecorateLineFg (cr, wrapper, offset, length, xPos, y, selectionStart + virtualSpaceMod, selectionEnd + virtualSpace.Length);
1592
switch (textEditor.Options.ShowWhitespaces) {
1593
case ShowWhitespaces.Selection:
1594
if (textEditor.IsSomethingSelected && (selectionStart < offset || selectionStart == selectionEnd) && BackgroundRenderer == null)
1595
DecorateTabsAndSpaces (cr, wrapper, offset, length, xPos, y, selectionStart, selectionEnd + virtualSpace.Length);
1597
case ShowWhitespaces.Always:
1598
DecorateTabsAndSpaces (cr, wrapper, offset, length, xPos, y, selectionStart, selectionEnd + virtualSpace.Length);
1488
1602
wrapper.Dispose ();
1489
1603
pangoPosition += vx;
1490
1604
} else if (index == length && textEditor.preeditString == null) {
1501
1615
utf8ByteIndex += preeditUtf8ByteIndex;
1503
1617
layout.Layout.GetCursorPos (utf8ByteIndex, out strong_pos, out weak_pos);
1504
SetVisibleCaretPosition (xPos + (strong_pos.X / Pango.Scale.PangoScale), y);
1618
SetVisibleCaretPosition (xPos + (strong_pos.X / Pango.Scale.PangoScale), y + (strong_pos.Y / Pango.Scale.PangoScale));
1509
foreach (TextMarker marker in line.Markers.Where (m => m.IsVisible)) {
1623
foreach (TextLineMarker marker in line.Markers.Where (m => m.IsVisible)) {
1624
if (layout.Layout != null)
1625
marker.Draw (textEditor, cr, layout.Layout, false, /*selected*/offset, offset + length, y, xPos, xPos + width);
1628
foreach (var marker in Document.GetTextSegmentMarkersAt (line).Where (m => m.IsVisible)) {
1510
1629
if (layout.Layout != null)
1511
1630
marker.Draw (textEditor, cr, layout.Layout, false, /*selected*/offset, offset + length, y, xPos, xPos + width);
1514
1633
pangoPosition += layout.PangoWidth;
1634
int scaledDown = (int)(pangoPosition / Pango.Scale.PangoScale);
1635
pangoPosition = scaledDown * Pango.Scale.PangoScale;
1515
1637
if (layout.IsUncached)
1516
1638
layout.Dispose ();
1520
1641
TextSegment GetFirstSearchResult (int startOffset, int endOffset)
1522
1643
if (startOffset < endOffset && this.selectedRegions.Count > 0) {
1550
1671
void DrawEolMarker (Cairo.Context cr, DocumentLine line, bool selected, double x, double y)
1673
if (!textEditor.Options.IncludeWhitespaces.HasFlag (IncludeWhitespaces.LineEndings))
1552
1676
Pango.Layout layout;
1677
Pango.Rectangle rect;
1553
1678
switch (line.DelimiterLength) {
1555
1680
// an emty line end should only happen at eof
1556
1681
layout = eofEolLayout;
1682
rect = eofEolLayoutRect;
1559
1685
if (Document.GetCharAt (line.Offset + line.Length) == '\n') {
1560
1686
layout = unixEolLayout;
1687
rect = unixEolLayoutRect;
1562
1689
layout = macEolLayout;
1690
rect = macEolLayoutRect;
1566
layout = windowEolLayout;
1694
layout = windowsEolLayout;
1695
rect = windowsEolLayoutRect;
1569
1698
throw new InvalidOperationException (); // other line endings are not known.
1572
cr.Translate (x, y);
1573
cr.Color = selected ? SelectionColor.CairoColor : ColorStyle.EolWhitespaceMarker;
1701
cr.Translate (x, y + System.Math.Max (0, LineHeight - rect.Height - 1));
1702
var col = ColorStyle.PlainText.Foreground;
1704
if (selected && !SelectionColor.TransparentForeground) {
1705
col = SelectionColor.Foreground;
1707
if (line != null && line.NextLine != null && line.NextLine.StartSpan != null && line.NextLine.StartSpan.Count > 0) {
1708
var span = line.NextLine.StartSpan.Peek ();
1709
var chunkStyle = ColorStyle.GetChunkStyle (span.Color);
1710
if (chunkStyle != null)
1711
col = ColorStyle.GetForeground (chunkStyle);
1715
cr.Color = new Cairo.Color (col.R, col.G, col.B, whitespaceMarkerAlpha);
1574
1716
cr.ShowLayout (layout);
1579
void DrawInvalidLineMarker (Cairo.Context cr, double x, double y)
1582
cr.Translate (x, y);
1583
cr.Color = ColorStyle.InvalidLineMarker;
1584
cr.ShowLayout (invalidLineLayout);
1588
1720
static internal ulong GetPixel (Color color)
1590
1722
return (((ulong)color.Red) << 32) | (((ulong)color.Green) << 16) | ((ulong)color.Blue);
1593
public bool inSelectionDrag = false;
1594
public bool inDrag = false;
1595
public DocumentLocation clickLocation;
1725
static internal ulong GetPixel (Cairo.Color color)
1727
return GetPixel ((Gdk.Color) ((HslColor)color));
1730
internal bool InSelectionDrag = false;
1731
internal bool inDrag = false;
1732
internal DocumentLocation clickLocation;
1596
1733
int mouseWordStart, mouseWordEnd;
1597
1734
enum MouseSelectionMode
1603
1740
MouseSelectionMode mouseSelectionMode = MouseSelectionMode.SingleChar;
1742
internal bool CalculateClickLocation (double x, double y, out DocumentLocation clickLocation)
1744
VisualLocationTranslator trans = new VisualLocationTranslator (this);
1746
clickLocation = trans.PointToLocation (x, y);
1747
if (clickLocation.Line < DocumentLocation.MinLine || clickLocation.Column < DocumentLocation.MinColumn)
1749
DocumentLine line = Document.GetLine (clickLocation.Line);
1750
if (line != null && clickLocation.Column >= line.Length + 1 && GetWidth (Document.GetTextAt (line.SegmentIncludingDelimiter) + "-") < x) {
1751
clickLocation = new DocumentLocation (clickLocation.Line, line.Length + 1);
1752
if (textEditor.GetTextEditorData ().HasIndentationTracker && textEditor.Options.IndentStyle == IndentStyle.Virtual && clickLocation.Column == 1) {
1753
int indentationColumn = this.textEditor.GetTextEditorData ().GetVirtualIndentationColumn (clickLocation);
1754
if (indentationColumn > clickLocation.Column)
1755
clickLocation = new DocumentLocation (clickLocation.Line, indentationColumn);
1605
1761
protected internal override void MousePressed (MarginMouseEventArgs args)
1607
1763
base.MousePressed (args);
1624
1779
if (args.Button == 1) {
1625
VisualLocationTranslator trans = new VisualLocationTranslator (this);
1626
clickLocation = trans.PointToLocation (args.X, args.Y);
1627
if (clickLocation.Line < DocumentLocation.MinLine || clickLocation.Column < DocumentLocation.MinColumn)
1780
if (!CalculateClickLocation (args.X, args.Y, out clickLocation))
1629
1783
DocumentLine line = Document.GetLine (clickLocation.Line);
1630
1784
bool isHandled = false;
1631
1785
if (line != null) {
1632
foreach (TextMarker marker in line.Markers) {
1633
if (marker is IActionTextMarker) {
1634
isHandled |= ((IActionTextMarker)marker).MousePressed (this.textEditor, args);
1786
foreach (TextLineMarker marker in line.Markers) {
1787
if (marker is IActionTextLineMarker) {
1788
isHandled |= ((IActionTextLineMarker)marker).MousePressed (textEditor, args);
1793
foreach (var marker in Document.GetTextSegmentMarkersAt (line).Where (m => m.IsVisible)) {
1794
if (marker is IActionTextLineMarker) {
1795
isHandled |= ((IActionTextLineMarker)marker).MousePressed (textEditor, args);
1712
1875
if (!Platform.IsWindows && args.Button == 2 && this.textEditor.CanEdit (docLocation.Line)) {
1713
1876
TextSegment selectionRange = TextSegment.Invalid;
1714
1877
int offset = Document.LocationToOffset (docLocation);
1715
if (selection != null)
1878
if (!selection.IsEmpty)
1716
1879
selectionRange = selection.GetSelectionRange (this.textEditor.GetTextEditorData ());
1880
var oldVersion = textEditor.Document.Version;
1718
1882
bool autoScroll = textEditor.Caret.AutoScrollToCaret;
1719
1883
textEditor.Caret.AutoScrollToCaret = false;
1720
if (selection != null && selectionRange.Contains (offset)) {
1884
if (!selection.IsEmpty && selectionRange.Contains (offset)) {
1721
1885
textEditor.ClearSelection ();
1722
1886
textEditor.Caret.Offset = selectionRange.EndOffset;
1726
int length = ClipboardActions.PasteFromPrimary (textEditor.GetTextEditorData (), offset);
1890
ClipboardActions.PasteFromPrimary (textEditor.GetTextEditorData (), offset);
1727
1891
textEditor.Caret.Offset = oldOffset;
1728
if (selection != null) {
1729
if (offset < selectionRange.EndOffset) {
1730
textEditor.SelectionRange = new TextSegment (selectionRange.Offset + length, selectionRange.Length);
1892
if (!selectionRange.IsInvalid)
1893
textEditor.SelectionRange = new TextSegment (oldVersion.MoveOffsetTo (Document.Version, selectionRange.Offset), selectionRange.Length);
1734
1895
if (autoScroll)
1735
1896
textEditor.Caret.ActivateAutoScrollWithoutMove ();
1818
1980
int ox = 0, oy = 0;
1819
1981
this.textEditor.GdkWindow.GetOrigin (out ox, out oy);
1982
ox += textEditor.Allocation.X;
1983
oy += textEditor.Allocation.Y;
1821
int x = hintRectangle.X + hintRectangle.Width;
1822
int y = hintRectangle.Y + hintRectangle.Height;
1985
int x = hintRectangle.Right;
1986
int y = hintRectangle.Bottom;
1823
1987
previewWindow.CalculateSize ();
1824
int w = previewWindow.SizeRequest ().Width;
1825
int h = previewWindow.SizeRequest ().Height;
1988
var req = previewWindow.SizeRequest ();
1827
Gdk.Rectangle geometry = this.textEditor.Screen.GetUsableMonitorGeometry (this.textEditor.Screen.GetMonitorAtPoint (ox + x, oy + y));
1992
var geometry = this.textEditor.Screen.GetUsableMonitorGeometry (this.textEditor.Screen.GetMonitorAtPoint (ox + x, oy + y));
1829
1994
if (x + ox + w > geometry.X + geometry.Width)
1830
1995
x = hintRectangle.Left - w;
1899
2064
HoveredLine = line;
1900
2065
OnHoveredLineChanged (new LineEventArgs (oldHoveredLine));
1902
var hoverResult = new TextMarkerHoverResult ();
1903
oldMarkers.ForEach (m => m.MouseHover (this.textEditor, args, hoverResult));
2067
var hoverResult = new TextLineMarkerHoverResult ();
2068
oldMarkers.ForEach (m => m.MouseHover (textEditor, args, hoverResult));
1905
2070
if (line != null) {
1906
2071
newMarkers.Clear ();
1907
newMarkers.AddRange (line.Markers.Where (m => m is IActionTextMarker).Cast <IActionTextMarker> ());
1908
var extraMarker = Document.GetExtendingTextMarker (loc.Line) as IActionTextMarker;
2072
newMarkers.AddRange (line.Markers.Where (m => m is IActionTextLineMarker).Cast <IActionTextLineMarker> ());
2073
var extraMarker = Document.GetExtendingTextMarker (loc.Line) as IActionTextLineMarker;
1909
2074
if (extraMarker != null && !oldMarkers.Contains (extraMarker))
1910
2075
newMarkers.Add (extraMarker);
1911
2076
foreach (var marker in newMarkers.Where (m => !oldMarkers.Contains (m))) {
1912
marker.MouseHover (this.textEditor, args, hoverResult);
2077
marker.MouseHover (textEditor, args, hoverResult);
1914
2079
oldMarkers.Clear ();
1915
2080
var tmp = oldMarkers;
1916
2081
oldMarkers = newMarkers;
1917
2082
newMarkers = tmp;
2083
foreach (var marker in Document.GetTextSegmentMarkersAt (line).Where (m => m.IsVisible)) {
2084
if (marker is IActionTextLineMarker) {
2085
((IActionTextLineMarker)marker).MouseHover (textEditor, args, hoverResult);
1919
2089
oldMarkers.Clear ();
1921
base.cursor = hoverResult.Cursor ?? xtermCursor;
2091
base.cursor = hoverResult.HasCursor ? hoverResult.Cursor : xtermCursor;
1922
2092
if (textEditor.TooltipMarkup != hoverResult.TooltipMarkup) {
1923
2093
textEditor.TooltipMarkup = null;
1924
2094
textEditor.TriggerTooltipQuery ();
1926
textEditor.TooltipMarkup = hoverResult.TooltipMarkup;
2096
if (!textEditor.GetTextEditorData ().SuppressTooltips)
2097
textEditor.TooltipMarkup = hoverResult.TooltipMarkup;
1928
2098
if (args.Button != 1 && args.Y >= 0 && args.Y <= this.textEditor.Allocation.Height) {
1929
2099
// folding marker
1930
2100
int lineNr = args.LineNumber;
1931
foreach (KeyValuePair<Rectangle, FoldSegment> shownFolding in GetFoldRectangles (lineNr)) {
1932
if (shownFolding.Key.Contains ((int)(args.X + this.XOffset), (int)args.Y)) {
1933
ShowTooltip (shownFolding.Value.Segment, shownFolding.Key);
2101
foreach (var shownFolding in GetFoldRectangles (lineNr)) {
2102
if (shownFolding.Item1.Contains ((int)(args.X + this.XOffset), (int)args.Y)) {
2103
ShowTooltip (shownFolding.Item2.Segment, shownFolding.Item1);
2061
2231
if (isDefaultColor && !drawDefaultBackground)
2063
2233
cr.Color = color;
2064
double xp = /*System.Math.Floor*/ (area.X);
2234
var left = (int)(area.X);
2235
var width = (int)area.Width + 1;
2066
2236
if (textEditor.Options.ShowRuler) {
2067
double divider = System.Math.Max (area.X, System.Math.Min (x + TextStartPosition + rulerX, area.X + area.Width));
2068
if (divider < area.X + area.Width) {
2069
cr.Rectangle (xp, area.Y, divider - area.X, area.Height);
2072
cr.Rectangle (divider, area.Y, area.X + area.Width - divider, area.Height);
2237
var right = left + width;
2239
var divider = (int) (System.Math.Max (left, System.Math.Min (x + TextStartPosition + rulerX, right)));
2240
if (divider < right) {
2241
var beforeDividerWidth = divider - left;
2242
if (beforeDividerWidth > 0) {
2243
cr.Rectangle (left, area.Y, beforeDividerWidth, area.Height);
2246
cr.Rectangle (divider, area.Y, right - divider, area.Height);
2073
2247
cr.Color = DimColor (color);
2075
cr.DrawLine (ColorStyle.Ruler, divider, area.Y, divider, area.Y + area.Height);
2250
if (beforeDividerWidth > 0) {
2252
ColorStyle.Ruler.Color,
2253
divider + 0.5, area.Y,
2254
divider + 0.5, area.Y + area.Height);
2079
cr.Rectangle (xp, area.Y, area.Width, area.Height);
2260
cr.Rectangle (left, area.Y, System.Math.Ceiling (area.Width), area.Height);
2083
List<System.Collections.Generic.KeyValuePair<Gdk.Rectangle, FoldSegment>> GetFoldRectangles (int lineNr)
2264
IEnumerable<Tuple<Gdk.Rectangle, FoldSegment>> GetFoldRectangles (int lineNr)
2085
List<System.Collections.Generic.KeyValuePair<Gdk.Rectangle, FoldSegment>> result = new List<System.Collections.Generic.KeyValuePair<Gdk.Rectangle, FoldSegment>> ();
2086
2266
if (lineNr < 0)
2089
DocumentLine line = lineNr <= Document.LineCount ? Document.GetLine (lineNr) : null;
2269
var line = lineNr <= Document.LineCount ? Document.GetLine (lineNr) : null;
2090
2270
// int xStart = XOffset;
2091
2271
int y = (int)(LineToY (lineNr) - textEditor.VAdjustment.Value);
2092
2272
// Gdk.Rectangle lineArea = new Gdk.Rectangle (XOffset, y, textEditor.Allocation.Width - XOffset, LineHeight);
2093
2273
int width, height;
2094
int xPos = (int)(XOffset - textEditor.HAdjustment.Value);
2100
IEnumerable<FoldSegment> foldings = Document.GetStartFoldings (line);
2274
var xPos = this.XOffset + this.TextStartPosition - textEditor.HAdjustment.Value;
2279
var foldings = Document.GetStartFoldings (line);
2101
2280
int offset = line.Offset;
2281
double foldXMargin = foldMarkerXMargin * textEditor.Options.Zoom;
2103
// int caretOffset = Caret.Offset;
2104
foreach (FoldSegment folding in foldings) {
2105
int foldOffset = folding.StartLine.Offset + folding.Column - 1;
2106
if (foldOffset < offset)
2109
if (folding.IsFolded) {
2110
markerLayout.SetText (Document.GetTextAt (offset, System.Math.Max (0, System.Math.Min (foldOffset - offset, Document.TextLength - offset))).Replace ("\t", new string (' ', textEditor.Options.TabSize)));
2111
markerLayout.GetPixelSize (out width, out height);
2113
offset = folding.EndLine.Offset + folding.EndColumn;
2115
markerLayout.SetText (folding.Description);
2116
markerLayout.GetPixelSize (out width, out height);
2117
Rectangle foldingRectangle = new Rectangle (xPos, y, width - 1, (int)this.LineHeight - 1);
2118
result.Add (new KeyValuePair<Rectangle, FoldSegment> (foldingRectangle, folding));
2120
if (folding.EndLine != line) {
2121
line = folding.EndLine;
2122
foldings = Document.GetStartFoldings (line);
2283
using (var calcTextLayout = PangoUtil.CreateLayout (textEditor))
2284
using (var calcFoldingLayout = PangoUtil.CreateLayout (textEditor)) {
2285
calcTextLayout.FontDescription = textEditor.Options.Font;
2286
calcTextLayout.Tabs = this.tabArray;
2288
calcFoldingLayout.FontDescription = markerLayout.FontDescription;
2289
calcFoldingLayout.Tabs = this.tabArray;
2290
foreach (var folding in foldings) {
2291
int foldOffset = folding.StartLine.Offset + folding.Column - 1;
2292
if (foldOffset < offset)
2295
if (folding.IsFolded) {
2296
var txt = Document.GetTextAt (offset, System.Math.Max (0, System.Math.Min (foldOffset - offset, Document.TextLength - offset)));
2297
calcTextLayout.SetText (txt);
2298
calcTextLayout.GetSize (out width, out height);
2299
xPos += width / Pango.Scale.PangoScale;
2300
offset = folding.EndLine.Offset + folding.EndColumn;
2302
calcFoldingLayout.SetText (folding.Description);
2304
calcFoldingLayout.GetSize (out width, out height);
2306
var pixelWidth = width / Pango.Scale.PangoScale + foldXMargin * 2;
2308
var foldingRectangle = new Rectangle ((int)xPos, y, (int)pixelWidth, (int)LineHeight - 1);
2309
yield return Tuple.Create (foldingRectangle, folding);
2311
if (folding.EndLine != line) {
2312
line = folding.EndLine;
2313
foldings = Document.GetStartFoldings (line);
2130
2321
List<TextSegment> selectedRegions = new List<TextSegment> ();
2131
2323
public int SearchResultMatchCount {
2133
2325
return selectedRegions.Count;
2136
2329
public IEnumerable<TextSegment> SearchResults {
2138
2331
return selectedRegions;
2365
public enum CairoCorners
2375
public static void RoundedRectangle(Cairo.Context cr, double x, double y, double w, double h,
2376
double r, CairoCorners corners, bool topBottomFallsThrough)
2378
if(topBottomFallsThrough && corners == CairoCorners.None) {
2379
cr.MoveTo(x, y - r);
2380
cr.LineTo(x, y + h + r);
2381
cr.MoveTo(x + w, y - r);
2382
cr.LineTo(x + w, y + h + r);
2384
} else if(r < 0.0001 || corners == CairoCorners.None) {
2385
cr.Rectangle(x, y, w, h);
2389
if((corners & (CairoCorners.TopLeft | CairoCorners.TopRight)) == 0 && topBottomFallsThrough) {
2392
cr.MoveTo(x + w, y);
2394
if((corners & CairoCorners.TopLeft) != 0) {
2395
cr.MoveTo(x + r, y);
2399
if((corners & CairoCorners.TopRight) != 0) {
2400
cr.Arc(x + w - r, y + r, r, System.Math.PI * 1.5, System.Math.PI * 2);
2402
cr.LineTo(x + w, y);
2406
if((corners & (CairoCorners.BottomLeft | CairoCorners.BottomRight)) == 0 && topBottomFallsThrough) {
2408
cr.LineTo(x + w, y + h);
2409
cr.MoveTo(x, y + h);
2410
cr.LineTo(x, y + r);
2411
cr.Arc(x + r, y + r, r, System.Math.PI, System.Math.PI * 1.5);
2413
if((corners & CairoCorners.BottomRight) != 0) {
2414
cr.Arc(x + w - r, y + h - r, r, 0, System.Math.PI * 0.5);
2416
cr.LineTo(x + w, y + h);
2419
if((corners & CairoCorners.BottomLeft) != 0) {
2420
cr.Arc(x + r, y + h - r, r, System.Math.PI * 0.5, System.Math.PI);
2422
cr.LineTo(x, y + h);
2425
if((corners & CairoCorners.TopLeft) != 0) {
2426
cr.Arc(x + r, y + r, r, System.Math.PI, System.Math.PI * 1.5);
2433
const double foldMarkerXMargin = 4.0;
2169
2435
protected internal override void Draw (Cairo.Context cr, Cairo.Rectangle area, DocumentLine line, int lineNr, double x, double y, double _lineHeight)
2171
2437
// double xStart = System.Math.Max (area.X, XOffset);
2172
2438
// xStart = System.Math.Max (0, xStart);
2173
var lineArea = new Cairo.Rectangle (XOffset - 1, y, textEditor.Allocation.Width - XOffset + 1, _lineHeight);
2439
var correctedXOffset = System.Math.Floor (XOffset) - 1;
2440
var lineArea = new Cairo.Rectangle (correctedXOffset, y, textEditor.Allocation.Width - correctedXOffset, _lineHeight);
2174
2441
int width, height;
2175
2442
double pangoPosition = (x - textEditor.HAdjustment.Value + TextStartPosition) * Pango.Scale.PangoScale;
2177
defaultBgColor = Document.ReadOnly ? ColorStyle.ReadOnlyTextBg : ColorStyle.Default.CairoBackgroundColor;
2444
defaultBgColor = Document.ReadOnly ? ColorStyle.BackgroundReadOnly.Color : ColorStyle.PlainText.Background;
2179
2446
// Draw the default back color for the whole line. Colors other than the default
2180
2447
// background will be drawn when rendering the text chunks.
2181
DrawRectangleWithRuler (cr, x, lineArea, defaultBgColor, true);
2448
if (BackgroundRenderer == null)
2449
DrawRectangleWithRuler (cr, x, lineArea, defaultBgColor, true);
2182
2450
bool isSelectionDrawn = false;
2184
if (BackgroundRenderer != null)
2185
BackgroundRenderer.Draw (cr, area, line, x, y, _lineHeight);
2187
2452
// Check if line is beyond the document length
2188
2453
if (line == null) {
2189
if (textEditor.Options.ShowInvalidLines)
2190
DrawInvalidLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y);
2191
2454
var marker = Document.GetExtendingTextMarker (lineNr);
2192
2455
if (marker != null)
2193
2456
marker.Draw (textEditor, cr, lineNr, lineArea);
2209
2475
if (folding.IsFolded) {
2211
DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, foldOffset - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width);
2477
DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, foldOffset - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width, _lineHeight);
2213
offset = folding.EndLine.Offset + folding.EndColumn;
2479
offset = folding.EndLine.Offset + folding.EndColumn - 1;
2214
2480
markerLayout.SetText (folding.Description);
2215
2481
markerLayout.GetSize (out width, out height);
2217
2483
bool isFoldingSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (folding.Segment);
2218
double pixelX = pangoPosition / Pango.Scale.PangoScale;
2219
double pixelWidth = (pangoPosition + width) / Pango.Scale.PangoScale - pixelX;
2220
var foldingRectangle = new Cairo.Rectangle (pixelX + 0.5, y + 0.5, pixelWidth - cr.LineWidth, this.LineHeight - cr.LineWidth);
2221
if (BackgroundRenderer == null) {
2222
cr.Color = isFoldingSelected ? SelectionColor.CairoBackgroundColor : defaultBgColor;
2484
double pixelX = 0.5 + System.Math.Floor (pangoPosition / Pango.Scale.PangoScale);
2485
double foldXMargin = foldMarkerXMargin * textEditor.Options.Zoom;
2486
double pixelWidth = System.Math.Floor ((pangoPosition + width) / Pango.Scale.PangoScale - pixelX + foldXMargin * 2);
2487
var foldingRectangle = new Cairo.Rectangle (
2493
if (BackgroundRenderer == null && isFoldingSelected) {
2494
cr.Color = SelectionColor.Background;
2223
2495
cr.Rectangle (foldingRectangle);
2227
cr.Color = isFoldingSelected ? SelectionColor.CairoColor : ColorStyle.FoldLine.CairoColor;
2228
cr.Rectangle (foldingRectangle);
2499
if (isFoldingSelected && SelectionColor.TransparentForeground) {
2500
cr.Color = ColorStyle.CollapsedText.Foreground;
2502
cr.Color = isFoldingSelected ? SelectionColor.Foreground : ColorStyle.CollapsedText.Foreground;
2504
var boundingRectangleHeight = foldingRectangle.Height - 1;
2505
var boundingRectangleY = System.Math.Floor (foldingRectangle.Y + (foldingRectangle.Height - boundingRectangleHeight) / 2);
2506
RoundedRectangle (cr,
2507
System.Math.Floor (foldingRectangle.X) + 0.5,
2508
boundingRectangleY + 0.5,
2509
System.Math.Floor (foldingRectangle.Width - cr.LineWidth),
2510
System.Math.Floor (boundingRectangleHeight - cr.LineWidth),
2511
LineHeight / 8, CairoCorners.All, false);
2232
cr.Translate (pangoPosition / Pango.Scale.PangoScale, y);
2233
cr.Color = isFoldingSelected ? SelectionColor.CairoColor : ColorStyle.FoldLine.CairoColor;
2516
pangoPosition / Pango.Scale.PangoScale + foldXMargin,
2517
System.Math.Floor (boundingRectangleY + (boundingRectangleHeight - System.Math.Floor (height / Pango.Scale.PangoScale)) / 2));
2234
2518
cr.ShowLayout (markerLayout);
2238
2521
if (caretOffset == foldOffset && !string.IsNullOrEmpty (folding.Description))
2239
2522
SetVisibleCaretPosition ((int)(pangoPosition / Pango.Scale.PangoScale), y);
2240
pangoPosition += width;
2523
pangoPosition += foldingRectangle.Width * Pango.Scale.PangoScale;
2241
2524
if (caretOffset == foldOffset + folding.Length && !string.IsNullOrEmpty (folding.Description))
2242
2525
SetVisibleCaretPosition ((int)(pangoPosition / Pango.Scale.PangoScale), y);
2255
2538
// Draw remaining line - must be called for empty line parts as well because the caret may be at this positon
2256
2539
// and the caret position is calculated in DrawLinePart.
2257
if (line.EndOffsetIncludingDelimiter - offset >= 0)
2258
DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, line.Offset + line.Length - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width);
2540
if (line.EndOffsetIncludingDelimiter - offset >= 0) {
2541
DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, line.Offset + line.Length - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width, _lineHeight);
2260
2544
bool isEolSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionMode == SelectionMode.Normal && textEditor.SelectionRange.Contains (line.Offset + line.Length);
2261
lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale,
2545
var lx = (int)(pangoPosition / Pango.Scale.PangoScale);
2546
lineArea = new Cairo.Rectangle (lx,
2263
textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale,
2548
textEditor.Allocation.Width - lx,
2264
2549
lineArea.Height);
2266
2551
if (textEditor.SelectionMode == SelectionMode.Block && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (line.Offset + line.Length)) {
2279
x1 += XOffset - textEditor.HAdjustment.Value;
2280
x2 += XOffset - textEditor.HAdjustment.Value;
2564
x1 += correctedXOffset - textEditor.HAdjustment.Value;
2565
x2 += correctedXOffset - textEditor.HAdjustment.Value;
2282
if (x2 > lineArea.X) {
2567
if (x2 > lineArea.X && BackgroundRenderer == null) {
2283
2568
if (x1 - lineArea.X > 0) {
2284
2569
DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x1 - lineArea.X, lineArea.Height), defaultBgColor, false);
2285
2570
lineArea = new Cairo.Rectangle (x1, lineArea.Y, lineArea.Width, lineArea.Height);
2287
DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x2 - lineArea.X, lineArea.Height), this.SelectionColor.CairoBackgroundColor, false);
2572
DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x2 - lineArea.X, lineArea.Height), this.SelectionColor.Background, false);
2288
2573
lineArea = new Cairo.Rectangle (x2, lineArea.Y, textEditor.Allocation.Width - lineArea.X, lineArea.Height);
2292
if (!isSelectionDrawn) {
2577
if (!isSelectionDrawn && BackgroundRenderer == null) {
2293
2578
if (isEolSelected) {
2294
if (!Platform.IsMac) {
2295
// prevent "gaps" in the selection drawing ('fuzzy' lines problem)
2296
lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale,
2298
textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale + 1,
2301
// prevent "gaps" in the selection drawing ('fuzzy' lines problem)
2302
lineArea = new Cairo.Rectangle (System.Math.Max (pangoPosition / Pango.Scale.PangoScale - 1, XOffset + TextStartPosition),
2304
textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale + 1,
2308
DrawRectangleWithRuler (cr, x, lineArea, this.SelectionColor.CairoBackgroundColor, false);
2579
// prevent "gaps" in the selection drawing ('fuzzy' lines problem)
2580
var eolStartX = System.Math.Floor (pangoPosition / Pango.Scale.PangoScale);
2581
lineArea = new Cairo.Rectangle (
2584
textEditor.Allocation.Width - eolStartX,
2586
DrawRectangleWithRuler (cr, x, lineArea, this.SelectionColor.Background, false);
2587
if (line.Length == 0)
2588
DrawIndent (cr, GetLayout (line), line, lx, y);
2309
2589
} else if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Caret.Line != lineNr) {
2310
2590
LayoutWrapper wrapper = GetLayout (line);
2311
2591
if (wrapper.EolSpanStack != null) {
2312
2592
foreach (var span in wrapper.EolSpanStack) {
2313
2593
var spanStyle = textEditor.ColorStyle.GetChunkStyle (span.Color);
2314
if (!spanStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (spanStyle.BackgroundColor)) {
2315
DrawRectangleWithRuler (cr, x, lineArea, spanStyle.CairoBackgroundColor, false);
2594
if (spanStyle == null)
2596
if (!spanStyle.TransparentBackground && GetPixel (ColorStyle.PlainText.Background) != GetPixel (spanStyle.Background)) {
2597
DrawRectangleWithRuler (cr, x, lineArea, spanStyle.Background, false);
2321
2603
double xPos = pangoPosition / Pango.Scale.PangoScale;
2322
DrawCaretLineMarker (cr, xPos, y, lineArea.X + lineArea.Width - xPos);
2604
DrawCaretLineMarker (cr, xPos, y, lineArea.X + lineArea.Width - xPos, _lineHeight);
2326
if (!isEolFolded && textEditor.Options.ShowEolMarkers)
2327
DrawEolMarker (cr, line, isEolSelected, pangoPosition / Pango.Scale.PangoScale, y);
2608
if (textEditor.Options.ShowWhitespaces != ShowWhitespaces.Never) {
2609
if (!isEolFolded && isEolSelected || textEditor.Options.ShowWhitespaces == ShowWhitespaces.Always)
2610
if (!(BackgroundRenderer != null && textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection))
2611
DrawEolMarker (cr, line, isEolSelected, pangoPosition / Pango.Scale.PangoScale, y);
2328
2614
var extendingMarker = Document.GetExtendingTextMarker (lineNr);
2329
2615
if (extendingMarker != null)
2330
2616
extendingMarker.Draw (textEditor, cr, lineNr, lineArea);
2332
2618
lastLineRenderWidth = pangoPosition / Pango.Scale.PangoScale;
2619
if (textEditor.HAdjustment.Value > 0) {
2620
cr.LineWidth = textEditor.Options.Zoom;
2621
for (int i = 0; i < verticalShadowAlphaTable.Length; i++) {
2622
cr.Color = new Cairo.Color (0, 0, 0, 1 - verticalShadowAlphaTable[i]);
2623
cr.MoveTo (x + i * cr.LineWidth + 0.5, y);
2624
cr.LineTo (x + i * cr.LineWidth + 0.5, y + 1 + _lineHeight);
2335
internal IBackgroundRenderer BackgroundRenderer {
2630
static double[] verticalShadowAlphaTable = new [] { 0.71, 0.84, 0.95 };
2340
2632
internal double lastLineRenderWidth = 0;
2407
2697
IEnumerable<FoldSegment> foldings = margin.Document.GetStartFoldings (line);
2408
2698
bool done = false;
2409
2699
Pango.Layout measueLayout = null;
2411
int logicalRulerColumn = line.GetLogicalColumn(margin.textEditor.GetTextEditorData(), margin.textEditor.Options.RulerColumn);
2412
foreach (FoldSegment folding in foldings.Where(f => f.IsFolded))
2414
int foldOffset = folding.StartLine.Offset + folding.Column - 1;
2415
if (foldOffset < offset)
2417
layoutWrapper = margin.CreateLinePartLayout(mode, line, logicalRulerColumn, line.Offset, foldOffset - offset, -1, -1);
2418
done |= ConsumeLayout ((int)(xp - xPos), (int)yp);
2422
layoutWrapper.Layout.GetPixelSize (out width, out height);
2423
xPos += width * (int)Pango.Scale.PangoScale;
2424
if (measueLayout == null) {
2425
measueLayout = PangoUtil.CreateLayout (margin.textEditor, folding.Description);
2426
measueLayout.FontDescription = margin.textEditor.Options.Font;
2430
measueLayout.GetPixelSize (out delta, out height);
2431
delta *= (int)Pango.Scale.PangoScale;
2433
if (xPos - delta / 2 >= xp) {
2434
index = foldOffset - offset;
2439
offset = folding.EndLine.Offset + folding.EndColumn;
2440
DocumentLocation foldingEndLocation = margin.Document.OffsetToLocation(offset);
2441
lineNumber = foldingEndLocation.Line;
2442
column = foldingEndLocation.Column;
2449
if (folding.EndLine != line) {
2450
line = folding.EndLine;
2451
foldings = margin.Document.GetStartFoldings (line);
2456
layoutWrapper = margin.CreateLinePartLayout(mode, line, logicalRulerColumn, offset, line.Offset + line.Length - offset, -1, -1);
2457
ConsumeLayout ((int)(xp - xPos), (int)yp);
2459
if (measueLayout != null)
2460
measueLayout.Dispose ();
2702
int logicalRulerColumn = line.GetLogicalColumn (margin.textEditor.GetTextEditorData (), margin.textEditor.Options.RulerColumn);
2703
foreach (FoldSegment folding in foldings.Where(f => f.IsFolded)) {
2704
int foldOffset = folding.StartLine.Offset + folding.Column - 1;
2705
if (foldOffset < offset)
2707
layoutWrapper = margin.CreateLinePartLayout (mode, line, logicalRulerColumn, line.Offset, foldOffset - offset, -1, -1);
2708
done |= ConsumeLayout ((int)(xp - xPos), 0);
2712
layoutWrapper.Layout.GetPixelSize (out width, out height);
2713
xPos += width * (int)Pango.Scale.PangoScale;
2714
if (measueLayout == null) {
2715
measueLayout = PangoUtil.CreateLayout (margin.textEditor, folding.Description);
2716
measueLayout.FontDescription = margin.textEditor.Options.Font;
2720
measueLayout.GetPixelSize (out delta, out height);
2721
delta *= (int)Pango.Scale.PangoScale;
2723
if (xPos - delta / 2 >= xp) {
2724
index = foldOffset - offset;
2729
offset = folding.EndLine.Offset + folding.EndColumn - 1;
2730
DocumentLocation foldingEndLocation = margin.Document.OffsetToLocation (offset);
2731
lineNumber = foldingEndLocation.Line;
2732
column = foldingEndLocation.Column;
2739
if (folding.EndLine != line) {
2740
line = folding.EndLine;
2741
foldings = margin.Document.GetStartFoldings (line);
2746
layoutWrapper = margin.CreateLinePartLayout (mode, line, logicalRulerColumn, offset, line.Offset + line.Length - offset, -1, -1);
2747
if (!ConsumeLayout ((int)(xp - xPos), 0)) {
2749
return DocumentLocation.Empty;
2753
if (measueLayout != null)
2754
measueLayout.Dispose ();
2461
2756
return new DocumentLocation (lineNumber, column + index);
2465
public DocumentLocation PointToLocation (double xp, double yp)
2467
return new VisualLocationTranslator (this).PointToLocation (xp, yp);
2470
public DocumentLocation PointToLocation (Cairo.Point p)
2472
return new VisualLocationTranslator (this).PointToLocation (p.X, p.Y);
2475
public DocumentLocation PointToLocation (Cairo.PointD p)
2477
return new VisualLocationTranslator (this).PointToLocation (p.X, p.Y);
2760
public DocumentLocation PointToLocation (double xp, double yp, bool endAtEol = false)
2762
return new VisualLocationTranslator (this).PointToLocation (xp, yp, endAtEol);
2765
public DocumentLocation PointToLocation (Cairo.Point p, bool endAtEol = false)
2767
return new VisualLocationTranslator (this).PointToLocation (p.X, p.Y, endAtEol);
2770
public DocumentLocation PointToLocation (Cairo.PointD p, bool endAtEol = false)
2772
return new VisualLocationTranslator (this).PointToLocation (p.X, p.Y, endAtEol);
2480
2775
static bool IsNearX1 (int pos, int x1, int x2)
2572
2879
HandleSelection (lineOffset, logicalRulerColumn, - 1, -1, chunk.Offset, chunk.EndOffset, delegate(int start, int end) {
2573
Pango.AttrForeground foreGround = new Pango.AttrForeground (chunkStyle.Color.Red, chunkStyle.Color.Green, chunkStyle.Color.Blue);
2880
var color = textEditor.ColorStyle.GetForeground (chunkStyle);
2881
Pango.AttrForeground foreGround = new Pango.AttrForeground (
2882
(ushort)(color.R * ushort.MaxValue),
2883
(ushort)(color.G * ushort.MaxValue),
2884
(ushort)(color.B * ushort.MaxValue));
2574
2885
foreGround.StartIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
2575
2886
foreGround.EndIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
2576
2887
attributes.Add (foreGround);
2577
if (!chunkStyle.TransparentBackround) {
2578
var background = new Pango.AttrBackground (chunkStyle.BackgroundColor.Red, chunkStyle.BackgroundColor.Green, chunkStyle.BackgroundColor.Blue);
2888
if (!chunkStyle.TransparentBackground) {
2889
color = chunkStyle.Background;
2890
var background = new Pango.AttrBackground (
2891
(ushort)(color.R * ushort.MaxValue),
2892
(ushort)(color.G * ushort.MaxValue),
2893
(ushort)(color.B * ushort.MaxValue));
2579
2894
background.StartIndex = foreGround.StartIndex;
2580
2895
background.EndIndex = foreGround.EndIndex;
2581
2896
attributes.Add (background);
2583
2898
}, delegate(int start, int end) {
2584
Pango.AttrForeground selectedForeground = new Pango.AttrForeground (SelectionColor.Color.Red, SelectionColor.Color.Green, SelectionColor.Color.Blue);
2899
Pango.AttrForeground selectedForeground;
2900
if (!SelectionColor.TransparentForeground) {
2901
var color = SelectionColor.Foreground;
2902
selectedForeground = new Pango.AttrForeground (
2903
(ushort)(color.R * ushort.MaxValue),
2904
(ushort)(color.G * ushort.MaxValue),
2905
(ushort)(color.B * ushort.MaxValue));
2907
var color = ColorStyle.GetForeground (chunkStyle);
2908
selectedForeground = new Pango.AttrForeground (
2909
(ushort)(color.R * ushort.MaxValue),
2910
(ushort)(color.G * ushort.MaxValue),
2911
(ushort)(color.B * ushort.MaxValue));
2585
2913
selectedForeground.StartIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
2586
2914
selectedForeground.EndIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
2587
2915
attributes.Add (selectedForeground);
2590
2918
var translatedStartIndex = TranslateToUTF8Index (lineChars, (uint)startIndex, ref curChunkIndex, ref byteChunkIndex);
2591
2919
var translatedEndIndex = TranslateToUTF8Index (lineChars, (uint)endIndex, ref curChunkIndex, ref byteChunkIndex);
2593
if (chunkStyle.Bold) {
2594
Pango.AttrWeight attrWeight = new Pango.AttrWeight (Pango.Weight.Bold);
2921
if (chunkStyle.FontWeight != Xwt.Drawing.FontWeight.Normal) {
2922
Pango.AttrWeight attrWeight = new Pango.AttrWeight ((Pango.Weight)chunkStyle.FontWeight);
2595
2923
attrWeight.StartIndex = translatedStartIndex;
2596
2924
attrWeight.EndIndex = translatedEndIndex;
2597
2925
attributes.Add (attrWeight);
2600
if (chunkStyle.Italic) {
2601
Pango.AttrStyle attrStyle = new Pango.AttrStyle (Pango.Style.Italic);
2928
if (chunkStyle.FontStyle != Xwt.Drawing.FontStyle.Normal) {
2929
Pango.AttrStyle attrStyle = new Pango.AttrStyle ((Pango.Style)chunkStyle.FontStyle);
2602
2930
attrStyle.StartIndex = translatedStartIndex;
2603
2931
attrStyle.EndIndex = translatedEndIndex;
2604
2932
attributes.Add (attrStyle);