HtmlImage.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // System.Web.UI.HtmlControls.HtmlImage.cs
  3. //
  4. // Author:
  5. // Dick Porter <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.ComponentModel;
  29. using System.Globalization;
  30. namespace System.Web.UI.HtmlControls
  31. {
  32. [ControlBuilder (typeof (HtmlControlBuilder))]
  33. public class HtmlImage : HtmlControl
  34. {
  35. public HtmlImage () : base ("img")
  36. {
  37. }
  38. [DefaultValue ("")]
  39. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  40. public string Align
  41. {
  42. get {
  43. string align = Attributes["align"];
  44. if (align == null) {
  45. return (String.Empty);
  46. }
  47. return (align);
  48. }
  49. set {
  50. /* Validate: left, center, right, top,
  51. * middle, bottom?
  52. */
  53. if (value == null) {
  54. Attributes.Remove ("align");
  55. } else {
  56. Attributes["align"] = value;
  57. }
  58. }
  59. }
  60. [DefaultValue ("")]
  61. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  62. public string Alt
  63. {
  64. get {
  65. string alt = Attributes["alt"];
  66. if (alt == null) {
  67. return (String.Empty);
  68. }
  69. return (alt);
  70. }
  71. set {
  72. if (value == null) {
  73. Attributes.Remove ("alt");
  74. } else {
  75. Attributes["alt"] = value;
  76. }
  77. }
  78. }
  79. [DefaultValue (0)]
  80. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  81. public int Border
  82. {
  83. get {
  84. string border = Attributes["border"];
  85. if (border == null) {
  86. return (-1);
  87. } else {
  88. return (Int32.Parse (border, CultureInfo.InvariantCulture));
  89. }
  90. }
  91. set {
  92. if (value == -1) {
  93. Attributes.Remove ("border");
  94. } else {
  95. Attributes["border"] = value.ToString ();
  96. }
  97. }
  98. }
  99. [DefaultValue (100)]
  100. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  101. public int Height
  102. {
  103. get {
  104. string height = Attributes["height"];
  105. if (height == null) {
  106. return (-1);
  107. } else {
  108. return (Int32.Parse (height, CultureInfo.InvariantCulture));
  109. }
  110. }
  111. set {
  112. if (value == -1) {
  113. Attributes.Remove ("height");
  114. } else {
  115. Attributes["height"] = value.ToString ();
  116. }
  117. }
  118. }
  119. [DefaultValue ("")]
  120. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  121. public string Src
  122. {
  123. get {
  124. string src = Attributes["src"];
  125. if (src == null) {
  126. return (String.Empty);
  127. }
  128. return (src);
  129. }
  130. set {
  131. if (value == null) {
  132. Attributes.Remove ("src");
  133. } else {
  134. Attributes["src"] = value;
  135. }
  136. }
  137. }
  138. [DefaultValue (100)]
  139. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  140. public int Width
  141. {
  142. get {
  143. string width = Attributes["width"];
  144. if (width == null) {
  145. return (-1);
  146. }
  147. else {
  148. return (Int32.Parse (width, CultureInfo.InvariantCulture));
  149. }
  150. }
  151. set {
  152. if (value == -1) {
  153. Attributes.Remove ("width");
  154. } else {
  155. Attributes["width"] = value.ToString ();
  156. }
  157. }
  158. }
  159. protected override void RenderAttributes (HtmlTextWriter w)
  160. {
  161. PreProcessRelativeReference (w, "src");
  162. base.RenderAttributes (w);
  163. /* MS closes the HTML element at the end of
  164. * the attributes too, according to the nunit
  165. * tests
  166. */
  167. w.Write (" /");
  168. }
  169. }
  170. }