/// <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); }
public UndoRedoInfo(string text, Win32.POINT scrollPos, int cursorLoc) { Text = text; ScrollPos = scrollPos; CursorLocation = cursorLoc; }
/// <summary> /// The on text changed overrided. Here we parse the text into RTF for the highlighting. /// </summary> /// <param name="e"></param> protected override void OnTextChanged(EventArgs e) { if (mParsing) { return; } if (this.HighlightDescriptors.Count == 0) { base.OnTextChanged(e); OnItemTextChanged(new ItemTextChangedEventArgs(this)); return; } mParsing = true; Win32.SendMessage(Handle, Win32.WM_SETREDRAW, 0, (IntPtr)0); 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; this.Select(0, this.Text.Length); this.SelectionFont = Parent.Font; this.SelectionColor = SystemColors.WindowText; int lastPos; int tokenLength; string token; foreach (HighlightDescriptor hd in this.HighlightDescriptors) { token = hd.Token.Replace("\t", " "); token = token.Replace("\v", "."); lastPos = 0; tokenLength = token.Length; while (true) { lastPos = this.Find(token, lastPos, RichTextBoxFinds.WholeWord); if (lastPos == -1 || lastPos >= this.Text.Length) { break; } this.Select(lastPos, tokenLength); this.SelectionColor = hd.Color; this.Select(lastPos + tokenLength, 1); this.SelectionColor = SystemColors.WindowText; lastPos += 1; } } //Restore cursor and scrollbars location. this.SelectionStart = cursorLoc; this.SelectionLength = 0; SetScrollPos(scrollPos); Win32.SendMessage(Handle, Win32.WM_SETREDRAW, 1, (IntPtr)0); Invalidate(); if (mAutoCompleteShown) { if (mFilterAutoComplete) { SetAutoCompleteItems(); SetAutoCompleteSize(); SetAutoCompleteLocation(false); } SetBestSelectedAutoCompleteItem(); } mParsing = false; OnItemTextChanged(new ItemTextChangedEventArgs(this)); }
/// <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); }
/// <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; }