using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Text;
namespace DBWebControls.WebControls{
/// <summary>
/// Summary description for TabControl.
/// </summary>
[Designer(typeof(TabControlDesigner)),
ToolboxData("<{0}:TabControl runat=\"server\"></{0}:TabControl>"),
ParseChildren(true, "TabPages"), //needed by the page parser
PersistChildren(false) // Needed by the designer
]
public class TabControl:Control, INamingContainer
{
private TabPageCollection m_TabPages = new TabPageCollection();
private int l_SelectedPageIndex = -1;
private string m_BackGroundImageUrl = string.Empty;
private string m_TabBackSelectedImageUrl=string.Empty;
private string m_TabBackUnSelectedImageUrl=string.Empty;
private const string IDPrefix = "TabPage__";
private const string SelectedIndexViewSateKey = "TabSelectedIndex";
//private System.ComponentModel.Container components = null;
public TabControl()
{
//
// TODO: Add constructor logic here
//
}
#region Properties
[Bindable(false),
Browsable(false)]
public int SelectedPageIndex
{
get
{
if(l_SelectedPageIndex < 0 || l_SelectedPageIndex >= TabPages.Count)
{
object tmp = this.ViewState[SelectedIndexViewSateKey];
if(tmp != null)
l_SelectedPageIndex = (int)tmp;
else
l_SelectedPageIndex = 0;
}
return l_SelectedPageIndex;
}
}
[
Bindable(true),
Browsable(true),
Category("Window"),
Editor(typeof(TabPageCollectionEditor), typeof(UITypeEditor)),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty),
Description("Collection of Property(string Key, string Value) objects sent to Modal Window.")
]
public TabPageCollection TabPages
{
get{return m_TabPages;}
}
[Category("Windows"),
Description("BackGround image"),
Bindable(true),
Browsable(true),
Localizable(false),
DefaultValue(""),
Editor(typeof( System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]
public string BackGroundImageUrl
{
get{return m_BackGroundImageUrl;}
set{m_BackGroundImageUrl = value;}
}
[Category("Windows"),
Description("image shown when the tab page is selected"),
Bindable(true),
Browsable(true),
Localizable(false),
DefaultValue(""),
Editor(typeof( System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]
public string TabBackSelectedImageUrl
{
get{return m_TabBackSelectedImageUrl;}
set{m_TabBackSelectedImageUrl = value;}
}
[Category("Windows"),
Description("image shown when the tab page is not selected"),
Bindable(true),
Browsable(true),
Localizable(false),
Editor(typeof(System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]
public string TabBackUnSelectedImageUrl
{
get{return m_TabBackUnSelectedImageUrl;}
set{m_TabBackUnSelectedImageUrl = value;}
}
#endregion
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
if(TabPages.Count <= 0)
return;
for(int i = 0; i < TabPages.Count; i++)
{
Control ctrl = this.Parent.FindControl(TabPages[i].TabPageControlID);
if(ctrl != null)
ctrl.Visible = (i == SelectedPageIndex);
}
Control tmp = this.FindControl(IDPrefix+TabPages[SelectedPageIndex].TabPageName);
((HtmlControl)tmp.Parent).Attributes["class"] = "selected";
this.ViewState.Add(SelectedIndexViewSateKey, SelectedPageIndex);
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
HtmlGenericControl div = new HtmlGenericControl("div");
div.Attributes["class"] = "shadetabs";
HtmlGenericControl ul = new HtmlGenericControl("ul");
ul.EnableViewState = false;
// HtmlTable htmltable = new HtmlTable();
// htmltable.EnableViewState = false;
// if(m_BackGroundImageUrl.Length > 0)
// htmltable.Attributes["background"] = m_BackGroundImageUrl;
// htmltable.Rows.Add(new HtmlTableRow());
// htmltable.Rows[0].EnableViewState = false;
foreach(TabPage tp in m_TabPages)
{
// HtmlGenericControl gc = new HtmlGenericControl("div");
// HtmlTableCell tcell = new HtmlTableCell();
HtmlGenericControl li = new HtmlGenericControl("li");
LinkButton lb = new LinkButton();
//lb.Style["BACKGROUND-IMAGE"] = "url("+m_TabBackSelectedImageUrl+")";
//lb.Style["BACKGROUND-REPEAT"] = "repeat-x";
lb.Text = tp.TabPageText;
lb.ID = IDPrefix+tp.TabPageName;
lb.Click +=new EventHandler(lb_Click);
lb.EnableViewState = false;
li.Controls.Add(lb);
li.EnableViewState = false;
// tcell.EnableViewState = false;
// tcell.Controls.Add(lb);
ul.Controls.Add(li);
}
div.Controls.Add(ul);
this.Controls.Add(div);
}
private void lb_Click(object sender, EventArgs e)
{
int tmpi = TabPages.GetTabPageIndexByName(((Control)sender).ID.Substring(IDPrefix.Length));
if(tmpi >= 0)
l_SelectedPageIndex = tmpi;
}
}
/// <summary>
/// Class for displaying WebModalAnchor in designer
/// </summary>
internal class TabControlDesigner : System.Web.UI.Design.ControlDesigner
{
#region Overriden methods
/// <summary>
/// Returns HTML code to show in designer
/// </summary>
public override string GetDesignTimeHtml()
{
StringBuilder sb = new StringBuilder(300);
sb.Append(@"<div style=""padding:1px; background-color: #333333;color:#FFFFFF;font:12px Verdana " +
" border-style:outset; border-width:1px; font: 75% 'Microsoft Sans Serif';\"> <span style=\"color:#FAB301\">TABCONTROL</span> "+((Control)Component).ID +
" <br/>Ver. "+ this.GetType().Assembly.GetName().Version +
"</div>");
return sb.ToString();
}
#endregion
}
}
|