Ver código fonte

modifications for ComboBox sample

svn path=/trunk/mcs/; revision=17502
Alexandre Pigolkine 22 anos atrás
pai
commit
3e3cdbe7d3

+ 5 - 0
mcs/class/System.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,8 @@
+2003-08-22  Alexandre Pigolkine <[email protected]>
+
+	* ComboBox.cs
+	* Control.cs		modofications for ComboBox sample
+
 2003-08-22  Duncan Mak  <[email protected]>
 
 	* ListControl.cs (DataSource): Implementation by Brian Takita

+ 15 - 11
mcs/class/System.Windows.Forms/System.Windows.Forms/ComboBox.cs

@@ -31,7 +31,6 @@ namespace System.Windows.Forms {
 		bool sorted;
 		Image backgroundImage;
 		ControlStyles controlStyles;
-		string text;
 		int selectedLength;
 		string selectedText;
 		int selectedIndex;
@@ -53,12 +52,11 @@ namespace System.Windows.Forms {
 			updateing = false;
 			//controlStyles = null;
 			drawMode = DrawMode.Normal;
-			dropDownStyle = ComboBoxStyle.DropDownList;
+			dropDownStyle = ComboBoxStyle.DropDown;
 			droppedDown = false;
 			integralHeight = true;
 			sorted = false;
 			backgroundImage = null;
-			text = "";
 			Items_ = new ComboBox.ObjectCollection(this);
 			itemHeight_ = 13;
 			maxDropDownItems = 8;
@@ -424,10 +422,13 @@ namespace System.Windows.Forms {
 		[MonoTODO]
 		public override string Text {
 			get {
-				return text;
+				return base.Text;
 			}
 			set {
-				text = value;
+				base.Text = value;
+				if (value == null || value == String.Empty) {
+					SelectedIndex = -1;
+				}
 			}
 		}
 		
@@ -573,7 +574,12 @@ namespace System.Windows.Forms {
 			//FIXME:
 			base.OnHandleCreated(e);
 			populateControl(Items_);
-			Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_SETCURSEL, selectedIndex, 0);
+			if (DropDownStyle != ComboBoxStyle.DropDown || Text == String.Empty) {
+				if (selectedIndex == -1 && Items.Count != 0) {
+					selectedIndex = 0;
+				}
+				Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_SETCURSEL, selectedIndex, 0);
+			}
 		}
 		
 		[MonoTODO]
@@ -727,20 +733,18 @@ namespace System.Windows.Forms {
 					else {
 						switch(m.HiWordWParam) {
 							case (uint)ComboBoxNotification.CBN_SELCHANGE:
-								//OnSelectedIndexChanged(new EventArgs());
 								SelectedIndex = Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_GETCURSEL, 0, 0);
 								m.Result = IntPtr.Zero;
-								//CallControlWndProc(ref m);
 								break;
 							default:
-								Console.WriteLine("ComboBox enter default");
-								//CallControlWndProc(ref m);
 								m.Result = IntPtr.Zero;
-								Console.WriteLine("ComboBox exit default");
 								break;
 						}
 					}
 					break;
+				case Msg.WM_CTLCOLOREDIT :
+					CallControlWndProc ( ref m );
+					break;
 				default:
 					base.WndProc(ref m);
 					break;

+ 1 - 3
mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs

@@ -1093,9 +1093,7 @@ namespace System.Windows.Forms {
 		//Compact Framework
     		public virtual string Text {
     			get {
-				// CHECKME: if we really need to provide back current text of real window
-				// or just our copy in text member.
-    				if (IsHandleCreated){
+    				if (GetStyle(ControlStyles.CacheText) && IsHandleCreated){
 					int len = Win32.GetWindowTextLengthA (Handle);
 					// FIXME: len is doubled due to some strange behaviour. (of GetWindowText function ?)
 					// instead of 10 characters we can get only 9, even if sb.Capacity is 10.