2003-09-04 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mcs / class / System.Web.Mobile / System.Web.UI.MobileControls / DeviceSpecific.cs
1 /**
2  * Project   : Mono
3  * Namespace : System.Web.UI.MobileControls
4  * Class     : DeviceSpecific
5  * Author    : Gaurav Vaish
6  *
7  * Copyright : 2003 with Gaurav Vaish, and with
8  *             Ximian Inc
9  */
10
11 using System.Collections;
12 using System.Web.UI;
13 using System.Web.Mobile;
14
15 namespace System.Web.UI.MobileControls
16 {
17         public class DeviceSpecific : Control
18         {
19                 private DeviceSpecificChoiceCollection choices;
20                 private TemplateControl closestTemplateControl = null;
21                 private bool haveSelectedChoice = false;
22                 private object owner;
23                 private DeviceSpecificChoice selectedChoice;
24
25                 public DeviceSpecific()
26                 {
27                 }
28
29                 internal void SetOwner(object owner)
30                 {
31                         this.owner = owner;
32                 }
33
34                 internal void SetDesignerChoice(DeviceSpecificChoice choice)
35                 {
36                         this.selectedChoice = choice;
37                         this.haveSelectedChoice = true;
38                 }
39
40                 internal void ApplyProperties()
41                 {
42                         if(SelectedChoice != null)
43                         {
44                                 SelectedChoice.ApplyProperties();
45                         }
46                 }
47
48                 public new event EventHandler DataBinding
49                 {
50                         add
51                         {
52                                 base.DataBinding += value;
53                         }
54                         remove
55                         {
56                                 base.DataBinding -= value;
57                         }
58                 }
59
60                 public new event EventHandler Disposed
61                 {
62                         add
63                         {
64                                 base.Disposed += value;
65                         }
66                         remove
67                         {
68                                 base.Disposed -= value;
69                         }
70                 }
71
72                 public new event EventHandler Init
73                 {
74                         add
75                         {
76                                 base.Init += value;
77                         }
78                         remove
79                         {
80                                 base.Init -= value;
81                         }
82                 }
83
84                 public new event EventHandler Load
85                 {
86                         add
87                         {
88                                 base.Load += value;
89                         }
90                         remove
91                         {
92                                 base.Load -= value;
93                         }
94                 }
95
96                 public new event EventHandler PreRender
97                 {
98                         add
99                         {
100                                 base.PreRender += value;
101                         }
102                         remove
103                         {
104                                 base.PreRender -= value;
105                         }
106                 }
107
108                 public new event EventHandler Unload
109                 {
110                         add
111                         {
112                                 base.Unload += value;
113                         }
114                         remove
115                         {
116                                 base.Unload -= value;
117                         }
118                 }
119
120                 public DeviceSpecificChoiceCollection Choices
121                 {
122                         get
123                         {
124                                 if(choices == null)
125                                 {
126                                         choices = new DeviceSpecificChoiceCollection(this);
127                                 }
128                                 return choices;
129                         }
130                 }
131
132                 public TemplateControl ClosestTemplateControl
133                 {
134                         get
135                         {
136                                 if(closestTemplateControl == null)
137                                 {
138                                         MobileControl ctrl = null;
139                                         if(Owner is System.Web.UI.MobileControls.Style)
140                                         {
141                                                 ctrl = ((System.Web.UI.MobileControls.Style)Owner).Control;
142                                         } else
143                                         {
144                                                 ctrl = (MobileControl) Owner;
145                                         }
146                                         closestTemplateControl = ctrl.FindClosestTemplateControl();
147                                 }
148                                 return closestTemplateControl;
149                         }
150                 }
151
152                 public override bool EnableViewState
153                 {
154                         get
155                         {
156                                 return base.EnableViewState;
157                         }
158                 }
159
160                 public bool HasTemplates
161                 {
162                         get
163                         {
164                                 if(SelectedChoice != null)
165                                 {
166                                         return SelectedChoice.HasTemplates;
167                                 }
168                                 return false;
169                         }
170                 }
171
172                 public MobilePage MobilePage
173                 {
174                         get
175                         {
176                                 throw new NotImplementedException();
177                         }
178                 }
179
180                 public object Owner
181                 {
182                         get
183                         {
184                                 return this.owner;
185                         }
186                 }
187
188                 public DeviceSpecificChoice SelectedChoice
189                 {
190                         get
191                         {
192                                 throw new NotImplementedException();
193                         }
194                 }
195
196                 public override bool Visible
197                 {
198                         get
199                         {
200                                 return base.Visible;
201                         }
202                 }
203                 
204                 protected override void AddParsedSubObject(object obj)
205                 {
206                         if(obj is DeviceSpecificChoice)
207                         {
208                                 DeviceSpecificChoice dsc = (DeviceSpecificChoice)obj;
209                                 Choices.Add(dsc);
210                         }
211                 }
212                 
213                 public ITemplate GetTemplate(string templateName)
214                 {
215                         ITemplate retVal = null;
216                         if(SelectedChoice != null)
217                         {
218                                 retVal = (ITemplate) SelectedChoice.Templates[templateName];
219                         }
220                         return retVal;
221                 }
222         }
223 }