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
internal bool backcolor_set;
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;
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;
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)
{
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
}
}
-#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;
}
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
}
}
}
}
}
-#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)]
}
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 ();
}
}
[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 {
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 ();
}
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();
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 ();
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)
}
}
-#if NET_2_0
[DefaultValue (true)]
public virtual bool ShortcutsEnabled {
get { return shortcuts_enabled; }
[Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
"System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
-#endif
[Localizable(true)]
public override string Text {
get {
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);
}
}
}
}
-#if NET_2_0
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public override ImageLayout BackgroundImageLayout {
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;
}
}
-#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
//
has_been_focused = true;
+ Modified = false;
OnTextChanged(EventArgs.Empty);
}
public void Clear ()
{
- Text = null;
+ Modified = false;
+ Text = string.Empty;
}
public void ClearUndo ()
document.ReplaceSelection (String.Empty, false);
document.undo.EndUserAction ();
+ Modified = true;
OnTextChanged (EventArgs.Empty);
}
return String.Concat (base.ToString (), ", Text: ", Text);
}
- [MonoTODO("Deleting is classed as Typing, instead of its own Undo event")]
+ [MonoInternalNote ("Deleting is classed as Typing, instead of its own Undo event")]
public void Undo ()
{
- if (document.undo.Undo ())
+ if (document.undo.Undo ()) {
+ Modified = true;
OnTextChanged (EventArgs.Empty);
+ }
}
-#if NET_2_0
public void DeselectAll ()
{
SelectionLength = 0;
{
return document.LineTagToCharIndex (document.caret.line, 0);
}
-#endif
#endregion // Public Instance Methods
#region Protected Instance Methods
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]);
base.OnFontChanged (e);
if (auto_size && !document.multiline) {
- if (PreferredHeight != ClientSize.Height) {
+ if (PreferredHeight != Height) {
Height = PreferredHeight;
}
}
eh (this, e);
}
-#if NET_2_0
protected override void OnPaddingChanged (EventArgs e)
{
base.OnPaddingChanged (e);
}
-#endif
protected virtual void OnReadOnlyChanged (EventArgs e)
{
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);
}
}
}
- OnTextChanged(EventArgs.Empty);
document.AlignCaret();
document.UpdateCaret();
CaretMoved(this, null);
+
+ Modified = true;
+ OnTextChanged (EventArgs.Empty);
+
return true;
}
}
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;
return false;
}
+ internal virtual void RaiseSelectionChanged ()
+ {
+ // Do nothing, overridden in RTB
+ }
+
private void HandleBackspace (bool control)
{
bool fire_changed;
}
}
- if (fire_changed)
+ CaretMoved (this, null);
+
+ if (fire_changed) {
+ Modified = true;
OnTextChanged(EventArgs.Empty);
- CaretMoved(this, null);
+ }
}
private void HandleEnter ()
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);
}
}
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) {
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;
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); }
remove { base.BackgroundImageChanged -= value; }
}
-#if NET_2_0
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler BackgroundImageLayoutChanged {
[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
}
}
+ 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)
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)
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;
}
}
}
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) {
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:
switch (scrollbars) {
case RichTextBoxScrollBars.Both:
case RichTextBoxScrollBars.Vertical:
-
- if (richtext) {
+ if (richtext)
vscroll.Visible = vscroll.Enabled;
- } else {
- vscroll.Visible = true;
- }
+ else
+ vscroll.Visible = this.Multiline;
break;
case RichTextBoxScrollBars.ForcedBoth:
case RichTextBoxScrollBars.ForcedVertical:
}
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;
}
}
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;
}
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;
}
// FIXME - implement center cursor alignment
}
+ if (Text.Length > 0)
+ RaiseSelectionChanged ();
+
if (!document.multiline)
return;
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);
}
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"));
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)
{
}
#endregion
-#if NET_2_0
// This is called just before OnTextChanged is called.
internal virtual void OnTextUpdate ()
{
{
base.OnMouseUp (mevent);
}
-#endif
}
}