**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / Image.cs
blob4845a13f80639c1c5b84a8fd13e8dafcc0a62c6b
1 //
2 // System.Web.UI.WebControls.Image.cs
3 //
4 // Authors:
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
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:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
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.
33 using System;
34 using System.Web;
35 using System.Web.UI;
36 using System.ComponentModel;
38 namespace System.Web.UI.WebControls
40 [DefaultProperty("ImageUrl")]
41 public class Image : WebControl
43 public Image(): base(HtmlTextWriterTag.Img)
47 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
48 [WebSysDescription ("An alternative text that is shown if the image cannot be displayed.")]
49 public virtual string AlternateText
51 get
53 object o = ViewState["AlternateText"];
54 if(o!=null)
55 return (string)o;
56 return String.Empty;
58 set
60 ViewState["AlternateText"] = value;
64 [Browsable (false), EditorBrowsable (EditorBrowsableState.Never)]
65 public override bool Enabled
67 get
69 return base.Enabled;
71 set
73 base.Enabled = value;
77 [Browsable (false), EditorBrowsable (EditorBrowsableState.Never)]
78 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
79 public override FontInfo Font
81 get
83 return base.Font;
87 [DefaultValue (typeof (ImageAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
88 [WebSysDescription ("The alignment of the image.")]
89 public virtual ImageAlign ImageAlign
91 get
93 object o = ViewState["ImageAlign"];
94 if(o!=null)
95 return (ImageAlign)o;
96 return ImageAlign.NotSet;
98 set
100 ViewState["ImageAlign"] = value;
104 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
105 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
106 [WebSysDescription ("The URL to the image file.")]
107 public virtual string ImageUrl
111 object o = ViewState["ImageUrl"];
112 if(o!=null)
113 return (string)o;
114 return String.Empty;
118 ViewState["ImageUrl"] = value;
122 protected override void AddAttributesToRender(HtmlTextWriter writer)
124 base.AddAttributesToRender(writer);
125 if(ImageUrl.Length > 0)
127 writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveUrl(ImageUrl));
129 if(AlternateText.Length > 0)
131 writer.AddAttribute(HtmlTextWriterAttribute.Alt, AlternateText);
133 if(BorderWidth.IsEmpty)
135 writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
137 if(ImageAlign != ImageAlign.NotSet)
139 writer.AddAttribute(HtmlTextWriterAttribute.Align, Enum.Format(typeof(ImageAlign), ImageAlign, "G"));
143 protected override void RenderContents(HtmlTextWriter writer)