2005-10-04 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Drawing / System.Drawing.Printing / StandardPrintController.cs
1 //
2 // System.Drawing.StandardPrintController.cs
3 //
4 // Author:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Herve Poussineau (hpoussineau@fr.st)
7 //
8 // (C) 2002 Ximian, Inc
9 //
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System;
35
36 namespace System.Drawing.Printing
37 {
38         public class StandardPrintController : PrintController
39         {
40                 private int page;
41                 private Image image;
42                 
43                 public StandardPrintController()
44                 {
45                 }
46
47                 [MonoTODO("StandardPrintController.OnEndPage")]
48                 public override void OnEndPage(PrintDocument document, PrintPageEventArgs e)
49                 {
50                         //TODO: print current page
51                         // - image to print is this.image
52                         // - page settings are in e.PageSettings
53                         // - printer settings are in document.PrinterSettings
54                         // - don't forget to use document.OriginAtMargins (only if .NET 1.1)
55                         
56                         // actually, "print" == "save to a file"
57                         try
58                         {
59                                 string fileName = document.DocumentName + " " + page.ToString("D4") + ".jpg";
60                                 Console.WriteLine("StandardPrintController: Print page \"{0}\"", fileName);
61                                 image.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
62                         }
63                         catch (Exception) {}
64                         
65                         if (e.Graphics != null)
66                                 e.Graphics.Dispose();
67                 }
68
69                 [MonoTODO("StandardPrintController.OnStartPrint")]
70                 public override void OnStartPrint(PrintDocument document, PrintEventArgs e){
71                         page = 0;
72                 }
73
74                 [MonoTODO("StandardPrintController.OnEndPrint")]
75                 public override void OnEndPrint(PrintDocument document, PrintEventArgs e){
76                         return;
77                 }
78
79                 [MonoTODO("StandardPrintController.OnStartPage")]
80                 public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)
81                 {
82                         //FIXME: I'm not sure of what I'm doing
83                         // I don't know what size to give to image
84                         // and why I have to clear it
85                         page++;
86                         // returns a new (empty) graphics
87                         image = new Bitmap(e.MarginBounds.Width, e.MarginBounds.Height);
88                         Graphics g = Graphics.FromImage(image);
89                         g.Clear(Color.White);
90                         return g;
91                 }
92         }
93 }