You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
*/\r
using System;\r
+using System.Text;\r
+using System.Threading.Tasks;\r
using System.Runtime.InteropServices;\r
using System.Windows;\r
using System.Windows.Input;\r
this.textStore = new TextStore();\r
this.textStore.IsLoading += textStore_IsLoading;\r
this.textStore.IsReadOnly += textStore_IsReadOnly;\r
+ this.textStore.GetDpi += textStore_GetDpi;\r
this.textStore.GetStringLength += () => this.Document.Length;\r
this.textStore.GetString += _textStore_GetString;\r
this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;\r
this.textStore.CompositionUpdated += textStore_CompositionUpdated;\r
this.textStore.CompositionEnded += textStore_CompositionEnded;\r
\r
- this.Document = new Document();\r
- DocumentExtend.Progress += new EventHandler<ProgressEventArgs>(Document_Progress);\r
-\r
this.Render = new D2DRender(this, 200, 200,this.image);\r
this.Render.ShowFullSpace = this.ShowFullSpace;\r
this.Render.ShowHalfSpace = this.ShowHalfSpace;\r
this.Render.ShowTab = this.ShowTab;\r
\r
- this.View = new EditView(this.Document, this.Render,new Padding(5,5,5,5));\r
+ this.Document = new Document();\r
+ this.Document.LayoutLines.Render = this.Render;\r
+\r
+ this.View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));\r
this.View.SrcChanged += View_SrcChanged;\r
this.View.InsertMode = this.InsertMode;\r
this.View.DrawLineNumber = this.DrawLineNumber;\r
/// <param name="length">長さ</param>\r
public void Select(int start, int length)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
this._Controller.Select(start, length);\r
this.textStore.NotifySelectionChanged();\r
}\r
/// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
public void JumpCaret(int index)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
this._Controller.JumpCaret(index);\r
}\r
/// <summary>\r
/// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
public void JumpCaret(int row, int col)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
this._Controller.JumpCaret(row, col);\r
}\r
\r
/// </summary>\r
public void Copy()\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
string text = this._Controller.SelectedText;\r
if (text != null && text != string.Empty)\r
Clipboard.SetText(text);\r
/// </summary>\r
public void Cut()\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
string text = this._Controller.SelectedText;\r
if (text != null && text != string.Empty)\r
{\r
/// </summary>\r
public void Paste()\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
if (Clipboard.ContainsText() == false)\r
return;\r
string text = Clipboard.GetText();\r
/// </summary>\r
public void DeSelectAll()\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
this._Controller.DeSelectAll();\r
this.textStore.NotifySelectionChanged();\r
}\r
/// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>\r
public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
if (this.Document.FireUpdateEvent == false)\r
throw new InvalidOperationException("");\r
return this.View.GetPostionFromTextPoint(tp);\r
/// <returns>テキストポイント</returns>\r
public TextPoint GetTextPointFromPostion(System.Windows.Point p)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
if (this.Document.FireUpdateEvent == false)\r
throw new InvalidOperationException("");\r
return this.View.GetTextPointFromPostion(p);\r
/// <returns>行の高さ</returns>\r
public double GetLineHeight(int row)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
if (this.Document.FireUpdateEvent == false)\r
throw new InvalidOperationException("");\r
return this.View.LayoutLines.GetLayout(row).Height;;\r
/// <returns>座標を返す</returns>\r
public System.Windows.Point GetPostionFromIndex(int index)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
if (this.Document.FireUpdateEvent == false)\r
throw new InvalidOperationException("");\r
TextPoint tp = this.View.GetLayoutLineFromIndex(index);\r
/// <returns>インデックスを返す</returns>\r
public int GetIndexFromPostion(System.Windows.Point p)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
if (this.Document.FireUpdateEvent == false)\r
throw new InvalidOperationException("");\r
TextPoint tp = this.View.GetTextPointFromPostion(p);\r
}\r
\r
/// <summary>\r
+ /// ストリームからドキュメントを構築する\r
+ /// </summary>\r
+ /// <param name="tr">TextReader</param>\r
+ /// <param name="token">キャンセル用トークン</param>\r
+ /// <returns>Taskオブジェクト</returns>\r
+ public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)\r
+ {\r
+ WinFileReader fs = new WinFileReader(tr);\r
+ await this.LoadAsyncImpl(fs, token);\r
+ }\r
+\r
+ /// <summary>\r
+ /// ファイルからドキュメントを構築する\r
+ /// </summary>\r
+ /// <param name="filepath">ファイルパス</param>\r
+ /// <param name="enc">エンコード</param>\r
+ /// <param name="token">キャンセル用トークン</param>\r
+ /// <returns>Taskオブジェクト</returns>\r
+ public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)\r
+ {\r
+ WinFileReader fs = new WinFileReader(filepath, enc);\r
+ await this.LoadAsyncImpl(fs, token);\r
+ fs.Close();\r
+ }\r
+\r
+ async Task LoadAsyncImpl(WinFileReader fs,System.Threading.CancellationTokenSource token)\r
+ {\r
+ this.IsEnabled = false;\r
+ this.View.LayoutLines.IsFrozneDirtyFlag = true;\r
+ await this.Document.LoadAsync(fs, token);\r
+ this.View.LayoutLines.IsFrozneDirtyFlag = false;\r
+ TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);\r
+ if (this.verticalScrollBar != null)\r
+ this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
+ this.View.CalculateLineCountOnScreen();\r
+ this.IsEnabled = true;\r
+ }\r
+\r
+ /// <summary>\r
+ /// ドキュメントの内容をファイルに保存する\r
+ /// </summary>\r
+ /// <param name="filepath">ファイルパス</param>\r
+ /// <param name="newLine">改行コード</param>\r
+ /// <param name="enc">エンコード</param>\r
+ /// <returns>Taskオブジェクト</returns>\r
+ public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)\r
+ {\r
+ WinFileWriter fs = new WinFileWriter(filepath, enc);\r
+ fs.NewLine = newLine;\r
+ await this.Document.SaveAsync(fs, token);\r
+ fs.Close();\r
+ }\r
+\r
+ /// <summary>\r
/// アンマネージドリソースを開放する\r
/// </summary>\r
public void Dispose()\r
this.Render.Dispose();\r
}\r
SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);\r
- DocumentExtend.Progress -= this.Document_Progress;\r
}\r
\r
void Refresh(Rectangle updateRect)\r
this.timer.Stop();\r
\r
this.Render.BegineDraw();\r
- if (this.Document.State != AsyncState.Loading)\r
+ if (this.IsEnabled)\r
this.View.Draw(updateRect);\r
else\r
this.Render.FillBackground(updateRect);\r
#region Commands\r
void CanExecute(object sender, CanExecuteRoutedEventArgs e)\r
{\r
- e.CanExecute = this.Document.State != FooEditEngine.AsyncState.Loading;\r
+ e.CanExecute = this.IsEnabled;\r
}\r
\r
void ToggleCodePointCommand(object sender, RoutedEventArgs e)\r
get { return this.textStore; }\r
}\r
\r
+ double textStore_GetDpi()\r
+ {\r
+ float dpi;\r
+ this.Render.GetDpi(out dpi, out dpi);\r
+ return dpi;\r
+ }\r
+\r
bool textStore_IsReadOnly()\r
{\r
return false;\r
\r
bool textStore_IsLoading()\r
{\r
- return this.Document.State == AsyncState.Loading;\r
+ return false;\r
}\r
\r
void textStore_CompositionEnded()\r
\r
void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);\r
this.Refresh();\r
}\r
/// <inheritdoc/>\r
protected override void OnTextInput(TextCompositionEventArgs e)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
if (e.Text == "\r")\r
{\r
this._Controller.DoEnterAction();\r
/// <inheritdoc/>\r
protected override void OnKeyDown(KeyEventArgs e)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
if (this.textStore.IsLocked())\r
return;\r
\r
/// </remarks>\r
protected override void OnMouseDoubleClick(MouseButtonEventArgs e)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
System.Windows.Point p = e.GetPosition(this);\r
TextPoint tp = this.View.GetTextPointFromPostion(p);\r
if (tp == TextPoint.Null)\r
/// </remarks>\r
protected override void OnMouseDown(MouseButtonEventArgs e)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
- \r
System.Windows.Point p = e.GetPosition(this);\r
TextPoint tp = this.View.GetTextPointFromPostion(p);\r
if (tp == TextPoint.Null)\r
}\r
if (this.peer != null)\r
this.peer.OnNotifyCaretChanged();\r
- this.Refresh();\r
+ this.View.IsFocused = true;\r
this.Focus();\r
+ this.Refresh();\r
}\r
}\r
\r
/// </remarks>\r
protected override void OnMouseMove(MouseEventArgs e)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- {\r
- this.Cursor = Cursors.Wait;\r
- base.OnMouseMove(e);\r
- return;\r
- }\r
System.Windows.Point p = e.GetPosition(this);\r
TextPoint tp = this.View.GetTextPointFromPostion(p);\r
if (tp == TextPoint.Null)\r
/// <inheritdoc/>\r
protected override void OnMouseWheel(MouseWheelEventArgs e)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
if(Keyboard.Modifiers == ModifierKeys.None)\r
{\r
if (e.Delta > 0)\r
\r
void Document_Update(object sender, DocumentUpdateEventArgs e)\r
{\r
- if (this.textStore.IsLocked() || e.type == UpdateType.Clear)\r
+ if (this.textStore.IsLocked())\r
return;\r
- TextStoreHelper.NotifyTextChanged(this.textStore, this.Document);\r
- }\r
-\r
- void Document_Progress(object sender, ProgressEventArgs e)\r
- {\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
- switch (e.state)\r
- {\r
- case ProgressState.Start:\r
- TextStoreHelper.NotifyTextChanged(this.textStore, this.Document);\r
- break;\r
- case ProgressState.Complete:\r
- TextStoreHelper.NotifyTextChanged(this.textStore, this.Document);\r
- this.OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, new TimeSpan(DateTime.Now.Ticks).Milliseconds));\r
- if(this.verticalScrollBar != null)\r
- this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
- this.View.CalculateLineCountOnScreen();\r
- break;\r
- }\r
+ TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);\r
}\r
\r
void timer_Tick(object sender, EventArgs e)\r
{\r
if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)\r
return;\r
- if (this.Document.State == AsyncState.Loading || this.Resize(this.image.ActualWidth, this.image.ActualHeight))\r
+ if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))\r
{\r
this.Refresh();\r
return;\r
\r
void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
if (this.horizontalScrollBar == null)\r
return;\r
double toX;\r
\r
void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- return;\r
if (this.verticalScrollBar == null)\r
return;\r
int newRow = (int)this.verticalScrollBar.Value;\r
{\r
if (width == 0 || height == 0)\r
throw new ArgumentOutOfRangeException();\r
- if (this.Render.Resize(width, height) && this.Document.State != AsyncState.Loading)\r
+ if (this.Render.Resize(width, height))\r
{\r
this.View.PageBound = new Rectangle(0, 0, width, height);\r
\r
this.Render.FontWeigth = this.FontWeight;\r
break;\r
case "Foreground":\r
- this.Render.Foreground = this.Foreground;\r
+ this.Render.Foreground = D2DRender.ToColor4(this.Foreground);\r
break;\r
case "Background":\r
- this.Render.Background = this.Background;\r
+ this.Render.Background = D2DRender.ToColor4(this.Background);\r
break;\r
case "ControlChar":\r
- this.Render.ControlChar = this.ControlChar;\r
+ this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);\r
break;\r
case "Hilight":\r
- this.Render.Hilight = this.Hilight;\r
+ this.Render.Hilight = D2DRender.ToColor4(this.Hilight);\r
break;\r
case "Keyword1":\r
- this.Render.Keyword1 = this.Keyword1;\r
+ this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);\r
break;\r
case "Keyword2":\r
- this.Render.Keyword2 = this.Keyword2;\r
+ this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);\r
break;\r
case "Comment":\r
- this.Render.Comment = this.Comment;\r
+ this.Render.Comment = D2DRender.ToColor4(this.Comment);\r
break;\r
case "Literal":\r
- this.Render.Literal = this.Literal;\r
+ this.Render.Literal = D2DRender.ToColor4(this.Literal);\r
break;\r
case "URL":\r
- this.Render.Url = this.URL;\r
+ this.Render.Url = D2DRender.ToColor4(this.URL);\r
break;\r
case "InsertCaret":\r
- this.Render.InsertCaret = this.InsertCaret;\r
+ this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);\r
break;\r
case "OverwriteCaret":\r
- this.Render.OverwriteCaret = this.OverwriteCaret;\r
+ this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);\r
+ break;\r
+ case "Padding":\r
+ this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);\r
break;\r
case "LineMarker":\r
- this.Render.LineMarker = this.LineMarker;\r
+ this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);\r
break;\r
case "MarkURL":\r
this.View.UrlMark = this.MarkURL;\r
this.View.HideRuler = !this.DrawRuler;\r
this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);\r
break;\r
+ case "UpdateArea":\r
+ this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);\r
+ break;\r
}\r
base.OnPropertyChanged(e);\r
}\r
DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));\r
\r
/// <summary>\r
+ /// 行更新フラグの色を表す\r
+ /// </summary>\r
+ public System.Windows.Media.Color UpdateArea\r
+ {\r
+ get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }\r
+ set { SetValue(UpdateAreaProperty, value); }\r
+ }\r
+\r
+ /// <summary>\r
+ /// UpdateAreaの依存プロパティを表す\r
+ /// </summary>\r
+ public static readonly DependencyProperty UpdateAreaProperty =\r
+ DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen)); \r
+\r
+ /// <summary>\r
/// 上書きモード時のキャレット職を表す\r
/// </summary>\r
public System.Windows.Media.Color OverwriteCaret\r