svn path=/branches/mono-1-1-9/mcs/; revision=50438
[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                 public string Src 
154                 {
155                         get {
156                                 string src = Attributes["src"];
157
158                                 if (src == null) {
159                                         return (String.Empty);
160                                 }
161                                 
162                                 return (src);
163                         }
164                         set {
165                                 if (value == null) {
166                                         Attributes.Remove ("src");
167                                 } else {
168                                         Attributes["src"] = value;
169                                 }
170                         }
171                 }
172
173                 [DefaultValue (100)]
174                 [WebSysDescription("")]
175                 [WebCategory("Layout")]
176                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
177                 public int Width 
178                 {
179                         get {
180                                 string width = Attributes["width"];
181
182                                 if (width == null) {
183                                         return (-1);
184                                 }
185                                 else {
186                                         return (Int32.Parse (width, CultureInfo.InvariantCulture));
187                                 }
188                         }
189                         set {
190                                 if (value == -1) {
191                                         Attributes.Remove ("width");
192                                 } else {
193                                         Attributes["width"] = value.ToString ();
194                                 }
195                         }
196                 }
197
198                 protected override void RenderAttributes (HtmlTextWriter w)
199                 {
200                         PreProcessRelativeReference (w, "src");
201                         base.RenderAttributes (w);
202
203                         /* MS closes the HTML element at the end of
204                          * the attributes too, according to the nunit
205                          * tests
206                          */
207                         w.Write (" /");
208                 }
209         }
210 }
211
212