Explorar el Código

button fixes

svn path=/trunk/mcs/; revision=37689
Jordi Mas i Hernandez hace 21 años
padre
commit
d02ca5dd8d

+ 7 - 1
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Button.cs

@@ -102,7 +102,13 @@ namespace System.Windows.Forms {
 		}
 
 		protected override bool ProcessMnemonic(char charCode) {
-			return base.ProcessMnemonic (charCode);
+			
+			if (IsMnemonic(charCode, Text) == true) {
+				PerformClick();
+				return true;
+			}
+			
+			return base.ProcessMnemonic(charCode);
 		}
 
 		protected override void WndProc(ref Message m) {

+ 2 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ButtonBase.cs

@@ -96,6 +96,7 @@
 
 using System.ComponentModel;
 using System.Drawing;
+using System.Drawing.Text;
 
 namespace System.Windows.Forms {
 	public abstract class ButtonBase : Control {
@@ -183,6 +184,7 @@ namespace System.Windows.Forms {
 			text_format	= new StringFormat();
 			text_format.Alignment = StringAlignment.Center;
 			text_format.LineAlignment = StringAlignment.Center;
+			text_format.HotkeyPrefix = HotkeyPrefix.Show;
 
 			TextChanged+=new System.EventHandler(RedrawEvent);
 			ForeColorChanged+=new EventHandler(RedrawEvent);

+ 8 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,11 @@
+2004-12-13  Jordi Mas i Hernandez <[email protected]>
+
+	* Button.cs: implement ProcessMnemonic
+	* ThemeWin32Classic.cs: use ResPool (caching) instead of creating
+	  brushes everytime
+	* Control.cs: fixes IsMnemonic (support for &&, case insensitive, etc)
+	* ButtonBase.cs: Show HotkeyPrefix (not the &)	
+
 2004-12-12  John BouAntoun  <[email protected]>
 	
 	* MonthCalendar.cs: Implemented click-hold for next/previous month

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

@@ -1898,13 +1898,17 @@ namespace System.Windows.Forms
 		}
 
 		public static bool IsMnemonic(char charCode, string text) {
-			int amp;
+			int amp;			
 
 			amp = text.IndexOf('&');
 
 			if (amp != -1) {
-				if (charCode == text.ToCharArray(amp, 1)[0]) {
-					return true;
+				if (amp + 1 < text.Length) {
+					if (text[amp + 1] != '&') {
+						if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
+							return true;
+						}	
+					}
 				}
 			}
 			return false;

+ 5 - 8
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs

@@ -381,10 +381,8 @@ namespace System.Windows.Forms
 
 			width = button.ClientSize.Width;
 			height = button.ClientSize.Height;
-
-			SolidBrush	sb = new SolidBrush(button.BackColor);
-			dc.FillRectangle(sb, button.ClientRectangle);
-			sb.Dispose();
+			
+			dc.FillRectangle(ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);			
 			
 			// set up the button rectangle
 			buttonRectangle = button.ClientRectangle;
@@ -511,10 +509,9 @@ namespace System.Windows.Forms
 					text_rect.Y++;
 				}
 
-				if (button.is_enabled) {
-					SolidBrush	b = new SolidBrush(button.ForeColor);
-					dc.DrawString(button.text, button.Font, b, text_rect, button.text_format);
-					b.Dispose();
+				if (button.is_enabled) {					
+					dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
+					
 				} else {
 					if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
 						dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rect, button.text_format);