www.pudn.com > (code)ComponentArt.rar > Rotator.cs, change:2004-10-14,size:31632b


using System; 
using System.Collections;  
using System.Collections.Specialized;  
using System.Data;  
using System.Drawing; 
using System.Globalization; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.ComponentModel; 
using System.IO;  
using System.Xml;  
using ComponentArt.Web.UI.Design;  
using System.Runtime.InteropServices;  
using ComponentArt.Licensing.Providers;  
 
namespace ComponentArt.Web.UI 
{ 
  #region Custom enumerations 
 
  /// <summary> 
  /// Which slide to output to down-level browsers. 
  /// </summary> 
  public enum DownLevelOutputType 
  { 
    /// <summary> 
    /// Output a random slide. 
    /// </summary> 
    RandomSlide, 
     
    /// <summary> 
    /// Output the first slide. 
    /// </summary> 
    FirstSlide 
  } 
 
  /// <summary> 
  /// Rotation effects. 
  /// </summary> 
  public enum RotationEffect 
  { 
    None, Fade, Pixelate, Dissolve, GradientWipe 
  } 
 
  /// <summary> 
  /// Types of rotations. 
  /// </summary> 
  public enum RotationType 
  { 
    ContentScroll, SlideShow, RandomSlide, SmoothScroll 
  } 
 
  /// <summary> 
  /// Scrolling directions. 
  /// </summary> 
  public enum ScrollDirection 
  { 
    /// <summary> 
    /// Scroll up. 
    /// </summary> 
    Up, 
     
    /// <summary> 
    /// Scroll down. 
    /// </summary> 
    Left 
  } 
 
  /// <summary> 
  /// Speed settings for smooth scrolling. 
  /// </summary> 
  public enum SmoothScrollSpeed 
  { 
    /// <summary> 
    /// Scroll medium speed. 
    /// </summary> 
    Medium, 
     
    /// <summary> 
    /// Scroll slow. 
    /// </summary> 
    Slow, 
     
    /// <summary> 
    /// Scroll fast. 
    /// </summary> 
    Fast  
  } 
 
  #endregion 
 
  #region Rotator web control  
 
  /// <summary> 
  /// ComponentArt Rotator control. Core product features include: ability to implement animated news scrollers, product slideshows, stock tickers, random content rotation in just a few lines of code.  
  /// </summary> 
  [GuidAttribute("191A11D9-D036-4EA0-96F3-D46291186E4D")] 
  [LicenseProviderAttribute(typeof(ComponentArt.Licensing.Providers.RedistributableLicenseProvider))] 
  [Designer(typeof(ComponentArt.Web.UI.Design.RotatorDesigner))] 
  [DefaultProperty("RotationType")] 
  [ToolboxData("<{0}:Rotator runat=server></{0}:Rotator>")] 
	public class Rotator : ComponentArt.Web.UI.WebControl 
	{ 
 
    #region Rotator Control interface  
 
     
    /// <summary> 
    /// AutoStart property.  
    /// </summary> 
    [  
    Description("Whether content rotation should automatically start when the page loads. "),  
    Category("Content Rotation")  
    ] 
    public bool AutoStart 
    { 
      get  
      { 
        object o = ViewState["AutoStart"];  
        return (o == null) ? true : (bool) o;  
      } 
        set  
      { 
        ViewState["AutoStart"] = value; 
      } 
    } 
 
    /// <summary> 
    /// DataMember property.  
    /// </summary> 
    [  
    Description("Data member for ASP.NET data binding. "),  
    Category("Data")  
    ] 
    public virtual string DataMember 
    { 
      get 
      { 
        object o = ViewState["DataMember"];  
        return (o == null) ? String.Empty : (string)o;  
      } 
 
      set 
      { 
        ViewState["DataMember"] = value;  
      } 
    } 
 
    /// <summary> 
    /// DataSource property.  
    /// </summary> 
    private object _dataSource;  
    [  
    Browsable(false),  
    Description("Data source for ASP.NET data binding. "),  
    Category("Data")  
    ] 
    public object DataSource 
    { 
      get  
      {  
        return _dataSource;  
      } 
       
      set  
      {  
        if (value == null || value is IEnumerable || value is IListSource) 
          _dataSource = value;  
        else 
          throw new ArgumentException();  
      } 
    } 
 
    /// <summary> 
    /// DownLevelOutputType property.  
    /// </summary> 
    [  
    Description("What to render for down-level browsers."),  
    Category("Content Rotation")  
    ] 
    public DownLevelOutputType DownLevelOutputType 
    { 
      get  
      { 
        object o = ViewState["DownLevelOutputType"];  
        return (o == null) ? new DownLevelOutputType() : (DownLevelOutputType) o;  
      } 
      set  
      { 
        ViewState["DownLevelOutputType"] = value; 
      } 
    } 
 
    /// <summary> 
    /// HideEffect property.  
    /// </summary> 
    [  
    Description("Transition effect used for hiding individual slides. "),  
    Category("Content Rotation")  
    ] 
    public RotationEffect HideEffect 
    { 
      get  
      { 
        object o = ViewState["HideEffect"];  
        return (o == null) ? new RotationEffect() : (RotationEffect) o;  
      } 
        set  
      { 
        ViewState["HideEffect"] = value; 
      } 
    } 
 
    /// <summary> 
    /// HideEffectDuration property.  
    /// </summary> 
    [  
    Description("Hide effect duration in milliseconds. "),  
    Category("Content Rotation")  
    ] 
    public int HideEffectDuration 
    { 
      get  
      { 
        object o = ViewState["HideEffectDuration"];  
        return (o == null) ? 250 : (int) o;  
      } 
      set  
      { 
        ViewState["HideEffectDuration"] = value; 
      } 
    } 
 
    /// <summary> 
    /// Loop property.  
    /// </summary> 
    [  
    Description("Whether to loop back to the first slide after the last slide has been displayed. "),  
    Category("Content Rotation")  
    ] 
    public bool Loop 
    { 
      get  
      { 
        object o = ViewState["Loop"];  
        return (o == null) ? true : (bool) o;  
      } 
      set  
      { 
        ViewState["Loop"] = value; 
      } 
    } 
 
    /// <summary> 
    /// PauseOnMouseOver property.  
    /// </summary> 
    [  
    Description("Whether the next slide should be paused on mouse over. "),  
    Category("Content Rotation")  
    ] 
    public bool PauseOnMouseOver 
    { 
      get  
      { 
        object o = ViewState["PauseOnMouseOver"];  
        return (o == null) ? false : (bool) o;  
      } 
      set  
      { 
        ViewState["PauseOnMouseOver"] = value; 
      } 
    } 
 
    /// <summary> 
    /// RotationType property.  
    /// </summary> 
    [  
    Description("Content rotation type. "),  
    Category("Content Rotation")  
    ] 
    public RotationType RotationType 
    { 
      get  
      { 
        object o = ViewState["RotationType"];  
        return (o == null) ? new RotationType() : (RotationType) o;  
      } 
      set  
      { 
        ViewState["RotationType"] = value; 
      } 
    } 
 
    /// <summary> 
    /// ScrollInterval property.  
    /// </summary> 
    [  
    Description("Applicable when RotationType=ContentScroll/SmoothScroll. Delay between scroll steps in milliseconds."),  
    Category("Content Rotation")  
    ] 
    public int ScrollInterval 
    { 
      get  
      { 
        object o = ViewState["ScrollInterval"];  
        return (o == null) ? 20 : (int) o;  
      } 
      set  
      { 
        ViewState["ScrollInterval"] = value; 
      } 
    } 
 
    /// <summary> 
    /// ScrollDirection property.  
    /// </summary> 
    [  
    Description("Applicable when RotationType=ContentScroll/SmoothScroll. Direction in which the content will be scrolled. "),  
    Category("Content Rotation")  
    ] 
    public ScrollDirection ScrollDirection 
    { 
      get  
      { 
        object o = ViewState["ScrollDirection"];  
        return (o == null) ? new ScrollDirection() : (ScrollDirection) o;  
      } 
      set  
      { 
        ViewState["ScrollDirection"] = value; 
      } 
    } 
 
    /// <summary> 
    /// ShowEffect property.  
    /// </summary> 
    [  
    Description("Transition effect used for showing individual slides. "),  
    Category("Content Rotation")  
    ] 
    public RotationEffect ShowEffect 
    { 
      get  
      { 
        object o = ViewState["ShowEffect"];  
        return (o == null) ? new RotationEffect() : (RotationEffect) o;  
      } 
      set  
      { 
        ViewState["ShowEffect"] = value; 
      } 
    } 
 
    /// <summary> 
    /// ShowEffectDuration property.  
    /// </summary> 
    [  
    Description("Show effect duration in milliseconds. "),  
    Category("Content Rotation")  
    ] 
    public int ShowEffectDuration 
    { 
      get  
      { 
        object o = ViewState["ShowEffectDuration"];  
        return (o == null) ? 250 : (int) o;  
      } 
      set  
      { 
        ViewState["ShowEffectDuration"] = value; 
      } 
    } 
 
    /// <summary> 
    /// SlideCssClass property.  
    /// </summary> 
    [  
    Description("CSS class for each slide. "),  
    Category("Appearance")  
    ] 
    public string SlideCssClass 
    { 
      get  
      { 
        object o = ViewState["SlideCssClass"];  
        return (o == null) ? String.Empty : (string) o;  
      } 
      set  
      { 
        ViewState["SlideCssClass"] = value; 
      } 
    } 
 
    /// <summary> 
    /// SlidePause property.  
    /// </summary> 
    [  
    Description("Pause between slides in milliseconds. "),  
    Category("Content Rotation")  
    ] 
    public int SlidePause 
    { 
      get  
      { 
        object o = ViewState["SlidePause"];  
        return (o == null) ? 2000 : (int) o;  
      } 
      set  
      { 
        ViewState["SlidePause"] = value; 
      } 
    } 
 
    /// <summary> 
    /// SlideTemplate property.  
    /// </summary> 
    private ITemplate _slideTemplate;  
    [ 
    Browsable(false),  
    PersistenceMode(PersistenceMode.InnerProperty), 
    TemplateContainer(typeof(Slide)) 
    ] 
    public ITemplate SlideTemplate 
    { 
      get  
      {  
        return _slideTemplate;  
      } 
      set  
      {  
        _slideTemplate = value;  
      } 
    } 
 
    /// <summary> 
    /// SmoothScrollSpeed property.  
    /// </summary> 
    [  
    Description("Speed of the smooth scroll effect when RotationType=SmoothScroll. "),  
    Category("Content Rotation")  
    ] 
    public SmoothScrollSpeed SmoothScrollSpeed 
    { 
      get  
      { 
        object o = ViewState["SmoothScrollSpeed"];  
        return (o == null) ? new SmoothScrollSpeed() : (SmoothScrollSpeed) o;  
      } 
      set  
      { 
        ViewState["SmoothScrollSpeed"] = value; 
      } 
    } 
 
    /// <summary> 
    /// XmlContentFile property.  
    /// </summary> 
    [  
    Description("XML file containing the rotation content. "),  
    Category("Data")  
    ] 
    public string XmlContentFile 
    { 
      get  
      { 
        object o = ViewState["XmlContentFile"];  
        return (o == null) ? String.Empty : (string) o;  
      } 
      set  
      { 
        ViewState["XmlContentFile"] = value; 
      } 
    } 
 
    #endregion 
 
 
    #region Rotator Control implementation  
 
    // Private, protected, and internal members  
    protected StringCollection slides = new StringCollection();  
    internal StringCollection tickers = new StringCollection();  
    internal StringCollection leadTickers = new StringCollection();  
    internal bool hasTickers = false;  
    private bool _writtenContents = false;  
 
/* 
 
    public Rotator() : base ("DIV") 
    { 
    } 
 
*/     
    #region Data Binding  
 
    protected virtual IEnumerable GetDataSource() 
    { 
      if (_dataSource == null) return null;  
 
      IEnumerable resolvedDataSource = _dataSource as IEnumerable;  
      if (resolvedDataSource != null) return resolvedDataSource;  
 
      IListSource listSource = _dataSource as IListSource;  
      if (listSource != null) 
      { 
        IList memberList = listSource.GetList();  
        if (!listSource.ContainsListCollection) return (IEnumerable)memberList;  
 
        ITypedList typedMemberList = memberList as ITypedList;  
        if (typedMemberList != null) 
        { 
          PropertyDescriptorCollection propDescs = typedMemberList.GetItemProperties(new PropertyDescriptor[0]);  
          PropertyDescriptor memberProperty = null;  
 
          if (propDescs != null && propDescs.Count != 0) 
          { 
            string dataMember = DataMember;  
 
            if (dataMember.Length == 0)  
              memberProperty = propDescs[0];  
            else 
              memberProperty = propDescs.Find(dataMember, true);  
 
            if (memberProperty != null) 
            { 
              object listRow = memberList[0];  
              object list = memberProperty.GetValue(listRow);  
 
              if (list is IEnumerable) return (IEnumerable)list;  
            } 
            throw new Exception("A list corresponding to the selected DataMember was not found. ");  
          } 
          throw new Exception("The selected data source did not contain any data members to bind to.");  
        } 
      } 
      return null;  
    } 
 
 
    protected override void CreateChildControls() 
    { 
      Controls.Clear();  
 
      if (ViewState["ItemCount"] != null) 
      { 
        CreateControlHierarchy(false);  
      } 
    } 
 
    protected void CreateControlHierarchy(bool UseDataSource) 
    { 
      IEnumerable data;  
      IEnumerator dataItems;  
 
      int itemCounter = 0;  
 
      if (UseDataSource) 
        data = GetDataSource();  
      else 
        data = new object[(int)ViewState["ItemCount"]];  
 
      dataItems = data.GetEnumerator();  
 
      if ((!isUpLevelBrowser()) || RotationType == RotationType.RandomSlide) 
      { 
        if ((!isUpLevelBrowser()) && DownLevelOutputType == DownLevelOutputType.FirstSlide)  
        { 
          dataItems.MoveNext();  
        } 
        else 
        { 
          // Count items  
          while (dataItems.MoveNext()) 
            itemCounter++;  
 
          // Pick a random item  
          Random rnd = new Random();  
          int choice = rnd.Next(1, itemCounter + 1);  
 
          try 
          { 
            // Get to the chosen item  
            dataItems.Reset();  
            for (int i = 0; i < choice; i++)  
              dataItems.MoveNext();  
          } 
          catch 
          { 
            // If the object doesn't support the Reset method,  
            // just display the first slide 
            dataItems.MoveNext();  
          } 
        } 
 
        // Create the chosen slide 
        Slide slide = new Slide(dataItems.Current, this.ClientID + "_slide" + itemCounter.ToString(), this);  
        slides.Add(this.ClientID + "_slide" + itemCounter.ToString());  
        slide.DataBind();  
        SlideTemplate.InstantiateIn(slide);  
        Controls.Add(slide);  
      } 
      else 
      { 
        while (dataItems.MoveNext()) 
        { 
          Slide slide = new Slide(dataItems.Current, this.ClientID + "_slide" + itemCounter.ToString(), this);  
          slides.Add(this.ClientID + "_slide" + itemCounter.ToString());  
          slide.DataBind();  
 
          SlideTemplate.InstantiateIn(slide);  
          Controls.Add(slide);  
          itemCounter++;  
        } 
        ViewState["ItemCount"] = itemCounter;  
      } 
    } 
 
    protected override void OnDataBinding(EventArgs e) 
    { 
      base.OnDataBinding(e);  
 
      Controls.Clear();  
      if (HasChildViewState) ClearChildViewState();  
 
      CreateControlHierarchy(true);  
 
      ChildControlsCreated = true;  
 
      if (IsTrackingViewState) TrackViewState();  
    } 
 
    private void bindWithXmlContentFile() 
    { 
      if (XmlContentFile != String.Empty) 
      { 
        DataSet ds = new DataSet();  
        ds.ReadXml(Context.Server.MapPath(XmlContentFile));  
        DataSource = ds;  
        DataBind();  
      } 
    } 
 
    protected override bool IsDownLevel() 
    { 
      return (!isUpLevelBrowser()); 
    } 
 
    #endregion  
 
 
    #region Rendering  
 
    protected override void OnPreRender(EventArgs e) 
    { 
      base.OnPreRender(e); 
      if(isUpLevelBrowser())  
      { 
        RegisterGlobalClientScript("ComponentArt.Web.UI.Rotator.client_scripts", "Rotator.js"); 
        RegisterGlobalClientScript("ComponentArt.Web.UI.Rotator.client_scripts", "Ticker.js"); 
      } 
    } 
 
    protected override void ComponentArtRender(HtmlTextWriter output) 
    { 
      if (Width == Unit.Empty) Width = Unit.Parse("250px");  
      if (Height == Unit.Empty) Height = Unit.Parse("50px");        
      if (_dataSource == null) 
      { 
        if (XmlContentFile != String.Empty) 
          bindWithXmlContentFile();  
        else 
          AutoStart = false;  
      } 
 
      System.Web.UI.HtmlTextWriter tw; 
 
      if(isUpLevelBrowser())  
      { 
        if (Context.Request.Browser.Browser == "Opera" & RotationType == RotationType.SlideShow) 
        { 
          RotationType = RotationType.SmoothScroll;  
        } 
        tw = new HtmlTextWriter(Page.Response.Output);  
        AddAttributesToRender(tw); 
        if (RotationType != RotationType.RandomSlide) tw.AddStyleAttribute("overflow", "hidden");  
        RenderPauseEventHandlers(tw);  
        tw.RenderBeginTag(HtmlTextWriterTag.Div); 
        RenderContents(tw);  
        _writtenContents = true;  
        tw.RenderEndTag(); 
      } 
      else  
      { 
        RenderSingleSlide(output);  
      } 
    } 
 
    protected override void RenderContents(HtmlTextWriter output) 
    { 
      if (!_writtenContents)  
        switch (RotationType) 
        { 
          case RotationType.ContentScroll :  
            RenderScrollContents(output);  
            break;  
          case RotationType.SmoothScroll :  
            RenderScrollContents(output);  
            break;  
          case RotationType.SlideShow :  
            RenderSlideShowContents(output);  
            break;  
          case RotationType.RandomSlide :  
            RenderSingleSlide(output);  
            break;  
        } 
    } 
 
    protected void RenderPauseEventHandlers(HtmlTextWriter output) 
    { 
      if (PauseOnMouseOver && RotationType != RotationType.RandomSlide && 
           (_dataSource != null || XmlContentFile != String.Empty))  
      { 
        if (Context.Request.Browser.Browser == "IE") 
        { 
          output.AddAttribute("onMouseOver", "ie_MsOver(this, " + "rco_" + ClientID + ");");  
          output.AddAttribute("onMouseOut", "ie_MsOut(this, " + "rco_" + ClientID + ");");  
        } 
        else if (Context.Request.Browser.Browser == "Netscape") 
        { 
          output.AddAttribute("onMouseOver", "ns_MsOver(event, '" + ClientID + "', " + "rco_" + ClientID + ");");  
          output.AddAttribute("onMouseOut", "ns_MsOut(event, '" + ClientID + "', " + "rco_" + ClientID + ");");  
        } 
      } 
    } 
 
    protected void RenderScrollContents(HtmlTextWriter output) 
    { 
      //RegisterClientScript("Rotator");  
 
      output.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_SlideContainer");  
      output.AddStyleAttribute("position", "relative");  
      output.AddStyleAttribute("visibility", "hidden");  
      output.RenderBeginTag(HtmlTextWriterTag.Div);  
 
      if (ScrollDirection == ScrollDirection.Left) 
      { 
        output.AddAttribute("cellpadding", "0");  
        output.AddAttribute("cellspacing", "0");  
        output.RenderBeginTag("table");  
        output.AddAttribute("id", ClientID + "_ContainerRow");  
        output.RenderBeginTag("tr");  
      } 
 
      base.RenderContents(output);  
 
      if (ScrollDirection == ScrollDirection.Left) 
      { 
        output.RenderEndTag(); // </tr> 
        output.RenderEndTag(); // </table> 
      } 
 
      output.RenderEndTag(); // </div> 
       
      RenderInstanceClientScript(output);  
    }     
 
    protected void RenderSlideShowContents(HtmlTextWriter output) 
    { 
      //RegisterClientScript("Rotator");  
 
      output.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_SlideContainer");  
      output.AddStyleAttribute("position", "relative");  
      output.AddStyleAttribute("visibility", "hidden");  
      output.AddStyleAttribute("width", "100%");  
      output.AddAttribute(HtmlTextWriterAttribute.Class, SlideCssClass);  
      output.RenderBeginTag(HtmlTextWriterTag.Div);  
      output.RenderEndTag();  
      //output.Write("</div>");  
 
      base.RenderContents(output);  
       
      RenderInstanceClientScript(output);  
    }     
 
    protected void RenderSingleSlide(HtmlTextWriter output) 
    { 
      base.RenderContents(output);        
    }     
 
    private void RegisterClientScript(string sScriptName) 
    { 
      RegisterGlobalClientScript("ComponentArt.Web.UI.Rotator.client_scripts", sScriptName + ".js"); 
    } 
 
    // Renders instance-specific client script, one for each instance of the control  
    private void RenderInstanceClientScript(HtmlTextWriter output) 
    { 
      string instanceSlides = "";  
      if (slides.Count > 0) 
        for (short i = 0; i < slides.Count; i++) 
        { 
          instanceSlides += "rotator_client_object.Slides[" + i.ToString() + "] = '";  
          instanceSlides += slides[i].Replace("'", "\'") + "'; ";  
        } 
 
      string instanceTickers = "";  
      if (tickers.Count > 0) 
        for (short i = 0; i < tickers.Count; i++) 
        { 
          instanceTickers += "rotator_client_object.Tickers[" + i.ToString() + "]=";  
          instanceTickers += tickers[i] + "; ";  
        } 
 
      string instanceLeadTickers = "";  
      if (leadTickers.Count > 0) 
        for (short i = 0; i < leadTickers.Count; i++) 
        { 
          instanceLeadTickers += "rotator_client_object.LeadTickers[" + i.ToString() + "]=";  
          instanceLeadTickers += leadTickers[i] + "; ";  
        } 
 
      string instanceScript;  
      instanceScript = "<script language=\"JavaScript\">";  
      instanceScript += GetResourceContent("ComponentArt.Web.UI.Rotator.client_scripts.Rotator_Instance.js");  
      instanceScript = instanceScript.Replace("rotator_client_object.Slides[0] = '...';", instanceSlides);  
      instanceScript = instanceScript.Replace("rotator_client_object.Tickers[0] = '...';", instanceTickers);  
      instanceScript = instanceScript.Replace("rotator_client_object.LeadTickers[0] = '...';", instanceLeadTickers);  
      instanceScript = instanceScript.Replace("rotator_client_object", "rco_" + this.ClientID);  
      instanceScript = instanceScript.Replace("rotator_element_id", this.ClientID);  
      instanceScript = instanceScript.Replace("rotator_container_id", this.ClientID + "_SlideContainer");  
      instanceScript = instanceScript.Replace("rotator_container_row_id", this.ClientID + "_ContainerRow");  
      instanceScript = instanceScript.Replace("auto_start", AutoStart.ToString().ToLower());  
      instanceScript = instanceScript.Replace("slide_pause", SlidePause.ToString());  
      instanceScript = instanceScript.Replace("hide_effect", effectString(HideEffect, HideEffectDuration));  
      instanceScript = instanceScript.Replace("hideEffect_duration", HideEffectDuration.ToString(NumberFormatInfo.InvariantInfo));  
      instanceScript = instanceScript.Replace("_loop", Loop.ToString().ToLower());  
      instanceScript = instanceScript.Replace("pause_on_mouse_over", PauseOnMouseOver.ToString().ToLower());  
      instanceScript = instanceScript.Replace("scroll_direction", "'" + ScrollDirection.ToString().ToLower() + "'");  
      instanceScript = instanceScript.Replace("scroll_interval", ScrollInterval.ToString());  
      instanceScript = instanceScript.Replace("show_effect", effectString(ShowEffect, ShowEffectDuration));  
      instanceScript = instanceScript.Replace("showEffect_duration", ShowEffectDuration.ToString(NumberFormatInfo.InvariantInfo));  
      instanceScript = instanceScript.Replace("rotation_type", "'" + RotationType.ToString() + "'");  
      instanceScript = instanceScript.Replace("smooth_scroll_speed", "'" + SmoothScrollSpeed.ToString() + "'");  
      instanceScript = instanceScript.Replace("has_tickers", hasTickers.ToString().ToLower());  
      instanceScript += "</script>";  
      output.Write(instanceScript);  
    } 
 
    private void RenderMessage(HtmlTextWriter output, string Message) 
    { 
      output.Write("<div style=\"background-color:#3F3F3F;border:1px;border-style:solid;border-bottom-color:black;border-right-color:black;border-left-color:lightslategray;border-top-color:lightslategray;color:cornsilk;padding:2px;font-family:verdana;font-size:11px;"); 
      if (RunningInDesignMode()) output.Write("height:100%;");  
      if (this.Width.IsEmpty) 
        output.Write("\">");  
      else 
        output.Write("width:100%\">");  
      output.Write("<b>Rich Content Rotator</b> :: " + Message + "</div>");  
    } 
 
    private string effectString(RotationEffect effect, int duration) 
    { 
      if (!supportEffects()) return "null";  
 
      string result;  
 
      switch(effect) 
      { 
        case RotationEffect.Dissolve :  
          result = "'progid:DXImageTransform.Microsoft.RandomDissolve(Duration=_duration_)'";  
          break;  
        case RotationEffect.Fade :  
          result = "'progid:DXImageTransform.Microsoft.Fade(Duration=_duration_, Overlap=0.0)'";  
          break;  
        case RotationEffect.GradientWipe :  
          result = "'progid:DXImageTransform.Microsoft.GradientWipe(duration=_duration_, GradientSize=0.25, wipestyle=0, motion=forward)'";  
          break;  
        case RotationEffect.Pixelate :  
          result = "'progid:DXImageTransform.Microsoft.Pixelate(Duration=_duration_, MaxSquare=15)'";  
          break;  
        default :  
          result = "null";  
          break;  
      } 
      double d = duration * 0.001;  
      result = result.Replace("_duration_", d.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));  
      return result;  
    } 
 
    // Whether the request was made by a supported browser  
    internal bool isUpLevelBrowser() 
    { 
      if (RunningInDesignMode()) return false;  
      if (Context.Request.UserAgent == null) return false;  
      if (Context.Request.UserAgent.IndexOf("Safari") >= 0) return false;  
 
      if (Context.Request.Browser.Browser == "IE" &  
          Context.Request.Browser.MajorVersion >= 5 &  
          !(Context.Request.Browser.Platform.ToLower().StartsWith("mac"))) 
        return true;  
      else if (Context.Request.Browser.Browser == "Netscape" & Context.Request.Browser.MajorVersion >= 5) 
        return true;  
      else if (Context.Request.Browser.Browser == "Opera" & Context.Request.Browser.MajorVersion >= 7) 
        return true;  
      else 
        return false;  
    } 
 
    // Whether the control is running in design mode  
    internal bool RunningInDesignMode() 
    { 
      if (Site != null) 
        return Site.DesignMode; 
      else 
        return false;  
    } 
 
    // Whether to support expand effects.  
    internal bool supportEffects() 
    { 
      if (Context.Request.Headers["User-Agent"].IndexOf("NT 4") > 0)   
        return false;  
      else if (Context.Request.Browser.Platform.StartsWith("Mac")) 
        return false;  
      else if (Context.Request.Browser.Browser == "IE" && Context.Request.Browser.MajorVersion >= 6) 
        return true;  
      else if (Context.Request.Browser.Browser == "IE" && Context.Request.Browser.MajorVersion == 5 && Context.Request.Browser.MinorVersion >= 5) 
        return true;  
      else 
        return false;  
    } 
 
    #endregion  
 
    #endregion 
     
	} 
  #endregion  
 
  #region Slide web control  
 
  [ 
  ToolboxItem(false) 
  ] 
  public class Slide : System.Web.UI.WebControls.WebControl, INamingContainer  
  { 
    #region Slide Control Interface  
    /// <summary> 
    /// ClientSideID property.  
    /// </summary> 
    private string _clientSideID; 
    public string ClientSideID 
    { 
      get  
      {  
        return _clientSideID;  
      } 
 
      set  
      {  
        _clientSideID = value;  
      } 
    } 
 
    /// <summary> 
    /// DataItem property.  
    /// </summary> 
    private object _dataItem; 
    public object DataItem 
    { 
      get  
      {  
        return _dataItem;  
      } 
 
      set  
      {  
        _dataItem = value;  
      } 
    } 
 
    #endregion  
 
    #region Slide Control Implementation  
 
    // Private, protected, internal members --------------------------------------------- 
    private Rotator _rotator;  
    private StringCollection _tickers = new StringCollection();  
 
    public Slide(object dataItem, string clientID, Rotator Rotator) : base ("DIV") 
    { 
      DataItem = dataItem;  
      CssClass = Rotator.SlideCssClass; 
      ClientSideID = clientID;  
      _rotator = Rotator;  
    } 
 
    protected override void Render(HtmlTextWriter output) 
    { 
      if (_rotator.RunningInDesignMode()) 
      { 
        base.RenderContents(output);  
      } 
      else 
      { 
        System.Web.UI.HtmlTextWriter tw; 
 
        tw = new HtmlTextWriter(Page.Response.Output);  
        if ((_rotator.RotationType == RotationType.ContentScroll || _rotator.RotationType == RotationType.SmoothScroll) && _rotator.ScrollDirection == ScrollDirection.Left) 
        { 
          tw.RenderBeginTag(HtmlTextWriterTag.Td);  
        } 
        AddAttributesToRender(tw); 
        tw.AddAttribute("id", ClientSideID);  
        if (_rotator.isUpLevelBrowser() && _rotator.RotationType == RotationType.SlideShow) 
        { 
          tw.AddStyleAttribute("position", "absolute");  
          tw.AddStyleAttribute("visibility", "hidden");  
        } 
        SetChildTickers();  
        tw.RenderBeginTag(HtmlTextWriterTag.Div); 
        base.RenderContents(tw);  
        tw.RenderEndTag(); // </div> 
        if ((_rotator.RotationType == RotationType.ContentScroll || _rotator.RotationType == RotationType.SmoothScroll) && _rotator.ScrollDirection == ScrollDirection.Left) 
        { 
          tw.RenderEndTag(); // </td> 
        } 
      } 
    } 
    
    protected void SetChildTickers() 
    { 
      // Enumerate all tickers, and set their default properties  
      foreach (Control childControl in Controls) 
      { 
        Ticker curTicker;  
        if (childControl is Ticker) 
        { 
          _rotator.hasTickers = true;  
          curTicker = childControl as Ticker;  
          curTicker.AutoStart = false;  
          curTicker.Loop = false;  
          if (_rotator.ClientScriptLocation != String.Empty && curTicker.ClientScriptLocation == String.Empty) 
          { 
            curTicker.ClientScriptLocation = _rotator.ClientScriptLocation;  
          } 
          _tickers.Add(curTicker.ClientID);  
          _rotator.tickers.Add("tco_" + curTicker.ClientID);  
        } 
      } 
 
      // Add the first ticker to the head ticker collection  
      if (_rotator.hasTickers) _rotator.leadTickers.Add("tco_" + _tickers[0]);  
 
      // Set OnEnd event handlers for every ticker instance  
      int tickerIndex = 0;  
      foreach (Control childControl in Controls) 
      { 
        Ticker curTicker;  
        if (childControl is Ticker) 
        { 
          curTicker = childControl as Ticker;  
          if (tickerIndex == _tickers.Count - 1)  
            curTicker.OnEnd = "rcr_EndTickerSequence(rco_" + _rotator.ClientID + ")";  
          else 
            curTicker.OnEnd = "rcr_StartTicker(tco_" + _tickers[tickerIndex + 1] + ")";  
          tickerIndex++;  
        } 
      } 
    } 
 
    #endregion  
  } 
  #endregion  
}