Bläddra i källkod

2005-09-07 Chris Toshok <[email protected]>

	* ListControl.cs (SelectedIndex): add comment about how you'd
	think OnSelectedIndexChanged would be called.. and you'd be wrong.
	(Text): implement in terms of SelectedValue.
	(TagKey): do the HAVE_CONTROL_ADAPTERS two-step.
	(LoadControlState): implement - this is where the selected index
	ArrayList gets stuffed in 2.0.
	(OnInit): call Page.RegisterRequiresControlState.
	(OnTextChanged): implement.
	(RenderContents): for now just chain up to base.RenderContents.
	(SaveControlState): save our control state properly.
	(GetSelectedIndices): split this out from SaveViewState to it can
	be used by both that and SaveControlState.
	(SaveViewState): mangle this function so it works in both 2.0 and
	1.0.
	(LoadViewState): same.


svn path=/trunk/mcs/; revision=49612
Chris Toshok 20 år sedan
förälder
incheckning
29b8303c76

+ 18 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,21 @@
+2005-09-07  Chris Toshok  <[email protected]>
+
+	* ListControl.cs (SelectedIndex): add comment about how you'd
+	think OnSelectedIndexChanged would be called.. and you'd be wrong.
+	(Text): implement in terms of SelectedValue.
+	(TagKey): do the HAVE_CONTROL_ADAPTERS two-step.
+	(LoadControlState): implement - this is where the selected index
+	ArrayList gets stuffed in 2.0.
+	(OnInit): call Page.RegisterRequiresControlState.
+	(OnTextChanged): implement.
+	(RenderContents): for now just chain up to base.RenderContents.
+	(SaveControlState): save our control state properly.
+	(GetSelectedIndices): split this out from SaveViewState to it can
+	be used by both that and SaveControlState.
+	(SaveViewState): mangle this function so it works in both 2.0 and
+	1.0.
+	(LoadViewState): same.
+
 2005-09-06  Chris Toshok  <[email protected]>
 
 	* BaseValidator.cs (AddAttributesToRender): render our ClientID if

+ 82 - 24
mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs

@@ -193,6 +193,9 @@ namespace System.Web.UI.WebControls {
 				if (value < 0 || value >= Items.Count)
 					throw new ArgumentOutOfRangeException ("value");
 				items [value].Selected = true;
+
+				/* you'd think this would be called, but noooo */
+				//OnSelectedIndexChanged (EventArgs.Empty);
 			}
 		}
 
@@ -245,17 +248,23 @@ namespace System.Web.UI.WebControls {
 		[MonoTODO]
 		[WebSysDescription ("")]
 		[WebCategoryAttribute ("Behavior")]
-		public virtual string Text 
-		{
+		public virtual string Text {
 			get {
-				throw new NotImplementedException ();
+				return SelectedValue;
 			}
 			set {
-				throw new NotImplementedException ();
+				SelectedValue = value;
+				/* you'd think this would be called, but noooo */
+				//OnTextChanged (EventArgs.Empty);
 			}
 		}
 
-		protected virtual new HtmlTextWriterTag TagKey
+#if HAVE_CONTROL_ADAPTERS
+		protected virtual new
+#else		
+		protected override
+#endif
+		HtmlTextWriterTag TagKey
 		{
 			get {
 				return HtmlTextWriterTag.Select;
@@ -280,10 +289,23 @@ namespace System.Web.UI.WebControls {
 		}
 
 #if NET_2_0
-		[MonoTODO]
 		protected internal override void LoadControlState (object savedState)
 		{
-			throw new NotImplementedException ();
+			object first = null;
+			ArrayList indices = null;
+			Pair pair = savedState as Pair;
+
+			if (pair != null) {
+				first = pair.First;
+				indices = pair.Second as ArrayList;
+			}
+
+			base.LoadControlState (first);
+
+			if (indices != null) {
+				foreach (int index in indices)
+					Items [index].Selected = true;
+			}
 		}
 #endif		
 
@@ -330,10 +352,10 @@ namespace System.Web.UI.WebControls {
 		}
 
 #if NET_2_0
-		[MonoTODO]
 		protected internal override void OnInit (EventArgs e)
 		{
-			throw new NotImplementedException ();
+			Page.RegisterRequiresControlState (this);
+			base.OnInit (e);
 		}
 #endif		
 
@@ -348,10 +370,11 @@ namespace System.Web.UI.WebControls {
 		}
 
 #if NET_2_0
-		[MonoTODO]
 		protected virtual void OnTextChanged (EventArgs e)
 		{
-			throw new NotImplementedException ();
+			EventHandler handler = (EventHandler) Events [TextChangedEvent];
+			if (handler != null)
+				handler (this, e);
 		}
 
 		[MonoTODO]
@@ -369,21 +392,41 @@ namespace System.Web.UI.WebControls {
 		[MonoTODO]
 		protected internal override void RenderContents (HtmlTextWriter w)
 		{
-			throw new NotImplementedException ();
+			base.RenderContents (w);
 		}
 
-		[MonoTODO]
 		protected internal override object SaveControlState ()
 		{
-			throw new NotImplementedException ();
+			object first;
+			ArrayList second;
+
+			first = base.SaveControlState ();
+			second = GetSelectedIndices();
+			if (second == null)
+				second = new ArrayList();
+
+			return new Pair (first, second);
 		}
 #endif		
 
+		ArrayList GetSelectedIndices ()
+		{
+			ArrayList selected = null;
+			if (items != null) {
+				selected = new ArrayList ();
+				int count = Items.Count;
+				for (int i = 0; i < count; i++) {
+					if (items [i].Selected)
+						selected.Add (i);
+				}
+			}
+			return selected;
+		}
+
 		protected override object SaveViewState ()
 		{
 			object first = null;
 			object second = null;
-			ArrayList selected = null;
 
 			first = base.SaveViewState ();
 
@@ -391,33 +434,46 @@ namespace System.Web.UI.WebControls {
 			if (manager != null)
 				second = manager.SaveViewState ();
 
-			if (items != null) {
-				selected = new ArrayList ();
-				int count = Items.Count;
-				for (int i = 0; i < count; i++) {
-					if (items [i].Selected)
-						selected.Add (i);
-				}
-			}
+#if !NET_2_0
+			ArrayList selected = GetSelectedIndices ();
+#endif
 
-			if (first == null && second == null && selected == null)
+			if (first == null && second == null
+#if !NET_2_0
+			    && selected == null
+#endif
+			    )
 				return null;
 
+#if NET_2_0
+			return new Pair (first, second);
+#else
 			return new Triplet (first, second, selected);
+#endif
 		}
 
 		protected override void LoadViewState (object savedState)
 		{
 			object first = null;
 			object second = null;
+#if !NET_2_0
 			ArrayList indices = null;
+#endif
 
+#if NET_2_0
+			Pair pair = savedState as Pair;
+			if (pair != null) {
+				first = pair.First;
+				second = pair.Second;
+			}
+#else
 			Triplet triplet = savedState as Triplet;
 			if (triplet != null) {
 				first = triplet.First;
 				second = triplet.Second;
 				indices = triplet.Third as ArrayList;
 			}
+#endif
 
 			base.LoadViewState (first);
 
@@ -426,10 +482,12 @@ namespace System.Web.UI.WebControls {
 				manager.LoadViewState (second);
 			}
 
+#if !NET_2_0
 			if (indices != null) {
 				foreach (int index in indices)
 					Items [index].Selected = true;
 			}
+#endif
 		}
 
 #if NET_2_0