2 // System.Web.UI.WebControls.Image.cs
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System.ComponentModel;
30 using System.Security.Permissions;
32 namespace System.Web.UI.WebControls
34 // Note: this control can live inside or outside a <form> element
37 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 [DefaultProperty ("ImageUrl")]
41 [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42 public class Image : WebControl
45 : base (HtmlTextWriterTag.Img)
53 [WebSysDescription ("")]
54 [WebCategory ("Appearance")]
55 public virtual string AlternateText {
57 string s = (string) ViewState ["AlternateText"];
58 return (s == null) ? String.Empty : s;
62 ViewState.Remove ("AlternateText");
64 ViewState ["AlternateText"] = value;
68 // not applicable to Image
70 [EditorBrowsable (EditorBrowsableState.Never)]
71 public override bool Enabled {
72 get { return base.Enabled; }
73 set {base.Enabled = value; }
76 // not applicable to Image
78 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
79 [EditorBrowsable (EditorBrowsableState.Never)]
80 public override FontInfo Font {
81 get { return base.Font; }
84 [DefaultValue (ImageAlign.NotSet)]
85 [WebSysDescription ("")]
86 [WebCategory ("Layout")]
87 public virtual ImageAlign ImageAlign {
89 object o = ViewState ["ImageAlign"];
90 return (o == null) ? ImageAlign.NotSet : (ImageAlign) o;
94 if ((value < ImageAlign.NotSet) || (value > ImageAlign.TextTop)) {
95 // invalid ImageAlign (note: 2.0 beta2 documents ArgumentException)
96 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid ImageAlign value."));
98 ViewState ["ImageAlign"] = value;
104 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
106 [WebSysDescription ("")]
107 [WebCategory ("Appearance")]
108 public virtual string ImageUrl {
110 string s = (string) ViewState ["ImageUrl"];
111 return (s == null) ? String.Empty : s;
115 ViewState.Remove ("ImageUrl");
117 ViewState ["ImageUrl"] = value;
121 // this was added in Fx 1.1 SP1
123 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
125 [WebSysDescription ("")]
126 [WebCategory ("Accessibility")]
127 public virtual string DescriptionUrl {
129 string s = (string) ViewState ["DescriptionUrl"];
130 return (s == null) ? String.Empty : s;
134 ViewState.Remove ("DescriptionUrl");
136 ViewState ["DescriptionUrl"] = value;
140 [DefaultValue (false)]
141 [WebSysDescription ("")]
142 [WebCategory ("Accessibility")]
143 public virtual bool GenerateEmptyAlternateText {
145 object o = ViewState ["GenerateEmptyAlternateText"];
146 return (o == null) ? false : (bool) o;
148 set { ViewState ["GenerateEmptyAlternateText"] = value; }
151 public override bool SupportsDisabledAttribute {
152 get { return RenderingCompatibilityLessThan40; }
155 protected override void AddAttributesToRender (HtmlTextWriter writer)
157 base.AddAttributesToRender (writer);
158 // src is always present, even if empty, in 2.0
159 writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveClientUrl (ImageUrl));
160 string s = AlternateText;
161 if ((s.Length > 0) || GenerateEmptyAlternateText)
162 writer.AddAttribute (HtmlTextWriterAttribute.Alt, s);
165 writer.AddAttribute (HtmlTextWriterAttribute.Longdesc, ResolveClientUrl (s));
167 switch (ImageAlign) {
168 case ImageAlign.Left:
169 writer.AddAttribute (HtmlTextWriterAttribute.Align, "left", false);
171 case ImageAlign.Right:
172 writer.AddAttribute (HtmlTextWriterAttribute.Align, "right", false);
174 case ImageAlign.Baseline:
175 writer.AddAttribute (HtmlTextWriterAttribute.Align, "baseline", false);
178 writer.AddAttribute (HtmlTextWriterAttribute.Align, "top", false);
180 case ImageAlign.Middle:
181 writer.AddAttribute (HtmlTextWriterAttribute.Align, "middle", false);
183 case ImageAlign.Bottom:
184 writer.AddAttribute (HtmlTextWriterAttribute.Align, "bottom", false);
186 case ImageAlign.AbsBottom:
187 writer.AddAttribute (HtmlTextWriterAttribute.Align, "absbottom", false);
189 case ImageAlign.AbsMiddle:
190 writer.AddAttribute (HtmlTextWriterAttribute.Align, "absmiddle", false);
192 case ImageAlign.TextTop:
193 writer.AddAttribute (HtmlTextWriterAttribute.Align, "texttop", false);
197 if (Context.Request.Browser.SupportsCss)
200 if (BorderWidth.IsEmpty)
201 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, "0px");
205 protected internal override void RenderContents (HtmlTextWriter writer)
207 base.RenderContents (writer);