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.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="row">行</param>\r
+ /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>\r
+ public void ScrollIntoView(int row, bool alignTop)\r
+ {\r
+ this.View.ScrollIntoView(row, alignTop);\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
{\r
- if (this.disposed)\r
+ if (this.disposed || this.Visibility == Visibility.Collapsed)\r
return;\r
\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
this.Render.EndDraw();\r
-\r
- this.timer.Start();\r
}\r
\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
\r
bool textStore_IsLoading()\r
{\r
- return this.Document.State == AsyncState.Loading;\r
+ return false;\r
}\r
\r
void textStore_CompositionEnded()\r
Point startPos, endPos;\r
TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);\r
\r
- startPos = PointToScreen(this.TranslatePoint(startPos, this));\r
- endPos = PointToScreen(this.TranslatePoint(endPos, this));\r
+ float dpi;\r
+ this.Render.GetDpi(out dpi, out dpi);\r
+ double scale = dpi / 96.0;\r
+ \r
+ startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));\r
+ endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));\r
\r
o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);\r
o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);\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
\r
- void _textStore_InsertAtSelection(string i_value)\r
+ void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)\r
{\r
TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);\r
this.Refresh();\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
/// </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() || this.Document.State == AsyncState.Loading)\r
+ if (this.textStore.IsLocked())\r
return;\r
TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);\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.Complete:\r
- TextStoreHelper.NotifyTextChanged(this.textStore,0,0,this.Document.Length);\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
- }\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
void FooTextBox_Loaded(object sender, RoutedEventArgs e)\r
{\r
this.Resize(this.image.ActualWidth, this.image.ActualHeight);\r
+ this.Focus();\r
+ this.timer.Start();\r
}\r
\r
bool Resize(double width, double height)\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
{\r
switch (e.Property.Name)\r
{\r
+ case "IndentMode":\r
+ this._Controller.IndentMode = this.IndentMode;\r
+ break;\r
case "Selection":\r
if(!this.nowCaretMove)\r
this.Select(this.Selection.Index, this.Selection.Length);\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
+ case "LineNumber":\r
+ this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);\r
+ break;\r
}\r
base.OnPropertyChanged(e);\r
}\r
}\r
\r
/// <summary>\r
+ /// インデントの方法を表す\r
+ /// </summary>\r
+ public IndentMode IndentMode\r
+ {\r
+ get { return (IndentMode)GetValue(IndentModeProperty); }\r
+ set { SetValue(IndentModeProperty, value); }\r
+ }\r
+\r
+ /// <summary>\r
+ /// IndentModeの依存プロパティを表す\r
+ /// </summary>\r
+ public static readonly DependencyProperty IndentModeProperty =\r
+ DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));\r
+\r
+ /// <summary>\r
/// 選択範囲を表す\r
/// </summary>\r
/// <remarks>\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
get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }\r
set { SetValue(OverwriteCaretProperty, value); }\r
}\r
-\r
+ \r
/// <summary>\r
/// OverwriteCaretの依存プロパティを表す\r
/// </summary>\r
public static readonly DependencyProperty OverwriteCaretProperty =\r
DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));\r
- \r
+\r
+ /// <summary>\r
+ /// 行番号の色を表す\r
+ /// </summary>\r
+ public System.Windows.Media.Color LineNumber\r
+ {\r
+ get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }\r
+ set { SetValue(LineNumberProperty, value); }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...\r
+ /// </summary>\r
+ public static readonly DependencyProperty LineNumberProperty =\r
+ DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));\r
+\r
/// <summary>\r
/// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです\r
/// </summary>\r