Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Control.cs « System.Web.UI « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 257be55c8262e0b3406e141293b1a125edea2790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
//
// System.Web.UI.Control.cs
//
// Author:
//   Bob Smith <bob@thestuff.net>
//
// (C) Bob Smith
//

/*
 * Maintainer: bob@thestuff.net, gvaish@iitk.ac.in
 * (C) Bob Smith, Gaurav Vaish
 */

//notes: view state only tracks changes after OnInit method is executed for the page request. You can read from it at any time, but cant write to it during rendering.
//even more notes: view state info in trackviewstate method description. read later.
//Ok, enough notes: what the heck is different between enable view state, and track view state.
//Well, maybe not. How does the ViewState know when to track changes? Does it look at the property
//on the owning control, or does it have a method/property of its own that gets called?
// I think this last question is solved in the Interface for it. Look into this.

//cycle:
//init is called when control is first created.
//load view state ic called right after init to populate the view state.
//loadpostdata is called if ipostbackdatahandler is implemented.
//load is called when control is loaded into a page
//raisepostdatachangedevent if ipostbackdatahandler is implemented.
//raisepostbackevent if ipostbackeventhandler is implemented.
//prerender is called when the server is about to render its page object
//SaveViewState is called.
//Unload then dispose it apears. :)

//Naming Container MUST have some methods. What are they? No clue. Help?

//read this later. http://gotdotnet.com/quickstart/aspplus/
//This to: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpconattributesdesign-timesupport.asp
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpcontracefunctionality.asp

// Isnt life grand? :)
// See the undocumented methods? Gota love um. ;)
// ASP.test4_aspx.Page_Load(Object Sender, EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
// System.Web.UI.Control.OnLoad(EventArgs e) +67
// System.Web.UI.Control.LoadRecursive() +73
// System.Web.UI.Page.ProcessRequestMain() +394

// ASP.test4_aspx.Page_Unload(Object Sender, EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
// System.EventHandler.Invoke(Object sender, EventArgs e) +0
// System.Web.UI.Control.OnUnload(EventArgs e) +67
// System.Web.UI.Control.UnloadRecursive(Boolean dispose) +78
// System.Web.UI.Page.ProcessRequest() +194
// System.Web.UI.Page.ProcessRequest(HttpContext context) +18
// System.Web.CallHandlerExecutionStep.Execute() +179
// System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87


// ASP.test4_aspx.Page_Unload(Object Sender, EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
// System.Web.UI.Control.OnUnload(EventArgs e) +67
// System.Web.UI.Control.UnloadRecursive(Boolean dispose) +78
// System.Web.UI.Page.ProcessRequest()

// ASP.test4_aspx.Page_Kill(Object Sender, EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
// System.Web.UI.Control.OnPreRender(EventArgs e) +67
// System.Web.UI.Control.PreRenderRecursiveInternal() +61
// System.Web.UI.Page.ProcessRequestMain() +753

// ASP.test4_aspx.OnInit(EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
// System.Web.UI.Control.InitRecursive(Control namingContainer) +202
// System.Web.UI.Page.ProcessRequestMain() +120

// ASP.test4_aspx.SaveViewState() in \\genfs2\www24\bobsmith11\test4.aspx:12
// System.Web.UI.Control.SaveViewStateRecursive() +51
// System.Web.UI.Page.SavePageViewState() +174
// System.Web.UI.Page.ProcessRequestMain() +861

// ASP.test_aspx.LoadViewState(Object t) +28
// System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +125
// System.Web.UI.Page.LoadPageViewState() +182
// System.Web.UI.Page.ProcessRequestMain() +256

using System;
using System.Collections;
using System.Web;
using System.ComponentModel;

namespace System.Web.UI
{
        public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
        {
                private static readonly object DataBindingEvent = new object();
                private static readonly object DisposedEvent = new object();
                private static readonly object InitEvent = new object();
                private static readonly object LoadEvent = new object();
                private static readonly object PreRenderEvent = new object();
                private static readonly object UnloadEvent = new object();
                private string _userId = null;
                private string _cachedUserId = null;
                private string _cachedClientId = null;
                private ControlCollection _controls = null;
                private bool _enableViewState = true;
                private IDictionary _childViewStates = null; //TODO: Not sure datatype. Placeholder guess.
                private bool _isNamingContainer = false;
                private Control _namingContainer = null;
                private Page _page = null;
                private Control _parent = null;
                private ISite _site = null;
                private bool _visible = true;
                private HttpContext _context = null;
                private bool _childControlsCreated = false;
                private StateBag _viewState = null;
                private bool _trackViewState = false;
                private EventHandlerList _events = new EventHandlerList();
                private RenderMethod _renderMethodDelegate = null;
		private bool autoID = true;
		private bool creatingControls = false;
        	
        	    private DataBindingCollection dataBindings = null;

                public Control()
                {
                        if (this is INamingContainer) _isNamingContainer = true;
                }

		public Control BindingContainer
		{
			get {
				Control container = NamingContainer;
				if (_isNamingContainer)
					container = container.BindingContainer;
				return container;
			}
		}
		
                public virtual string ClientID //DIT
                {
                        get
                        {
                                if (_cachedUserId != null && _cachedClientId != null)
                                        return _cachedClientId;
                                _cachedUserId = UniqueID.Replace(':', '_');
                                return _cachedUserId;
                        }
                }
                public virtual ControlCollection Controls //DIT
                {
                        get
                        {
                                if (_controls == null) _controls = CreateControlCollection();
                                return _controls;
                        }
                }
                public virtual bool EnableViewState //DIT
                {
                        get
                        {
                                return _enableViewState;
                        }
                        set
                        {
                                _enableViewState = value;
                        }
                }
                public virtual string ID
                {
                        get //DIT
                        {
                                return _userId;
                        }
                        set
                        {
                                if (value == null || value == "") return;
                                _userId = value;
                                _cachedUserId = null;
                                //TODO: Some Naming Container stuff here I think.
                        }
                }
                public virtual Control NamingContainer //DIT
                {
                        get
                        {
                                if (_namingContainer == null && _parent != null)
                                {
                                        if (_parent._isNamingContainer == false)
                                                _namingContainer = _parent.NamingContainer;
                                        else
                                                _namingContainer = _parent;
                                }
                                return _namingContainer;
                        }
                }
                public virtual Page Page //DIT
                {
                        get
                        {
                                if (_page == null && _parent != null) _page = _parent.Page;
                                return _page;
                        }
                        set
                        {
                                _page = value;
                        }
                }
                public virtual Control Parent //DIT
                {
                        get
                        {
                                return _parent;
                        }
                }
                public ISite Site //DIT
                {
                        get
                        {
                                return _site;
                        }
                        set
                        {
                                _site = value;
                        }
                }
                public virtual string TemplateSourceDirectory
                {
                        get
                        {
                                return Context.Request.ApplicationPath; //TODO: Dont think this is right.
                        }
                }

				[MonoTODO]
                public virtual string UniqueID
                {
                        get
                        {
                                //TODO: Some Naming container methods here. What are they? Why arnt they declared?
                                //Note: Nuked the old stuff here. Was total crap. :)
                                return ID;
                        }
                }
                public virtual bool Visible
                { //TODO: Are children visible when parents are not?
                        get
                        {
                                return _visible;
                        }
                        set
                        {
                                _visible = value;
                        }
                }
                protected bool ChildControlsCreated //DIT
                {
                        get
                        {
                                return _childControlsCreated;
                        }
                        set
                        {
                                if (value == false && _childControlsCreated == true)
                                        _controls.Clear();
                                _childControlsCreated = value;
                        }
                }
                protected virtual HttpContext Context //DIT
                {
                        get
                        {
                                HttpContext context;
                                if (_context != null)
                                        return _context;
                                if (_parent == null)
                                        return HttpContext.Current;
                                context = _parent.Context;
                                if (context != null)
                                        return context;
                                return HttpContext.Current;
                        }
                }
                protected EventHandlerList Events //DIT
                {
                        get
                        {
                                if (_events == null)
                                {
                                	_events = new EventHandlerList();
                                }
                                return _events;
                        }
                }
                protected bool HasChildViewState //DIT
                {
                        get
                        {
                                if (_childViewStates == null) return false;
                                return true;
                        }
                }
                protected bool IsTrackingViewState //DIT
                {
                        get
                        {
                                return _trackViewState;
                        }
                }
                protected virtual StateBag ViewState
                {
                        get
                        {
                        	if(_viewState == null)
                        	{
	                        	_viewState = new StateBag(ViewStateIgnoresCase);
    	                    	if(IsTrackingViewState)
        	                		_viewState.TrackViewState();
                        	}
                        	return _viewState;
                        }
                }
                protected virtual bool ViewStateIgnoresCase //DIT
                {
                        get
                        {
                                return true;
                        }
                }

		private int defaultNumberID;
		protected internal virtual void AddedControl (Control control, int index)
		{
			/* Ensure the control don't have more than 1 parent */
			if (control._parent != null)
				control._parent.Controls.Remove (control);

			control._parent = this;
			control._page = _page;

			// Without this, DataBoundLiteralControl crashes in OnDataBound event.
			Control namingContainer = NamingContainer;
			if (namingContainer != null)
				control._namingContainer = namingContainer;
			
			if (control.AutoID == true && control.ID == null)
				control.ID = "_ctrl_" + defaultNumberID++;
		}

                protected virtual void AddParsedSubObject(object obj) //DIT
                {
                        Control c = (Control)obj;
                        if (c != null) Controls.Add(c);
                }
                protected void BuildProfileTree(string parentId, bool calcViewState)
                {
                        //TODO
                }
                protected void ClearChildViewState()
                {
                        //TODO
                        //Not quite sure about this. an example clears children then calls this, so I think
                        //view state is local to the current object, not children.
                }
                protected virtual void CreateChildControls() {} //DIT
                protected virtual ControlCollection CreateControlCollection() //DIT
                {
                        return new ControlCollection(this);
                }

                protected virtual void EnsureChildControls () //DIT
                {
                        if (ChildControlsCreated == false && !creatingControls) {
				creatingControls = true;
                                CreateChildControls();
                                ChildControlsCreated = true;
				creatingControls = false;
                        }
                }

                protected virtual Control FindControl(string id, int pathOffset)
                {
                        //TODO: I think there is Naming Container stuff here. Redo.
                        int i;
                        for (i = pathOffset; i < _controls.Count; i++)
                                if (_controls[i].ID == id) return _controls[i];
                        return null;
                }
                protected virtual void LoadViewState(object savedState)
                {
                        //TODO: What should I do by default?
                }
                
				[MonoTODO]
                protected string MapPathSecure(string virtualPath)
                {
                        //TODO: Need to read up on security+web.
			//Return the same path. So AdRotator can read its config file.
			return virtualPath;
                }
                protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
                {
                        return false;
                }
                protected virtual void OnDataBinding(EventArgs e) //DIT
                {
                        if (_events != null)
                        {
                                EventHandler eh = (EventHandler)(_events[DataBindingEvent]);
                                if (eh != null) eh(this, e);
                        }
                }
                protected virtual void OnInit(EventArgs e) //DIT
                {
                        if (_events != null)
                        {
                                EventHandler eh = (EventHandler)(_events[InitEvent]);
                                if (eh != null) eh(this, e);
                        }
                }
                protected virtual void OnLoad(EventArgs e) //DIT
                {
                        if (_events != null)
                        {
                                EventHandler eh = (EventHandler)(_events[LoadEvent]);
                                if (eh != null) eh(this, e);
                        }
                }
                protected virtual void OnPreRender(EventArgs e) //DIT
                {
                        if (_events != null)
                        {
                                EventHandler eh = (EventHandler)(_events[PreRenderEvent]);
                                if (eh != null) eh(this, e);
                        }
                }
                protected virtual void OnUnload(EventArgs e) //DIT
                {
                        if (_events != null)
                        {
                                EventHandler eh = (EventHandler)(_events[UnloadEvent]);
                                if (eh != null) eh(this, e);
                        }
                }
                
				[MonoTODO]
                protected void RaiseBubbleEvent(object source, EventArgs args)
                {
                        throw new NotImplementedException();
                        //return false;
                }
                protected virtual void Render(HtmlTextWriter writer) //DIT
                {
                        RenderChildren(writer);
                }
                protected virtual void RenderChildren(HtmlTextWriter writer) //DIT
                {
                        if (_renderMethodDelegate != null)
                                _renderMethodDelegate(writer, this);
                        else if (_controls != null)
                                foreach (Control c in _controls)
                                        c.RenderControl(writer);
                }
                protected virtual object SaveViewState()
                {
                        return ViewState;
                }
                protected virtual void TrackViewState()
                {
                        _trackViewState = true;
                }
                
				[MonoTODO]
                public virtual void Dispose()
                {
                        //TODO: nuke stuff.
                        throw new NotImplementedException();
                	/*
                        if (_events != null)
                        {
                                EventHandler eh = (EventHandler)(_events[DisposedEvent]);
                                if (eh != null) eh(this, e);
                        }
                    */
                }

		public bool HasChildren
		{
			get { return (_controls != null && _controls.Count > 0); }
		}

                public event EventHandler DataBinding //DIT
                {
                        add
                        {
                                Events.AddHandler(DataBindingEvent, value);
                        }
                        remove
                        {
                                Events.RemoveHandler(DataBindingEvent, value);
                        }
                }
                public event EventHandler Disposed //DIT
                {
                        add
                        {
                                Events.AddHandler(DisposedEvent, value);
                        }
                        remove
                        {
                                Events.RemoveHandler(DisposedEvent, value);
                        }
                }
                public event EventHandler Init //DIT
                {
                        add
                        {
                                Events.AddHandler(InitEvent, value);
                        }
                        remove
                        {
                                Events.RemoveHandler(InitEvent, value);
                        }
                }
                public event EventHandler Load //DIT
                {
                        add
                        {
                                Events.AddHandler(LoadEvent, value);
                        }
                        remove
                        {
                                Events.RemoveHandler(LoadEvent, value);
                        }
                }
                public event EventHandler PreRender //DIT
                {
                        add
                        {
                                Events.AddHandler(PreRenderEvent, value);
                        }
                        remove
                        {
                                Events.RemoveHandler(PreRenderEvent, value);
                        }
                }
                public event EventHandler Unload //DIT
                {
                        add
                        {
                                Events.AddHandler(UnloadEvent, value);
                        }
                        remove
                        {
                                Events.RemoveHandler(UnloadEvent, value);
                        }
                }
                public virtual void DataBind() //DIT
                {
                        OnDataBinding(EventArgs.Empty);
                        if (_controls != null)
                                foreach (Control c in _controls)
                                        c.DataBind();
                }
                public virtual Control FindControl(string id) //DIT
                {
                        return FindControl(id, 0);
                }
                public virtual bool HasControls() //DIT
                {
                        if (_controls != null && _controls.Count >0) return true;
                        return false;
                }
                public void RenderControl(HtmlTextWriter writer)
                {
                        if (_visible)
                        {
				// By now, PreRender is fired here.
				OnPreRender (EventArgs.Empty); //FIXME
                                //TODO: Something about tracing here.
                                Render(writer);
                        }
                }
                
                [MonoTODO]
                public string ResolveUrl(string relativeUrl)
                {
                	return relativeUrl;
                }
                public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
                {
                        _renderMethodDelegate = renderMethod;
                }
                protected void LoadRecursive()
                {
                        OnLoad(EventArgs.Empty);
                        if (_controls != null) foreach (Control c in _controls) c.LoadRecursive();
                }
                protected void UnloadRecursive(Boolean dispose)
                {
                        OnUnload(EventArgs.Empty);
                        if (_controls != null) foreach (Control c in _controls) c.UnloadRecursive(dispose);
                        if (dispose) Dispose();
                }
                protected void PreRenderRecursiveInternal()
                {
                        OnPreRender(EventArgs.Empty);
                        if (_controls != null) foreach (Control c in _controls) c.PreRenderRecursiveInternal();
                }
                protected void InitRecursive(Control namingContainer)
                {
                        if (_controls != null) foreach (Control c in _controls) c.InitRecursive(namingContainer);
                        OnInit(EventArgs.Empty);
                }
                
                [MonoTODO]
                protected object SaveViewStateRecursive()
                {
                        throw new NotImplementedException();
                }
                
                [MonoTODO]
                protected void LoadViewStateRecursive(Object savedState)
                {
                        throw new NotImplementedException();
                }
                
                void IParserAccessor.AddParsedSubObject(object obj)
                {
                	this.AddParsedSubObject(obj);
                }
                
                DataBindingCollection IDataBindingsAccessor.DataBindings
                {
                	get
                	{
                		if(dataBindings == null)
                			dataBindings = new DataBindingCollection();
                		return dataBindings;
                	}
                }
                
                bool IDataBindingsAccessor.HasDataBindings
                {
                	get
                	{
                		return (dataBindings!=null && dataBindings.Count>0);
                	}
                }
                
		internal bool AutoID
		{
			get { return autoID; }
			set { autoID = value; }
		}

                internal void PreventAutoID()
                {
			AutoID = false;
                }
                
                //TODO: I think there are some needed Interface implementations to do here.
                //TODO: Find api for INamingContainer.
        }
}