Author: andreia
Date: 2007-05-25 11:40:53 -0400 (Fri, 25 May 2007)
New Revision: 77948
Modified:
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NumericUpDown.cs
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/UpDownBase.cs
Log:
2007-05-25 Andreia Gaita <[EMAIL PROTECTED]>
Proper fixes for PieChart
* NumericUpDown.cs: Refactor code to fix regressions on #79950 and
fixes for PieChart. suppress_validation should not be a counter,
if there are several BeginInit calls, the first EndInit will
activate validation. Fix exceptions thrown by set_Value.
* UpDownBase.cs: ValidateText only if it's the user editing it.
Modified:
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
---
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-05-25 14:51:06 UTC (rev 77947)
+++
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-05-25 15:40:53 UTC (rev 77948)
@@ -1,3 +1,12 @@
+2007-05-25 Andreia Gaita <[EMAIL PROTECTED]>
+ Proper fixes for PieChart
+
+ * NumericUpDown.cs: Refactor code to fix regressions on #79950 and
+ fixes for PieChart. suppress_validation should not be a counter,
+ if there are several BeginInit calls, the first EndInit will
+ activate validation. Fix exceptions thrown by set_Value.
+ * UpDownBase.cs: ValidateText only if it's the user editing it.
+
2007-05-23 Andreia Gaita <[EMAIL PROTECTED]>
* NumericUpDown.cs: Fix PieChart by not returning from UpdateEditText
@@ -25832,5 +25841,3 @@
XplatUIDriver.cs, XplatUIStructs.cs, XplatUIWin32.cs,
XplatUIX11.cs, lang.cs:
- Initial check-in
-
-
Modified:
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NumericUpDown.cs
===================================================================
---
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NumericUpDown.cs
2007-05-25 14:51:06 UTC (rev 77947)
+++
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NumericUpDown.cs
2007-05-25 15:40:53 UTC (rev 77948)
@@ -45,7 +45,7 @@
#endif
public class NumericUpDown : UpDownBase, ISupportInitialize {
#region Local Variables
- private int suppress_validation;
+ private bool suppress_validation;
private int decimal_places;
private bool hexadecimal;
private decimal increment;
@@ -57,7 +57,7 @@
#region Public Constructors
public NumericUpDown() {
- suppress_validation = 0;
+ suppress_validation = false;
decimal_places = 0;
hexadecimal = false;
increment = 1M;
@@ -251,20 +251,23 @@
public decimal Value {
get {
if (UserEdit)
- dvalue = ParseEditText (Text);
+ ValidateEditText ();
return dvalue;
}
set {
- if (suppress_validation <= 0) {
- if ((value < minimum) || (value >
maximum)) {
- throw new
ArgumentException("NumericUpDown.Value must be within the specified Minimum and
Maximum values", "value");
- }
- }
if (value != dvalue) {
+ if (!suppress_validation && ((value <
minimum) || (value > maximum))) {
+#if NET_2_0
+ throw new
ArgumentOutOfRangeException ("value", "NumericUpDown.Value must be within the
specified Minimum and Maximum values");
+#else
+ throw new ArgumentException
("NumericUpDown.Value must be within the specified Minimum and Maximum values",
"value");
+#endif
+ }
+
dvalue = value;
- OnValueChanged(EventArgs.Empty);
- Text = UpdateEditText (dvalue);
+ OnValueChanged (EventArgs.Empty);
+ UpdateEditText ();
}
}
}
@@ -272,13 +275,13 @@
#region Public Instance Methods
public void BeginInit() {
- suppress_validation++;
+ suppress_validation = true;
}
public void EndInit() {
- suppress_validation--;
- if (suppress_validation == 0)
- UpdateEditText ();
+ suppress_validation = false;
+ Value = Check (dvalue);
+ UpdateEditText ();
}
public override string ToString() {
@@ -286,20 +289,19 @@
}
public override void DownButton() {
- decimal val = dvalue;
if (UserEdit) {
- val = ParseEditText (Text);
+ ParseEditText ();
}
- Value = Math.Max(minimum, unchecked(val - increment));
+ Value = Math.Max (minimum, unchecked (dvalue -
increment));
}
public override void UpButton() {
- decimal val = dvalue;
- if (UserEdit)
- val = ParseEditText (Text);
+ if (UserEdit) {
+ ParseEditText ();
+ }
- Value = Math.Min(maximum, unchecked(val + increment));
+ Value = Math.Min (maximum, unchecked (dvalue +
increment));
}
#endregion // Public Instance Methods
@@ -341,54 +343,45 @@
}
protected void ParseEditText () {
- Value = ParseEditText (Text);
- UserEdit = false;
- }
-
- private decimal ParseEditText (string text) {
- UserEdit = false;
- decimal ret = dvalue;
-
try {
- string user_edit_text = text;
-
if (!hexadecimal) {
- ret = decimal.Parse(user_edit_text,
CultureInfo.CurrentCulture);
+ Value = decimal.Parse (Text,
CultureInfo.CurrentCulture);
} else {
#if !NET_2_0
- ret = Convert.ToDecimal
(Convert.ToInt32 (user_edit_text, 16));
+ Value = Check (Convert.ToDecimal
(Convert.ToInt32 (Text, 16)));
#else
- ret = Convert.ToDecimal
(Convert.ToInt32 (user_edit_text, 10));
+ Value = Check (Convert.ToDecimal
(Convert.ToInt32 (Text, 10)));
#endif
}
+ }
+ catch { }
+ finally {
+ UserEdit = false;
+ }
+ }
- if (ret < minimum) {
- ret = minimum;
- }
+ private decimal Check (decimal val)
+ {
+ decimal ret = val;
+ if (ret < minimum) {
+ ret = minimum;
+ }
- if (ret > maximum) {
- ret = maximum;
- }
+ if (ret > maximum) {
+ ret = maximum;
}
- catch {}
+
return ret;
}
- protected override void UpdateEditText() {
- Text = UpdateEditText (ParseEditText (Text));
- }
+ protected override void UpdateEditText () {
+ if (suppress_validation)
+ return;
- private string UpdateEditText (decimal val) {
- // TODO: why is this here?
-// if (suppress_validation > 0)
-// return Text;
-
- decimal ret = val;
- string text = Text;
-
if (UserEdit)
- ret = ParseEditText (text); // parse user input
+ ParseEditText ();
+ ChangingText = true;
if (!hexadecimal) {
// "N" and "F" differ only in that "N" includes
commas
// every 3 digits to the left of the decimal
and "F"
@@ -404,15 +397,14 @@
format_string += decimal_places;
- ChangingText = true;
- text = ret.ToString(format_string,
CultureInfo.CurrentCulture);
- }
- else {
+ Text = dvalue.ToString (format_string,
CultureInfo.CurrentCulture);
+
+ } else {
// Decimal.ToString doesn't know the "X"
formatter, and
// converting it to an int is narrowing, so do
it
// manually...
- int[] bits = decimal.GetBits(ret);
+ int[] bits = decimal.GetBits (dvalue);
bool negative = (bits[3] < 0);
@@ -424,59 +416,56 @@
radix[0] = 1;
- for (int i=0; i < scale; i++)
- wide_number_multiply_by_10(radix);
+ for (int i = 0; i < scale; i++)
+ wide_number_multiply_by_10 (radix);
int num_chars = 0;
- while (!wide_number_less_than(bits, radix)) {
+ while (!wide_number_less_than (bits, radix)) {
num_chars++;
- wide_number_multiply_by_16(radix);
+ wide_number_multiply_by_16 (radix);
}
if (num_chars == 0) {
-// ChangingText = true;
- text = "0";
- return text;
+ Text = "0";
}
StringBuilder chars = new StringBuilder ();
if (negative)
- chars.Append('-');
+ chars.Append ('-');
- for (int i=0; i < num_chars; i++) {
+ for (int i = 0; i < num_chars; i++) {
int digit = 0;
- wide_number_divide_by_16(radix);
+ wide_number_divide_by_16 (radix);
- while (!wide_number_less_than(bits,
radix)) { // greater than or equals
+ while (!wide_number_less_than (bits,
radix)) { // greater than or equals
digit++;
- wide_number_subtract(bits,
radix);
+ wide_number_subtract (bits,
radix);
}
if (digit < 10) {
- chars.Append((char)('0' +
digit));
+ chars.Append ((char) ('0' +
digit));
} else {
- chars.Append((char)('A' + digit
- 10));
+ chars.Append ((char) ('A' +
digit - 10));
}
}
-// ChangingText = true;
- text = chars.ToString();
+ Text = chars.ToString ();
}
- return text;
}
protected override void ValidateEditText() {
- Value = ParseEditText (Text);
+ ParseEditText ();
+ UpdateEditText ();
}
#if NET_2_0
protected override void OnLostFocus(EventArgs e) {
base.OnLostFocus(e);
- if (this.UserEdit)
- this.UpdateEditText();
+ if (UserEdit)
+ UpdateEditText();
}
#endif
#endregion // Protected Instance Methods
Modified:
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/UpDownBase.cs
===================================================================
---
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/UpDownBase.cs
2007-05-25 14:51:06 UTC (rev 77947)
+++
branches/mono-1-2-4/mcs/class/Managed.Windows.Forms/System.Windows.Forms/UpDownBase.cs
2007-05-25 15:40:53 UTC (rev 77948)
@@ -531,11 +531,8 @@
return "";
}
set {
- bool suppress_validation = changing_text;
-
txtView.Text = value;
-
- if (!suppress_validation)
+ if (this.UserEdit)
ValidateEditText();
txtView.SelectionLength = 0;
@@ -677,7 +674,7 @@
protected virtual void OnTextBoxLostFocus (object source,
EventArgs e)
{
- if (user_edit) {
+ if (UserEdit) {
ValidateEditText();
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches