コード例 #1
0
 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
 {
     base.OnPropertyChanged(e);
     if (e.Property == DataContextProperty)
     {
         if (e.OldValue is IMRATextItemInfo)
         {
             IMRATextItemInfo oldvalue = (IMRATextItemInfo)(e.OldValue);
             oldvalue.View = null;
         }
         if (e.NewValue is IMRATextItemInfo)
         {
             IMRATextItemInfo newvalue = (IMRATextItemInfo)(e.NewValue);
             newvalue.View = this;
         }
         if (Core == null)
         {
             ReleaseMouseOver();
         }
         else
         {
             InvalidateVisual();
             Width  = Math.Max(TextCore.View.ActualWidth, textline.Width + TextCore.View.MarginLeft);
             Height = textline.TextHeight;
             Point p = Mouse.PrimaryDevice.GetPosition(this);
             UpdateMouseOver(p);
         }
     }
 }
コード例 #2
0
 protected virtual void OnIsCltOpeningChanged(DependencyPropertyChangedEventArgs e)
 {
     if (IsCltOpening)
     {
         int line   = Core.SelectedStart.Line;
         int column = Core.SelectedStart.Column;
         IMRATextItemInfo lineitem = UI_Main.GetItem(line);
         MRATextItemView  lineview = lineitem?.View;
         if (lineview == null)
         {
             return;
         }
         #region Canvas Top
         {
             Point p = lineview.TranslatePoint(new Point(0, 0), CV_Cover);
             if (p.Y + lineview.ActualHeight + UI_CltBox.ActualHeight < ActualHeight)
             {
                 Canvas.SetTop(UI_CltBox, p.Y + lineview.ActualHeight);
             }
             else
             {
                 Canvas.SetTop(UI_CltBox, p.Y - UI_CltBox.ActualHeight);
             }
         }
         #endregion
         #region Canvas Left
         {
             Rect   rect = lineview.GetColumnActualRect(column);
             double x    = rect.X;
             if (UI_Main.UI_Stack != null)
             {
                 x -= UI_Main.UI_Stack.HorizontalOffset;
             }
             x = Math.Max(x, 0.0);
             x = Math.Min(x, ActualWidth - UI_CltBox.ActualWidth);
             Canvas.SetLeft(UI_CltBox, x);
         }
         #endregion
         IEnumerable <IMRACltItem> cltsrcs = Counselor.GetCltItems(Core.GetInputContext());
         UI_CltBox.SetCltSources(cltsrcs);
         ITextPosition pos = Core.SelectedStart.NextSeek();
         UI_CltBox.SetInputText(String.Empty);
         UI_CltBox.SetInputText(pos.Item.ToString());
         UI_CltBox.Visibility = Visibility.Visible;
     }
     else
     {
         UI_CltBox.Visibility = Visibility.Hidden;
     }
 }
コード例 #3
0
        protected override void Render(DrawingContext ctx)
        {
            if (Core == null || Core.IsDisposed)
            {
                return;
            }
            base.Render(ctx);
            IMRATextItemInfo item = ViewParent?.Core;
            ITextBoxCore     core = ViewParent?.TextCore;
            WinTextLine      text = ViewParent?.TextLine;

            if (core == null)
            {
                return;
            }
            ITextPosition start = core.SelectedStart;
            ITextPosition end   = core.SelectedEnd;

            if (start.CompareTo(end) == 0)
            {
                ITextPosition pos = start.NextSeek();
                RenderBracket(ctx, pos);
                RenderDefaultMatch(ctx, pos);
                pos = pos.PrevSeek();
                RenderBracket(ctx, pos);
                RenderDefaultMatch(ctx, pos);
            }
            if (start.Line == end.Line && start.Column == end.Column)
            {
                status = start.Line == item.Line ? SelectionStatus.Caret : SelectionStatus.None;
            }
            else if (item.Line >= start.Line && item.Line <= end.Line)
            {
                status = SelectionStatus.Range;
            }
            else
            {
                status = SelectionStatus.None;
            }
            switch (status)
            {
            case SelectionStatus.None:
                break;

            case SelectionStatus.Caret:
            {
                if (!blinkshow && !forceshow)
                {
                    break;
                }
                int        index     = start.Column - 1;
                TextBounds bound     = text.GetTextBounds(index, 1).FirstOrDefault();
                Brush      brush     = null;
                double     thickness = 1.0;
                ViewParent.TextCore.DictBrush.TryGetValue("foreground_rawtext_caret", out brush);
                ViewParent.TextCore.DictValue.TryGetValue("rawtext_caret_thickness", out thickness);
                Pen   pen = new Pen(brush, thickness);
                Point p1  = bound.Rectangle.TopLeft;
                Point p2  = bound.Rectangle.BottomLeft;
                p1.Y -= 2;
                p1.X += ViewParent.TextCore.View.MarginLeft;
                p2.X += ViewParent.TextCore.View.MarginLeft;
                ctx.DrawLine(pen, p1, p2);
            }
            break;

            case SelectionStatus.Range:
            {
                //int left = start.Column - 1;
                //int right = end.Column - 1;
                if (start.Line < item.Line)
                {
                    start = Core.Start;
                }
                if (end.Line > item.Line)
                {
                    end = Core.End;
                }
                //if (right - left <= 0) break;
                //TextBounds bound = text.GetTextBounds(left, right - left).FirstOrDefault();
                Brush brush = null;
                //Rect rect = bound.Rectangle;
                ViewParent.TextCore.DictBrush.TryGetValue("background_rawtext_selected", out brush);
                //rect.X += ViewParent.TextCore.View.MarginLeft;
                //ctx.DrawRectangle(brush, null, rect);
                DrawTextRectangle(ctx, brush, null, start, end);
            }
            break;
            }
        }