2 // System.Web.UI.WebControls.Image.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Web.UI;
\r
36 using System.ComponentModel;
\r
38 namespace System.Web.UI.WebControls
\r
40 [DefaultProperty("ImageUrl")]
\r
41 public class Image : WebControl
\r
43 public Image(): base(HtmlTextWriterTag.Img)
\r
48 [Localizable (true)]
\r
50 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
51 [WebSysDescription ("An alternative text that is shown if the image cannot be displayed.")]
\r
52 public virtual string AlternateText
\r
56 object o = ViewState["AlternateText"];
\r
59 return String.Empty;
\r
63 ViewState["AlternateText"] = value;
\r
67 [Browsable (false), EditorBrowsable (EditorBrowsableState.Never)]
\r
68 public override bool Enabled
\r
72 return base.Enabled;
\r
76 base.Enabled = value;
\r
80 [Browsable (false), EditorBrowsable (EditorBrowsableState.Never)]
81 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
82 public override FontInfo Font
\r
93 [DefaultValue (typeof (ImageAlign), "NotSet"), WebCategory ("Layout")]
94 [WebSysDescription ("The alignment of the image.")]
\r
95 public virtual ImageAlign ImageAlign
\r
99 object o = ViewState["ImageAlign"];
\r
101 return (ImageAlign)o;
\r
102 return ImageAlign.NotSet;
\r
106 ViewState["ImageAlign"] = value;
\r
111 [Localizable (true)]
\r
114 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
115 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
116 [WebSysDescription ("The URL to the image file.")]
\r
117 public virtual string ImageUrl
\r
121 object o = ViewState["ImageUrl"];
\r
124 return String.Empty;
\r
128 ViewState["ImageUrl"] = value;
\r
133 [WebCategory ("Accessibility")]
\r
134 [DefaultValueAttribute ("")]
\r
136 [UrlPropertyAttribute]
\r
137 [EditorAttribute ("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
\r
139 public string DescriptionUrl {
\r
141 object o = ViewState["DescriptionUrl"];
\r
144 return String.Empty;
\r
147 ViewState["DescriptionUrl"] = value;
\r
151 [DefaultValueAttribute (false)]
\r
152 [WebCategory ("Accessibility")]
\r
153 public bool GenerateEmptyAlternateText {
\r
155 object o = ViewState["GenerateEmptyAlternateText"];
\r
161 ViewState["GenerateEmptyAlternateText"] = value;
\r
167 protected override void AddAttributesToRender(HtmlTextWriter writer)
\r
169 base.AddAttributesToRender(writer);
\r
170 if(ImageUrl.Length > 0)
\r
172 writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveUrl(ImageUrl));
\r
176 if (DescriptionUrl.Length > 0)
\r
177 writer.AddAttribute ("longdesc", DescriptionUrl);
\r
179 if (AlternateText.Length > 0 || GenerateEmptyAlternateText)
\r
180 writer.AddAttribute(HtmlTextWriterAttribute.Alt, AlternateText);
\r
182 if (AlternateText.Length > 0)
\r
183 writer.AddAttribute(HtmlTextWriterAttribute.Alt, AlternateText);
\r
186 if(BorderWidth.IsEmpty)
\r
188 writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
\r
190 if(ImageAlign != ImageAlign.NotSet)
\r
192 writer.AddAttribute(HtmlTextWriterAttribute.Align, Enum.Format(typeof(ImageAlign), ImageAlign, "G"));
\r
196 protected override void RenderContents(HtmlTextWriter writer)
\r