2 // System.Drawing.PrintDocument.cs
5 // Dennis Hayes (dennish@Raytek.com)
6 // Herve Poussineau (hpoussineau@fr.st)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (C) 2002 Ximian, Inc
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System
.ComponentModel
;
38 namespace System
.Drawing
.Printing
40 [DefaultEvent ("PrintPage"), DefaultProperty ("DocumentName")]
41 [ToolboxItemFilter ("System.Drawing.Printing", ToolboxItemFilterType
.Allow
)]
42 public class PrintDocument
: System
.ComponentModel
.Component
44 private PageSettings defaultpagesettings
;
45 private PrinterSettings printersettings
;
46 private PrintController printcontroller
;
47 private string documentname
;
49 private bool originAtMargins
= false; // .NET V1.1 Beta
52 public PrintDocument() {
53 documentname
= "document"; //offical default.
54 defaultpagesettings
= new PageSettings(); // use default values of default printer
55 printersettings
= new PrinterSettings(); // use default values
56 printcontroller
= new StandardPrintController();
60 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
62 [SRDescription ("The settings for the current page.")]
63 public PageSettings DefaultPageSettings
{
65 return defaultpagesettings
;
68 defaultpagesettings
= value;
72 // Name of the document, not the file!
73 [DefaultValue ("document")]
74 [SRDescription ("The name of the document.")]
75 public string DocumentName
{
84 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
86 [SRDescription ("The print controller object.")]
87 public PrintController PrintController
{
89 return printcontroller
;
92 printcontroller
= value;
96 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
98 [SRDescription ("The current settings for the active printer.")]
99 public PrinterSettings PrinterSettings
{
101 return printersettings
;
104 printersettings
= value;
109 [DefaultValue (false)]
110 [SRDescription ("Determines if the origin is set at the specified margins.")]
111 public bool OriginAtMargins
{
113 return originAtMargins
;
116 originAtMargins
= value;
123 PrintEventArgs printArgs
= new PrintEventArgs();
124 this.OnBeginPrint(printArgs
);
125 if (printArgs
.Cancel
)
127 PrintController
.OnStartPrint(this, printArgs
);
128 if (printArgs
.Cancel
)
131 // while there is more pages
132 PrintPageEventArgs printPageArgs
;
135 PageSettings pageSettings
= DefaultPageSettings
.Clone() as PageSettings
;
136 this.OnQueryPageSettings(new QueryPageSettingsEventArgs(pageSettings
));
138 printPageArgs
= new PrintPageEventArgs(
141 new Rectangle(0, 0, pageSettings
.PaperSize
.Width
, pageSettings
.PaperSize
.Height
),
143 Graphics g
= PrintController
.OnStartPage(this, printPageArgs
);
144 // assign Graphics in printPageArgs
145 printPageArgs
.SetGraphics(g
);
147 if (!printPageArgs
.Cancel
)
148 this.OnPrintPage(printPageArgs
);
150 PrintController
.OnEndPage(this, printPageArgs
);
151 if (printPageArgs
.Cancel
)
153 } while (printPageArgs
.HasMorePages
);
155 this.OnEndPrint(printArgs
);
156 PrintController
.OnEndPrint(this, printArgs
);
159 public override string ToString(){
160 return "[PrintDocument " + this.DocumentName
+ "]";
164 protected virtual void OnBeginPrint(PrintEventArgs e
){
166 if (BeginPrint
!= null)
170 protected virtual void OnEndPrint(PrintEventArgs e
){
172 if (EndPrint
!= null)
176 protected virtual void OnPrintPage(PrintPageEventArgs e
){
178 if (PrintPage
!= null)
182 protected virtual void OnQueryPageSettings(QueryPageSettingsEventArgs e
){
184 if (QueryPageSettings
!= null)
185 QueryPageSettings(this, e
);
188 [SRDescription ("Raised when printing begins")]
189 public event PrintEventHandler BeginPrint
;
191 [SRDescription ("Raised when printing ends")]
192 public event PrintEventHandler EndPrint
;
194 [SRDescription ("Raised when printing of a new page begins")]
195 public event PrintPageEventHandler PrintPage
;
197 [SRDescription ("Raised before printing of a new page begins")]
198 public event QueryPageSettingsEventHandler QueryPageSettings
;