Merge pull request #4453 from lambdageek/bug-49721
[mono.git] / mcs / class / System.Web / System.Web.UI.Adapters / ControlAdapter.cs
1 //
2 // System.Web.UI.Adapters.ControlAdapter
3 //
4 // Author:
5 //      Dick Porter  <dick@ximian.com>
6 //
7 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System.Web;
30 using System.Web.UI;
31 using System.ComponentModel;
32
33 namespace System.Web.UI.Adapters
34 {
35         public abstract class ControlAdapter
36         {
37                 internal ControlAdapter (Control c)
38                 {
39                         control = c;
40                 }
41                 
42                 protected ControlAdapter ()
43                 {
44                 }
45
46                 protected HttpBrowserCapabilities Browser 
47                 {
48                         get {
49                                 Page page = Page;
50
51                                 if (page != null)
52                                         return page.Request.Browser;
53
54                                 return null;
55                         }
56                 }
57
58                 internal Control control;
59                 
60                 [Browsable (false)]
61                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
62                 protected Control Control 
63                 {
64                         get { return control; }
65                 }
66
67                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
68                 [Browsable (false)]
69                 protected Page Page 
70                 {
71                         get {
72                                 Control control = Control;
73
74                                 if (control != null)
75                                         return control.Page;
76
77                                 return null;
78                         }
79                 }
80                 
81                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
82                 [Browsable (false)]
83                 protected PageAdapter PageAdapter 
84                 {
85                         get {
86                                 Page page = Page;
87
88                                 if (page != null)
89                                         return page.PageAdapter;
90
91                                 return null;
92                         }
93                 }
94
95                 protected internal virtual void BeginRender (HtmlTextWriter writer)
96                 {
97                         writer.BeginRender();
98                 }
99
100                 protected internal virtual void CreateChildControls ()
101                 {
102                         Control control = Control;
103                         if (control != null)
104                                 control.CreateChildControls ();
105                 }
106
107                 protected internal virtual void EndRender (HtmlTextWriter writer)
108                 {
109                         writer.EndRender ();
110                 }
111
112                 protected internal virtual void LoadAdapterControlState (object state)
113                 {
114                 }
115
116                 protected internal virtual void LoadAdapterViewState (object state)
117                 {
118                 }
119
120                 protected internal virtual void OnInit (EventArgs e)
121                 {
122                         Control control = Control;
123
124                         if (control != null)
125                                 control.OnInit(e);
126                 }
127
128                 protected internal virtual void OnLoad (EventArgs e)
129                 {
130                         Control control = Control;
131
132                         if (control != null)
133                                 control.OnLoad(e);
134                 }
135
136                 protected internal virtual void OnPreRender (EventArgs e)
137                 {
138                         Control control = Control;
139
140                         if (control != null)
141                                 control.OnPreRender(e);
142                 }
143
144                 protected internal virtual void OnUnload (EventArgs e)
145                 {
146                         Control control = Control;
147
148                         if (control != null)
149                                 control.OnUnload(e);
150                 }
151
152                 protected internal virtual void Render (HtmlTextWriter writer)
153                 {
154                         Control control = Control;
155
156                         if (control != null)
157                                 control.Render (writer);
158                 }
159
160                 protected internal virtual void RenderChildren (HtmlTextWriter writer)
161                 {
162                         Control control = Control;
163
164                         if (control != null)
165                                 control.RenderChildren (writer);
166                 }
167
168                 protected internal virtual object SaveAdapterControlState ()
169                 {
170                         return null;
171                 }
172
173                 protected internal virtual object SaveAdapterViewState ()
174                 {
175                         return null;
176                 }
177         }
178 }
179