Files
mono/mcs/class/System.Web/System.Web.UI.WebControls/Image.cs
T
Sebastien Pouliot 9c6f49799f 2005-09-21 Sebastien Pouliot <[email protected]>
* AdCreatedEventArgs.cs: Added declarative security (Link and, for 
	2.0, Inheritance demands) for Minimal.
	* BaseCompareValidator.cs: Added declarative security (Link and 
	Inheritance demands) for Minimal.
	* BaseDataBoundControl.cs: Added declarative security (Link and 
	Inheritance demands) for Minimal.
	* BaseValidator.cs: Added declarative security (Link and Inheritance 
	demands) for Minimal.
	* BoundColumn.cs: Added declarative security (Link and Inheritance 
	demands) for Minimal.
	* ButtonColumn.cs: Added declarative security (Link and Inheritance 
	demands) for Minimal.
	* CalendarDay.cs: Added declarative security (Link and Inheritance 
	demands) for Minimal.
	* CheckBoxList.cs: Added declarative security (Link and Inheritance 
	demands) for Minimal.
	* CompareValidator.cs: Added declarative security (Link and 
	Inheritance demands) for Minimal.
	* CustomValidator.cs: Added declarative security (Link and Inheritance
	demands) for Minimal.
	* DataBoundControl.cs: Added declarative security (Link and 
	Inheritance demands) for Minimal.
	* DataGridItemCollection.cs: Added declarative security (Link and 
	Inheritance demands) for Minimal.
	* DataKeyCollection.cs: Added declarative security (LinkDemands) for 
	Minimal.
 	* DataListItemCollection.cs: Added declarative security (LinkDemands) 
	for Minimal.
	* DataListItem.cs: Added declarative security (Link and Inheritance 
	demands) for Minimal.
	* FontNamesConverter.cs: Added declarative security (Link and 
	Inheritance demands) for Minimal.
	* HyperLink.cs: Added declarative security (Link and Inheritance 
	demands) for Minimal.
	* HyperLinkColumn.cs: Added declarative security (Link and Inheritance 
	demands) for Minimal.
	* Image.cs: Added declarative security (Link and Inheritance demands) 
	for Minimal.


svn path=/trunk/mcs/; revision=50392
2005-09-21 17:24:38 +00:00

245 lines
7.3 KiB
C#

//
// 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;
using System.Security.Permissions;
namespace System.Web.UI.WebControls {
// Note: this control can live inside or outside a <form> element
// CAS
[AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
// attributes
[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);
}
}
}