[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / PrintControllerWithStatusDialog.cs
blobd4652eb7694f7fab5172069444829580b3478a40
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006 Novell, Inc.
22 // Authors:
23 // Jonathan Chambers (jonathan.chambers@ansys.com)
26 using System;
27 using System.Drawing;
28 using System.Drawing.Printing;
29 using System.Reflection;
31 namespace System.Windows.Forms
34 public class PrintControllerWithStatusDialog : PrintController {
35 #region Local variables
36 PrintController underlyingController;
37 PrintingDialog dialog;
38 int currentPage;
39 #endregion // Local variables
41 #region Public Constructors
43 public PrintControllerWithStatusDialog(PrintController underlyingController) {
44 this.underlyingController = underlyingController;
45 dialog = new PrintingDialog();
46 dialog.Text = "Printing";
49 public PrintControllerWithStatusDialog(PrintController underlyingController, string dialogTitle) : this(underlyingController) {
50 dialog.Text = dialogTitle;
52 #endregion // Public Constructors
54 #region Protected Instance Methods
55 public override void OnEndPage(PrintDocument document, PrintPageEventArgs e) {
56 if (dialog.DialogResult == DialogResult.Cancel) {
57 e.Cancel = true;
58 dialog.Hide();
59 return;
61 underlyingController.OnEndPage (document, e);
64 public override void OnEndPrint(PrintDocument document, PrintEventArgs e) {
65 dialog.Hide();
66 underlyingController.OnEndPrint (document, e);
69 public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e) {
70 if (dialog.DialogResult == DialogResult.Cancel) {
71 e.Cancel = true;
72 dialog.Hide();
73 return null;
75 dialog.LabelText = string.Format("Page {0} of document", ++currentPage);
76 return underlyingController.OnStartPage (document, e);
79 void Set_PrinterSettings_PrintFileName (PrinterSettings settings, string filename)
81 settings.PrintFileName = filename;
84 public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {
85 try {
86 currentPage = 0;
87 dialog.Show();
88 if (document.PrinterSettings.PrintToFile) {
89 SaveFileDialog d = new SaveFileDialog ();
90 if (d.ShowDialog () != DialogResult.OK)
91 // Windows throws a Win32Exception here.
92 throw new Exception ("The operation was canceled by the user");
93 Set_PrinterSettings_PrintFileName (document.PrinterSettings, d.FileName);
95 underlyingController.OnStartPrint (document, e);
97 catch {
98 dialog.Hide ();
99 throw;
103 #endregion // Protected Instance Methods
105 #region Public Properties
106 public override bool IsPreview {
107 get { return underlyingController.IsPreview; }
109 #endregion
111 #region Internal Class
112 class PrintingDialog : Form {
113 private Button buttonCancel;
114 private Label label;
116 public PrintingDialog() {
117 buttonCancel = new System.Windows.Forms.Button();
118 label = new System.Windows.Forms.Label();
119 SuspendLayout();
121 buttonCancel.Location = new System.Drawing.Point(88, 88);
122 buttonCancel.Name = "buttonCancel";
123 buttonCancel.TabIndex = 0;
124 buttonCancel.Text = "Cancel";
126 label.Location = new System.Drawing.Point(0, 40);
127 label.Name = "label";
128 label.Size = new System.Drawing.Size(257, 23);
129 label.TabIndex = 1;
130 label.Text = "Page 1 of document";
131 label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
133 AutoScaleBaseSize = new System.Drawing.Size(5, 13);
134 CancelButton = buttonCancel;
135 ClientSize = new System.Drawing.Size(258, 124);
136 ControlBox = false;
137 Controls.Add(label);
138 Controls.Add(buttonCancel);
139 FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
140 Name = "PrintingDialog";
141 ShowInTaskbar = false;
142 Text = "Printing";
143 ResumeLayout(false);
146 public string LabelText {
147 get { return label.Text; }
148 set { label.Text = value; }
151 #endregion Internal Class