2006-11-28 Andreia Gaita <avidigal@novell.com>
authorAndreia Gaita <avidigal@novell.com>
Wed, 29 Nov 2006 03:13:04 +0000 (03:13 -0000)
committerAndreia Gaita <avidigal@novell.com>
Wed, 29 Nov 2006 03:13:04 +0000 (03:13 -0000)
* Form.cs: Removed call to UpdateBounds on Form
constructor, it was causing a call to CreateHandle
before it was supposed to.
* PrintControllerWithStatusDialog: Applied patch
by Chris Toshok to hide controller when there are
no printers available.
PrintDialog.cs: initialize printer settings to
null - correct DefaultValues test #5
* PrintPreviewControl.cs: Move PrintController
initialization to GeneratePreview
* PrintPreviewDialog.cs:
- Remove Preview generation from Document_set(). It is
called on OnPaint
- Throw InvalidPrinterException on CreateHandle if
a Document is set but there are no printers or
printer is not valid.
* ThemeWin32Classic: don't paint PrintPreviewControl
if there is nothing to paint

* PageSettings.cs:
- internal member name changes to help
out with intelisense.
- Use internal members directly instead of using
corresponding properties so that exceptions are not thrown
* PrintingServicesWin32:
- Only return DefaultPrinter if it is actually valid. This
is because Win32GetDefaultPrinter returns a printer name
even if PrintSpooler is stopped (which should  behave the
same way as if there are no printers installed)
- Do not try to allocate if EnumPrinters returns 0

svn path=/trunk/mcs/; revision=68635

12 files changed:
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/PrintControllerWithStatusDialog.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/PrintDialog.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/PrintPreviewControl.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/PrintPreviewDialog.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/PrintDialogTest.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/tests-ms.sh
mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog
mcs/class/System.Drawing/System.Drawing.Printing/PageSettings.cs
mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesWin32.cs

index 0f39edb3610192a798c8386c1032ca416bbc932f..e99604ff608a077a2103d7a57e980d664b30ef3a 100644 (file)
@@ -1,3 +1,24 @@
+2006-11-28  Andreia Gaita  <avidigal@novell.com>
+
+       * Form.cs: Removed call to UpdateBounds on Form
+       constructor, it was causing a call to CreateHandle
+       before it was supposed to.
+       * PrintControllerWithStatusDialog: Applied patch
+       by Chris Toshok to hide controller when there are
+       no printers available.
+       PrintDialog.cs: initialize printer settings to 
+       null - correct DefaultValues test #5
+       * PrintPreviewControl.cs: Move PrintController
+       initialization to GeneratePreview
+       * PrintPreviewDialog.cs: 
+       - Remove Preview generation     from Document_set(). It is 
+       called on OnPaint
+       - Throw InvalidPrinterException on CreateHandle if
+       a Document is set but there are no printers or 
+       printer is not valid.
+       * ThemeWin32Classic: don't paint PrintPreviewControl
+       if there is nothing to paint    
+
 2006-11-28  Miguel de Icaza  <miguel@novell.com>
 
        * Form.cs: Add another popular method.
index 85e01d249d49c7e3fef9f9dec0f0cd516b266874..314a3df052b56642b6a43fc1aade8d3663f76793 100644 (file)
@@ -85,7 +85,7 @@ namespace System.Windows.Forms {
                #region Private & Internal Methods
                static Form ()
                {
-                       default_icon = (Icon)Locale.GetResource("mono.ico");
+                       default_icon = Locale.GetResource("mono.ico") as Icon;
                }
 
                // warning: this is only hooked up when an mdi container is created.
@@ -177,7 +177,6 @@ namespace System.Windows.Forms {
                        owned_forms = new Form.ControlCollection(this);
                        transparency_key = Color.Empty;
 
-                       UpdateBounds();
                }
                #endregion      // Public Constructor & Destructor
 
index c71672a1e28bd431c043eb73820ba083ba7153cf..2759d95442489e52599414f79fb2cca464ec97fd 100644 (file)
@@ -86,16 +86,22 @@ namespace System.Windows.Forms
                }
 
                public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {
-                       currentPage = 0;
-                       dialog.Show();
-                       if (document.PrinterSettings.PrintToFile) {
-                               SaveFileDialog d = new SaveFileDialog ();
-                               if (d.ShowDialog () != DialogResult.OK)
-                                       // Windows throws a Win32Exception here.
-                                       throw new Exception ("The operation was canceled by the user");
-                               Set_PrinterSettings_PrintFileName (document.PrinterSettings, d.FileName);
+                       try {
+                               currentPage = 0;
+                               dialog.Show();
+                               if (document.PrinterSettings.PrintToFile) {
+                                       SaveFileDialog d = new SaveFileDialog ();
+                                       if (d.ShowDialog () != DialogResult.OK)
+                                               // Windows throws a Win32Exception here.
+                                               throw new Exception ("The operation was canceled by the user");
+                                       Set_PrinterSettings_PrintFileName (document.PrinterSettings, d.FileName);
+                               }
+                               underlyingController.OnStartPrint (document, e);
+                       }
+                       catch {
+                               dialog.Hide ();
+                               throw;
                        }
-                       underlyingController.OnStartPrint (document, e);
                }
 
                #endregion      // Protected Instance Methods
index e2b3275cb30cd6b3f6f0ea6ea9bdae9adfe7d5cd..f08fff1346a11c97e3912ea5985fd4e9b1c7a015 100644 (file)
@@ -82,7 +82,7 @@ namespace System.Windows.Forms
 
                public override void Reset ()
                {
-                       current_settings = new PrinterSettings ();
+                       current_settings = null;
                        AllowPrintToFile = true;
                        AllowSelection = false;
                        AllowSomePages = false;
index 55c5a67886c8e6428dc00da1e6b9786d528eb7cb..2da1ffb472fe8092de0c3ec1bd7260130df19ed9 100644 (file)
@@ -111,8 +111,6 @@ namespace System.Windows.Forms {
                        get { return document; }
                        set {
                                document = value;
-                               document.PrintController = new PrintControllerWithStatusDialog (controller);
-                               InvalidatePreview ();
                        }
                }
                [DefaultValue(1)]
@@ -184,6 +182,7 @@ namespace System.Windows.Forms {
                                        return;
 
                                if (page_infos == null) {
+                                       document.PrintController = new PrintControllerWithStatusDialog (controller);
                                        document.Print ();
                                        page_infos = controller.GetPreviewPageInfo ();
                                }
index cfa94277c5a3a1339b0ca0de554430bdc53db24a..81b0a127b2fc03ccf6c2687a01b2616c93b20278 100644 (file)
@@ -530,9 +530,6 @@ namespace System.Windows.Forms {
                        get { return print_preview.Document; }
                        set {
                                print_preview.Document = value;
-                               print_preview.GeneratePreview ();
-                               pageUpDown.Minimum = print_preview.page_infos.Length > 0 ? 1 : 0;
-                               pageUpDown.Maximum = print_preview.page_infos.Length;
                        }
                }
 
@@ -883,6 +880,9 @@ namespace System.Windows.Forms {
                }
 
                protected override void CreateHandle() {
+                       if (this.Document != null && !this.Document.PrinterSettings.IsValid) {
+                               throw new InvalidPrinterException(this.Document.PrinterSettings);
+                       }
                        base.CreateHandle ();
                }
 
index e708b6bbd05bc8060b64a1a5cdb1bd1935c68e46..680bf8a90e4fa2badc48c749af7f4fe62d2e8aa0 100644 (file)
@@ -2911,6 +2911,8 @@ namespace System.Windows.Forms
                {
                        int padding = 8;
                        PreviewPageInfo[] pis = preview.page_infos;
+                       if (pis == null)
+                               return;
 
                        int page_x, page_y;
 
index 923d21b3ff2f5826d719b4e8c00f145db14edbcc..c9637892498caca01fc959e63961114fd4c94daf 100644 (file)
@@ -38,8 +38,7 @@ namespace MonoTests.System.Windows.Forms
        [TestFixture]
        public class PrintDialogTest
        {
-               [Test]
-               [Category ("NotWorking")]
+               [Test]          
                public void DefaultValues ()
                {
                        PrintDialog pd = new PrintDialog ();
index a3fe29033b4f21b98f3e9fb5c9cb76fdbd446b20..d30fb697ca8d4014bb9f8f91f1ad1e17e8950959 100755 (executable)
@@ -1,28 +1,28 @@
-#!/bin/sh\r
-\r
-if [ $# -eq 0 ]; then\r
-       echo "You should give a list of test names such as: "\r
-       echo "$0 System.Windows.Forms.ListViewItemTest"\r
-       echo "or"\r
-       echo "$0 all"   \r
-       exit 1\r
-fi\r
-\r
-export MSNet=Yes\r
-cp ../../System.Windows.Forms_test_default.dll .\r
-topdir=../../../..\r
-NUNITCONSOLE=$topdir/class/lib/default/nunit-console.exe\r
-MONO_PATH=$topdir/nunit20:$topdir/class/lib:.\r
-\r
-for i in $@; do\r
-       if [ "$i" = "all" ]; then\r
-               fixture=""\r
-       else\r
-               fixture="/fixture:MonoTests.${i}"\r
-       fi\r
-       MONO_PATH=$MONO_PATH \\r
-               ${NUNITCONSOLE} System.Windows.Forms_test_default.dll $fixture\r
-done\r
-\r
-\r
-\r
+#!/bin/sh
+
+if [ $# -eq 0 ]; then
+       echo "You should give a list of test names such as: "
+       echo "$0 System.Windows.Forms.ListViewItemTest"
+       echo "or"
+       echo "$0 all"   
+       exit 1
+fi
+
+export MSNet=Yes
+cp ../../System.Windows.Forms_test_default.dll .
+topdir=../../../..
+NUNITCONSOLE=$topdir/class/lib/default/nunit-console.exe
+MONO_PATH=$topdir/nunit20:$topdir/class/lib:.
+
+for i in $@; do
+       if [ "$i" = "all" ]; then
+               fixture=""
+       else
+               fixture="/fixture:MonoTests.${i}"
+       fi
+       MONO_PATH=$MONO_PATH \
+               ${NUNITCONSOLE} System.Windows.Forms_test_default.dll $fixture
+done
+
+
+
index 474f2978153db5bbe667f7e80aa98b4c16dd9bf3..476921ce70dcacf518baa0c83b814bc55ebb4521 100644 (file)
@@ -1,3 +1,17 @@
+2006-11-28  Andreia Gaita  <avidigal@novell.com>
+
+       * PageSettings.cs: 
+       - internal member name changes to help
+       out with intelisense. 
+       - Use internal members directly instead of using
+       corresponding properties so that exceptions are not thrown
+       * PrintingServicesWin32:
+       - Only return DefaultPrinter if it is actually valid. This
+       is because Win32GetDefaultPrinter returns a printer name
+       even if PrintSpooler is stopped (which should  behave the
+       same way as if there are no printers installed)
+       - Do not try to allocate if EnumPrinters returns 0
+       
 2006-11-25 Jordi Mas i Hernandez <jordimash@gmail.com>
 
        * PrintingServicesUnix.cs: Implements GetPrintDialogInfo
index deb464d6b5a7df2156236ff8e9eaa1ddce69f0cd..0d08d76b27533a271be64b9cdfdd56fe13c5b031 100644 (file)
@@ -44,17 +44,19 @@ namespace System.Drawing.Printing
 #endif
        public class PageSettings : ICloneable
        {
-               internal bool _Color;
-               internal bool _Landscape;
-               internal PaperSize _PaperSize;
-               internal PaperSource _PaperSource;
-               internal PrinterResolution _PrinterResolution;
-               float _HardMarginX;\r
-               float _HardMarginY;
-               RectangleF _PrintableArea;
+               internal bool color;
+               internal bool landscape;
+               internal PaperSize paperSize;
+               internal PaperSource paperSource;
+               internal PrinterResolution printerResolution;
+
                // create a new default Margins object (is 1 inch for all margins)
-               Margins _Margins = new Margins();
-               PrinterSettings _PrinterSettings;
+               Margins margins = new Margins();
+\r
+               float hardMarginX;\r
+               float hardMarginY;
+               RectangleF printableArea;
+               PrinterSettings printerSettings;
                
                public PageSettings() : this(new PrinterSettings())
                {
@@ -64,11 +66,11 @@ namespace System.Drawing.Printing
                {
                        PrinterSettings = printerSettings;
                        
-                       Color = printerSettings.DefaultPageSettings._Color;
-                       Landscape = printerSettings.DefaultPageSettings._Landscape;
-                       PaperSize = printerSettings.DefaultPageSettings._PaperSize;
-                       PaperSource = printerSettings.DefaultPageSettings._PaperSource;
-                       PrinterResolution = printerSettings.DefaultPageSettings._PrinterResolution;
+                       this.color = printerSettings.DefaultPageSettings.color;
+                       this.landscape = printerSettings.DefaultPageSettings.landscape;
+                       this.paperSize = printerSettings.DefaultPageSettings.paperSize;
+                       this.paperSource = printerSettings.DefaultPageSettings.paperSource;
+                       this.printerResolution = printerSettings.DefaultPageSettings.printerResolution;
                }
                
                // used by PrinterSettings.DefaultPageSettings
@@ -76,122 +78,122 @@ namespace System.Drawing.Printing
                {
                        PrinterSettings = printerSettings;
                        
-                       _Color = color;
-                       _Landscape = landscape;
-                       _PaperSize = paperSize;
-                       _PaperSource = paperSource;
-                       _PrinterResolution = printerResolution;
+                       this.color = color;
+                       this.landscape = landscape;
+                       this.paperSize = paperSize;
+                       this.paperSource = paperSource;
+                       this.printerResolution = printerResolution;
                }
 
                //props
                public Rectangle Bounds{
                        get{
-                               int width = this.PaperSize.Width;
-                               int height = this.PaperSize.Height;
+                               int width = this.paperSize.Width;
+                               int height = this.paperSize.Height;
                                
-                               width -= this.Margins.Left + this.Margins.Right;
-                               height -= this.Margins.Top + this.Margins.Bottom;
+                               width -= this.margins.Left + this.margins.Right;
+                               height -= this.margins.Top + this.margins.Bottom;
                                
-                               if (this.Landscape) {
+                               if (this.landscape) {
                                        // swap width and height
                                        int tmp = width;
                                        width = height;
                                        height = tmp;
                                }
-                               return new Rectangle (Margins.Left, Margins.Top, width, height);
+                               return new Rectangle (this.margins.Left, this.margins.Top, width, height);
                        }
                }
                
                public bool Color{
                        get{
-                               if (!this._PrinterSettings.IsValid)
-                                       throw new InvalidPrinterException(this._PrinterSettings);
-                               return _Color;
+                               if (!this.printerSettings.IsValid)
+                                       throw new InvalidPrinterException(this.printerSettings);
+                               return color;
                        }
                        set{
-                               _Color = value;
+                               color = value;
                        }
                }
                
                public bool Landscape {
                        get{
-                               if (!this._PrinterSettings.IsValid)
-                                       throw new InvalidPrinterException(this._PrinterSettings);
-                               return _Landscape;
+                               if (!this.printerSettings.IsValid)
+                                       throw new InvalidPrinterException(this.printerSettings);
+                               return landscape;
                        }
                        set{
-                               _Landscape = value;
+                               landscape = value;
                        }
                }
                
                public Margins Margins{
                        get{
-                               if (!this._PrinterSettings.IsValid)
-                                       throw new InvalidPrinterException(this._PrinterSettings);
-                               return _Margins;
+                               if (!this.printerSettings.IsValid)
+                                       throw new InvalidPrinterException(this.printerSettings);
+                               return margins;
                        }
                        set{
-                               _Margins = value;
+                               margins = value;
                        }
                }
                
                public PaperSize PaperSize{
                        get{
-                               if (!this._PrinterSettings.IsValid)
-                                       throw new InvalidPrinterException(this._PrinterSettings);
-                               return _PaperSize;
+                               if (!this.printerSettings.IsValid)
+                                       throw new InvalidPrinterException(this.printerSettings);
+                               return paperSize;
                        }
                        set{
-                               _PaperSize = value;
+                               paperSize = value;
                        }
                }
                
                public PaperSource PaperSource{
                        get{
-                               if (!this._PrinterSettings.IsValid)
-                                       throw new InvalidPrinterException(this._PrinterSettings);
-                               return _PaperSource;
+                               if (!this.printerSettings.IsValid)
+                                       throw new InvalidPrinterException(this.printerSettings);
+                               return paperSource;
                        }
                        set{
-                               _PaperSource = value;
+                               paperSource = value;
                        }
                }
                
                public PrinterResolution PrinterResolution{
                        get{
-                               if (!this._PrinterSettings.IsValid)
-                                       throw new InvalidPrinterException(this._PrinterSettings);
-                               return _PrinterResolution;
+                               if (!this.printerSettings.IsValid)
+                                       throw new InvalidPrinterException(this.printerSettings);
+                               return printerResolution;
                        }
                        set{
-                               _PrinterResolution = value;
+                               printerResolution = value;
                        }
                }
                
                public PrinterSettings PrinterSettings{
                        get{
-                               return _PrinterSettings;
+                               return printerSettings;
                        }
                        set{
-                               _PrinterSettings = value;
+                               printerSettings = value;
                        }
                }               
 #if NET_2_0
                public float HardMarginX {
                        get {
-                               return _HardMarginX;
+                               return hardMarginX;
                        }
                }
                \r
                public float HardMarginY {
                        get {
-                               return _HardMarginY;
+                               return hardMarginY;
                        }
                }
                
                public RectangleF PrintableArea {
                        get {
-                               return _PrintableArea;
+                               return printableArea;
                        }
                }
 #endif\r
@@ -200,14 +202,14 @@ namespace System.Drawing.Printing
                public object Clone ()
                {
                        // We do a deep copy
-                       PrinterResolution pres = new PrinterResolution (_PrinterResolution.X, _PrinterResolution.Y, _PrinterResolution.Kind);
-                       PaperSource psource = new PaperSource (_PaperSource.SourceName, _PaperSource.Kind);
-                       PaperSize psize = new PaperSize (_PaperSize.PaperName, _PaperSize.Width, _PaperSize.Height);
-                       psize.SetKind (_PaperSize.Kind);
+                       PrinterResolution pres = new PrinterResolution (this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind);
+                       PaperSource psource = new PaperSource (this.paperSource.SourceName, this.paperSource.Kind);
+                       PaperSize psize = new PaperSize (this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height);
+                       psize.SetKind (this.paperSize.Kind);
 
-                       PageSettings ps = new PageSettings (PrinterSettings, Color, Landscape,
+                       PageSettings ps = new PageSettings (this.printerSettings, this.color, this.landscape,
                                        psize, psource, pres);
-                       ps.Margins = (Margins) _Margins.Clone ();
+                       ps.Margins = (Margins) this.margins.Clone ();
                        return ps;
                }
 
@@ -232,7 +234,7 @@ namespace System.Drawing.Printing
                        ret += ", PrinterResolution={5}";
                        ret += "]";
                        
-                       return String.Format(ret, this.Color, this.Landscape, this.Margins, this.PaperSize, this.PaperSource, this.PrinterResolution);
+                       return String.Format(ret, this.color, this.landscape, this.margins, this.paperSize, this.paperSource, this.printerResolution);
                }
        }
 }
index 3677236393871f2e06661b16cf725f4fdbf9ff7c..9cb61ba68f447df20cc9b7b89865f4763b50740e 100644 (file)
@@ -296,11 +296,13 @@ namespace System.Drawing.Printing
                // Properties
                internal override string DefaultPrinter {
                        get {
-                               StringBuilder name = new StringBuilder (1024);
-                               int length = name.Capacity;
+                               StringBuilder name = new StringBuilder (1024);
+                               int length = name.Capacity;
 
-                               Win32GetDefaultPrinter (name, ref length);
-                               return name.ToString ();
+                               if (Win32GetDefaultPrinter (name, ref length) > 0)
+                                       if (this.IsPrinterValid(name.ToString(), false))
+                                               return name.ToString ();
+                               return String.Empty;
                        }
                }
 
@@ -313,10 +315,14 @@ namespace System.Drawing.Printing
                                string s;
 
                                // Determine space need it
-                               Win32EnumPrinters (2 /* PRINTER_ENUM_LOCAL */,
-                                       null, 2, IntPtr.Zero, 0, ref cbNeeded, ref printers);
+                       Win32EnumPrinters (2 /* PRINTER_ENUM_LOCAL */,
+                               null, 2, IntPtr.Zero, 0, ref cbNeeded, ref printers);
+
+                               if (cbNeeded <= 0)
+                                       return col;
+
+                               ptr = buff = Marshal.AllocHGlobal ((int) cbNeeded);
 
-                               ptr = buff = Marshal.AllocHGlobal ((int) cbNeeded);
                                try {
                                        // Give us the printer list
                                        Win32EnumPrinters (2 /* PRINTER_ENUM_LOCAL */,