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 [DefaultProperty("ID")]
\r
26 public class WebControl : Control, IAttributeAccessor
\r
28 //TODO: A list of private members may be incomplete
\r
30 private HtmlTextWriterTag tagKey;
\r
31 private string stringTag;
\r
32 private AttributeCollection attributes;
\r
33 private StateBag attributeState;
\r
34 private Style controlStyle;
\r
35 private bool enabled;
\r
36 private string tagName;
\r
38 // TODO: The constructors definitions
\r
39 protected WebControl () : this (HtmlTextWriterTag.Span)
\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
58 private void Initialize()
\r
60 controlStyle = null;
\r
62 tagName = stringTag;
\r
63 attributeState = null;
\r
66 public virtual string AccessKey
\r
70 object o = ViewState["AccessKey"];
\r
73 return String.Empty;
\r
77 ViewState["AccessKey"] = value;
\r
81 [MonoTODO("FIXME_Internal_method_calls")]
\r
82 public AttributeCollection Attributes
\r
86 if(attributes==null)
\r
88 //FIXME: From where to get StateBag and how? I think this method is OK!
\r
89 if(attributeState == null)
\r
91 attributeState = new StateBag(true);
\r
92 //FIXME: Uncomment the following in the final release
\r
93 // commented because of the assembly problem.
\r
94 //The function TrackViewState() is internal
\r
96 if(IsTrackingViewState)
\r
98 attributeState.TrackViewState();
\r
102 attributes = new AttributeCollection(attributeState);
\r
108 public virtual Color BackColor
\r
112 object o = ViewState["BackColor"];
\r
117 return Color.Empty;
\r
121 ViewState["BackColor"] = value;
\r
125 public virtual Color BorderColor
\r
129 object o = ViewState["BorderColor"];
\r
134 return Color.Empty;
\r
138 ViewState["BorderColor"] = value;
\r
142 [MonoTODO("FIXME_Internal_method_calls")]
\r
143 public virtual BorderStyle BorderStyle
\r
147 object o = ViewState["BorderStyle"];
\r
150 return (BorderStyle)o;
\r
152 return BorderStyle.NotSet;
\r
156 if(!Enum.IsDefined(typeof(BorderStyle), value))
\r
158 throw new ArgumentException();
\r
160 ViewState["BorderStyle"] = value;
\r
164 public virtual Unit BorderWidth
\r
168 object o = ViewState["BorderWidth"];
\r
177 if(value.Value < 0)
\r
179 throw new ArgumentException();
\r
181 ViewState["BorderWidth"] = value;
\r
185 [MonoTODO("FIXME_Internal_method_calls")]
\r
186 public Style ControlStyle
\r
190 if(controlStyle == null)
\r
192 controlStyle = CreateControlStyle();
\r
193 //FIXME: Uncomment the following in the final release
\r
194 // commented because of the assembly problem.
\r
195 //The functions TrackViewState() and LoadViewState() are internal
\r
197 if(IsTrackingViewState)
\r
199 controlStyle.TrackViewState();
\r
201 controlStyle.LoadViewState(null);
\r
204 return controlStyle;
\r
208 public bool ControlStyleCreated
\r
212 return (controlStyle!=null);
\r
216 public virtual string CssClass
\r
220 return ControlStyle.CssClass;
\r
224 ControlStyle.CssClass = value;
\r
228 public virtual bool Enabled
\r
240 public virtual FontInfo Font
\r
244 return ControlStyle.Font;
\r
248 public virtual Color ForeColor
\r
252 return ControlStyle.ForeColor;
\r
256 ControlStyle.ForeColor = value;
\r
260 public virtual Unit Height
\r
264 return ControlStyle.Height;
\r
268 ControlStyle.Height = value;
\r
272 public CssStyleCollection Style
\r
276 return Attributes.CssStyle;
\r
280 public virtual short TabIndex
\r
284 object o = ViewState["TabIndex"];
\r
291 if(value < -32768 || value > 32767)
\r
292 throw new ArgumentException();
\r
293 ViewState["TabIndex"] = value;
\r
297 public virtual string ToolTip
\r
301 object o = ViewState["ToolTip"];
\r
304 return String.Empty;
\r
308 ViewState["ToolTip"] = value;
\r
312 public virtual Unit Width
\r
316 return ControlStyle.Width;
\r
320 ControlStyle.Width = value;
\r
324 [MonoTODO("FIXME_Internal_method_calls")]
\r
325 public void ApplyStyle(Style s)
\r
327 /* FIXME: Again internal problem
\r
328 if(!ControlStyle.IsEmpty)
\r
331 ControlStyle.CopyFrom(s);
\r
335 public void CopyBaseAttributes(WebControl controlSrc)
\r
338 * AccessKey, Enabled, ToolTip, TabIndex, Attributes
\r
340 AccessKey = controlSrc.AccessKey;
\r
341 Enabled = controlSrc.Enabled;
\r
342 ToolTip = controlSrc.ToolTip;
\r
343 TabIndex = controlSrc.TabIndex;
\r
344 attributes = controlSrc.Attributes;
\r
345 AttributeCollection otherAtt = controlSrc.Attributes;
\r
346 foreach (string key in controlSrc.Attributes.Keys)
\r
347 Attributes [key] = otherAtt [key];
\r
350 public void MergeStyle(Style s)
\r
352 ControlStyle.MergeWith(s);
\r
355 public virtual void RenderBeginTag(HtmlTextWriter writer)
\r
357 AddAttributesToRender(writer);
\r
358 writer.RenderBeginTag(TagName);
\r
361 public virtual void RenderEndTag(HtmlTextWriter writer)
\r
363 writer.RenderEndTag();
\r
366 protected virtual HtmlTextWriterTag TagKey
\r
374 protected virtual string TagName
\r
378 if(tagName == null && TagKey != 0)
\r
380 tagName = Enum.Format(typeof(HtmlTextWriterTag), TagKey, "G").ToString();
\r
382 // What if tagName is null and tagKey 0?
\r
387 protected virtual void AddAttributesToRender(HtmlTextWriter writer)
\r
390 Page.VerifyRenderingInServerForm (this);
\r
394 writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
\r
396 if(AccessKey.Length>0)
\r
398 writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
\r
402 writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
\r
404 if(ToolTip.Length>0)
\r
406 writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
\r
410 writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, TabIndex.ToString());
\r
412 if(ControlStyleCreated)
\r
414 if(!ControlStyle.IsEmpty)
\r
416 ControlStyle.AddAttributesToRender(writer, this);
\r
419 if(attributeState != null){
\r
420 IEnumerator ie = Attributes.Keys.GetEnumerator ();
\r
421 while (ie.MoveNext ()){
\r
422 string key = (string) ie.Current;
\r
423 writer.AddAttribute (key, Attributes [key]);
\r
428 protected virtual Style CreateControlStyle()
\r
430 return new Style(ViewState);
\r
434 protected override void LoadViewState(object savedState)
\r
436 throw new NotImplementedException();
\r
437 //TODO: Load viewStates
\r
439 * May be will have to first look at Control::LoadViewState
\r
443 protected override void Render(HtmlTextWriter writer)
\r
445 RenderBeginTag(writer);
\r
446 RenderContents(writer);
\r
447 RenderEndTag(writer);
\r
450 protected virtual void RenderContents(HtmlTextWriter writer)
\r
452 base.Render(writer);
\r
456 protected override object SaveViewState()
\r
458 throw new NotImplementedException();
\r
459 //TODO: Implement me!
\r
462 protected override void TrackViewState()
\r
465 if(ControlStyleCreated)
\r
467 ControlStyle.TrackViewState();
\r
469 if(attributeState!=null)
\r
471 attributeState.TrackViewState();
\r
475 string IAttributeAccessor.GetAttribute(string key)
\r
477 if(Attributes!=null)
\r
478 return (string)Attributes[key];
\r
482 void IAttributeAccessor.SetAttribute(string key, string value)
\r
484 Attributes[key] = value;
\r