2 * Namespace: System.Web.UI.WebControls
\r
5 * Author: Gaurav Vaish
\r
6 * Maintainer: gvaish@iitk.ac.in
\r
7 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
\r
8 * Implementation: yes
\r
11 * (C) Gaurav Vaish (2001)
\r
15 using System.Collections;
\r
17 using System.Web.UI;
\r
18 using System.Drawing;
\r
19 using System.Collections.Specialized;
\r
21 namespace System.Web.UI.WebControls
\r
23 public class WebControl : Control, IAttributeAccessor
\r
25 //TODO: A list of private members may be incomplete
\r
27 private HtmlTextWriterTag writerTag;
\r
28 private string stringTag;
\r
29 private AttributeCollection attributes;
\r
30 private StateBag attributeState;
\r
31 private Style controlStyle;
\r
32 private bool enabled;
\r
33 private HtmlTextWriterTag tagKey;
\r
34 private string tagName;
\r
36 // TODO: The constructors definitions
\r
37 protected WebControl(): base()
\r
39 //todo: what now? To be rendered as SPAN tag!
\r
43 public WebControl(HtmlTextWriterTag tag): base()
\r
45 //FIXME: am i right?
\r
51 protected WebControl(string tag): base()
\r
53 //FIXME: am i right?
\r
59 private void Initialize()
\r
61 controlStyle = null;
\r
64 attributeState = null;
\r
67 public virtual string AccessKey
\r
71 object o = ViewState["AccessKey"];
\r
74 return String.Empty;
\r
78 ViewState["AccessKey"] = value;
\r
82 public AttributeCollection Attributes
\r
86 throw new NotImplementedException("FIXME: \"Internal\" method calls");
\r
87 if(attributes==null)
\r
89 //TODO: From where to get StateBag and how? I think this method is OK!
\r
90 if(attributeState == null)
\r
92 attributeState = new StateBag(true);
\r
93 //FIXME: Uncomment the following in the final release
\r
94 // commented because of the assembly problem.
\r
95 //The function TrackViewState() is internal
\r
97 if(IsTrackingViewState)
\r
99 attributeState.TrackViewState();
\r
103 attributes = new AttributeCollection(attributeState);
\r
109 public Style ControlStyle
\r
113 throw new NotImplementedException("FIXME: \"Internal\" method calls");
\r
114 if(controlStyle == null)
\r
116 controlStyle = CreateControlStyle();
\r
117 //FIXME: Uncomment the following in the final release
\r
118 // commented because of the assembly problem.
\r
119 //The functions TrackViewState() and LoadViewState() are internal
\r
121 if(IsTrackingViewState)
\r
123 controlStyle.TrackViewState();
\r
125 controlStyle.LoadViewState(null);
\r
128 return controlStyle;
\r
132 public bool ControlStyleCreated
\r
136 return (controlStyle!=null);
\r
140 public virtual string CssClass
\r
144 return ControlStyle.CssClass;
\r
148 ControlStyle.CssClass = value;
\r
152 public virtual bool Enabled
\r
164 public virtual FontInfo Font
\r
168 return ControlStyle.Font;
\r
172 public virtual Color ForeColor
\r
176 return ControlStyle.ForeColor;
\r
180 ControlStyle.ForeColor = value;
\r
184 public virtual Unit Height
\r
188 return ControlStyle.Height;
\r
192 ControlStyle.Height = value;
\r
196 public CssStyleCollection Style
\r
200 return Attributes.CssStyle;
\r
204 public virtual short TabIndex
\r
208 object o = ViewState["TabIndex"];
\r
215 if(value < -32768 || value > 32767)
\r
216 throw new ArgumentException();
\r
217 ViewState["TabIndex"] = value;
\r
221 public virtual string ToolTip
\r
225 object o = ViewState["ToolTip"];
\r
228 return String.Empty;
\r
232 ViewState["ToolTip"] = value;
\r
236 public virtual Unit Width
\r
240 return ControlStyle.Width;
\r
244 ControlStyle.Width = value;
\r
248 public void ApplyStyle(Style s)
\r
250 /* FIXME: Again internal problem
\r
251 if(!ControlStyle.IsEmpty)
\r
254 ControlStyle.CopyFrom(s);
\r
256 throw new NotImplementedException("FIXME: \"Internal\" method calls");
\r
259 public void CopyBaseAttributes(WebControl controlSrc)
\r
263 * AccessKey, Enabled, ToolTip, TabIndex, Attributes
\r
265 AccessKey = controlSrc.AccessKey;
\r
266 Enabled = controlSrc.Enabled;
\r
267 ToolTip = controlSrc.ToolTip;
\r
268 TabIndex = controlSrc.TabIndex;
\r
269 attributes = controlSrc.Attributes;
\r
270 throw new NotImplementedException();
\r
273 public void MergeStyle(Style s)
\r
275 ControlStyle.MergeWith(s);
\r
278 public virtual void RenderBeginTag(HtmlTextWriter writer)
\r
280 AddAttributesToRender(writer);
\r
281 if( Enum.IsDefined(typeof(HtmlTextWriterTag), TagKey) )
\r
283 writer.RenderBeginTag(TagKey);
\r
286 writer.RenderBeginTag(tagName);
\r
289 public virtual void RenderEndTag(HtmlTextWriter writer)
\r
291 writer.RenderEndTag();
\r
294 protected virtual HtmlTextWriterTag TagKey
\r
302 protected virtual string TagName
\r
306 if(tagName==null && Enum.IsDefined(typeof(HtmlTextWriterTag), TagKey) )
\r
308 tagName = Enum.Format(typeof(HtmlTextWriterTag), tagKey, "G").ToString();
\r
314 protected virtual void AddAttributesToRender(HtmlTextWriter writer)
\r
318 writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
\r
320 if(AccessKey.Length>0)
\r
322 writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
\r
326 writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
\r
328 if(ToolTip.Length>0)
\r
330 writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
\r
334 writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, TabIndex.ToString());
\r
336 if(ControlStyleCreated)
\r
338 if(!ControlStyle.IsEmpty)
\r
340 ControlStyle.AddAttributesToRender(writer, this);
\r
343 if(attributeState!=null)
\r
345 IEnumerator ie = Attributes.Keys.GetEnumerator();
\r
348 writer.AddAttribute((string)ie.Current, Attributes[(string)ie.Current]);
\r
349 } while(ie.MoveNext());
\r
353 protected virtual Style CreateControlStyle()
\r
355 return new Style(ViewState);
\r
358 protected override void LoadViewState(object savedState)
\r
360 throw new NotImplementedException();
\r
361 //TODO: Load viewStates
\r
363 * May be will have to first look at Control::LoadViewState
\r
367 protected override void Render(HtmlTextWriter writer)
\r
369 RenderBeginTag(writer);
\r
370 RenderContents(writer);
\r
371 RenderEndTag(writer);
\r
374 protected virtual void RenderContents(HtmlTextWriter writer)
\r
376 base.Render(writer);
\r
379 protected override object SaveViewState()
\r
381 throw new NotImplementedException();
\r
382 //TODO: Implement me!
\r
385 protected override void TrackViewState()
\r
387 base.TrackViewState();
\r
388 if(ControlStyleCreated)
\r
390 ControlStyle.TrackViewState();
\r
392 if(attributeState!=null)
\r
394 attributeState.TrackViewState();
\r
398 // Implemented procedures
\r
399 //TODO: The scope of the functions - is public valid. Test thru Reflection
\r
400 string IAttributeAccessor.GetAttribute(string key)
\r
402 if(Attributes!=null)
\r
403 return (string)Attributes[key];
\r
407 void IAttributeAccessor.SetAttribute(string key, string value)
\r
409 Attributes[key] = value;
\r