Author: calberto
Date: 2006-11-29 13:13:48 -0500 (Wed, 29 Nov 2006)
New Revision: 68680
Added:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NumericTextBox.cs
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PageSetupDialog.cs
Log:
2006-11-29 Carlos Alberto Cortez <[EMAIL PROTECTED]>
* PageSetupDialog.cs: Validate the margins and set them in
PageSettings.
* NumericTextBox.cs: New class to mimic the behavior of the
textboxes used in the printing dialogs.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2006-11-29 17:39:39 UTC (rev 68679)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2006-11-29 18:13:48 UTC (rev 68680)
@@ -1,3 +1,10 @@
+2006-11-29 Carlos Alberto Cortez <[EMAIL PROTECTED]>
+
+ * PageSetupDialog.cs: Validate the margins and set them in
+ PageSettings.
+ * NumericTextBox.cs: New class to mimic the behavior of the
+ textboxes used in the printing dialogs.
+
2006-11-29 Andreia Gaita <[EMAIL PROTECTED]>
* Form.cs: Revert previous change (remove call UpdateBounds
Added:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NumericTextBox.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NumericTextBox.cs
2006-11-29 17:39:39 UTC (rev 68679)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NumericTextBox.cs
2006-11-29 18:13:48 UTC (rev 68680)
@@ -0,0 +1,104 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005-2006 Novell, Inc.
+//
+// Authors:
+// Carlos Alberto Cortez <[EMAIL PROTECTED]>
+//
+
+using System;
+
+namespace System.Windows.Forms
+{
+ class NumericTextBox : TextBox
+ {
+ double val;
+ double min;
+
+ // Last valid value for the numeric textbox
+ public double Value {
+ get {
+ return val;
+ }
+ set {
+ if (value == val)
+ return;
+ if (value < min)
+ value = min;
+
+ val = value;
+ OnValueChanged (EventArgs.Empty);
+ }
+ }
+
+ public double Min {
+ get {
+ return min;
+ }
+ set {
+ min = value;
+ }
+ }
+
+ protected void OnLostFocus (EventArgs args)
+ {
+ // Update to the last valid value
+ string val = Value.ToString ();
+ if (Text != val)
+ Text = val;
+
+ base.OnLostFocus (args);
+ }
+
+ protected override void OnTextChanged (EventArgs args)
+ {
+ // Try to set the value to the new text.
+ // Otherwise keep the old one.
+ try {
+ string text = Text.Length == 0 ? "0" : Text;
+ double new_value = Double.Parse (text);
+ Value = new_value;
+
+ } catch (FormatException) {
+ } catch (OverflowException) {
+ }
+
+ base.OnTextChanged (args);
+ }
+
+ protected override void OnKeyPress (KeyPressEventArgs args)
+ {
+ string acceptable = "\b.01234567890";
+ if (acceptable.IndexOf (args.KeyChar) < 0)
+ args.Handled = true;
+
+ base.OnKeyPress (args);
+ }
+
+ protected virtual void OnValueChanged (EventArgs args)
+ {
+ if (ValueChanged != null)
+ ValueChanged (this, args);
+ }
+
+ public event EventHandler ValueChanged;
+ }
+}
+
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PageSetupDialog.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PageSetupDialog.cs
2006-11-29 17:39:39 UTC (rev 68679)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PageSetupDialog.cs
2006-11-29 18:13:48 UTC (rev 68680)
@@ -46,9 +46,6 @@
private PageSettings page_settings;
private PrinterSettings printer_settings;
private Margins min_margins;
- private Margins default_margins = UseYardPound ?
- new Margins (yard_pound_default, yard_pound_default,
yard_pound_default, yard_pound_default) :
- new Margins (meter_default, meter_default,
meter_default, meter_default);
private bool allow_margins;
private bool allow_orientation;
private bool allow_paper;
@@ -71,10 +68,10 @@
private Label label_top;
private Label label_right;
private Label label_bottom;
- private TextBox textbox_left;
- private TextBox textbox_top;
- private TextBox textbox_right;
- private TextBox textbox_bottom;
+ private NumericTextBox textbox_left;
+ private NumericTextBox textbox_top;
+ private NumericTextBox textbox_right;
+ private NumericTextBox textbox_bottom;
private ComboBox combobox_source;
private ComboBox combobox_size;
private PrinterForm printer_helper_form;
@@ -221,10 +218,10 @@
this.label_top = new System.Windows.Forms.Label();
this.label_right = new System.Windows.Forms.Label();
this.label_bottom = new System.Windows.Forms.Label();
- this.textbox_left = new System.Windows.Forms.TextBox();
- this.textbox_top = new System.Windows.Forms.TextBox();
- this.textbox_right = new System.Windows.Forms.TextBox();
- this.textbox_bottom = new
System.Windows.Forms.TextBox();
+ this.textbox_left = new
System.Windows.Forms.NumericTextBox();
+ this.textbox_top = new
System.Windows.Forms.NumericTextBox();
+ this.textbox_right = new
System.Windows.Forms.NumericTextBox();
+ this.textbox_bottom = new
System.Windows.Forms.NumericTextBox();
this.groupbox_paper.SuspendLayout();
this.groupbox_orientation.SuspendLayout();
this.groupbox_margin.SuspendLayout();
@@ -383,15 +380,13 @@
this.textbox_left.Name = "textbox_left";
this.textbox_left.Size = new System.Drawing.Size(48,
20);
this.textbox_left.TabIndex = 4;
- this.textbox_left.Text = ToLocalizedLength
(default_margins.Left);
//
// textbox_top
- //
+ //
this.textbox_top.Location = new
System.Drawing.Point(57, 54);
this.textbox_top.Name = "textbox_top";
this.textbox_top.Size = new System.Drawing.Size(48, 20);
this.textbox_top.TabIndex = 5;
- this.textbox_top.Text = ToLocalizedLength
(default_margins.Top);
//
// textbox_right
//
@@ -399,7 +394,6 @@
this.textbox_right.Name = "textbox_right";
this.textbox_right.Size = new System.Drawing.Size(48,
20);
this.textbox_right.TabIndex = 6;
- this.textbox_right.Text = ToLocalizedLength
(default_margins.Right);
//
// textbox_bottom
//
@@ -407,7 +401,6 @@
this.textbox_bottom.Name = "textbox_bottom";
this.textbox_bottom.Size = new System.Drawing.Size(48,
20);
this.textbox_bottom.TabIndex = 7;
- this.textbox_bottom.Text = ToLocalizedLength
(default_margins.Bottom);
//
// Form3
//
@@ -457,13 +450,20 @@
}
}
- private string ToLocalizedLength (int marginsUnit)
+ private double ToLocalizedLength (int marginsUnit)
{
- return (UseYardPound ?
- marginsUnit / 100 :
- marginsUnit / 3.937 / 100).ToString ();
+ return UseYardPound ?
+ marginsUnit / 100.0 :
+ marginsUnit / 10.0;
}
+ private int FromLocalizedLength (double marginsUnit)
+ {
+ return UseYardPound ?
+ (int) (marginsUnit * 100.0) :
+ (int) (marginsUnit * 3.937);
+ }
+
private string LocalizedLengthUnit ()
{
return UseYardPound ? "Margins (inches)" : "Margins
(millimeters)";
@@ -492,12 +492,25 @@
if (ShowHelp)
ShowHelpButton ();
+ Margins page_margins = PageSettings.Margins;
+ Margins min_margins = MinMargins;
+
+ // Update margin data
+ textbox_top.Text = ToLocalizedLength
(page_margins.Top).ToString ();
+ textbox_bottom.Text = ToLocalizedLength
(page_margins.Bottom).ToString ();
+ textbox_left.Text = ToLocalizedLength
(page_margins.Left).ToString ();
+ textbox_right.Text = ToLocalizedLength
(page_margins.Right).ToString ();
+ textbox_top.Min = ToLocalizedLength (min_margins.Top);
+ textbox_bottom.Min = ToLocalizedLength
(min_margins.Bottom);
+ textbox_left.Min = ToLocalizedLength (min_margins.Left);
+ textbox_right.Min = ToLocalizedLength
(min_margins.Right);
+
button_printer.Enabled = AllowPrinter &&
PrinterSettings != null;
groupbox_orientation.Enabled = AllowOrientation;
groupbox_paper.Enabled = AllowPaper;
groupbox_margin.Enabled = AllowMargins;
}
-
+
private void OnClickOkButton (object sender, EventArgs e)
{
if (combobox_size.SelectedItem != null) {
@@ -518,6 +531,13 @@
}
}
+ Margins margins = new Margins ();
+ margins.Top = FromLocalizedLength (textbox_top.Value);
+ margins.Bottom = FromLocalizedLength
(textbox_bottom.Value);
+ margins.Left = FromLocalizedLength (textbox_left.Value);
+ margins.Right = FromLocalizedLength
(textbox_right.Value);
+ PageSettings.Margins = margins;
+
PageSettings.Landscape = radio_landscape.Checked;
form.DialogResult = DialogResult.OK;
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches