Match match;
StringBuffer buffer;
LineToIndexTable _LayoutLines;
- bool _EnableFireUpdateEvent = true;
+ bool _EnableFireUpdateEvent = true,_UrlMark = false, _DrawLineNumber = false;
SemaphoreSlim Semaphore = new SemaphoreSlim(MaxSemaphoreCount);
+ LineBreakMethod _LineBreak;
+ int _TabStops, _LineBreakCharCount = 80;
+
+ /// <summary>
+ /// 一行当たりの最大文字数
+ /// </summary>
+ public const int MaximumLineLength = 1000;
/// <summary>
/// コンストラクター
this.Markers = new MarkerCollection(this);
this.UndoManager = new UndoManager();
this._LayoutLines = new LineToIndexTable(this);
- this._LayoutLines.SpilitString = LayoutLines_SpilitStringByChar;
+ this._LayoutLines.SpilitString = (s,e)=> {
+ return this.CreateLineList(e.index, e.length, MaximumLineLength);
+ };
this._LayoutLines.Clear();
+ this.MarkerPatternSet = new MarkerPatternSet(this._LayoutLines, this.Markers);
+ this.MarkerPatternSet.Updated += WacthDogPattern_Updated;
+ this.LineBreakChanged += (s, e) => { };
+ this.TabStopsChanged += (s, e) => { };
+ this.DrawLineNumberChanged += (s, e) => { };
+ }
+
+ void WacthDogPattern_Updated(object sender, EventArgs e)
+ {
+ this._LayoutLines.ClearLayoutCache();
}
/// <summary>
- /// レイアウト行を表す
+ /// DrawLineNumberの値が変わったときに通知される
/// </summary>
- public LineToIndexTable LayoutLines
+ public event EventHandler DrawLineNumberChanged;
+
+ /// <summary>
+ /// 行番号を表示するかどうか
+ /// </summary>
+ public bool DrawLineNumber
+ {
+ get { return this._DrawLineNumber; }
+ set
+ {
+ this._DrawLineNumber = value;
+ this._LayoutLines.ClearLayoutCache();
+ this.DrawLineNumberChanged(this, null);
+ }
+ }
+
+ /// <summary>
+ /// URLをハイパーリンクとして表示するなら真。そうでないなら偽
+ /// </summary>
+ public bool UrlMark
+ {
+ get { return this._UrlMark; }
+ set
+ {
+ this._UrlMark = value;
+ if (value)
+ {
+ Regex regex = new Regex("(http|https|ftp)(:\\/\\/[-_.!~*\\'()a-zA-Z0-9;\\/?:\\@&=+\\$,%#]+)");
+ this.MarkerPatternSet.Add(MarkerIDs.URL, new RegexMarkerPattern(regex, HilightType.Url, new Color()));
+ }
+ else
+ {
+ this.MarkerPatternSet.Remove(MarkerIDs.URL);
+ }
+ }
+ }
+
+ /// <summary>
+ /// LineBreakが変更されたときに通知される
+ /// </summary>
+ public EventHandler LineBreakChanged;
+
+ /// <summary>
+ /// 桁折り処理の方法を指定する
+ /// </summary>
+ /// <remarks>
+ /// 変更した場合、呼び出し側で再描写とレイアウトの再構築を行う必要があります
+ /// </remarks>
+ public LineBreakMethod LineBreak
{
get
{
- return this._LayoutLines;
+ return this._LineBreak;
+ }
+ set
+ {
+ this._LineBreak = value;
+ this.LineBreakChanged(this, null);
}
}
- IList<LineToIndexTableData> LayoutLines_SpilitStringByChar(object sender, SpilitStringEventArgs e)
+ /// <summary>
+ /// 折り返し行う文字数。実際に折り返しが行われる幅はem単位×この値となります
+ /// </summary>
+ /// <remarks>この値を変えた場合、LineBreakChangedイベントが発生します</remarks>
+ public int LineBreakCharCount
{
- return this.CreateLineList(e.index, e.length);
+ get
+ {
+ return this._LineBreakCharCount;
+ }
+ set
+ {
+ this._LineBreakCharCount = value;
+ this.LineBreakChanged(this, null);
+ }
+ }
+
+ /// <summary>
+ /// TabStopsの値が変わったことを通知する
+ /// </summary>
+ public event EventHandler TabStopsChanged;
+
+ /// <summary>
+ /// タブの幅
+ /// </summary>
+ /// <remarks>変更した場合、呼び出し側で再描写する必要があります</remarks>
+ public int TabStops
+ {
+ get { return this._TabStops; }
+ set {
+ this._TabStops = value;
+ this.TabStopsChanged(this, null);
+ }
+ }
+
+ /// <summary>
+ /// マーカーパターンセット
+ /// </summary>
+ public MarkerPatternSet MarkerPatternSet
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// レイアウト行を表す
+ /// </summary>
+ public LineToIndexTable LayoutLines
+ {
+ get
+ {
+ return this._LayoutLines;
+ }
}
/// <summary>
protected Rectangle _Rect;
protected double _LongestWidth;
Padding _Padding;
- bool _DrawLineNumber,_UrlMark;
- LineBreakMethod _LineBreak;
- int _LineBreakCharCount = 80;
public ViewBase(Document doc, ITextRender r,Padding padding)
{
this.SrcChanged += new EventHandler((s, e) => { });
this.PerformLayouted += new EventHandler((s, e) => { });
this.PageBoundChanged += new EventHandler((s, e) => { });
- this.MarkerPatternSet = new MarkerPatternSet(this._LayoutLines, doc.Markers);
- this.MarkerPatternSet.Updated += WacthDogPattern_Updated;
+ this.Document.LineBreakChanged += (s, e) =>
+ {
+ if (this.Document.LineBreak != LineBreakMethod.None)
+ this._LayoutLines.SpilitString = new SpilitStringEventHandler(LayoutLines_SpilitStringByPixelbase);
+ else
+ this._LayoutLines.SpilitString = new SpilitStringEventHandler(LayoutLines_SpilitStringByChar);
+ };
+ this.Document.TabStopsChanged += (s, e) =>
+ {
+ this.render.TabWidthChar = this.Document.TabStops;
+ };
+ this.Document.DrawLineNumberChanged += (s, e) =>
+ {
+ CalculateClipRect();
+ };
}
protected LineToIndexTable _LayoutLines
/// </summary>
public MarkerPatternSet MarkerPatternSet
{
- get;
- private set;
+ get { return this.Document.MarkerPatternSet; }
}
/// <summary>
/// </summary>
public bool UrlMark
{
- get { return this._UrlMark; }
+ get { return this.Document.UrlMark; }
set
{
- this._UrlMark = value;
- if (value)
- {
- Regex regex = new Regex("(http|https|ftp)(:\\/\\/[-_.!~*\\'()a-zA-Z0-9;\\/?:\\@&=+\\$,%#]+)");
- this.MarkerPatternSet.Add(MarkerIDs.URL, new RegexMarkerPattern(regex, HilightType.Url,new Color()));
- }
- else
- {
- this.MarkerPatternSet.Remove(MarkerIDs.URL);
- }
+ this.Document.UrlMark = value;
}
}
{
get
{
- return this._LineBreak;
+ return this.Document.LineBreak;
}
set
{
- this._LineBreak = value;
- if (value != LineBreakMethod.None)
- this._LayoutLines.SpilitString = new SpilitStringEventHandler(LayoutLines_SpilitStringByPixelbase);
- else
- this._LayoutLines.SpilitString = new SpilitStringEventHandler(LayoutLines_SpilitStringByChar);
+ this.Document.LineBreak = value;
}
}
{
get
{
- return this._LineBreakCharCount;
+ return this.Document.LineBreakCharCount;
}
set
{
- this._LineBreakCharCount = value;
+ this.Document.LineBreakCharCount = value;
}
}
/// <remarks>変更した場合、呼び出し側で再描写する必要があります</remarks>
public int TabStops
{
- get { return this.render.TabWidthChar; }
- set { this.render.TabWidthChar = value; }
+ get { return this.Document.TabStops; }
+ set { this.Document.TabStops = value; }
}
/// <summary>
/// </summary>
public bool DrawLineNumber
{
- get { return this._DrawLineNumber; }
+ get { return this.Document.DrawLineNumber; }
set
{
- this._DrawLineNumber = value;
- this._LayoutLines.ClearLayoutCache();
- CalculateClipRect();
+ this.Document.DrawLineNumber = value;
}
}
this.PageBoundChanged(this, e);
}
- void WacthDogPattern_Updated(object sender, EventArgs e)
- {
- this._LayoutLines.ClearLayoutCache();
- }
-
void render_ChangedRightToLeft(object sender, EventArgs e)
{
this._Src.X = 0;
IList<LineToIndexTableData> LayoutLines_SpilitStringByPixelbase(object sender, SpilitStringEventArgs e)
{
double WrapWidth;
- if (_LineBreak == LineBreakMethod.PageBound)
+ if (this.LineBreak == LineBreakMethod.PageBound)
WrapWidth = this.render.TextArea.Width - LineBreakingMarginWidth; //余白を残さないと欠ける
else
- WrapWidth = this.render.emSize.Width * this._LineBreakCharCount;
+ WrapWidth = this.render.emSize.Width * this.LineBreakCharCount;
- if (WrapWidth < 0 && this._LineBreak != LineBreakMethod.None)
+ if (WrapWidth < 0 && this.LineBreak != LineBreakMethod.None)
throw new InvalidOperationException();
int startIndex = e.index;
IList<LineToIndexTableData> LayoutLines_SpilitStringByChar(object sender, SpilitStringEventArgs e)
{
- return this.Document.CreateLineList(e.index, e.length,1000);
+ return this.Document.CreateLineList(e.index, e.length, Document.MaximumLineLength);
}
}
}