- int w, h;
- RECT rect;
-
- wxWindow *parent = GetParent();
- GetWindowRect((HWND) GetHWND(), &rect);
-
- // Since we now have the absolute screen coords,
- // if there's a parent we must subtract its top left corner
- POINT point;
- point.x = rect.left;
- point.y = rect.top;
- if (parent)
- {
- ::ScreenToClient((HWND) parent->GetHWND(), &point);
- }
-
- GetTextExtent(label, &w, &h, NULL, NULL, & this->GetFont());
- MoveWindow((HWND) GetHWND(), point.x, point.y, (int)(w + 10), (int)h,
- TRUE);
- SetWindowText((HWND) GetHWND(), (const char *)label);
+ 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 ( *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
+ 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;
+ }
+ }
+
+ return wxSize(widthTextMax, heightTextTotal);