2 // System.Drawing.PrinterSettings.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
10 // Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Runtime.InteropServices;
33 using System.Collections;
34 using System.ComponentModel;
35 using System.Drawing.Imaging;
37 namespace System.Drawing.Printing
43 public class PrinterSettings : ICloneable
45 private string printer_name;
46 private string print_filename;
48 private int maximum_page;
49 private int minimum_page;
50 private int from_page;
53 private PrintRange print_range;
54 internal int maximum_copies;
55 internal bool can_duplex;
56 internal bool supports_color;
57 internal int landscape_angle;
58 private bool print_tofile;
59 internal PrinterSettings.PrinterResolutionCollection printer_resolutions;
60 internal PrinterSettings.PaperSizeCollection paper_sizes;
62 public PrinterSettings() : this (SysPrn.Service.DefaultPrinter)
67 internal PrinterSettings (string printer)
69 printer_name = printer;
71 SysPrn.Service.LoadPrinterSettings (printer_name, this);
74 private void ResetToDefaults ()
76 printer_resolutions = null;
83 public class PaperSourceCollection : ICollection, IEnumerable
85 ArrayList _PaperSources = new ArrayList();
87 public PaperSourceCollection(PaperSource[] array) {
88 foreach (PaperSource ps in array)
89 _PaperSources.Add(ps);
92 public int Count { get { return _PaperSources.Count; } }
93 int ICollection.Count { get { return _PaperSources.Count; } }
94 bool ICollection.IsSynchronized { get { return false; } }
95 object ICollection.SyncRoot { get { return this; } }
97 [EditorBrowsable(EditorBrowsableState.Never)]
\r
98 public int Add (PaperSource paperSource) {throw new NotImplementedException (); }
\r
99 public void CopyTo (PaperSource[] paperSources, int index) {throw new NotImplementedException (); }
102 public virtual PaperSource this[int index] {
103 get { return _PaperSources[index] as PaperSource; }
106 IEnumerator IEnumerable.GetEnumerator()
108 return _PaperSources.GetEnumerator();
111 public IEnumerator GetEnumerator()
113 return _PaperSources.GetEnumerator();
116 void ICollection.CopyTo(Array array, int index)
118 _PaperSources.CopyTo(array, index);
122 public class PaperSizeCollection : ICollection, IEnumerable
124 ArrayList _PaperSizes = new ArrayList();
126 public PaperSizeCollection(PaperSize[] array) {
127 foreach (PaperSize ps in array)
131 public int Count { get { return _PaperSizes.Count; } }
132 int ICollection.Count { get { return _PaperSizes.Count; } }
133 bool ICollection.IsSynchronized { get { return false; } }
134 object ICollection.SyncRoot { get { return this; } }
136 [EditorBrowsable(EditorBrowsableState.Never)]
\r
137 public int Add (PaperSize paperSize) {return _PaperSizes.Add (paperSize); }
138 public void CopyTo (PaperSize[] paperSizes, int index) {throw new NotImplementedException (); }
\r
140 internal int Add (PaperSize paperSize) {return _PaperSizes.Add (paperSize); }
143 public virtual PaperSize this[int index] {
144 get { return _PaperSizes[index] as PaperSize; }
147 IEnumerator IEnumerable.GetEnumerator()
149 return _PaperSizes.GetEnumerator();
152 public IEnumerator GetEnumerator()
154 return _PaperSizes.GetEnumerator();
157 void ICollection.CopyTo(Array array, int index)
159 _PaperSizes.CopyTo(array, index);
162 internal void Clear ()
164 _PaperSizes.Clear ();
168 public class PrinterResolutionCollection : ICollection, IEnumerable
170 ArrayList _PrinterResolutions = new ArrayList();
172 public PrinterResolutionCollection(PrinterResolution[] array) {
173 foreach (PrinterResolution pr in array)
174 _PrinterResolutions.Add(pr);
177 public int Count { get { return _PrinterResolutions.Count; } }
178 int ICollection.Count { get { return _PrinterResolutions.Count; } }
179 bool ICollection.IsSynchronized { get { return false; } }
180 object ICollection.SyncRoot { get { return this; } }
182 [EditorBrowsable(EditorBrowsableState.Never)]
\r
183 public int Add (PrinterResolution printerResolution) { return _PrinterResolutions.Add (printerResolution); }
\r
184 public void CopyTo (PrinterResolution[] printerResolutions, int index) {throw new NotImplementedException (); }
186 internal int Add (PrinterResolution printerResolution) { return _PrinterResolutions.Add (printerResolution); }
189 public virtual PrinterResolution this[int index] {
190 get { return _PrinterResolutions[index] as PrinterResolution; }
193 IEnumerator IEnumerable.GetEnumerator()
195 return _PrinterResolutions.GetEnumerator();
198 public IEnumerator GetEnumerator()
200 return _PrinterResolutions.GetEnumerator();
203 void ICollection.CopyTo(Array array, int index)
205 _PrinterResolutions.CopyTo(array, index);
208 internal void Clear ()
210 _PrinterResolutions.Clear ();
214 public class StringCollection : ICollection, IEnumerable
216 ArrayList _Strings = new ArrayList();
218 public StringCollection(string[] array) {
219 foreach (string s in array)
223 public int Count { get { return _Strings.Count; } }
224 int ICollection.Count { get { return _Strings.Count; } }
225 bool ICollection.IsSynchronized { get { return false; } }
226 object ICollection.SyncRoot { get { return this; } }
228 public virtual string this[int index] {
229 get { return _Strings[index] as string; }
232 [EditorBrowsable(EditorBrowsableState.Never)]
\r
233 public int Add (string value) { return _Strings.Add (value); }
\r
234 public void CopyTo (string[] strings, int index) {throw new NotImplementedException (); }
236 internal int Add (string value) { return _Strings.Add (value); }
239 IEnumerator IEnumerable.GetEnumerator()
241 return _Strings.GetEnumerator();
244 public IEnumerator GetEnumerator()
246 return _Strings.GetEnumerator();
249 void ICollection.CopyTo(Array array, int index)
251 _Strings.CopyTo(array, index);
257 public bool CanDuplex
259 get { return can_duplex; }
264 get { return collate; }
265 set { collate = value; }
270 get { return copies; }
273 throw new ArgumentException ("The value of the Copies property is less than zero.");
279 [MonoTODO("PrinterSettings.DefaultPageSettings")]
280 public PageSettings DefaultPageSettings
284 return new PageSettings(
288 // TODO: get default paper size for this printer
289 new PaperSize("A4", 827, 1169),
290 // TODO: get default paper source for this printer
291 new PaperSource("default", PaperSourceKind.FormSource),
292 // TODO: get default resolution for this printer
293 new PrinterResolution(200, 200, PrinterResolutionKind.Medium)
298 [MonoTODO("PrinterSettings.Duplex")]
301 get { throw new NotImplementedException(); }
302 set { throw new NotImplementedException(); }
307 get { return from_page; }
310 throw new ArgumentException ("The value of the FromPage property is less than zero");
316 public static PrinterSettings.StringCollection InstalledPrinters
318 get { return SysPrn.Service.InstalledPrinters; }
321 public bool IsDefaultPrinter
323 get { return (printer_name == SysPrn.Service.DefaultPrinter); }
326 [MonoTODO("PrinterSettings.IsPlotter")]
327 public bool IsPlotter
329 get { return false; }
332 [MonoTODO("PrinterSettings.IsValid")]
338 public int LandscapeAngle
340 get { return landscape_angle; }
343 public int MaximumCopies
345 get { return maximum_copies; }
348 public int MaximumPage
350 get { return maximum_page; }
352 // This not documented but behaves like MinimumPage
354 throw new ArgumentException ("The value of the MaximumPage property is less than zero");
356 maximum_page = value;
360 public int MinimumPage
362 get { return minimum_page; }
365 throw new ArgumentException ("The value of the MaximumPage property is less than zero");
367 minimum_page = value;
371 public PrinterSettings.PaperSizeCollection PaperSizes
374 if (paper_sizes == null) {
375 paper_sizes = new PrinterSettings.PaperSizeCollection (new PaperSize [] {});
376 SysPrn.Service.LoadPrinterPaperSizes (printer_name, this);
382 [MonoTODO("PrinterSettings.PaperSources")]
383 public PrinterSettings.PaperSourceCollection PaperSources
385 get { throw new NotImplementedException(); }
394 get { return print_filename; }
395 set { print_filename = value; }
397 public string PrinterName
399 get { return printer_name; }
401 if (printer_name == value)
404 printer_name = value;
405 SysPrn.Service.LoadPrinterSettings (printer_name, this);
409 public PrinterSettings.PrinterResolutionCollection PrinterResolutions
412 if (printer_resolutions == null) {
413 printer_resolutions = new PrinterSettings.PrinterResolutionCollection (new PrinterResolution[] {});
414 SysPrn.Service.LoadPrinterResolutions (printer_name, this);
416 return printer_resolutions;
420 public PrintRange PrintRange
422 get { return print_range; }
424 if (value != PrintRange.AllPages && value != PrintRange.Selection &&
425 value != PrintRange.SomePages)
426 throw new InvalidEnumArgumentException ("The value of the PrintRange property is not one of the PrintRange values");
432 public bool PrintToFile
434 get { return print_tofile; }
435 set { print_tofile = value; }
438 public bool SupportsColor
440 get { return supports_color; }
445 get { return to_page; }
448 throw new ArgumentException ("The value of the ToPage property is less than zero");
455 public object Clone ()
457 PrinterSettings ps = new PrinterSettings (printer_name);
461 [MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
462 public Graphics CreateMeasurementGraphics()
464 throw new NotImplementedException();
467 [MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
468 public Graphics CreateMeasurementGraphics(bool honorOriginAtMargins)
470 throw new NotImplementedException();
473 [MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
474 public Graphics CreateMeasurementGraphics(PageSettings pageSettings)
476 throw new NotImplementedException();
479 [MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
\r
480 public Graphics CreateMeasurementGraphics (PageSettings pageSettings, bool honorOriginAtMargins)
482 throw new NotImplementedException();
486 [MonoTODO("PrinterSettings.GetHdevmode")]
487 public IntPtr GetHdevmode()
489 throw new NotImplementedException();
492 [MonoTODO("PrinterSettings.GetHdevmode")]
493 public IntPtr GetHdevmode(PageSettings pageSettings)
495 throw new NotImplementedException();
498 [MonoTODO("PrinterSettings.GetHdevname")]
499 public IntPtr GetHdevnames()
501 throw new NotImplementedException();
506 [MonoTODO("IsDirectPrintingSupported")]
507 public bool IsDirectPrintingSupported (Image image)
509 throw new NotImplementedException();
512 [MonoTODO("IsDirectPrintingSupported")]
\r
513 public bool IsDirectPrintingSupported (ImageFormat imageFormat)
515 throw new NotImplementedException();
519 [MonoTODO("PrinterSettings.SetHdevmode")]
520 public void SetHdevmode(IntPtr hdevmode)
522 throw new NotImplementedException();
525 [MonoTODO("PrinterSettings.SetHdevnames")]
526 public void SetHdevnames(IntPtr hdevnames)
528 throw new NotImplementedException();
531 public override string ToString()
533 return "Printer [PrinterSettings" + printer_name + " Copies=" + copies + " Collate=" + collate
534 + " Duplex=" + can_duplex + " FromPage=" + from_page + " LandscapeAngle=" + landscape_angle
535 + " MaximumCopies=" + maximum_copies + " OutputPort=" + " ToPage=" + to_page + "]";
\r