OSDN Git Service

コンパイルエラーを修正した
[fooeditengine/FooEditEngine.git] / Core / ViewBase.cs
index c91d38a..715cd1c 100644 (file)
@@ -77,8 +77,7 @@ namespace FooEditEngine
     {
         const int SpiltCharCount = 1024;
 
-        protected Document Document;
-        protected Point2 _Src = new Point2();
+        Document _Document;
         protected Rectangle _Rect;
         protected double _LongestWidth;
         Padding _Padding;
@@ -87,53 +86,77 @@ namespace FooEditEngine
         {
             this._Padding = padding;
             this.Document = doc;
-            this.Document.UpdateCalledAlways += new DocumentUpdateEventHandler(doc_Update);
             this._LayoutLines.SpilitString = new SpilitStringEventHandler(LayoutLines_SpilitStringByChar);
             this.render = r;
             this.render.ChangedRenderResource += new ChangedRenderResourceEventHandler(render_ChangedRenderResource);
             this.render.ChangedRightToLeft += render_ChangedRightToLeft;
             this.SrcChanged += new EventHandler((s, e) => { });
-            this.PerformLayouted += new EventHandler((s, e) => { });
             this.PageBoundChanged += new EventHandler((s, e) => { });
-            this.Document.LineBreakChanged += (s, e) =>
+        }
+
+        public Document Document
+        {
+            get
             {
-                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) =>
+                return this._Document;
+            }
+            set
             {
+                if(this._Document != null)
+                {
+                    this._Document.UpdateCalledAlways -= new DocumentUpdateEventHandler(doc_Update);
+                    this._Document.LineBreakChanged -= Document_LineBreakChanged;
+                    this._Document.StatusUpdate -= Document_StatusUpdate;
+                    this._Document.PerformLayouted -= _Document_PerformLayouted;
+                }
+
+                this._Document = value;
+
+                this._Document.UpdateCalledAlways += new DocumentUpdateEventHandler(doc_Update);
+                this._Document.LineBreakChanged += Document_LineBreakChanged;
+                this._Document.StatusUpdate += Document_StatusUpdate;
+                this._Document.PerformLayouted += _Document_PerformLayouted;
+
+                this.Document_LineBreakChanged(this, null);
+
+                this.Document_StatusUpdate(this, null);
+            }
+        }
+
+        private void _Document_PerformLayouted(object sender, EventArgs e)
+        {
+            CalculateLineCountOnScreen();
+            if(this.PerformLayouted != null)
+                this.PerformLayouted(this, e);
+        }
+
+        private void Document_StatusUpdate(object sender, EventArgs e)
+        {
+            if (this.render == null)
+                return;
+            if (this.render.TabWidthChar != this.Document.TabStops)
                 this.render.TabWidthChar = this.Document.TabStops;
-            };
-            this.Document.DrawLineNumberChanged += (s, e) =>
-            {
-                CalculateClipRect();
-            };
-            this.Document.RightToLeftChanged += (s, e) =>
-            {
+            if (this.render.RightToLeft != this.Document.RightToLeft)
                 this.render.RightToLeft = this.Document.RightToLeft;
-            };
-            this.Document.ShowFullSpaceChanged += (s, e) =>
-            {
+            if (this.render.ShowFullSpace != this.Document.ShowFullSpace)
                 this.render.ShowFullSpace = this.Document.ShowFullSpace;
-                this._LayoutLines.ClearLayoutCache();
-            };
-            this.Document.ShowHalfSpaceChanged += (s, e) =>
-            {
+            if (this.render.ShowHalfSpace != this.Document.ShowHalfSpace)
                 this.render.ShowHalfSpace = this.Document.ShowHalfSpace;
-                this._LayoutLines.ClearLayoutCache();
-            };
-            this.Document.ShowTabChanged += (s, e) =>
-            {
+            if (this.render.ShowTab != this.Document.ShowTab)
                 this.render.ShowTab = this.Document.ShowTab;
-                this._LayoutLines.ClearLayoutCache();
-            };
-            this.Document.ShowLineBreakChanged += (s, e) =>
-            {
+            if (this.render.ShowLineBreak != this.Document.ShowLineBreak)
                 this.render.ShowLineBreak = this.Document.ShowLineBreak;
-                this._LayoutLines.ClearLayoutCache();
-            };
+            CalculateClipRect();
+            CalculateLineCountOnScreen();
+            this._LayoutLines.ClearLayoutCache();
+        }
+
+        private void Document_LineBreakChanged(object sender, EventArgs e)
+        {
+            if (this.Document.LineBreak != LineBreakMethod.None)
+                this._LayoutLines.SpilitString = new SpilitStringEventHandler(LayoutLines_SpilitStringByPixelbase);
+            else
+                this._LayoutLines.SpilitString = new SpilitStringEventHandler(LayoutLines_SpilitStringByChar);
         }
 
         protected LineToIndexTable _LayoutLines
@@ -146,6 +169,7 @@ namespace FooEditEngine
 
         public event EventHandler SrcChanged;
 
+        [Obsolete]
         public event EventHandler PerformLayouted;
 
         public event EventHandler PageBoundChanged;
@@ -208,18 +232,17 @@ namespace FooEditEngine
         public IHilighter Hilighter
         {
             get { return this._LayoutLines.Hilighter; }
-            set { this._LayoutLines.Hilighter = value; }
+            set { this._LayoutLines.Hilighter = value; this._LayoutLines.ClearLayoutCache(); }
         }
 
         /// <summary>
         /// すべてのレイアウト行を破棄し、再度レイアウトをやり直す
         /// </summary>
+        [Obsolete]
         public virtual void PerfomLayouts()
         {
-            this.Document.FireUpdate(new DocumentUpdateEventArgs(UpdateType.Clear, -1, -1, -1));
-            this.Document.FireUpdate(new DocumentUpdateEventArgs(UpdateType.Replace, 0, 0, this.Document.Length));
-            CalculateLineCountOnScreen();
-            this.PerformLayouted(this, null);
+            //互換性を保つために残しておく
+            this.Document.PerformLayout();
         }
 
         /// <summary>
@@ -262,14 +285,15 @@ namespace FooEditEngine
         /// <summary>
         /// Draw()の対象となる領域の左上を表す
         /// </summary>
-        public Point2 Src
+        public SrcPoint Src
         {
-            get { return this._Src; }
-            set { this._Src = value; }
+            get { return this.Document.Src; }
+            set { this.Document.Src = value; }
         }
 
-        public virtual void Draw(Rectangle updateRect)
+        public virtual void Draw(Rectangle updateRect, bool force = false)
         {
+            return;
         }
 
         public virtual bool TryScroll(double x, int row)
@@ -278,9 +302,7 @@ namespace FooEditEngine
                 return true;
             if (row > this.LayoutLines.Count - 1)
                 return true;
-            this._Src.X = x;
-            this._Src.Row = row;
-            CalculateLineCountOnScreen();
+            this.Document.Src = new SrcPoint(x, row, row * this.render.emSize.Height);
             this.SrcChanged(this,null);
             return false;
         }
@@ -299,7 +321,10 @@ namespace FooEditEngine
         {
             if (disposing)
             {
-                this.Document.UpdateCalledAlways -= new DocumentUpdateEventHandler(this.doc_Update);    //これをしないと複数のビューを作成した時に妙なエラーが発生する
+                this._Document.UpdateCalledAlways -= new DocumentUpdateEventHandler(this.doc_Update);    //これをしないと複数のビューを作成した時に妙なエラーが発生する
+                this._Document.LineBreakChanged -= Document_LineBreakChanged;
+                this._Document.StatusUpdate -= Document_StatusUpdate;
+                this._Document.PerformLayouted -= _Document_PerformLayouted;
             }
             this._LayoutLines.Clear();
         }
@@ -332,9 +357,7 @@ namespace FooEditEngine
 
         void render_ChangedRightToLeft(object sender, EventArgs e)
         {
-            this._Src.X = 0;
-            this._LayoutLines.ClearLayoutCache();
-            this.CalculateClipRect();
+            this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Src.Y);
         }
 
         void render_ChangedRenderResource(object sender, ChangedRenderRsourceEventArgs e)