Control.cs 42 KB

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