Move negative tests from ilasm/tests to ilasm/errors.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / MultiView.cs
index baeb9e7d254beed1e79a32c927308ac640a7c81f..f2ea72e0243beee6c048b7479fd04676d0186699 100644 (file)
-//\r
-// System.Web.UI.WebControls.MultiView.cs\r
-//\r
-// Authors:\r
-//     Lluis Sanchez Gual (lluis@novell.com)\r
-//\r
-// (C) 2004 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)\r
-//\r
-\r
-#if NET_2_0\r
-\r
-using System;\r
-using System.Globalization;\r
-using System.Web;\r
-using System.Web.UI;\r
-using System.ComponentModel;\r
-\r
-namespace System.Web.UI.WebControls\r
-{\r
-//     [ControlBuilder (typeof(MultiViewControlBuilder)]\r
-       [Designer ("System.Web.UI.Design.WebControls.MultiViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]\r
-       [ToolboxData ("<{0}:MultiView runat=\"server\"></{0}:MultiView>")]\r
-       [ParseChildren (false, ChildControlType = typeof(View))]\r
-       [DefaultEvent ("ActiveViewChanged")]\r
-       public class MultiView: Control\r
-       {\r
-               public static readonly string NextViewCommandName = "NextView";\r
-               public static readonly string PreviousViewCommandName = "PrevView";\r
-               public static readonly string SwitchViewByIDCommandName = "SwitchViewByID";\r
-               public static readonly string SwitchViewByIndexCommandName = "SwitchViewByIndex";\r
-               \r
-               private static readonly object ActiveViewChangedEvent = new object();\r
-               \r
-               int viewIndex = -1;\r
-               int initialIndex = -1;\r
-               bool initied;\r
-               \r
-               public event EventHandler ActiveViewChanged {\r
-                       add { Events.AddHandler (ActiveViewChangedEvent, value); }\r
-                       remove { Events.RemoveHandler (ActiveViewChangedEvent, value); }\r
-               }\r
-               \r
-               protected override void AddParsedSubObject (object ob)\r
-               {\r
-                       if (ob is View)\r
-                               Controls.Add (ob as View);\r
-               }\r
-               \r
-               protected override ControlCollection CreateControlCollection ()\r
-               {\r
-                       return new ViewCollection (this);\r
-               }\r
-               \r
-               public View GetActiveView ()\r
-               {\r
-                       if (viewIndex < 0 || viewIndex >= Controls.Count)\r
-                               throw new HttpException ("The ActiveViewIndex is not set to a valid View control");\r
-                       return Controls [viewIndex] as View;\r
-               }\r
-               \r
-               public void SetActiveView (View view)\r
-               {\r
-                       int i = Controls.IndexOf (view);\r
-                       if (i == -1)\r
-                               throw new HttpException ("The provided view is not contained in the MultiView control.");\r
-                               \r
-                       ActiveViewIndex = i;\r
-               }\r
-               \r
-               [DefaultValue (-1)]\r
-               public virtual int ActiveViewIndex {\r
-                       get { return viewIndex; }\r
-                       set {\r
-                               if (!initied) {\r
-                                       initialIndex = value;\r
-                                       return;\r
-                               }\r
-                               \r
-                               if (value < -1 || value >= Controls.Count)\r
-                                       throw new ArgumentOutOfRangeException ();\r
-\r
-                               if (viewIndex != -1)\r
-                                       ((View)Controls [viewIndex]).NotifyActivation (false);\r
-\r
-                               viewIndex = value;\r
-\r
-                               if (viewIndex != -1)\r
-                                       ((View)Controls [viewIndex]).NotifyActivation (true);\r
-\r
-                               UpdateViewVisibility ();\r
-                       }\r
-               }\r
-\r
-               [Browsable (true)]\r
-               [MonoTODO]\r
-               public virtual new bool EnableTheming\r
-               {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-                       set {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-               \r
-               [PersistenceMode (PersistenceMode.InnerDefaultProperty)]\r
-               [Browsable (false)]\r
-               public virtual ViewCollection Views {\r
-                       get { return Controls as ViewCollection; }\r
-               }\r
-               \r
-               protected override bool OnBubbleEvent (object source, EventArgs e)\r
-               {\r
-                       CommandEventArgs ca = e as CommandEventArgs;\r
-                       if (ca != null) {\r
-                               switch (ca.CommandName) {\r
-                                       case "NextView":\r
-                                               if (viewIndex < Controls.Count - 1 && Controls.Count > 0)\r
-                                                       ActiveViewIndex = viewIndex + 1;\r
-                                               break;\r
-                                               \r
-                                       case "PrevView": \r
-                                               if (viewIndex > 0)\r
-                                                       ActiveViewIndex = viewIndex - 1;\r
-                                               break;\r
-                                               \r
-                                       case "SwitchViewByID":\r
-                                               foreach (View v in Controls)\r
-                                                       if (v.ID == ca.CommandArgument) {\r
-                                                               SetActiveView (v);\r
-                                                               break;\r
-                                                       }\r
-                                               break;\r
-                                               \r
-                                       case "SwitchViewByIndex":\r
-                                               int i = (int) Convert.ChangeType (ca.CommandArgument, typeof(int));\r
-                                               ActiveViewIndex = i;\r
-                                               break;\r
-                               }\r
-                       }\r
-                       return false;\r
-               }\r
-               \r
-               protected internal override void OnInit (EventArgs e)\r
-               {\r
-                       initied = true;\r
-                       Page.RegisterRequiresControlState (this);\r
-                       if (initialIndex != -1) {\r
-                               ActiveViewIndex = initialIndex;\r
-                               initialIndex = -1;\r
-                       }\r
-                       base.OnInit (e);\r
-               }\r
-               \r
-               void UpdateViewVisibility ()\r
-               {\r
-                       for (int n=0; n<Views.Count; n++)\r
-                               Views [n].Visible = (n == viewIndex);\r
-               }\r
-               \r
-               protected internal override void RemovedControl (Control ctl)\r
-               {\r
-                       if (viewIndex >= Controls.Count) {\r
-                               viewIndex = Controls.Count - 1;\r
-                               UpdateViewVisibility ();\r
-                       }\r
-\r
-                       base.RemovedControl (ctl);\r
-               }\r
-               \r
-               protected internal override void LoadControlState (object state)\r
-               {\r
-                       if (state != null) {\r
-                               viewIndex = (int)state;\r
-                               UpdateViewVisibility ();\r
-                       }\r
-                       else viewIndex = -1;\r
-               }\r
-               \r
-               protected internal override object SaveControlState ()\r
-               {\r
-                       if (viewIndex != -1) return viewIndex;\r
-                       else return null;\r
-               }\r
-               \r
-               protected virtual void OnActiveViewChanged (EventArgs e)\r
-               {\r
-                       if (Events != null) {\r
-                               EventHandler eh = (EventHandler) Events [ActiveViewChangedEvent];\r
-                               if (eh != null) eh (this, e);\r
-                       }\r
-               }\r
-               \r
-               protected internal override void Render (HtmlTextWriter writer)\r
-               {\r
-                       if (!initied) viewIndex = initialIndex;\r
-                       if (viewIndex != -1)\r
-                               GetActiveView ().Render (writer);\r
-               }\r
-       }\r
-}\r
-\r
-#endif\r
+//
+// System.Web.UI.WebControls.MultiView.cs
+//
+// Authors:
+//     Lluis Sanchez Gual (lluis@novell.com)
+//
+// (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+
+#if NET_2_0
+
+using System;
+using System.Globalization;
+using System.Web;
+using System.Web.UI;
+using System.ComponentModel;
+
+namespace System.Web.UI.WebControls
+{
+//     [ControlBuilder (typeof(MultiViewControlBuilder)]
+       [Designer ("System.Web.UI.Design.WebControls.MultiViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+       [ToolboxData ("<{0}:MultiView runat=\"server\"></{0}:MultiView>")]
+       [ParseChildren (false, ChildControlType = typeof(View))]
+       [DefaultEvent ("ActiveViewChanged")]
+       public class MultiView: Control
+       {
+               public static readonly string NextViewCommandName = "NextView";
+               public static readonly string PreviousViewCommandName = "PrevView";
+               public static readonly string SwitchViewByIDCommandName = "SwitchViewByID";
+               public static readonly string SwitchViewByIndexCommandName = "SwitchViewByIndex";
+               
+               private static readonly object ActiveViewChangedEvent = new object();
+               
+               int viewIndex = -1;
+               int initialIndex = -1;
+               bool initied;
+               
+               public event EventHandler ActiveViewChanged {
+                       add { Events.AddHandler (ActiveViewChangedEvent, value); }
+                       remove { Events.RemoveHandler (ActiveViewChangedEvent, value); }
+               }
+               
+               protected override void AddParsedSubObject (object ob)
+               {
+                       if (ob is View)
+                               Controls.Add (ob as View);
+               }
+               
+               protected override ControlCollection CreateControlCollection ()
+               {
+                       return new ViewCollection (this);
+               }
+               
+               public View GetActiveView ()
+               {
+                       if (viewIndex < 0 || viewIndex >= Controls.Count)
+                               throw new HttpException ("The ActiveViewIndex is not set to a valid View control");
+                       return Controls [viewIndex] as View;
+               }
+               
+               public void SetActiveView (View view)
+               {
+                       int i = Controls.IndexOf (view);
+                       if (i == -1)
+                               throw new HttpException ("The provided view is not contained in the MultiView control.");
+                               
+                       ActiveViewIndex = i;
+               }
+               
+               [DefaultValue (-1)]
+               public virtual int ActiveViewIndex {
+                       get { return viewIndex; }
+                       set {
+                               if (!initied) {
+                                       initialIndex = value;
+                                       return;
+                               }
+                               
+                               if (value < -1 || value >= Controls.Count)
+                                       throw new ArgumentOutOfRangeException ();
+
+                               if (viewIndex != -1)
+                                       ((View)Controls [viewIndex]).NotifyActivation (false);
+
+                               viewIndex = value;
+
+                               if (viewIndex != -1)
+                                       ((View)Controls [viewIndex]).NotifyActivation (true);
+
+                               UpdateViewVisibility ();
+                       }
+               }
+
+               [Browsable (true)]
+               [MonoTODO]
+               public virtual new bool EnableTheming
+               {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+                       set {
+                               throw new NotImplementedException ();
+                       }
+               }
+               
+               [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
+               [Browsable (false)]
+               public virtual ViewCollection Views {
+                       get { return Controls as ViewCollection; }
+               }
+               
+               protected override bool OnBubbleEvent (object source, EventArgs e)
+               {
+                       CommandEventArgs ca = e as CommandEventArgs;
+                       if (ca != null) {
+                               switch (ca.CommandName) {
+                                       case "NextView":
+                                               if (viewIndex < Controls.Count - 1 && Controls.Count > 0)
+                                                       ActiveViewIndex = viewIndex + 1;
+                                               break;
+                                               
+                                       case "PrevView": 
+                                               if (viewIndex > 0)
+                                                       ActiveViewIndex = viewIndex - 1;
+                                               break;
+                                               
+                                       case "SwitchViewByID":
+                                               foreach (View v in Controls)
+                                                       if (v.ID == (string)ca.CommandArgument) {
+                                                               SetActiveView (v);
+                                                               break;
+                                                       }
+                                               break;
+                                               
+                                       case "SwitchViewByIndex":
+                                               int i = (int) Convert.ChangeType (ca.CommandArgument, typeof(int));
+                                               ActiveViewIndex = i;
+                                               break;
+                               }
+                       }
+                       return false;
+               }
+               
+               protected internal override void OnInit (EventArgs e)
+               {
+                       initied = true;
+                       Page.RegisterRequiresControlState (this);
+                       if (initialIndex != -1) {
+                               ActiveViewIndex = initialIndex;
+                               initialIndex = -1;
+                       }
+                       base.OnInit (e);
+               }
+               
+               void UpdateViewVisibility ()
+               {
+                       for (int n=0; n<Views.Count; n++)
+                               Views [n].Visible = (n == viewIndex);
+               }
+               
+               protected internal override void RemovedControl (Control ctl)
+               {
+                       if (viewIndex >= Controls.Count) {
+                               viewIndex = Controls.Count - 1;
+                               UpdateViewVisibility ();
+                       }
+
+                       base.RemovedControl (ctl);
+               }
+               
+               protected internal override void LoadControlState (object state)
+               {
+                       if (state != null) {
+                               viewIndex = (int)state;
+                               UpdateViewVisibility ();
+                       }
+                       else viewIndex = -1;
+               }
+               
+               protected internal override object SaveControlState ()
+               {
+                       if (viewIndex != -1) return viewIndex;
+                       else return null;
+               }
+               
+               protected virtual void OnActiveViewChanged (EventArgs e)
+               {
+                       if (Events != null) {
+                               EventHandler eh = (EventHandler) Events [ActiveViewChangedEvent];
+                               if (eh != null) eh (this, e);
+                       }
+               }
+               
+               protected internal override void Render (HtmlTextWriter writer)
+               {
+                       if (!initied) viewIndex = initialIndex;
+                       if (viewIndex != -1)
+                               GetActiveView ().Render (writer);
+               }
+       }
+}
+
+#endif