| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- //
- // System.Web.UI.WebControls.Image.cs
- //
- // Author:
- // Sebastien Pouliot <[email protected]>
- //
- // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System.ComponentModel;
- namespace System.Web.UI.WebControls {
- // Note: this control can live inside or outside a <form> element
- [DefaultProperty ("ImageUrl")]
- #if NET_2_0
- [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
- #endif
- public class Image : WebControl {
- private bool enabled; // not applicable to image
- public Image ()
- : base (HtmlTextWriterTag.Img)
- {
- enabled = true;
- }
- [Bindable (true)]
- [DefaultValue ("")]
- #if NET_2_0
- [Localizable (true)]
- #endif
- [WebSysDescription ("")]
- [WebCategory ("Appearance")]
- public virtual string AlternateText {
- get {
- string s = (string) ViewState ["AlternateText"];
- return (s == null) ? String.Empty : s;
- }
- set {
- if (value == null)
- ViewState.Remove ("AlternateText");
- else
- ViewState ["AlternateText"] = value;
- }
- }
- // not applicable to Image
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public override bool Enabled {
- get { return enabled; }
- set { enabled = value; }
- }
- // not applicable to Image
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public override FontInfo Font {
- get { return base.Font; }
- }
- #if ONLY_1_1
- [Bindable (true)]
- #endif
- [DefaultValue (ImageAlign.NotSet)]
- [WebSysDescription ("")]
- [WebCategory ("Layout")]
- public virtual ImageAlign ImageAlign {
- get {
- object o = ViewState ["ImageAlign"];
- return (o == null) ? ImageAlign.NotSet : (ImageAlign) o;
- }
- set {
- // avoid reflection
- if ((value < ImageAlign.NotSet) || (value > ImageAlign.TextTop)) {
- // invalid ImageAlign (note: 2.0 beta2 documents ArgumentException)
- throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid ImageAlign value."));
- }
- ViewState ["ImageAlign"] = value;
- }
- }
- [Bindable (true)]
- [DefaultValue ("")]
- #if NET_2_0
- [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- [UrlProperty]
- #else
- [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
- #endif
- [WebSysDescription ("")]
- [WebCategory ("Appearance")]
- public virtual string ImageUrl {
- get {
- string s = (string) ViewState ["ImageUrl"];
- return (s == null) ? String.Empty : s;
- }
- set {
- if (value == null)
- ViewState.Remove ("ImageUrl");
- else
- ViewState ["ImageUrl"] = value;
- }
- }
- // this was added in Fx 1.1 SP1
- [DefaultValue ("")]
- #if NET_2_0
- [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- [UrlProperty]
- #endif
- [WebSysDescription ("")]
- [WebCategory ("Accessibility")]
- public virtual string DescriptionUrl {
- get {
- string s = (string) ViewState ["DescriptionUrl"];
- return (s == null) ? String.Empty : s;
- }
- set {
- if (value == null)
- ViewState.Remove ("DescriptionUrl");
- else
- ViewState ["DescriptionUrl"] = value;
- }
- }
- #if NET_2_0
- [DefaultValue (false)]
- [WebSysDescription ("")]
- [WebCategory ("Accessibility")]
- public virtual bool GenerateEmptyAlternateText {
- get {
- object o = ViewState ["GenerateEmptyAlternateText"];
- return (o == null) ? false : (bool) o;
- }
- set {
- ViewState ["GenerateEmptyAlternateText"] = value;
- }
- }
- #endif
- protected override void AddAttributesToRender (HtmlTextWriter writer)
- {
- base.AddAttributesToRender (writer);
- #if NET_2_0
- // src is always present, even if empty, in 2.0
- writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (ImageUrl));
- string s = AlternateText;
- if ((s.Length > 0) || GenerateEmptyAlternateText)
- writer.AddAttribute (HtmlTextWriterAttribute.Alt, s);
- s = DescriptionUrl;
- if (s.Length > 0)
- writer.AddAttribute (HtmlTextWriterAttribute.Longdesc, ResolveUrl (s));
- #else
- // alt is always present, even if empty, in 1.x
- writer.AddAttribute (HtmlTextWriterAttribute.Alt, AlternateText);
- string s = ImageUrl;
- if (s.Length > 0)
- writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (s));
- // added in Fx 1.1 SP1 but the HtmlTextWriterAttribute wasn't
- s = DescriptionUrl;
- if (s.Length > 0)
- writer.AddAttribute ("longdesc", s);
- #endif
- if (!enabled)
- writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
- // avoid reflection
- switch (ImageAlign) {
- case ImageAlign.Left:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "left");
- break;
- case ImageAlign.Right:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "right");
- break;
- case ImageAlign.Baseline:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "baseline");
- break;
- case ImageAlign.Top:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "top");
- break;
- case ImageAlign.Middle:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "middle");
- break;
- case ImageAlign.Bottom:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "bottom");
- break;
- case ImageAlign.AbsBottom:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "absbottom");
- break;
- case ImageAlign.AbsMiddle:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "absmiddle");
- break;
- case ImageAlign.TextTop:
- writer.AddAttribute (HtmlTextWriterAttribute.Align, "texttop");
- break;
- }
- // if no style is defined default image to no border
- if (!ControlStyleCreated) {
- writer.AddAttribute (HtmlTextWriterAttribute.Border, "0");
- }
- }
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- override void RenderContents (HtmlTextWriter writer)
- {
- base.RenderContents (writer);
- }
- }
- }
|