]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/stattext.cpp
bb9b15ad7fc1ef77dd9c941d9d19190e5336ceb9
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxStaticText 
   8 // Copyright:   (c) AUTHOR 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "stattext.h" 
  17 #include "wx/stattext.h" 
  18 #include "wx/notebook.h" 
  19 #include "wx/tabctrl.h" 
  21 #include "wx/dcclient.h" 
  26 #if !USE_SHARED_LIBRARY 
  27 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
) 
  30 #include "wx/mac/uma.h" 
  32 BEGIN_EVENT_TABLE(wxStaticText
, wxStaticTextBase
) 
  33     EVT_PAINT(wxStaticText::OnPaint
) 
  36 bool wxStaticText::Create(wxWindow 
*parent
, wxWindowID id
, 
  37            const wxString
& label
, 
  44     m_backgroundColour 
= parent
->GetBackgroundColour() ; 
  45     m_foregroundColour 
= parent
->GetForegroundColour() ; 
  48         m_windowId 
= (int)NewControlId(); 
  52     m_windowStyle 
= style
; 
  55     bool ret 
= wxControl::Create( parent
, id
, pos
, size
, style 
, wxDefaultValidator 
, name 
); 
  61 const wxString punct 
= " ,.-;:!?"; 
  63 void wxStaticText::DrawParagraph(wxDC 
&dc
, wxString paragraph
) 
  69   bool linedrawn 
= true; 
  70   while( paragraph
.Length() > 0 ) 
  72         dc
.GetTextExtent( paragraph 
, &width 
, &height 
) ; 
  74         if ( width 
> m_width 
) 
  76             for ( int p 
= paragraph
.Length() -1 ; p 
> 0 ; --p 
) 
  78               if ((punct
.Find(paragraph
[p
]) != wxNOT_FOUND
) || !linedrawn
) 
  80                   int blank 
= (paragraph
[p
] == ' ') ? 0 : 1; 
  82                     dc
.GetTextExtent( paragraph
.Left(p 
+ blank
) , &width 
, &height 
) ; 
  84                     if ( width 
<= m_width 
) 
  87                         if ( HasFlag( wxALIGN_CENTER 
) ) 
  89                             pos 
+= ( m_width 
- width 
) / 2 ; 
  91                         else if ( HasFlag( wxALIGN_RIGHT 
) ) 
  93                             pos 
+= ( m_width 
- width 
) ; 
  96                     dc
.DrawText( paragraph
.Left(p 
+ blank
), pos 
, y
) ; 
  98                         paragraph 
= paragraph
.Mid(p
+1) ; 
 110             if ( HasFlag( wxALIGN_CENTER 
) ) 
 112                 pos 
+= ( m_width 
- width 
) / 2 ; 
 114             else if ( HasFlag( wxALIGN_RIGHT 
) ) 
 116                 pos 
+= ( m_width 
- width 
) ; 
 119         dc
.DrawText( paragraph
, pos 
, y
) ; 
 126 void wxStaticText::OnDraw( wxDC 
&dc 
) 
 128     if (m_width 
<= 0 || m_height 
<= 0) 
 133   wxString text 
= m_label
; 
 134         while (i 
< text
.Length()) 
 136           paragraph 
+= text
[i
]; 
 138         if (text
[i
] == 13 || text
[i
] == 10) 
 139             DrawParagraph(dc
, paragraph
); 
 143   if (paragraph
.Length() > 0) 
 144           DrawParagraph(dc
, paragraph
); 
 147 void wxStaticText::OnPaint( wxPaintEvent 
&event 
)  
 153 wxSize 
wxStaticText::DoGetBestSize() const 
 156     int widthTextMax 
= 0, widthLine
, 
 157         heightTextTotal 
= 0, heightLineDefault 
= 0, heightLine 
= 0; 
 160     for ( const wxChar 
*pc 
= m_label
; ; pc
++ ) 
 162         if ( *pc 
== wxT('\n') || *pc 
== wxT('\0') ) 
 166                 // we can't use GetTextExtent - it will return 0 for both width 
 167                 // and height and an empty line should count in height 
 169                 if ( !heightLineDefault 
) 
 170                     heightLineDefault 
= heightLine
; 
 171                 if ( !heightLineDefault 
) 
 172                     GetTextExtent(_T("W"), NULL
, &heightLineDefault
); 
 174                 heightTextTotal 
+= heightLineDefault
; 
 176                 heightTextTotal
++;  // FIXME: why is this necessary? 
 180                 GetTextExtent(curLine
, &widthLine
, &heightLine
); 
 181                 if ( widthLine 
> widthTextMax 
) 
 182                     widthTextMax 
= widthLine
; 
 183                 heightTextTotal 
+= heightLine
; 
 185                 heightTextTotal
++;  // FIXME: why is this necessary? 
 188             if ( *pc 
== wxT('\n') ) { 
 201     return wxSize(widthTextMax
, heightTextTotal
); 
 204 void wxStaticText::SetLabel(const wxString
& st 
) 
 208         if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) ) 
 209                 SetSize( GetBestSize() ) ;