]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/stattext.cpp
fixed bug due to missing break in GetColourFromGTKWidget() (part of patch 1160117)
[wxWidgets.git] / src / msw / stattext.cpp
index dcc643398503780be159ea3d600acb5160f03f79..466fb5484d981a815ee5523f67e20a60a6081e22 100644 (file)
 #if wxUSE_STATTEXT
 
 #ifndef WX_PRECOMP
-#include "wx/event.h"
-#include "wx/app.h"
-#include "wx/brush.h"
+    #include "wx/event.h"
+    #include "wx/app.h"
+    #include "wx/brush.h"
+    #include "wx/dcclient.h"
+    #include "wx/settings.h"
 #endif
 
 #include "wx/stattext.h"
 #include "wx/msw/private.h"
-#include <stdio.h>
 
 #if wxUSE_EXTENDED_RTTI
 WX_DEFINE_FLAGS( wxStaticTextStyle )
@@ -125,76 +126,44 @@ WXDWORD wxStaticText::MSWGetStyle(long style, WXDWORD *exstyle) const
     return msStyle;
 }
 
-wxSize wxStaticText::DoGetBestSize() const
+WXHBRUSH wxStaticText::DoMSWControlColor(WXHDC pDC, wxColour colBg)
 {
-    wxString text(wxGetWindowText(GetHWND()));
-
-    int widthTextMax = 0, widthLine,
-        heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
-
-    bool lastWasAmpersand = false;
-
-    wxString curLine;
-    for ( const wxChar *pc = text; ; pc++ )
+    // If this control has a non-standard fg colour but still has the standard
+    // bg then we need to also give it a non-standard bg otherwise the fg
+    // setting has no effect.
+    WXHBRUSH hbr = wxControl::DoMSWControlColor(pDC, colBg);
+    if (!hbr && m_hasFgCol)
     {
-        if ( *pc == wxT('\n') || *pc == wxT('\0') )
+        hbr = MSWGetBgBrushForChild(pDC, this);
+        if (!hbr)
         {
-            if ( !curLine )
-            {
-                // we can't use GetTextExtent - it will return 0 for both width
-                // and height and an empty line should count in height
-                // calculation
-                if ( !heightLineDefault )
-                    heightLineDefault = heightLine;
-                if ( !heightLineDefault )
-                    GetTextExtent(_T("W"), NULL, &heightLineDefault);
-
-                heightTextTotal += heightLineDefault;
-            }
-            else
-            {
-                GetTextExtent(curLine, &widthLine, &heightLine);
-                if ( widthLine > widthTextMax )
-                    widthTextMax = widthLine;
-                heightTextTotal += heightLine;
-            }
-
-            if ( *pc == wxT('\n') )
-            {
-               curLine.Empty();
-            }
-            else
-            {
-               // the end of string
-               break;
-            }
-        }
-        else
-        {
-            // we shouldn't take into account the '&' which just introduces the
-            // mnemonic characters and so are not shown on the screen -- except
-            // when it is preceded by another '&' in which case it stands for a
-            // literal ampersand
-            if ( *pc == _T('&') )
-            {
-                if ( !lastWasAmpersand )
-                {
-                    lastWasAmpersand = true;
-
-                    // skip the statement adding pc to curLine below
-                    continue;
-                }
-
-                // it is a literal ampersand
-                lastWasAmpersand = false;
-            }
-
-            curLine += *pc;
+            HDC hdc = (HDC)pDC;
+            wxColour bg = GetBackgroundColour();
+            ::SetBkColor(hdc, wxColourToRGB(bg));
+            wxBrush *brush = wxTheBrushList->FindOrCreateBrush(bg, wxSOLID);
+            hbr = (WXHBRUSH)brush->GetResourceHandle();
         }
     }
+    return hbr;
+}
+
+wxSize wxStaticText::DoGetBestSize() const
+{
+    wxClientDC dc(wx_const_cast(wxStaticText *, this));
+    wxFont font(GetFont());
+    if (!font.Ok())
+        font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
+    
+    dc.SetFont(font);
+
+    wxCoord widthTextMax, heightTextTotal;
+    dc.GetMultiLineTextExtent(GetLabel(), &widthTextMax, &heightTextTotal);
+
 #ifdef __WXWINCE__
-    if(widthTextMax) widthTextMax += 2;
-#endif
+    if ( widthTextMax )
+        widthTextMax += 2;
+#endif // __WXWINCE__
+
     return wxSize(widthTextMax, heightTextTotal);
 }