[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Drawing / System.Drawing.Printing / PrintDocument.cs
blobef4965ad8c42f5edf34ec4d8c3f386de0467a45f
1 //
2 // System.Drawing.PrintDocument.cs
3 //
4 // Authors:
5 // Dennis Hayes (dennish@Raytek.com)
6 // Herve Poussineau (hpoussineau@fr.st)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 //
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:
22 //
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 //
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.
35 using System;
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;
48 private bool originAtMargins = false; // .NET V1.1 Beta
50 public PrintDocument() {
51 documentname = "document"; //offical default.
52 printersettings = new PrinterSettings(); // use default values
53 defaultpagesettings = (PageSettings) printersettings.DefaultPageSettings.Clone ();
54 printcontroller = new StandardPrintController();
57 // properties
58 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
59 [Browsable (false)]
60 [SRDescription ("The settings for the current page.")]
61 public PageSettings DefaultPageSettings{
62 get{
63 return defaultpagesettings;
65 set{
66 defaultpagesettings = value;
70 // Name of the document, not the file!
71 [DefaultValue ("document")]
72 [SRDescription ("The name of the document.")]
73 public string DocumentName{
74 get{
75 return documentname;
77 set{
78 documentname = value;
82 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
83 [Browsable (false)]
84 [SRDescription ("The print controller object.")]
85 public PrintController PrintController{
86 get{
87 return printcontroller;
89 set{
90 printcontroller = value;
94 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
95 [Browsable (false)]
96 [SRDescription ("The current settings for the active printer.")]
97 public PrinterSettings PrinterSettings{
98 get{
99 return printersettings;
101 set{
102 printersettings = value == null ? new PrinterSettings () : value;
106 [DefaultValue (false)]
107 [SRDescription ("Determines if the origin is set at the specified margins.")]
108 public bool OriginAtMargins{
109 get{
110 return originAtMargins;
112 set{
113 originAtMargins = value;
117 // methods
118 public void Print(){
119 PrintEventArgs printArgs = new PrintEventArgs();
120 this.OnBeginPrint(printArgs);
121 if (printArgs.Cancel)
122 return;
123 PrintController.OnStartPrint(this, printArgs);
124 if (printArgs.Cancel)
125 return;
127 Graphics g = null;
129 if (printArgs.GraphicsContext != null) {
130 g = Graphics.FromHdc (printArgs.GraphicsContext.Hdc);
131 printArgs.GraphicsContext.Graphics = g;
134 // while there are more pages
135 PrintPageEventArgs printPageArgs;
138 QueryPageSettingsEventArgs queryPageSettingsArgs = new QueryPageSettingsEventArgs (
139 DefaultPageSettings.Clone () as PageSettings);
140 OnQueryPageSettings (queryPageSettingsArgs);
142 PageSettings pageSettings = queryPageSettingsArgs.PageSettings;
143 printPageArgs = new PrintPageEventArgs(
145 pageSettings.Bounds,
146 new Rectangle(0, 0, pageSettings.PaperSize.Width, pageSettings.PaperSize.Height),
147 pageSettings);
149 // TODO: We should create a graphics context for each page since they can have diferent paper
150 // size, orientation, etc. We use a single graphic for now to keep Cairo using a single PDF file.
152 printPageArgs.GraphicsContext = printArgs.GraphicsContext;
153 Graphics pg = PrintController.OnStartPage(this, printPageArgs);
155 // assign Graphics in printPageArgs
156 printPageArgs.SetGraphics(pg);
158 if (!printPageArgs.Cancel)
159 this.OnPrintPage(printPageArgs);
161 PrintController.OnEndPage(this, printPageArgs);
162 if (printPageArgs.Cancel)
163 break;
164 } while (printPageArgs.HasMorePages);
166 this.OnEndPrint(printArgs);
167 PrintController.OnEndPrint(this, printArgs);
170 public override string ToString(){
171 return "[PrintDocument " + this.DocumentName + "]";
174 // events
175 protected virtual void OnBeginPrint(PrintEventArgs e){
176 //fire the event
177 if (BeginPrint != null)
178 BeginPrint(this, e);
181 protected virtual void OnEndPrint(PrintEventArgs e){
182 //fire the event
183 if (EndPrint != null)
184 EndPrint(this, e);
187 protected virtual void OnPrintPage(PrintPageEventArgs e){
188 //fire the event
189 if (PrintPage != null)
190 PrintPage(this, e);
193 protected virtual void OnQueryPageSettings(QueryPageSettingsEventArgs e){
194 //fire the event
195 if (QueryPageSettings != null)
196 QueryPageSettings(this, e);
199 [SRDescription ("Raised when printing begins")]
200 public event PrintEventHandler BeginPrint;
202 [SRDescription ("Raised when printing ends")]
203 public event PrintEventHandler EndPrint;
205 [SRDescription ("Raised when printing of a new page begins")]
206 public event PrintPageEventHandler PrintPage;
208 [SRDescription ("Raised before printing of a new page begins")]
209 public event QueryPageSettingsEventHandler QueryPageSettings;