Exemplo n.º 1
0
 internal static void InsertChar(char c, ref char deletedChar, QText tb)
 {
     switch (c)
     {
         case '\n':
             if (tb.LinesCount == 0) InsertLine(tb);
             InsertLine(tb);
             break;
         case '\r': break;
         case '\b'://backspace
             if (tb.Selection.Start.iChar == 0 && tb.Selection.Start.iLine == 0) return;
             if (tb.Selection.Start.iChar == 0)
             {
                 if (tb[tb.Selection.Start.iLine - 1].VisibleState != VisibleState.Visible) tb.ExpandBlock(tb.Selection.Start.iLine - 1);
                 deletedChar = '\n';
                 MergeLines(tb.Selection.Start.iLine - 1, tb);
             }
             else
             {
                 deletedChar = tb[tb.Selection.Start.iLine][tb.Selection.Start.iChar - 1].c;
                 tb[tb.Selection.Start.iLine].RemoveAt(tb.Selection.Start.iChar - 1);
                 tb.Selection.Start = new Place(tb.Selection.Start.iChar - 1, tb.Selection.Start.iLine);
             }
             break;
         default:
             tb[tb.Selection.Start.iLine].Insert(tb.Selection.Start.iChar, new Char(c));
             tb.Selection.Start = new Place(tb.Selection.Start.iChar + 1, tb.Selection.Start.iLine);
             break;
     }
 }
Exemplo n.º 2
0
        internal AutoCompleteListView(QText tb)
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
            base.Font = new Font(FontFamily.GenericSansSerif, 9);
            visibleItems = new List<AutoCompleteItem>();
            itemHeight = Font.Height + 2;
            VerticalScroll.SmallChange = itemHeight;
            BackColor = Color.White;
            MaximumSize = new Size(Size.Width, 180);
            toolTip.ShowAlways = false;
            AppearInterval = 500;
            timer.Tick += new EventHandler(timer_Tick);

            this.tb = tb;

            tb.KeyDown += new KeyEventHandler(tb_KeyDown);
            tb.SelectionChanged += new EventHandler(tb_SelectionChanged);
            tb.KeyPressed += new KeyPressEventHandler(tb_KeyPressed);

            Form form = tb.FindForm();
            if (form != null)
            {
                form.LocationChanged += (o, e) => Menu.Close();
                form.ResizeBegin += (o, e) => Menu.Close();
                form.FormClosing += (o, e) => Menu.Close();
                form.LostFocus += (o, e) => Menu.Close();
            }

            tb.LostFocus += (o, e) =>
            {
                if (!Menu.Focused) Menu.Close();
            };
            tb.Scroll += (o, e) => Menu.Close();
        }
Exemplo n.º 3
0
 internal static void BreakLines(int iLine, int pos, QText tb)
 {
     Line newLine = new Line(tb.GenerateUniqueLineId());
     for (int i = pos; i < tb[iLine].Count; i++)
         newLine.Add(tb[iLine][i]);
     tb[iLine].RemoveRange(pos, tb[iLine].Count - pos);
     tb.InsertLine(iLine + 1, newLine);
 }
Exemplo n.º 4
0
 public ReplaceTextCommand(QText tb, List<Range> ranges, string insertedText)
     : base(tb)
 {
     this.ranges = ranges;
     this.insertedText = insertedText;
     sel = tb.Selection.Clone();
     sel.SelectAll();
 }
Exemplo n.º 5
0
 public AutoCompleteMenu(QText tb)
 {
     // create a new popup and add the list view to it
     AutoClose = false;
     AutoSize = false;
     Margin = Padding.Empty;
     Padding = Padding.Empty;
     listView = new AutoCompleteListView(tb);
     host = new ToolStripControlHost(listView);
     host.Margin = new Padding(2, 2, 2, 2);
     host.Padding = Padding.Empty;
     host.AutoSize = false;
     host.AutoToolTip = false;
     CalcSize();
     base.Items.Add(host);
     SearchPattern = @"[\w\.]";
     MinFragmentLength = 2;
 }
Exemplo n.º 6
0
 internal static void InsertText(string insertedText, QText tb)
 {
     try
     {
         tb.Selection.BeginUpdate();
         char cc = '\x0';
         if (tb.LinesCount == 0)
             InsertCharCommand.InsertLine(tb);
         tb.ExpandBlock(tb.Selection.Start.iLine);
         foreach (char c in insertedText)
             InsertCharCommand.InsertChar(c, ref cc, tb);
         tb.needRecalc = true;
     }
     finally
     {
         tb.Selection.EndUpdate();
     }
 }
Exemplo n.º 7
0
 internal static void ClearSelected(QText tb)
 {
     Place start = tb.Selection.Start;
     Place end = tb.Selection.End;
     int fromLine = Math.Min(end.iLine, start.iLine);
     int toLine = Math.Max(end.iLine, start.iLine);
     int fromChar = tb.Selection.FromX;
     int toChar = tb.Selection.ToX;
     if (fromLine < 0) return;
     //
     if (fromLine == toLine)
         tb[fromLine].RemoveRange(fromChar, toChar - fromChar);
     else
     {
         tb[fromLine].RemoveRange(fromChar, tb[fromLine].Count - fromChar);
         tb[toLine].RemoveRange(0, toChar);
         tb.RemoveLine(fromLine + 1, toLine - fromLine - 1);
         InsertCharCommand.MergeLines(fromLine, tb);
     }
     //
     tb.Selection.Start = new Place(fromChar, fromLine);
     //
     tb.needRecalc = true;
 }
Exemplo n.º 8
0
        internal static void InsertLine(QText tb)
        {
            if (tb.LinesCount == 0) tb.InsertLine(tb.Selection.Start.iLine + 1, new Line(tb.GenerateUniqueLineId()));
            else BreakLines(tb.Selection.Start.iLine, tb.Selection.Start.iChar, tb);

            tb.Selection.Start = new Place(0, tb.Selection.Start.iLine + 1);
            tb.needRecalc = true;
        }
Exemplo n.º 9
0
 public UndoableCommand(QText tb)
 {
     this.tb = tb;
     sel = tb.Selection.Clone();
 }
Exemplo n.º 10
0
        public string GetHtml(Range r)
        {
            this.tb = r.tb;
            Dictionary<StyleIndex, object> styles = new Dictionary<StyleIndex, object>();
            StringBuilder sb = new StringBuilder();
            StringBuilder tempSB = new StringBuilder();
            StyleIndex currentStyleId = StyleIndex.None;
            r.Normalize();
            int currentLine = r.Start.iLine;
            styles[currentStyleId] = null;
            //
            if (UseOriginalFont)
                sb.AppendFormat("<font style=\"font-family: {0}, monospace; font-size: {1}px; line-height: {2}px;\">", r.tb.Font.Name, r.tb.CharHeight - r.tb.LineInterval, r.tb.CharHeight);
            //
            bool hasNonSpace = false;
            foreach (Place p in r)
            {
                Char c = r.tb[p.iLine][p.iChar];
                if (c.style != currentStyleId)
                {
                    Flush(sb, tempSB, currentStyleId);
                    currentStyleId = c.style;
                    styles[currentStyleId] = null;
                }

                if (p.iLine != currentLine)
                {
                    for (int i = currentLine; i < p.iLine; i++)
                        tempSB.AppendLine(UseBr ? "<br>" : "");
                    currentLine = p.iLine;
                    hasNonSpace = false;
                }
                switch (c.c)
                {
                    case ' ':
                        if ((hasNonSpace || !UseForwardNbsp) && !UseNbsp)
                            goto default;

                        tempSB.Append("&nbsp;");
                        break;
                    case '<':
                        tempSB.Append("&lt;"); break;
                    case '>':
                        tempSB.Append("&gt;"); break;
                    case '&':
                        tempSB.Append("&amp;"); break;
                    default:
                        hasNonSpace = true;
                        tempSB.Append(c.c); break;
                }
            }
            Flush(sb, tempSB, currentStyleId);

            if (UseOriginalFont)
                sb.AppendLine("</font>");

            //build styles
            if (UseStyleTag)
            {
                tempSB.Length = 0;
                tempSB.AppendLine("<style type=\"text/css\">");
                foreach (var styleId in styles.Keys)
                    tempSB.AppendFormat(".fctb{0}{{ {1} }}\r\n", GetStyleName(styleId), GetCss(styleId));
                tempSB.AppendLine("</style>");

                sb.Insert(0, tempSB.ToString());
            }

            return sb.ToString();
        }
Exemplo n.º 11
0
 public string GetHtml(QText tb)
 {
     this.tb = tb;
     Range sel = new Range(tb);
     sel.SelectAll();
     return GetHtml(sel);
 }
Exemplo n.º 12
0
 protected virtual void AddVisualMarker(QText tb, StyleVisualMarker marker)
 {
     tb.AddVisualMarker(marker);
 }
Exemplo n.º 13
0
 public virtual void OnVisualMarkerClick(QText tb, VisualMarkerEventArgs args)
 {
     if (VisualMarkerClick != null)
         VisualMarkerClick(tb, args);
 }
Exemplo n.º 14
0
 public ClearSelectedCommand(QText tb)
     : base(tb)
 {
 }
Exemplo n.º 15
0
        internal static void MergeLines(int i, QText tb)
        {
            if (i + 1 >= tb.LinesCount) return;

            tb.ExpandBlock(i);
            tb.ExpandBlock(i + 1);
            int pos = tb[i].Count;
            //
            if (tb[i].Count == 0)
                tb.RemoveLine(i);
            else
                if (tb[i + 1].Count == 0)
                    tb.RemoveLine(i + 1);
                else
                {
                    tb[i].AddRange(tb[i + 1]);
                    tb.RemoveLine(i + 1);
                }
            tb.Selection.Start = new Place(pos, i);
            tb.needRecalc = true;
        }
Exemplo n.º 16
0
        void DoAutocomplete(QText tb)
        {
            visibleItems.Clear();
            selectedItemIndex = 0;
            VerticalScroll.Value = 0;
            //get fragment around caret
            Range fragment = tb.Selection.GetFragment(Menu.SearchPattern);
            string text = fragment.Text;
            //calc screen point for popup menu
            Point point = tb.PlaceToPoint(fragment.End);
            point.Offset(2, tb.CharHeight);
            //
            if (text.Length >= Menu.MinFragmentLength && tb.Selection.Start == tb.Selection.End)
            {
                Menu.Fragment = fragment;
                bool foundSelected = false;
                //build popup menu
                foreach (var item in sourceItems)
                {
                    item.Parent = Menu;
                    CompareResult res = item.Compare(text);
                    if (res != CompareResult.Hidden)
                        visibleItems.Add(item);
                    if (res == CompareResult.VisibleAndSelected && !foundSelected)
                    {
                        foundSelected = true;
                        selectedItemIndex = visibleItems.Count - 1;
                    }
                }

                if (foundSelected)
                {
                    AdjustScroll();
                    DoSelectedVisible();
                }
            }

            //show popup menu
            if (Count > 0)
            {
                if (!Menu.Visible)
                {
                    //prevSelection = tb.Selection.Start;
                    Menu.Show(tb, point);
                }
                else
                    Invalidate();
            }
            else
                Menu.Close();
        }
Exemplo n.º 17
0
 public InsertTextCommand(QText tb, string insertedText)
     : base(tb)
 {
     this.insertedText = insertedText;
 }
Exemplo n.º 18
0
 public InsertCharCommand(QText tb, char c)
     : base(tb)
 {
     this.c = c;
 }