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
, wxControl
)
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
);
55 SetSizeOrDefault( size
) ;
60 void wxStaticText::OnDraw( wxDC
&dc
)
62 if (m_width
<= 0 || m_height
<= 0)
68 WindowRef window
= GetMacRootWindow() ;
71 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
74 wxWindow
* parent
= GetParent() ;
77 if( parent
->MacGetWindowData() )
82 if( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
84 if ( ((wxControl
*)parent
)->GetMacControl() ) {
85 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
86 if ( DrawThemeTabPane
!= (void*)kUnresolvedCFragSymbolAddress
)
88 DrawThemeTabPane ( &rect
, kThemeStateActive
);
95 parent
= parent
->GetParent() ;
104 wxString text
= m_label
;
110 while( i
< text
.Length() )
112 if( text
[i
] == 13 || text
[i
] == 10)
114 paragraph
= text
.Mid( laststop
, i
- laststop
) ;
115 while( paragraph
.Length() > 0 )
117 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
118 if ( width
> m_width
)
120 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
122 if ( paragraph
[p
]=='.' )
124 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
125 if ( width
<= m_width
)
128 if ( HasFlag( wxALIGN_CENTER
) )
130 pos
+= ( m_width
- width
) / 2 ;
132 else if ( HasFlag( wxALIGN_RIGHT
) )
134 pos
+= ( m_width
- width
) ;
136 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
138 paragraph
= paragraph
.Mid(p
+1) ;
142 if ( paragraph
[p
]==' ' )
144 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
145 if ( width
<= m_width
)
148 if ( HasFlag( wxALIGN_CENTER
) )
150 pos
+= ( m_width
- width
) / 2 ;
152 else if ( HasFlag( wxALIGN_RIGHT
) )
154 pos
+= ( m_width
- width
) ;
156 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
158 paragraph
= paragraph
.Mid(p
+1) ;
166 dc
.DrawText( paragraph
, x
, y
) ;
175 paragraph
= text
.Mid( laststop
, text
.Length() - laststop
) ;
176 while( paragraph
.Length() > 0 )
178 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
179 if ( width
> m_width
)
181 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
183 if ( paragraph
[p
]=='.' )
185 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
186 if ( width
<= m_width
)
189 if ( HasFlag( wxALIGN_CENTER
) )
191 pos
+= ( m_width
- width
) / 2 ;
193 else if ( HasFlag( wxALIGN_RIGHT
) )
195 pos
+= ( m_width
- width
) ;
197 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
199 paragraph
= paragraph
.Mid(p
+1) ;
203 if ( paragraph
[p
]==' ' )
205 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
206 if ( width
<= m_width
)
209 if ( HasFlag( wxALIGN_CENTER
) )
211 pos
+= ( m_width
- width
) / 2 ;
213 else if ( HasFlag( wxALIGN_RIGHT
) )
215 pos
+= ( m_width
- width
) ;
217 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
219 paragraph
= paragraph
.Mid(p
+1) ;
228 if ( HasFlag( wxALIGN_CENTER
) )
230 pos
+= ( m_width
- width
) / 2 ;
232 else if ( HasFlag( wxALIGN_RIGHT
) )
234 pos
+= ( m_width
- width
) ;
236 dc
.DrawText( paragraph
, pos
, y
) ;
243 void wxStaticText::OnPaint( wxPaintEvent
&event
)
249 wxSize
wxStaticText::DoGetBestSize() const
252 int widthTextMax
= 0, widthLine
,
253 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
256 for ( const wxChar
*pc
= m_label
; ; pc
++ ) {
257 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
259 // we can't use GetTextExtent - it will return 0 for both width
260 // and height and an empty line should count in height
262 if ( !heightLineDefault
)
263 heightLineDefault
= heightLine
;
264 if ( !heightLineDefault
)
265 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
267 heightTextTotal
+= heightLineDefault
;
270 GetTextExtent(curLine
, &widthLine
, &heightLine
);
271 if ( widthLine
> widthTextMax
)
272 widthTextMax
= widthLine
;
273 heightTextTotal
+= heightLine
;
276 if ( *pc
== wxT('\n') ) {
289 return wxSize(widthTextMax
, heightTextTotal
);
292 void wxStaticText::SetLabel(const wxString
& st
)
296 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
300 MacUpdateImmediately() ;
301 // wxClientDC dc(this);