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