Control.cs 46 KB

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