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"
25 #if !USE_SHARED_LIBRARY
26 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
29 #include "wx/mac/uma.h"
31 BEGIN_EVENT_TABLE(wxStaticText
, wxStaticTextBase
)
32 EVT_PAINT(wxStaticText::OnPaint
)
35 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
36 const wxString
& label
,
43 m_backgroundColour
= parent
->GetBackgroundColour() ;
44 m_foregroundColour
= parent
->GetForegroundColour() ;
47 m_windowId
= (int)NewControlId();
51 m_windowStyle
= style
;
54 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
60 const wxString punct
= " ,.-;:!?";
62 void wxStaticText::DrawParagraph(wxDC
&dc
, wxString paragraph
)
68 bool linedrawn
= true;
69 while( paragraph
.Length() > 0 )
71 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
73 if ( width
> m_width
)
75 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
77 if ((punct
.Find(paragraph
[p
]) != wxNOT_FOUND
) || !linedrawn
)
79 int blank
= (paragraph
[p
] == ' ') ? 0 : 1;
81 dc
.GetTextExtent( paragraph
.Left(p
+ blank
) , &width
, &height
) ;
83 if ( width
<= m_width
)
86 if ( HasFlag( wxALIGN_CENTER
) )
88 pos
+= ( m_width
- width
) / 2 ;
90 else if ( HasFlag( wxALIGN_RIGHT
) )
92 pos
+= ( m_width
- width
) ;
95 dc
.DrawText( paragraph
.Left(p
+ blank
), pos
, y
) ;
97 paragraph
= paragraph
.Mid(p
+1) ;
109 if ( HasFlag( wxALIGN_CENTER
) )
111 pos
+= ( m_width
- width
) / 2 ;
113 else if ( HasFlag( wxALIGN_RIGHT
) )
115 pos
+= ( m_width
- width
) ;
118 dc
.DrawText( paragraph
, pos
, y
) ;
125 void wxStaticText::OnDraw( wxDC
&dc
)
127 if (m_width
<= 0 || m_height
<= 0)
132 wxString text
= m_label
;
136 bool doClear
= true ;
137 WindowRef window
= GetMacRootWindow() ;
140 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
143 wxWindow
* parent
= GetParent() ;
146 if( parent
->MacGetWindowData() )
151 if( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
153 if ( ((wxControl
*)parent
)->GetMacControl() ) {
154 Rect rect
= { -10000 , -10000 , 10000 , 10000 } ; // MacOS X was having a coord rollover
155 if ( DrawThemeTabPane
!= (void*)kUnresolvedCFragSymbolAddress
)
157 DrawThemeTabPane ( &rect
, kThemeStateActive
);
164 parent
= parent
->GetParent() ;
171 while (i
< text
.Length())
173 paragraph
+= text
[i
];
175 if (text
[i
] == 13 || text
[i
] == 10)
176 DrawParagraph(dc
, paragraph
);
180 if (paragraph
.Length() > 0)
181 DrawParagraph(dc
, paragraph
);
184 void wxStaticText::OnPaint( wxPaintEvent
&event
)
190 wxSize
wxStaticText::DoGetBestSize() const
193 int widthTextMax
= 0, widthLine
,
194 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
197 for ( const wxChar
*pc
= m_label
; ; pc
++ )
199 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
203 // we can't use GetTextExtent - it will return 0 for both width
204 // and height and an empty line should count in height
206 if ( !heightLineDefault
)
207 heightLineDefault
= heightLine
;
208 if ( !heightLineDefault
)
209 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
211 heightTextTotal
+= heightLineDefault
;
213 heightTextTotal
++; // FIXME: why is this necessary?
217 GetTextExtent(curLine
, &widthLine
, &heightLine
);
218 if ( widthLine
> widthTextMax
)
219 widthTextMax
= widthLine
;
220 heightTextTotal
+= heightLine
;
222 heightTextTotal
++; // FIXME: why is this necessary?
225 if ( *pc
== wxT('\n') ) {
238 return wxSize(widthTextMax
, heightTextTotal
);
241 void wxStaticText::SetLabel(const wxString
& st
)
245 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
246 SetSize( GetBestSize() ) ;
249 MacUpdateImmediately() ;
250 // wxClientDC dc(this);