]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/stattext.cpp
Remove unnecessary header dependencies. Fix resulting compilation
[wxWidgets.git] / src / msw / stattext.cpp
index 14c62eca20a3ace748db6d4b6b2287294e3f1f64..e34b05595891e3ba478ddabe94932ce309f03f39 100644 (file)
@@ -76,10 +76,15 @@ wxSize wxStaticText::DoGetBestSize() const
     int widthTextMax = 0, widthLine,
         heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
 
+    bool lastWasAmpersand = FALSE;
+
     wxString curLine;
-    for ( const wxChar *pc = text; ; pc++ ) {
-        if ( *pc == wxT('\n') || *pc == wxT('\0') ) {
-            if ( !curLine ) {
+    for ( const wxChar *pc = text; ; pc++ )
+    {
+        if ( *pc == wxT('\n') || *pc == wxT('\0') )
+        {
+            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
@@ -90,26 +95,45 @@ wxSize wxStaticText::DoGetBestSize() const
 
                 heightTextTotal += heightLineDefault;
             }
-            else {
+            else
+            {
                 GetTextExtent(curLine, &widthLine, &heightLine);
                 if ( widthLine > widthTextMax )
                     widthTextMax = widthLine;
                 heightTextTotal += heightLine;
             }
 
-            if ( *pc == wxT('\n') ) {
+            if ( *pc == wxT('\n') )
+            {
                curLine.Empty();
             }
-            else {
+            else
+            {
                // the end of string
                break;
             }
         }
-        else {
-            // we shouldn't take into account the '&' which just introduce the
-            // mnemonic characters and so are not shown on the screen
-            if ( pc != _T('&') )
-                curLine += *pc;
+        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;
         }
     }