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
16 using System.Web.UI;
\r
17 using System.Drawing;
\r
18 using System.Collections.Specialized;
\r
20 namespace System.Web.UI.WebControls
\r
22 public class WebControl : Control, IAttributeAccessor
\r
24 //TODO: A list of private members may be incomplete
\r
26 private HtmlTextWriterTag writerTag;
\r
27 private string stringTag;
\r
28 private AttributeCollection attributes;
\r
29 private StateBag attributeState;
\r
30 private Style controlStyle;
\r
31 private bool enabled;
\r
32 private HtmlTextWriterTag tagKey;
\r
33 private string tagName;
\r
35 // TODO: The constructors definitions
\r
36 protected WebControl()
\r
38 //todo: what now? To be rendered as SPAN tag!
\r
43 public WebControl(HtmlTextWriterTag tag)
\r
45 //FIXME: am i right?
\r
52 protected WebControl(string tag)
\r
54 //FIXME: am i right?
\r
61 private void Initialize()
\r
63 controlStyle = null;
\r
66 attributeState = null;
\r
69 public virtual string AccessKey
\r
73 object o = ViewState["AccessKey"];
\r
76 return String.Empty;
\r
80 ViewState["AccessKey"] = value;
\r
84 public AttributeCollection Attributes
\r
88 throw new NotImplementedException("FIXME: \"Internal\" method calls");
\r
89 if(attributes==null)
\r
91 //TODO: From where to get StateBag and how? I think this method is OK!
\r
92 if(attributeState == null)
\r
94 attributeState = new StateBag(true);
\r
95 //FIXME: Uncomment the following in the final release
\r
96 // commented because of the assembly problem.
\r
97 //The function TrackViewState() is internal
\r
99 if(IsTrackingViewState)
\r
101 attributeState.TrackViewState();
\r
105 attributes = new AttributeCollection(attributeState);
\r
111 public Style ControlStyle
\r
115 throw new NotImplementedException("FIXME: \"Internal\" method calls");
\r
116 if(controlStyle == null)
\r
118 controlStyle = CreateControlStyle();
\r
119 //FIXME: Uncomment the following in the final release
\r
120 // commented because of the assembly problem.
\r
121 //The functions TrackViewState() and LoadViewState() are internal
\r
123 if(IsTrackingViewState)
\r
125 controlStyle.TrackViewState();
\r
127 controlStyle.LoadViewState(null);
\r
130 return controlStyle;
\r
134 public bool ControlStyleCreated
\r
138 return (controlStyle!=null);
\r
142 public virtual string CssClass
\r
146 return ControlStyle.CssClass;
\r
150 ControlStyle.CssClass = value;
\r
154 public virtual bool Enabled
\r
166 public virtual FontInfo Font
\r
170 return ControlStyle.Font;
\r
174 public virtual Color ForeColor
\r
178 return ControlStyle.ForeColor;
\r
182 ControlStyle.ForeColor = value;
\r
186 public virtual Unit Height
\r
190 return ControlStyle.Height;
\r
194 ControlStyle.Height = value;
\r
198 public CssStyleCollection Style
\r
202 return Attributes.CssStyle;
\r
206 public virtual short TabIndex
\r
210 object o = ViewState["TabIndex"];
\r
217 if(value < -32768 || value > 32767)
\r
218 throw new ArgumentException();
\r
219 ViewState["TabIndex"] = value;
\r
223 public virtual string ToolTip
\r
227 object o = ViewState["ToolTip"];
\r
230 return String.Empty;
\r
234 ViewState["ToolTip"] = value;
\r
238 public virtual Unit Width
\r
242 return ControlStyle.Width;
\r
246 ControlStyle.Width = value;
\r
250 public void ApplyStyle(Style s)
\r
252 /* FIXME: Again internal problem
\r
253 if(!ControlStyle.IsEmpty)
\r
256 ControlStyle.CopyFrom(s);
\r
258 throw new NotImplementedException("FIXME: \"Internal\" method calls");
\r
261 public void CopyBaseAttributes(WebControl controlSrc)
\r
265 * AccessKey, Enabled, ToolTip, TabIndex, Attributes
\r
267 AccessKey = controlSrc.AccessKey;
\r
268 Enabled = controlSrc.Enabled;
\r
269 ToolTip = controlSrc.ToolTip;
\r
270 TabIndex = controlSrc.TabIndex;
\r
271 Attributes = controlSrc.Attributes;
\r
272 throw new NotImplementedException();
\r
275 public void MergeStyle(Style s)
\r
277 ControlStyle.MergeWith(s);
\r
280 public virtual void RenderBeginTag(HtmlTextWriter writer)
\r
282 AddAttributesToRender(writer);
\r
285 writer.RenderBeginTag(TagKey);
\r
287 writer.RenderBeginTag(tagName);
\r
290 public virtual void RenderEndTag(HtmlTextWriter writer)
\r
292 writer.RenderEndTag();
\r
295 protected virtual HtmlTextWriterTag TagKey
\r
299 //FIXME: should I do new HtmlTextWriter()?
\r
300 throw new NotImplementedException();
\r
305 protected virtual string TagName
\r
313 //FIXME: If it is null, is this the right way? I don't think
\r
314 throw new NotImplementedException();
\r
315 tagKey = new HtmlTextWriter();
\r
317 tagName = Enum.Format(typeof(tagKey), tagKey, "G").ToLower();
\r
323 protected virtual void AddAttributesToRender(HtmlTextWriter writer)
\r
327 writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
\r
329 if(AccessKey.Length>0)
\r
331 writer.AddAttribute(HtmlTextWriterAttribute.AccessKey, AccessKey);
\r
335 writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
\r
337 if(ToolTip.Length>0)
\r
339 writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
\r
343 writer.AddAttribute(HtmlTextWriterAttribute.TabIndex, TabIndex.ToString());
\r
345 if(ControlStyleCreated)
\r
347 if(!ControlStyle.IsEmpty)
\r
349 ControlStyle.AddAttributesToRender(writer, this);
\r
352 if(attributeState!=null)
\r
354 IEnumerator ie = Attributes.Keys.GetEnumerator();
\r
357 writer.AddAttribute((string)ie.Current, Attributes.Item[(string)ie.Current]);
\r
358 } while(ie.MoveNext());
\r
362 protected virtual Style CreateControlStyle()
\r
364 return new Style(ViewState);
\r
367 protected override void LoadViewState(object savedState)
\r
369 throw new NotImplementedException();
\r
370 //TODO: Load viewStates
\r
372 * May be will have to first look at Control::LoadViewState
\r
376 protected override void Render(HtmlTextWriter writer)
\r
378 RenderBeginTag(writer);
\r
379 RenderContents(writer);
\r
380 RenderEngTags(writer);
\r
383 protected override void RenderContents(HtmlTextWriter writer)
\r
385 base.RenderContents(writer);
\r
388 protected override object SaveViewState()
\r
390 throw new NotImplementedException();
\r
391 //TODO: Implement me!
\r
394 protected override void TrackViewState()
\r
396 base.TrackViewState();
\r
397 if(ControlStyleCreated)
\r
399 ControlStyle.TrackViewState();
\r
401 if(attributeState!=null)
\r
403 attributeState.TrackViewState();
\r
407 // Implemented procedures
\r
408 //TODO: The scope of the functions - is public valid. Test thru Reflection
\r
409 string IAttributeAccessor.GetAttribute(string key)
\r
411 if(Attributes!=null)
\r
412 return (string)Attributes[key];
\r
415 void IAttributeAccessor.SetAttribute(string key, string val)
\r
417 Attributes[key] = value;
\r