diff options
Diffstat (limited to 'mcs/class/System.Drawing/System.Drawing.Printing')
34 files changed, 4030 insertions, 0 deletions
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog b/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog new file mode 100644 index 00000000000..34b32630033 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog @@ -0,0 +1,54 @@ +2006-01-15 Jordi Mas i Hernandez <jordimash@gmail.com> + + * PrintingServicesUnix.cs: Allow setting the dpy's for the surface + +2005-12-22 Jordi Mas i Hernandez <jordimash@gmail.com> + + * PrintingServices.cs: Printing services abstration class + * PrintingServicesWin32.cs: Win32 printer driver + * PrintingServicesUnix.cs: Unix printer driver + * Margins.cs: Fixes exceptions error messages + * PrinterResolution.cs: Fixes + * PrintEventArgs.cs: New internal method + * PrintPageEventArgs.cs: New internal method + * StandardPrintController.cs: Fixes + * PrinterUnitConvert.cs: Fixes conversion errors + * PrintDocument.cs: Fixes to make it print + * PageSettings.cs: Take margains into account + * PrintController.cs: Fixes + * PaperSize.cs: Method to set paper Kind + * PrinterSettings.cs: Implements settings and fixes + * + +2005-12-07 Jordi Mas i Hernandez <jordimash@gmail.com> + + * PrinterResolutionKind.cs: Fixes signature for .Net 2.0 + * PaperKind.cs: Fixes signature for .Net 2.0 + * PaperSource.cs: Fixes signature for .Net 2.0 + * Margins.cs: Fixes signature for .Net 2.0 + * PrinterResolution.cs: Fixes signature for .Net 2.0 + * PrintEventArgs.cs: Fixes signature for .Net 2.0 + * PrintAction.cs: New enum in .Net 2.0 + * PageSettings.cs: Fixes signature for .Net 2.0 + * PaperSourceKind.cs: Fixes signature for .Net 2.0 + * PrintController.cs: Fixes signature for .Net 2.0 + * Duplex.cs: Fixes signature for .Net 2.0 + * PaperSize.cs: Fixes signature for .Net 2.0 + * PreviewPrintController.cs: Fixes signature for .Net 2.0 + * PrinterSettings.cs: Fixes signature for .Net 2.0 + * PrintRange.cs: Fixes signature for .Net 2.0 + +2005-09-16 Sebastien Pouliot <sebastien@ximian.com> + + * InvalidPrinterException.cs: Removed NotImplementedException (not + required) and added a demand for SerializationFormatter on the + GetObjectData method. + * PrintingPermission.cs: Throw ArgumentException if the class or + version attributes are missing in the supplied XML (only in 1.x). + +2005-03-23 Jordi Mas i Hernandez <jordi@ximian.com> + * PaperKind.cs: fixes wrong enum values + +2005-01-27 Lluis Sanchez Gual <lluis@novell.com> + + * MarginsConverter.cs: Implemented support for InstanceDescriptor. diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/Duplex.cs b/mcs/class/System.Drawing/System.Drawing.Printing/Duplex.cs new file mode 100644 index 00000000000..2eaf3452f02 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/Duplex.cs @@ -0,0 +1,42 @@ +//
+// System.Drawing.Duplex.cs
+//
+// (C) 2001 Ximian, Inc. http://www.ximian.com
+// Author: Dennis Hayes (dennish@raytek.com)
+//
+ +// +// 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;
+namespace System.Drawing.Printing
+{ +#if NET_2_0 + [Serializable] +#endif
+ public enum Duplex {
+ Default = -1,
+ Horizontal = 3,
+ Simplex = 1,
+ Vertical = 2
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/InvalidPrinterException.cs b/mcs/class/System.Drawing/System.Drawing.Printing/InvalidPrinterException.cs new file mode 100644 index 00000000000..9ee8b733b7f --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/InvalidPrinterException.cs @@ -0,0 +1,64 @@ +// +// System.Drawing.InvalidPrinterExecption.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.com) +// +// (C) 2002 Ximian, Inc +// + +// +// Copyright (C) 2004-2005 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.Serialization; +using System.Security.Permissions; + +namespace System.Drawing.Printing { + +#if NET_2_0 + [Serializable] +#endif + public class InvalidPrinterException : SystemException { + + private PrinterSettings settings; + + public InvalidPrinterException (PrinterSettings settings) + { + this.settings = settings; + } + + protected InvalidPrinterException (SerializationInfo info, StreamingContext context) + : base (info, context) + { + } + + [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData (SerializationInfo info, StreamingContext context) + { + if (info == null) + throw new ArgumentNullException ("info"); + + base.GetObjectData (info, context); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/Margins.cs b/mcs/class/System.Drawing/System.Drawing.Printing/Margins.cs new file mode 100644 index 00000000000..20b49572926 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/Margins.cs @@ -0,0 +1,151 @@ +// +// System.Drawing.Margins.cs +// +// Authors: +// Dennis Hayes (dennish@Raytek.com) +// 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.ComponentModel; + +namespace System.Drawing.Printing +{ +#if NET_2_0 + [Serializable] +#endif + [TypeConverter (typeof (MarginsConverter))] + public class Margins : ICloneable + { + int left; + int right; + int top; + int bottom; + + public Margins() + { + left = 100; + right = 100; + top = 100; + bottom = 100; + } + + public Margins(int left, int right, int top, int bottom) + { + //Verify parameters + if (left < 0) + throw new System.ArgumentException("All Margins must be greater than 0", "left"); + if (right < 0) + throw new System.ArgumentException("All Margins must be greater than 0", "right"); + if (top < 0) + throw new System.ArgumentException("All Margins must be greater than 0", "top"); + if (bottom < 0) + throw new System.ArgumentException("All Margins must be greater than 0", "bottom"); + + //Set proprities + this.left = left; + this.right = right; + this.top = top; + this.bottom = bottom; + } + + public int Left { + get { + return left; + } + set { + if (left < 0) + throw new System.ArgumentException("All Margins must be greater than 0", "left"); + left = value; + } + } + + public int Right { + get { + return right; + } + set { + if (right < 0) + throw new System.ArgumentException("All Margins must be greater than 0", "right"); + right = value; + } + } + + public int Top { + get { + return top; + } + set { + if (top < 0) + throw new System.ArgumentException("All Margins must be greater than 0", "top"); + top = value; + } + } + + public int Bottom { + get { + return bottom; + } + set { + if (bottom < 0) + throw new System.ArgumentException("All Margins must be greater than 0", "bottom"); + bottom = value; + } + } + + public object Clone() + { + return new Margins (this.Left, this.Right, this.Top, this.Bottom); + } + + public override bool Equals (object obj) + { + Margins m = obj as Margins; + + if (m == null) + return false; + if (m.Left == left && m.Right == right && m.Top == top && m.Bottom == bottom) + return true; + + return false; + } + + public override int GetHashCode () + { + // Try to create a somewhat meaningful hash + int hash = left + right * 2^8 + top * 2^16 + bottom * 2^24; + return hash; + } + + public override string ToString() + { + string ret = "[Margins Left={0} Right={1} Top={2} Bottom={3}]"; + return String.Format (ret, this.Left, this.Right, this.Top, this.Bottom); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/MarginsConverter.cs b/mcs/class/System.Drawing/System.Drawing.Printing/MarginsConverter.cs new file mode 100644 index 00000000000..c437a1c4b68 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/MarginsConverter.cs @@ -0,0 +1,137 @@ +// +// System.Drawing.MarginsConverter.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.com) +// Herve Poussineau (hpoussineau@fr.st) +// +// (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.ComponentModel; +using System.Globalization; +using System.Text.RegularExpressions; +using System.ComponentModel.Design.Serialization; +using System.Reflection;
+ +namespace System.Drawing.Printing { + /// <summary> + /// Summary description for MarginsConverter. + /// </summary> + public class MarginsConverter : ExpandableObjectConverter { + public MarginsConverter() { + } + #region Methods + public override bool CanConvertFrom(ITypeDescriptorContext context,Type sourceType) { + if (sourceType == typeof(string)) + return true; + + return base.CanConvertFrom(context, sourceType); + } + + public override bool CanConvertTo(ITypeDescriptorContext context,Type destinationType) { + if (destinationType == typeof(string)) + return true; + + if (destinationType == typeof (InstanceDescriptor)) + return true; + + return base.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(ITypeDescriptorContext context,CultureInfo culture,object value) { + if (value is string) + { + if (value == null) + return new Margins(); + + // format [left];[right];[top];[bottom] + string separator = @"( |\t)*"; + separator = separator + ";" + separator; + string regex = @"(?<left>\d+)" + separator + @"(?<right>\d+)" + separator + @"(?<top>\d+)" + separator + @"(?<bottom>\d+)"; + + Match match = new Regex(regex).Match(value as string); + if (!match.Success) + throw new ArgumentException("value"); + + int left, right, top, bottom; + try + { + left = int.Parse(match.Groups["left"].Value); + right = int.Parse(match.Groups["right"].Value); + top = int.Parse(match.Groups["top"].Value); + bottom = int.Parse(match.Groups["bottom"].Value); + } + catch (Exception e) + { + throw new ArgumentException("value", e); + } + return new Margins(left, right, top, bottom); + } else + return base.ConvertFrom(context, culture, value); + } + + public override object ConvertTo(ITypeDescriptorContext context,CultureInfo culture,object value,Type destinationType) { + if (destinationType == typeof(string) && value is Margins) + { + Margins source = value as Margins; + string ret = "{0}; {1}; {2}; {3}"; + return String.Format(ret, source.Left, source.Right, source.Top, source.Bottom); + } + if (destinationType == typeof (InstanceDescriptor) && value is Margins) { + Margins c = (Margins) value; + ConstructorInfo ctor = typeof(Margins).GetConstructor (new Type[] {typeof(int), typeof(int), typeof(int), typeof(int)} ); + return new InstanceDescriptor (ctor, new object[] {c.Left, c.Right, c.Top, c.Bottom}); + } + + return base.ConvertTo(context, culture, value, destinationType); + } + + public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) + { + return true; + } + + public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues) + { + try + { + Margins margins = new Margins(); + margins.Left = int.Parse(propertyValues["Left"].ToString()); + margins.Right = int.Parse(propertyValues["Right"].ToString()); + margins.Top = int.Parse(propertyValues["Top"].ToString()); + margins.Bottom = int.Parse(propertyValues["Bottom"].ToString()); + return margins; + } + catch (Exception) + { + // in case of error, return null + return null; + } + } + #endregion + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PageSettings.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PageSettings.cs new file mode 100644 index 00000000000..c962f00d8bb --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PageSettings.cs @@ -0,0 +1,216 @@ +// +// System.Drawing.PageSettings.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; + +namespace System.Drawing.Printing +{ +#if NET_2_0 + [Serializable] +#else + [ComVisible (false)] +#endif + public class PageSettings : ICloneable + { + bool _Color; + bool _Landscape; + float _HardMarginX;
+ float _HardMarginY; + RectangleF _PrintableArea; + // create a new default Margins object (is 1 inch for all margins) + Margins _Margins = new Margins(); + PaperSize _PaperSize; + PaperSource _PaperSource; + PrinterResolution _PrinterResolution; + PrinterSettings _PrinterSettings; + + public PageSettings() : this(new PrinterSettings()) + { + } + + public PageSettings(PrinterSettings printerSettings) + { + PrinterSettings = printerSettings; + + Color = printerSettings.DefaultPageSettings.Color; + Landscape = printerSettings.DefaultPageSettings.Landscape; + PaperSize = printerSettings.DefaultPageSettings.PaperSize; + PaperSource = printerSettings.DefaultPageSettings.PaperSource; + PrinterResolution = printerSettings.DefaultPageSettings.PrinterResolution; + } + + // used by PrinterSettings.DefaultPageSettings + internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution) + { + PrinterSettings = printerSettings; + + Color = color; + Landscape = landscape; + PaperSize = paperSize; + PaperSource = paperSource; + PrinterResolution = printerResolution; + } + + //props + public Rectangle Bounds{ + get{ + int width = this.PaperSize.Width; + int height = this.PaperSize.Height; + + width -= this.Margins.Left + this.Margins.Right; + height -= this.Margins.Top + this.Margins.Bottom; + + if (this.Landscape) { + // swap width and height + int tmp = width; + width = height; + height = tmp; + } + return new Rectangle (Margins.Left, Margins.Top, width, height); + } + } + + public bool Color{ + get{ + return _Color; + } + set{ + _Color = value; + } + } + + public bool Landscape { + get{ + return _Landscape; + } + set{ + _Landscape = value; + } + } + + public Margins Margins{ + get{ + return _Margins; + } + set{ + _Margins = value; + } + } + + public PaperSize PaperSize{ + get{ + return _PaperSize; + } + set{ + _PaperSize = value; + } + } + + public PaperSource PaperSource{ + get{ + return _PaperSource; + } + set{ + _PaperSource = value; + } + } + + public PrinterResolution PrinterResolution{ + get{ + return _PrinterResolution; + } + set{ + _PrinterResolution = value; + } + } + + public PrinterSettings PrinterSettings{ + get{ + return _PrinterSettings; + } + set{ + _PrinterSettings = value; + } + } +#if NET_2_0 + public float HardMarginX { + get { + return _HardMarginX; + } + } +
+ public float HardMarginY { + get { + return _HardMarginY; + } + } + + public RectangleF PrintableArea { + get { + return _PrintableArea; + } + } +#endif
+ + + public object Clone(){ + return new PageSettings(this.PrinterSettings); + } + + + [MonoTODO("PageSettings.CopyToHdevmode")] + public void CopyToHdevmode (IntPtr hdevmode){ + throw new NotImplementedException (); + } + + + [MonoTODO("PageSettings.SetHdevmode")] + public void SetHdevmode (IntPtr hdevmode){ + throw new NotImplementedException (); + } + + public override string ToString(){ + string ret = "[PageSettings: Color={0}"; + ret += ", Landscape={1}"; + ret += ", Margins={2}"; + ret += ", PaperSize={3}"; + ret += ", PaperSource={4}"; + ret += ", PrinterResolution={5}"; + ret += "]"; + + return String.Format(ret, this.Color, this.Landscape, this.Margins, this.PaperSize, this.PaperSource, this.PrinterResolution); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PaperKind.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PaperKind.cs new file mode 100644 index 00000000000..d379f1ef5d3 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PaperKind.cs @@ -0,0 +1,157 @@ +//
+// System.Drawing.PaperKind.cs
+//
+// (C) 2002 Ximian, Inc. http://www.ximian.com
+// Author: Dennis Hayes (dennish@raytek.com)
+//
+ +// +// 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; +
+namespace System.Drawing.Printing
+{
+#if NET_2_0 + [Serializable] +#endif
+ public enum PaperKind + {
+ A2 = 66,
+ A3 = 8,
+ A3Extra = 63,
+ A3ExtraTransverse = 68,
+ A3Rotated = 76,
+ A3Transverse = 67,
+ A4 = 9,
+ A4Extra = 53,
+ A4Plus = 60,
+ A4Rotated = 77,
+ A4Small = 10,
+ A4Transverse = 55,
+ A5 = 11,
+ A5Extra = 64,
+ A5Rotated = 78,
+ A5Transverse = 61,
+ A6 = 70,
+ A6Rotated = 83,
+ APlus = 57,
+ B4 = 12,
+ B4Envelope = 33,
+ B4JisRotated = 79, + B5 = 13, + B5Envelope = 34,
+ B5Extra = 65,
+ B5JisRotated = 80,
+ B5Transverse = 62,
+ B6Envelope = 35,
+ B6Jis = 88,
+ B6JisRotated = 89,
+ BPlus = 58,
+ C3Envelope = 29,
+ C4Envelope = 30,
+ C5Envelope = 28,
+ C65Envelope = 32, + C6Envelope = 31,
+ CSheet = 24,
+ Custom = 0,
+ DLEnvelope = 27,
+ DSheet = 25,
+ ESheet = 26,
+ Executive = 7,
+ Folio = 14,
+ GermanLegalFanfold = 41,
+ GermanStandardFanfold = 40,
+ InviteEnvelope = 47,
+ IsoB4 = 42, + ItalyEnvelope = 36,
+ JapaneseDoublePostcard = 69,
+ JapaneseDoublePostcardRotated = 82,
+ JapaneseEnvelopeChouNumber3 = 73,
+ JapaneseEnvelopeChouNumber3Rotated = 86,
+ JapaneseEnvelopeChouNumber4 = 74,
+ JapaneseEnvelopeChouNumber4Rotated = 87,
+ JapaneseEnvelopeKakuNumber2 = 71,
+ JapaneseEnvelopeKakuNumber2Rotated = 84,
+ JapaneseEnvelopeKakuNumber3 = 72,
+ JapaneseEnvelopeKakuNumber3Rotated = 85,
+ JapaneseEnvelopeYouNumber4 = 91,
+ JapaneseEnvelopeYouNumber4Rotated = 92,
+ JapanesePostcard = 43,
+ JapanesePostcardRotated = 81,
+ Ledger = 4,
+ Legal = 5,
+ LegalExtra = 51,
+ Letter = 1,
+ LetterExtra = 50,
+ LetterExtraTransverse = 56,
+ LetterPlus = 59,
+ LetterRotated = 75,
+ LetterSmall = 2,
+ LetterTransverse = 54,
+ MonarchEnvelope = 37,
+ Note = 18,
+ Number10Envelope = 20,
+ Number11Envelope = 21,
+ Number12Envelope = 22,
+ Number14Envelope = 23,
+ Number9Envelope = 19,
+ PersonalEnvelope = 38,
+ Prc16K = 93,
+ Prc16KRotated = 106,
+ Prc32K = 94,
+ Prc32KBig = 95,
+ Prc32KBigRotated = 108,
+ Prc32KRotated = 107,
+ PrcEnvelopeNumber1 = 96,
+ PrcEnvelopeNumber10 = 105,
+ PrcEnvelopeNumber10Rotated = 118,
+ PrcEnvelopeNumber1Rotated = 109,
+ PrcEnvelopeNumber2 = 97,
+ PrcEnvelopeNumber2Rotated = 110,
+ PrcEnvelopeNumber3 = 98,
+ PrcEnvelopeNumber3Rotated = 111,
+ PrcEnvelopeNumber4 = 99,
+ PrcEnvelopeNumber4Rotated = 112,
+ PrcEnvelopeNumber5 = 100,
+ PrcEnvelopeNumber5Rotated = 113,
+ PrcEnvelopeNumber6 = 101,
+ PrcEnvelopeNumber6Rotated = 114,
+ PrcEnvelopeNumber7 = 102,
+ PrcEnvelopeNumber7Rotated = 115,
+ PrcEnvelopeNumber8 = 103,
+ PrcEnvelopeNumber8Rotated = 116,
+ PrcEnvelopeNumber9 = 104,
+ PrcEnvelopeNumber9Rotated = 117,
+ Quarto = 15,
+ Standard10x11 = 45,
+ Standard10x14 = 16,
+ Standard11x17 = 17,
+ Standard12x11 = 90,
+ Standard15x11 = 46,
+ Standard9x11 = 44,
+ Statement = 6,
+ Tabloid = 3,
+ TabloidExtra = 52,
+ USStandardFanfold = 39
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PaperSize.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PaperSize.cs new file mode 100644 index 00000000000..8ded0d59eaf --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PaperSize.cs @@ -0,0 +1,115 @@ +// +// System.Drawing.PaperSize.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.com) +// Herve Poussineau (hpoussineau@fr.st) +// +// (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; + +namespace System.Drawing.Printing +{ + /// <summary> + /// Summary description for PaperSize. + /// </summary> +#if NET_2_0 + [Serializable] +#endif + public class PaperSize + { + string name; + int width; + int height; + PaperKind kind; +#if NET_2_0 + public PaperSize () + { + + } +#endif + public PaperSize(string name, int width, int height) + { + this.width = width; + this.height = height; + this.name = name; + this.kind = PaperKind.Custom; + } + + public int Width{ + get{ + return width; + }set + { + if (Kind != PaperKind.Custom) + throw new ArgumentException(); + width = value; + } + } + public int Height{ + get{ + return height; + }set + { + if (Kind != PaperKind.Custom) + throw new ArgumentException(); + height = value; + } + } + + public string PaperName{ + get{ + return name; + } + set{ + if (Kind != PaperKind.Custom) + throw new ArgumentException(); + name = value; + } + } + + public PaperKind Kind{ + get{ + return kind; + } + } + internal void SetKind (PaperKind k) {kind = k;} +#if NET_2_0 + [MonoTODO] + public int RawKind { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + }
+ +#endif + + public override string ToString(){ + string ret = "[PaperSize {0} Kind={1} Height={2} Width={3}]"; + return String.Format(ret, this.PaperName, this.Kind, this.Height, this.Width); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PaperSource.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PaperSource.cs new file mode 100644 index 00000000000..9523f304977 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PaperSource.cs @@ -0,0 +1,95 @@ +// +// System.Drawing.PaperSource.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.com) +// Herve Poussineau (hpoussineau@fr.st) +// +// (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; + +namespace System.Drawing.Printing +{ + /// <summary> + /// Summary description for PaperSource. + /// </summary> +#if NET_2_0 + [Serializable] +#endif + public class PaperSource + { + PaperSourceKind _Kind; + string _SourceName; + +#if NET_2_0 + public PaperSource () + { + + } +#endif + // NOTE:how to construct this class? + // I have added a constructor, but I am not sure of me... + internal PaperSource(string sourceName, PaperSourceKind kind) + { + _SourceName = sourceName; + _Kind = kind; + } + + public PaperSourceKind Kind{ + get { + return _Kind; + } + } + public string SourceName{ + get { + return _SourceName; + } +#if NET_2_0 + set { + _SourceName = value; + } +#endif + } + +#if NET_2_0 + [MonoTODO] + public int RawKind { + get { + throw new NotImplementedException (); + } + set { + throw new NotImplementedException (); + } + } +#endif
+ + public override string ToString(){ + string ret = "[PaperSource {0} Kind={1}]"; + return String.Format(ret, this.SourceName, this.Kind); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PaperSourceKind.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PaperSourceKind.cs new file mode 100644 index 00000000000..3312630ef5a --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PaperSourceKind.cs @@ -0,0 +1,52 @@ +//
+// System.Drawing.PaperSourceKind.cs
+//
+// (C) 2002 Ximian, Inc. http://www.ximian.com
+// Author: Dennis Hayes (dennish@raytek.com)
+//
+ +// +// 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;
+namespace System.Drawing.Printing
+{
+#if NET_2_0 + [Serializable] +#endif
+ public enum PaperSourceKind {
+ AutomaticFeed = 7,
+ Cassette = 14,
+ Custom = 257,
+ Envelope = 5,
+ FormSource = 15,
+ LargeCapacity = 11,
+ LargeFormat = 10,
+ Lower = 2,
+ Manual = 4,
+ ManualFeed = 6,
+ Middle = 3,
+ SmallFormat = 9,
+ TractorFeed = 8,
+ Upper = 1
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PreviewPageInfo.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PreviewPageInfo.cs new file mode 100644 index 00000000000..4242b054e11 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PreviewPageInfo.cs @@ -0,0 +1,57 @@ +// +// System.Drawing.PreviewPageInfo.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.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; + +namespace System.Drawing.Printing +{ + /// <summary> + /// Summary description for PreviewPageInfo. + /// </summary> + public sealed class PreviewPageInfo { + Image image; + Size physicalSize; + public PreviewPageInfo(Image image, Size physicalSize) { + this.image = image; + this.physicalSize = physicalSize; + } + public Image Image { + get{ + return image; + } + } + public Size PhysicalSize{ + get{ + return physicalSize; + } + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PreviewPrintController.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PreviewPrintController.cs new file mode 100644 index 00000000000..63d26f5d89c --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PreviewPrintController.cs @@ -0,0 +1,87 @@ +//
+// System.Drawing.PreviewPrintController.cs
+//
+// Author:
+// Dennis Hayes (dennish@Raytek.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;
+
+namespace System.Drawing.Printing
+{
+ public class PreviewPrintController : PrintController
+ {
+ private bool useantialias; +
+ public PreviewPrintController()
+ {
+ useantialias = false;
+ }
+#if NET_2_0 + [MonoTODO] + public virtual bool IsPreview { + get { throw new NotImplementedException(); } + }
+#endif +
+ [MonoTODO]
+ public override void OnEndPage(PrintDocument document, PrintPageEventArgs e){
+ throw new NotImplementedException ();
+ } +
+ [MonoTODO]
+ public override void OnStartPrint(PrintDocument document, PrintEventArgs e){
+ throw new NotImplementedException ();
+ } +
+ [MonoTODO]
+ public override void OnEndPrint(PrintDocument document, PrintEventArgs e){
+ throw new NotImplementedException ();
+ } +
+ [MonoTODO]
+ public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e){
+ throw new NotImplementedException ();
+ }
+
+ public virtual bool UseAntiAlias {
+ get{
+ return useantialias;
+ }
+ set{
+ useantialias = value;
+ }
+ } +
+ [MonoTODO]
+ public PreviewPageInfo [] GetPreviewPageInfo(){
+ throw new NotImplementedException ();
+ }
+
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintAction.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintAction.cs new file mode 100644 index 00000000000..efe7aaef663 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintAction.cs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2005 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. +// +// Authors: +// +// Jordi Mas i Hernandez <jordimash@gmail.com> +// +// + +#if NET_2_0 + +using System; + +namespace System.Drawing.Printing +{ + public enum PrintAction + { + PrintToFile = 0, + PrintToPreview = 1, + PrintToPrinter = 2 + }
+ +} + +#endif + diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintController.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintController.cs new file mode 100644 index 00000000000..5855e3faaec --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintController.cs @@ -0,0 +1,65 @@ +// +// System.Drawing.PrintController.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.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; + +namespace System.Drawing.Printing +{ + public abstract class PrintController + { + public PrintController () + { + } +#if NET_2_0 + public virtual bool IsPreview { + get { return false; } + }
+#endif + public virtual void OnEndPage (PrintDocument document, PrintPageEventArgs e) + { + } + + public virtual void OnStartPrint (PrintDocument document, PrintEventArgs e) + { + } + + public virtual void OnEndPrint (PrintDocument document, PrintEventArgs e) + { + } + + + public virtual Graphics OnStartPage (PrintDocument document, PrintPageEventArgs e) + { + return null; + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintDocument.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintDocument.cs new file mode 100644 index 00000000000..8c9c6d550e2 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintDocument.cs @@ -0,0 +1,209 @@ +// +// System.Drawing.PrintDocument.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.ComponentModel; + +namespace System.Drawing.Printing +{ + [DefaultEvent ("PrintPage"), DefaultProperty ("DocumentName")] + [ToolboxItemFilter ("System.Drawing.Printing", ToolboxItemFilterType.Allow)] + public class PrintDocument : System.ComponentModel.Component + { + private PageSettings defaultpagesettings; + private PrinterSettings printersettings; + private PrintController printcontroller; + private string documentname; +#if !(NET_1_0) + private bool originAtMargins = false; // .NET V1.1 Beta +#endif + + public PrintDocument() { + documentname = "document"; //offical default. + defaultpagesettings = new PageSettings(); // use default values of default printer + printersettings = new PrinterSettings(); // use default values + printcontroller = new StandardPrintController(); + } + + // properties + [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] + [Browsable (false)] + [SRDescription ("The settings for the current page.")] + public PageSettings DefaultPageSettings{ + get{ + return defaultpagesettings; + } + set{ + defaultpagesettings = value; + } + } + + // Name of the document, not the file! + [DefaultValue ("document")] + [SRDescription ("The name of the document.")] + public string DocumentName{ + get{ + return documentname; + } + set{ + documentname = value; + } + } + + [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] + [Browsable (false)] + [SRDescription ("The print controller object.")] + public PrintController PrintController{ + get{ + return printcontroller; + } + set{ + printcontroller = value; + } + } + + [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] + [Browsable (false)] + [SRDescription ("The current settings for the active printer.")] + public PrinterSettings PrinterSettings{ + get{ + return printersettings; + } + set{ + printersettings = value; + } + } + +#if !(NET_1_0) + [DefaultValue (false)] + [SRDescription ("Determines if the origin is set at the specified margins.")] + public bool OriginAtMargins{ + get{ + return originAtMargins; + } + set{ + originAtMargins = value; + } + } +#endif + + // methods + public void Print(){ + PrintEventArgs printArgs = new PrintEventArgs(); + this.OnBeginPrint(printArgs); + if (printArgs.Cancel) + return; + PrintController.OnStartPrint(this, printArgs); + if (printArgs.Cancel) + return; + + Graphics g = null; + + // while there are more pages + PrintPageEventArgs printPageArgs; + do + { + PageSettings pageSettings = DefaultPageSettings.Clone() as PageSettings; + this.OnQueryPageSettings(new QueryPageSettingsEventArgs(pageSettings)); + + printPageArgs = new PrintPageEventArgs( + null, + pageSettings.Bounds, + new Rectangle(0, 0, pageSettings.PaperSize.Width, pageSettings.PaperSize.Height), + pageSettings); + + if (g == null) { + g = Graphics.FromHdc (printArgs.GraphicsContext.Hdc); + printArgs.GraphicsContext.Graphics = g; + } + + printPageArgs.GraphicsContext = printArgs.GraphicsContext; + PrintController.OnStartPage(this, printPageArgs); + // assign Graphics in printPageArgs + printPageArgs.SetGraphics(g); + + if (!printPageArgs.Cancel) + this.OnPrintPage(printPageArgs); + + PrintController.OnEndPage(this, printPageArgs); + if (printPageArgs.Cancel) + break; + } while (printPageArgs.HasMorePages); + + this.OnEndPrint(printArgs); + PrintController.OnEndPrint(this, printArgs); + } + + public override string ToString(){ + return "[PrintDocument " + this.DocumentName + "]"; + } + + // events + protected virtual void OnBeginPrint(PrintEventArgs e){ + //fire the event + if (BeginPrint != null) + BeginPrint(this, e); + } + + protected virtual void OnEndPrint(PrintEventArgs e){ + //fire the event + if (EndPrint != null) + EndPrint(this, e); + } + + protected virtual void OnPrintPage(PrintPageEventArgs e){ + //fire the event + if (PrintPage != null) + PrintPage(this, e); + } + + protected virtual void OnQueryPageSettings(QueryPageSettingsEventArgs e){ + //fire the event + if (QueryPageSettings != null) + QueryPageSettings(this, e); + } + + [SRDescription ("Raised when printing begins")] + public event PrintEventHandler BeginPrint; + + [SRDescription ("Raised when printing ends")] + public event PrintEventHandler EndPrint; + + [SRDescription ("Raised when printing of a new page begins")] + public event PrintPageEventHandler PrintPage; + + [SRDescription ("Raised before printing of a new page begins")] + public event QueryPageSettingsEventHandler QueryPageSettings; + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintEventArgs.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintEventArgs.cs new file mode 100644 index 00000000000..94a4491b469 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintEventArgs.cs @@ -0,0 +1,60 @@ +// +// System.Drawing.PrintEventArgs.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.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; +//NOTE: Complete! Aparently just a redifiniton of CancleEventArgs specific to Printing. +namespace System.Drawing.Printing +{ + /// <summary> + /// Summary description for PrintEventArgs. + /// </summary> + public class PrintEventArgs : System.ComponentModel.CancelEventArgs + { + private GraphicsPrinter graphics_context; +#if NET_2_0 + internal PrintAction action; +#endif + + public PrintEventArgs() + { + } +#if NET_2_0 + public PrintAction PrintAction { + get { return action; } + } +#endif + + internal GraphicsPrinter GraphicsContext { + get { return graphics_context; } + set { graphics_context = value; } + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintEventHandler.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintEventHandler.cs new file mode 100644 index 00000000000..2cff92bcff1 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintEventHandler.cs @@ -0,0 +1,40 @@ +// +// System.Drawing.PrintEventHandler.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.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; + +namespace System.Drawing.Printing +{ + /// <summary> + /// Summary description for PrintEventHandler. + /// </summary> + public delegate void PrintEventHandler(object sender, PrintEventArgs e); +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintPageEventArgs.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintPageEventArgs.cs new file mode 100644 index 00000000000..859d5e38bf0 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintPageEventArgs.cs @@ -0,0 +1,103 @@ +// +// System.Drawing.PrintPageEventArgs.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.com) +// Herve Poussineau (hpoussineau@fr.st) +// +// (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.Drawing; +namespace System.Drawing.Printing { + /// <summary> + /// Summary description for PrintPageEventArgs. + /// </summary> + public class PrintPageEventArgs : EventArgs { + bool cancel; + Graphics graphics; + bool hasmorePages; + Rectangle marginBounds; + Rectangle pageBounds; + PageSettings pageSettings; + GraphicsPrinter graphics_context; + + public PrintPageEventArgs(Graphics graphics, Rectangle marginBounds, + Rectangle pageBounds, PageSettings pageSettings) { + this.graphics = graphics; + this.marginBounds = marginBounds; + this.pageBounds = pageBounds; + this.pageSettings = pageSettings; + } + public bool Cancel { + get{ + return cancel; + } + set{ + cancel = value; + } + } + public Graphics Graphics { + get{ + return graphics; + } + } + public bool HasMorePages { + get{ + return hasmorePages; + } + set{ + hasmorePages = value; + } + } + public Rectangle MarginBounds { + get{ + return marginBounds; + } + } + public Rectangle PageBounds { + get{ + return pageBounds; + } + } + public PageSettings PageSettings { + get{ + return pageSettings; + } + } + + // used in PrintDocument.Print() + internal void SetGraphics(Graphics g) + { + graphics = g; + } + + internal GraphicsPrinter GraphicsContext { + get { return graphics_context; } + set { graphics_context = value; } + } +} +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintPageEventHandler.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintPageEventHandler.cs new file mode 100644 index 00000000000..e60998de74c --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintPageEventHandler.cs @@ -0,0 +1,40 @@ +//
+// System.Drawing.PrintPageEventHandler.cs
+//
+// Author:
+// Dennis Hayes (dennish@Raytek.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;
+
+namespace System.Drawing.Printing
+{
+ /// <summary>
+ /// Summary description for PrintPageEventHandler.
+ /// </summary>
+ public delegate void PrintPageEventHandler(object sender, PrintPageEventArgs e);
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintRange.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintRange.cs new file mode 100644 index 00000000000..a13e3eb9514 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintRange.cs @@ -0,0 +1,44 @@ +//
+// System.Drawing.PrintRange.cs
+//
+// (C) 2002 Ximian, Inc. http://www.ximian.com
+// Author: Dennis Hayes (dennish@raytek.com)
+//
+ +// +// 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;
+namespace System.Drawing.Printing
+{ +#if NET_2_0 + [Serializable] +#endif
+ public enum PrintRange {
+ AllPages = 0,
+ Selection = 1,
+ SomePages = 2, +#if NET_2_0 + CurrentPage = 0x400000 +#endif
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrinterResolution.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterResolution.cs new file mode 100644 index 00000000000..f6b20ecdba9 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterResolution.cs @@ -0,0 +1,106 @@ +//
+// System.Drawing.Printing.PrinterResolution.cs
+//
+// Author:
+// Dennis Hayes (dennish@Raytek.com) +// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+//
+// (C) 2002 Ximian, Inc +// (C) 2003 Andreas Nahr
+//
+ +// +// 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;
+
+namespace System.Drawing.Printing +{
+ +#if NET_2_0 + [Serializable] +#endif
+ public class PrinterResolution + {
+ private PrinterResolutionKind kind = PrinterResolutionKind.Custom;
+ private int x;
+ private int y; + +#if NET_2_0 + public PrinterResolution () + { + } +#else + private PrinterResolution () + { + } +#endif
+ + internal PrinterResolution (int x, int y, PrinterResolutionKind kind) + { + this.x = x; + this.y = y; + this.kind = kind; + } +
+ public int X {
+ get {
+ return x;
+ } +#if NET_2_0 + set { + x = value; + } +#endif
+ } +
+ public int Y {
+ get {
+ return y;
+ } +#if NET_2_0 + set { + y = value; + } +#endif
+ } +
+ public PrinterResolutionKind Kind {
+ get {
+ return kind;
+ } +#if NET_2_0 + set { + kind = value; + } +#endif
+ } + + public override string ToString () + { + if (kind != PrinterResolutionKind.Custom) + return "[PrinterResolution " + kind.ToString () + "]"; + + return "[PrinterResolution X=" + x + " Y=" + y + "]"; + }
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrinterResolutionKind.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterResolutionKind.cs new file mode 100644 index 00000000000..4b4b514f39f --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterResolutionKind.cs @@ -0,0 +1,43 @@ +//
+// System.Drawing.PrinterResolutionKind.cs
+//
+// (C) 2002 Ximian, Inc. http://www.ximian.com
+// Author: Dennis Hayes (dennish@raytek.com)
+//
+ +// +// 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;
+namespace System.Drawing.Printing
+{ +#if NET_2_0 + [Serializable] +#endif
+ public enum PrinterResolutionKind {
+ Custom = 0,
+ Draft = -1,
+ High = -4,
+ Low = -2,
+ Medium = -3
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrinterSettings.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterSettings.cs new file mode 100644 index 00000000000..d4deb296336 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterSettings.cs @@ -0,0 +1,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(); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrinterUnit.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterUnit.cs new file mode 100644 index 00000000000..ff9264c7bef --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterUnit.cs @@ -0,0 +1,39 @@ +//
+// System.Drawing.PrinterUnit.cs
+//
+// (C) 2002 Ximian, Inc. http://www.ximian.com
+// Author: Dennis Hayes (dennish@raytek.com)
+//
+ +// +// 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;
+namespace System.Drawing.Printing
+{
+ public enum PrinterUnit {
+ Display = 0,
+ HundredthsOfAMillimeter = 2,
+ TenthsOfAMillimeter = 3,
+ ThousandthsOfAnInch = 1
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrinterUnitConvert.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterUnitConvert.cs new file mode 100644 index 00000000000..00452060da0 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrinterUnitConvert.cs @@ -0,0 +1,139 @@ +// +// System.Drawing.Printing.PrinterUnitConvert.cs +// +// Authors: +// Martin Willemoes Hansen (mwh@sysrq.dk) +// Herve Poussineau (hpoussineau@fr.st) +// +// (C) 2003 Martin Willemoes Hansen +// + +// +// 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. +// + +namespace System.Drawing.Printing +{ + public sealed class PrinterUnitConvert + { + private PrinterUnitConvert () + { + } + + public static double Convert (double value, + PrinterUnit fromUnit, + PrinterUnit toUnit) + { + switch (fromUnit) + { + case PrinterUnit.Display: + switch (toUnit) + { + case PrinterUnit.Display: return value; + case PrinterUnit.ThousandthsOfAnInch: return value * 10; + case PrinterUnit.HundredthsOfAMillimeter: return value * 25.4; + case PrinterUnit.TenthsOfAMillimeter: return value * 2.54; + } + break; + case PrinterUnit.ThousandthsOfAnInch: + switch (toUnit) + { + case PrinterUnit.Display: return value / 10; + case PrinterUnit.ThousandthsOfAnInch: return value; + case PrinterUnit.HundredthsOfAMillimeter: return value * 2.54; + case PrinterUnit.TenthsOfAMillimeter: return value * 0.254; + } + break; + case PrinterUnit.HundredthsOfAMillimeter: + switch (toUnit) + { + case PrinterUnit.Display: return value / 25.4; + case PrinterUnit.ThousandthsOfAnInch: return value / 2.54; + case PrinterUnit.HundredthsOfAMillimeter: return value; + case PrinterUnit.TenthsOfAMillimeter: return value / 10; + } + break; + case PrinterUnit.TenthsOfAMillimeter: + switch (toUnit) + { + case PrinterUnit.Display: return value / 2.54; + case PrinterUnit.ThousandthsOfAnInch: return value / 0.254; + case PrinterUnit.HundredthsOfAMillimeter: return value * 10; + case PrinterUnit.TenthsOfAMillimeter: return value; + } + break; + } + // should never happen + throw new NotImplementedException(); + } + + public static int Convert (int value, + PrinterUnit fromUnit, + PrinterUnit toUnit) + { + double rslt; + rslt = Convert ((double) value, fromUnit, toUnit); + return (int) Math.Round (rslt); + + } + + public static Margins Convert (Margins value, + PrinterUnit fromUnit, + PrinterUnit toUnit) + { + return new Margins( + Convert(value.Left, fromUnit, toUnit), + Convert(value.Right, fromUnit, toUnit), + Convert(value.Top, fromUnit, toUnit), + Convert(value.Bottom, fromUnit, toUnit)); + } + + public static Point Convert (Point value, + PrinterUnit fromUnit, + PrinterUnit toUnit) + { + return new Point( + Convert(value.X, fromUnit, toUnit), + Convert(value.Y, fromUnit, toUnit)); + } + + public static Rectangle Convert (Rectangle value, + PrinterUnit fromUnit, + PrinterUnit toUnit) + { + return new Rectangle( + Convert(value.X, fromUnit, toUnit), + Convert(value.Y, fromUnit, toUnit), + Convert(value.Width, fromUnit, toUnit), + Convert(value.Height, fromUnit, toUnit)); + } + + public static Size Convert (Size value, + PrinterUnit fromUnit, + PrinterUnit toUnit) + { + return new Size( + Convert(value.Width, fromUnit, toUnit), + Convert(value.Height, fromUnit, toUnit)); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermission.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermission.cs new file mode 100644 index 00000000000..8aee6ce95cd --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermission.cs @@ -0,0 +1,259 @@ +// +// System.Drawing.PrintingPermission.cs +// +// Authors: +// Dennis Hayes (dennish@Raytek.com) +// Herve Poussineau (hpoussineau@fr.st) +// Sebastien Pouliot <sebastien@ximian.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.Globalization; +using System.Security; +using System.Security.Permissions; + +namespace System.Drawing.Printing { + + [Serializable] + public sealed class PrintingPermission : CodeAccessPermission, IUnrestrictedPermission { + + private const int version = 1; + + private PrintingPermissionLevel _Level; + + public PrintingPermission (PermissionState state) + { + if (CheckPermissionState (state, true) == PermissionState.Unrestricted) + _Level = PrintingPermissionLevel.AllPrinting; + else + _Level = PrintingPermissionLevel.NoPrinting; + } + + public PrintingPermission (PrintingPermissionLevel printingLevel) + { + Level = printingLevel; + } + + // properties + + public PrintingPermissionLevel Level{ + get { return _Level; } + set { + if (!Enum.IsDefined (typeof (PrintingPermissionLevel), value)) { + string msg = Locale.GetText ("Invalid enum {0}"); + throw new ArgumentException (String.Format (msg, value), "Level"); + } + _Level = value; + } + } + + // methods + + public override IPermission Copy () + { + return new PrintingPermission (this.Level); + } + + public override void FromXml (SecurityElement esd) + { + CheckSecurityElement (esd, "esd", version, version); + // Note: we do not (yet) care about the return value + // as we only accept version 1 (min/max values) + + if (IsUnrestricted (esd)) + _Level = PrintingPermissionLevel.AllPrinting; + else { + string level = esd.Attribute ("Level"); + if (level != null) { + _Level = (PrintingPermissionLevel) Enum.Parse ( + typeof (PrintingPermissionLevel), level); + } + else + _Level = PrintingPermissionLevel.NoPrinting; + } + } + + public override IPermission Intersect (IPermission target) + { + PrintingPermission pp = Cast (target); + if ((pp == null) || IsEmpty () || pp.IsEmpty ()) + return null; + + PrintingPermissionLevel level = (_Level <= pp.Level) ? _Level : pp.Level; + return new PrintingPermission (level); + } + + public override bool IsSubsetOf (IPermission target) + { + PrintingPermission pp = Cast (target); + if (pp == null) + return IsEmpty (); + + return (_Level <= pp.Level); + } + + public bool IsUnrestricted () + { + return (_Level == PrintingPermissionLevel.AllPrinting); + } + + public override SecurityElement ToXml () + { + SecurityElement se = Element (version); + if (IsUnrestricted ()) + se.AddAttribute ("Unrestricted", "true"); + else + se.AddAttribute ("Level", _Level.ToString ()); + return se; + } + + public override IPermission Union (IPermission target) + { + PrintingPermission pp = Cast (target); + if (pp == null) + return new PrintingPermission (_Level); + if (IsUnrestricted () || pp.IsUnrestricted ()) + return new PrintingPermission (PermissionState.Unrestricted); + if (IsEmpty () && pp.IsEmpty ()) + return null; + + PrintingPermissionLevel level = (_Level > pp.Level) ? _Level : pp.Level; + return new PrintingPermission (level); + } + + // Internal helpers methods + + private bool IsEmpty () + { + return (_Level == PrintingPermissionLevel.NoPrinting); + } + + private PrintingPermission Cast (IPermission target) + { + if (target == null) + return null; + + PrintingPermission pp = (target as PrintingPermission); + if (pp == null) { + ThrowInvalidPermission (target, typeof (PrintingPermission)); + } + + return pp; + } + + // NOTE: The following static methods should be moved out to a (static?) class + // if (ever) System.Drawing.dll gets more than one permission in it's assembly. + + // snippet moved from FileIOPermission (nickd) to be reused in all derived classes + internal SecurityElement Element (int version) + { + SecurityElement se = new SecurityElement ("IPermission"); + Type type = this.GetType (); + se.AddAttribute ("class", type.FullName + ", " + type.Assembly.ToString ().Replace ('\"', '\'')); + se.AddAttribute ("version", version.ToString ()); + return se; + } + + internal static PermissionState CheckPermissionState (PermissionState state, bool allowUnrestricted) + { + string msg; + switch (state) { + case PermissionState.None: + break; + case PermissionState.Unrestricted: + if (!allowUnrestricted) { + msg = Locale.GetText ("Unrestricted isn't not allowed for identity permissions."); + throw new ArgumentException (msg, "state"); + } + break; + default: + msg = String.Format (Locale.GetText ("Invalid enum {0}"), state); + throw new ArgumentException (msg, "state"); + } + return state; + } + + // logic isn't identical to CodeAccessPermission.CheckSecurityElement - see unit tests + internal static int CheckSecurityElement (SecurityElement se, string parameterName, int minimumVersion, int maximumVersion) + { + if (se == null) + throw new ArgumentNullException (parameterName); + + string c = se.Attribute ("class"); +#if NET_2_0 + if (c == null) { + string msg = Locale.GetText ("Missing 'class' attribute."); + throw new ArgumentException (msg, parameterName); + } +#else + if ((c == null) || (String.Compare (c, 0, "System.Drawing.Printing.PrintingPermission", 0, 42) != 0)) { + string msg = Locale.GetText ("Wrong 'class' attribute."); + throw new ArgumentException (msg, parameterName); + } +#endif + // we assume minimum version if no version number is supplied + int version = minimumVersion; + string v = se.Attribute ("version"); + if (v != null) { + try { + version = Int32.Parse (v); + } + catch (Exception e) { + string msg = Locale.GetText ("Couldn't parse version from '{0}'."); + msg = String.Format (msg, v); + throw new ArgumentException (msg, parameterName, e); + } + } +#if !NET_2_0 + else { + string msg = Locale.GetText ("Missing 'version' attribute."); + throw new ArgumentException (msg, parameterName); + } +#endif + + if ((version < minimumVersion) || (version > maximumVersion)) { + string msg = Locale.GetText ("Unknown version '{0}', expected versions between ['{1}','{2}']."); + msg = String.Format (msg, version, minimumVersion, maximumVersion); + throw new ArgumentException (msg, parameterName); + } + return version; + } + + // must be called after CheckSecurityElement (i.e. se != null) + internal static bool IsUnrestricted (SecurityElement se) + { + string value = se.Attribute ("Unrestricted"); + if (value == null) + return false; + return (String.Compare (value, Boolean.TrueString, true, CultureInfo.InvariantCulture) == 0); + } + + internal static void ThrowInvalidPermission (IPermission target, Type expected) + { + string msg = Locale.GetText ("Invalid permission type '{0}', expected type '{1}'."); + msg = String.Format (msg, target.GetType (), expected); + throw new ArgumentException (msg, "target"); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermissionAttribute.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermissionAttribute.cs new file mode 100644 index 00000000000..da6623c14eb --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermissionAttribute.cs @@ -0,0 +1,69 @@ +// +// System.Drawing.PrintingPermissionAttribute.cs +// +// Authors: +// Dennis Hayes (dennish@Raytek.com) +// Herve Poussineau (hpoussineau@fr.st) +// Sebastien Pouliot <sebastien@ximian.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.Security; +using System.Security.Permissions; + +namespace System.Drawing.Printing { + + [AttributeUsage (AttributeTargets.All, AllowMultiple=true)] + // strangely this class isn't [Serializable] like other permission classes + public sealed class PrintingPermissionAttribute : CodeAccessSecurityAttribute { + + private PrintingPermissionLevel _level; + + public PrintingPermissionAttribute (SecurityAction action) + : base (action) + { + // seems to always assign PrintingPermissionLevel.NoPrinting ... + _level = PrintingPermissionLevel.NoPrinting; + } + + public PrintingPermissionLevel Level { + get { return _level; } + set { + if (!Enum.IsDefined (typeof (PrintingPermissionLevel), value)) { + string msg = Locale.GetText ("Invalid enum {0}"); + throw new ArgumentException (String.Format (msg, value), "Level"); + } + _level = value; + } + } + + public override IPermission CreatePermission () + { + if (base.Unrestricted) + return new PrintingPermission (PermissionState.Unrestricted); + else + return new PrintingPermission (_level); + } + } +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermissionLevel.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermissionLevel.cs new file mode 100644 index 00000000000..16e3ad80f4b --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingPermissionLevel.cs @@ -0,0 +1,41 @@ +//
+// System.Drawing.PrintingPermissionLevel.cs
+//
+// Author: +// Dennis Hayes (dennish@raytek.com)
+// +// (C) 2002 Ximian, Inc. http://www.ximian.com
+// 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. +// + +namespace System.Drawing.Printing { + +#if NET_2_0 + [Serializable] +#endif
+ public enum PrintingPermissionLevel {
+ AllPrinting = 3,
+ DefaultPrinting = 2,
+ NoPrinting = 0,
+ SafePrinting = 1
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServices.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServices.cs new file mode 100644 index 00000000000..aac6dff9e84 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServices.cs @@ -0,0 +1,102 @@ +// +// Copyright (C) 2005 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. +// +// Author: +// +// Jordi Mas i Hernandez, jordimash@gmail.com +// + +using System.Runtime.InteropServices; +using System.Collections; +using System.Drawing.Printing; +using System.ComponentModel; +using System.Drawing.Imaging; + +namespace System.Drawing.Printing +{ + internal abstract class PrintingServices + { + // Properties + internal abstract PrinterSettings.StringCollection InstalledPrinters { get; } + internal abstract string DefaultPrinter { get; } + + + // Methods + internal abstract bool StartDoc (GraphicsPrinter gr, string doc_name, string output_file); + internal abstract IntPtr CreateGraphicsContext (PrinterSettings settings); + internal abstract bool StartPage (GraphicsPrinter gr); + internal abstract bool EndPage (GraphicsPrinter gr); + internal abstract bool EndDoc (GraphicsPrinter gr); + + internal abstract void LoadPrinterSettings (string printer, PrinterSettings settings); + internal abstract void LoadPrinterResolutions (string printer, PrinterSettings settings); + internal abstract void LoadPrinterPaperSizes (string printer, PrinterSettings settings); + + internal void LoadDefaultResolutions (PrinterSettings.PrinterResolutionCollection col) + { + col.Add (new PrinterResolution ((int) PrinterResolutionKind.High, -1, PrinterResolutionKind.High)); + col.Add (new PrinterResolution ((int) PrinterResolutionKind.Medium, -1, PrinterResolutionKind.Medium)); + col.Add (new PrinterResolution ((int) PrinterResolutionKind.Low, -1, PrinterResolutionKind.Low)); + col.Add (new PrinterResolution ((int) PrinterResolutionKind.Draft, -1, PrinterResolutionKind.Draft)); + } + } + + internal class SysPrn + { + static PrintingServices service; + + static SysPrn () + { + int platform = (int) Environment.OSVersion.Platform; + + if (platform == 4 || platform == 128) { + service = new PrintingServicesUnix (); + } else { + service = new PrintingServicesWin32 (); + } + } + + static internal PrintingServices Service { + get { return service; } + } + } + + internal class GraphicsPrinter + { + private Graphics graphics; + private IntPtr hDC; + + internal GraphicsPrinter (Graphics gr, IntPtr dc) + { + graphics = gr; + hDC = dc; + } + + internal Graphics Graphics { + get { return graphics; } + set { graphics = value; } + } + internal IntPtr Hdc { get { return hDC; }} + } +} + + diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs new file mode 100644 index 00000000000..ce4af5dc18d --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs @@ -0,0 +1,354 @@ +// +// Copyright (C) 2005 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. +// +// Author: +// +// Jordi Mas i Hernandez, jordimash@gmail.com +// + +using System.Runtime.InteropServices; +using System.Collections; +using System.Drawing.Printing; +using System.ComponentModel; +using System.Drawing.Imaging; +using System.Text; + +namespace System.Drawing.Printing +{ + internal class PrintingServicesUnix : PrintingServices + { + private Hashtable doc_info = new Hashtable (); + + internal PrintingServicesUnix () + { + + } + + // Methods + internal override void LoadPrinterSettings (string printer, PrinterSettings settings) + { + IntPtr ptr, ppd_handle; + string ppd_filename; + PPD_FILE ppd; + + ptr = cupsGetPPD (printer); + ppd_filename = Marshal.PtrToStringAnsi (ptr); + ppd_handle = ppdOpenFile (ppd_filename); + //Console.WriteLine ("File: {0}", ppd_filename); + + ppd = (PPD_FILE) Marshal.PtrToStructure (ppd_handle, typeof (PPD_FILE)); + settings.landscape_angle = ppd.landscape; + settings.supports_color = (ppd.color_device == 0) ? false : true; + ppdClose (ppd_handle); + } + + internal override void LoadPrinterResolutions (string printer, PrinterSettings settings) + { + settings.PrinterResolutions.Clear (); + LoadDefaultResolutions (settings.PrinterResolutions); + } + + internal override void LoadPrinterPaperSizes (string printer, PrinterSettings settings) + { + IntPtr ptr, ppd_handle; + string ppd_filename, real_name; + PPD_FILE ppd; + PPD_SIZE size; + PaperSize ps; + PaperKind kind = PaperKind.Custom; + + settings.PaperSizes.Clear (); + + ptr = cupsGetPPD (printer); + ppd_filename = Marshal.PtrToStringAnsi (ptr); + ppd_handle = ppdOpenFile (ppd_filename); + + ppd = (PPD_FILE) Marshal.PtrToStructure (ppd_handle, typeof (PPD_FILE)); + ptr = ppd.sizes; + float w, h; + for (int i = 0; i < ppd.num_sizes; i++) { + size = (PPD_SIZE) Marshal.PtrToStructure (ptr, typeof (PPD_SIZE)); + real_name = GetPaperSizeName (ppd, size.name); + ptr = new IntPtr (ptr.ToInt64 () + Marshal.SizeOf (size)); + + w = size.width * 100 / 72; + h = size.length * 100 / 72; + ps = new PaperSize (real_name, (int) w, (int) h); + // TODO: Convert from name to paper kind enum + ps.SetKind (kind); + settings.PaperSizes.Add (ps); + } + + ppdClose (ppd_handle); + } + + internal override bool StartPage (GraphicsPrinter gr) + { + return true; + } + + internal override bool EndPage (GraphicsPrinter gr) + { + GdipGetPostScriptSavePage (gr.Hdc); + return true; + } + + internal override bool EndDoc (GraphicsPrinter gr) + { + DOCINFO doc = (DOCINFO) doc_info[gr.Hdc]; + + gr.Graphics.Dispose (); // Dispose object to force surface finish + cupsPrintFile (doc.settings.PrinterName, doc.filename, doc.title, 0, IntPtr.Zero); + doc_info.Remove (gr.Hdc); + //TODO: Delete temporary file created + return true; + } + + internal override bool StartDoc (GraphicsPrinter gr, string doc_name, string output_file) + { + DOCINFO doc = (DOCINFO) doc_info[gr.Hdc]; + doc.title = doc_name; + return true; + } + + internal override IntPtr CreateGraphicsContext (PrinterSettings settings) + { + IntPtr graphics = IntPtr.Zero; + StringBuilder name = new StringBuilder (1024); + int length = name.Capacity; + cupsTempFile (name, length); + + GdipGetPostScriptGraphicsContext (name.ToString(), + settings.DefaultPageSettings.PaperSize.Width / 100 * 72, + settings.DefaultPageSettings.PaperSize.Height / 100 * 72, + // Harcoded dpy's + 300, 300, ref graphics); + + DOCINFO doc = new DOCINFO (); + doc.filename = name.ToString(); + doc.settings = settings; + doc_info.Add (graphics, doc); + + return graphics; + } + + // Properties + + internal override PrinterSettings.StringCollection InstalledPrinters { + get { + int n_printers; + IntPtr printers = IntPtr.Zero, ptr_printers, ptr_printer; + string str; + PrinterSettings.StringCollection col = new PrinterSettings.StringCollection (new string[] {}); + + n_printers = cupsGetPrinters (ref printers); + + ptr_printers = printers; + for (int i = 0; i < n_printers; i++) { + ptr_printer = (IntPtr) Marshal.ReadInt32 (ptr_printers); + str = Marshal.PtrToStringAnsi (ptr_printer); + ptr_printers = new IntPtr (ptr_printers.ToInt64 () + 4); + col.Add (str); + } + Marshal.FreeHGlobal (printers); + return col; + } + } + + internal override string DefaultPrinter { + get { + IntPtr str; + str = cupsGetDefault (); + return Marshal.PtrToStringAnsi (str); + } + } + + // Private functions + + private string GetPaperSizeName (PPD_FILE ppd, string name) + { + string rslt = name; + PPD_GROUP group; + PPD_OPTION option; + PPD_CHOICE choice; + IntPtr ptr, ptr_opt, ptr_choice; + + ptr = ppd.groups; + for (int i = 0; i < ppd.num_groups; i++) { + group = (PPD_GROUP) Marshal.PtrToStructure (ptr, typeof (PPD_GROUP)); + //Console.WriteLine ("Size text:{0} name:{1} opts {2}", group.text, group.name, group.num_options); + ptr = new IntPtr (ptr.ToInt64 () + Marshal.SizeOf (group)); + + ptr_opt = group.options; + for (int n = 0; n < group.num_options; n++) { + option = (PPD_OPTION) Marshal.PtrToStructure (ptr_opt, typeof (PPD_OPTION)); + ptr_opt = new IntPtr (ptr_opt.ToInt64 () + Marshal.SizeOf (option)); + //Console.WriteLine (" key:{0} def:{1} text: {2}", option.keyword, option.defchoice, option.text); + + if (!option.keyword.Equals ("PageSize")) + continue; + + ptr_choice = option.choices; + for (int c = 0; c < option.num_choices; c++) { + choice = (PPD_CHOICE) Marshal.PtrToStructure (ptr_choice, typeof (PPD_CHOICE)); + ptr_choice = new IntPtr (ptr_choice.ToInt64 () + Marshal.SizeOf (choice)); + //Console.WriteLine (" choice:{0} - text: {1}", choice.choice, choice.text); + if (name.Equals (choice.choice)) { + rslt = choice.text; + break; + } + } + } + } + + return rslt; + } + + + // + // DllImports + // + + [DllImport("libcups", CharSet=CharSet.Ansi)] + static extern int cupsGetPrinters (ref IntPtr printers); + + [DllImport("libcups", CharSet=CharSet.Ansi)] + static extern IntPtr cupsTempFile (StringBuilder sb, int len); + + [DllImport("libcups", CharSet=CharSet.Ansi)] + static extern IntPtr cupsGetDefault (); + + [DllImport("libcups", CharSet=CharSet.Ansi)] + static extern int cupsPrintFile (string printer, string filename, string title, int num_options, IntPtr options); + + [DllImport("libcups", CharSet=CharSet.Ansi)] + static extern IntPtr cupsGetPPD (string printer); + + [DllImport("libcups", CharSet=CharSet.Ansi)] + static extern IntPtr ppdOpenFile (string filename); + + [DllImport("libcups")] + static extern void ppdClose (IntPtr ppd); + + [DllImport("libgdiplus", CharSet=CharSet.Ansi)] + static extern int GdipGetPostScriptGraphicsContext (string filename, int with, int height, double dpix, double dpiy, ref IntPtr graphics); + + [DllImport("libgdiplus")] + static extern int GdipGetPostScriptSavePage (IntPtr graphics); + + + //Struct + public struct DOCINFO + { + public PrinterSettings settings; + public string title; + public string filename; + } + + public struct PPD_SIZE + { + public int marked; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=42)] + public string name; + public float width; + public float length; + public float left; + public float bottom; + public float right; + public float top; + } + + public struct PPD_GROUP + { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=40)] + public string text; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=42)] + public string name; + public int num_options; + public IntPtr options; + public int num_subgroups; + public IntPtr subgrups; + } + + public struct PPD_OPTION + { + public byte conflicted; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=41)] + public string keyword; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=41)] + public string defchoice; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=81)] + public string text; + public int ui; + public int section; + public float order; + public int num_choices; + public IntPtr choices; + } + + public struct PPD_CHOICE + { + public byte marked; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=41)] + public string choice; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=81)] + public string text; + public IntPtr code; + public IntPtr option; + } + + public struct PPD_FILE + { + public int language_level; + public int color_device; + public int variable_sizes; + public int accurate_screens; + public int contone_only; + public int landscape; + public int model_number; + public int manual_copies; + public int throughput; + public int colorspace; + public IntPtr patches; + public int num_emulations; + public IntPtr emulations; + public IntPtr jcl_begin; + public IntPtr jcl_ps; + public IntPtr jcl_end; + public IntPtr lang_encoding; + public IntPtr lang_version; + public IntPtr modelname; + public IntPtr ttrasterizer; + public IntPtr manufacturer; + public IntPtr product; + public IntPtr nickname; + public IntPtr shortnickname; + public int num_groups; + public IntPtr groups; + public int num_sizes; + public IntPtr sizes; + + /* There is more data after this that we are not using*/ + } + } +} + diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesWin32.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesWin32.cs new file mode 100644 index 00000000000..52f7ef55b91 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesWin32.cs @@ -0,0 +1,339 @@ +// +// Copyright (C) 2005 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. +// +// Author: +// +// Jordi Mas i Hernandez, jordimash@gmail.com +// + +using System.Runtime.InteropServices; +using System.Collections; +using System.Drawing.Printing; +using System.ComponentModel; +using System.Text; + +namespace System.Drawing.Printing +{ + internal class PrintingServicesWin32 : PrintingServices + { + internal PrintingServicesWin32 () + { + + } + + internal override void LoadPrinterSettings (string printer, PrinterSettings settings) + { + int ret; + + settings.maximum_copies = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_COPIES, IntPtr.Zero, IntPtr.Zero); + + ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_DUPLEX, IntPtr.Zero, IntPtr.Zero); + settings.can_duplex = (ret == 1) ? true : false; + + ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_COLORDEVICE, IntPtr.Zero, IntPtr.Zero); + settings.supports_color = (ret == 1) ? true : false; + + ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_ORIENTATION, IntPtr.Zero, IntPtr.Zero); + if (ret != -1) + settings.landscape_angle = ret; + } + + internal override void LoadPrinterResolutions (string printer, PrinterSettings settings) + { + int ret; + IntPtr ptr, buff = IntPtr.Zero; + + settings.PrinterResolutions.Clear (); + LoadDefaultResolutions (settings.PrinterResolutions); + ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_ENUMRESOLUTIONS, IntPtr.Zero, IntPtr.Zero); + + if (ret == -1) + return; + + ptr = buff = Marshal.AllocHGlobal (ret * 2 * Marshal.SizeOf (buff)); + ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_ENUMRESOLUTIONS, buff, IntPtr.Zero); + int x, y; + if (ret != -1) { + for (int i = 0; i < ret; i++) { + x = Marshal.ReadInt32 (ptr); + ptr = new IntPtr (ptr.ToInt64 () + Marshal.SizeOf (x)); + y = Marshal.ReadInt32 (ptr); + ptr = new IntPtr (ptr.ToInt64 () + Marshal.SizeOf (y)); + settings.PrinterResolutions.Add (new PrinterResolution + (x,y, PrinterResolutionKind.Custom)); + } + } + Marshal.FreeHGlobal (buff); + } + + internal override void LoadPrinterPaperSizes (string printer, PrinterSettings settings) + { + int items, ret; + IntPtr ptr_names, buff_names = IntPtr.Zero; + IntPtr ptr_sizes, buff_sizes = IntPtr.Zero; + IntPtr ptr_sizes_enum, buff_sizes_enum = IntPtr.Zero; + string name; + + settings.PaperSizes.Clear (); + items = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERSIZE, IntPtr.Zero, IntPtr.Zero); + + if (items == -1) + return; + + ptr_sizes = buff_sizes = Marshal.AllocHGlobal (items * 2 * 4); + ptr_names = buff_names = Marshal.AllocHGlobal (items * 64 * 2); + ptr_sizes_enum = buff_sizes_enum = Marshal.AllocHGlobal (items * 2); + ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERSIZE, buff_sizes, IntPtr.Zero); + + if (ret == -1) + return; + + ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERS, buff_sizes_enum, IntPtr.Zero); + ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERNAMES, buff_names, IntPtr.Zero); + + int x, y; + PaperSize ps; + PaperKind kind; + for (int i = 0; i < ret; i++) { + x = Marshal.ReadInt32 (ptr_sizes); + ptr_sizes = new IntPtr (ptr_sizes.ToInt64 () + 4); + y = Marshal.ReadInt32 (ptr_sizes); + ptr_sizes = new IntPtr (ptr_sizes.ToInt64 () + 4); + + x = PrinterUnitConvert.Convert (x, PrinterUnit.TenthsOfAMillimeter, + PrinterUnit.Display); + + y = PrinterUnitConvert.Convert (y, PrinterUnit.TenthsOfAMillimeter, + PrinterUnit.Display); + + name = Marshal.PtrToStringUni (ptr_names); + ptr_names = new IntPtr (ptr_names.ToInt64 () + 64 * 2); + + kind = (PaperKind) Marshal.ReadInt16 (ptr_sizes_enum); + ptr_sizes_enum = new IntPtr (ptr_sizes_enum.ToInt64 () + 2); + + ps = new PaperSize (name, x,y); + ps.SetKind (kind); + settings.PaperSizes.Add (ps); + } + Marshal.FreeHGlobal (buff_names); + Marshal.FreeHGlobal (buff_sizes); + Marshal.FreeHGlobal (buff_sizes_enum); + } + + internal override bool StartDoc (GraphicsPrinter gr, string doc_name, string output_file) + { + DOCINFO di = new DOCINFO (); + int ret; + + di.cbSize = Marshal.SizeOf (di); + di.lpszDocName = Marshal.StringToHGlobalUni (doc_name); + di.lpszOutput = IntPtr.Zero; + di.lpszDatatype = IntPtr.Zero; + di.fwType = 0; + + ret = Win32StartDoc (gr.Hdc, ref di); + Marshal.FreeHGlobal (di.lpszDocName); + return (ret > 0) ? true : false; + } + + internal override bool StartPage (GraphicsPrinter gr) + { + int ret = Win32StartPage (gr.Hdc); + return (ret > 0) ? true : false; + } + + internal override bool EndPage (GraphicsPrinter gr) + { + int ret = Win32EndPage (gr.Hdc); + return (ret > 0) ? true : false; + } + + internal override bool EndDoc (GraphicsPrinter gr) + { + int ret = Win32EndDoc (gr.Hdc); + Win32DeleteDC (gr.Hdc); + gr.Graphics.Dispose (); + return (ret > 0) ? true : false; + } + + internal override IntPtr CreateGraphicsContext (PrinterSettings settings) + { + IntPtr dc = IntPtr.Zero; + dc = Win32CreateDC (null, settings.PrinterName, null, IntPtr.Zero /* DEVMODE */); + return dc; + } + + // Properties + internal override string DefaultPrinter { + get { + StringBuilder name = new StringBuilder (1024); + int length = name.Capacity; + + Win32GetDefaultPrinter (name, ref length); + return name.ToString (); + } + } + + internal override PrinterSettings.StringCollection InstalledPrinters { + get { + PrinterSettings.StringCollection col = new PrinterSettings.StringCollection (new string[] {}); + PRINTER_INFO printer_info; + uint cbNeeded = 0, printers = 0; + IntPtr ptr, buff; + string s; + + // Determine space need it + Win32EnumPrinters (2 /* PRINTER_ENUM_LOCAL */, + null, 2, IntPtr.Zero, 0, ref cbNeeded, ref printers); + + ptr = buff = Marshal.AllocHGlobal ((int) cbNeeded); + + // Give us the printer list + Win32EnumPrinters (2 /* PRINTER_ENUM_LOCAL */, + null, 2, buff, (uint)cbNeeded, ref cbNeeded, ref printers); + + for (int i = 0; i < printers; i++) { + printer_info = (PRINTER_INFO) Marshal.PtrToStructure (ptr, typeof (PRINTER_INFO)); + s = Marshal.PtrToStringUni (printer_info.pPrinterName); + col.Add (s); + ptr = new IntPtr (ptr.ToInt64 () + Marshal.SizeOf (printer_info)); + } + + Marshal.FreeHGlobal (buff); + return col; + } + } + + // + // DllImports + // + + [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="DeviceCapabilities", SetLastError=true)]
+ static extern int Win32DeviceCapabilities (string device, string port, DCCapabilities cap, IntPtr outputBuffer, IntPtr deviceMode); + + [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="EnumPrinters", SetLastError=true)] + static extern int Win32EnumPrinters (int Flags, string Name, uint Level, IntPtr pPrinterEnum, uint cbBuf, + ref uint pcbNeeded, ref uint pcReturned); + + [DllImport("winspool.drv", EntryPoint="GetDefaultPrinter", CharSet=CharSet.Unicode, SetLastError=true)] + private static extern int Win32GetDefaultPrinter (StringBuilder buffer, ref int bufferSize); + + [DllImport("gdi32.dll", EntryPoint="CreateDC")] + static extern IntPtr Win32CreateDC (string lpszDriver, string lpszDevice, + string lpszOutput, IntPtr lpInitData); + + [DllImport("gdi32.dll", CharSet=CharSet.Unicode, EntryPoint="StartDoc")] + static extern int Win32StartDoc (IntPtr hdc, [In] ref DOCINFO lpdi); + + [DllImport("gdi32.dll", EntryPoint="StartPage")] + static extern int Win32StartPage (IntPtr hDC); + + [DllImport("gdi32.dll", EntryPoint="EndPage")] + static extern int Win32EndPage (IntPtr hdc); + + [DllImport("gdi32.dll", EntryPoint="EndDoc")] + static extern int Win32EndDoc (IntPtr hdc); + + [DllImport("gdi32.dll", EntryPoint="DeleteDC")] + public static extern IntPtr Win32DeleteDC (IntPtr hDc); + + // + // Structs + // + [StructLayout (LayoutKind.Sequential)] + internal struct PRINTER_INFO + { + public IntPtr pServerName; + public IntPtr pPrinterName; + public IntPtr pShareName; + public IntPtr pPortName; + public IntPtr pDriverName; + public IntPtr pComment; + public IntPtr pLocation; + public IntPtr pDevMode; + public IntPtr pSepFile; + public IntPtr pPrintProcessor; + public IntPtr pDatatype; + public IntPtr pParameters; + public IntPtr pSecurityDescriptor; + public uint Attributes; + public uint Priority; + public uint DefaultPriority; + public uint StartTime; + public uint UntilTime; + public uint Status; + public uint cJobs; + public uint AveragePPM; + } + + [StructLayout (LayoutKind.Sequential)] + internal struct DOCINFO + { + public int cbSize; + public IntPtr lpszDocName; + public IntPtr lpszOutput; + public IntPtr lpszDatatype; + public int fwType; + } + + // Enums + internal enum DCCapabilities : short
+ {
+ DC_FIELDS = 1,
+ DC_PAPERS = 2,
+ DC_PAPERSIZE = 3,
+ DC_MINEXTENT = 4,
+ DC_MAXEXTENT = 5,
+ DC_BINS = 6,
+ DC_DUPLEX = 7,
+ DC_SIZE = 8,
+ DC_EXTRA = 9,
+ DC_VERSION = 10,
+ DC_DRIVER = 11,
+ DC_BINNAMES = 12,
+ DC_ENUMRESOLUTIONS = 13,
+ DC_FILEDEPENDENCIES = 14,
+ DC_TRUETYPE = 15,
+ DC_PAPERNAMES = 16,
+ DC_ORIENTATION = 17,
+ DC_COPIES = 18,
+ DC_BINADJUST = 19,
+ DC_EMF_COMPLIANT = 20,
+ DC_DATATYPE_PRODUCED = 21,
+ DC_COLLATE = 22,
+ DC_MANUFACTURER = 23,
+ DC_MODEL = 24,
+ DC_PERSONALITY = 25,
+ DC_PRINTRATE = 26,
+ DC_PRINTRATEUNIT = 27,
+ DC_PRINTERMEM = 28,
+ DC_MEDIAREADY = 29,
+ DC_STAPLE = 30,
+ DC_PRINTRATEPPM = 31,
+ DC_COLORDEVICE = 32,
+ DC_NUP = 33
+ } + } +} + + diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/QueryPageSettingsEventArgs.cs b/mcs/class/System.Drawing/System.Drawing.Printing/QueryPageSettingsEventArgs.cs new file mode 100644 index 00000000000..2e9215076e5 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/QueryPageSettingsEventArgs.cs @@ -0,0 +1,57 @@ +//
+// System.Drawing.QueryPageSettingsEventArgs.cs
+//
+// Author:
+// Dennis Hayes (dennish@Raytek.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;
+
+namespace System.Drawing.Printing
+{
+ /// <summary>
+ /// Summary description for QueryPageSettingEventArgs.
+ /// </summary>
+ public class QueryPageSettingsEventArgs : PrintEventArgs
+ {
+ private PageSettings pageSettings;
+
+ public QueryPageSettingsEventArgs(PageSettings pageSettings)
+ {
+ this.pageSettings = pageSettings;
+ }
+ public PageSettings PageSettings {
+ get{
+ return pageSettings;
+ }
+ set{
+ pageSettings = value;
+ }
+ }
+
+ }
+}
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/QueryPageSettingsEventHandler.cs b/mcs/class/System.Drawing/System.Drawing.Printing/QueryPageSettingsEventHandler.cs new file mode 100644 index 00000000000..373eeb85ff4 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/QueryPageSettingsEventHandler.cs @@ -0,0 +1,40 @@ +// +// System.Drawing.QueryPageSettingsEventHandler.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.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; + +namespace System.Drawing.Printing +{ + /// <summary> + /// Summary description for QueryPageSettingsEventHandler. + /// </summary> + public delegate void QueryPageSettingsEventHandler(object sender, QueryPageSettingsEventArgs e); +} diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/StandardPrintController.cs b/mcs/class/System.Drawing/System.Drawing.Printing/StandardPrintController.cs new file mode 100644 index 00000000000..0e1e533b072 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing.Printing/StandardPrintController.cs @@ -0,0 +1,68 @@ +// +// System.Drawing.StandardPrintController.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.com) +// Herve Poussineau (hpoussineau@fr.st) +// Jordi Mas i Hernandez (jordimash@gmail.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; + +namespace System.Drawing.Printing +{ + public class StandardPrintController : PrintController + { + public StandardPrintController() + { + } + + public override void OnEndPage (PrintDocument document, PrintPageEventArgs e) + { + SysPrn.Service.EndPage (e.GraphicsContext); + } + + public override void OnStartPrint (PrintDocument document, PrintEventArgs e) + { + IntPtr dc = SysPrn.Service.CreateGraphicsContext (document.PrinterSettings); + e.GraphicsContext = new GraphicsPrinter (null, dc); + SysPrn.Service.StartDoc (e.GraphicsContext, document.DocumentName, string.Empty); + } + + public override void OnEndPrint (PrintDocument document, PrintEventArgs e) + { + SysPrn.Service.EndDoc (e.GraphicsContext); + } + + public override Graphics OnStartPage (PrintDocument document, PrintPageEventArgs e) + { + SysPrn.Service.StartPage (e.GraphicsContext); + return e.Graphics; + } + } +} |