PageSettings.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // System.Drawing.PageSettings.cs
  3. //
  4. // Authors:
  5. // Dennis Hayes ([email protected])
  6. // Herve Poussineau ([email protected])
  7. // Andreas Nahr ([email protected])
  8. //
  9. // (C) 2002 Ximian, Inc
  10. //
  11. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System;
  34. using System.Runtime.InteropServices;
  35. namespace System.Drawing.Printing
  36. {
  37. [ComVisible (false)]
  38. public class PageSettings : ICloneable
  39. {
  40. bool _Color;
  41. bool _Landscape;
  42. // create a new default Margins object (is 1 inch for all margins)
  43. Margins _Margins = new Margins();
  44. PaperSize _PaperSize;
  45. PaperSource _PaperSource;
  46. PrinterResolution _PrinterResolution;
  47. PrinterSettings _PrinterSettings;
  48. public PageSettings() : this(new PrinterSettings())
  49. {
  50. }
  51. public PageSettings(PrinterSettings printerSettings)
  52. {
  53. PrinterSettings = printerSettings;
  54. Color = printerSettings.DefaultPageSettings.Color;
  55. Landscape = printerSettings.DefaultPageSettings.Landscape;
  56. PaperSize = printerSettings.DefaultPageSettings.PaperSize;
  57. PaperSource = printerSettings.DefaultPageSettings.PaperSource;
  58. PrinterResolution = printerSettings.DefaultPageSettings.PrinterResolution;
  59. }
  60. // used by PrinterSettings.DefaultPageSettings
  61. internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
  62. {
  63. PrinterSettings = printerSettings;
  64. Color = color;
  65. Landscape = landscape;
  66. PaperSize = paperSize;
  67. PaperSource = paperSource;
  68. PrinterResolution = printerResolution;
  69. }
  70. //props
  71. public Rectangle Bounds{
  72. get{
  73. int width = this.PaperSize.Width;
  74. int height = this.PaperSize.Height;
  75. width -= this.Margins.Left + this.Margins.Right;
  76. height -= this.Margins.Top + this.Margins.Bottom;
  77. if (this.Landscape) {
  78. // swap width and height
  79. int tmp = width;
  80. width = height;
  81. height = tmp;
  82. }
  83. return new Rectangle(0, 0, width, height);
  84. }
  85. }
  86. public bool Color{
  87. get{
  88. return _Color;
  89. }
  90. set{
  91. _Color = value;
  92. }
  93. }
  94. public bool Landscape {
  95. get{
  96. return _Landscape;
  97. }
  98. set{
  99. _Landscape = value;
  100. }
  101. }
  102. public Margins Margins{
  103. get{
  104. return _Margins;
  105. }
  106. set{
  107. _Margins = value;
  108. }
  109. }
  110. public PaperSize PaperSize{
  111. get{
  112. return _PaperSize;
  113. }
  114. set{
  115. _PaperSize = value;
  116. }
  117. }
  118. public PaperSource PaperSource{
  119. get{
  120. return _PaperSource;
  121. }
  122. set{
  123. _PaperSource = value;
  124. }
  125. }
  126. public PrinterResolution PrinterResolution{
  127. get{
  128. return _PrinterResolution;
  129. }
  130. set{
  131. _PrinterResolution = value;
  132. }
  133. }
  134. public PrinterSettings PrinterSettings{
  135. get{
  136. return _PrinterSettings;
  137. }
  138. set{
  139. _PrinterSettings = value;
  140. }
  141. }
  142. public object Clone(){
  143. return new PageSettings(this.PrinterSettings);
  144. }
  145. [MonoTODO("PageSettings.CopyToHdevmode")]
  146. public void CopyToHdevmode (IntPtr hdevmode){
  147. throw new NotImplementedException ();
  148. }
  149. [MonoTODO("PageSettings.SetHdevmode")]
  150. public void SetHdevmode (IntPtr hdevmode){
  151. throw new NotImplementedException ();
  152. }
  153. public override string ToString(){
  154. string ret = "[PageSettings: Color={0}";
  155. ret += ", Landscape={1}";
  156. ret += ", Margins={2}";
  157. ret += ", PaperSize={3}";
  158. ret += ", PaperSource={4}";
  159. ret += ", PrinterResolution={5}";
  160. ret += "]";
  161. return String.Format(ret, this.Color, this.Landscape, this.Margins, this.PaperSize, this.PaperSource, this.PrinterResolution);
  162. }
  163. }
  164. }