| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880 |
- //
- // System.Web.UI.Control.cs
- //
- // Authors:
- // Bob Smith <[email protected]>
- // Gonzalo Paniagua Javier ([email protected]
- // Andreas Nahr ([email protected])
- // Sanjay Gupta ([email protected])
- //
- // (C) Bob Smith
- // (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
- // (C) 2004 Novell, Inc. (http://www.novell.com)
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System.Collections;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.ComponentModel.Design.Serialization;
- using System.Security.Permissions;
- using System.Web;
- using System.Web.Util;
- using System.Globalization;
- #if NET_2_0
- using System.Web.UI.Adapters;
- using System.IO;
- #endif
- namespace System.Web.UI
- {
- // CAS
- [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- // attributes
- [DefaultProperty ("ID"), DesignerCategory ("Code"), ToolboxItemFilter ("System.Web.UI", ToolboxItemFilterType.Require)]
- [ToolboxItem ("System.Web.UI.Design.WebControlToolboxItem, " + Consts.AssemblySystem_Design)]
- [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
- #if NET_2_0
- [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web,
- "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
- [Bindable (true)]
- [Themeable (false)]
- #else
- [DesignerSerializer ("Microsoft.VSDesigner.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner,
- "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
- #endif
- public partial class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
- #if NET_2_0
- , IUrlResolutionService, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
- #endif
- {
- internal static readonly object DataBindingEvent = new object ();
- internal static readonly object DisposedEvent = new object ();
- internal static readonly object InitEvent = new object ();
- internal static readonly object LoadEvent = new object ();
- internal static readonly object PreRenderEvent = new object ();
- internal static readonly object UnloadEvent = new object ();
- internal static string [] defaultNameArray;
- /* */
- int event_mask;
- const int databinding_mask = 1;
- const int disposed_mask = 1 << 1;
- const int init_mask = 1 << 2;
- const int load_mask = 1 << 3;
- const int prerender_mask = 1 << 4;
- const int unload_mask = 1 << 5;
- /* */
- string uniqueID;
- string _userId;
- ControlCollection _controls;
- Control _namingContainer;
- Page _page;
- Control _parent;
- ISite _site;
- StateBag _viewState;
- EventHandlerList _events;
- RenderMethod _renderMethodDelegate;
- Hashtable _controlsCache;
- int defaultNumberID;
- DataBindingCollection dataBindings;
- Hashtable pendingVS; // may hold unused viewstate data from child controls
- #if NET_2_0
- TemplateControl _templateControl;
- bool _isChildControlStateCleared;
- #endif
- string _templateSourceDirectory;
- /*************/
- int stateMask;
- const int ENABLE_VIEWSTATE = 1;
- const int VISIBLE = 1 << 1;
- const int AUTOID = 1 << 2;
- const int CREATING_CONTROLS = 1 << 3;
- const int BINDING_CONTAINER = 1 << 4;
- const int AUTO_EVENT_WIREUP = 1 << 5;
- const int IS_NAMING_CONTAINER = 1 << 6;
- const int VISIBLE_CHANGED = 1 << 7;
- const int TRACK_VIEWSTATE = 1 << 8;
- const int CHILD_CONTROLS_CREATED = 1 << 9;
- const int ID_SET = 1 << 10;
- const int INITED = 1 << 11;
- const int INITING = 1 << 12;
- const int VIEWSTATE_LOADED = 1 << 13;
- const int LOADED = 1 << 14;
- const int PRERENDERED = 1 << 15;
- #if NET_2_0
- const int ENABLE_THEMING = 1 << 16;
- #endif
- const int AUTOID_SET = 1 << 17;
- /*************/
- static Control ()
- {
- defaultNameArray = new string [100];
- for (int i = 0; i < 100; i++)
- #if NET_2_0
- defaultNameArray [i] = String.Concat ("ctl", i.ToString ("D2"));
- #else
- defaultNameArray [i] = "_ctl" + i;
- #endif
- }
- public Control ()
- {
- stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
- if (this is INamingContainer)
- stateMask |= IS_NAMING_CONTAINER;
- }
- #if NET_2_0
- ControlAdapter adapter;
- bool did_adapter_lookup;
- protected internal ControlAdapter Adapter {
- get {
- if (!did_adapter_lookup) {
- adapter = ResolveAdapter ();
- if (adapter != null)
- adapter.Control = this;
- did_adapter_lookup = true;
- }
- return adapter;
- }
- }
- string _appRelativeTemplateSourceDirectory = null;
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public string AppRelativeTemplateSourceDirectory {
- get {
- if (_appRelativeTemplateSourceDirectory != null)
- return _appRelativeTemplateSourceDirectory;
- string tempSrcDir = null;
- TemplateControl templateControl = TemplateControl;
- if (templateControl != null)
- if (!string.IsNullOrEmpty (templateControl.AppRelativeVirtualPath))
- tempSrcDir = VirtualPathUtility.GetDirectory (templateControl.AppRelativeVirtualPath, false);
- _appRelativeTemplateSourceDirectory = (tempSrcDir != null) ? tempSrcDir : "~/";
- return _appRelativeTemplateSourceDirectory;
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- set {
- _appRelativeTemplateSourceDirectory = value;
- _templateSourceDirectory = null;
- }
- }
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
- public Control BindingContainer {
- get {
- Control container = NamingContainer;
- if (container != null && (container.stateMask & BINDING_CONTAINER) == 0)
- container = container.BindingContainer;
- return container;
- }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- [WebSysDescription ("An Identification of the control that is rendered.")]
- public virtual string ClientID {
- get {
- string client = UniqueID;
- if (client != null)
- #if NET_2_0
- client = UniqueID2ClientID (client);
- #else
- client = client.Replace (':', ClientIDSeparator);
- #endif
- stateMask |= ID_SET;
- return client;
- }
- }
- #if NET_2_0
- internal string UniqueID2ClientID (string uniqueId)
- {
- return uniqueId.Replace (IdSeparator, ClientIDSeparator);
- }
- protected char ClientIDSeparator
- #else
- char ClientIDSeparator
- #endif
- {
- get { return '_'; }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- [WebSysDescription ("The child controls of this control.")]
- public virtual ControlCollection Controls { //DIT
- get {
- if (_controls == null)
- _controls = CreateControlCollection ();
- return _controls;
- }
- }
- #if NET_2_0
- [MonoTODO ("revisit once we have a real design strategy")]
- protected internal bool DesignMode {
- get { return false; }
- }
- #endif
- [DefaultValue (true), WebCategory ("Behavior")]
- [WebSysDescription ("An Identification of the control that is rendered.")]
- #if NET_2_0
- [Themeable (false)]
- #endif
- public virtual bool EnableViewState {
- get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
- set { SetMask (ENABLE_VIEWSTATE, value); }
- }
- [MergableProperty (false), ParenthesizePropertyName (true)]
- [WebSysDescription ("The name of the control that is rendered.")]
- #if NET_2_0
- [Filterable (false), Themeable (false)]
- #endif
- public virtual string ID {
- get { return (((stateMask & ID_SET) != 0) ? _userId : null); }
- set {
- if (value == "")
- value = null;
- stateMask |= ID_SET;
- _userId = value;
- NullifyUniqueID ();
- }
- }
- #if NET_2_0
- protected internal bool IsChildControlStateCleared {
- get { return _isChildControlStateCleared; }
- }
- protected internal bool IsViewStateEnabled {
- get {
- for (Control control = this; control != null; control = control.Parent)
- if (!control.EnableViewState)
- return false;
- return true;
- }
- }
- protected bool LoadViewStateByID {
- get { return false; }
- }
- protected char IdSeparator {
- get { return '$'; }
- }
- #else
- internal char IdSeparator {
- get { return ':'; }
- }
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
- public virtual Control NamingContainer {
- get {
- if (_namingContainer == null && _parent != null) {
- if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
- _namingContainer = _parent.NamingContainer;
- else
- _namingContainer = _parent;
- }
- return _namingContainer;
- }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- [WebSysDescription ("The webpage that this control resides on.")]
- #if NET_2_0
- [Bindable (false)]
- #endif
- public virtual Page Page { //DIT
- get {
- if (_page == null){
- if (NamingContainer != null)
- _page = NamingContainer.Page;
- else if (Parent != null)
- _page = Parent.Page;
- }
- return _page;
- }
-
- set { _page = value; }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- [WebSysDescription ("The parent control of this control.")]
- public virtual Control Parent { //DIT
- get { return _parent; }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
- [WebSysDescription ("The site this control is part of.")]
- public ISite Site { //DIT
- get { return _site; }
- set { _site = value; }
- }
- #if NET_2_0
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public TemplateControl TemplateControl {
- get { return TemplateControlInternal; }
- [EditorBrowsable (EditorBrowsableState.Never)]
- set { _templateControl = value; }
- }
- internal virtual TemplateControl TemplateControlInternal {
- get {
- if (_templateControl != null)
- return _templateControl;
- if (_parent != null)
- return _parent.TemplateControl;
- return null;
- }
- }
- #endif
- #if !TARGET_J2EE
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- [WebSysDescription ("A virtual directory containing the parent of the control.")]
- public virtual string TemplateSourceDirectory {
- get {
- #if NET_2_0
- if (_templateSourceDirectory == null) {
- TemplateControl tc = TemplateControl;
- if (tc == null) {
- HttpContext ctx = Context;
- if (ctx != null)
- _templateSourceDirectory = VirtualPathUtility.GetDirectory (ctx.Request.CurrentExecutionFilePath);
- } else if (tc != this)
- _templateSourceDirectory = tc.TemplateSourceDirectory;
- if (_templateSourceDirectory == null && this is TemplateControl) {
- string path = ((TemplateControl) this).AppRelativeVirtualPath;
- if (path != null) {
- string ret = VirtualPathUtility.GetDirectory (VirtualPathUtility.ToAbsolute (path));
- int len = ret.Length;
- if (len <= 1)
- return ret;
- if (ret [--len] == '/')
- _templateSourceDirectory = ret.Substring (0, len);
- } else
- _templateSourceDirectory = String.Empty;
- }
- if (_templateSourceDirectory == null)
- _templateSourceDirectory = String.Empty;
- }
- return _templateSourceDirectory;
- #else
- if (_templateSourceDirectory == null) {
- HttpContext ctx = HttpContext.Current;
- HttpRequest req = ctx != null ? ctx.Request : null;
-
- _templateSourceDirectory = (_parent == null)
- ? req != null ? VirtualPathUtility.RemoveTrailingSlash (
- VirtualPathUtility.GetDirectory (
- HttpContext.Current.Request.CurrentExecutionFilePath)) : String.Empty
- : _parent.TemplateSourceDirectory;
- }
- return _templateSourceDirectory;
- #endif
- }
- }
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- [WebSysDescription ("The unique ID of the control.")]
- public virtual string UniqueID {
- get {
- if (uniqueID != null)
- return uniqueID;
- if (NamingContainer == null)
- return _userId;
- EnsureIDInternal ();
- string prefix = NamingContainer.UniqueID;
- if (NamingContainer == Page || prefix == null) {
- uniqueID = _userId;
- #if TARGET_J2EE
- if (getFacesContext () != null)
- uniqueID = getFacesContext ().getExternalContext ().encodeNamespace (uniqueID);
- #endif
- return uniqueID;
- }
- uniqueID = prefix + IdSeparator + _userId;
- return uniqueID;
- }
- }
- void SetMask (int m, bool val) {
- if (val)
- stateMask |= m;
- else
- stateMask &= ~m;
- }
- [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
- [WebSysDescription ("Visiblity state of the control.")]
- public virtual bool Visible {
- get {
- if ((stateMask & VISIBLE) == 0)
- return false;
- if (_parent != null)
- return _parent.Visible;
- return true;
- }
- set {
- if ((value && (stateMask & VISIBLE) == 0) ||
- (!value && (stateMask & VISIBLE) != 0)) {
- if (IsTrackingViewState)
- stateMask |= VISIBLE_CHANGED;
- }
- SetMask (VISIBLE, value);
- }
- }
- protected bool ChildControlsCreated {
- get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
- set {
- if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0) {
- if (_controls != null)
- _controls.Clear ();
- }
- SetMask (CHILD_CONTROLS_CREATED, value);
- }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- virtual HttpContext Context { //DIT
- get {
- #if NET_2_0
- Page page = Page;
- if (page != null)
- return page.Context;
- #else
- if (_parent == null)
- return HttpContext.Current;
- HttpContext context = _parent.Context;
- if (context != null)
- return context;
- #endif
-
- return HttpContext.Current;
- }
- }
- protected EventHandlerList Events {
- get {
- if (_events == null)
- _events = new EventHandlerList ();
- return _events;
- }
- }
- protected bool HasChildViewState {
- get { return (pendingVS != null && pendingVS.Count > 0); }
- }
- protected bool IsTrackingViewState {
- get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [WebSysDescription ("ViewState")]
- protected virtual StateBag ViewState {
- get {
- if (_viewState == null)
- _viewState = new StateBag (ViewStateIgnoresCase);
- if (IsTrackingViewState)
- _viewState.TrackViewState ();
- return _viewState;
- }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- protected virtual bool ViewStateIgnoresCase {
- get { return false; }
- }
- internal bool AutoEventWireup {
- get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
- set { SetMask (AUTO_EVENT_WIREUP, value); }
- }
- internal void SetBindingContainer (bool isBC)
- {
- SetMask (BINDING_CONTAINER, isBC);
- }
- internal void ResetChildNames ()
- {
- defaultNumberID = 0;
- }
- string GetDefaultName ()
- {
- string defaultName;
- if (defaultNumberID > 99) {
- #if NET_2_0
- defaultName = "ctl" + defaultNumberID++;
- #else
- defaultName = "_ctl" + defaultNumberID++;
- #endif
- } else {
- defaultName = defaultNameArray [defaultNumberID++];
- }
- return defaultName;
- }
- void NullifyUniqueID ()
- {
- uniqueID = null;
- if (!HasControls ())
- return;
- for (int i = 0; i < _controls.Count; i++)
- _controls [i].NullifyUniqueID ();
- }
- protected internal virtual void AddedControl (Control control, int index)
- {
- ResetControlsCache ();
- /* Ensure the control don't have more than 1 parent */
- if (control._parent != null)
- control._parent.Controls.Remove (control);
- control._parent = this;
- Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
- if ((stateMask & (INITING | INITED)) != 0)
- control.InitRecursive (nc);
- else {
- control.SetNamingContainer (nc);
- return;
- }
- if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
- if (pendingVS != null) {
- object vs = pendingVS [index];
- if (vs != null) {
- pendingVS.Remove (index);
- if (pendingVS.Count == 0)
- pendingVS = null;
- control.LoadViewStateRecursive (vs);
- }
- }
- }
- if ((stateMask & LOADED) != 0)
- control.LoadRecursive ();
- if ((stateMask & PRERENDERED) != 0)
- control.PreRenderRecursiveInternal ();
- }
-
- void SetNamingContainer (Control nc)
- {
- if (nc != null) {
- _namingContainer = nc;
- if (AutoID)
- EnsureIDInternal ();
- }
- }
- protected virtual void AddParsedSubObject (object obj) //DIT
- {
- Control c = obj as Control;
- if (c != null)
- Controls.Add (c);
- }
- #if NET_2_0
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public virtual void ApplyStyleSheetSkin (Page page)
- {
- if (!EnableTheming) /* this enough? */
- return;
- /* apply the style sheet skin here */
- if (page.StyleSheetPageTheme != null) {
- ControlSkin cs = page.StyleSheetPageTheme.GetControlSkin (GetType (), SkinID);
- if (cs != null)
- cs.ApplySkin (this);
- }
- }
- #endif
- protected void BuildProfileTree (string parentId, bool calcViewState)
- {
- //TODO
- }
- #if NET_2_0
- protected void ClearChildControlState ()
- {
- _isChildControlStateCleared = true;
- }
- protected void ClearChildState ()
- {
- ClearChildViewState ();
- ClearChildControlState ();
- }
- #endif
- protected void ClearChildViewState ()
- {
- pendingVS = null;
- }
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- virtual void CreateChildControls () //DIT
- {
- }
- protected virtual ControlCollection CreateControlCollection () //DIT
- {
- return new ControlCollection (this);
- }
- protected virtual void EnsureChildControls ()
- {
- if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
- stateMask |= CREATING_CONTROLS;
- #if NET_2_0
- if (Adapter != null)
- Adapter.CreateChildControls ();
- else
- #endif
- CreateChildControls ();
- ChildControlsCreated = true;
- stateMask &= ~CREATING_CONTROLS;
- }
- }
- void EnsureIDInternal ()
- {
- if (_userId != null)
- return;
- _userId = NamingContainer.GetDefaultName ();
- SetMask (AUTOID_SET, true);
- }
- #if NET_2_0
- protected void EnsureID ()
- {
- if (NamingContainer == null)
- return;
- EnsureIDInternal ();
- SetMask (ID_SET, true);
- }
- protected bool HasEvents ()
- {
- return _events != null;
- }
- #endif
- void ResetControlsCache ()
- {
- _controlsCache = null;
- if ((this.stateMask & IS_NAMING_CONTAINER) == 0 && Parent != null)
- Parent.ResetControlsCache ();
- }
- Hashtable InitControlsCache ()
- {
- if (_controlsCache != null)
- return _controlsCache;
- if ((this.stateMask & IS_NAMING_CONTAINER) != 0 || Parent == null)
- //LAMESPEC: MS' docs don't mention it, but FindControl is case insensitive.
- #if NET_2_0
- _controlsCache = new Hashtable (StringComparer.OrdinalIgnoreCase);
- #else
- _controlsCache = new Hashtable (CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
- #endif
- else
- _controlsCache = Parent.InitControlsCache ();
- return _controlsCache;
- }
- void EnsureControlsCache ()
- {
- if (_controlsCache != null)
- return;
- InitControlsCache ();
- FillControlCache (this);
- }
- void FillControlCache (Control control)
- {
- if (!HasControls ())
- return;
- foreach (Control c in control._controls) {
- try {
- if (c._userId != null)
- _controlsCache.Add (c._userId, c);
- } catch (ArgumentException) {
- throw new HttpException (
- "Multiple controls with the same ID '" +
- c._userId +
- "' were found. FindControl requires that controls have unique IDs. ");
- }
- if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ())
- FillControlCache (c);
- }
- }
- protected bool IsLiteralContent ()
- {
- if (HasControls () && _controls.Count == 1 && (_controls [0] is LiteralControl))
- return true;
- return false;
- }
- [WebSysDescription ("")]
- public virtual Control FindControl (string id)
- {
- return FindControl (id, 0);
- }
- Control LookForControlByName (string id)
- {
- EnsureControlsCache ();
- return (Control) _controlsCache [id];
- }
- protected virtual Control FindControl (string id, int pathOffset)
- {
- EnsureChildControls ();
- Control namingContainer = null;
- if ((stateMask & IS_NAMING_CONTAINER) == 0) {
- namingContainer = NamingContainer;
- if (namingContainer == null)
- return null;
- return namingContainer.FindControl (id, pathOffset);
- }
- if (!HasControls ())
- return null;
- int separatorIdx = id.IndexOf (IdSeparator, pathOffset);
- if (separatorIdx == -1)
- return LookForControlByName (id.Substring (pathOffset));
- string idfound = id.Substring (pathOffset, separatorIdx - pathOffset);
- namingContainer = LookForControlByName (idfound);
- if (namingContainer == null)
- return null;
- return namingContainer.FindControl (id, separatorIdx + 1);
- }
- protected virtual void LoadViewState (object savedState)
- {
- if (savedState != null) {
- ViewState.LoadViewState (savedState);
- object o = ViewState ["Visible"];
- if (o != null) {
- SetMask (VISIBLE, (bool) o);
- stateMask |= VISIBLE_CHANGED;
- }
- }
- }
- // [MonoTODO("Secure?")]
- protected string MapPathSecure (string virtualPath)
- {
- string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
- return Context.Request.MapPath (combined);
- }
- protected virtual bool OnBubbleEvent (object source, EventArgs args) //DIT
- {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("OnBubbleEvent ", _userId, " ", type_name));
- }
- #endif
- return false;
- }
- protected virtual void OnDataBinding (EventArgs e)
- {
- if ((event_mask & databinding_mask) != 0) {
- EventHandler eh = (EventHandler) (_events [DataBindingEvent]);
- if (eh != null) {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("OnDataBinding ", _userId, " ", type_name));
- }
- #endif
- eh (this, e);
- }
- }
- }
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- virtual void OnInit (EventArgs e)
- {
- if ((event_mask & init_mask) != 0) {
- EventHandler eh = (EventHandler) (_events [InitEvent]);
- if (eh != null) {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("OnInit ", _userId, " ", type_name));
- }
- #endif
- eh (this, e);
- }
- }
- }
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- virtual void OnLoad (EventArgs e)
- {
- if ((event_mask & load_mask) != 0) {
- EventHandler eh = (EventHandler) (_events [LoadEvent]);
- if (eh != null) {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("OnLoad ", _userId, " ", type_name));
- }
- #endif
- eh (this, e);
- }
- }
- }
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- virtual void OnPreRender (EventArgs e)
- {
- if ((event_mask & prerender_mask) != 0) {
- EventHandler eh = (EventHandler) (_events [PreRenderEvent]);
- if (eh != null) {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("OnPreRender ", _userId, " ", type_name));
- }
- #endif
- eh (this, e);
- }
- }
- }
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- virtual void OnUnload (EventArgs e)
- {
- if ((event_mask & unload_mask) != 0) {
- EventHandler eh = (EventHandler) (_events [UnloadEvent]);
- if (eh != null) {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("OnUnload ", _userId, " ", type_name));
- }
- #endif
- eh (this, e);
- }
- }
- }
- #if NET_2_0
- protected internal Stream OpenFile (string path)
- {
- try {
- string filePath = Context.Server.MapPath (path);
- return File.OpenRead (filePath);
- }
- catch (UnauthorizedAccessException) {
- throw new HttpException ("Access to the specified file was denied.");
- }
- }
- internal string GetPhysicalFilePath (string virtualPath)
- {
- Page page = Page;
- if (VirtualPathUtility.IsAbsolute (virtualPath))
- return page != null ? page.MapPath (virtualPath) : Context.Server.MapPath (virtualPath);
- // We need to determine whether one of our parents is a
- // master page. If so, we need to map the path
- // relatively to the master page and not our containing
- // page/control. This is necessary for cases when a
- // relative path is used in a control placed in a master
- // page and the master page is referenced from a
- // location other than its own. In such cases MS.NET looks
- // for the file in the directory where the master page
- // is.
- //
- // An example of where it is needed is at
- //
- // http://quickstarts.asp.net/QuickStartv20/aspnet/samples/masterpages/masterpages_cs/pages/default.aspx
- //
- MasterPage master = null;
- Control ctrl = Parent;
- while (ctrl != null) {
- if (ctrl is MasterPage) {
- master = ctrl as MasterPage;
- break;
- }
- ctrl = ctrl.Parent;
- }
- string path;
- if (master != null)
- path = VirtualPathUtility.Combine (master.TemplateSourceDirectory + "/", virtualPath);
- else
- path = VirtualPathUtility.Combine (TemplateSourceDirectory + "/", virtualPath);
-
- return page != null ? page.MapPath (path) : Context.Server.MapPath (path);
- }
- #endif
- protected void RaiseBubbleEvent (object source, EventArgs args)
- {
- Control c = Parent;
- while (c != null) {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("RaiseBubbleEvent ", _userId, " ", type_name));
- }
- #endif
- if (c.OnBubbleEvent (source, args)) {
- #if MONO_TRACE
- if (trace != null)
- trace.Write ("control", String.Concat ("End RaiseBubbleEvent (false) ", _userId, " ", type_name));
- #endif
- break;
- }
- #if MONO_TRACE
- if (trace != null)
- trace.Write ("control", String.Concat ("End RaiseBubbleEvent (true) ", _userId, " ", type_name));
- #endif
- c = c.Parent;
- }
- }
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- virtual void Render (HtmlTextWriter writer) //DIT
- {
- RenderChildren (writer);
- }
- #if NET_2_0
- protected internal
- #else
- protected
- #endif
- virtual void RenderChildren (HtmlTextWriter writer) //DIT
- {
- if (_renderMethodDelegate != null) {
- _renderMethodDelegate (writer, this);
- } else if (_controls != null) {
- int len = _controls.Count;
- Control c;
- for (int i = 0; i < len; i++) {
- c = _controls [i];
- if (c == null)
- continue;
- #if NET_2_0
- ControlAdapter tmp = c.Adapter;
- if (tmp != null)
- c.RenderControl (writer, tmp);
- else
- #endif
- c.RenderControl (writer);
- }
- }
- }
- #if NET_2_0
- protected virtual ControlAdapter ResolveAdapter ()
- {
- HttpContext context = Context;
- if (context == null)
- return null;
- if (!context.Request.BrowserMightHaveAdapters)
- return null;
-
- // Search up the type hierarchy until we find a control with an adapter.
- Type adapterType = null;
- Type controlType = GetType();
- IDictionary typeMap = context.Request.Browser.Adapters;
- while (controlType != typeof(object)) {
- adapterType = (Type)typeMap [controlType];
- if (adapterType != null)
- break;
- controlType = controlType.BaseType;
- }
- ControlAdapter a = null;
- if (adapterType != null)
- a = (ControlAdapter)Activator.CreateInstance (adapterType);
- return a;
- }
- #endif
- protected virtual object SaveViewState ()
- {
- if ((stateMask & VISIBLE_CHANGED) != 0) {
- ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
- } else if (_viewState == null) {
- return null;
- }
- return _viewState.SaveViewState ();
- }
- protected virtual void TrackViewState ()
- {
- if (_viewState != null)
- _viewState.TrackViewState ();
- stateMask |= TRACK_VIEWSTATE;
- }
- public virtual void Dispose ()
- {
- if ((event_mask & disposed_mask) != 0) {
- EventHandler eh = (EventHandler) (_events [DisposedEvent]);
- if (eh != null)
- eh (this, EventArgs.Empty);
- }
- }
- [WebCategory ("FIXME")]
- [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
- public event EventHandler DataBinding {
- add {
- event_mask |= databinding_mask;
- Events.AddHandler (DataBindingEvent, value);
- }
- remove { Events.RemoveHandler (DataBindingEvent, value); }
- }
- [WebSysDescription ("Raised when the contol is disposed.")]
- public event EventHandler Disposed {
- add {
- event_mask |= disposed_mask;
- Events.AddHandler (DisposedEvent, value);
- }
- remove { Events.RemoveHandler (DisposedEvent, value); }
- }
- [WebSysDescription ("Raised when the page containing the control is initialized.")]
- public event EventHandler Init {
- add {
- event_mask |= init_mask;
- Events.AddHandler (InitEvent, value);
- }
- remove { Events.RemoveHandler (InitEvent, value); }
- }
- [WebSysDescription ("Raised after the page containing the control has been loaded.")]
- public event EventHandler Load {
- add {
- event_mask |= load_mask;
- Events.AddHandler (LoadEvent, value);
- }
- remove { Events.RemoveHandler (LoadEvent, value); }
- }
- [WebSysDescription ("Raised before the page containing the control is rendered.")]
- public event EventHandler PreRender {
- add {
- event_mask |= prerender_mask;
- Events.AddHandler (PreRenderEvent, value);
- }
- remove { Events.RemoveHandler (PreRenderEvent, value); }
- }
- [WebSysDescription ("Raised when the page containing the control is unloaded.")]
- public event EventHandler Unload {
- add {
- event_mask |= unload_mask;
- Events.AddHandler (UnloadEvent, value);
- }
- remove { Events.RemoveHandler (UnloadEvent, value); }
- }
- public virtual void DataBind () //DIT
- {
- #if NET_2_0
- DataBind (true);
- #else
- OnDataBinding (EventArgs.Empty);
- DataBindChildren();
- #endif
- }
- #if NET_2_0
- protected virtual
- #endif
- void DataBindChildren ()
- {
- if (!HasControls ())
- return;
- int len = _controls.Count;
- for (int i = 0; i < len; i++) {
- Control c = _controls [i];
- c.DataBind ();
- }
- }
- public virtual bool HasControls ()
- {
- return (_controls != null && _controls.Count > 0);
- }
- #if NET_2_0
- public virtual
- #else
- public
- #endif
- void RenderControl (HtmlTextWriter writer)
- {
- if ((stateMask & VISIBLE) != 0) {
- HttpContext ctx = Context;
- TraceContext trace = (ctx != null) ? ctx.Trace : null;
- int pos = 0;
- if ((trace != null) && trace.IsEnabled)
- pos = ctx.Response.GetOutputByteCount ();
- Render (writer);
- if ((trace != null) && trace.IsEnabled) {
- int size = ctx.Response.GetOutputByteCount () - pos;
- trace.SaveSize (this, size >= 0 ? size : 0);
- }
- }
- }
- #if NET_2_0
- protected void RenderControl (HtmlTextWriter writer, ControlAdapter adapter)
- {
- if ((stateMask & VISIBLE) != 0) {
- adapter.BeginRender (writer);
- adapter.Render (writer);
- adapter.EndRender (writer);
- }
- }
- #endif
- public string ResolveUrl (string relativeUrl)
- {
- if (relativeUrl == null)
- throw new ArgumentNullException ("relativeUrl");
- if (relativeUrl == String.Empty)
- return relativeUrl;
- if (VirtualPathUtility.IsAbsolute (relativeUrl))
- return relativeUrl;
- if (relativeUrl [0] == '#')
- return relativeUrl;
- #if NET_2_0
- string ts = AppRelativeTemplateSourceDirectory;
- #else
- string ts = TemplateSourceDirectory;
- #endif
- if (ts == null || ts.Length == 0 ||
- Context == null || Context.Response == null ||
- relativeUrl.IndexOf (':') >= 0)
- return relativeUrl;
- HttpResponse resp = Context.Response;
- if (!VirtualPathUtility.IsAppRelative (relativeUrl))
- relativeUrl = VirtualPathUtility.Combine (VirtualPathUtility.AppendTrailingSlash (ts), relativeUrl);
- return resp.ApplyAppPathModifier (relativeUrl);
- }
- #if NET_2_0
- public
- #else
- internal
- #endif
- string ResolveClientUrl (string relativeUrl)
- {
- if (relativeUrl == null)
- throw new ArgumentNullException ("relativeUrl");
- if (relativeUrl.Length == 0)
- return String.Empty;
- #if TARGET_J2EE
- relativeUrl = ResolveClientUrlInternal (relativeUrl);
- javax.faces.context.FacesContext faces = getFacesContext ();
- if (faces == null)
- return relativeUrl;
- string url;
- if (relativeUrl.IndexOf (':') >= 0)
- url = ResolveAppRelativeFromFullPath (relativeUrl);
- else if (VirtualPathUtility.IsAbsolute (relativeUrl))
- url = VirtualPathUtility.ToAppRelative (relativeUrl);
- else
- return faces.getApplication ().getViewHandler ().getResourceURL (faces, relativeUrl);
- if (VirtualPathUtility.IsAppRelative (url)) {
- url = url.Substring (1);
- url = url.Length == 0 ? "/" : url;
- return faces.getApplication ().getViewHandler ().getResourceURL (faces, url);
- }
- return relativeUrl;
- }
-
- string ResolveClientUrlInternal (string relativeUrl) {
- if (relativeUrl.StartsWith (J2EE.J2EEConsts.ACTION_URL_PREFIX, StringComparison.Ordinal))
- return CreateActionUrl (relativeUrl.Substring (J2EE.J2EEConsts.ACTION_URL_PREFIX.Length));
- if (relativeUrl.StartsWith (J2EE.J2EEConsts.RENDER_URL_PREFIX, StringComparison.Ordinal))
- return ResolveClientUrl (relativeUrl.Substring (J2EE.J2EEConsts.RENDER_URL_PREFIX.Length));
- #endif
- if (VirtualPathUtility.IsAbsolute (relativeUrl) || relativeUrl.IndexOf (':') >= 0)
- return relativeUrl;
- HttpContext context = Context;
- if (context != null && context.Request != null) {
- string templateSourceDirectory = TemplateSourceDirectory;
- if (templateSourceDirectory == null || templateSourceDirectory.Length == 0)
- return relativeUrl;
- string basePath = context.Request.FilePath;
- if (basePath.Length > 1 && basePath [basePath.Length - 1] != '/')
- basePath = VirtualPathUtility.GetDirectory (basePath, false);
- if (VirtualPathUtility.IsAppRelative (relativeUrl))
- return VirtualPathUtility.MakeRelative (basePath, relativeUrl);
- string templatePath = VirtualPathUtility.AppendTrailingSlash (templateSourceDirectory);
- if (basePath.Length == templatePath.Length && String.CompareOrdinal (basePath, templatePath) == 0)
- return relativeUrl;
- relativeUrl = VirtualPathUtility.Combine (templatePath, relativeUrl);
- return VirtualPathUtility.MakeRelative (basePath, relativeUrl);
- }
- return relativeUrl;
- }
- internal bool HasRenderMethodDelegate ()
- {
- return _renderMethodDelegate != null;
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public void SetRenderMethodDelegate (RenderMethod renderMethod) //DIT
- {
- _renderMethodDelegate = renderMethod;
- }
- internal void LoadRecursive ()
- {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("LoadRecursive ", _userId, " ", type_name));
- }
- #endif
- #if NET_2_0
- if (Adapter != null)
- Adapter.OnLoad (EventArgs.Empty);
- else
- #endif
- OnLoad (EventArgs.Empty);
- if (HasControls ()) {
- int len = _controls.Count;
- for (int i = 0; i < len; i++) {
- Control c = _controls [i];
- c.LoadRecursive ();
- }
- }
- #if MONO_TRACE
- if (trace != null)
- trace.Write ("control", String.Concat ("End LoadRecursive ", _userId, " ", type_name));
- #endif
- stateMask |= LOADED;
- }
- internal void UnloadRecursive (Boolean dispose)
- {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("UnloadRecursive ", _userId, " ", type_name));
- }
- #endif
- if (HasControls ()) {
- int len = _controls.Count;
- for (int i = 0; i < len; i++) {
- Control c = _controls [i];
- c.UnloadRecursive (dispose);
- }
- }
- #if MONO_TRACE
- if (trace != null)
- trace.Write ("control", String.Concat ("End UnloadRecursive ", _userId, " ", type_name));
- #endif
- #if NET_2_0
- ControlAdapter tmp = Adapter;
- if (tmp != null)
- tmp.OnUnload (EventArgs.Empty);
- else
- #endif
- OnUnload (EventArgs.Empty);
- if (dispose)
- Dispose ();
- }
- internal void PreRenderRecursiveInternal ()
- {
- bool visible;
- #if NET_2_0
- visible = Visible;
- #else
- visible = (stateMask & VISIBLE) != 0;
- #endif
-
- if (visible) {
- #if NET_2_0
- SetMask (VISIBLE, true);
- #endif
- EnsureChildControls ();
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("PreRenderRecursive ", _userId, " ", type_name));
- }
- #endif
- #if NET_2_0
- if (Adapter != null)
- Adapter.OnPreRender (EventArgs.Empty);
- else
- #endif
- OnPreRender (EventArgs.Empty);
- if (!HasControls ())
- return;
- int len = _controls.Count;
- for (int i = 0; i < len; i++) {
- Control c = _controls [i];
- c.PreRenderRecursiveInternal ();
- }
- #if MONO_TRACE
- if (trace != null)
- trace.Write ("control", String.Concat ("End PreRenderRecursive ", _userId, " ", type_name));
- #endif
- }
- #if NET_2_0
- else
- SetMask (VISIBLE, false);
- #endif
-
- stateMask |= PRERENDERED;
- }
- internal void InitRecursive (Control namingContainer)
- {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("InitRecursive ", _userId, " ", type_name));
- }
- #endif
- SetNamingContainer (namingContainer);
- if (HasControls ()) {
- if ((stateMask & IS_NAMING_CONTAINER) != 0)
- namingContainer = this;
- int len = _controls.Count;
- for (int i = 0; i < len; i++) {
- Control c = _controls [i];
- c.InitRecursive (namingContainer);
- }
- }
- stateMask |= INITING;
- #if NET_2_0
- ApplyTheme ();
- ControlAdapter tmp = Adapter;
- if (tmp != null)
- tmp.OnInit (EventArgs.Empty);
- else
- #endif
- OnInit (EventArgs.Empty);
- #if MONO_TRACE
- if (trace != null)
- trace.Write ("control", String.Concat ("End InitRecursive ", _userId, " ", type_name));
- #endif
- TrackViewState ();
- stateMask |= INITED;
- stateMask &= ~INITING;
- }
- internal object SaveViewStateRecursive ()
- {
- if (!EnableViewState)
- return null;
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- #if MONO_TRACE
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("SaveViewStateRecursive ", _userId, " ", type_name));
- }
- #endif
- ArrayList controlList = null;
- ArrayList controlStates = null;
- int idx = -1;
- if (HasControls ()) {
- int len = _controls.Count;
- for (int i = 0; i < len; i++) {
- Control ctrl = _controls [i];
- object ctrlState = ctrl.SaveViewStateRecursive ();
- idx++;
- if (ctrlState == null)
- continue;
- if (controlList == null) {
- controlList = new ArrayList ();
- controlStates = new ArrayList ();
- }
- controlList.Add (idx);
- controlStates.Add (ctrlState);
- }
- }
- #if NET_2_0
- object thisAdapterViewState = null;
- if (Adapter != null)
- thisAdapterViewState = Adapter.SaveAdapterViewState ();
- #endif
- object thisState = SaveViewState ();
- if (thisState == null && controlList == null && controlStates == null) {
- if (trace != null) {
- #if MONO_TRACE
- trace.Write ("control", "End SaveViewStateRecursive " + _userId + " " + type_name + " saved nothing");
- #endif
- trace.SaveViewState (this, null);
- }
- return null;
- }
- if (trace != null) {
- #if MONO_TRACE
- trace.Write ("control", "End SaveViewStateRecursive " + _userId + " " + type_name + " saved a Triplet");
- #endif
- trace.SaveViewState (this, thisState);
- }
- #if NET_2_0
- thisState = new object[] { thisState, thisAdapterViewState };
- #endif
- return new Triplet (thisState, controlList, controlStates);
- }
- internal void LoadViewStateRecursive (object savedState)
- {
- if (!EnableViewState || savedState == null)
- return;
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("LoadViewStateRecursive ", _userId, " ", type_name));
- }
- #endif
- Triplet savedInfo = (Triplet) savedState;
- #if NET_2_0
- object[] controlAndAdapterViewStates = (object [])savedInfo.First;
- if (Adapter != null)
- Adapter.LoadAdapterViewState (controlAndAdapterViewStates [1]);
- LoadViewState (controlAndAdapterViewStates [0]);
- #else
- LoadViewState (savedInfo.First);
- #endif
- ArrayList controlList = savedInfo.Second as ArrayList;
- if (controlList == null)
- return;
- ArrayList controlStates = savedInfo.Third as ArrayList;
- int nControls = controlList.Count;
- for (int i = 0; i < nControls; i++) {
- int k = (int) controlList [i];
- if (k < Controls.Count && controlStates != null) {
- Control c = Controls [k];
- c.LoadViewStateRecursive (controlStates [i]);
- }
- else {
- if (pendingVS == null)
- pendingVS = new Hashtable ();
- pendingVS [k] = controlStates [i];
- }
- }
- #if MONO_TRACE
- if (trace != null)
- trace.Write ("control", String.Concat ("End LoadViewStateRecursive ", _userId, " ", type_name));
- #endif
- stateMask |= VIEWSTATE_LOADED;
- }
- #if NET_2_0
- internal ControlSkin controlSkin;
- internal void ApplyTheme ()
- {
- #if MONO_TRACE
- TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
- string type_name = null;
- if (trace != null) {
- type_name = GetType ().Name;
- trace.Write ("control", String.Concat ("ApplyThemeRecursive ", _userId, " ", type_name));
- }
- #endif
- if (Page.PageTheme != null && EnableTheming) {
- ControlSkin controlSkin = Page.PageTheme.GetControlSkin (GetType (), SkinID);
- if (controlSkin != null)
- controlSkin.ApplySkin (this);
- }
- #if MONO_TRACE
- if (trace != null)
- trace.Write ("control", String.Concat ("End ApplyThemeRecursive ", _userId, " ", type_name));
- #endif
- }
- #endif
- internal bool AutoID {
- get { return (stateMask & AUTOID) != 0; }
- set {
- if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
- return;
- SetMask (AUTOID, value);
- }
- }
- protected internal virtual void RemovedControl (Control control)
- {
- control.UnloadRecursive (false);
- control._parent = null;
- control._page = null;
- control._namingContainer = null;
- if ((control.stateMask & AUTOID_SET) != 0) {
- control._userId = null;
- control.SetMask (ID_SET, false);
- }
- control.NullifyUniqueID ();
- }
-
- #if NET_2_0
- string skinId = string.Empty;
- bool _enableTheming = true;
- [Browsable (false)]
- [Themeable (false)]
- [DefaultValue (true)]
- public virtual bool EnableTheming {
- get {
- if ((stateMask & ENABLE_THEMING) != 0)
- return _enableTheming;
- if (_parent != null)
- return _parent.EnableTheming;
- return true;
- }
- set {
- SetMask (ENABLE_THEMING, true);
- _enableTheming = value;
- }
- }
- [Browsable (false)]
- [DefaultValue ("")]
- [Filterable (false)]
- public virtual string SkinID {
- get { return skinId; }
- set { skinId = value; }
- }
- ControlBuilder IControlBuilderAccessor.ControlBuilder {
- get { throw new NotImplementedException (); }
- }
- IDictionary IControlDesignerAccessor.GetDesignModeState ()
- {
- throw new NotImplementedException ();
- }
- void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
- {
- SetDesignModeState (designData);
- }
- void IControlDesignerAccessor.SetOwnerControl (Control control)
- {
- throw new NotImplementedException ();
- }
- IDictionary IControlDesignerAccessor.UserData {
- get { throw new NotImplementedException (); }
- }
- ExpressionBindingCollection expressionBindings;
- ExpressionBindingCollection IExpressionsAccessor.Expressions {
- get {
- if (expressionBindings == null)
- expressionBindings = new ExpressionBindingCollection ();
- return expressionBindings;
- }
- }
- bool IExpressionsAccessor.HasExpressions {
- get { return (expressionBindings != null && expressionBindings.Count > 0); }
- }
- public virtual void Focus ()
- {
- Page.SetFocus (this);
- }
- protected internal virtual void LoadControlState (object state)
- {
- }
- protected internal virtual object SaveControlState ()
- {
- return null;
- }
- protected virtual void DataBind (bool raiseOnDataBinding)
- {
- bool foundDataItem = false;
- if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
- object o = DataBinder.GetDataItem (this, out foundDataItem);
- if (foundDataItem)
- Page.PushDataItemContext (o);
- }
- try {
- if (raiseOnDataBinding)
- OnDataBinding (EventArgs.Empty);
- DataBindChildren ();
- } finally {
- if (foundDataItem)
- Page.PopDataItemContext ();
- }
- }
- protected virtual IDictionary GetDesignModeState ()
- {
- throw new NotImplementedException ();
- }
- protected virtual void SetDesignModeState (IDictionary data)
- {
- throw new NotImplementedException ();
- }
- internal bool IsInited {
- get { return (stateMask & INITED) != 0; }
- }
- internal bool IsLoaded {
- get { return (stateMask & LOADED) != 0; }
- }
- internal bool IsPrerendered {
- get { return (stateMask & PRERENDERED) != 0; }
- }
- #endif
- void IParserAccessor.AddParsedSubObject (object obj)
- {
- this.AddParsedSubObject (obj);
- }
- DataBindingCollection IDataBindingsAccessor.DataBindings {
- get {
- if (dataBindings == null) {
- dataBindings = new DataBindingCollection ();
- }
- return dataBindings;
- }
- }
- bool IDataBindingsAccessor.HasDataBindings {
- get {
- if (dataBindings != null && dataBindings.Count > 0) {
- return true;
- }
- return false;
- }
- }
- }
- }
|