Control.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  1. //
  2. // System.Web.UI.Control.cs
  3. //
  4. // Authors:
  5. // Bob Smith <[email protected]>
  6. // Gonzalo Paniagua Javier ([email protected]
  7. // Andreas Nahr ([email protected])
  8. // Sanjay Gupta ([email protected])
  9. //
  10. // (C) Bob Smith
  11. // (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
  12. // (C) 2004 Novell, Inc. (http://www.novell.com)
  13. //
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. // This will provide extra information when trace is enabled. Might be too verbose.
  35. #define MONO_TRACE
  36. using System.Collections;
  37. using System.ComponentModel;
  38. using System.ComponentModel.Design;
  39. using System.ComponentModel.Design.Serialization;
  40. using System.Security.Permissions;
  41. using System.Web;
  42. using System.Web.Util;
  43. #if NET_2_0
  44. using System.Web.UI.Adapters;
  45. using System.IO;
  46. #endif
  47. namespace System.Web.UI
  48. {
  49. // CAS
  50. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  51. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  52. // attributes
  53. [DefaultProperty ("ID"), DesignerCategory ("Code"), ToolboxItemFilter ("System.Web.UI", ToolboxItemFilterType.Require)]
  54. [ToolboxItem ("System.Web.UI.Design.WebControlToolboxItem, " + Consts.AssemblySystem_Design)]
  55. [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  56. #if NET_2_0
  57. [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web,
  58. "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  59. [Bindable (true)]
  60. [Themeable (false)]
  61. #else
  62. [DesignerSerializer ("Microsoft.VSDesigner.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner,
  63. "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  64. #endif
  65. public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
  66. #if NET_2_0
  67. , IUrlResolutionService, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
  68. #endif
  69. {
  70. static readonly object DataBindingEvent = new object();
  71. static readonly object DisposedEvent = new object();
  72. static readonly object InitEvent = new object();
  73. static readonly object LoadEvent = new object();
  74. static readonly object PreRenderEvent = new object();
  75. static readonly object UnloadEvent = new object();
  76. static string[] defaultNameArray;
  77. /* */
  78. int event_mask;
  79. const int databinding_mask = 1;
  80. const int disposed_mask = 1 << 1;
  81. const int init_mask = 1 << 2;
  82. const int load_mask = 1 << 3;
  83. const int prerender_mask = 1 << 4;
  84. const int unload_mask = 1 << 5;
  85. /* */
  86. string uniqueID;
  87. string _userId;
  88. TemplateControl _templateControl;
  89. ControlCollection _controls;
  90. Control _namingContainer;
  91. Page _page;
  92. Control _parent;
  93. ISite _site;
  94. HttpContext _context;
  95. StateBag _viewState;
  96. EventHandlerList _events;
  97. RenderMethod _renderMethodDelegate;
  98. int defaultNumberID;
  99. DataBindingCollection dataBindings;
  100. Hashtable pendingVS; // may hold unused viewstate data from child controls
  101. /*************/
  102. int stateMask;
  103. const int ENABLE_VIEWSTATE = 1;
  104. const int VISIBLE = 1 << 1;
  105. const int AUTOID = 1 << 2;
  106. const int CREATING_CONTROLS = 1 << 3;
  107. const int BINDING_CONTAINER = 1 << 4;
  108. const int AUTO_EVENT_WIREUP = 1 << 5;
  109. const int IS_NAMING_CONTAINER = 1 << 6;
  110. const int VISIBLE_CHANGED = 1 << 7;
  111. const int TRACK_VIEWSTATE = 1 << 8;
  112. const int CHILD_CONTROLS_CREATED = 1 << 9;
  113. const int ID_SET = 1 << 10;
  114. const int INITED = 1 << 11;
  115. const int INITING = 1 << 12;
  116. const int VIEWSTATE_LOADED = 1 << 13;
  117. const int LOADED = 1 << 14;
  118. const int PRERENDERED = 1 << 15;
  119. #if NET_2_0
  120. const int ENABLE_THEMING = 1 << 16;
  121. #endif
  122. /*************/
  123. static Control ()
  124. {
  125. defaultNameArray = new string [100];
  126. for (int i = 0 ; i < 100 ; i++)
  127. defaultNameArray [i] = "_ctl" + i;
  128. }
  129. public Control()
  130. {
  131. stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
  132. if (this is INamingContainer)
  133. stateMask |= IS_NAMING_CONTAINER;
  134. }
  135. #if NET_2_0
  136. [MonoTODO]
  137. protected ControlAdapter Adapter
  138. {
  139. get {
  140. // for the time being, fool the
  141. // Control machinery into thinking we
  142. // don't have an Adapter. This will
  143. // allow us to write all the rest of
  144. // the Adapter handling code without
  145. // having to worry about *having*
  146. // adapters.
  147. return null;
  148. }
  149. }
  150. string _appRelativeTemplateSourceDirectory = "~/";
  151. [EditorBrowsable (EditorBrowsableState.Advanced)]
  152. [Browsable (false)]
  153. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  154. public string AppRelativeTemplateSourceDirectory
  155. {
  156. get { return _appRelativeTemplateSourceDirectory; }
  157. [EditorBrowsable (EditorBrowsableState.Never)]
  158. set { _appRelativeTemplateSourceDirectory = value; }
  159. }
  160. #endif
  161. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  162. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  163. public Control BindingContainer {
  164. get {
  165. Control container = NamingContainer;
  166. if (container != null && (container.stateMask & BINDING_CONTAINER) == 0)
  167. container = container.BindingContainer;
  168. return container;
  169. }
  170. }
  171. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  172. [Browsable (false)]
  173. [WebSysDescription ("An Identification of the control that is rendered.")]
  174. public virtual string ClientID {
  175. get {
  176. string client = UniqueID;
  177. if (client != null)
  178. client = client.Replace (':', ClientIDSeparator);
  179. return client;
  180. }
  181. }
  182. #if NET_2_0
  183. protected char ClientIDSeparator
  184. #else
  185. char ClientIDSeparator
  186. #endif
  187. {
  188. get {
  189. return '_';
  190. }
  191. }
  192. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  193. [Browsable (false)]
  194. [WebSysDescription ("The child controls of this control.")]
  195. public virtual ControlCollection Controls //DIT
  196. {
  197. get
  198. {
  199. if (_controls == null) _controls = CreateControlCollection();
  200. return _controls;
  201. }
  202. }
  203. #if NET_2_0
  204. [MonoTODO ("revisit once we have a real design strategy")]
  205. protected internal bool DesignMode
  206. {
  207. get { return false; }
  208. }
  209. #endif
  210. [DefaultValue (true), WebCategory ("Behavior")]
  211. [WebSysDescription ("An Identification of the control that is rendered.")]
  212. #if NET_2_0
  213. [Themeable (false)]
  214. #endif
  215. public virtual bool EnableViewState {
  216. get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
  217. set { SetMask (ENABLE_VIEWSTATE, value); }
  218. }
  219. [MergableProperty (false), ParenthesizePropertyName (true)]
  220. [WebSysDescription ("The name of the control that is rendered.")]
  221. #if NET_2_0
  222. [Filterable (false), Themeable (false)]
  223. #endif
  224. public virtual string ID {
  225. get {
  226. return (((stateMask & ID_SET) != 0) ? _userId : null);
  227. }
  228. set {
  229. if (value == "")
  230. value = null;
  231. stateMask |= ID_SET;
  232. _userId = value;
  233. NullifyUniqueID ();
  234. }
  235. }
  236. #if NET_2_0
  237. protected char IdSeparator
  238. {
  239. get {
  240. return '$';
  241. }
  242. }
  243. protected internal bool IsChildControlStateCleared
  244. {
  245. get {
  246. throw new NotImplementedException ();
  247. }
  248. }
  249. protected internal bool IsViewStateEnabled
  250. {
  251. get {
  252. if (Page == null)
  253. return false;
  254. for (Control control = this; control != null; control = control.Parent)
  255. if (!control.EnableViewState)
  256. return false;
  257. return true;
  258. }
  259. }
  260. protected bool LoadViewStateByID
  261. {
  262. get {
  263. return false;
  264. }
  265. }
  266. #endif
  267. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  268. [Browsable (false)]
  269. [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
  270. public virtual Control NamingContainer {
  271. get {
  272. if (_namingContainer == null && _parent != null) {
  273. if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
  274. _namingContainer = _parent.NamingContainer;
  275. else
  276. _namingContainer = _parent;
  277. }
  278. return _namingContainer;
  279. }
  280. }
  281. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  282. [Browsable (false)]
  283. [WebSysDescription ("The webpage that this control resides on.")]
  284. #if NET_2_0
  285. [Bindable (false)]
  286. #endif
  287. public virtual Page Page //DIT
  288. {
  289. get
  290. {
  291. if (_page == null && _parent != null) _page = _parent.Page;
  292. return _page;
  293. }
  294. set
  295. {
  296. _page = value;
  297. }
  298. }
  299. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  300. [Browsable (false)]
  301. [WebSysDescription ("The parent control of this control.")]
  302. public virtual Control Parent //DIT
  303. {
  304. get
  305. {
  306. return _parent;
  307. }
  308. }
  309. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  310. [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
  311. [WebSysDescription ("The site this control is part of.")]
  312. public ISite Site //DIT
  313. {
  314. get
  315. {
  316. return _site;
  317. }
  318. set
  319. {
  320. _site = value;
  321. }
  322. }
  323. #if NET_2_0
  324. [Browsable (false)]
  325. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  326. public TemplateControl TemplateControl
  327. {
  328. get {
  329. return _templateControl;
  330. }
  331. [EditorBrowsable (EditorBrowsableState.Never)]
  332. set {
  333. _templateControl = value;
  334. }
  335. }
  336. #endif
  337. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  338. [Browsable (false)]
  339. [WebSysDescription ("A virtual directory containing the parent of the control.")]
  340. public virtual string TemplateSourceDirectory {
  341. get { return (_parent == null) ? String.Empty : _parent.TemplateSourceDirectory; }
  342. }
  343. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  344. [Browsable (false)]
  345. [WebSysDescription ("The unique ID of the control.")]
  346. public virtual string UniqueID {
  347. get {
  348. if (uniqueID != null)
  349. return uniqueID;
  350. if (_namingContainer == null) {
  351. if ((stateMask & IS_NAMING_CONTAINER) == 0)
  352. _namingContainer = NamingContainer;
  353. if (_namingContainer == null)
  354. return _userId;
  355. }
  356. if (_userId == null)
  357. _userId = _namingContainer.GetDefaultName ();
  358. string prefix = _namingContainer.UniqueID;
  359. if (_namingContainer == _page || prefix == null) {
  360. uniqueID = _userId;
  361. return uniqueID;
  362. }
  363. uniqueID = prefix + ":" + _userId;
  364. return uniqueID;
  365. }
  366. }
  367. void SetMask (int m, bool val)
  368. {
  369. if (val)
  370. stateMask |= m;
  371. else
  372. stateMask &= ~m;
  373. }
  374. [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
  375. [WebSysDescription ("Visiblity state of the control.")]
  376. public virtual bool Visible {
  377. get {
  378. if ((stateMask & VISIBLE) == 0)
  379. return false;
  380. if (_parent != null)
  381. return _parent.Visible;
  382. return true;
  383. }
  384. set {
  385. if ((value && (stateMask & VISIBLE) == 0) ||
  386. (!value && (stateMask & VISIBLE) != 0)) {
  387. if (IsTrackingViewState)
  388. stateMask |= VISIBLE_CHANGED;
  389. }
  390. SetMask (VISIBLE, value);
  391. }
  392. }
  393. protected bool ChildControlsCreated {
  394. get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
  395. set {
  396. if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0) {
  397. if (_controls != null)
  398. _controls.Clear();
  399. }
  400. SetMask (CHILD_CONTROLS_CREATED, value);
  401. }
  402. }
  403. [Browsable (false)]
  404. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  405. protected virtual HttpContext Context //DIT
  406. {
  407. get
  408. {
  409. HttpContext context;
  410. if (_context != null)
  411. return _context;
  412. if (_parent == null)
  413. return HttpContext.Current;
  414. context = _parent.Context;
  415. if (context != null)
  416. return context;
  417. return HttpContext.Current;
  418. }
  419. }
  420. protected EventHandlerList Events {
  421. get {
  422. if (_events == null)
  423. _events = new EventHandlerList ();
  424. return _events;
  425. }
  426. }
  427. protected bool HasChildViewState {
  428. get {
  429. return (pendingVS != null && pendingVS.Count > 0);
  430. }
  431. }
  432. protected bool IsTrackingViewState {
  433. get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
  434. }
  435. [Browsable (false)]
  436. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  437. [WebSysDescription ("ViewState")]
  438. protected virtual StateBag ViewState
  439. {
  440. get
  441. {
  442. if(_viewState == null)
  443. _viewState = new StateBag (ViewStateIgnoresCase);
  444. if (IsTrackingViewState)
  445. _viewState.TrackViewState ();
  446. return _viewState;
  447. }
  448. }
  449. [Browsable (false)]
  450. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  451. protected virtual bool ViewStateIgnoresCase
  452. {
  453. get {
  454. return false;
  455. }
  456. }
  457. internal bool AutoEventWireup {
  458. get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
  459. set { SetMask (AUTO_EVENT_WIREUP, value); }
  460. }
  461. internal void SetBindingContainer (bool isBC)
  462. {
  463. SetMask (BINDING_CONTAINER, isBC);
  464. }
  465. internal void ResetChildNames ()
  466. {
  467. defaultNumberID = 0;
  468. }
  469. string GetDefaultName ()
  470. {
  471. string defaultName;
  472. if (defaultNumberID > 99) {
  473. defaultName = "_ctl" + defaultNumberID++;
  474. } else {
  475. defaultName = defaultNameArray [defaultNumberID++];
  476. }
  477. return defaultName;
  478. }
  479. void NullifyUniqueID ()
  480. {
  481. uniqueID = null;
  482. if (!HasControls ())
  483. return;
  484. foreach (Control c in _controls)
  485. c.NullifyUniqueID ();
  486. }
  487. protected internal virtual void AddedControl (Control control, int index)
  488. {
  489. /* Ensure the control don't have more than 1 parent */
  490. if (control._parent != null)
  491. control._parent.Controls.Remove (control);
  492. control._parent = this;
  493. control._page = _page;
  494. Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
  495. if (nc != null) {
  496. control._namingContainer = nc;
  497. if (control.AutoID == true && control._userId == null)
  498. control._userId = nc.GetDefaultName ();
  499. }
  500. if ((stateMask & (INITING | INITED)) != 0)
  501. control.InitRecursive (nc);
  502. if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
  503. if (pendingVS != null) {
  504. object vs = pendingVS [index];
  505. if (vs != null) {
  506. pendingVS.Remove (index);
  507. if (pendingVS.Count == 0)
  508. pendingVS = null;
  509. control.LoadViewStateRecursive (vs);
  510. }
  511. }
  512. }
  513. if ((stateMask & LOADED) != 0)
  514. control.LoadRecursive ();
  515. if ((stateMask & PRERENDERED) != 0)
  516. control.PreRenderRecursiveInternal ();
  517. }
  518. protected virtual void AddParsedSubObject(object obj) //DIT
  519. {
  520. Control c = obj as Control;
  521. if (c != null) Controls.Add(c);
  522. }
  523. #if NET_2_0
  524. [MonoTODO]
  525. [EditorBrowsable (EditorBrowsableState.Advanced)]
  526. public virtual void ApplyStyleSheetSkin (Page page)
  527. {
  528. if (!EnableTheming) /* this enough? */
  529. return;
  530. /* apply the style sheet skin here */
  531. if (page.StyleSheetPageTheme != null) {
  532. ControlSkin cs = page.StyleSheetPageTheme.GetControlSkin (GetType(), SkinID);
  533. if (cs != null)
  534. cs.ApplySkin (this);
  535. }
  536. }
  537. #endif
  538. protected void BuildProfileTree(string parentId, bool calcViewState)
  539. {
  540. //TODO
  541. }
  542. #if NET_2_0
  543. protected void ClearChildControlState ()
  544. {
  545. throw new NotImplementedException ();
  546. }
  547. protected void ClearChildState ()
  548. {
  549. throw new NotImplementedException ();
  550. }
  551. #endif
  552. protected void ClearChildViewState ()
  553. {
  554. pendingVS = null;
  555. }
  556. #if NET_2_0
  557. protected internal
  558. #else
  559. protected
  560. #endif
  561. virtual void CreateChildControls() {} //DIT
  562. protected virtual ControlCollection CreateControlCollection() //DIT
  563. {
  564. return new ControlCollection(this);
  565. }
  566. protected virtual void EnsureChildControls ()
  567. {
  568. if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
  569. stateMask |= CREATING_CONTROLS;
  570. #if NET_2_0
  571. if (Adapter != null)
  572. Adapter.CreateChildControls ();
  573. else
  574. #endif
  575. CreateChildControls();
  576. ChildControlsCreated = true;
  577. stateMask &= ~CREATING_CONTROLS;
  578. }
  579. }
  580. #if NET_2_0
  581. protected void EnsureID ()
  582. {
  583. throw new NotImplementedException ();
  584. }
  585. protected bool HasEvents ()
  586. {
  587. throw new NotImplementedException ();
  588. }
  589. #endif
  590. protected bool IsLiteralContent()
  591. {
  592. if (HasControls () && _controls.Count == 1 && (_controls [0] is LiteralControl))
  593. return true;
  594. return false;
  595. }
  596. [WebSysDescription ("")]
  597. public virtual Control FindControl (string id)
  598. {
  599. return FindControl (id, 0);
  600. }
  601. Control LookForControlByName (string id)
  602. {
  603. if (!HasControls ())
  604. return null;
  605. Control result = null;
  606. foreach (Control c in _controls) {
  607. if (String.Compare (id, c._userId, true) == 0) {
  608. if (result != null && result != c) {
  609. throw new HttpException ("1 Found more than one control with ID '" + id + "'");
  610. }
  611. result = c;
  612. continue;
  613. }
  614. if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
  615. Control child = c.LookForControlByName (id);
  616. if (child != null) {
  617. if (result != null && result != child)
  618. throw new HttpException ("2 Found more than one control with ID '" + id + "'");
  619. result = child;
  620. }
  621. }
  622. }
  623. return result;
  624. }
  625. protected virtual Control FindControl (string id, int pathOffset)
  626. {
  627. EnsureChildControls ();
  628. Control namingContainer = null;
  629. if ((stateMask & IS_NAMING_CONTAINER) == 0) {
  630. namingContainer = NamingContainer;
  631. if (namingContainer == null)
  632. return null;
  633. return namingContainer.FindControl (id, pathOffset);
  634. }
  635. if (!HasControls ())
  636. return null;
  637. int colon = id.IndexOf (':', pathOffset);
  638. if (colon == -1)
  639. return LookForControlByName (id.Substring (pathOffset));
  640. string idfound = id.Substring (pathOffset, colon - pathOffset);
  641. namingContainer = LookForControlByName (idfound);
  642. if (namingContainer == null)
  643. return null;
  644. return namingContainer.FindControl (id, colon + 1);
  645. }
  646. protected virtual void LoadViewState(object savedState)
  647. {
  648. if (savedState != null) {
  649. ViewState.LoadViewState (savedState);
  650. object o = ViewState ["Visible"];
  651. if (o != null) {
  652. SetMask (VISIBLE, (bool) o);
  653. stateMask |= VISIBLE_CHANGED;
  654. }
  655. }
  656. }
  657. [MonoTODO("Secure?")]
  658. protected string MapPathSecure(string virtualPath)
  659. {
  660. string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
  661. return Context.Request.MapPath (combined);
  662. }
  663. protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
  664. {
  665. #if MONO_TRACE
  666. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  667. string type_name = null;
  668. if (trace != null) {
  669. type_name = GetType ().Name;
  670. trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
  671. }
  672. #endif
  673. return false;
  674. }
  675. protected virtual void OnDataBinding (EventArgs e)
  676. {
  677. if ((event_mask & databinding_mask) != 0) {
  678. EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
  679. if (eh != null) {
  680. #if MONO_TRACE
  681. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  682. string type_name = null;
  683. if (trace != null) {
  684. type_name = GetType ().Name;
  685. trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
  686. }
  687. #endif
  688. eh (this, e);
  689. }
  690. }
  691. }
  692. #if NET_2_0
  693. protected internal
  694. #else
  695. protected
  696. #endif
  697. virtual void OnInit (EventArgs e)
  698. {
  699. if ((event_mask & init_mask) != 0) {
  700. EventHandler eh = (EventHandler)(_events [InitEvent]);
  701. if (eh != null) {
  702. #if MONO_TRACE
  703. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  704. string type_name = null;
  705. if (trace != null) {
  706. type_name = GetType ().Name;
  707. trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
  708. }
  709. #endif
  710. eh (this, e);
  711. }
  712. }
  713. }
  714. #if NET_2_0
  715. protected internal
  716. #else
  717. protected
  718. #endif
  719. virtual void OnLoad (EventArgs e)
  720. {
  721. if ((event_mask & load_mask) != 0) {
  722. EventHandler eh = (EventHandler)(_events [LoadEvent]);
  723. if (eh != null) {
  724. #if MONO_TRACE
  725. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  726. string type_name = null;
  727. if (trace != null) {
  728. type_name = GetType ().Name;
  729. trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
  730. }
  731. #endif
  732. eh (this, e);
  733. }
  734. }
  735. }
  736. #if NET_2_0
  737. protected internal
  738. #else
  739. protected
  740. #endif
  741. virtual void OnPreRender (EventArgs e)
  742. {
  743. if ((event_mask & prerender_mask) != 0) {
  744. EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
  745. if (eh != null) {
  746. #if MONO_TRACE
  747. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  748. string type_name = null;
  749. if (trace != null) {
  750. type_name = GetType ().Name;
  751. trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
  752. }
  753. #endif
  754. eh (this, e);
  755. }
  756. }
  757. }
  758. #if NET_2_0
  759. protected internal
  760. #else
  761. protected
  762. #endif
  763. virtual void OnUnload(EventArgs e)
  764. {
  765. if ((event_mask & unload_mask) != 0) {
  766. EventHandler eh = (EventHandler)(_events [UnloadEvent]);
  767. if (eh != null) {
  768. #if MONO_TRACE
  769. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  770. string type_name = null;
  771. if (trace != null) {
  772. type_name = GetType ().Name;
  773. trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
  774. }
  775. #endif
  776. eh (this, e);
  777. }
  778. }
  779. }
  780. #if NET_2_0
  781. protected internal Stream OpenFile (string path)
  782. {
  783. throw new NotImplementedException ();
  784. }
  785. #endif
  786. protected void RaiseBubbleEvent(object source, EventArgs args)
  787. {
  788. Control c = Parent;
  789. while (c != null) {
  790. #if MONO_TRACE
  791. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  792. string type_name = null;
  793. if (trace != null) {
  794. type_name = GetType ().Name;
  795. trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
  796. }
  797. #endif
  798. if (c.OnBubbleEvent (source, args)) {
  799. #if MONO_TRACE
  800. if (trace != null)
  801. trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
  802. #endif
  803. break;
  804. }
  805. #if MONO_TRACE
  806. if (trace != null)
  807. trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
  808. #endif
  809. c = c.Parent;
  810. }
  811. }
  812. #if NET_2_0
  813. protected internal
  814. #else
  815. protected
  816. #endif
  817. virtual void Render(HtmlTextWriter writer) //DIT
  818. {
  819. RenderChildren(writer);
  820. }
  821. #if NET_2_0
  822. protected internal
  823. #else
  824. protected
  825. #endif
  826. virtual void RenderChildren (HtmlTextWriter writer) //DIT
  827. {
  828. if (_renderMethodDelegate != null) {
  829. _renderMethodDelegate (writer, this);
  830. } else if (_controls != null) {
  831. int len = _controls.Count;
  832. for (int i = 0; i < len; i++) {
  833. Control c = _controls [i];
  834. #if NET_2_0
  835. if (c.Adapter != null)
  836. c.RenderControl (writer, c.Adapter);
  837. else
  838. #endif
  839. c.RenderControl (writer);
  840. }
  841. }
  842. }
  843. #if NET_2_0
  844. protected virtual ControlAdapter ResolveAdapter ()
  845. {
  846. throw new NotImplementedException ();
  847. }
  848. #endif
  849. protected virtual object SaveViewState ()
  850. {
  851. if ((stateMask & VISIBLE_CHANGED) != 0) {
  852. ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
  853. } else if (_viewState == null) {
  854. return null;
  855. }
  856. return _viewState.SaveViewState ();
  857. }
  858. protected virtual void TrackViewState()
  859. {
  860. if (_viewState != null)
  861. _viewState.TrackViewState ();
  862. stateMask |= TRACK_VIEWSTATE;
  863. }
  864. public virtual void Dispose ()
  865. {
  866. if ((event_mask & disposed_mask) != 0) {
  867. EventHandler eh = (EventHandler)(_events [DisposedEvent]);
  868. if (eh != null) eh (this, EventArgs.Empty);
  869. }
  870. }
  871. [WebCategory ("FIXME")]
  872. [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
  873. public event EventHandler DataBinding {
  874. add {
  875. event_mask |= databinding_mask;
  876. Events.AddHandler (DataBindingEvent, value);
  877. }
  878. remove { Events.RemoveHandler (DataBindingEvent, value); }
  879. }
  880. [WebSysDescription ("Raised when the contol is disposed.")]
  881. public event EventHandler Disposed {
  882. add {
  883. event_mask |= disposed_mask;
  884. Events.AddHandler (DisposedEvent, value);
  885. }
  886. remove { Events.RemoveHandler (DisposedEvent, value); }
  887. }
  888. [WebSysDescription ("Raised when the page containing the control is initialized.")]
  889. public event EventHandler Init {
  890. add {
  891. event_mask |= init_mask;
  892. Events.AddHandler (InitEvent, value);
  893. }
  894. remove { Events.RemoveHandler (InitEvent, value); }
  895. }
  896. [WebSysDescription ("Raised after the page containing the control has been loaded.")]
  897. public event EventHandler Load {
  898. add {
  899. event_mask |= load_mask;
  900. Events.AddHandler (LoadEvent, value);
  901. }
  902. remove { Events.RemoveHandler (LoadEvent, value); }
  903. }
  904. [WebSysDescription ("Raised before the page containing the control is rendered.")]
  905. public event EventHandler PreRender {
  906. add {
  907. event_mask |= prerender_mask;
  908. Events.AddHandler (PreRenderEvent, value);
  909. }
  910. remove { Events.RemoveHandler (PreRenderEvent, value); }
  911. }
  912. [WebSysDescription ("Raised when the page containing the control is unloaded.")]
  913. public event EventHandler Unload {
  914. add {
  915. event_mask |= unload_mask;
  916. Events.AddHandler (UnloadEvent, value);
  917. }
  918. remove { Events.RemoveHandler (UnloadEvent, value); }
  919. }
  920. public virtual void DataBind() //DIT
  921. {
  922. #if NET_2_0
  923. DataBind (true);
  924. #else
  925. OnDataBinding (EventArgs.Empty);
  926. DataBindChildren();
  927. #endif
  928. }
  929. #if NET_2_0
  930. protected virtual
  931. #endif
  932. void DataBindChildren ()
  933. {
  934. if (!HasControls ())
  935. return;
  936. int len = _controls.Count;
  937. for (int i = 0; i < len; i++) {
  938. Control c = _controls [i];
  939. c.DataBind ();
  940. }
  941. }
  942. public virtual bool HasControls ()
  943. {
  944. return (_controls != null && _controls.Count > 0);
  945. }
  946. #if NET_2_0
  947. public virtual
  948. #else
  949. public
  950. #endif
  951. void RenderControl (HtmlTextWriter writer)
  952. {
  953. if ((stateMask & VISIBLE) != 0) {
  954. HttpContext ctx = Context;
  955. TraceContext trace = (ctx != null) ? ctx.Trace : null;
  956. int pos = 0;
  957. if ((trace != null) && trace.IsEnabled)
  958. pos = ctx.Response.GetOutputByteCount ();
  959. Render(writer);
  960. if ((trace != null) && trace.IsEnabled) {
  961. int size = ctx.Response.GetOutputByteCount () - pos;
  962. trace.SaveSize (this, size >= 0 ? size : 0);
  963. }
  964. }
  965. }
  966. #if NET_2_0
  967. protected void RenderControl (HtmlTextWriter writer,
  968. ControlAdapter adapter)
  969. {
  970. if ((stateMask & VISIBLE) != 0) {
  971. adapter.BeginRender (writer);
  972. adapter.Render (writer);
  973. adapter.EndRender (writer);
  974. }
  975. }
  976. #endif
  977. public string ResolveUrl (string relativeUrl)
  978. {
  979. if (relativeUrl == null)
  980. throw new ArgumentNullException ("relativeUrl");
  981. if (relativeUrl == "")
  982. return "";
  983. if (relativeUrl [0] == '#')
  984. return relativeUrl;
  985. string ts = TemplateSourceDirectory;
  986. if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
  987. return relativeUrl;
  988. HttpResponse resp = Context.Response;
  989. return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
  990. }
  991. #if NET_2_0
  992. public
  993. #else
  994. internal
  995. #endif
  996. string ResolveClientUrl (string relativeUrl)
  997. {
  998. if (relativeUrl == null)
  999. throw new ArgumentNullException ("relativeUrl");
  1000. if (relativeUrl == "")
  1001. return "";
  1002. if (relativeUrl [0] == '#')
  1003. return relativeUrl;
  1004. string ts = TemplateSourceDirectory;
  1005. if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
  1006. return relativeUrl;
  1007. HttpResponse resp = Context.Response;
  1008. string absoluteUrl = resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
  1009. if (absoluteUrl.StartsWith (ts + "/"))
  1010. return absoluteUrl.Substring (ts.Length + 1);
  1011. return absoluteUrl;
  1012. }
  1013. internal bool HasRenderMethodDelegate () {
  1014. return _renderMethodDelegate != null;
  1015. }
  1016. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1017. public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
  1018. {
  1019. _renderMethodDelegate = renderMethod;
  1020. }
  1021. internal void LoadRecursive()
  1022. {
  1023. #if MONO_TRACE
  1024. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1025. string type_name = null;
  1026. if (trace != null) {
  1027. type_name = GetType ().Name;
  1028. trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
  1029. }
  1030. #endif
  1031. #if NET_2_0
  1032. if (Adapter != null)
  1033. Adapter.OnLoad (EventArgs.Empty);
  1034. else
  1035. #endif
  1036. OnLoad (EventArgs.Empty);
  1037. if (HasControls ()) {
  1038. int len = _controls.Count;
  1039. for (int i=0;i<len;i++)
  1040. {
  1041. Control c = _controls[i];
  1042. c.LoadRecursive ();
  1043. }
  1044. }
  1045. #if MONO_TRACE
  1046. if (trace != null)
  1047. trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
  1048. #endif
  1049. stateMask |= LOADED;
  1050. }
  1051. internal void UnloadRecursive(Boolean dispose)
  1052. {
  1053. #if MONO_TRACE
  1054. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1055. string type_name = null;
  1056. if (trace != null) {
  1057. type_name = GetType ().Name;
  1058. trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
  1059. }
  1060. #endif
  1061. if (HasControls ()) {
  1062. int len = _controls.Count;
  1063. for (int i=0;i<len;i++)
  1064. {
  1065. Control c = _controls[i];
  1066. c.UnloadRecursive (dispose);
  1067. }
  1068. }
  1069. #if MONO_TRACE
  1070. if (trace != null)
  1071. trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
  1072. #endif
  1073. #if NET_2_0
  1074. if (Adapter != null)
  1075. Adapter.OnUnload (EventArgs.Empty);
  1076. else
  1077. #endif
  1078. OnUnload (EventArgs.Empty);
  1079. if (dispose)
  1080. Dispose();
  1081. }
  1082. internal void PreRenderRecursiveInternal()
  1083. {
  1084. if ((stateMask & VISIBLE) != 0) {
  1085. EnsureChildControls ();
  1086. #if MONO_TRACE
  1087. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1088. string type_name = null;
  1089. if (trace != null) {
  1090. type_name = GetType ().Name;
  1091. trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
  1092. }
  1093. #endif
  1094. #if NET_2_0
  1095. if (Adapter != null)
  1096. Adapter.OnPreRender (EventArgs.Empty);
  1097. else
  1098. #endif
  1099. OnPreRender (EventArgs.Empty);
  1100. if (!HasControls ())
  1101. return;
  1102. int len = _controls.Count;
  1103. for (int i=0;i<len;i++)
  1104. {
  1105. Control c = _controls[i];
  1106. c.PreRenderRecursiveInternal ();
  1107. }
  1108. #if MONO_TRACE
  1109. if (trace != null)
  1110. trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
  1111. #endif
  1112. }
  1113. stateMask |= PRERENDERED;
  1114. }
  1115. internal void InitRecursive(Control namingContainer)
  1116. {
  1117. #if MONO_TRACE
  1118. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1119. string type_name = null;
  1120. if (trace != null) {
  1121. type_name = GetType ().Name;
  1122. trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
  1123. }
  1124. #endif
  1125. if (HasControls ()) {
  1126. if ((stateMask & IS_NAMING_CONTAINER) != 0)
  1127. namingContainer = this;
  1128. if (namingContainer != null &&
  1129. namingContainer._userId == null &&
  1130. namingContainer.AutoID)
  1131. namingContainer._userId = namingContainer.GetDefaultName () + "b";
  1132. int len = _controls.Count;
  1133. for (int i=0;i<len;i++)
  1134. {
  1135. Control c = _controls[i];
  1136. c._page = Page;
  1137. c._namingContainer = namingContainer;
  1138. if (namingContainer != null && c._userId == null && c.AutoID)
  1139. c._userId = namingContainer.GetDefaultName () + "c";
  1140. c.InitRecursive (namingContainer);
  1141. }
  1142. }
  1143. stateMask |= INITING;
  1144. #if NET_2_0
  1145. ApplyTheme ();
  1146. if (Adapter != null)
  1147. Adapter.OnInit (EventArgs.Empty);
  1148. else
  1149. #endif
  1150. OnInit (EventArgs.Empty);
  1151. #if MONO_TRACE
  1152. if (trace != null)
  1153. trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
  1154. #endif
  1155. TrackViewState ();
  1156. stateMask |= INITED;
  1157. stateMask &= ~INITING;
  1158. }
  1159. internal object SaveViewStateRecursive ()
  1160. {
  1161. if (!EnableViewState)
  1162. return null;
  1163. #if MONO_TRACE
  1164. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1165. string type_name = null;
  1166. if (trace != null) {
  1167. type_name = GetType ().Name;
  1168. trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
  1169. }
  1170. #endif
  1171. ArrayList controlList = null;
  1172. ArrayList controlStates = null;
  1173. int idx = -1;
  1174. if (HasControls ())
  1175. {
  1176. int len = _controls.Count;
  1177. for (int i=0;i<len;i++)
  1178. {
  1179. Control ctrl = _controls[i];
  1180. object ctrlState = ctrl.SaveViewStateRecursive ();
  1181. idx++;
  1182. if (ctrlState == null)
  1183. continue;
  1184. if (controlList == null)
  1185. {
  1186. controlList = new ArrayList ();
  1187. controlStates = new ArrayList ();
  1188. }
  1189. controlList.Add (idx);
  1190. controlStates.Add (ctrlState);
  1191. }
  1192. }
  1193. object thisState = SaveViewState ();
  1194. if (thisState == null && controlList == null && controlStates == null) {
  1195. #if MONO_TRACE
  1196. if (trace != null) {
  1197. trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
  1198. trace.SaveViewState (this, null);
  1199. }
  1200. #endif
  1201. return null;
  1202. }
  1203. #if MONO_TRACE
  1204. if (trace != null) {
  1205. trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
  1206. trace.SaveViewState (this, thisState);
  1207. }
  1208. #endif
  1209. return new Triplet (thisState, controlList, controlStates);
  1210. }
  1211. internal void LoadViewStateRecursive (object savedState)
  1212. {
  1213. if (!EnableViewState || savedState == null)
  1214. return;
  1215. #if MONO_TRACE
  1216. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1217. string type_name = null;
  1218. if (trace != null) {
  1219. type_name = GetType ().Name;
  1220. trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
  1221. }
  1222. #endif
  1223. Triplet savedInfo = (Triplet) savedState;
  1224. LoadViewState (savedInfo.First);
  1225. ArrayList controlList = savedInfo.Second as ArrayList;
  1226. if (controlList == null)
  1227. return;
  1228. ArrayList controlStates = savedInfo.Third as ArrayList;
  1229. int nControls = controlList.Count;
  1230. for (int i = 0; i < nControls; i++) {
  1231. int k = (int) controlList [i];
  1232. if (k < Controls.Count && controlStates != null) {
  1233. Control c = Controls [k];
  1234. c.LoadViewStateRecursive (controlStates [i]);
  1235. } else {
  1236. if (pendingVS == null)
  1237. pendingVS = new Hashtable ();
  1238. pendingVS [k] = controlStates [i];
  1239. }
  1240. }
  1241. #if MONO_TRACE
  1242. if (trace != null)
  1243. trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
  1244. #endif
  1245. stateMask |= VIEWSTATE_LOADED;
  1246. }
  1247. #if NET_2_0
  1248. internal ControlSkin controlSkin;
  1249. internal void ApplyTheme ()
  1250. {
  1251. #if MONO_TRACE
  1252. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1253. string type_name = null;
  1254. if (trace != null) {
  1255. type_name = GetType ().Name;
  1256. trace.Write ("control", String.Format ("ApplyThemeRecursive {0} {1}", _userId, type_name));
  1257. }
  1258. #endif
  1259. if (Page.PageTheme != null && EnableTheming) {
  1260. ControlSkin controlSkin = Page.PageTheme.GetControlSkin (GetType (), SkinID);
  1261. if (controlSkin != null)
  1262. controlSkin.ApplySkin (this);
  1263. }
  1264. #if MONO_TRACE
  1265. if (trace != null)
  1266. trace.Write ("control", String.Format ("End ApplyThemeRecursive {0} {1}", _userId, type_name));
  1267. #endif
  1268. }
  1269. #endif
  1270. internal bool AutoID
  1271. {
  1272. get { return (stateMask & AUTOID) != 0; }
  1273. set {
  1274. if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
  1275. return;
  1276. SetMask (AUTOID, value);
  1277. }
  1278. }
  1279. protected internal virtual void RemovedControl (Control control)
  1280. {
  1281. control.UnloadRecursive (false);
  1282. control._parent = null;
  1283. control._page = null;
  1284. control._namingContainer = null;
  1285. }
  1286. #if NET_2_0
  1287. string skinId = string.Empty;
  1288. bool _enableTheming = true;
  1289. [Browsable (false)]
  1290. [Themeable (false)]
  1291. [DefaultValue (true)]
  1292. public virtual bool EnableTheming
  1293. {
  1294. get
  1295. {
  1296. if ((stateMask & ENABLE_THEMING) != 0)
  1297. return _enableTheming;
  1298. if (_parent != null)
  1299. return _parent.EnableTheming;
  1300. return true;
  1301. }
  1302. set
  1303. {
  1304. SetMask (ENABLE_THEMING, true);
  1305. _enableTheming = value;
  1306. }
  1307. }
  1308. [Browsable (false)]
  1309. [DefaultValue ("")]
  1310. [Filterable (false)]
  1311. public virtual string SkinID
  1312. {
  1313. get { return skinId; }
  1314. set { skinId = value; }
  1315. }
  1316. ControlBuilder IControlBuilderAccessor.ControlBuilder {
  1317. get {throw new NotImplementedException (); }
  1318. }
  1319. IDictionary IControlDesignerAccessor.GetDesignModeState ()
  1320. {
  1321. throw new NotImplementedException ();
  1322. }
  1323. void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
  1324. {
  1325. SetDesignModeState (designData);
  1326. }
  1327. void IControlDesignerAccessor.SetOwnerControl (Control control)
  1328. {
  1329. throw new NotImplementedException ();
  1330. }
  1331. IDictionary IControlDesignerAccessor.UserData {
  1332. get { throw new NotImplementedException (); }
  1333. }
  1334. ExpressionBindingCollection expressionBindings;
  1335. ExpressionBindingCollection IExpressionsAccessor.Expressions {
  1336. get {
  1337. if (expressionBindings == null)
  1338. expressionBindings = new ExpressionBindingCollection ();
  1339. return expressionBindings;
  1340. }
  1341. }
  1342. bool IExpressionsAccessor.HasExpressions {
  1343. get {
  1344. return (expressionBindings != null && expressionBindings.Count > 0);
  1345. }
  1346. }
  1347. [MonoTODO]
  1348. public virtual void Focus()
  1349. {
  1350. throw new NotImplementedException();
  1351. }
  1352. protected internal virtual void LoadControlState (object state)
  1353. {
  1354. }
  1355. protected internal virtual object SaveControlState ()
  1356. {
  1357. return null;
  1358. }
  1359. protected virtual void DataBind (bool raiseOnDataBinding)
  1360. {
  1361. bool foundDataItem = false;
  1362. if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
  1363. object o = DataBinder.GetDataItem (this, out foundDataItem);
  1364. if (foundDataItem)
  1365. Page.PushDataItemContext (o);
  1366. }
  1367. try {
  1368. if (raiseOnDataBinding)
  1369. OnDataBinding (EventArgs.Empty);
  1370. DataBindChildren();
  1371. } finally {
  1372. if (foundDataItem)
  1373. Page.PopDataItemContext ();
  1374. }
  1375. }
  1376. protected virtual IDictionary GetDesignModeState ()
  1377. {
  1378. throw new NotImplementedException ();
  1379. }
  1380. protected virtual void SetDesignModeState (IDictionary data)
  1381. {
  1382. throw new NotImplementedException ();
  1383. }
  1384. #endif
  1385. void IParserAccessor.AddParsedSubObject (object obj) {
  1386. this.AddParsedSubObject (obj);
  1387. }
  1388. DataBindingCollection IDataBindingsAccessor.DataBindings {
  1389. get {
  1390. if (dataBindings == null) {
  1391. dataBindings = new DataBindingCollection ();
  1392. }
  1393. return dataBindings;
  1394. }
  1395. }
  1396. bool IDataBindingsAccessor.HasDataBindings {
  1397. get {
  1398. if (dataBindings != null && dataBindings.Count > 0) {
  1399. return true;
  1400. }
  1401. return false;
  1402. }
  1403. }
  1404. }
  1405. }