Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PrinterSettings.cs « System.Drawing.Printing « System.Drawing « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d4deb296336cd8b76f09d60fbe4edf9c92045b27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
//
// System.Drawing.PrinterSettings.cs
//
// Authors:
//   Dennis Hayes (dennish@Raytek.com)
//   Herve Poussineau (hpoussineau@fr.st)
//   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (C) 2002 Ximian, Inc
//

//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Drawing.Printing;
using System.ComponentModel;
using System.Drawing.Imaging;

namespace System.Drawing.Printing
{
	[Serializable]
#if ! NET_2_0
	[ComVisible(false)]
#endif	
	public class PrinterSettings : ICloneable
	{
		private string printer_name;
		private string print_filename;
		private short copies;
		private int maximum_page;
		private int minimum_page; 
		private int from_page;
		private int to_page;
		private bool collate;
		private PrintRange print_range;
		internal int maximum_copies;
		internal bool can_duplex;
		internal bool supports_color;
		internal int landscape_angle;		
		internal PrinterSettings.PrinterResolutionCollection printer_resolutions;
		internal PrinterSettings.PaperSizeCollection paper_sizes;
		
		public PrinterSettings() : this (SysPrn.Service.DefaultPrinter)
		{			
		}
		
		internal PrinterSettings (string printer)
		{						
			printer_name = printer;			
			ResetToDefaults ();
			SysPrn.Service.LoadPrinterSettings (printer_name, this);			
		}
		
		private void ResetToDefaults ()
		{			
			printer_resolutions = null;
			paper_sizes = null;
			maximum_page = 9999; 	
		}

		// Public subclasses

		public class PaperSourceCollection : ICollection, IEnumerable
		{
			ArrayList _PaperSources = new ArrayList();
			
			public PaperSourceCollection(PaperSource[] array) {
				foreach (PaperSource ps in array)
					_PaperSources.Add(ps);
			}
			
			public int Count { get { return _PaperSources.Count; } }
			int ICollection.Count { get { return _PaperSources.Count; } }
			bool ICollection.IsSynchronized { get { return false; } }
			object ICollection.SyncRoot { get { return this; } }			
#if NET_2_0
			[EditorBrowsable(EditorBrowsableState.Never)]
      			public int Add (PaperSource paperSource) {throw new NotImplementedException (); }
			public void CopyTo (PaperSource[] paperSources, int index)  {throw new NotImplementedException (); }
#endif
			
			public virtual PaperSource this[int index] {
				get { return _PaperSources[index] as PaperSource; }
			}
			
			IEnumerator IEnumerable.GetEnumerator()
			{
				return _PaperSources.GetEnumerator();
			}
			
			public IEnumerator GetEnumerator()
			{
				return _PaperSources.GetEnumerator();
			}
			
			void ICollection.CopyTo(Array array, int index)
			{
				_PaperSources.CopyTo(array, index);
			}
		}

		public class PaperSizeCollection : ICollection, IEnumerable
		{
			ArrayList _PaperSizes = new ArrayList();
			
			public PaperSizeCollection(PaperSize[] array) {
				foreach (PaperSize ps in array)
					_PaperSizes.Add(ps);
			}
			
			public int Count { get { return _PaperSizes.Count; } }
			int ICollection.Count { get { return _PaperSizes.Count; } }
			bool ICollection.IsSynchronized { get { return false; } }
			object ICollection.SyncRoot { get { return this; } }			
#if NET_2_0		
			[EditorBrowsable(EditorBrowsableState.Never)]
			public int Add (PaperSize paperSize) {return _PaperSizes.Add (paperSize); }	
			public void CopyTo (PaperSize[] paperSizes, int index) {throw new NotImplementedException (); }			
#else
			internal int Add (PaperSize paperSize) {return _PaperSizes.Add (paperSize); }	
#endif
			
			public virtual PaperSize this[int index] {
				get { return _PaperSizes[index] as PaperSize; }
			}
			
			IEnumerator IEnumerable.GetEnumerator()
			{
				return _PaperSizes.GetEnumerator();
			}
			
			public IEnumerator GetEnumerator()
			{
				return _PaperSizes.GetEnumerator();
			}
			
			void ICollection.CopyTo(Array array, int index)
			{
				_PaperSizes.CopyTo(array, index);
			}
			
			internal void Clear ()
			{ 
				_PaperSizes.Clear (); 
			}
		}

		public class PrinterResolutionCollection : ICollection, IEnumerable
		{
			ArrayList _PrinterResolutions = new ArrayList();
			
			public PrinterResolutionCollection(PrinterResolution[] array) {
				foreach (PrinterResolution pr in array)
					_PrinterResolutions.Add(pr);
			}
			
			public int Count { get { return _PrinterResolutions.Count; } }
			int ICollection.Count { get { return _PrinterResolutions.Count; } }
			bool ICollection.IsSynchronized { get { return false; } }
			object ICollection.SyncRoot { get { return this; } }			
#if NET_2_0
			[EditorBrowsable(EditorBrowsableState.Never)]
			public int Add (PrinterResolution printerResolution) { return _PrinterResolutions.Add (printerResolution); }
			public void CopyTo (PrinterResolution[] printerResolutions, int index) {throw new NotImplementedException (); }
#else
			internal int Add (PrinterResolution printerResolution) { return _PrinterResolutions.Add (printerResolution); }
#endif
						
			public virtual PrinterResolution this[int index] {
				get { return _PrinterResolutions[index] as PrinterResolution; }
			}
			
			IEnumerator IEnumerable.GetEnumerator()
			{
				return _PrinterResolutions.GetEnumerator();
			}
			
			public IEnumerator GetEnumerator()
			{
				return _PrinterResolutions.GetEnumerator();
			}
			
			void ICollection.CopyTo(Array array, int index)
			{
				_PrinterResolutions.CopyTo(array, index);
			}
			
			internal void Clear ()
			{ 
				_PrinterResolutions.Clear (); 
			}
		}

		public class StringCollection : ICollection, IEnumerable
		{
			ArrayList _Strings = new ArrayList();
			
			public StringCollection(string[] array) {
				foreach (string s in array)
					_Strings.Add(s);
			}
			
			public int Count { get { return _Strings.Count; } }
			int ICollection.Count { get { return _Strings.Count; } }
			bool ICollection.IsSynchronized { get { return false; } }
			object ICollection.SyncRoot { get { return this; } }
						
			public virtual string this[int index] {
				get { return _Strings[index] as string; }
			}
#if NET_2_0
			[EditorBrowsable(EditorBrowsableState.Never)]
      			public int Add (string value) { return _Strings.Add (value); }
      			public void CopyTo (string[] strings, int index) {throw new NotImplementedException (); }      			
#else
			internal int Add (string value) { return _Strings.Add (value); }
#endif

			IEnumerator IEnumerable.GetEnumerator()
			{
				return _Strings.GetEnumerator();
			}
			
			public IEnumerator GetEnumerator()
			{
				return _Strings.GetEnumerator();
			}
			
			void ICollection.CopyTo(Array array, int index)
			{
				_Strings.CopyTo(array, index);
			}			
		}
		
		//properties
		
		public bool CanDuplex
		{
			get { return can_duplex; }
		}
		
		public bool Collate
		{
			get { return collate; }
			set { collate = value; }
		}

		public short Copies
		{
			get { return copies; }
			set { 
				if (value < 0)
					throw new ArgumentException ("The value of the Copies property is less than zero.");
				
				copies = value;
			}
		}

		[MonoTODO("PrinterSettings.DefaultPageSettings")]
		public PageSettings DefaultPageSettings
		{
			get
			{
				return new PageSettings(
					this,
					// TODO: get default color mode for this printer
					false,
					// TODO: get default orientation for this printer
					false,
					// TODO: get default paper size for this printer
					new PaperSize("A4", 827, 1169),
					// TODO: get default paper source for this printer
					new PaperSource("default", PaperSourceKind.FormSource),
					// TODO: get default resolution for this printer
					new PrinterResolution(300, 300, PrinterResolutionKind.Medium)
				);
			}
		}

		[MonoTODO("PrinterSettings.Duplex")]
		public Duplex Duplex
		{
			get { throw new NotImplementedException(); }
			set { throw new NotImplementedException(); }
		}
		
		public int FromPage
		{
			get { return from_page; }
			set {
				if (value < 0)
					throw new ArgumentException ("The value of the FromPage property is less than zero");
				
				from_page = value;
			}
		}
		
		public static PrinterSettings.StringCollection InstalledPrinters
		{
			get { return SysPrn.Service.InstalledPrinters; }
		}
	
		public bool IsDefaultPrinter
		{
			get { return (printer_name == SysPrn.Service.DefaultPrinter); }
		}

		[MonoTODO("PrinterSettings.IsPlotter")]
		public bool IsPlotter
		{
			get { return false; }
		}

		[MonoTODO("PrinterSettings.IsValid")]
		public bool IsValid
		{
			get { return true; }
		}
		
		public int LandscapeAngle
		{
			get { return landscape_angle; }
		}
		
		public int MaximumCopies
		{
			get { return maximum_copies; }
		}
		
		public int MaximumPage
		{
			get { return maximum_page; }
			set {
				// This not documented but behaves like MinimumPage
				if (value < 0)
					throw new ArgumentException ("The value of the MaximumPage property is less than zero");
				
				maximum_page = value;
			}
		}
		
		public int MinimumPage
		{
			get { return minimum_page; }
			set {
				if (value < 0)
					throw new ArgumentException ("The value of the MaximumPage property is less than zero");
				
				minimum_page = value;
			}
		}
		
		public PrinterSettings.PaperSizeCollection PaperSizes
		{
			get {
				if (paper_sizes == null) {
					paper_sizes = new PrinterSettings.PaperSizeCollection (new PaperSize [] {});
					SysPrn.Service.LoadPrinterPaperSizes (printer_name, this);
				}				
				return paper_sizes;				
			}
		}

		[MonoTODO("PrinterSettings.PaperSources")]
		public PrinterSettings.PaperSourceCollection PaperSources
		{
			get { throw new NotImplementedException(); }
		}
#if NET_2_0		
		
		public string PrintFileName
		{
			get { return print_filename; }
			set { print_filename = value; }
		}
#endif		
		public string PrinterName
		{
			get { return printer_name; }
			set { 
				if (printer_name == value)
					return;
					
				printer_name = value;
				SysPrn.Service.LoadPrinterSettings (printer_name, this);
			}
		}
		
		public PrinterSettings.PrinterResolutionCollection PrinterResolutions
		{
			get {
				if (printer_resolutions == null) {
					printer_resolutions = new PrinterSettings.PrinterResolutionCollection (new PrinterResolution[] {});
					SysPrn.Service.LoadPrinterResolutions (printer_name, this);
				}
				return printer_resolutions;
			}
		}
		
		public PrintRange PrintRange
		{
			get { return print_range; }
			set { 
				if (value != PrintRange.AllPages && value != PrintRange.Selection &&
					value != PrintRange.SomePages)
					throw new InvalidEnumArgumentException ("The value of the PrintRange property is not one of the PrintRange values");
				
				print_range = value;
			}
		}

		[MonoTODO("PrinterSettings.PrintToFile")]
		public bool PrintToFile
		{
			get { throw new NotImplementedException(); }
			set { throw new NotImplementedException(); }
		}
		
		public bool SupportsColor
		{
			get { return supports_color; }
		}
		
		public int ToPage
		{
			get { return to_page; }
			set {
				if (value < 0)
					throw new ArgumentException ("The value of the ToPage property is less than zero");
				
				to_page = value;
			}		
		}

		//methods		
		public virtual object Clone()
		{
			PrinterSettings ps = new PrinterSettings (printer_name);
			return ps;
		}

		[MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
		public Graphics CreateMeasurementGraphics()
		{
			throw new NotImplementedException();
		}
#if NET_2_0
		[MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
		public Graphics CreateMeasurementGraphics(bool honorOriginAtMargins)		
		{
			throw new NotImplementedException();
		}
		
		[MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
		public Graphics CreateMeasurementGraphics(PageSettings pageSettings)		
		{
			throw new NotImplementedException();
		}
		
		[MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
		public Graphics CreateMeasurementGraphics (PageSettings pageSettings, bool honorOriginAtMargins)		
		{
			throw new NotImplementedException();
		} 
#endif		

		[MonoTODO("PrinterSettings.GetHdevmode")]
		public IntPtr GetHdevmode()
		{
			throw new NotImplementedException();
		}

		[MonoTODO("PrinterSettings.GetHdevmode")]
		public IntPtr GetHdevmode(PageSettings pageSettings)
		{
			throw new NotImplementedException();
		}

		[MonoTODO("PrinterSettings.GetHdevname")]
		public IntPtr GetHdevnames()
		{
			throw new NotImplementedException();
		}
		
#if NET_2_0

		[MonoTODO("IsDirectPrintingSupported")]
		public bool IsDirectPrintingSupported (Image image)
		{
			throw new NotImplementedException();
		}
		
		[MonoTODO("IsDirectPrintingSupported")]
		public bool IsDirectPrintingSupported (ImageFormat imageFormat)
		{
			throw new NotImplementedException();
		}
#endif

		[MonoTODO("PrinterSettings.SetHdevmode")]
		public void SetHdevmode(IntPtr hdevmode)
		{
			throw new NotImplementedException();
		}

		[MonoTODO("PrinterSettings.SetHdevnames")]
		public void SetHdevnames(IntPtr hdevnames)
		{
			throw new NotImplementedException();
		}

		[MonoTODO("PrinterSettings.ToString")]
		public override string ToString()
		{
			throw new NotImplementedException();
		}		
	}
}