also, disable the call do BindColumns in
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TextRenderer.cs
index 67cc68bf78b36184d986b3a9fef57677fb5df5c6..be572119ac032171e719d91cf291c9ec40411859 100644 (file)
@@ -44,6 +44,9 @@ namespace System.Windows.Forms
                [MonoTODO("This should be correct for Windows, other platforms need a more accurate fallback method than the one provided")]
                public static void DrawText (IDeviceContext dc, string text, Font font, Rectangle bounds, Color foreColor, TextFormatFlags flags)
                {
+                       if (text == null || text.Length == 0)
+                               return;
+                               
                        if (Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.Win32Windows) {
                                Rectangle new_bounds = bounds;
                                new_bounds.Offset ((int)(dc as Graphics).Transform.OffsetX + 0, (int)(dc as Graphics).Transform.OffsetY + 0);
@@ -151,6 +154,44 @@ namespace System.Windows.Forms
                                return retval;  
                        }
                }
+
+               [MonoTODO ("This should be correct for Windows, other platforms need a more accurate fallback method than the one provided")]
+               public static Size MeasureText (string text, Font font, Size proposedSize, TextFormatFlags flags)
+               {
+                       if (Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.Win32Windows) {
+                               if ((flags & TextFormatFlags.HidePrefix) == TextFormatFlags.HidePrefix)
+                               {
+                                       text = text.Replace ("&", "");
+                               }
+                               
+                               Bitmap b = new Bitmap (5, 5);
+                               Graphics g = Graphics.FromImage (b);
+
+                               IntPtr hdc = g.GetHdc ();
+
+                               if (font != null)
+                                       SelectObject (hdc, font.ToHfont ());
+
+                               VisualStyles.UXTheme.SIZE text_size = new System.Windows.Forms.VisualStyles.UXTheme.SIZE ();
+
+                               GetTextExtentPoint32 (hdc, text, text.Length, out text_size);
+
+                               g.ReleaseHdc ();
+
+                               Size retval = text_size.ToSize ();
+                               //retval.Height += 4;
+                               if (retval.Width > 0) retval.Width += 6;
+                               return retval;
+                       }
+                       else {
+                               Bitmap b = new Bitmap (5, 5);
+                               Graphics g = Graphics.FromImage (b);
+
+                               Size retval = g.MeasureString (text, font).ToSize ();
+                               if (retval.Width > 0) retval.Width += 6;
+                               return retval;
+                       }
+               }
                #endregion
 
                #region Private Methods
@@ -225,14 +266,14 @@ namespace System.Windows.Forms
                [DllImport ("gdi32")]
                private extern static IntPtr SelectObject (IntPtr hDC, IntPtr hObject);
 
-               [DllImport ("gdi32")]
-               static extern int SetBkColor (IntPtr hdc, int crColor);
+               //[DllImport ("gdi32")]
+               //static extern int SetBkColor (IntPtr hdc, int crColor);
 
                [DllImport ("gdi32")]
                static extern int SetBkMode (IntPtr hdc, int iBkMode);
 
-               [DllImport ("gdi32")]
-               static extern bool GetTextExtentExPoint (IntPtr hdc, string lpszStr, int cchString, int nMaxExtent, IntPtr lpnFit, IntPtr alpDx, out VisualStyles.UXTheme.SIZE lpSize);
+               //[DllImport ("gdi32")]
+               //static extern bool GetTextExtentExPoint (IntPtr hdc, string lpszStr, int cchString, int nMaxExtent, IntPtr lpnFit, IntPtr alpDx, out VisualStyles.UXTheme.SIZE lpSize);
 
                [DllImport ("gdi32")]
                static extern bool GetTextExtentPoint32 (IntPtr hdc, string lpString, int cbString, out VisualStyles.UXTheme.SIZE lpSize);