- // Under Windows at least, we will get this immediately
- // because when the view window is focussed, the
- // tip window goes out of focus.
-#ifdef __WXGTK__
- Close();
-#endif
+ wxClientDC dc(this);
+ dc.SetFont(GetFont());
+
+ // calculate the length: we want each line be no longer than maxLength
+ // pixels and we only break lines at words boundary
+ wxString current;
+ wxCoord height, width,
+ widthMax = 0;
+ m_heightLine = 0;
+
+ bool breakLine = FALSE;
+ for ( const wxChar *p = text.c_str(); ; p++ )
+ {
+ if ( *p == _T('\n') || *p == _T('\0') )
+ {
+ dc.GetTextExtent(current, &width, &height);
+ if ( width > widthMax )
+ widthMax = width;
+
+ if ( height > m_heightLine )
+ m_heightLine = height;
+
+ m_textLines.Add(current);
+
+ if ( !*p )
+ {
+ // end of text
+ break;
+ }
+
+ current.clear();
+ breakLine = FALSE;
+ }
+ else if ( breakLine && (*p == _T(' ') || *p == _T('\t')) )
+ {
+ // word boundary - break the line here
+ m_textLines.Add(current);
+ current.clear();
+ breakLine = FALSE;
+ }
+ else // line goes on
+ {
+ current += *p;
+ dc.GetTextExtent(current, &width, &height);
+ if ( width > maxLength )
+ breakLine = TRUE;
+
+ if ( width > widthMax )
+ widthMax = width;
+
+ if ( height > m_heightLine )
+ m_heightLine = height;
+ }
+ }
+
+ // take into account the border size and the margins
+ SetClientSize(2*(TEXT_MARGIN_X + 1) + widthMax,
+ 2*(TEXT_MARGIN_Y + 1) + m_textLines.GetCount() * m_heightLine);