2 // System.Web.UI.WebControls.MultiView.cs
\r
5 // Lluis Sanchez Gual (lluis@novell.com)
\r
7 // (C) 2004 Novell, Inc (http://www.novell.com)
\r
9 // Permission is hereby granted, free of charge, to any person obtaining
\r
10 // a copy of this software and associated documentation files (the
\r
11 // "Software"), to deal in the Software without restriction, including
\r
12 // without limitation the rights to use, copy, modify, merge, publish,
\r
13 // distribute, sublicense, and/or sell copies of the Software, and to
\r
14 // permit persons to whom the Software is furnished to do so, subject to
\r
15 // the following conditions:
\r
17 // The above copyright notice and this permission notice shall be
\r
18 // included in all copies or substantial portions of the Software.
\r
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
\r
34 using System.Globalization;
\r
36 using System.Web.UI;
\r
37 using System.ComponentModel;
\r
39 namespace System.Web.UI.WebControls
\r
41 // [ControlBuilder (typeof(MultiViewControlBuilder)]
\r
42 [Designer ("System.Web.UI.Design.WebControls.MultiViewDesigner, System.Design, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
\r
43 [ToolboxData ("<{0}:MultiView runat=\"server\"></{0}:MultiView>")]
\r
44 [ParseChildren (false, ChildControlType = typeof(View))]
\r
45 [DefaultEvent ("ActiveViewChanged")]
\r
46 public class MultiView: Control
\r
48 public static readonly string NextViewCommandName = "NextView";
\r
49 public static readonly string PreviousViewCommandName = "PrevView";
\r
50 public static readonly string SwitchViewByIDCommandName = "SwitchViewByID";
\r
51 public static readonly string SwitchViewByIndexCommandName = "SwitchViewByIndex";
\r
53 private static readonly object ActiveViewChangedEvent = new object();
\r
56 int initialIndex = -1;
\r
59 public event EventHandler ActiveViewChanged {
\r
60 add { Events.AddHandler (ActiveViewChangedEvent, value); }
\r
61 remove { Events.RemoveHandler (ActiveViewChangedEvent, value); }
\r
64 protected override void AddParsedSubObject (object ob)
\r
67 Controls.Add (ob as View);
\r
70 protected override ControlCollection CreateControlCollection ()
\r
72 return new ViewCollection (this);
\r
75 public View GetActiveView ()
\r
77 if (viewIndex < 0 || viewIndex >= Controls.Count)
\r
78 throw new HttpException ("The ActiveViewIndex is not set to a valid View control");
\r
79 return Controls [viewIndex] as View;
\r
82 public void SetActiveView (View view)
\r
84 int i = Controls.IndexOf (view);
\r
86 throw new HttpException ("The provided view is not contained in the MultiView control.");
\r
88 ActiveViewIndex = i;
\r
92 public virtual int ActiveViewIndex {
\r
93 get { return viewIndex; }
\r
96 initialIndex = value;
\r
100 if (value < -1 || value >= Controls.Count)
\r
101 throw new ArgumentOutOfRangeException ();
\r
103 if (viewIndex != -1)
\r
104 ((View)Controls [viewIndex]).NotifyActivation (false);
\r
108 if (viewIndex != -1)
\r
109 ((View)Controls [viewIndex]).NotifyActivation (true);
\r
113 [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
\r
114 [Browsable (false)]
\r
115 public virtual ViewCollection Views {
\r
116 get { return Controls as ViewCollection; }
\r
119 protected override bool OnBubbleEvent (object source, EventArgs e)
\r
121 CommandEventArgs ca = e as CommandEventArgs;
\r
123 switch (ca.CommandName) {
\r
125 if (viewIndex < Controls.Count - 1 && Controls.Count > 0)
\r
126 ActiveViewIndex = viewIndex + 1;
\r
131 ActiveViewIndex = viewIndex - 1;
\r
134 case "SwitchViewByID":
\r
135 foreach (View v in Controls)
\r
136 if (v.ID == ca.CommandArgument) {
\r
142 case "SwitchViewByIndex":
\r
143 int i = (int) Convert.ChangeType (ca.CommandArgument, typeof(int));
\r
144 ActiveViewIndex = i;
\r
151 protected override void OnInit (EventArgs e)
\r
154 Page.RegisterRequiresControlState (this);
\r
155 ActiveViewIndex = initialIndex;
\r
159 protected internal override void RemovedControl (Control ctl)
\r
161 if (viewIndex >= Controls.Count)
\r
162 viewIndex = Controls.Count - 1;
\r
164 base.RemovedControl (ctl);
\r
167 protected internal override void LoadControlState (object state)
\r
169 if (state != null) viewIndex = (int)state;
\r
170 else viewIndex = -1;
\r
173 protected internal override object SaveControlState ()
\r
175 if (viewIndex != -1) return viewIndex;
\r
179 protected virtual void OnActiveViewChanged (EventArgs e)
\r
181 if (Events != null) {
\r
182 EventHandler eh = (EventHandler) Events [ActiveViewChangedEvent];
\r
183 if (eh != null) eh (this, e);
\r
187 protected override void Render (HtmlTextWriter writer)
\r
189 if (viewIndex != -1)
\r
190 GetActiveView ().Render (writer);
\r