merge -r 61110:61111
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / PrintControllerWithStatusDialog.cs
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.
19 //
20 // Copyright (c) 2006 Novell, Inc.
21 //
22 // Authors:
23 //      Jonathan Chambers (jonathan.chambers@ansys.com)
24 //\r
25 \r
26 using System;\r
27 using System.Drawing;\r
28 using System.Drawing.Printing;\r
29 \r
30 namespace System.Windows.Forms\r
31 {\r
32         \r
33         public class PrintControllerWithStatusDialog : PrintController {
34                 #region Local variables
35                 PrintController underlyingController;
36                 string dialogTitle;
37                 PrintingDialog dialog;
38                 int currentPage;
39                 #endregion // Local variables
40
41                 #region Public Constructors\r
42 \r
43                 [MonoTODO("Localize Dialog Title")]\r
44                 public PrintControllerWithStatusDialog(PrintController underlyingController) {\r
45                         this.underlyingController = underlyingController;\r
46                         dialog = new PrintingDialog();\r
47                         dialog.Text = "Printing";\r
48                 }\r
49 \r
50                 public PrintControllerWithStatusDialog(PrintController underlyingController, string dialogTitle) : this(underlyingController) {
51                         dialog.Text = dialogTitle;
52                 }
53                 #endregion // Public Constructors\r
54                 
55                 #region Protected Instance Methods\r
56                 public override void OnEndPage(PrintDocument document, PrintPageEventArgs e) {\r
57                         if (dialog.DialogResult == DialogResult.Cancel) {\r
58                                 e.Cancel = true;\r
59                                 dialog.Close();\r
60                         }\r
61                         base.OnEndPage (document, e);\r
62                 }\r
63 \r
64                 public override void OnEndPrint(PrintDocument document, PrintEventArgs e) {\r
65                         if (dialog.Visible)\r
66                                 dialog.Close();\r
67                         base.OnEndPrint (document, e);\r
68                 }\r
69 \r
70                 public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e) {\r
71                         if (dialog.DialogResult == DialogResult.Cancel) {\r
72                                 e.Cancel = true;\r
73                                 dialog.Close();\r
74                         }\r
75                         dialog.LabelText = string.Format("Page {0} of document", ++currentPage);\r
76                         return base.OnStartPage (document, e);\r
77                 }\r
78 \r
79                 public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {\r
80                         currentPage = 0;\r
81                         dialog.Show();\r
82                         base.OnStartPrint (document, e);\r
83                 }\r
84
85                 #endregion      // Protected Instance Methods\r
86 \r
87                 #region Internal Class\r
88                 class PrintingDialog : Form {\r
89                         private Button buttonCancel;\r
90                         private Label label;\r
91 \r
92                         public PrintingDialog() {\r
93                                 buttonCancel = new System.Windows.Forms.Button();\r
94                                 label = new System.Windows.Forms.Label();\r
95                                 SuspendLayout();\r
96 \r
97                                 buttonCancel.Location = new System.Drawing.Point(88, 88);\r
98                                 buttonCancel.Name = "buttonCancel";\r
99                                 buttonCancel.TabIndex = 0;\r
100                                 buttonCancel.Text = "Cancel";\r
101 \r
102                                 label.Location = new System.Drawing.Point(0, 40);\r
103                                 label.Name = "label";\r
104                                 label.Size = new System.Drawing.Size(257, 23);\r
105                                 label.TabIndex = 1;\r
106                                 label.Text = "Page 1 of document";\r
107                                 label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;\r
108 \r
109                                 AutoScaleBaseSize = new System.Drawing.Size(5, 13);\r
110                                 CancelButton = buttonCancel;\r
111                                 ClientSize = new System.Drawing.Size(258, 124);\r
112                                 ControlBox = false;\r
113                                 Controls.Add(label);\r
114                                 Controls.Add(buttonCancel);\r
115                                 FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;\r
116                                 Name = "PrintingDialog";\r
117                                 ShowInTaskbar = false;\r
118                                 Text = "Printing";\r
119                                 ResumeLayout(false);\r
120                         }\r
121 \r
122                         public string LabelText {\r
123                                 get { return label.Text; }\r
124                                 set { label.Text = value; }\r
125                         }\r
126                 }\r
127                 #endregion Internal Class\r
128         }\r
129 }\r