Bladeren bron

Initial PrintDialog implementation

svn path=/trunk/mcs/; revision=19198
Jordi Mas i Hernandez 22 jaren geleden
bovenliggende
commit
40cdc01417

+ 48 - 0
mcs/class/System.Windows.Forms/System.Windows.Forms.Test/PrintDialogTest.cs

@@ -0,0 +1,48 @@
+//
+// Test application for the PrinttDialogTest class implementation
+//
+// Author:
+//   Jordi Mas i Hernàndez, [email protected]
+//
+
+using System;
+using System.Collections;
+using System.Windows.Forms;
+using System.Drawing;
+using System.Drawing.Printing;
+
+
+class PrintDialogTest : Form	{
+				
+	public PrintDialogTest(): base() {
+				
+    }
+        
+    public static void Main(string[] args){
+    	
+    	PrintDialog printDlg = new PrintDialog();
+    	
+    	Console.WriteLine ("Default class values------");		
+		Console.WriteLine ("AllowPrintToFile->" +  printDlg.AllowPrintToFile);
+		Console.WriteLine ("AllowSelection->" +  printDlg.AllowSelection);
+		Console.WriteLine ("AllowSomePages->" +  printDlg.AllowSomePages);
+		Console.WriteLine ("ShowHelp->" +  printDlg.ShowHelp);
+		Console.WriteLine ("ShowNetwork->" +  printDlg.ShowNetwork);
+		Console.WriteLine ("PrintToFile->" +  printDlg.PrintToFile);
+						
+        // Declare the PrintDocument object.
+    	PrintDocument docToPrint = 	new PrintDocument();	               	
+        
+        printDlg.Document = docToPrint;
+        DialogResult result = printDlg.ShowDialog();
+
+        // If the result is OK then print the document.
+        if (result==DialogResult.OK){
+			//docToPrint.Print();
+			Console.WriteLine ("Copies->" +  printDlg.PrinterSettings.Copies);
+        }
+		
+	}
+
+}
+

+ 3 - 0
mcs/class/System.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,6 @@
+2003-10-20 Jordi Mas i Hernàndez <[email protected]>
+	* Initial PrintDialog.cs implementation
+	
 2003-10-16 Jordi Mas i Hernàndez <[email protected]>
 	* FileDialog uses the PlaceToolBar and allows resizing
 

+ 96 - 76
mcs/class/System.Windows.Forms/System.Windows.Forms/PrintDialog.cs

@@ -4,12 +4,15 @@
 // Author:
 //   stubbed out by Paul Osman ([email protected])
 //	Dennis Hayes ([email protected])
+//	Implemented by Jordi Mas i Hernàndez <[email protected]>
 //
-// (C) 2002 Ximian, Inc
+// (C) 2002-3 Ximian, Inc
 //
 using System.Drawing.Printing;
 using System.Runtime.Remoting;
 using System.ComponentModel;
+using System.Runtime.InteropServices;
+
 namespace System.Windows.Forms {
 
 	// <summary>
@@ -17,111 +20,128 @@ namespace System.Windows.Forms {
 	// </summary>
 
         public sealed class PrintDialog : CommonDialog {
+        	
+		private bool allowPrintToFile;	
+		private bool allowSelection;	
+		private bool allowSomePages;	
+		private bool showHelp;
+		private bool showNetwork;	
+		private bool printToFile;
+		private PrintDocument document = null;
+		private PrinterSettings printerSettings;
 
 		//
 		//  --- Constructor
-		//
-		[MonoTODO]
-		public PrintDialog()
-		{
-			
+		//		
+		public PrintDialog(){
+			Reset();			
 		}
 
 		//
 		//  --- Public Properties
-		//
-		[MonoTODO]
+		//		
 		public bool AllowPrintToFile {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
+			get {return allowPrintToFile;}
+			set {allowPrintToFile = value;}
 		}
-		[MonoTODO]
+		
 		public bool AllowSelection {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
+			get {return allowSelection;}
+			set {allowSelection = value;}
 		}
-		[MonoTODO]
+		
 		public bool AllowSomePages {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
+			get {return allowSomePages;}
+			set {allowSomePages = value;}
 		}
 
-		[MonoTODO]
+		
 		public PrintDocument Document {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		[MonoTODO]
+			get {return document;}
+			set {document = value;}
+		}		
+		
 		public PrinterSettings PrinterSettings {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
+			get {return printerSettings;}
+			set {printerSettings = value;}
 		}
-		[MonoTODO]
+		
 		public bool PrintToFile {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
+			get {return printToFile;}
+			set {printToFile = value;}
 		}
-		[MonoTODO]
-		public bool ShowHelp {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
+
+		public bool ShowHelp {		
+			get {return showHelp;}
+			set {showHelp = value;}
 		}
-		[MonoTODO]
+		
 		public bool ShowNetwork {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
+			get {return showNetwork;}
+			set {showNetwork = value;}
 		}
+		
+		
 
 		//
 		//  --- Public Methods
 		//
-
-		[MonoTODO]
-		public override void Reset()
-		{
-			throw new NotImplementedException ();
+				
+		public override void Reset(){
+			
+			allowPrintToFile = true;	
+			allowSelection = false;	
+			allowSomePages = false;	
+			showHelp = false;
+			showNetwork = true;	
+			printToFile = false;
 		}
 
 		//
 		//  --- Protected Methods
-		//
-
-		[MonoTODO]
-		protected override bool RunDialog(IntPtr hwndOwner)
-		{
-			throw new NotImplementedException ();
+		//		
+		protected override bool RunDialog(IntPtr hwndOwner)	{			
+			
+			PRINTDLG pdlg = new PRINTDLG();
+			pdlg.hwndOwner = hwndOwner;						
+			pdlg.lStructSize  = (uint)Marshal.SizeOf(pdlg);				
+			pdlg.hDevMode = (IntPtr)0;
+			pdlg.hDevNames = (IntPtr)0;
+			pdlg.nFromPage = 0;
+			pdlg.nToPage = 0;
+			pdlg.nMinPage = 0;
+			pdlg.nMaxPage = 0;	
+			pdlg.nCopies = 0;
+			pdlg.hInstance = (IntPtr)0;
+			pdlg.lCustData = (IntPtr)0;
+			pdlg.lpfnPrintHook = (IntPtr)0;
+			pdlg.lpfnSetupHook = (IntPtr)0;
+			pdlg.lpPrintTemplateName = (IntPtr)0;
+			pdlg.lpSetupTemplateName = (IntPtr)0;
+			pdlg.hPrintTemplate = (IntPtr)0;
+			pdlg.hSetupTemplate = (IntPtr)0;
+			pdlg.Flags = 0;			
+			
+			if (!allowPrintToFile) pdlg.Flags |=  PrintDlgFlags.PD_DISABLEPRINTTOFILE;		
+			if (!allowSelection) pdlg.Flags |=  PrintDlgFlags.PD_NOSELECTION;				
+			if (!allowSomePages) pdlg.Flags |=  PrintDlgFlags.PD_NOPAGENUMS;
+			if (showHelp) pdlg.Flags |=  PrintDlgFlags.PD_SHOWHELP;				
+			if (!showNetwork) pdlg.Flags |=  PrintDlgFlags.PD_NONETWORKBUTTON;
+			if (!printToFile) pdlg.Flags |=  PrintDlgFlags.PD_DISABLEPRINTTOFILE;
+									
+			IntPtr lfBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(pdlg));
+      		Marshal.StructureToPtr(pdlg, lfBuffer, false);			
+			
+			if (Win32_WineLess.PrintDlg(lfBuffer)){
+				
+				pdlg = (PRINTDLG)Marshal.PtrToStructure (lfBuffer, typeof (PRINTDLG));
+				
+				// TODO: PrinterSettings is not yet implemented, we should pass the values
+				// to that struct
+				//PrinterSettings.Copies =  pdlg.nCopies;
+				}
+			
+			return true;
 		}
 	 }
 }

+ 29 - 0
mcs/class/System.Windows.Forms/System.Windows.Forms/win32Enums.cs

@@ -2954,6 +2954,35 @@ namespace System.Windows.Forms{
 		CF_NOVERTFONTS				= 0x01000000,
 
 	}
+	
+	internal enum PrintDlgFlags : uint {
+		
+		PD_ALLPAGES						= 0x00000000,
+		PD_SELECTION					= 0x00000001,
+		PD_PAGENUMS						= 0x00000002,
+		PD_NOSELECTION					= 0x00000004,
+		PD_NOPAGENUMS					= 0x00000008,
+		PD_COLLATE						= 0x00000010,
+		PD_PRINTTOFILE					= 0x00000020,
+		PD_PRINTSETUP					= 0x00000040,
+		PD_NOWARNING					= 0x00000080,
+		PD_RETURNDC						= 0x00000100,
+		PD_RETURNIC						= 0x00000200,
+		PD_RETURNDEFAULT				= 0x00000400,
+		PD_SHOWHELP						= 0x00000800,
+		PD_ENABLEPRINTHOOK				= 0x00001000,
+		PD_ENABLESETUPHOOK				= 0x00002000,
+		PD_ENABLEPRINTTEMPLATE			= 0x00004000,
+		PD_ENABLESETUPTEMPLATE			= 0x00008000,
+		PD_ENABLEPRINTTEMPLATEHANDLE	= 0x00010000,
+		PD_ENABLESETUPTEMPLATEHANDLE	= 0x00020000,
+		PD_USEDEVMODECOPIES				= 0x00040000,
+		PD_USEDEVMODECOPIESANDCOLLATE 	= 0x00040000,
+		PD_DISABLEPRINTTOFILE 			= 0x00080000,
+		PD_HIDEPRINTTOFILE 				= 0x00100000,
+		PD_NONETWORKBUTTON				= 0x00200000
+	}
+	
 
 	internal enum CommDlgErrors : uint {
 		FNERR_FILENAMECODES          = 0x3000,

+ 31 - 0
mcs/class/System.Windows.Forms/System.Windows.Forms/win32Structs.cs

@@ -28,6 +28,14 @@
  * authorization from Carlos Harvey Perez.
  */
 
+/*
+	Note. Please, take into account the Windows types defintion
+	
+	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/windows_data_types.asp
+	
+	Typically:	DWORD=uint, Handles=IntPtr, WORD=ushort, etc
+	
+*/
 
 using System;
 using System.Drawing;
@@ -1003,5 +1011,28 @@ namespace System.Windows.Forms
 		internal TVITEM    itemNew;
 		internal POINT     ptDrag;
 	}
+	
+	[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi,  Pack=1)]
+	internal struct PRINTDLG {
+		internal uint			lStructSize;
+		internal IntPtr			hwndOwner;
+		internal IntPtr			hDevMode;
+		internal IntPtr			hDevNames;
+		internal IntPtr			hDC;
+		internal PrintDlgFlags	Flags;	//uint
+		internal short			nFromPage;
+		internal short			nToPage;
+		internal short			nMinPage;
+		internal short			nMaxPage;	
+		internal short			nCopies;
+		internal IntPtr			hInstance;
+		internal IntPtr			lCustData;
+		internal IntPtr			lpfnPrintHook;
+		internal IntPtr			lpfnSetupHook;
+		internal IntPtr			lpPrintTemplateName;
+		internal IntPtr			lpSetupTemplateName;
+		internal IntPtr			hPrintTemplate;
+		internal IntPtr			hSetupTemplate;
+	}
 }
 

+ 6 - 0
mcs/class/System.Windows.Forms/System.Windows.Forms/win32functions.cs

@@ -78,6 +78,12 @@ namespace System.Windows.Forms{
 		internal static extern bool ChooseColor ( ref CHOOSECOLOR lpofn );
 		
 		
+		[DllImport ("comdlg32.dll",
+			 CallingConvention = CallingConvention.StdCall, 
+			 CharSet = CharSet.Ansi)]
+		internal static extern bool PrintDlg (IntPtr pDlg);
+		
+		
 		[DllImport ("comdlg32.dll",
 			 CallingConvention = CallingConvention.StdCall, 
 			 CharSet = CharSet.Ansi)]