OSDN Git Service

MVVM対応の準備のためにLineBreak,TabStops,DrawLineNumber,LineBreakCharCount,MarkerPatternSetをDo...
[fooeditengine/FooEditEngine.git] / Core / ViewBase.cs
index 41a029e..1c2fdf8 100644 (file)
@@ -82,9 +82,6 @@ namespace FooEditEngine
         protected Rectangle _Rect;
         protected double _LongestWidth;
         Padding _Padding;
-        bool _DrawLineNumber,_UrlMark;
-        LineBreakMethod _LineBreak;
-        int _LineBreakCharCount = 80;
 
         public ViewBase(Document doc, ITextRender r,Padding padding)
         {
@@ -98,8 +95,21 @@ namespace FooEditEngine
             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
@@ -121,8 +131,7 @@ namespace FooEditEngine
         /// </summary>
         public MarkerPatternSet MarkerPatternSet
         {
-            get;
-            private set;
+            get { return this.Document.MarkerPatternSet; }
         }
 
         /// <summary>
@@ -130,19 +139,10 @@ namespace FooEditEngine
         /// </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;
             }
         }
 
@@ -199,15 +199,11 @@ namespace FooEditEngine
         {
             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;
             }
         }
 
@@ -218,11 +214,11 @@ namespace FooEditEngine
         {
             get
             {
-                return this._LineBreakCharCount;
+                return this.Document.LineBreakCharCount;
             }
             set
             {
-                this._LineBreakCharCount = value;
+                this.Document.LineBreakCharCount = value;
             }
         }
 
@@ -249,8 +245,8 @@ namespace FooEditEngine
         /// <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>
@@ -315,12 +311,10 @@ namespace FooEditEngine
         /// </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;
             }
         }
 
@@ -386,11 +380,6 @@ namespace FooEditEngine
                 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;
@@ -421,12 +410,12 @@ namespace FooEditEngine
         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;
@@ -439,7 +428,7 @@ namespace FooEditEngine
 
         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);
         }
     }
 }