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 542 543 544 545 546 547 548 549 550 551
|
//
// 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,2006 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.Runtime.InteropServices;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing.Imaging;
namespace System.Drawing.Printing
{
[Serializable]
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;
private bool print_tofile;
internal PrinterSettings.PrinterResolutionCollection printer_resolutions;
internal PrinterSettings.PaperSizeCollection paper_sizes;
internal PrinterSettings.PaperSourceCollection paper_sources;
private PageSettings default_pagesettings;
private Duplex duplex;
internal bool is_plotter;
private PrintingServices printing_services;
internal NameValueCollection printer_capabilities; // this stores a list of all the printer options. Used only in cups, but might come in handy on win too.
public PrinterSettings() : this (SysPrn.CreatePrintingService ())
{
}
internal PrinterSettings (PrintingServices printing_services)
{
this.printing_services = printing_services;
printer_name = printing_services.DefaultPrinter;
ResetToDefaults ();
printing_services.LoadPrinterSettings (printer_name, this);
}
private void ResetToDefaults ()
{
printer_resolutions = null;
paper_sizes = null;
paper_sources = null;
default_pagesettings = null;
maximum_page = 9999;
copies = 1;
collate = true;
}
//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;
}
}
public PageSettings DefaultPageSettings
{
get {
if (default_pagesettings == null) {
default_pagesettings = new PageSettings (this,
SupportsColor,
false,
// Real defaults are set by LoadPrinterSettings
new PaperSize("A4", 827, 1169),
new PaperSource(PaperSourceKind.FormSource, "Tray"),
new PrinterResolution(PrinterResolutionKind.Medium, 200, 200));
}
return default_pagesettings;
}
}
public Duplex Duplex
{
get { return this.duplex; }
set { this.duplex = value; }
}
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.GlobalService.InstalledPrinters; }
}
public bool IsDefaultPrinter
{
get { return (printer_name == printing_services.DefaultPrinter); }
}
public bool IsPlotter
{
get { return is_plotter; }
}
public bool IsValid
{
get { return printing_services.IsPrinterValid (this.printer_name); }
}
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 (!this.IsValid)
throw new InvalidPrinterException(this);
return paper_sizes;
}
}
public PrinterSettings.PaperSourceCollection PaperSources
{
get {
if (!this.IsValid)
throw new InvalidPrinterException(this);
return paper_sources;
}
}
public
string PrintFileName
{
get { return print_filename; }
set { print_filename = value; }
}
public string PrinterName
{
get { return printer_name; }
set {
if (printer_name == value)
return;
printer_name = value;
printing_services.LoadPrinterSettings (printer_name, this);
}
}
public PrinterSettings.PrinterResolutionCollection PrinterResolutions
{
get {
if (!this.IsValid)
throw new InvalidPrinterException(this);
if (printer_resolutions == null) {
printer_resolutions = new PrinterSettings.PrinterResolutionCollection (new PrinterResolution[] {});
printing_services.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;
}
}
public bool PrintToFile
{
get { return print_tofile; }
set { print_tofile = value; }
}
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;
}
}
internal NameValueCollection PrinterCapabilities {
get {
if (this.printer_capabilities == null)
this.printer_capabilities = new NameValueCollection();
return this.printer_capabilities;
}
}
//methods
public object Clone ()
{
PrinterSettings ps = new PrinterSettings (printing_services);
return ps;
}
[MonoTODO("PrinterSettings.CreateMeasurementGraphics")]
public Graphics CreateMeasurementGraphics()
{
throw new NotImplementedException();
}
[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();
}
[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();
}
[MonoTODO("IsDirectPrintingSupported")]
public bool IsDirectPrintingSupported (Image image)
{
throw new NotImplementedException();
}
[MonoTODO("IsDirectPrintingSupported")]
public bool IsDirectPrintingSupported (ImageFormat imageFormat)
{
throw new NotImplementedException();
}
[MonoTODO("PrinterSettings.SetHdevmode")]
public void SetHdevmode(IntPtr hdevmode)
{
throw new NotImplementedException();
}
[MonoTODO("PrinterSettings.SetHdevnames")]
public void SetHdevnames(IntPtr hdevnames)
{
throw new NotImplementedException();
}
public override string ToString()
{
return "Printer [PrinterSettings " + printer_name + " Copies=" + copies + " Collate=" + collate
+ " Duplex=" + can_duplex + " FromPage=" + from_page + " LandscapeAngle=" + landscape_angle
+ " MaximumCopies=" + maximum_copies + " OutputPort=" + " ToPage=" + to_page + "]";
}
// Public subclasses
#region 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; } }
[EditorBrowsable(EditorBrowsableState.Never)]
public int Add (PaperSource paperSource) {return _PaperSources.Add (paperSource); }
public void CopyTo (PaperSource[] paperSources, int index) {throw new NotImplementedException (); }
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);
}
internal void Clear ()
{
_PaperSources.Clear ();
}
}
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; } }
[EditorBrowsable(EditorBrowsableState.Never)]
public int Add (PaperSize paperSize) {return _PaperSizes.Add (paperSize); }
public void CopyTo (PaperSize[] paperSizes, int index) {throw new NotImplementedException (); }
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; } }
[EditorBrowsable(EditorBrowsableState.Never)]
public int Add (PrinterResolution printerResolution) { return _PrinterResolutions.Add (printerResolution); }
public void CopyTo (PrinterResolution[] printerResolutions, int index) {throw new NotImplementedException (); }
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; }
}
[EditorBrowsable(EditorBrowsableState.Never)]
public int Add (string value) { return _Strings.Add (value); }
public void CopyTo (string[] strings, int index) {throw new NotImplementedException (); }
IEnumerator IEnumerable.GetEnumerator()
{
return _Strings.GetEnumerator();
}
public IEnumerator GetEnumerator()
{
return _Strings.GetEnumerator();
}
void ICollection.CopyTo(Array array, int index)
{
_Strings.CopyTo(array, index);
}
}
#endregion
/*
void GetPrintDialogInfo (string printer_name, ref string port, ref string type, ref string status, ref string comment)
{
printing_services.GetPrintDialogInfo (printer_name, ref port, ref type, ref status, ref comment);
}
*/
}
}
|