Hey,

S.D.Printing.PrintDocument.PrintController has as default a new instance
of S.W.F.PrintControllerWithStatusDialog, which is in SWF assembly. 

The current code assigns a new instance of S.D.P.StandardPrintController
to PrintDocument.PrintController, which isn't the right behaviour.

The problem is that it's not a good idea to add System.Windows.Forms as
a reference to the System.Drawing assembly IMHO. So, the approach is to
load the SWD assembly using reflection and then cache the type .ctor.


Also, PrintDocument.PrintController should be never null, and should get
a new PrintControllerWithStatusDialog instance, just like .Net does.

Carlos. 
Index: PrintDocument.cs
===================================================================
--- PrintDocument.cs	(revisiĆ³n: 63154)
+++ PrintDocument.cs	(copia de trabajo)
@@ -34,6 +34,7 @@
 
 using System;
 using System.ComponentModel;
+using System.Reflection;
 
 namespace System.Drawing.Printing
 {
@@ -45,6 +46,8 @@
 		private PrinterSettings printersettings;
 		private PrintController printcontroller;
 		private string documentname;
+
+		static ConstructorInfo pcontroller_with_status_ctor;
 #if !(NET_1_0)
 		private bool originAtMargins = false; // .NET V1.1 Beta
 #endif
@@ -53,8 +56,20 @@
 			documentname = "document"; //offical default.
 			defaultpagesettings = new PageSettings(); // use default values of default printer
 			printersettings = new PrinterSettings(); // use default values
-			printcontroller = new StandardPrintController();
+			printcontroller = CreatePrintControllerWithStatusDialog (new StandardPrintController ());
 		}
+
+		PrintController CreatePrintControllerWithStatusDialog (PrintController underlying_pc)
+		{
+			if (pcontroller_with_status_ctor == null) {
+				Assembly wf_assembly = Assembly.Load ("System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
+				Type pcontroller_with_status_type = wf_assembly.GetType ("System.Windows.Forms.PrintControllerWithStatusDialog");
+				pcontroller_with_status_ctor = pcontroller_with_status_type.GetConstructor (new Type [] {typeof (PrintController)});
+			}
+
+			PrintController retval = (PrintController) pcontroller_with_status_ctor.Invoke (new object [] {underlying_pc});
+			return retval;
+		}
 		
 		// properties
 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
@@ -89,7 +104,8 @@
 				return printcontroller;
 			}
 			set{
-				printcontroller = value;
+				printcontroller = value == null ? 
+					CreatePrintControllerWithStatusDialog (new StandardPrintController ()) : value;
 			}
 		}
 
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to