using System;
using System.Reflection;
using System.Globalization;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.ComponentModel.Design.Serialization;
namespace DBWebControls.WebControls{
/// <summary>
/// Summary description for TabPage.
/// </summary>
// [Serializable]
// [TypeConverter(typeof(TabPageTypeConverter))]
public class TabPage
{
private string m_TabPageName=string.Empty;
private string m_TabPageText=string.Empty;
private string m_TabPageControlID=string.Empty;
private string m_SelectedImageUrl=string.Empty;
private string m_UnSelectedImageUrl=string.Empty;
public TabPage()
{
}
public TabPage(string p_TabPAgeName)
{
m_TabPageName = p_TabPAgeName;
}
[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 SelectedImageUrl
{
get{return m_SelectedImageUrl;}
set{m_SelectedImageUrl = 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 UnSelectedImageUrl
{
get{return m_UnSelectedImageUrl;}
set{m_UnSelectedImageUrl = value;}
}
[Category("Windows")]
[Description("The Tab Page Name")]
[Bindable(true)]
[Localizable(false)]
[Editor(typeof(System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]
public string TabPageName
{
get{return m_TabPageName;}
set{m_TabPageName = value;}
}
[Category("Binding")]
[Description("The Text shown in the page")]
[Bindable(true)]
[Localizable(true)]
public string TabPageText
{
get{return m_TabPageText;}
set{m_TabPageText = value;}
}
[Category("Action")]
[Description("The coresponding control ID for the TabPage")]
[Bindable(false)]
[Localizable(false)]
[Editor(typeof(AllControlsEditor), typeof(UITypeEditor))]
public string TabPageControlID
{
get{return m_TabPageControlID;}
set{m_TabPageControlID = value;}
}
}
/// <summary>
/// Editor for selecting all Asp.Net controls
/// </summary>
internal class AllControlsEditor : ControlsEditor
{
#region Members
/// <summary>
/// Invoke base constructor
/// </summary>
public AllControlsEditor() : base(typeof(Control)) {}
#endregion
}
internal abstract class ControlsEditor : UITypeEditor
{
#region Variables
private System.Windows.Forms.Design.IWindowsFormsEditorService edSvc=null;
private System.Windows.Forms.ListBox lb;
private Type typeShow;
#endregion
#region Constructor
/// <summary>
/// onstructor - show specified types
/// </summary>
/// <param name="show">Type descriptor</param>
public ControlsEditor(Type show)
{
typeShow=show;
}
#endregion
#region Methods
/// <summary>
/// Overrides the method used to provide basic behaviour for selecting editor.
/// Shows our custom control for editing the value.
/// </summary>
/// <param name="context">The context of the editing control</param>
/// <param name="provider">A valid service provider</param>
/// <param name="value">The current value of the object to edit</param>
/// <returns>The new value of the object</returns>
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider,object value)
{
if (context!=null&&context.Instance!=null&&provider!=null)
{
edSvc=(System.Windows.Forms.Design.IWindowsFormsEditorService)
provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
if (edSvc!=null)
{
lb=new System.Windows.Forms.ListBox();
ArrayList controlArray = new ArrayList();
lb.BorderStyle=System.Windows.Forms.BorderStyle.None;
lb.SelectedIndexChanged+=new EventHandler(lb_SelectedIndexChanged);
//Cycle through the controls in the anchor's NamingContainer
ControlCollection coll = ((Control)context.Instance).NamingContainer.Controls;
//((ReadOnlyCollectionBase)((IContainer)(context.Container)).Components)
for(int i = 0; i<= coll.Count; i++)
{
try
{
Control ctrl = coll[i];
if ((ctrl.GetType().IsSubclassOf(typeShow) || ctrl.GetType().FullName==typeShow.FullName) && ctrl.ID != null)
controlArray.Add(ctrl.ID);
}
catch{}
}
//Sort the controls by ID, and then add them to the listbox
controlArray.Sort(new CaseInsensitiveComparer());
IEnumerator myEnumerator = controlArray.GetEnumerator();
while ( myEnumerator.MoveNext() )
lb.Items.Add(myEnumerator.Current);
//return it to the IDE
edSvc.DropDownControl(lb);
if (lb.SelectedIndex==-1) return value;
return lb.SelectedItem;
}
}
return value;
}
/// <summary>
/// Choose editor type
/// </summary>
/// <param name="context">The context of the editing control</param>
/// <returns>Returns <c>UITypeEditorEditStyle.DropDown</c></returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
/// <summary>
/// Close the dropdowncontrol when theProperty has selected a value
/// </summary>
private void lb_SelectedIndexChanged(object sender, EventArgs e)
{
if (edSvc != null)
{
edSvc.CloseDropDown();
}
}
#endregion
}
public class TabPageTypeConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
{
if (destType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
{
if (destType == typeof(InstanceDescriptor))
{
ConstructorInfo info1 = typeof(TabPage).GetConstructor(new Type[0]);
return new InstanceDescriptor(info1, null, false);
}
return base.ConvertTo(context, culture, value, destType);
}
}
public class TabPageUIEditor:UITypeEditor
{
public override object EditValue(ITypeDescriptorContext ctx, IServiceProvider provider, object value)
{
if (((ctx == null) || (ctx.Instance == null)) || (provider == null))
{
return value;
}
UITypeEditor editor1 = new UITypeEditor();
// TabPageCollection collection1 = (TabPageCollection) value;
// IWindowsFormsEditorService service1 = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService));
return editor1.EditValue( provider, value);
// DialogResult result1 = service1.ShowDialog(editor1);
// return collection1;
}
}
// [Serializable]
public class TabPageCollection:CollectionBase
{
public int Add(TabPage value)
{
return base.List.Add(value);
}
public void AddRange(TabPageCollection value)
{
foreach (TabPage item1 in value)
this.Add(item1);
}
public bool Contains(TabPage value)
{
return base.List.Contains(value);
}
public void CopyTo(TabPage[] array, int index)
{
base.List.CopyTo(array, index);
}
public int IndexOf(TabPage value)
{
return base.List.IndexOf(value);
}
public void Insert(int index, TabPage value)
{
base.List.Insert(index, value);
}
public void Remove(TabPage value)
{
base.List.Remove(value);
}
public TabPage this[int index]
{
get
{
return (TabPage) base.List[index];
}
set
{
base.List[index] = value;
}
}
public int GetTabPageIndexByName(string tabpagename)
{
for(int i = 0; i < this.Count; i++)
if(this[i].TabPageName.Equals(tabpagename))
return i;
return -1;
}
}
public class TabPageCollectionEditor : System.ComponentModel.Design.CollectionEditor
{
public TabPageCollectionEditor(Type type) : base(type)
{
}
protected override Type CreateCollectionItemType()
{
return typeof(TabPage);
}
}
}
|