HtmlImage.cs 4.9 KB

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