Example #1
0
        /// <summary>
        /// Sends a win32 message to get the scrollbars' position.
        /// </summary>
        /// <returns>a POINT structore containing horizontal and vertical scrollbar position.</returns>
        private unsafe Win32.POINT GetScrollPos()
        {
            Win32.POINT res = new Win32.POINT();
            IntPtr      ptr = new IntPtr(&res);

            Win32.SendMessage(Handle, Win32.EM_GETSCROLLPOS, 0, ptr);
            return(res);
        }
Example #2
0
        /// <summary>
        /// Sends a win32 message to set scrollbars position.
        /// </summary>
        /// <param name="point">a POINT conatining H/Vscrollbar scrollpos.</param>
        private unsafe void SetScrollPos(Win32.POINT point)
        {
            IntPtr ptr = new IntPtr(&point);

            Win32.SendMessage(Handle, Win32.EM_SETSCROLLPOS, 0, ptr);
        }
Example #3
0
 public UndoRedoInfo(string text, Win32.POINT scrollPos, int cursorLoc)
 {
     Text           = text;
     ScrollPos      = scrollPos;
     CursorLocation = cursorLoc;
 }
Example #4
0
        /// <summary>
        /// The on text changed overrided. Here we parse the text into RTF for the .
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTextChanged(EventArgs e)
        {
            if (mParsing)
            {
                return;
            }
            mParsing = true;
            Win32.LockWindowUpdate(Handle);
            base.OnTextChanged(e);

            if (!mIsUndo)
            {
                mRedoStack.Clear();
                mUndoList.Insert(0, mLastInfo);
                this.LimitUndo();
                mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
            }

            //Save scroll bar an cursor position, changeing the RTF moves the cursor and scrollbars to top positin
            Win32.POINT scrollPos = GetScrollPos();
            int         cursorLoc = SelectionStart;

            //Created with an estimate of how big the stringbuilder has to be...
            StringBuilder sb = new StringBuilder((int)(Text.Length * 1.5 + 150));

            //Kevin.C modify 2005-12
            //Adding RTF header
            //sb.Append(@"{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{");
            sb.Append(@"{\rtf1\fbidis\ansi\ansicpg1255\deff0\deflang1037\deftab380{\fonttbl{");

            //Font table creation
            int       fontCounter = 0;
            Hashtable fonts       = new Hashtable();

            AddFontToTable(sb, Font, ref fontCounter, fonts);
            foreach (Descriptor desc in mDescriptors)
            {
                if ((desc.Font != null) && !fonts.ContainsKey(desc.Font.Name))
                {
                    AddFontToTable(sb, desc.Font, ref fontCounter, fonts);
                }
            }
            sb.Append("}\n");

            //ColorTable
            int colorCounter = 1;

            sb.Append(@"{\colortbl ;");
            Hashtable colors = new Hashtable();

            AddColorToTable(sb, ForeColor, ref colorCounter, colors);
            AddColorToTable(sb, BackColor, ref colorCounter, colors);
            foreach (Descriptor desc in mDescriptors)
            {
                if (!colors.ContainsKey(desc.Color))
                {
                    AddColorToTable(sb, desc.Color, ref colorCounter, colors);
                }
            }

            //Parsing text
            sb.Append("}\n").Append(@"\viewkind4\uc1\pard\ltrpar");
            SetDefaultSettings(sb, colors, fonts);

            //Seperators
            char[] sperators = mSeperators.GetAsCharArray();

            //Replacing "\" to "\\" for RTF...
            string[] lines = Text.Replace("\\", "\\\\").Replace("{", "\\{").Replace("}", "\\}").Split('\n');
            for (int lineCounter = 0; lineCounter < lines.Length; lineCounter++)
            {
                if (lineCounter != 0)
                {
                    AddNewLine(sb);
                }
                string   line   = lines[lineCounter];
                string[] tokens = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
                if (tokens.Length == 0)
                {
                    sb.Append(line);
                    AddNewLine(sb);
                    continue;
                }

                int tokenCounter = 0;
                for (int i = 0; i < line.Length;)
                {
                    char curChar = line[i];
                    if (mSeperators.Contains(curChar))
                    {
                        sb.Append(curChar);
                        i++;
                    }
                    else
                    {
                        string curToken  = tokens[tokenCounter++];
                        bool   bAddToken = true;
                        foreach (Descriptor desc in mDescriptors)
                        {
                            string compareStr = mCaseSesitive ? desc.Token : desc.Token.ToUpper();
                            bool   match      = false;

                            //Check if the  descriptor matches the current toker according to the DescriptoRecognision property.
                            switch (desc.DescriptorRecognition)
                            {
                            case DescriptorRecognition.WholeWord:
                                if (curToken == compareStr)
                                {
                                    match = true;
                                }
                                break;

                            case DescriptorRecognition.StartsWith:
                                if (curToken.StartsWith(compareStr))
                                {
                                    match = true;
                                }
                                break;

                            case DescriptorRecognition.Contains:
                                if (curToken.IndexOf(compareStr) != -1)
                                {
                                    match = true;
                                }
                                break;
                            }
                            if (!match)
                            {
                                //If this token doesn't match chech the next one.
                                continue;
                            }

                            //printing this token will be handled by the inner code, don't apply default settings...
                            bAddToken = false;

                            //Set colors to current descriptor settings.
                            SetDescriptorSettings(sb, desc, colors, fonts);

                            //Print text affected by this descriptor.
                            switch (desc.DescriptorType)
                            {
                            case DescriptorType.Word:
                                sb.Append(line.Substring(i, curToken.Length));
                                SetDefaultSettings(sb, colors, fonts);
                                i += curToken.Length;
                                break;

                            case DescriptorType.ToEOL:
                                sb.Append(line.Remove(0, i));
                                i = line.Length;
                                SetDefaultSettings(sb, colors, fonts);
                                break;

                            case DescriptorType.ToCloseToken:
                                while ((line.IndexOf(desc.CloseToken, i) == -1) && (lineCounter < lines.Length))
                                {
                                    sb.Append(line.Remove(0, i));
                                    lineCounter++;
                                    if (lineCounter < lines.Length)
                                    {
                                        AddNewLine(sb);
                                        line = lines[lineCounter];
                                        i    = 0;
                                    }
                                    else
                                    {
                                        i = line.Length;
                                    }
                                }
                                if (line.IndexOf(desc.CloseToken, i) != -1)
                                {
                                    sb.Append(line.Substring(i, line.IndexOf(desc.CloseToken, i) + desc.CloseToken.Length - i));
                                    line         = line.Remove(0, line.IndexOf(desc.CloseToken, i) + desc.CloseToken.Length);
                                    tokenCounter = 0;
                                    tokens       = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
                                    SetDefaultSettings(sb, colors, fonts);
                                    i = 0;
                                }
                                break;
                            }
                            break;
                        }
                        if (bAddToken)
                        {
                            //Print text with default settings...
                            sb.Append(line.Substring(i, curToken.Length));
                            i += curToken.Length;
                        }
                    }
                }
            }

            //System.Diagnostics.Debug.WriteLine(sb.ToString());
            Rtf = sb.ToString();

            //Restore cursor and scrollbars location.
            SelectionStart = cursorLoc;
            mParsing       = false;
            SetScrollPos(scrollPos);
            Win32.LockWindowUpdate((IntPtr)0);
            Invalidate();


            //Adjust AutoCompleteForm items, size, location, selectItem
            if (mAutoCompleteShown)
            {
                if (mFilterAutoComplete)
                {
                    SetAutoCompleteItems();
                    SetAutoCompleteSize();
                    SetAutoCompleteLocation(true);                     //...
                }
                SetBestSelectedAutoCompleteItem();
            }
        }