X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FManaged.Windows.Forms%2FSystem.Windows.Forms%2FTextBoxBase.cs;h=e3c1a70f5cfa98867c03c559fb6c6b8c3afcb28b;hb=837b034d76dc74e14c8dadc1f1f011be08b3d339;hp=81eec108e366adbdd6f68269509e2bd87c29ead3;hpb=036de75d4d14e48c3967011e90ad9588e3430db2;p=mono.git diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs index 81eec108e36..e3c1a70f5cf 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs @@ -38,11 +38,9 @@ using System.Collections; namespace System.Windows.Forms { -#if NET_2_0 [ComVisible (true)] [DefaultBindingProperty ("Text")] [ClassInterface (ClassInterfaceType.AutoDispatch)] -#endif [DefaultEvent("TextChanged")] [Designer("System.Windows.Forms.Design.TextBoxBaseDesigner, " + Consts.AssemblySystem_Design)] public abstract class TextBoxBase : Control @@ -53,10 +51,9 @@ namespace System.Windows.Forms internal bool accepts_return; internal bool auto_size; internal bool backcolor_set; - internal bool disabled_foreground_grey; internal CharacterCasing character_casing; internal bool hide_selection; - internal int max_length; + int max_length; internal bool modified; internal char password_char; internal bool read_only; @@ -116,7 +113,6 @@ namespace System.Windows.Forms list_links = new ArrayList (); current_link = null; show_caret_w_selection = (this is TextBox); - disabled_foreground_grey = true; document = new Document(this); document.WidthChanged += new EventHandler(document_WidthChanged); document.HeightChanged += new EventHandler(document_HeightChanged); @@ -132,6 +128,7 @@ namespace System.Windows.Forms FontChanged += new EventHandler(TextBoxBase_FontOrColorChanged); ForeColorChanged += new EventHandler(TextBoxBase_FontOrColorChanged); MouseWheel += new MouseEventHandler(TextBoxBase_MouseWheel); + RightToLeftChanged += new EventHandler (TextBoxBase_RightToLeftChanged); scrollbars = RichTextBoxScrollBars.None; @@ -155,11 +152,9 @@ namespace System.Windows.Forms ResumeLayout (); SetStyle(ControlStyles.UserPaint | ControlStyles.StandardClick, false); -#if NET_2_0 SetStyle(ControlStyles.UseTextForAccessibility, false); base.SetAutoSizeMode (AutoSizeMode.GrowAndShrink); -#endif canvas_width = ClientSize.Width; canvas_height = ClientSize.Height; @@ -180,12 +175,10 @@ namespace System.Windows.Forms return s.ToUpper(); } -#if NET_2_0 internal override Size GetPreferredSizeCore (Size proposedSize) { return new Size (Width, Height); } -#endif internal override void HandleClick (int clicks, MouseEventArgs me) { @@ -205,6 +198,12 @@ namespace System.Windows.Forms SetStyle (ControlStyles.StandardDoubleClick, false); } + internal override void PaintControlBackground (PaintEventArgs pevent) + { + if (!ThemeEngine.Current.TextBoxBaseShouldPaintBackground (this)) + return; + base.PaintControlBackground (pevent); + } #endregion // Private and Internal Methods #region Public Instance Properties @@ -223,21 +222,13 @@ namespace System.Windows.Forms } } -#if NET_2_0 [Browsable (false)] [EditorBrowsable (EditorBrowsableState.Never)] -#endif [DefaultValue(true)] [Localizable(true)] [RefreshProperties(RefreshProperties.Repaint)] [MWFCategory("Behavior")] - public -#if NET_2_0 - override -#else - virtual -#endif - bool AutoSize { + public override bool AutoSize { get { return auto_size; } @@ -246,13 +237,10 @@ namespace System.Windows.Forms if (value != auto_size) { auto_size = value; if (auto_size) { - if (PreferredHeight != ClientSize.Height) { - ClientSize = new Size(ClientSize.Width, PreferredHeight); + if (PreferredHeight != Height) { + Height = PreferredHeight; } } -#if NET_1_1 - OnAutoSizeChanged(EventArgs.Empty); -#endif } } } @@ -337,9 +325,7 @@ namespace System.Windows.Forms } } -#if NET_2_0 [MergableProperty (false)] -#endif [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Editor("System.Windows.Forms.Design.StringArrayEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))] [Localizable(true)] @@ -375,34 +361,24 @@ namespace System.Windows.Forms } set { - int i; - int l; - - document.Empty(); - - l = value.Length; - - document.SuspendRecalc (); - for (i = 0; i < l; i++) { - + StringBuilder sb = new StringBuilder (); + + for (int i = 0; i < value.Length; i++) { // Don't add the last line if it is just an empty line feed // the line feed is reflected in the previous line's ending - if (i == l - 1 && value [i].Length == 0) + if (i == value.Length - 1 && value[i].Length == 0) break; - - LineEnding ending = LineEnding.Rich; - if (value [i].EndsWith ("\r")) - ending = LineEnding.Hard; - - document.Add (i + 1, CaseAdjust (value[i]), alignment, Font, this.ForeColor, ending); + + sb.Append (value[i] + Environment.NewLine); } - document.ResumeRecalc (true); + int newline_length = Environment.NewLine.Length; - if (IsHandleCreated) - CalculateDocument (); + // We want to remove the final new line character + if (sb.Length >= newline_length) + sb.Remove (sb.Length - newline_length, newline_length); - OnTextChanged(EventArgs.Empty); + Text = sb.ToString (); } } @@ -455,6 +431,9 @@ namespace System.Windows.Forms if (value != document.multiline) { document.multiline = value; + if (this is TextBox) + SetStyle (ControlStyles.FixedHeight, !value); + // SetBoundsCore overrides the Height for multiline if it needs to, // so we don't need to worry about it here. SetBoundsCore (Left, Top, Width, ExplicitBounds.Height, BoundsSpecified.None); @@ -487,15 +466,20 @@ namespace System.Windows.Forms [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [EditorBrowsable(EditorBrowsableState.Advanced)] + // This returns the preferred outer height, not the client height. public int PreferredHeight { get { - return Font.Height + (BorderStyle == BorderStyle.None ? 0 : 7); + int clientDelta = Height - ClientSize.Height; + if (BorderStyle != BorderStyle.None) + return Font.Height + 7 + clientDelta; + + // usually in borderless mode the top margin is 0, but + // try to access it, in case it was set manually, as ToolStrip* controls do + return Font.Height + TopMargin + clientDelta; } } -#if NET_2_0 [RefreshProperties (RefreshProperties.Repaint)] -#endif [DefaultValue(false)] [MWFCategory("Behavior")] public bool ReadOnly { @@ -506,14 +490,12 @@ namespace System.Windows.Forms set { if (value != read_only) { read_only = value; -#if NET_2_0 if (!backcolor_set) { if (read_only) background_color = SystemColors.Control; else background_color = SystemColors.Window; } -#endif OnReadOnlyChanged(EventArgs.Empty); Invalidate (); } @@ -526,14 +508,13 @@ namespace System.Windows.Forms get { string retval = document.GetSelection (); -#if ONLY_1_1 - if (!IsHandleCreated && retval == string.Empty) - return null; -#endif return retval; } set { + if (value == null) + value = String.Empty; + document.ReplaceSelection(CaseAdjust(value), false); ScrollToCaret(); @@ -547,22 +528,13 @@ namespace System.Windows.Forms get { int res = document.SelectionLength (); -#if !NET_2_0 - if (res == 0 && !IsHandleCreated) - res = -1; -#endif - return res; } set { if (value < 0) { string msg = String.Format ("'{0}' is not a valid value for 'SelectionLength'", value); -#if NET_2_0 throw new ArgumentOutOfRangeException ("SelectionLength", msg); -#else - throw new ArgumentException (msg); -#endif } document.InvalidateSelectionArea (); @@ -596,13 +568,12 @@ namespace System.Windows.Forms set { if (value < 0) { string msg = String.Format ("'{0}' is not a valid value for 'SelectionStart'", value); -#if NET_2_0 throw new ArgumentOutOfRangeException ("SelectionStart", msg); -#else - throw new ArgumentException (msg); -#endif } + // If SelectionStart has been used, we don't highlight on focus + has_been_focused = true; + document.InvalidateSelectionArea (); document.SetSelectionStart (value, false); if (selection_length > -1) @@ -614,7 +585,6 @@ namespace System.Windows.Forms } } -#if NET_2_0 [DefaultValue (true)] public virtual bool ShortcutsEnabled { get { return shortcuts_enabled; } @@ -623,7 +593,6 @@ namespace System.Windows.Forms [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)] -#endif [Localizable(true)] public override string Text { get { @@ -648,24 +617,21 @@ namespace System.Windows.Forms if (value == Text) return; + document.Empty (); if ((value != null) && (value != "")) { - - document.Empty (); - document.Insert (document.GetLine (1), 0, false, value); - - document.PositionCaret (document.GetLine (1), 0); - document.SetSelectionToCaret (true); - - ScrollToCaret (); } else { - document.Empty(); - if (IsHandleCreated) + if (IsHandleCreated) { + document.SetSelectionToCaret (true); CalculateDocument (); + } } + + document.PositionCaret (document.GetLine (1), 0); + document.SetSelectionToCaret (true); + + ScrollToCaret (); - // set the var so OnModifiedChanged is not raised - modified = false; OnTextChanged(EventArgs.Empty); } } @@ -698,7 +664,6 @@ namespace System.Windows.Forms } } -#if NET_2_0 [Browsable (false)] [EditorBrowsable (EditorBrowsableState.Never)] public override ImageLayout BackgroundImageLayout { @@ -717,10 +682,18 @@ namespace System.Windows.Forms protected override Cursor DefaultCursor { get { return Cursors.IBeam; } } -#endif #endregion // Public Instance Properties #region Protected Instance Properties + protected override bool CanEnableIme { + get { + if (ReadOnly || password_char != '\0') + return false; + + return true; + } + } + protected override CreateParams CreateParams { get { return base.CreateParams; @@ -733,14 +706,12 @@ namespace System.Windows.Forms } } -#if NET_2_0 // Currently our double buffering breaks our scrolling, so don't let people enable this [EditorBrowsable (EditorBrowsableState.Never)] protected override bool DoubleBuffered { get { return false; } set { } } -#endif #endregion // Protected Instance Properties @@ -750,8 +721,12 @@ namespace System.Windows.Forms // Save some cycles and only check the Text if we are one line bool is_empty = document.Lines == 1 && Text == String.Empty; - document.MoveCaret (CaretDirection.CtrlEnd); - document.Insert (document.caret.line, document.caret.pos, false, text); + // make sure the caret begins at the end + if (document.caret.line.line_no != document.Lines || + (document.caret.pos) != document.caret.line.TextLengthWithoutEnding ()) { + document.MoveCaret (CaretDirection.CtrlEnd); + } + document.Insert (document.caret.line, document.caret.pos, false, text, document.CaretTag); document.MoveCaret (CaretDirection.CtrlEnd); document.SetSelectionToCaret (true); @@ -763,12 +738,14 @@ namespace System.Windows.Forms // has_been_focused = true; + Modified = false; OnTextChanged(EventArgs.Empty); } public void Clear () { - Text = null; + Modified = false; + Text = string.Empty; } public void ClearUndo () @@ -799,6 +776,7 @@ namespace System.Windows.Forms document.ReplaceSelection (String.Empty, false); document.undo.EndUserAction (); + Modified = true; OnTextChanged (EventArgs.Empty); } @@ -852,20 +830,23 @@ namespace System.Windows.Forms return String.Concat (base.ToString (), ", Text: ", Text); } + [MonoInternalNote ("Deleting is classed as Typing, instead of its own Undo event")] public void Undo () { - document.undo.Undo(); + if (document.undo.Undo ()) { + Modified = true; + OnTextChanged (EventArgs.Empty); + } } -#if NET_2_0 public void DeselectAll () { SelectionLength = 0; } - public virtual char GetCharFromPosition (Point p) + public virtual char GetCharFromPosition (Point pt) { - return GetCharFromPositionInternal (p); + return GetCharFromPositionInternal (pt); } internal virtual char GetCharFromPositionInternal (Point p) @@ -896,10 +877,10 @@ namespace System.Windows.Forms return tag.Line.text [index]; } - public virtual int GetCharIndexFromPosition (Point p) + public virtual int GetCharIndexFromPosition (Point pt) { int line_index; - LineTag tag = document.FindCursor (p.X, p.Y, out line_index); + LineTag tag = document.FindCursor (pt.X, pt.Y, out line_index); if (tag == null) return 0; @@ -936,9 +917,9 @@ namespace System.Windows.Forms line.Y + document.viewport_y + tag.Shift); } - public int GetFirstCharIndexFromLine (int line_number) + public int GetFirstCharIndexFromLine (int lineNumber) { - Line line = document.GetLine (line_number + 1); + Line line = document.GetLine (lineNumber + 1); if (line == null) return -1; @@ -949,7 +930,6 @@ namespace System.Windows.Forms { return document.LineTagToCharIndex (document.caret.line, 0); } -#endif #endregion // Public Instance Methods #region Protected Instance Methods @@ -1003,15 +983,6 @@ namespace System.Windows.Forms eh (this, e); } -#if ONLY_1_1 - protected virtual void OnAutoSizeChanged (EventArgs e) - { - EventHandler eh = (EventHandler)(Events [AutoSizeChangedEvent]); - if (eh != null) - eh (this, e); - } -#endif - protected virtual void OnBorderStyleChanged (EventArgs e) { EventHandler eh = (EventHandler)(Events [BorderStyleChangedEvent]); @@ -1024,7 +995,7 @@ namespace System.Windows.Forms base.OnFontChanged (e); if (auto_size && !document.multiline) { - if (PreferredHeight != ClientSize.Height) { + if (PreferredHeight != Height) { Height = PreferredHeight; } } @@ -1062,12 +1033,10 @@ namespace System.Windows.Forms eh (this, e); } -#if NET_2_0 protected override void OnPaddingChanged (EventArgs e) { base.OnPaddingChanged (e); } -#endif protected virtual void OnReadOnlyChanged (EventArgs e) { @@ -1076,14 +1045,18 @@ namespace System.Windows.Forms eh (this, e); } -#if NET_2_0 protected override bool ProcessCmdKey (ref Message msg, Keys keyData) { return base.ProcessCmdKey (ref msg, keyData); } -#endif protected override bool ProcessDialogKey (Keys keyData) { + // The user can use Ctrl-Tab or Ctrl-Shift-Tab to move control focus + // instead of inserting a Tab. However, the focus-moving-tab-stuffs + // doesn't work if Ctrl is pushed, so we remove it before sending it. + if (accepts_tab && (keyData & (Keys.Control | Keys.Tab)) == (Keys.Control | Keys.Tab)) + keyData ^= Keys.Control; + return base.ProcessDialogKey(keyData); } @@ -1119,7 +1092,7 @@ namespace System.Windows.Forms case Keys.Z: if (control && read_only == false) { - Undo(); + Undo (); return true; } return false; @@ -1197,10 +1170,13 @@ namespace System.Windows.Forms } } - OnTextChanged(EventArgs.Empty); document.AlignCaret(); document.UpdateCaret(); CaretMoved(this, null); + + Modified = true; + OnTextChanged (EventArgs.Empty); + return true; } } @@ -1351,8 +1327,10 @@ namespace System.Windows.Forms if (!read_only && accepts_tab && document.multiline) { document.InsertCharAtCaret ('\t', true); - OnTextChanged(EventArgs.Empty); CaretMoved(this, null); + Modified = true; + OnTextChanged (EventArgs.Empty); + return true; } break; @@ -1382,6 +1360,11 @@ namespace System.Windows.Forms return false; } + internal virtual void RaiseSelectionChanged () + { + // Do nothing, overridden in RTB + } + private void HandleBackspace (bool control) { bool fire_changed; @@ -1394,8 +1377,9 @@ namespace System.Windows.Forms document.ReplaceSelection("", false); document.undo.EndUserAction (); fire_changed = true; - } - document.SetSelectionToCaret(true); + document.SetSelectionToCaret (true); + } else { + document.SetSelectionToCaret (true); if (document.CaretPosition == 0) { if (document.CaretLine.LineNo > 1) { @@ -1442,11 +1426,15 @@ namespace System.Windows.Forms } document.UpdateCaret(); fire_changed = true; + } } - if (fire_changed) + CaretMoved (this, null); + + if (fire_changed) { + Modified = true; OnTextChanged(EventArgs.Empty); - CaretMoved(this, null); + } } private void HandleEnter () @@ -1456,18 +1444,18 @@ namespace System.Windows.Forms Line line; if (document.selection_visible) - document.ReplaceSelection ("\n", false); + document.ReplaceSelection ("", false); line = document.CaretLine; document.Split (document.CaretLine, document.CaretTag, document.CaretPosition); - line.ending = LineEnding.Rich; + line.ending = document.StringToLineEnding (Environment.NewLine); document.InsertString (line, line.text.Length, document.LineEndingToString (line.ending)); - OnTextChanged (EventArgs.Empty); - document.UpdateView (line, document.Lines - line.line_no, 0); CaretMoved (this, null); + Modified = true; + OnTextChanged (EventArgs.Empty); } } @@ -1542,13 +1530,13 @@ namespace System.Windows.Forms if (document.Length < max_length) { document.InsertCharAtCaret(c, true); -#if NET_2_0 OnTextUpdate (); -#endif + CaretMoved (this, null); + Modified = true; OnTextChanged(EventArgs.Empty); - CaretMoved(this, null); + } else { - XplatUI.AudibleAlert(); + XplatUI.AudibleAlert(AlertType.Default); } return; } else if (ch == 8) { @@ -1569,6 +1557,11 @@ namespace System.Windows.Forms document.CaretLostFocus (); break; + case Msg.WM_NCPAINT: + if (!ThemeEngine.Current.TextBoxBaseHandleWmNcPaint (this, ref m)) + base.WndProc(ref m); + break; + default: base.WndProc(ref m); return; @@ -1593,10 +1586,8 @@ namespace System.Windows.Forms remove { Events.RemoveHandler (AcceptsTabChangedEvent, value); } } -#if NET_2_0 [Browsable (false)] [EditorBrowsable (EditorBrowsableState.Never)] -#endif public new event EventHandler AutoSizeChanged { add { Events.AddHandler (AutoSizeChangedEvent, value); } remove { Events.RemoveHandler (AutoSizeChangedEvent, value); } @@ -1644,7 +1635,6 @@ namespace System.Windows.Forms remove { base.BackgroundImageChanged -= value; } } -#if NET_2_0 [Browsable (false)] [EditorBrowsable (EditorBrowsableState.Never)] public new event EventHandler BackgroundImageLayoutChanged { @@ -1669,19 +1659,19 @@ namespace System.Windows.Forms [Browsable (true)] [EditorBrowsable (EditorBrowsableState.Always)] -#else - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Advanced)] -#endif public new event EventHandler Click { add { base.Click += value; } remove { base.Click -= value; } } // XXX should this not manipulate base.Paint? +#pragma warning disable 0067 + [MonoTODO] [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new event PaintEventHandler Paint; +#pragma warning restore 0067 + #endregion // Events #region Private Methods @@ -1704,6 +1694,10 @@ namespace System.Windows.Forms } } + internal override bool ScaleChildrenInternal { + get { return false; } + } + internal bool ShowSelection { get { if (show_selection || !hide_selection) { @@ -1723,6 +1717,27 @@ namespace System.Windows.Forms } } + internal int TopMargin { + get { + return document.top_margin; + } + set { + document.top_margin = value; + } + } + + #region UIA Framework Properties + + internal ScrollBar UIAHScrollBar { + get { return hscroll; } + } + + internal ScrollBar UIAVScrollBar { + get { return vscroll; } + } + + #endregion UIA Framework Properties + internal Graphics CreateGraphicsInternal () { if (IsHandleCreated) @@ -1733,15 +1748,7 @@ namespace System.Windows.Forms internal override void OnPaintInternal (PaintEventArgs pevent) { - // Fill background - if (backcolor_set || (Enabled && !read_only)) { - pevent.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(BackColor), pevent.ClipRectangle); - } else { - pevent.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(ThemeEngine.Current.ColorControl), pevent.ClipRectangle); - } - - // Draw the viewable document - document.Draw(pevent.Graphics, pevent.ClipRectangle); + Draw (pevent.Graphics, pevent.ClipRectangle); // // OnPaint does not get raised on MS (see bug #80639) @@ -1749,12 +1756,20 @@ namespace System.Windows.Forms pevent.Handled = true; } + internal void Draw (Graphics g, Rectangle clippingArea) + { + ThemeEngine.Current.TextBoxBaseFillBackground (this, g, clippingArea); + + // Draw the viewable document + document.Draw(g, clippingArea); + } + private void FixupHeight () { if (!richtext) { if (!document.multiline) { - if (PreferredHeight != ClientSize.Height) { - ClientSize = new Size (ClientSize.Width, PreferredHeight); + if (PreferredHeight != Height) { + Height = PreferredHeight; } } } @@ -1775,16 +1790,38 @@ namespace System.Windows.Forms private void TextBoxBase_MouseDown (object sender, MouseEventArgs e) { + bool dbliclick = false; + if (e.Button == MouseButtons.Left) { + // Special case when shift key is pressed and + // left mouse is clicked.. set selection from + // current cursor to mouse + if ((Control.ModifierKeys & Keys.Shift) > 0) { + document.PositionCaret (e.X + document.ViewPortX, e.Y + document.ViewPortY); + document.SetSelectionToCaret (false); + document.DisplayCaret (); + return; + } + + dbliclick = IsDoubleClick (e); + if (current_link != null) { HandleLinkClicked (current_link); return; } + //ensure nothing is selected anymore BEFORE we + //position the caret, so the caret is recreated + //(caret is only visible when nothing is selected) + if (document.selection_visible && dbliclick == false) { + document.SetSelectionToCaret (true); + click_mode = CaretSelection.Position; + } + document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY); - if (IsDoubleClick (e)) { + if (dbliclick) { switch (click_mode) { case CaretSelection.Position: SelectWord (); @@ -1839,6 +1876,10 @@ namespace System.Windows.Forms if (click_mode == CaretSelection.Position) { document.SetSelectionToCaret(false); document.DisplayCaret(); + + // Only raise if there is text. + if (Text.Length > 0) + RaiseSelectionChanged (); } if (scroll_timer != null) { @@ -1848,7 +1889,7 @@ namespace System.Windows.Forms } } - private void PositionControls () + private void SizeControls () { if (hscroll.Visible) { //vscroll.Maximum += hscroll.Height; @@ -1860,27 +1901,60 @@ namespace System.Windows.Forms if (vscroll.Visible) { //hscroll.Maximum += vscroll.Width; canvas_width = ClientSize.Width - vscroll.Width; + + if (GetInheritedRtoL () == RightToLeft.Yes) { + document.OffsetX = vscroll.Width; + } else { + document.OffsetX = 0; + } + } else { canvas_width = ClientSize.Width; + document.OffsetX = 0; } - document.ViewPortWidth = canvas_width; document.ViewPortHeight = canvas_height; + } + private void PositionControls () + { if (canvas_height < 1 || canvas_width < 1) return; - // We always move them, they just might not be displayed - hscroll.Bounds = new Rectangle (ClientRectangle.Left, - Math.Max (0, ClientRectangle.Height - hscroll.Height), - Math.Max (0, ClientSize.Width - (vscroll.Visible ? vscroll.Width : 0)), + int hmod = vscroll.Visible ? vscroll.Width : 0; + int vmod = hscroll.Visible ? hscroll.Height : 0; + + if (GetInheritedRtoL () == RightToLeft.Yes) { + hscroll.Bounds = new Rectangle (ClientRectangle.Left + hmod, + Math.Max(0, ClientRectangle.Height - hscroll.Height), + ClientSize.Width, hscroll.Height); - vscroll.Bounds = new Rectangle (Math.Max (0, ClientRectangle.Right - vscroll.Width), - ClientRectangle.Top, vscroll.Width, - Math.Max (0, ClientSize.Height - (hscroll.Visible ? hscroll.Height : 0))); - + vscroll.Bounds = new Rectangle (ClientRectangle.Left, + ClientRectangle.Top, + vscroll.Width, + Math.Max(0, ClientSize.Height - (vmod))); + } else { + hscroll.Bounds = new Rectangle (ClientRectangle.Left, + Math.Max(0, ClientRectangle.Height - hscroll.Height), + Math.Max(0, ClientSize.Width - hmod), + hscroll.Height); + + vscroll.Bounds = new Rectangle ( + Math.Max(0, ClientRectangle.Right - vscroll.Width), + ClientRectangle.Top, + vscroll.Width, + Math.Max(0, ClientSize.Height - vmod)); + } + } + + internal RightToLeft GetInheritedRtoL () + { + for (Control c = this; c != null; c = c.Parent) + if (c.RightToLeft != RightToLeft.Inherit) + return c.RightToLeft; + return RightToLeft.No; } private void TextBoxBase_SizeChanged (object sender, EventArgs e) @@ -1889,6 +1963,12 @@ namespace System.Windows.Forms CalculateDocument (); } + private void TextBoxBase_RightToLeftChanged (object o, EventArgs e) + { + if (IsHandleCreated) + CalculateDocument (); + } + private void TextBoxBase_MouseWheel (object sender, MouseEventArgs e) { if (!vscroll.Enabled) @@ -1963,6 +2043,7 @@ namespace System.Windows.Forms internal void CalculateScrollBars () { // FIXME - need separate calculations for center and right alignment + SizeControls (); if (document.Width >= document.ViewPortWidth) { hscroll.SetValues (0, Math.Max (1, document.Width), -1, @@ -1988,7 +2069,10 @@ namespace System.Windows.Forms switch (scrollbars) { case RichTextBoxScrollBars.Both: case RichTextBoxScrollBars.Horizontal: - hscroll.Visible = hscroll.Enabled; + if (richtext) + hscroll.Visible = hscroll.Enabled; + else + hscroll.Visible = this.Multiline; break; case RichTextBoxScrollBars.ForcedBoth: case RichTextBoxScrollBars.ForcedHorizontal: @@ -2005,7 +2089,10 @@ namespace System.Windows.Forms switch (scrollbars) { case RichTextBoxScrollBars.Both: case RichTextBoxScrollBars.Vertical: - vscroll.Visible = vscroll.Enabled; + if (richtext) + vscroll.Visible = vscroll.Enabled; + else + vscroll.Visible = this.Multiline; break; case RichTextBoxScrollBars.ForcedBoth: case RichTextBoxScrollBars.ForcedVertical: @@ -2017,6 +2104,8 @@ namespace System.Windows.Forms } PositionControls (); + + SizeControls (); //Update sizings now we've decided whats visible } private void document_WidthChanged (object sender, EventArgs e) @@ -2051,7 +2140,11 @@ namespace System.Windows.Forms document.CaretLostFocus (); if (vscroll.Visible) { - XplatUI.ScrollWindow(this.Handle, new Rectangle(0, 0, ClientSize.Width - vscroll.Width, ClientSize.Height), old_viewport_x - this.hscroll.Value, 0, false); + if (GetInheritedRtoL () == RightToLeft.Yes) { + XplatUI.ScrollWindow (this.Handle, new Rectangle (vscroll.Width, 0, ClientSize.Width - vscroll.Width, ClientSize.Height), old_viewport_x - this.hscroll.Value, 0, false); + } else { + XplatUI.ScrollWindow (this.Handle, new Rectangle (0, 0, ClientSize.Width - vscroll.Width, ClientSize.Height), old_viewport_x - this.hscroll.Value, 0, false); + } } else { XplatUI.ScrollWindow(this.Handle, ClientRectangle, old_viewport_x - this.hscroll.Value, 0, false); } @@ -2137,33 +2230,27 @@ namespace System.Windows.Forms } if (found_link == false) { -#if NET_2_0 XplatUI.SetCursor (window.Handle, DefaultCursor.handle); -#else - XplatUI.SetCursor(window.Handle, Cursors.IBeam.handle); -#endif current_link = null; } } private void TextBoxBase_FontOrColorChanged (object sender, EventArgs e) { - if (!richtext) { - Line line; + Line line; - document.SuspendRecalc (); - // Font changes apply to the whole document - for (int i = 1; i <= document.Lines; i++) { - line = document.GetLine(i); - if (LineTag.FormatText(line, 1, line.text.Length, Font, ForeColor, - Color.Empty, FormatSpecified.Font | FormatSpecified.Color)) - document.RecalculateDocument (CreateGraphicsInternal (), line.LineNo, line.LineNo, false); - } - document.ResumeRecalc (false); - - // Make sure the caret height is matching the new font height - document.AlignCaret(); + document.SuspendRecalc (); + // Font changes apply to the whole document + for (int i = 1; i <= document.Lines; i++) { + line = document.GetLine(i); + if (LineTag.FormatText(line, 1, line.text.Length, Font, ForeColor, + Color.Empty, FormatSpecified.Font | FormatSpecified.Color)) + document.RecalculateDocument (CreateGraphicsInternal (), line.LineNo, line.LineNo, false); } + document.ResumeRecalc (false); + + // Make sure the caret height is matching the new font height + document.AlignCaret(); } private void ScrollTimerTickHandler (object sender, EventArgs e) @@ -2221,7 +2308,7 @@ namespace System.Windows.Forms if (pos.X < (document.ViewPortX)) { do { if ((hscroll.Value - document.ViewPortWidth / 3) >= hscroll.Minimum) { - hscroll.Value -= document.ViewPortWidth / 3; + hscroll.SafeValueSet (hscroll.Value - document.ViewPortWidth / 3); } else { hscroll.Value = hscroll.Minimum; } @@ -2232,7 +2319,7 @@ namespace System.Windows.Forms if ((pos.X >= (document.ViewPortWidth + document.ViewPortX)) && (hscroll.Value != hscroll.Maximum)) { if ((pos.X - document.ViewPortWidth + 1) <= hscroll.Maximum) { if (pos.X - document.ViewPortWidth >= 0) { - hscroll.Value = pos.X - document.ViewPortWidth + 1; + hscroll.SafeValueSet (pos.X - document.ViewPortWidth + 1); } else { hscroll.Value = 0; } @@ -2250,6 +2337,9 @@ namespace System.Windows.Forms // FIXME - implement center cursor alignment } + if (Text.Length > 0) + RaiseSelectionChanged (); + if (!document.multiline) return; @@ -2257,7 +2347,7 @@ namespace System.Windows.Forms height = document.CaretLine.Height + 1; if (pos.Y < document.ViewPortY) - vscroll.Value = pos.Y; + vscroll.SafeValueSet (pos.Y); if ((pos.Y + height) > (document.ViewPortY + canvas_height)) vscroll.Value = Math.Min (vscroll.Maximum, pos.Y - canvas_height + height); } @@ -2295,6 +2385,7 @@ namespace System.Windows.Forms document.undo.BeginUserAction (Locale.GetText ("Paste")); ((RichTextBox)this).SelectedRtf = (string)clip.GetData(DataFormats.Rtf); document.undo.EndUserAction (); + Modified = true; return true; } else if (format.Name == DataFormats.Bitmap) { document.undo.BeginUserAction (Locale.GetText ("Paste")); @@ -2315,21 +2406,25 @@ namespace System.Windows.Forms this.SelectedText = s; document.undo.EndUserAction (); } else { - if ((s.Length + document.Length) < max_length) { + if ((s.Length + (document.Length - SelectedText.Length)) < max_length) { document.undo.BeginUserAction (Locale.GetText ("Paste")); this.SelectedText = s; document.undo.EndUserAction (); - } else if (document.Length < max_length) { + } else if ((document.Length - SelectedText.Length) < max_length) { document.undo.BeginUserAction (Locale.GetText ("Paste")); - this.SelectedText = s.Substring (0, max_length - document.Length); + this.SelectedText = s.Substring (0, max_length - (document.Length - SelectedText.Length)); document.undo.EndUserAction (); } } + Modified = true; return true; } - internal abstract Color ChangeBackColor (Color backColor); + internal virtual Color ChangeBackColor (Color backColor) + { + return backColor; + } internal override bool IsInputCharInternal (char charCode) { @@ -2366,7 +2461,6 @@ namespace System.Windows.Forms } #endregion -#if NET_2_0 // This is called just before OnTextChanged is called. internal virtual void OnTextUpdate () { @@ -2388,10 +2482,9 @@ namespace System.Windows.Forms return line_out.LineNo; } - protected override void OnMouseUp (MouseEventArgs e) + protected override void OnMouseUp (MouseEventArgs mevent) { - base.OnMouseUp (e); + base.OnMouseUp (mevent); } -#endif } }