| ofs | hex dump | ascii |
|---|
| 0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 f4 00 00 01 1e 08 06 00 00 00 7c 09 e7 | .PNG........IHDR.............|.. |
| 0020 | 6e 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 00 | n....sRGB.........gAMA......a... |
| 0040 | 00 09 70 48 59 73 00 00 0e c3 00 00 0e c3 01 c7 6f a8 64 00 00 00 19 74 45 58 74 53 6f 66 74 77 | ..pHYs..........o.d....tEXtSoftw |
| 0060 | 61 72 65 00 70 61 69 6e 74 2e 6e 65 74 20 34 2e 30 2e 32 31 f1 20 69 95 00 00 ff 80 49 44 41 54 | are.paint.net.4.0.21..i.....IDAT |
| 0080 | 78 5e ec dd 07 b8 6d 57 55 f7 ff 57 54 8a 22 8a 20 bd 77 e9 bd 24 a0 40 80 10 7a 07 43 53 08 4d | x^....mWU..WT."...w..$.@..z.CS.M |
| 00a0 | 8a 22 0a 0a d8 00 41 90 a2 74 45 50 44 45 50 c1 57 a4 59 00 01 3b 88 60 40 04 42 2f 49 20 09 24 | ."....A..tEPDEP.W.Y..;.`@.B/I..$ |
| 00c0 | 21 c9 cd bd f7 9c ff f8 ac 37 bf fc 27 2b 73 9f b3 cf 39 fb d4 bb d6 f3 8c 67 ed bd f6 2a 73 8e | !........7..'+s...9......g...*s. |
| 00e0 | 31 e6 f8 8e 59 f6 de ff 67 79 79 79 92 49 26 99 64 92 49 26 d9 e5 d2 3d 38 c9 24 93 4c 32 c9 24 | 1...Y...gyyy.I&.d.I&...=8.$.L2.$ |
| 0100 | 93 ec 2e e9 1e 9c 64 92 49 26 99 64 92 49 76 97 74 0f 4e 32 c9 24 93 4c 32 c9 24 bb 4b ba 07 27 | ......d.I&.d.Iv.t.N2.$.L2.$.K..' |
| 0120 | 99 64 92 49 26 99 64 92 dd 25 dd 83 93 4c 32 c9 24 93 4c 32 c9 ee 92 ee c1 49 26 99 64 92 49 26 | .d.I&.d..%...L2.$.L2.....I&.d.I& |
| 0140 | 99 64 77 49 f7 e0 24 93 4c 32 c9 24 93 4c b2 bb a4 7b 70 92 49 26 99 64 92 49 26 d9 5d d2 3d 38 | .dwI..$.L2.$.L...{p.I&.d.I&.].=8 |
| 0160 | c9 24 93 4c 32 c9 24 93 ec 2e e9 1e 9c 64 92 49 26 99 64 92 49 76 97 74 0f 4e 32 c9 24 93 4c 32 | .$.L2.$......d.I&.d.Iv.t.N2.$.L2 |
| 0180 | c9 24 bb 4b ba 07 27 99 64 92 49 26 99 64 92 dd 25 dd 83 93 4c 32 c9 24 93 4c 32 c9 ee 92 ee c1 | .$.K..'.d.I&.d..%...L2.$.L2..... |
| 01a0 | 49 26 99 64 92 49 26 99 64 77 49 f7 e0 24 93 4c 32 c9 24 93 4c b2 bb a4 7b 70 92 d5 e5 f8 e3 8f | I&.d.I&.dwI..$.L2.$.L...{p...... |
| 01c0 | af 5d ff b3 49 26 99 64 92 49 26 d9 6a e9 1e dc ad f2 d5 af 7e 75 f9 2b 5f f9 ca 20 e3 e3 ed 67 | .]..I&.d.I&.j.......~u.+_......g |
| 01e0 | 5f fe f2 97 87 f7 b3 e4 6b 5f fb da 79 de 13 10 8f e4 58 ef 33 d2 3e 7f 92 49 26 99 64 92 49 36 | _.......k_..y.....X.3.>..I&.d.I6 |
| 0200 | 5b ba 07 77 aa 80 2b 18 93 2f 7d e9 4b cb 5f fc e2 17 07 f9 fc e7 3f bf fc b9 cf 7d 6e f9 b3 9f | [..w..+../}.K._.......?....}n... |
| 0220 | fd ec f2 71 c7 1d 37 48 7b 5e 7b ee 17 be f0 85 41 5c 33 4b 7c ee 7e ed 7b 92 7b 90 80 3c 65 f2 | ...q..7H{^{.....A\3K|.~.{.{..<e. |
| 0240 | 8c f6 be 8e 49 1e 7c 3e 01 fe bc d2 da 32 3a 8d ee e8 9e 0d 3f f3 99 cf cc dc 8f ef 37 c9 62 a5 | ....I.|>.....2:.....?.......7.b. |
| 0260 | 6d 4b 3d 61 83 59 e2 f3 24 b9 e3 fb 4e 32 c9 24 9b 27 dd 83 db 25 82 40 c0 28 a0 44 04 f8 16 b0 | mK=a.Y..$...N2.$.'...%.@.(.D.... |
| 0280 | 01 66 40 1d 90 b6 41 e8 93 9f fc e4 f2 ff fc cf ff 0c f2 89 4f 7c 62 90 8f 7f fc e3 e7 ca c7 3e | .f@...A.............O|b........> |
| 02a0 | f6 b1 15 e5 bf fe eb bf 06 f9 e8 47 3f 3a 48 8e ff f7 7f ff f7 20 5e 1f 7b ec b1 c3 7d ff f7 7f | ...........G?:H.......^.{...}... |
| 02c0 | ff 77 08 64 ca a8 3c 29 57 ea 42 02 29 65 74 6e 7b 8d 7a 8f 75 b1 5b 85 5d 62 8f d8 4d 3d 3f fd | .w.d..<)W.B.)etn{.z.u.[.]b..M=?. |
| 02e0 | e9 4f 0f 36 21 74 96 63 84 2e 48 6b a7 d8 6e 96 d0 bd f3 9c ef bd fb ba c7 a7 3e f5 a9 e1 de f6 | .O.6!t.c..Hk..n...........>..... |
| 0300 | ee 4d df ca 33 1e b5 39 d4 84 8f f1 c9 f8 5f ec 93 f7 f4 95 36 43 af b1 c9 2c 69 6d d1 13 f7 48 | .M..3..9......_.....6C...,im...H |
| 0320 | fb 70 df d8 25 6d 20 7b b6 e1 33 e3 f2 4e 32 c9 24 6b 97 ee c1 ad 92 34 e8 04 15 af 05 e1 04 9b | .p..%m.{..3..N2.$k.....4........ |
| 0340 | 04 9e 13 4f 3c 71 f9 a4 93 4e 1a 7a bb 01 b7 40 f1 fe f7 bf 7f f9 3d ef 79 cf b0 ff 87 7f f8 87 | ...O<q...N.z...@......=.y....... |
| 0360 | e5 bf ff fb bf 5f 7e ef 7b df bb fc ee 77 bf 7b f9 6f fe e6 6f ce 7d ff 77 7f f7 77 cb 7f fb b7 | ....._~.{....w.{.o..o.}.w..w.... |
| 0380 | 7f 3b bc 76 ee fb de f7 be e5 77 bc e3 1d cb ff f1 1f ff b1 fc 4f ff f4 4f cb ff f6 6f ff 36 1c | .;.v......w..........O..O...o.6. |
| 03a0 | 73 8f 7f fd d7 7f 1d 5e ff e3 3f fe e3 70 6f f7 20 3e 73 9f 77 bd eb 5d c3 bd dd ef af ff fa af | s......^..?..po..>s.w..]........ |
| 03c0 | 07 71 ec ff fe df ff bb fc ce 77 be f3 dc 73 95 e1 3f ff f3 3f 87 b2 0a a6 df f8 c6 37 96 4f 38 | .q........w...s..?..?.......7.O8 |
| 03e0 | e1 84 01 f2 ea d6 c2 dd eb 88 cf d5 71 ac ab 9d 24 6d 12 a5 cc 2d 0c 48 a0 2c a0 27 f1 09 7c 25 | ............q...$m...-.H.,.'..|% |
| 0400 | 43 12 24 e7 05 f2 39 cf 6b 92 eb 81 23 d0 cf fd ed bd 0f 54 72 df 3c db fb 24 5f ce f1 3c 89 99 | C.$...9.k...#......Tr.<..$_..<.. |
| 0420 | cf ec d9 84 ce 9d 67 9f c4 8b 8c eb b9 1b 45 3d 24 2f ea a6 fe d1 a5 7d f4 4b 17 6c 10 e0 12 af | ......g.......E=$/.....}.K.l.... |
| 0440 | e9 ca b9 63 bd 66 9f d7 39 87 e4 9e c4 67 b1 af 73 92 f8 fa 8c af db 3b e6 3a 9f e7 3e 8e 2b 2b | ...c.f..9....g..s......;.:..>.++ |
| 0460 | e1 4b 44 1b d9 e9 ed 60 92 49 76 9a 74 0f 6e a6 08 a0 1a aa e0 0a d4 1a af 63 60 a7 61 0b 46 86 | .KD....`.Iv.t.n..........c`.a.F. |
| 0480 | ea 4e 3b ed b4 e1 f8 47 3e f2 91 e5 0f 7c e0 03 03 34 ff f2 2f ff 72 f9 4d 6f 7a d3 f2 9f ff f9 | .N;....G>....|...4../.r.Moz..... |
| 04a0 | 9f 0f 00 7d cb 5b de 32 80 d5 e7 20 fc c1 0f 7e 70 f9 c3 1f fe f0 10 b4 3f f4 a1 0f 7d 87 00 b5 | ...}.[.2.......~p.......?...}... |
| 04c0 | f3 80 1a d4 c1 1c 7c ff ea af fe 6a 80 b2 d7 ff fc cf ff 7c 2e f0 81 de 39 82 93 32 fc fb bf ff | ......|....j.......|....9..2.... |
| 04e0 | fb 70 0f f7 17 94 c0 5d 1d dc db 3d 3d 3b e5 54 26 e5 03 76 e5 fd dd df fd dd 01 f0 ea 27 50 65 | .p.....]...==;.T&..v.........'Pe |
| 0500 | 38 52 5d d5 d1 31 92 80 46 2f 40 b9 13 86 2c 93 7c 00 84 f2 27 f0 7b 2d 18 e7 7d e0 a0 0e 39 37 | 8R]..1..F/@...,.|...'.{-..}...97 |
| 0520 | e7 44 7c ee 3c 41 9e 2e c9 bf fc cb bf 0c e2 35 7d b3 1d 7d 7b ed 18 3b b0 8b a4 8b c4 46 ae f1 | .D|.<A....// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using Tango.Scripting.Editors.Document;
using Tango.Scripting.Editors.Rendering;
using Tango.Scripting.Editors.Utils;
namespace Tango.Scripting.Editors.Editing
{
/// <summary>
/// Margin showing line numbers.
/// </summary>
public class LineNumberMargin : AbstractMargin, IWeakEventListener
{
public Brush Foreground
{
get { return (Brush)GetValue(ForegroundProperty); }
set { SetValue(ForegroundProperty, value); }
}
public static readonly DependencyProperty ForegroundProperty =
DependencyProperty.Register("Foreground", typeof(Brush), typeof(LineNumberMargin), new PropertyMetadata(Brushes.Gray));
static LineNumberMargin()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(LineNumberMargin),
new FrameworkPropertyMetadata(typeof(LineNumberMargin)));
}
TextArea textArea;
Typeface typeface;
double emSize;
/// <inheritdoc/>
protected override Size MeasureOverride(Size availableSize)
{
typeface = this.CreateTypeface();
emSize = (double)GetValue(TextBlock.FontSizeProperty);
FormattedText text = TextFormatterFactory.CreateFormattedText(
this,
new string('9', maxLineNumberLength),
typeface,
emSize,
Foreground
);
return new Size(text.Width, 0);
}
/// <inheritdoc/>
protected override void OnRender(DrawingContext drawingContext)
{
TextView textView = this.TextView;
Size renderSize = this.RenderSize;
if (textView != null && textView.VisualLinesValid) {
var foreground = Foreground;
foreach (VisualLine line in textView.VisualLines) {
int lineNumber = line.FirstDocumentLine.LineNumber;
FormattedText text = TextFormatterFactory.CreateFormattedText(
this,
lineNumber.ToString(CultureInfo.CurrentCulture),
typeface, emSize, foreground
);
double y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);
drawingContext.DrawText(text, new Point((renderSize.Width / 2) - text.Width + 5, y - textView.VerticalOffset));
}
}
}
/// <inheritdoc/>
protected override void OnTextViewChanged(TextView oldTextView, TextView newTextView)
{
if (oldTextView != null) {
oldTextView.VisualLinesChanged -= TextViewVisualLinesChanged;
}
base.OnTextViewChanged(oldTextView, newTextView);
if (newTextView != null) {
newTextView.VisualLinesChanged += TextViewVisualLinesChanged;
// find the text area belonging to the new text view
textArea = newTextView.Services.GetService(typeof(TextArea)) as TextArea;
} else {
textArea = null;
}
InvalidateVisual();
}
/// <inheritdoc/>
protected override void OnDocumentChanged(TextDocument oldDocument, TextDocument newDocument)
{
if (oldDocument != null) {
PropertyChangedEventManager.RemoveListener(oldDocument, this, "LineCount");
}
base.OnDocumentChanged(oldDocument, newDocument);
if (newDocument != null) {
PropertyChangedEventManager.AddListener(newDocument, this, "LineCount");
}
OnDocumentLineCountChanged();
}
/// <inheritdoc cref="IWeakEventListener.ReceiveWeakEvent"/>
protected virtual bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
{
if (managerType == typeof(PropertyChangedEventManager)) {
OnDocumentLineCountChanged();
return true;
}
return false;
}
bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
{
return ReceiveWeakEvent(managerType, sender, e);
}
int maxLineNumberLength = 1;
void OnDocumentLineCountChanged()
{
int documentLineCount = Document != null ? Document.LineCount : 1;
int newLength = documentLineCount.ToString(CultureInfo.CurrentCulture).Length;
// The margin looks too small when there is only one digit, so always reserve space for
// at least two digits
if (newLength < 2)
newLength = 2;
if (newLength != maxLineNumberLength) {
maxLineNumberLength = newLength;
InvalidateMeasure();
}
}
void TextViewVisualLinesChanged(object sender, EventArgs e)
{
InvalidateVisual();
}
AnchorSegment selectionStart;
bool selecting;
/// <inheritdoc/>
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
if (!e.Handled && TextView != null && textArea != null) {
e.Handled = true;
textArea.Focus();
SimpleSegment currentSeg = GetTextLineSegment(e);
if (currentSeg == SimpleSegment.Invalid)
return;
textArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;
if (CaptureMouse()) {
selecting = true;
selectionStart = new AnchorSegment(Document, currentSeg.Offset, currentSeg.Length);
if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
SimpleSelection simpleSelection = textArea.Selection as SimpleSelection;
if (simpleSelection != null)
selectionStart = new AnchorSegment(Document, simpleSelection.SurroundingSegment);
}
textArea.Selection = Selection.Create(textArea, selectionStart);
if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
ExtendSelection(currentSeg);
}
}
}
}
SimpleSegment GetTextLineSegment(MouseEventArgs e)
{
Point pos = e.GetPosition(TextView);
pos.X = 0;
pos.Y += TextView.VerticalOffset;
VisualLine vl = TextView.GetVisualLineFromVisualTop(pos.Y);
if (vl == null)
return SimpleSegment.Invalid;
TextLine tl = vl.GetTextLineByVisualYPosition(pos.Y);
int visualStartColumn = vl.GetTextLineVisualStartColumn(tl);
int visualEndColumn = visualStartColumn + tl.Length;
int relStart = vl.FirstDocumentLine.Offset;
int startOffset = vl.GetRelativeOffset(visualStartColumn) + relStart;
int endOffset = vl.GetRelativeOffset(visualEndColumn) + relStart;
if (endOffset == vl.LastDocumentLine.Offset + vl.LastDocumentLine.Length)
endOffset += vl.LastDocumentLine.DelimiterLength;
return new SimpleSegment(startOffset, endOffset - startOffset);
}
void ExtendSelection(SimpleSegment currentSeg)
{
if (currentSeg.Offset < selectionStart.Offset) {
textArea.Caret.Offset = currentSeg.Offset;
textArea.Selection = Selection.Create(textArea, currentSeg.Offset, selectionStart.Offset + selectionStart.Length);
} else {
textArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;
textArea.Selection = Selection.Create(textArea, selectionStart.Offset, currentSeg.Offset + currentSeg.Length);
}
}
/// <inheritdoc/>
protected override void OnMouseMove(MouseEventArgs e)
{
if (selecting && textArea != null && TextView != null) {
e.Handled = true;
SimpleSegment currentSeg = GetTextLineSegment(e);
if (currentSeg == SimpleSegment.Invalid)
return;
ExtendSelection(currentSeg);
}
base.OnMouseMove(e);
}
/// <inheritdoc/>
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
if (selecting) {
selecting = false;
selectionStart = null;
ReleaseMouseCapture();
e.Handled = true;
}
base.OnMouseLeftButtonUp(e);
}
/// <inheritdoc/>
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
{
// accept clicks even when clicking on the background
return new PointHitTestResult(this, hitTestParameters.HitPoint);
}
}
}
|