2
0

HtmlImage.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #if NET_2_0
  33. [ControlBuilder (typeof (HtmlEmptyTagControlBuilder))]
  34. #else
  35. [ControlBuilder (typeof (HtmlControlBuilder))]
  36. #endif
  37. public class HtmlImage : HtmlControl
  38. {
  39. public HtmlImage () : base ("img")
  40. {
  41. }
  42. [DefaultValue ("")]
  43. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  44. public string Align
  45. {
  46. get {
  47. string align = Attributes["align"];
  48. if (align == null) {
  49. return (String.Empty);
  50. }
  51. return (align);
  52. }
  53. set {
  54. /* Validate: left, center, right, top,
  55. * middle, bottom?
  56. */
  57. if (value == null) {
  58. Attributes.Remove ("align");
  59. } else {
  60. Attributes["align"] = value;
  61. }
  62. }
  63. }
  64. [DefaultValue ("")]
  65. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  66. #if NET_2_0
  67. [Localizable (true)]
  68. #endif
  69. public string Alt
  70. {
  71. get {
  72. string alt = Attributes["alt"];
  73. if (alt == null) {
  74. return (String.Empty);
  75. }
  76. return (alt);
  77. }
  78. set {
  79. if (value == null) {
  80. Attributes.Remove ("alt");
  81. } else {
  82. Attributes["alt"] = value;
  83. }
  84. }
  85. }
  86. [DefaultValue (0)]
  87. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  88. public int Border
  89. {
  90. get {
  91. string border = Attributes["border"];
  92. if (border == null) {
  93. return (-1);
  94. } else {
  95. return (Int32.Parse (border, CultureInfo.InvariantCulture));
  96. }
  97. }
  98. set {
  99. if (value == -1) {
  100. Attributes.Remove ("border");
  101. } else {
  102. Attributes["border"] = value.ToString ();
  103. }
  104. }
  105. }
  106. [DefaultValue (100)]
  107. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  108. public int Height
  109. {
  110. get {
  111. string height = Attributes["height"];
  112. if (height == null) {
  113. return (-1);
  114. } else {
  115. return (Int32.Parse (height, CultureInfo.InvariantCulture));
  116. }
  117. }
  118. set {
  119. if (value == -1) {
  120. Attributes.Remove ("height");
  121. } else {
  122. Attributes["height"] = value.ToString ();
  123. }
  124. }
  125. }
  126. [DefaultValue ("")]
  127. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  128. public string Src
  129. {
  130. get {
  131. string src = Attributes["src"];
  132. if (src == null) {
  133. return (String.Empty);
  134. }
  135. return (src);
  136. }
  137. set {
  138. if (value == null) {
  139. Attributes.Remove ("src");
  140. } else {
  141. Attributes["src"] = value;
  142. }
  143. }
  144. }
  145. [DefaultValue (100)]
  146. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  147. public int Width
  148. {
  149. get {
  150. string width = Attributes["width"];
  151. if (width == null) {
  152. return (-1);
  153. }
  154. else {
  155. return (Int32.Parse (width, CultureInfo.InvariantCulture));
  156. }
  157. }
  158. set {
  159. if (value == -1) {
  160. Attributes.Remove ("width");
  161. } else {
  162. Attributes["width"] = value.ToString ();
  163. }
  164. }
  165. }
  166. protected override void RenderAttributes (HtmlTextWriter w)
  167. {
  168. PreProcessRelativeReference (w, "src");
  169. base.RenderAttributes (w);
  170. /* MS closes the HTML element at the end of
  171. * the attributes too, according to the nunit
  172. * tests
  173. */
  174. w.Write (" /");
  175. }
  176. }
  177. }