| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- /**
- * Namespace: System.Web.UI.WebControls
- * Class: WebControl
- *
- * Author: Gaurav Vaish
- * Maintainer: [email protected]
- * Contact: <[email protected]>, <[email protected]>
- * Implementation: yes
- * Status: 40%
- *
- * (C) Gaurav Vaish (2001)
- */
- using System;
- using System.Collections;
- using System.Web;
- using System.Web.UI;
- using System.Drawing;
- using System.Collections.Specialized;
- namespace System.Web.UI.WebControls
- {
- public class WebControl : Control, IAttributeAccessor
- {
- //TODO: A list of private members may be incomplete
- private HtmlTextWriterTag tagKey;
- private string stringTag;
- private AttributeCollection attributes;
- private StateBag attributeState;
- private Style controlStyle;
- private bool enabled;
- private string tagName;
- // TODO: The constructors definitions
- protected WebControl(): base()
- {
- //todo: what now? To be rendered as SPAN tag!
- Initialize();
- }
- public WebControl(HtmlTextWriterTag tag): base()
- {
- //FIXME: am i right?
- tagKey = tag;
- //stringTag = null;
- Initialize();
- }
- protected WebControl(string tag): base()
- {
- //FIXME: am i right?
- stringTag = tag;
- Initialize();
- }
- private void Initialize()
- {
- controlStyle = null;
- enabled = true;
- tagName = null;
- attributeState = null;
- }
- public virtual string AccessKey
- {
- get
- {
- object o = ViewState["AccessKey"];
- if(o!=null)
- return (string)o;
- return String.Empty;
- }
- set
- {
- ViewState["AccessKey"] = value;
- }
- }
- [MonoTODO("FIXME_Internal_method_calls")]
- public AttributeCollection Attributes
- {
- get
- {
- throw new NotImplementedException();
- if(attributes==null)
- {
- //FIXME: From where to get StateBag and how? I think this method is OK!
- if(attributeState == null)
- {
- attributeState = new StateBag(true);
- //FIXME: Uncomment the following in the final release
- // commented because of the assembly problem.
- //The function TrackViewState() is internal
- /*
- if(IsTrackingViewState)
- {
- attributeState.TrackViewState();
- }
- */
- }
- attributes = new AttributeCollection(attributeState);
- }
- return attributes;
- }
- }
- public virtual Color BackColor
- {
- get
- {
- object o = ViewState["BackColor"];
- if(o != null)
- {
- return (Color)o;
- }
- return Color.Empty;
- }
- set
- {
- ViewState["BackColor"] = value;
- }
- }
- public virtual Color BorderColor
- {
- get
- {
- object o = ViewState["BorderColor"];
- if(o != null)
- {
- return (Color)o;
- }
- return Color.Empty;
- }
- set
- {
- ViewState["BorderColor"] = value;
- }
- }
- [MonoTODO("FIXME_Internal_method_calls")]
- public virtual BorderStyle BorderStyle
- {
- get
- {
- object o = ViewState["BorderStyle"];
- if(o != null)
- {
- return (BorderStyle)o;
- }
- return BorderStyle.NotSet;
- }
- set
- {
- if(!Enum.IsDefined(typeof(BorderStyle), value))
- {
- throw new ArgumentException();
- }
- ViewState["BorderStyle"] = value;
- }
- }
- public virtual Unit BorderWidth
- {
- get
- {
- object o = ViewState["BorderWidth"];
- if(o != null)
- {
- return (Unit)o;
- }
- return Unit.Empty;
- }
- set
- {
- if(value.Value < 0)
- {
- throw new ArgumentException();
- }
- ViewState["BorderWidth"] = value;
- }
- }
- [MonoTODO("FIXME_Internal_method_calls")]
- public virtual Style ControlStyle
- {
- get
- {
- if(controlStyle == null)
- {
- controlStyle = CreateControlStyle();
- //FIXME: Uncomment the following in the final release
- // commented because of the assembly problem.
- //The functions TrackViewState() and LoadViewState() are internal
- /*
- if(IsTrackingViewState)
- {
- controlStyle.TrackViewState();
- }
- controlStyle.LoadViewState(null);
- */
- }
- return controlStyle;
- }
- }
- public bool ControlStyleCreated
- {
- get
- {
- return (controlStyle!=null);
- }
- }
- public virtual string CssClass
- {
- get
- {
- return ControlStyle.CssClass;
- }
- set
- {
- ControlStyle.CssClass = value;
- }
- }
- public virtual bool Enabled
- {
- get
- {
- return enabled;
- }
- set
- {
- enabled = value;
- }
- }
- public virtual FontInfo Font
- {
- get
- {
- return ControlStyle.Font;
- }
- }
- public virtual Color ForeColor
- {
- get
- {
- return ControlStyle.ForeColor;
- }
- set
- {
- ControlStyle.ForeColor = value;
- }
- }
- public virtual Unit Height
- {
- get
- {
- return ControlStyle.Height;
- }
- set
- {
- ControlStyle.Height = value;
- }
- }
- public CssStyleCollection Style
- {
- get
- {
- return Attributes.CssStyle;
- }
- }
- public virtual short TabIndex
- {
- get
- {
- object o = ViewState["TabIndex"];
- if(o!=null)
- return (short)o;
- return 0;
- }
- set
- {
- if(value < -32768 || value > 32767)
- throw new ArgumentException();
- ViewState["TabIndex"] = value;
- }
- }
- public virtual string ToolTip
- {
- get
- {
- object o = ViewState["ToolTip"];
- if(o!=null)
- return (string)o;
- return String.Empty;
- }
- set
- {
- ViewState["ToolTip"] = value;
- }
- }
- public virtual Unit Width
- {
- get
- {
- return ControlStyle.Width;
- }
- set
- {
- ControlStyle.Width = value;
- }
- }
- [MonoTODO("FIXME_Internal_method_calls")]
- public void ApplyStyle(Style s)
- {
- /* FIXME: Again internal problem
- if(!ControlStyle.IsEmpty)
- {
- */
- ControlStyle.CopyFrom(s);
- //}
- }
- [MonoTODO]
- public void CopyBaseAttributes(WebControl controlSrc)
- {
- //TODO: tocopy
- /*
- * AccessKey, Enabled, ToolTip, TabIndex, Attributes
- */
- AccessKey = controlSrc.AccessKey;
- Enabled = controlSrc.Enabled;
- ToolTip = controlSrc.ToolTip;
- TabIndex = controlSrc.TabIndex;
- attributes = controlSrc.Attributes;
- throw new NotImplementedException();
- }
- public void MergeStyle(Style s)
- {
- ControlStyle.MergeWith(s);
- }
- public virtual void RenderBeginTag(HtmlTextWriter writer)
- {
- AddAttributesToRender(writer);
- if(Enum.IsDefined(typeof(HtmlTextWriterTag), TagKey) )
- {
- writer.RenderBeginTag(TagKey);
- return;
- }
- writer.RenderBeginTag(tagName);
- }
- public virtual void RenderEndTag(HtmlTextWriter writer)
- {
- writer.RenderEndTag();
- }
- protected virtual HtmlTextWriterTag TagKey
- {
- get
- {
- return tagKey;
- }
- }
- protected virtual string TagName
- {
- get
- {
- if(tagName==null && Enum.IsDefined(typeof(HtmlTextWriterTag), tagKey) )
- {
- tagName = Enum.Format(typeof(HtmlTextWriterTag), tagKey, "G").ToString();
- }
- return tagName;
- }
- }
- protected virtual void AddAttributesToRender(HtmlTextWriter writer)
- {
- if(ID!=null)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
- }
- if(AccessKey.Length>0)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
- }
- if(!Enabled)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
- }
- if(ToolTip.Length>0)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
- }
- if(TabIndex != 0)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, TabIndex.ToString());
- }
- if(ControlStyleCreated)
- {
- if(!ControlStyle.IsEmpty)
- {
- ControlStyle.AddAttributesToRender(writer, this);
- }
- }
- if(attributeState!=null)
- {
- IEnumerator ie = Attributes.Keys.GetEnumerator();
- do
- {
- writer.AddAttribute((string)ie.Current, Attributes[(string)ie.Current]);
- } while(ie.MoveNext());
- }
- }
- protected virtual Style CreateControlStyle()
- {
- return new Style(ViewState);
- }
- [MonoTODO]
- protected override void LoadViewState(object savedState)
- {
- throw new NotImplementedException();
- //TODO: Load viewStates
- /*
- * May be will have to first look at Control::LoadViewState
- */
- }
- protected override void Render(HtmlTextWriter writer)
- {
- RenderBeginTag(writer);
- RenderContents(writer);
- RenderEndTag(writer);
- }
- protected virtual void RenderContents(HtmlTextWriter writer)
- {
- base.Render(writer);
- }
- [MonoTODO]
- protected override object SaveViewState()
- {
- throw new NotImplementedException();
- //TODO: Implement me!
- }
- protected override void TrackViewState()
- {
- TrackViewState();
- if(ControlStyleCreated)
- {
- ControlStyle.TrackViewState();
- }
- if(attributeState!=null)
- {
- attributeState.TrackViewState();
- }
- }
- string IAttributeAccessor.GetAttribute(string key)
- {
- if(Attributes!=null)
- return (string)Attributes[key];
- return null;
- }
- void IAttributeAccessor.SetAttribute(string key, string value)
- {
- Attributes[key] = value;
- }
- }
- }
|