2003-09-04 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mcs / class / System.Web.Mobile / System.Web.UI.MobileControls / Panel.cs
1 /**
2  * Project   : Mono
3  * Namespace : System.Web.UI.MobileControls
4  * Class     : Panel
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 Panel : MobileControl, ITemplateable
18         {
19                 private Panel deviceSpecificContent;
20                 private bool  paginationStateChanged = false;
21
22                 public Panel()
23                 {
24                 }
25
26                 public override bool BreakAfter
27                 {
28                         get
29                         {
30                                 return base.BreakAfter;
31                         }
32                         set
33                         {
34                                 base.BreakAfter = value;
35                         }
36                 }
37
38                 protected override bool PaginateChildren
39                 {
40                         get
41                         {
42                                 return Paginate;
43                         }
44                 }
45
46                 public virtual bool Paginate
47                 {
48                         get
49                         {
50                                 object o = ViewState["Paginate"];
51                                 if(o != null)
52                                         return (bool)o;
53                                 return false;
54                         }
55                         set
56                         {
57                                 bool oldPaginate = Paginate;
58                                 ViewState["Paginate"] = value;
59                                 if(IsTrackingViewState)
60                                 {
61                                         PaginationStateChanged = true;
62                                         if(oldPaginate && !value)
63                                                 MobileControl.SetControlPageRecursive(this, 1);
64                                 }
65                         }
66                 }
67
68                 public Panel Content
69                 {
70                         get
71                         {
72                                 return deviceSpecificContent;
73                         }
74                 }
75
76                 internal bool PaginationStateChanged
77                 {
78                         get
79                         {
80                                 return paginationStateChanged;
81                         }
82                         set
83                         {
84                                 paginationStateChanged = value;
85                         }
86                 }
87
88                 public override void AddLinkedForms(IList linkedForms)
89                 {
90                         try
91                         {
92                                 foreach(Control current in Controls)
93                                 {
94                                         if(current is MobileControl)
95                                                 ((MobileControl)current).AddLinkedForms(linkedForms);
96                                 }
97                         } finally
98                         {
99                                 if(linkedForms.GetEnumerator() is IDisposable)
100                                         ((IDisposable)linkedForms.GetEnumerator()).Dispose();
101                         }
102                 }
103
104                 public override void CreateDefaultTemplatedUI(bool doDataBind)
105                 {
106                         ITemplate contentTmpl = GetTemplate(Constants.ContentTemplateTag);
107                         if(contentTmpl != null)
108                         {
109                                 deviceSpecificContent = new TemplateContainer();
110                                 contentTmpl.InstantiateIn(this);
111                                 Controls.AddAt(0, deviceSpecificContent);
112                         }
113                 }
114
115                 public override void PaginateRecursive(ControlPager pager)
116                 {
117                         if(EnablePagination)
118                         {
119                                 if(Paginate && Content != null)
120                                 {
121                                         Content.Paginate = true;
122                                         Content.PaginateRecursive(pager);
123                                         FirstPage = Content.FirstPage;
124                                         LastPage  = pager.PageCount;
125                                         base.PaginateRecursive(pager);
126                                 }
127                         }
128                 }
129
130                 protected override void OnInit(EventArgs e)
131                 {
132                         base.OnInit(e);
133                         if(IsTemplated)
134                         {
135                                 ClearChildViewState();
136                                 CreateTemplatedUI(false);
137                                 ChildControlsCreated = true;
138                         }
139                 }
140         }
141 }