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 borderStyle;
\r
32 private Style controlStyle;
\r
33 private bool enabled;
\r
34 private HtmlTextWriterTag tagKey;
\r
35 private string tagName;
\r
37 // TODO: The constructors definitions
\r
38 protected WebControl(): base()
\r
40 //todo: what now? To be rendered as SPAN tag!
\r
44 public WebControl(HtmlTextWriterTag tag): base()
\r
46 //FIXME: am i right?
\r
52 protected WebControl(string tag): base()
\r
54 //FIXME: am i right?
\r
60 private void Initialize()
\r
62 controlStyle = null;
\r
65 attributeState = null;
\r
68 public virtual string AccessKey
\r
72 object o = ViewState["AccessKey"];
\r
75 return String.Empty;
\r
79 ViewState["AccessKey"] = value;
\r
83 [MonoTODO("FIXME_Internal_method_calls")]
\r
84 public AttributeCollection Attributes
\r
88 throw new NotImplementedException();
\r
89 if(attributes==null)
\r
91 //FIXME: 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 virtual Color BackColor
\r
115 object o = ViewState["BackColor"];
\r
120 return Color.Empty;
\r
124 ViewState["BackColor"] = value;
\r
128 public virtual Color BorderColor
\r
132 object o = ViewState["BorderColor"];
\r
137 return Color.Empty;
\r
141 ViewState["BorderColor"] = value;
\r
145 [MonoTODO("FIXME_Internal_method_calls")]
\r
146 public virtual Style BorderStyle
\r
150 return borderStyle;
\r
154 borderStyle = value;
\r
158 public virtual Unit BorderWidth
\r
162 object o = ViewState["BorderWidth"];
\r
171 if(value.Value < 0)
\r
173 throw new ArgumentException();
\r
175 ViewState["BorderWidth"] = value;
\r
179 [MonoTODO("FIXME_Internal_method_calls")]
\r
180 public virtual Style ControlStyle
\r
184 if(controlStyle == null)
\r
186 controlStyle = CreateControlStyle();
\r
187 //FIXME: Uncomment the following in the final release
\r
188 // commented because of the assembly problem.
\r
189 //The functions TrackViewState() and LoadViewState() are internal
\r
191 if(IsTrackingViewState)
\r
193 controlStyle.TrackViewState();
\r
195 controlStyle.LoadViewState(null);
\r
198 return controlStyle;
\r
202 public bool ControlStyleCreated
\r
206 return (controlStyle!=null);
\r
210 public virtual string CssClass
\r
214 return ControlStyle.CssClass;
\r
218 ControlStyle.CssClass = value;
\r
222 public virtual bool Enabled
\r
234 public virtual FontInfo Font
\r
238 return ControlStyle.Font;
\r
242 public virtual Color ForeColor
\r
246 return ControlStyle.ForeColor;
\r
250 ControlStyle.ForeColor = value;
\r
254 public virtual Unit Height
\r
258 return ControlStyle.Height;
\r
262 ControlStyle.Height = value;
\r
266 public CssStyleCollection Style
\r
270 return Attributes.CssStyle;
\r
274 public virtual short TabIndex
\r
278 object o = ViewState["TabIndex"];
\r
285 if(value < -32768 || value > 32767)
\r
286 throw new ArgumentException();
\r
287 ViewState["TabIndex"] = value;
\r
291 public virtual string ToolTip
\r
295 object o = ViewState["ToolTip"];
\r
298 return String.Empty;
\r
302 ViewState["ToolTip"] = value;
\r
306 public virtual Unit Width
\r
310 return ControlStyle.Width;
\r
314 ControlStyle.Width = value;
\r
318 [MonoTODO("FIXME_Internal_method_calls")]
\r
319 public void ApplyStyle(Style s)
\r
321 /* FIXME: Again internal problem
\r
322 if(!ControlStyle.IsEmpty)
\r
325 ControlStyle.CopyFrom(s);
\r
330 public void CopyBaseAttributes(WebControl controlSrc)
\r
334 * AccessKey, Enabled, ToolTip, TabIndex, Attributes
\r
336 AccessKey = controlSrc.AccessKey;
\r
337 Enabled = controlSrc.Enabled;
\r
338 ToolTip = controlSrc.ToolTip;
\r
339 TabIndex = controlSrc.TabIndex;
\r
340 attributes = controlSrc.Attributes;
\r
341 throw new NotImplementedException();
\r
344 public void MergeStyle(Style s)
\r
346 ControlStyle.MergeWith(s);
\r
349 public virtual void RenderBeginTag(HtmlTextWriter writer)
\r
351 AddAttributesToRender(writer);
\r
352 if(Enum.IsDefined(typeof(HtmlTextWriterTag), TagKey) )
\r
354 writer.RenderBeginTag(TagKey);
\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 && Enum.IsDefined(typeof(HtmlTextWriterTag), tagKey) )
\r
379 tagName = Enum.Format(typeof(HtmlTextWriterTag), tagKey, "G").ToString();
\r
385 protected virtual void AddAttributesToRender(HtmlTextWriter writer)
\r
389 writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
\r
391 if(AccessKey.Length>0)
\r
393 writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
\r
397 writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
\r
399 if(ToolTip.Length>0)
\r
401 writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
\r
405 writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, TabIndex.ToString());
\r
407 if(ControlStyleCreated)
\r
409 if(!ControlStyle.IsEmpty)
\r
411 ControlStyle.AddAttributesToRender(writer, this);
\r
414 if(attributeState!=null)
\r
416 IEnumerator ie = Attributes.Keys.GetEnumerator();
\r
419 writer.AddAttribute((string)ie.Current, Attributes[(string)ie.Current]);
\r
420 } while(ie.MoveNext());
\r
424 protected virtual Style CreateControlStyle()
\r
426 return new Style(ViewState);
\r
430 protected override void LoadViewState(object savedState)
\r
432 throw new NotImplementedException();
\r
433 //TODO: Load viewStates
\r
435 * May be will have to first look at Control::LoadViewState
\r
439 protected override void Render(HtmlTextWriter writer)
\r
441 RenderBeginTag(writer);
\r
442 RenderContents(writer);
\r
443 RenderEndTag(writer);
\r
446 protected virtual void RenderContents(HtmlTextWriter writer)
\r
448 base.Render(writer);
\r
452 protected override object SaveViewState()
\r
454 throw new NotImplementedException();
\r
455 //TODO: Implement me!
\r
458 protected override void TrackViewState()
\r
461 if(ControlStyleCreated)
\r
463 ControlStyle.TrackViewState();
\r
465 if(attributeState!=null)
\r
467 attributeState.TrackViewState();
\r
471 string IAttributeAccessor.GetAttribute(string key)
\r
473 if(Attributes!=null)
\r
474 return (string)Attributes[key];
\r
478 void IAttributeAccessor.SetAttribute(string key, string value)
\r
480 Attributes[key] = value;
\r