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 [PersistChildrenAttribute(false)]
\r
24 [ParseChildrenAttribute(true)]
\r
25 public class WebControl : Control, IAttributeAccessor
\r
27 //TODO: A list of private members may be incomplete
\r
29 private HtmlTextWriterTag tagKey;
\r
30 private string stringTag;
\r
31 private AttributeCollection attributes;
\r
32 private StateBag attributeState;
\r
33 private Style controlStyle;
\r
34 private bool enabled;
\r
35 private string tagName;
\r
37 // TODO: The constructors definitions
\r
38 protected WebControl () : this (HtmlTextWriterTag.Span)
\r
42 public WebControl(HtmlTextWriterTag tag): base()
\r
44 //FIXME: am i right?
\r
50 protected WebControl(string tag): base()
\r
52 //FIXME: am i right?
\r
57 private void Initialize()
\r
59 controlStyle = null;
\r
61 tagName = stringTag;
\r
62 attributeState = null;
\r
65 public virtual string AccessKey
\r
69 object o = ViewState["AccessKey"];
\r
72 return String.Empty;
\r
76 ViewState["AccessKey"] = value;
\r
80 [MonoTODO("FIXME_Internal_method_calls")]
\r
81 public AttributeCollection Attributes
\r
85 if(attributes==null)
\r
87 //FIXME: From where to get StateBag and how? I think this method is OK!
\r
88 if(attributeState == null)
\r
90 attributeState = new StateBag(true);
\r
91 //FIXME: Uncomment the following in the final release
\r
92 // commented because of the assembly problem.
\r
93 //The function TrackViewState() is internal
\r
95 if(IsTrackingViewState)
\r
97 attributeState.TrackViewState();
\r
101 attributes = new AttributeCollection(attributeState);
\r
107 public virtual Color BackColor
\r
111 object o = ViewState["BackColor"];
\r
116 return Color.Empty;
\r
120 ViewState["BackColor"] = value;
\r
124 public virtual Color BorderColor
\r
128 object o = ViewState["BorderColor"];
\r
133 return Color.Empty;
\r
137 ViewState["BorderColor"] = value;
\r
141 [MonoTODO("FIXME_Internal_method_calls")]
\r
142 public virtual BorderStyle BorderStyle
\r
146 object o = ViewState["BorderStyle"];
\r
149 return (BorderStyle)o;
\r
151 return BorderStyle.NotSet;
\r
155 if(!Enum.IsDefined(typeof(BorderStyle), value))
\r
157 throw new ArgumentException();
\r
159 ViewState["BorderStyle"] = value;
\r
163 public virtual Unit BorderWidth
\r
167 object o = ViewState["BorderWidth"];
\r
176 if(value.Value < 0)
\r
178 throw new ArgumentException();
\r
180 ViewState["BorderWidth"] = value;
\r
184 [MonoTODO("FIXME_Internal_method_calls")]
\r
185 public virtual Style ControlStyle
\r
189 if(controlStyle == null)
\r
191 controlStyle = CreateControlStyle();
\r
192 //FIXME: Uncomment the following in the final release
\r
193 // commented because of the assembly problem.
\r
194 //The functions TrackViewState() and LoadViewState() are internal
\r
196 if(IsTrackingViewState)
\r
198 controlStyle.TrackViewState();
\r
200 controlStyle.LoadViewState(null);
\r
203 return controlStyle;
\r
207 public bool ControlStyleCreated
\r
211 return (controlStyle!=null);
\r
215 public virtual string CssClass
\r
219 return ControlStyle.CssClass;
\r
223 ControlStyle.CssClass = value;
\r
227 public virtual bool Enabled
\r
239 public virtual FontInfo Font
\r
243 return ControlStyle.Font;
\r
247 public virtual Color ForeColor
\r
251 return ControlStyle.ForeColor;
\r
255 ControlStyle.ForeColor = value;
\r
259 public virtual Unit Height
\r
263 return ControlStyle.Height;
\r
267 ControlStyle.Height = value;
\r
271 public CssStyleCollection Style
\r
275 return Attributes.CssStyle;
\r
279 public virtual short TabIndex
\r
283 object o = ViewState["TabIndex"];
\r
290 if(value < -32768 || value > 32767)
\r
291 throw new ArgumentException();
\r
292 ViewState["TabIndex"] = value;
\r
296 public virtual string ToolTip
\r
300 object o = ViewState["ToolTip"];
\r
303 return String.Empty;
\r
307 ViewState["ToolTip"] = value;
\r
311 public virtual Unit Width
\r
315 return ControlStyle.Width;
\r
319 ControlStyle.Width = value;
\r
323 [MonoTODO("FIXME_Internal_method_calls")]
\r
324 public void ApplyStyle(Style s)
\r
326 /* FIXME: Again internal problem
\r
327 if(!ControlStyle.IsEmpty)
\r
330 ControlStyle.CopyFrom(s);
\r
335 public void CopyBaseAttributes(WebControl controlSrc)
\r
339 * AccessKey, Enabled, ToolTip, TabIndex, Attributes
\r
341 AccessKey = controlSrc.AccessKey;
\r
342 Enabled = controlSrc.Enabled;
\r
343 ToolTip = controlSrc.ToolTip;
\r
344 TabIndex = controlSrc.TabIndex;
\r
345 attributes = controlSrc.Attributes;
\r
346 throw new NotImplementedException();
\r
349 public void MergeStyle(Style s)
\r
351 ControlStyle.MergeWith(s);
\r
354 public virtual void RenderBeginTag(HtmlTextWriter writer)
\r
356 AddAttributesToRender(writer);
\r
357 writer.RenderBeginTag(TagName);
\r
360 public virtual void RenderEndTag(HtmlTextWriter writer)
\r
362 writer.RenderEndTag();
\r
365 protected virtual HtmlTextWriterTag TagKey
\r
373 protected virtual string TagName
\r
377 if(tagName == null && tagKey != 0)
\r
379 tagName = Enum.Format(typeof(HtmlTextWriterTag), tagKey, "G").ToString();
\r
381 // What if tagName is null and tagKey 0?
\r
386 protected virtual void AddAttributesToRender(HtmlTextWriter writer)
\r
390 writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
\r
392 if(AccessKey.Length>0)
\r
394 writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
\r
398 writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
\r
400 if(ToolTip.Length>0)
\r
402 writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
\r
406 writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, TabIndex.ToString());
\r
408 if(ControlStyleCreated)
\r
410 if(!ControlStyle.IsEmpty)
\r
412 ControlStyle.AddAttributesToRender(writer, this);
\r
415 if(attributeState!=null)
\r
417 IEnumerator ie = Attributes.Keys.GetEnumerator();
\r
420 writer.AddAttribute((string)ie.Current, Attributes[(string)ie.Current]);
\r
421 } while(ie.MoveNext());
\r
425 protected virtual Style CreateControlStyle()
\r
427 return new Style(ViewState);
\r
431 protected override void LoadViewState(object savedState)
\r
433 throw new NotImplementedException();
\r
434 //TODO: Load viewStates
\r
436 * May be will have to first look at Control::LoadViewState
\r
440 protected override void Render(HtmlTextWriter writer)
\r
442 RenderBeginTag(writer);
\r
443 RenderContents(writer);
\r
444 RenderEndTag(writer);
\r
447 protected virtual void RenderContents(HtmlTextWriter writer)
\r
449 base.Render(writer);
\r
453 protected override object SaveViewState()
\r
455 throw new NotImplementedException();
\r
456 //TODO: Implement me!
\r
459 protected override void TrackViewState()
\r
462 if(ControlStyleCreated)
\r
464 ControlStyle.TrackViewState();
\r
466 if(attributeState!=null)
\r
468 attributeState.TrackViewState();
\r
472 string IAttributeAccessor.GetAttribute(string key)
\r
474 if(Attributes!=null)
\r
475 return (string)Attributes[key];
\r
479 void IAttributeAccessor.SetAttribute(string key, string value)
\r
481 Attributes[key] = value;
\r