/*
C# Object Persistent Framework.
Copyright (C) 2004 Yoon-Kit Yong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Yoon Kit: yoonkit@users.sourceforge.net (yoonkit@yahoo.com)
*/
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Xml.Serialization;
//using System.Web.UI;
//using System.Drawing.Design;
using csopf.Core;
namespace csopf.UI{
/// <summary>
/// Sets the Table Titles for the
/// PropertyName
/// ColumnTitle
/// Size and Relative Size
/// Clickable
/// 041003 yky Created
/// Property, Title, Size, Clickable.
/// 041130 yky Added PDGridTitleConverter for its TypeConverter.
/// </summary>
//[ToolboxData("<{0}:PDGridTitle runat=server></{0}:PDGridTitle>")]
[TypeConverter(typeof(PDGridTitleConverter))]
//[Serializable()]
public class PDGridTitle//: Control
{
private string fProperty;
public string Property
{
get { return fProperty; }
set { fProperty = value; }
}
private string fTitle;
public string Title
{
get { return fTitle; }
set { fTitle = value; }
}
private int fSize;
public int Size
{
get { return fSize; }
set { fSize = value; }
}
private bool fClickable = false;
public bool Clickable
{
get { return fClickable; }
set { fClickable = value; }
}
public int RelativeSize;
public MetaInfo Info;
public PDGridTitle(): this( "Property", "Title" )
{}
public PDGridTitle( string pProperty ): this( pProperty, pProperty )
{}
public PDGridTitle( string pProperty, string pTitle ): this (pProperty, pTitle, 10)
{}
public PDGridTitle( string pProperty, string pTitle, int pSize ): this (pProperty, pTitle, pSize, false )
{}
public PDGridTitle( string pProperty, string pTitle, int pSize, bool pClickable )
{
Property = pProperty;
Title = pTitle;
Size = pSize;
Info = null;
Clickable = pClickable;
}
}
/// <summary>
/// Class to convert the PDGridTitle object to and
/// from something editable via the Designer.
/// 041130 yky Created
/// Unfortunately the Title property is an ArrayList.
/// Not entirely sure on how to set this thing to editable.
/// Ref: 'Designer Intergration for ASP.NET Custom Controls' by Fritz Onion (DevelopMentor)
/// </summary>
public class PDGridTitleConverter: ExpandableObjectConverter // TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true;
else
return base.CanConvertFrom (context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if ( (destinationType == typeof(InstanceDescriptor)) ||
(destinationType == typeof(string)) )
return true;
return base.CanConvertTo (context, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
string vVal = value as string;
if (vVal != null)
{
string[] vArr = vVal.Split(',');
return new PDGridTitle( vArr[0], vArr[1], Convert.ToInt32(vArr[2]), Convert.ToBoolean( vArr[3] ) );
}
else
return base.ConvertFrom (context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
PDGridTitle vTitle = value as PDGridTitle;
if (destinationType == typeof(string))
{
return string.Format("{0},{1},{2},{3}",
vTitle.Property, vTitle.Title,
vTitle.Size, vTitle.Clickable );
}
else if (destinationType == typeof(InstanceDescriptor))
{
Type[] vParam = new Type[] { typeof(string), typeof(string), typeof(int), typeof(bool) };
object[] vVal = new object[] { vTitle.Property, vTitle.Title, vTitle.Size, vTitle.Clickable };
return new InstanceDescriptor( typeof(PDGridTitle).GetConstructor( vParam ), vVal );
}
return base.ConvertTo (context, culture, value, destinationType);
}
}
/* // 041201 yky Not sure why this doesnt work.
//[Serializable()]
public class PDGridTitleList: ArrayList
{
new public PDGridTitle this[ int index ]
{
get { return base[ index ] as PDGridTitle; }
set { base[index] = value; }
}
} */
// 041201 yky fobbed off wwWebTabControlList
public class PDGridTitleList : CollectionBase
{
public PDGridTitle this[int index]
{ get { return (PDGridTitle) this.List[index]; }
set { this.List[index] = value; }
}
public bool HasTitle( string pTitle )
{
foreach( PDGridTitle vTitle in List )
if (vTitle.Title == pTitle) return true;
return false;
}
public void Add(PDGridTitle pItem)
{ this.List.Add(pItem); }
public void Insert(int index, PDGridTitle pItem)
{ this.List.Insert(index,pItem); }
public void Remove(PDGridTitle pItem)
{ List.Remove(pItem); }
public bool Contains(PDGridTitle pItem)
{ return this.List.Contains(pItem); }
public int IndexOf(PDGridTitle pItem)
{ return List.IndexOf(pItem); }
public void CopyTo(PDGridTitle[] array, int index)
{ List.CopyTo(array, index); }
}
}
|