rendered paste bodyusing System;
using System.ComponentModel;
using System.Web.UI;
using BulletinX.Components;
namespace BulletinX.Controls
{
public class Style : LiteralControl
{
[ DefaultValue( "screen" ) ]
public virtual string Media
{
get
{
object state = ViewState[ "Media" ];
if ( state != null )
{
return (string)state;
}
return "screen";
}
set { ViewState[ "Media" ] = value; }
}
private string appliation = string.Empty;
public string Application
{
get { return appliation; }
set { appliation = value; }
}
public virtual String Href
{
get
{
string state = (string)ViewState[ "Href" ];
if ( state != null )
{
if ( state.StartsWith( "/" ) || state.StartsWith( "." ) || state.StartsWith( "~" ) || state.StartsWith( "http://" ) )
{
return ResolveUrl( state );
}
else
{
return ResolveUrl( "http://" + state );
}
}
else
{
return "";
}
}
set { ViewState[ "Href" ] = value; }
}
public virtual StyleFlags RelativePosition
{
get
{
Object state = ViewState[ "RelativePosition" ];
if ( state != null )
{
return (StyleFlags)Enum.Parse( typeof( StyleFlags ), state.ToString( ) );
}
else
{
return StyleFlags.Unknown;
}
}
set { ViewState[ "RelativePosition" ] = value; }
}
public virtual bool Enqueue
{
get
{
Object state = ViewState[ "Enqueue" ];
if ( state != null )
{
return bool.Parse( state.ToString( ) );
}
else
{
return false;
}
}
set { ViewState[ "Enqueue" ] = value; }
}
private const string linkFormat = "<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" media=\"{1}\" />";
protected override void OnPreRender( EventArgs e )
{
if ( Enqueue )
{
Head.AddStyle( Href, Media, RelativePosition );
}
}
protected override void Render(HtmlTextWriter writer)
{
if(Enqueue)
return;
if (Href != null)
writer.Write( linkFormat, Href, Media );
}
}
}